aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2006-04-18 17:33:33 +0000
committerStefan Monnier2006-04-18 17:33:33 +0000
commit8d85a56561fbb7d30248ea30e36d2ad6f2a7e08b (patch)
tree8a9fe98afddd8a40a229273ed34739622752248c
parent1122736087465ac2256b591b17d04bda7ea40cb5 (diff)
downloademacs-8d85a56561fbb7d30248ea30e36d2ad6f2a7e08b.tar.gz
emacs-8d85a56561fbb7d30248ea30e36d2ad6f2a7e08b.zip
(partial-completion-mode): Use 'choose-completion-string-functions to make
sure that choose-completion fills the minibuffer properly. (PC-old-read-file-name-internal): Remove. (PC-read-include-file-name-internal): Remove. Turn it into an advice of read-file-name-internal. (partial-completion-mode): Enable/disable this advice.
-rw-r--r--lisp/ChangeLog14
-rw-r--r--lisp/complete.el66
2 files changed, 51 insertions, 29 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 45c3b9a5d43..22f9e768270 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12006-04-18 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * complete.el (partial-completion-mode):
4 Use 'choose-completion-string-functions to make sure that
5 choose-completion fills the minibuffer properly.
6
7 * complete.el (PC-old-read-file-name-internal): Remove.
8 (PC-read-include-file-name-internal): Remove. Turn it into an advice
9 of read-file-name-internal.
10 (partial-completion-mode): Enable/disable this advice.
11
12006-04-18 Juanma Barranquero <lekktu@gmail.com> 122006-04-18 Juanma Barranquero <lekktu@gmail.com>
2 13
3 * net/tramp.el (tramp-completion-file-name-handler): Revert change 14 * net/tramp.el (tramp-completion-file-name-handler): Revert change
@@ -30,8 +41,7 @@
30 Sync with Tramp 2.0.53. 41 Sync with Tramp 2.0.53.
31 42
32 * net/tramp.el (tramp-completion-mode): ?\t has event-modifier 43 * net/tramp.el (tramp-completion-mode): ?\t has event-modifier
33 'control. Reported by Matthias F,bv(Brste 44 'control. Reported by Matthias F,bv(Brste <slashdevslashnull@gmx.net>.
34 <slashdevslashnull@gmx.net>.
35 (tramp-completion-file-name-handler): Add autoload cookie for 45 (tramp-completion-file-name-handler): Add autoload cookie for
36 adding to `file-name-handler-alist'. 46 adding to `file-name-handler-alist'.
37 47
diff --git a/lisp/complete.el b/lisp/complete.el
index a50d02c41f0..6620db860c3 100644
--- a/lisp/complete.el
+++ b/lisp/complete.el
@@ -141,8 +141,6 @@ If nil, means use the colon-separated path in the variable $INCPATH instead."
141 "A list of the environment variable names and values.") 141 "A list of the environment variable names and values.")
142 142
143 143
144(defvar PC-old-read-file-name-internal nil)
145
146(defun PC-bindings (bind) 144(defun PC-bindings (bind)
147 (let ((completion-map minibuffer-local-completion-map) 145 (let ((completion-map minibuffer-local-completion-map)
148 (must-match-map minibuffer-local-must-match-map)) 146 (must-match-map minibuffer-local-must-match-map))
@@ -219,21 +217,32 @@ second TAB brings up the `*Completions*' buffer."
219 ((not PC-disable-includes) 217 ((not PC-disable-includes)
220 (add-hook 'find-file-not-found-functions 'PC-look-for-include-file))) 218 (add-hook 'find-file-not-found-functions 'PC-look-for-include-file)))
221 ;; ... with some underhand redefining. 219 ;; ... with some underhand redefining.
222 (cond ((and (not partial-completion-mode) 220 (cond ((not partial-completion-mode)
223 (functionp PC-old-read-file-name-internal)) 221 (ad-disable-advice 'read-file-name-internal 'around 'PC-include-file)
224 (fset 'read-file-name-internal PC-old-read-file-name-internal)) 222 (ad-activate 'read-file-name-internal))
225 ((and (not PC-disable-includes) (not PC-old-read-file-name-internal)) 223 ((not PC-disable-includes)
226 (setq PC-old-read-file-name-internal 224 (ad-enable-advice 'read-file-name-internal 'around 'PC-include-file)
227 (symbol-function 'read-file-name-internal)) 225 (ad-activate 'read-file-name-internal)))
228 (fset 'read-file-name-internal 226 ;; Adjust the completion selection in *Completion* buffers to the way
229 'PC-read-include-file-name-internal))) 227 ;; we work. The default minibuffer completion code only completes the
230 (when (and partial-completion-mode (null PC-env-vars-alist)) 228 ;; text before point and leaves the text after point alone (new in
231 (setq PC-env-vars-alist 229 ;; Emacs-22). In contrast we use the whole text and we even sometimes
232 (mapcar (lambda (string) 230 ;; move point to a place before EOB, to indicate the first position where
233 (let ((d (string-match "=" string))) 231 ;; there's a difference, so when the user uses choose-completion, we have
234 (cons (concat "$" (substring string 0 d)) 232 ;; to trick choose-completion into replacing the whole minibuffer text
235 (and d (substring string (1+ d)))))) 233 ;; rather than only the text before point. --Stef
236 process-environment)))) 234 (funcall
235 (if partial-completion-mode 'add-hook 'remove-hook)
236 'choose-completion-string-functions
237 (lambda (&rest x) (goto-char (point-max)) nil))
238 ;; Build the env-completion and mapping table.
239 (when (and partial-completion-mode (null PC-env-vars-alist))
240 (setq PC-env-vars-alist
241 (mapcar (lambda (string)
242 (let ((d (string-match "=" string)))
243 (cons (concat "$" (substring string 0 d))
244 (and d (substring string (1+ d))))))
245 process-environment))))
237 246
238 247
239(defun PC-complete () 248(defun PC-complete ()
@@ -930,20 +939,23 @@ absolute rather than relative to some directory on the SEARCH-PATH."
930 (setq sorted (cdr sorted))) 939 (setq sorted (cdr sorted)))
931 compressed)))) 940 compressed))))
932 941
933(defun PC-read-include-file-name-internal (string dir action) 942(defadvice read-file-name-internal (around PC-include-file disable)
934 (if (string-match "<\\([^\"<>]*\\)>?$" string) 943 (if (string-match "<\\([^\"<>]*\\)>?\\'" (ad-get-arg 0))
935 (let* ((name (substring string (match-beginning 1) (match-end 1))) 944 (let* ((string (ad-get-arg 0))
945 (action (ad-get-arg 2))
946 (name (substring string (match-beginning 1) (match-end 1)))
936 (str2 (substring string (match-beginning 0))) 947 (str2 (substring string (match-beginning 0)))
937 (completion-table 948 (completion-table
938 (mapcar (function (lambda (x) (list (format "<%s>" x)))) 949 (mapcar (lambda (x) (format "<%s>" x))
939 (PC-include-file-all-completions 950 (PC-include-file-all-completions
940 name (PC-include-file-path))))) 951 name (PC-include-file-path)))))
941 (cond 952 (setq ad-return-value
942 ((not completion-table) nil) 953 (cond
943 ((eq action nil) (try-completion str2 completion-table nil)) 954 ((not completion-table) nil)
944 ((eq action t) (all-completions str2 completion-table nil)) 955 ((eq action 'lambda) (test-completion str2 completion-table nil))
945 ((eq action 'lambda) (test-completion str2 completion-table nil)))) 956 ((eq action nil) (try-completion str2 completion-table nil))
946 (funcall PC-old-read-file-name-internal string dir action))) 957 ((eq action t) (all-completions str2 completion-table nil)))))
958 ad-do-it))
947 959
948 960
949(provide 'complete) 961(provide 'complete)