diff options
| author | Oleh Krehel | 2015-04-20 14:18:32 +0200 |
|---|---|---|
| committer | Oleh Krehel | 2015-04-20 14:22:24 +0200 |
| commit | 63161721fe696508d91425a9429c048c72f9f801 (patch) | |
| tree | 47a61bd3b9379979cbc244e32924e58dc245ba7e | |
| parent | 8f1eda7a8a7e268413e38fa9d704a92cf7a860d5 (diff) | |
| download | emacs-scratch/fix-info-dups.tar.gz emacs-scratch/fix-info-dups.zip | |
Fix duplicates when completing Info filesscratch/fix-info-dups
* lisp/info.el (Info-read-node-name-2): Use the STRING argument a lot
less, it's actually always "". Update the regex to remove the split
files, the old one wasn't working properly. Delete duplicates and
nreverse the list to make it alphabetical. Return names sans
suffixes always.
(Bug#20365)
| -rw-r--r-- | lisp/info.el | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/lisp/info.el b/lisp/info.el index 01596619476..44c4aabe172 100644 --- a/lisp/info.el +++ b/lisp/info.el | |||
| @@ -1766,41 +1766,22 @@ directories to search if FILENAME is not absolute; SUFFIXES is a | |||
| 1766 | list of valid filename suffixes for Info files. See | 1766 | list of valid filename suffixes for Info files. See |
| 1767 | `try-completion' for a description of the remaining arguments." | 1767 | `try-completion' for a description of the remaining arguments." |
| 1768 | (setq suffixes (remove "" suffixes)) | 1768 | (setq suffixes (remove "" suffixes)) |
| 1769 | (when (file-name-absolute-p string) | ||
| 1770 | (setq dirs (list (file-name-directory string)))) | ||
| 1771 | (let ((names nil) | 1769 | (let ((names nil) |
| 1772 | (names-sans-suffix nil) | 1770 | (suffix (concat (regexp-opt suffixes t) "\\'"))) |
| 1773 | (suffix (concat (regexp-opt suffixes t) "\\'")) | ||
| 1774 | (string-dir (file-name-directory string))) | ||
| 1775 | (dolist (dir dirs) | 1771 | (dolist (dir dirs) |
| 1776 | (unless dir | ||
| 1777 | (setq dir default-directory)) | ||
| 1778 | (if string-dir (setq dir (expand-file-name string-dir dir))) | ||
| 1779 | (when (file-directory-p dir) | 1772 | (when (file-directory-p dir) |
| 1780 | (dolist (file (file-name-all-completions | 1773 | (dolist (file (directory-files dir)) |
| 1781 | (file-name-nondirectory string) dir)) | 1774 | ;; If the file name has a standard suffix, |
| 1782 | ;; If the file name has no suffix or a standard suffix, | 1775 | ;; include it (without the suffix). |
| 1783 | ;; include it. | 1776 | (when (and (string-match suffix file) |
| 1784 | (and (or (null (file-name-extension file)) | 1777 | ;; But exclude subfiles of split Info files. |
| 1785 | (string-match suffix file)) | 1778 | (not (string-match "\.info-[0-9]+" file)) |
| 1786 | ;; But exclude subfiles of split Info files. | 1779 | ;; And exclude backup files. |
| 1787 | (not (string-match "-[0-9]+\\'" file)) | 1780 | (not (string-match "~\\'" file))) |
| 1788 | ;; And exclude backup files. | 1781 | (push (substring file 0 (match-beginning 0)) |
| 1789 | (not (string-match "~\\'" file)) | 1782 | names))))) |
| 1790 | (push (if string-dir (concat string-dir file) file) names)) | 1783 | (complete-with-action action (cl-delete-duplicates |
| 1791 | ;; If the file name ends in a standard suffix, | 1784 | (nreverse names) :test 'equal) string pred))) |
| 1792 | ;; add the unsuffixed name as a completion option. | ||
| 1793 | (when (string-match suffix file) | ||
| 1794 | (setq file (substring file 0 (match-beginning 0))) | ||
| 1795 | (push (if string-dir (concat string-dir file) file) | ||
| 1796 | names-sans-suffix))))) | ||
| 1797 | ;; If there is just one file, don't duplicate it with suffixes, | ||
| 1798 | ;; so `Info-read-node-name-1' will be able to complete a single | ||
| 1799 | ;; candidate and to add the terminating ")". | ||
| 1800 | (if (and (= (length names) 1) (= (length names-sans-suffix) 1)) | ||
| 1801 | (setq names names-sans-suffix) | ||
| 1802 | (setq names (append names-sans-suffix names))) | ||
| 1803 | (complete-with-action action names string pred))) | ||
| 1804 | 1785 | ||
| 1805 | (defun Info-read-node-name-1 (string predicate code) | 1786 | (defun Info-read-node-name-1 (string predicate code) |
| 1806 | "Internal function used by `Info-read-node-name'. | 1787 | "Internal function used by `Info-read-node-name'. |