From 6f52adf5c1a183bc7e9d79438462df682855bfd6 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Wed, 1 Feb 2023 17:48:37 -0800 Subject: [PATCH 1/3] ; Throw strings as the values for 'eshell-incomplete' This lets us distinguish between cases like "'foo" and "$'foo". * lisp/eshell/em-cmpl.el (eshell-complete-parse-arguments): Use strings when checking the delimiter. * lisp/eshell/em-glob.el (eshell-parse-glob-chars): * lisp/eshell/em-pred.el (eshell-parse-arg-modifier): * lisp/eshell/esh-arg.el (eshell-parse-backslash) (eshell-parse-literal-quote, eshell-parse-double-quote) (eshell-parse-special-reference): * lisp/eshell/esh-cmd.el (eshell-parse-subcommand-argument) (eshell-parse-lisp-argument): * lisp/eshell/esh-var (eshell-parse-variable-ref) (eshell-parse-indices): Throw strings instead of characters. * lisp/eshell/esh-mode.el (eshell-parse-command-input): Print delimiter as a string. --- lisp/eshell/em-cmpl.el | 4 ++-- lisp/eshell/em-glob.el | 2 +- lisp/eshell/em-pred.el | 2 +- lisp/eshell/esh-arg.el | 8 ++++---- lisp/eshell/esh-cmd.el | 4 ++-- lisp/eshell/esh-mode.el | 2 +- lisp/eshell/esh-var.el | 18 +++++++++++------- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lisp/eshell/em-cmpl.el b/lisp/eshell/em-cmpl.el index acbf206a3c6..7f73922f370 100644 --- a/lisp/eshell/em-cmpl.el +++ b/lisp/eshell/em-cmpl.el @@ -332,10 +332,10 @@ eshell-complete-parse-arguments (catch 'eshell-incomplete (ignore (setq args (eshell-parse-arguments begin end))))) - (cond ((memq (car delim) '(?\{ ?\<)) + (cond ((member (car delim) '("{" "${" "$<")) (setq begin (1+ (cadr delim)) args (eshell-parse-arguments begin end))) - ((eq (car delim) ?\() + ((member (car delim) '("(" "$(")) (throw 'pcompleted (elisp-completion-at-point))) (t (eshell--pcomplete-insert-tab)))) diff --git a/lisp/eshell/em-glob.el b/lisp/eshell/em-glob.el index 716f5c32b87..1ac288ea226 100644 --- a/lisp/eshell/em-glob.el +++ b/lisp/eshell/em-glob.el @@ -170,7 +170,7 @@ eshell-parse-glob-chars (end (eshell-find-delimiter delim (if (eq delim ?\[) ?\] ?\))))) (if (not end) - (throw 'eshell-incomplete delim) + (throw 'eshell-incomplete (char-to-string delim)) (if (and (eshell-using-module 'eshell-pred) (eshell-arg-delimiter (1+ end))) (ignore (goto-char here)) diff --git a/lisp/eshell/em-pred.el b/lisp/eshell/em-pred.el index 14fa27aba06..2ccca092b86 100644 --- a/lisp/eshell/em-pred.el +++ b/lisp/eshell/em-pred.el @@ -293,7 +293,7 @@ eshell-parse-arg-modifier (forward-char) (let ((end (eshell-find-delimiter ?\( ?\)))) (if (not end) - (throw 'eshell-incomplete ?\() + (throw 'eshell-incomplete "(") (when (eshell-arg-delimiter (1+ end)) (save-restriction (narrow-to-region (point) end) diff --git a/lisp/eshell/esh-arg.el b/lisp/eshell/esh-arg.el index 6c882471aee..cb0b2e0938c 100644 --- a/lisp/eshell/esh-arg.el +++ b/lisp/eshell/esh-arg.el @@ -421,7 +421,7 @@ eshell-parse-backslash after are both returned." (when (eq (char-after) ?\\) (when (eshell-looking-at-backslash-return (point)) - (throw 'eshell-incomplete ?\\)) + (throw 'eshell-incomplete "\\")) (forward-char 2) ; Move one char past the backslash. (let ((special-chars (if eshell-current-quoted eshell-special-chars-inside-quoting @@ -447,7 +447,7 @@ eshell-parse-literal-quote (if (eq (char-after) ?\') (let ((end (eshell-find-delimiter ?\' ?\'))) (if (not end) - (throw 'eshell-incomplete ?\') + (throw 'eshell-incomplete "'") (let ((string (buffer-substring-no-properties (1+ (point)) end))) (goto-char (1+ end)) (while (string-match "''" string) @@ -460,7 +460,7 @@ eshell-parse-double-quote (let* ((end (eshell-find-delimiter ?\" ?\" nil nil t)) (eshell-current-quoted t)) (if (not end) - (throw 'eshell-incomplete ?\") + (throw 'eshell-incomplete "\"") (prog1 (save-restriction (forward-char) @@ -514,7 +514,7 @@ eshell-parse-special-reference t)) ;; buffer-p is non-nil by default. (end (eshell-find-delimiter ?\< ?\>))) (when (not end) - (throw 'eshell-incomplete ?\<)) + (throw 'eshell-incomplete "#<")) (if (eshell-arg-delimiter (1+ end)) (prog1 (list (if buffer-p 'get-buffer-create 'get-process) diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index b5f1d60ff18..972a6eda868 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el @@ -681,7 +681,7 @@ eshell-parse-subcommand-argument (not (eq (char-after (1+ (point))) ?\})))) (let ((end (eshell-find-delimiter ?\{ ?\}))) (if (not end) - (throw 'eshell-incomplete ?\{) + (throw 'eshell-incomplete "{") (when (eshell-arg-delimiter (1+ end)) (prog1 `(eshell-as-subcommand @@ -698,7 +698,7 @@ eshell-parse-lisp-argument (condition-case nil (read (current-buffer)) (end-of-file - (throw 'eshell-incomplete ?\())))) + (throw 'eshell-incomplete "("))))) (if (eshell-arg-delimiter) `(eshell-command-to-value (eshell-lisp-command (quote ,obj))) diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el index 503d9ba1b63..d3e9823622f 100644 --- a/lisp/eshell/esh-mode.el +++ b/lisp/eshell/esh-mode.el @@ -567,7 +567,7 @@ eshell-parse-command-input (setq command (eshell-parse-command (cons beg end) args t))))) (ignore - (message "Expecting completion of delimiter %c ..." + (message "Expecting completion of delimiter %s ..." (if (listp delim) (car delim) delim))) diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el index 60aab92b33e..a5bfbf4254d 100644 --- a/lisp/eshell/esh-var.el +++ b/lisp/eshell/esh-var.el @@ -503,7 +503,7 @@ eshell-parse-variable-ref ((eq (char-after) ?{) (let ((end (eshell-find-delimiter ?\{ ?\}))) (if (not end) - (throw 'eshell-incomplete ?\{) + (throw 'eshell-incomplete "${") (forward-char) (prog1 `(eshell-apply-indices @@ -527,7 +527,7 @@ eshell-parse-variable-ref ((eq (char-after) ?\<) (let ((end (eshell-find-delimiter ?\< ?\>))) (if (not end) - (throw 'eshell-incomplete ?\<) + (throw 'eshell-incomplete "$<") (let* ((temp (make-temp-file temporary-file-directory)) (cmd (concat (buffer-substring (1+ (point)) end) " > " temp))) @@ -560,15 +560,19 @@ eshell-parse-variable-ref (current-buffer))))) indices ,eshell-current-quoted) (end-of-file - (throw 'eshell-incomplete ?\()))) + (throw 'eshell-incomplete "$(")))) ((looking-at (rx-to-string `(or "'" ,(if eshell-current-quoted "\\\"" "\"")))) (eshell-with-temp-command (or (eshell-unescape-inner-double-quote (point-max)) (cons (point) (point-max))) - (let ((name (if (eq (char-after) ?\') - (eshell-parse-literal-quote) - (eshell-parse-double-quote)))) + (let (name) + (when-let ((delim + (catch 'eshell-incomplete + (ignore (setq name (if (eq (char-after) ?\') + (eshell-parse-literal-quote) + (eshell-parse-double-quote))))))) + (throw 'eshell-incomplete (concat "$" delim))) (when name `(eshell-get-variable ,(eval name) indices ,eshell-current-quoted))))) ((assoc (char-to-string (char-after)) @@ -597,7 +601,7 @@ eshell-parse-indices (while (eq (char-after) ?\[) (let ((end (eshell-find-delimiter ?\[ ?\]))) (if (not end) - (throw 'eshell-incomplete ?\[) + (throw 'eshell-incomplete "[") (forward-char) (eshell-with-temp-command (or (eshell-unescape-inner-double-quote end) (cons (point) end)) -- 2.25.1