Commit d86d2721 authored by Stefan Monnier's avatar Stefan Monnier

First step towards using standard completion in comint.

* lisp/minibuffer.el (completion--flush-all-sorted-completions):
Remove itself from hook.
(completion-at-point): Let the functions perform the completion
immediately and return nil or t.
* lisp/comint.el (comint-dynamic-complete-functions): Now identical to
completion-at-point-functions.
(comint-dynamic-list-input-ring): Remove unused var `index'.
(comint--match-partial-filename, comint--unquote&expand-filename):
New funs, split from comint-match-partial-filename.
(comint-dynamic-complete): Use completion-at-point.
(comint-dynamic-complete-filename): Use comint--match-partial-filename.
parent e8974c48
2011-03-24 Stefan Monnier <monnier@iro.umontreal.ca>
* minibuffer.el (completion--flush-all-sorted-completions):
Remove itself from hook.
(completion-at-point): Let the functions perform the completion
immediately and return nil or t.
* comint.el (comint-dynamic-complete-functions): Now identical to
completion-at-point-functions.
(comint-dynamic-list-input-ring): Remove unused var `index'.
(comint--match-partial-filename, comint--unquote&expand-filename):
New funs, split from comint-match-partial-filename.
(comint-dynamic-complete): Use completion-at-point.
(comint-dynamic-complete-filename): Use comint--match-partial-filename.
2011-03-24 Drew Adams <drew.adams@oracle.com> 2011-03-24 Drew Adams <drew.adams@oracle.com>
* thingatpt.el: Support `defun'. * thingatpt.el: Support `defun'.
...@@ -52,8 +66,8 @@ ...@@ -52,8 +66,8 @@
(provide-theme): Ignore custom--inhibit-theme-enable. (provide-theme): Ignore custom--inhibit-theme-enable.
(load-theme): Enable the theme explicitly if NO-ENABLE is non-nil. (load-theme): Enable the theme explicitly if NO-ENABLE is non-nil.
(custom-enabling-themes): Delete variable. (custom-enabling-themes): Delete variable.
(enable-theme): Accept only loaded themes as arguments. Ignore (enable-theme): Accept only loaded themes as arguments.
the special custom-enabled-themes variable. Ignore the special custom-enabled-themes variable.
(custom-enabled-themes): Forbid themes from setting this. (custom-enabled-themes): Forbid themes from setting this.
Eliminate use of custom-enabling-themes. Eliminate use of custom-enabling-themes.
(custom-push-theme): Quote "changed" custom var entry. (custom-push-theme): Quote "changed" custom var entry.
...@@ -390,8 +404,8 @@ ...@@ -390,8 +404,8 @@
2011-03-09 Michael Albinus <michael.albinus@gmx.de> 2011-03-09 Michael Albinus <michael.albinus@gmx.de>
* net/tramp-sh.el (tramp-do-copy-or-rename-file-out-of-band): Do * net/tramp-sh.el (tramp-do-copy-or-rename-file-out-of-band):
not use `tramp-file-name-port', because this returns also Do not use `tramp-file-name-port', because this returns also
`tramp-default-port'. `tramp-default-port'.
2011-03-09 Deniz Dogan <deniz.a.m.dogan@gmail.com> 2011-03-09 Deniz Dogan <deniz.a.m.dogan@gmail.com>
...@@ -420,8 +434,8 @@ ...@@ -420,8 +434,8 @@
* emacs-lisp/package.el (package-tar-file-info): Handle also * emacs-lisp/package.el (package-tar-file-info): Handle also
remote files. remote files.
* emacs-lisp/package-x.el (package-upload-buffer-internal): Use * emacs-lisp/package-x.el (package-upload-buffer-internal):
`equal' for upload base check. Use `equal' for upload base check.
2011-03-08 Arni Magnusson <arnima@hafro.is> (tiny change) 2011-03-08 Arni Magnusson <arnima@hafro.is> (tiny change)
...@@ -750,9 +764,9 @@ ...@@ -750,9 +764,9 @@
2011-03-03 Christian Ohler <ohler@gnu.org> 2011-03-03 Christian Ohler <ohler@gnu.org>
* emacs-lisp/ert.el (ert--explain-equal): New function. * emacs-lisp/ert.el (ert--explain-equal): New function.
(ert--explain-equal-rec): Renamed from `ert--explain-not-equal'. (ert--explain-equal-rec): Rename from `ert--explain-not-equal'.
All callers changed. All callers changed.
(ert--explain-equal-including-properties): Renamed from (ert--explain-equal-including-properties): Rename from
`ert--explain-not-equal-including-properties'. All callers `ert--explain-not-equal-including-properties'. All callers
changed. changed.
...@@ -8275,8 +8289,8 @@ ...@@ -8275,8 +8289,8 @@
Sync with Tramp 2.1.19. Sync with Tramp 2.1.19.
* net/tramp-gvfs.el (tramp-gvfs-handle-write-region): Protect * net/tramp-gvfs.el (tramp-gvfs-handle-write-region):
deleting tmpfile. Protect deleting tmpfile.
(tramp-gvfs-maybe-open-connection): Use `tramp-compat-funcall'. (tramp-gvfs-maybe-open-connection): Use `tramp-compat-funcall'.
* net/tramp.el (tramp-handle-expand-file-name) * net/tramp.el (tramp-handle-expand-file-name)
...@@ -10554,8 +10568,8 @@ ...@@ -10554,8 +10568,8 @@
* net/tramp-ftp.el (tramp-ftp-file-name-handler): * net/tramp-ftp.el (tramp-ftp-file-name-handler):
Use `delete-file' instead of `tramp-compat-delete-file'. Use `delete-file' instead of `tramp-compat-delete-file'.
* net/tramp-gvfs.el (tramp-gvfs-handle-write-region): Use * net/tramp-gvfs.el (tramp-gvfs-handle-write-region):
`delete-file' instead of `tramp-compat-delete-file'. Use `delete-file' instead of `tramp-compat-delete-file'.
* net/tramp-imap.el (tramp-imap-do-copy-or-rename-file): * net/tramp-imap.el (tramp-imap-do-copy-or-rename-file):
Use `delete-file' instead of `tramp-compat-delete-file'. Use `delete-file' instead of `tramp-compat-delete-file'.
......
...@@ -368,7 +368,7 @@ text matching `comint-prompt-regexp', depending on the value of ...@@ -368,7 +368,7 @@ text matching `comint-prompt-regexp', depending on the value of
(defvar comint-dynamic-complete-functions (defvar comint-dynamic-complete-functions
'(comint-replace-by-expanded-history comint-dynamic-complete-filename) '(comint-replace-by-expanded-history comint-dynamic-complete-filename)
"List of functions called to perform completion. "List of functions called to perform completion.
Functions should return non-nil if completion was performed. Works like `completion-at-point-functions'.
See also `comint-dynamic-complete'. See also `comint-dynamic-complete'.
This is a good thing to set in mode hooks.") This is a good thing to set in mode hooks.")
...@@ -1008,7 +1008,6 @@ See also `comint-read-input-ring'." ...@@ -1008,7 +1008,6 @@ See also `comint-read-input-ring'."
(message "No history") (message "No history")
(let ((history nil) (let ((history nil)
(history-buffer " *Input History*") (history-buffer " *Input History*")
(index (1- (ring-length comint-input-ring)))
(conf (current-window-configuration))) (conf (current-window-configuration)))
;; We have to build up a list ourselves from the ring vector. ;; We have to build up a list ourselves from the ring vector.
(dotimes (index (ring-length comint-input-ring)) (dotimes (index (ring-length comint-input-ring))
...@@ -2946,13 +2945,22 @@ interpreter (e.g., the percent notation of cmd.exe on NT)." ...@@ -2946,13 +2945,22 @@ interpreter (e.g., the percent notation of cmd.exe on NT)."
(setq name (replace-match env-var-val t t name)))))) (setq name (replace-match env-var-val t t name))))))
name)) name))
(defun comint--match-partial-filename ()
"Return the filename at point as-is, or nil if none is found.
See `comint-word'."
(comint-word comint-file-name-chars))
(defun comint--unquote&expand-filename (filename)
;; FIXME: The code below does unquote-then-expand which means that "\\$HOME"
;; gets expanded to the same as "$HOME"
(comint-substitute-in-file-name
(comint-unquote-filename filename)))
(defun comint-match-partial-filename () (defun comint-match-partial-filename ()
"Return the filename at point, or nil if none is found. "Return the unquoted&expanded filename at point, or nil if none is found.
Environment variables are substituted. See `comint-word'." Environment variables are substituted. See `comint-word'."
(let ((filename (comint-word comint-file-name-chars))) (let ((filename (comint--match-partial-filename)))
(and filename (comint-substitute-in-file-name (and filename (comint--unquote&expand-filename filename))))
(comint-unquote-filename filename)))))
(defun comint-quote-filename (filename) (defun comint-quote-filename (filename)
"Return FILENAME with magic characters quoted. "Return FILENAME with magic characters quoted.
...@@ -2987,13 +2995,13 @@ Calls the functions in `comint-dynamic-complete-functions' to perform ...@@ -2987,13 +2995,13 @@ Calls the functions in `comint-dynamic-complete-functions' to perform
completion until a function returns non-nil, at which point completion is completion until a function returns non-nil, at which point completion is
assumed to have occurred." assumed to have occurred."
(interactive) (interactive)
(run-hook-with-args-until-success 'comint-dynamic-complete-functions)) (let ((completion-at-point-functions comint-dynamic-complete-functions))
(completion-at-point)))
(defun comint-dynamic-complete-filename () (defun comint-dynamic-complete-filename ()
"Dynamically complete the filename at point. "Dynamically complete the filename at point.
Completes if after a filename. See `comint-match-partial-filename' and Completes if after a filename.
`comint-dynamic-complete-as-filename'.
This function is similar to `comint-replace-by-expanded-filename', except that This function is similar to `comint-replace-by-expanded-filename', except that
it won't change parts of the filename already entered in the buffer; it just it won't change parts of the filename already entered in the buffer; it just
adds completion characters to the end of the filename. A completions listing adds completion characters to the end of the filename. A completions listing
...@@ -3005,7 +3013,7 @@ completions listing is dependent on the value of `comint-completion-autolist'. ...@@ -3005,7 +3013,7 @@ completions listing is dependent on the value of `comint-completion-autolist'.
Returns t if successful." Returns t if successful."
(interactive) (interactive)
(when (comint-match-partial-filename) (when (comint--match-partial-filename)
(unless (window-minibuffer-p (selected-window)) (unless (window-minibuffer-p (selected-window))
(message "Completing file name...")) (message "Completing file name..."))
(comint-dynamic-complete-as-filename))) (comint-dynamic-complete-as-filename)))
...@@ -3021,18 +3029,12 @@ See `comint-dynamic-complete-filename'. Returns t if successful." ...@@ -3021,18 +3029,12 @@ See `comint-dynamic-complete-filename'. Returns t if successful."
;;(file-name-handler-alist nil) ;;(file-name-handler-alist nil)
(minibuffer-p (window-minibuffer-p (selected-window))) (minibuffer-p (window-minibuffer-p (selected-window)))
(success t) (success t)
(dirsuffix (cond ((not comint-completion-addsuffix) (dirsuffix (cond ((not comint-completion-addsuffix) "")
"") ((not (consp comint-completion-addsuffix)) "/")
((not (consp comint-completion-addsuffix)) (t (car comint-completion-addsuffix))))
"/") (filesuffix (cond ((not comint-completion-addsuffix) "")
(t ((not (consp comint-completion-addsuffix)) " ")
(car comint-completion-addsuffix)))) (t (cdr comint-completion-addsuffix))))
(filesuffix (cond ((not comint-completion-addsuffix)
"")
((not (consp comint-completion-addsuffix))
" ")
(t
(cdr comint-completion-addsuffix))))
(filename (comint-match-partial-filename)) (filename (comint-match-partial-filename))
(filename-beg (if filename (match-beginning 0) (point))) (filename-beg (if filename (match-beginning 0) (point)))
(filename-end (if filename (match-end 0) (point))) (filename-end (if filename (match-end 0) (point)))
......
...@@ -688,6 +688,8 @@ scroll the window of possible completions." ...@@ -688,6 +688,8 @@ scroll the window of possible completions."
(t t))))) (t t)))))
(defun completion--flush-all-sorted-completions (&rest ignore) (defun completion--flush-all-sorted-completions (&rest ignore)
(remove-hook 'after-change-functions
'completion--flush-all-sorted-completions t)
(setq completion-cycling nil) (setq completion-cycling nil)
(setq completion-all-sorted-completions nil)) (setq completion-all-sorted-completions nil))
...@@ -1242,6 +1244,8 @@ Point needs to be somewhere between START and END." ...@@ -1242,6 +1244,8 @@ Point needs to be somewhere between START and END."
(assert (<= start (point)) (<= (point) end)) (assert (<= start (point)) (<= (point) end))
;; FIXME: undisplay the *Completions* buffer once the completion is done. ;; FIXME: undisplay the *Completions* buffer once the completion is done.
(with-wrapper-hook (with-wrapper-hook
;; FIXME: Maybe we should use this hook to provide a "display
;; completions" operation as well.
completion-in-region-functions (start end collection predicate) completion-in-region-functions (start end collection predicate)
(let ((minibuffer-completion-table collection) (let ((minibuffer-completion-table collection)
(minibuffer-completion-predicate predicate) (minibuffer-completion-predicate predicate)
...@@ -1253,7 +1257,9 @@ Point needs to be somewhere between START and END." ...@@ -1253,7 +1257,9 @@ Point needs to be somewhere between START and END."
(defvar completion-at-point-functions '(tags-completion-at-point-function) (defvar completion-at-point-functions '(tags-completion-at-point-function)
"Special hook to find the completion table for the thing at point. "Special hook to find the completion table for the thing at point.
It is called without any argument and should return either nil, Each function on this hook is called in turns without any argument and should
return either nil to mean that it is not applicable at point,
or t to mean that it already performed completion (discouraged),
or a function of no argument to perform completion (discouraged), or a function of no argument to perform completion (discouraged),
or a list of the form (START END COLLECTION &rest PROPS) where or a list of the form (START END COLLECTION &rest PROPS) where
START and END delimit the entity to complete and should include point, START and END delimit the entity to complete and should include point,
...@@ -1271,7 +1277,7 @@ The completion method is determined by `completion-at-point-functions'." ...@@ -1271,7 +1277,7 @@ The completion method is determined by `completion-at-point-functions'."
'completion-at-point-functions))) 'completion-at-point-functions)))
(cond (cond
((functionp res) (funcall res)) ((functionp res) (funcall res))
(res ((consp res)
(let* ((plist (nthcdr 3 res)) (let* ((plist (nthcdr 3 res))
(start (nth 0 res)) (start (nth 0 res))
(end (nth 1 res)) (end (nth 1 res))
...@@ -1279,7 +1285,8 @@ The completion method is determined by `completion-at-point-functions'." ...@@ -1279,7 +1285,8 @@ The completion method is determined by `completion-at-point-functions'."
(or (plist-get plist :annotation-function) (or (plist-get plist :annotation-function)
completion-annotate-function))) completion-annotate-function)))
(completion-in-region start end (nth 2 res) (completion-in-region start end (nth 2 res)
(plist-get plist :predicate))))))) (plist-get plist :predicate))))
(res)))) ;Maybe completion already happened and the function returned t.
;;; Key bindings. ;;; Key bindings.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment