diff options
| author | Stefan Monnier | 2010-08-19 23:21:21 +0200 |
|---|---|---|
| committer | Stefan Monnier | 2010-08-19 23:21:21 +0200 |
| commit | 118cf45490e054aa813300e101650021b63cbb93 (patch) | |
| tree | bd0a078b96103aa206545cf62db1961b7c774cfa /lisp | |
| parent | 926cd98cf11c307a3cce8c4fd963e1af719acd8d (diff) | |
| download | emacs-118cf45490e054aa813300e101650021b63cbb93.tar.gz emacs-118cf45490e054aa813300e101650021b63cbb93.zip | |
* lisp/files.el (locate-file-completion-table): Only list the .el and .elc
extensions if there's no other choice.
Fixes: debbugs:5955
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 3 | ||||
| -rw-r--r-- | lisp/files.el | 45 |
2 files changed, 37 insertions, 11 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 62d61759aa7..ced3cf2dfa4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | 2010-08-19 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2010-08-19 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * files.el (locate-file-completion-table): Only list the .el and .elc | ||
| 4 | extensions if there's no other choice (bug#5955). | ||
| 5 | |||
| 3 | * facemenu.el (facemenu-self-insert-data): New var. | 6 | * facemenu.el (facemenu-self-insert-data): New var. |
| 4 | (facemenu-post-self-insert-function, facemenu-set-self-insert-face): | 7 | (facemenu-post-self-insert-function, facemenu-set-self-insert-face): |
| 5 | New functions. | 8 | New functions. |
diff --git a/lisp/files.el b/lisp/files.el index 8b131e04ebc..9a07509ed8b 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -757,21 +757,44 @@ one or more of those symbols." | |||
| 757 | (let ((x (file-name-directory suffix))) | 757 | (let ((x (file-name-directory suffix))) |
| 758 | (if x (1- (length x)) (length suffix)))))) | 758 | (if x (1- (length x)) (length suffix)))))) |
| 759 | (t | 759 | (t |
| 760 | (let ((names nil) | 760 | (let ((names '()) |
| 761 | ;; If we have files like "foo.el" and "foo.elc", we could load one of | ||
| 762 | ;; them with "foo.el", "foo.elc", or "foo", where just "foo" is the | ||
| 763 | ;; preferred way. So if we list all 3, that gives a lot of redundant | ||
| 764 | ;; entries for the poor soul looking just for "foo". OTOH, sometimes | ||
| 765 | ;; the user does want to pay attention to the extension. We try to | ||
| 766 | ;; diffuse this tension by stripping the suffix, except when the | ||
| 767 | ;; result is a single element (i.e. usually we only list "foo" unless | ||
| 768 | ;; it's the only remaining element in the list, in which case we do | ||
| 769 | ;; list "foo", "foo.elc" and "foo.el"). | ||
| 770 | (fullnames '()) | ||
| 761 | (suffix (concat (regexp-opt suffixes t) "\\'")) | 771 | (suffix (concat (regexp-opt suffixes t) "\\'")) |
| 762 | (string-dir (file-name-directory string)) | 772 | (string-dir (file-name-directory string)) |
| 763 | (string-file (file-name-nondirectory string))) | 773 | (string-file (file-name-nondirectory string))) |
| 764 | (dolist (dir dirs) | 774 | (dolist (dir dirs) |
| 765 | (unless dir | 775 | (unless dir |
| 766 | (setq dir default-directory)) | 776 | (setq dir default-directory)) |
| 767 | (if string-dir (setq dir (expand-file-name string-dir dir))) | 777 | (if string-dir (setq dir (expand-file-name string-dir dir))) |
| 768 | (when (file-directory-p dir) | 778 | (when (file-directory-p dir) |
| 769 | (dolist (file (file-name-all-completions | 779 | (dolist (file (file-name-all-completions |
| 770 | string-file dir)) | 780 | string-file dir)) |
| 771 | (push file names) | 781 | (if (not (string-match suffix file)) |
| 772 | (when (string-match suffix file) | 782 | (push file names) |
| 773 | (setq file (substring file 0 (match-beginning 0))) | 783 | (push file fullnames) |
| 774 | (push file names))))) | 784 | (push (substring file 0 (match-beginning 0)) names))))) |
| 785 | ;; Switching from names to names+fullnames creates a non-monotonicity | ||
| 786 | ;; which can cause problems with things like partial-completion. | ||
| 787 | ;; To minimize the problem, filter out completion-regexp-list, so that | ||
| 788 | ;; M-x load-library RET t/x.e TAB finds some files. | ||
| 789 | (if completion-regexp-list | ||
| 790 | (setq names (all-completions "" names))) | ||
| 791 | ;; Remove duplicates of the first element, so that we can easily check | ||
| 792 | ;; if `names' really only contains a single element. | ||
| 793 | (when (cdr names) (setcdr names (delete (car names) (cdr names)))) | ||
| 794 | (unless (cdr names) | ||
| 795 | ;; There's no more than one matching non-suffixed element, so expand | ||
| 796 | ;; the list by adding the suffixed elements as well. | ||
| 797 | (setq names (nconc names fullnames))) | ||
| 775 | (completion-table-with-context | 798 | (completion-table-with-context |
| 776 | string-dir names string-file pred action))))) | 799 | string-dir names string-file pred action))))) |
| 777 | 800 | ||