summaryrefslogtreecommitdiff
path: root/lisp/eshell/em-cmpl.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2022-03-18 11:59:32 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2022-03-18 11:59:32 -0400
commitce28de5d3a1293ceaf4317520ec8c3d2095ab947 (patch)
treefee494d06643e8e03a8b5bf6f01f31d121cf12b1 /lisp/eshell/em-cmpl.el
parentf51e12feceae18f0b6715142a4e61d6522f79389 (diff)
downloademacs-ce28de5d3a1293ceaf4317520ec8c3d2095ab947.tar.gz
Pcomplete: Better obey `completion-at-point-functions`
Functions on `completion-at-point-functions` should not modify the buffer. Pcomplete itself mostly abides by this but Eshell's use of it doesn't. Try and catch those cases. Also fix one of those cases. * lisp/pcomplete.el (pcomplete-allow-modifications): New var. (pcomplete-completions-at-point): Enforce it. (pcomplete, pcomplete-expand-and-complete, pcomplete-expand): Rebind it since these commands expect the extra side effects. * lisp/eshell/em-cmpl.el (eshell--pcomplete-insert-tab): New function, extracted from `eshell-complete-parse-arguments`. (eshell-complete-parse-arguments): Use it and obey `pcomplete-allow-modifications`.
Diffstat (limited to 'lisp/eshell/em-cmpl.el')
-rw-r--r--lisp/eshell/em-cmpl.el23
1 files changed, 13 insertions, 10 deletions
diff --git a/lisp/eshell/em-cmpl.el b/lisp/eshell/em-cmpl.el
index b79475f6e07..f4c1302629b 100644
--- a/lisp/eshell/em-cmpl.el
+++ b/lisp/eshell/em-cmpl.el
@@ -311,18 +311,24 @@ to writing a completion function."
(describe-prefix-bindings)
(call-interactively 'pcomplete-help)))
+(defun eshell--pcomplete-insert-tab ()
+ (if (not pcomplete-allow-modifications)
+ (throw 'pcompleted nil)
+ (insert-and-inherit "\t")
+ (throw 'pcompleted t)))
+
(defun eshell-complete-parse-arguments ()
"Parse the command line arguments for `pcomplete-argument'."
(when (and eshell-no-completion-during-jobs
(eshell-interactive-process-p))
- (insert-and-inherit "\t")
- (throw 'pcompleted t))
+ (eshell--pcomplete-insert-tab))
(let ((end (point-marker))
(begin (save-excursion (eshell-bol) (point)))
(posns (list t))
args delim)
- (when (memq this-command '(pcomplete-expand
- pcomplete-expand-and-complete))
+ (when (and pcomplete-allow-modifications
+ (memq this-command '(pcomplete-expand
+ pcomplete-expand-and-complete)))
(run-hook-with-args 'eshell-expand-input-functions begin end)
(if (= begin end)
(end-of-line))
@@ -335,14 +341,11 @@ to writing a completion function."
(setq begin (1+ (cadr delim))
args (eshell-parse-arguments begin end)))
((eq (car delim) ?\()
- (eshell-complete-lisp-symbol)
- (throw 'pcompleted t))
+ (throw 'pcompleted (elisp-completion-at-point)))
(t
- (insert-and-inherit "\t")
- (throw 'pcompleted t))))
+ (eshell--pcomplete-insert-tab))))
(when (get-text-property (1- end) 'comment)
- (insert-and-inherit "\t")
- (throw 'pcompleted t))
+ (eshell--pcomplete-insert-tab))
(let ((pos begin))
(while (< pos end)
(if (get-text-property pos 'arg-begin)