diff options
author | Dmitry Gutov <dgutov@yandex.ru> | 2018-12-29 02:13:54 +0200 |
---|---|---|
committer | Dmitry Gutov <dgutov@yandex.ru> | 2018-12-29 02:15:35 +0200 |
commit | 8f9d93f3054a5a99a760101fa81a013c67d52f58 (patch) | |
tree | 315f9a8f7ae1bba00680771864a643afb0068da8 /lisp | |
parent | cf62106878ef76592a90fbe584927003b5420f99 (diff) | |
download | emacs-8f9d93f3054a5a99a760101fa81a013c67d52f58.tar.gz |
project-find-file: Move the common parent directory to the prompt
* lisp/progmodes/project.el (project--completing-read-strict):
Extract the common parent directory of all files first
(https://lists.gnu.org/archive/html/emacs-devel/2018-12/msg00444.html).
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/progmodes/project.el | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index f3f29cbac94..628694450fa 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -401,23 +401,38 @@ recognized." ;; removing it when it has no matches. Neither seems natural ;; enough. Removal is confusing; early expansion makes the prompt ;; too long. - (let* (;; (initial-input - ;; (let ((common-prefix (try-completion "" collection))) - ;; (if (> (length common-prefix) 0) - ;; (file-name-directory common-prefix)))) + (let* ((common-parent-directory + (let ((common-prefix (try-completion "" collection))) + (if (> (length common-prefix) 0) + (file-name-directory common-prefix)))) + (cpd-length (length common-parent-directory)) + (prompt (if (zerop cpd-length) + prompt + (concat prompt (format " in %s" common-parent-directory)))) + ;; XXX: This requires collection to be "flat" as well. + (substrings (mapcar (lambda (s) (substring s cpd-length)) + (all-completions "" collection))) + (new-collection + (lambda (string pred action) + (cond + ((eq action 'metadata) + (if (functionp collection) (funcall collection nil nil 'metadata))) + (t + (complete-with-action action substrings string pred))))) (new-prompt (if default (format "%s (default %s): " prompt default) (format "%s: " prompt))) (res (completing-read new-prompt - collection predicate t + new-collection predicate t nil ;; initial-input hist default inherit-input-method))) - (if (and (equal res default) - (not (test-completion res collection predicate))) - (completing-read (format "%s: " prompt) - collection predicate t res hist nil - inherit-input-method) - res))) + (when (and (equal res default) + (not (test-completion res collection predicate))) + (setq res + (completing-read (format "%s: " prompt) + new-collection predicate t res hist nil + inherit-input-method))) + (concat common-parent-directory res))) (declare-function multifile-continue "multifile" ()) |