# HG changeset patch # User Stefan Monnier # Date 1145381613 0 # Node ID 10e0b8ee99930dd4cae2ac21d5da0e96f4217a60 # Parent 900c28bb2ad44b4fc80084f5bc90027db85853d9 (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. diff -r 900c28bb2ad4 -r 10e0b8ee9993 lisp/ChangeLog --- a/lisp/ChangeLog Tue Apr 18 17:27:51 2006 +0000 +++ b/lisp/ChangeLog Tue Apr 18 17:33:33 2006 +0000 @@ -1,3 +1,14 @@ +2006-04-18 Stefan Monnier + + * complete.el (partial-completion-mode): + Use 'choose-completion-string-functions to make sure that + choose-completion fills the minibuffer properly. + + * complete.el (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. + 2006-04-18 Juanma Barranquero * net/tramp.el (tramp-completion-file-name-handler): Revert change @@ -30,8 +41,7 @@ Sync with Tramp 2.0.53. * net/tramp.el (tramp-completion-mode): ?\t has event-modifier - 'control. Reported by Matthias F,bv(Brste - . + 'control. Reported by Matthias F,bv(Brste . (tramp-completion-file-name-handler): Add autoload cookie for adding to `file-name-handler-alist'. diff -r 900c28bb2ad4 -r 10e0b8ee9993 lisp/complete.el --- a/lisp/complete.el Tue Apr 18 17:27:51 2006 +0000 +++ b/lisp/complete.el Tue Apr 18 17:33:33 2006 +0000 @@ -141,8 +141,6 @@ "A list of the environment variable names and values.") -(defvar PC-old-read-file-name-internal nil) - (defun PC-bindings (bind) (let ((completion-map minibuffer-local-completion-map) (must-match-map minibuffer-local-must-match-map)) @@ -219,21 +217,32 @@ ((not PC-disable-includes) (add-hook 'find-file-not-found-functions 'PC-look-for-include-file))) ;; ... with some underhand redefining. - (cond ((and (not partial-completion-mode) - (functionp PC-old-read-file-name-internal)) - (fset 'read-file-name-internal PC-old-read-file-name-internal)) - ((and (not PC-disable-includes) (not PC-old-read-file-name-internal)) - (setq PC-old-read-file-name-internal - (symbol-function 'read-file-name-internal)) - (fset 'read-file-name-internal - 'PC-read-include-file-name-internal))) - (when (and partial-completion-mode (null PC-env-vars-alist)) - (setq PC-env-vars-alist - (mapcar (lambda (string) - (let ((d (string-match "=" string))) - (cons (concat "$" (substring string 0 d)) - (and d (substring string (1+ d)))))) - process-environment)))) + (cond ((not partial-completion-mode) + (ad-disable-advice 'read-file-name-internal 'around 'PC-include-file) + (ad-activate 'read-file-name-internal)) + ((not PC-disable-includes) + (ad-enable-advice 'read-file-name-internal 'around 'PC-include-file) + (ad-activate 'read-file-name-internal))) + ;; Adjust the completion selection in *Completion* buffers to the way + ;; we work. The default minibuffer completion code only completes the + ;; text before point and leaves the text after point alone (new in + ;; Emacs-22). In contrast we use the whole text and we even sometimes + ;; move point to a place before EOB, to indicate the first position where + ;; there's a difference, so when the user uses choose-completion, we have + ;; to trick choose-completion into replacing the whole minibuffer text + ;; rather than only the text before point. --Stef + (funcall + (if partial-completion-mode 'add-hook 'remove-hook) + 'choose-completion-string-functions + (lambda (&rest x) (goto-char (point-max)) nil)) + ;; Build the env-completion and mapping table. + (when (and partial-completion-mode (null PC-env-vars-alist)) + (setq PC-env-vars-alist + (mapcar (lambda (string) + (let ((d (string-match "=" string))) + (cons (concat "$" (substring string 0 d)) + (and d (substring string (1+ d)))))) + process-environment)))) (defun PC-complete () @@ -930,20 +939,23 @@ (setq sorted (cdr sorted))) compressed)))) -(defun PC-read-include-file-name-internal (string dir action) - (if (string-match "<\\([^\"<>]*\\)>?$" string) - (let* ((name (substring string (match-beginning 1) (match-end 1))) +(defadvice read-file-name-internal (around PC-include-file disable) + (if (string-match "<\\([^\"<>]*\\)>?\\'" (ad-get-arg 0)) + (let* ((string (ad-get-arg 0)) + (action (ad-get-arg 2)) + (name (substring string (match-beginning 1) (match-end 1))) (str2 (substring string (match-beginning 0))) (completion-table - (mapcar (function (lambda (x) (list (format "<%s>" x)))) + (mapcar (lambda (x) (format "<%s>" x)) (PC-include-file-all-completions name (PC-include-file-path))))) - (cond - ((not completion-table) nil) - ((eq action nil) (try-completion str2 completion-table nil)) - ((eq action t) (all-completions str2 completion-table nil)) - ((eq action 'lambda) (test-completion str2 completion-table nil)))) - (funcall PC-old-read-file-name-internal string dir action))) + (setq ad-return-value + (cond + ((not completion-table) nil) + ((eq action 'lambda) (test-completion str2 completion-table nil)) + ((eq action nil) (try-completion str2 completion-table nil)) + ((eq action t) (all-completions str2 completion-table nil))))) + ad-do-it)) (provide 'complete)