+2006-04-18 Stefan Monnier <monnier@iro.umontreal.ca>
+
+ * 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 <lekktu@gmail.com>
* net/tramp.el (tramp-completion-file-name-handler): Revert change
Sync with Tramp 2.0.53.
* net/tramp.el (tramp-completion-mode): ?\t has event-modifier
- 'control. Reported by Matthias F\e,bv\e(Brste
- <slashdevslashnull@gmx.net>.
+ 'control. Reported by Matthias F\e,bv\e(Brste <slashdevslashnull@gmx.net>.
(tramp-completion-file-name-handler): Add autoload cookie for
adding to `file-name-handler-alist'.
"A list of the environment variable names and values.")
\f
-(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))
((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))))
\f
(defun PC-complete ()
(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))
\f
(provide 'complete)