summaryrefslogtreecommitdiff
path: root/lisp/eshell/em-cmpl.el
diff options
context:
space:
mode:
authorJim Porter <jporterbugs@gmail.com>2022-11-08 22:49:23 -0800
committerJim Porter <jporterbugs@gmail.com>2022-12-15 21:41:03 -0800
commite63ef66c57ee74b24998a16b34949f67bbb73d8d (patch)
treed41fe6c0405a02f78f025284a245e1c4735a6a1b /lisp/eshell/em-cmpl.el
parent66ac920b0c233e472c7f54d108503dfe9236d3c0 (diff)
Add support for the "splice operator" in Eshell
This allows splicing lists in-place in argument lists, which is particularly important when defining aliases using the '$*' special variable (bug#59960). * lisp/eshell/esh-var.el (eshell-parse-variable): Add support for the splice operator. (eshell-interpolate-variable): Let 'eshell-parse-variable' handle adding 'eshell-escape-arg'. (eshell-complete-variable-reference): Handle the splice operator. * lisp/eshell/esh-arg.el (eshell-concat-groups) (eshell-prepare-splice): New functions... (eshell-resolve-current-argument): ... use them. (eshell-splice-args): New function. * lisp/eshell/esh-cmd.el (eshell-rewrite-named-command): Handle 'eshell-splice-args'. * lisp/eshell/esh-util.el (eshell-list-to-string): New function... (eshell-flatten-and-stringify): ... use it. * lisp/eshell/em-cmpl.el (eshell-complete-parse-arguments): Remove 'eshell-splice-args' sigils in Eshell command forms so that we can perform completion on splice-expansions. * lisp/eshell/em-unix.el (eshell-complete-host-reference): Don't try to complete arguments containing "$@". * test/lisp/eshell/esh-var-tets.el (esh-var-test/interp-list-var) (esh-var-test/interp-list-var-concat, esh-var-test/interp-var-splice) (esh-var-test/interp-var-splice-concat) (esh-var-test/quoted-interp-list-var) (esh-var-test/quoted-interp-list-var-concat) (esh-var-test/quoted-interp-var-splice) (esh-var-test/quoted-interp-var-splice-concat): New tests. * test/lisp/eshell/em-alias-tests.el (em-alias-test/alias-all-args-var-splice): New test. * doc/misc/eshell.texi (Dollars Expansion): Explain the splice operator. (Aliases): Expand documentation and use '$@*'. (Built-ins, Bugs and Ideas): Use '$@*' where appropriate. * etc/NEWS: Announce this change.
Diffstat (limited to 'lisp/eshell/em-cmpl.el')
-rw-r--r--lisp/eshell/em-cmpl.el26
1 files changed, 16 insertions, 10 deletions
diff --git a/lisp/eshell/em-cmpl.el b/lisp/eshell/em-cmpl.el
index ac82e3f225c..2c721eb9e31 100644
--- a/lisp/eshell/em-cmpl.el
+++ b/lisp/eshell/em-cmpl.el
@@ -342,17 +342,23 @@ to writing a completion function."
(setq pos (1+ pos))))
(setq posns (cdr posns))
(cl-assert (= (length args) (length posns)))
- (let ((a args)
- (i 0)
- l)
+ (let ((a args) (i 0) new-start)
(while a
- (if (and (consp (car a))
- (eq (caar a) 'eshell-operator))
- (setq l i))
- (setq a (cdr a) i (1+ i)))
- (and l
- (setq args (nthcdr (1+ l) args)
- posns (nthcdr (1+ l) posns))))
+ ;; Remove any top-level `eshell-splice-args' sigils. These
+ ;; are meant to be rewritten and can't actually be called.
+ (when (and (consp (car a))
+ (eq (caar a) 'eshell-splice-args))
+ (setcar a (cadar a)))
+ ;; If there's an unreplaced `eshell-operator' sigil, consider
+ ;; the token after it the new start of our arguments.
+ (when (and (consp (car a))
+ (eq (caar a) 'eshell-operator))
+ (setq new-start i))
+ (setq a (cdr a)
+ i (1+ i)))
+ (when new-start
+ (setq args (nthcdr (1+ new-start) args)
+ posns (nthcdr (1+ new-start) posns))))
(cl-assert (= (length args) (length posns)))
(when (and args (eq (char-syntax (char-before end)) ? )
(not (eq (char-before (1- end)) ?\\)))