Commit 047c1b19 authored by Stefan Monnier's avatar Stefan Monnier

* lisp/eshell/em-cmpl.el: Use completion-at-point i.s.o pcomplete

(eshell-cmpl-initialize): Refrain from binding to the `tab` key,
which prevents the tab -> TAB remapping.
Use completion-at-point and completion-help-at-point.
(eshell-complete-commands-list): Use `fboundp` test instead of ugly
gymnastics to try and hide the function call from the compiler.
(eshell-pcomplete): Make it an alias of completion-at-point.

* doc/misc/eshell.texi (Completion): Change wording to reflect
different default behavior.
parent e14c0d74
Pipeline #1027 passed with stage
in 47 minutes and 48 seconds
...@@ -499,15 +499,14 @@ be directories @emph{and} files. Eshell provides predefined completions ...@@ -499,15 +499,14 @@ be directories @emph{and} files. Eshell provides predefined completions
for the built-in functions and some common external commands, and you for the built-in functions and some common external commands, and you
can define your own for any command. can define your own for any command.
Eshell completion also works for lisp forms and glob patterns. If the Eshell completion also works for lisp forms and glob patterns. If the point is
point is on a lisp form, then @key{TAB} will behave similarly to completion on a lisp form, then @key{TAB} will behave similarly to completion in
in @code{elisp-mode} and @code{lisp-interaction-mode}. For glob @code{elisp-mode} and @code{lisp-interaction-mode}. For glob patterns, the
patterns, If there are few enough possible completions of the patterns, pattern will be removed from the input line, and replaced by the
they will be cycled when @key{TAB} is pressed, otherwise it will be removed completion.
from the input line and the possible completions will be listed.
If you want to see the entire list of possible completions (e.g. when it's
If you want to see the entire list of possible completions when it's below the @code{completion-cycle-threshold}), press @kbd{M-?}.
below the cycling threshold, press @kbd{M-?}.
@subsection pcomplete @subsection pcomplete
Pcomplete, short for programmable completion, is the completion Pcomplete, short for programmable completion, is the completion
......
...@@ -985,6 +985,11 @@ default, and not just the opening element. ...@@ -985,6 +985,11 @@ default, and not just the opening element.
** Eshell ** Eshell
*** TAB completion uses the standard completion-at-point rather than pcomplete
Its UI is slightly different but can be customized to behave similarly,
e.g. Pcomplete's default cycling can be obtained with
(setq completion-cycle-threshold 5).
--- ---
*** Expansion of history event designators is disabled by default. *** Expansion of history event designators is disabled by default.
To restore the old behavior, use To restore the old behavior, use
......
...@@ -288,9 +288,10 @@ to writing a completion function." ...@@ -288,9 +288,10 @@ to writing a completion function."
(function (function
(lambda () (lambda ()
(set (make-local-variable 'comint-file-name-quote-list) (set (make-local-variable 'comint-file-name-quote-list)
eshell-special-chars-outside-quoting))) nil t) eshell-special-chars-outside-quoting)))
(add-hook 'pcomplete-quote-arg-hook 'eshell-quote-backslash nil t) nil t)
(define-key eshell-mode-map [(meta tab)] 'eshell-complete-lisp-symbol) (add-hook 'pcomplete-quote-arg-hook #'eshell-quote-backslash nil t)
;;(define-key eshell-mode-map [(meta tab)] 'eshell-complete-lisp-symbol) ; Redundant
(define-key eshell-mode-map [(meta control ?i)] 'eshell-complete-lisp-symbol) (define-key eshell-mode-map [(meta control ?i)] 'eshell-complete-lisp-symbol)
(define-key eshell-command-map [(meta ?h)] 'eshell-completion-help) (define-key eshell-command-map [(meta ?h)] 'eshell-completion-help)
(define-key eshell-command-map [tab] 'pcomplete-expand-and-complete) (define-key eshell-command-map [tab] 'pcomplete-expand-and-complete)
...@@ -298,15 +299,14 @@ to writing a completion function." ...@@ -298,15 +299,14 @@ to writing a completion function."
'pcomplete-expand-and-complete) 'pcomplete-expand-and-complete)
(define-key eshell-command-map [space] 'pcomplete-expand) (define-key eshell-command-map [space] 'pcomplete-expand)
(define-key eshell-command-map [? ] 'pcomplete-expand) (define-key eshell-command-map [? ] 'pcomplete-expand)
(define-key eshell-mode-map [tab] 'eshell-pcomplete) ;;(define-key eshell-mode-map [tab] 'completion-at-point) ;Redundant!
(define-key eshell-mode-map [(control ?i)] 'eshell-pcomplete) (define-key eshell-mode-map [(control ?i)] 'completion-at-point)
(add-hook 'completion-at-point-functions (add-hook 'completion-at-point-functions
#'pcomplete-completions-at-point nil t) #'pcomplete-completions-at-point nil t)
;; jww (1999-10-19): Will this work on anything but X? ;; jww (1999-10-19): Will this work on anything but X?
(if (featurep 'xemacs) (define-key eshell-mode-map
(define-key eshell-mode-map [iso-left-tab] 'pcomplete-reverse) (if (featurep 'xemacs) [iso-left-tab] [backtab]) 'pcomplete-reverse)
(define-key eshell-mode-map [backtab] 'pcomplete-reverse)) (define-key eshell-mode-map [(meta ??)] 'completion-help-at-point))
(define-key eshell-mode-map [(meta ??)] 'pcomplete-list))
(defun eshell-completion-command-name () (defun eshell-completion-command-name ()
"Return the command name, possibly sans globbing." "Return the command name, possibly sans globbing."
...@@ -442,34 +442,24 @@ to writing a completion function." ...@@ -442,34 +442,24 @@ to writing a completion function."
(if glob-name (if glob-name
completions completions
(setq completions (setq completions
(append (and (eshell-using-module 'eshell-alias) (append (if (fboundp 'eshell-alias-completions)
(funcall (symbol-function 'eshell-alias-completions) (eshell-alias-completions filename))
filename))
(eshell-winnow-list (eshell-winnow-list
(mapcar (mapcar
(function (function
(lambda (name) (lambda (name)
(substring name 7))) (substring name 7)))
(all-completions (concat "eshell/" filename) (all-completions (concat "eshell/" filename)
obarray 'functionp)) obarray #'functionp))
nil '(eshell-find-alias-function)) nil '(eshell-find-alias-function))
completions)) completions))
(append (and (or eshell-show-lisp-completions (append (and (or eshell-show-lisp-completions
(and eshell-show-lisp-alternatives (and eshell-show-lisp-alternatives
(null completions))) (null completions)))
(all-completions filename obarray 'functionp)) (all-completions filename obarray #'functionp))
completions))))))) completions)))))))
(defun eshell-pcomplete (&optional interactively) (define-obsolete-function-alias 'eshell-pcomplete #'completion-at-point "27.1")
"Eshell wrapper for `pcomplete'."
(interactive "p")
;; Pretend to be pcomplete so that cycling works (bug#13293).
(setq this-command 'pcomplete)
(condition-case nil
(if interactively
(call-interactively 'pcomplete)
(pcomplete))
(text-read-only (completion-at-point)))) ; Workaround for bug#12838.
(provide 'em-cmpl) (provide 'em-cmpl)
......
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