[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master b3af1952135 3/3: Merge branch 'master' of git.savannah.gnu.org:/s
From: |
Eli Zaretskii |
Subject: |
master b3af1952135 3/3: Merge branch 'master' of git.savannah.gnu.org:/srv/git/emacs |
Date: |
Mon, 21 Oct 2024 01:26:40 -0400 (EDT) |
branch: master
commit b3af195213518514f78ac6f66f9598e45befd1ec
Merge: e289f7dbb4f b573aaab76b
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>
Merge branch 'master' of git.savannah.gnu.org:/srv/git/emacs
---
lisp/eshell/em-glob.el | 4 +-
lisp/eshell/esh-arg.el | 140 ++++++++++++++++++++------------------
lisp/eshell/esh-cmd.el | 2 +-
lisp/eshell/esh-var.el | 4 +-
test/lisp/eshell/esh-var-tests.el | 6 +-
5 files changed, 82 insertions(+), 74 deletions(-)
diff --git a/lisp/eshell/em-glob.el b/lisp/eshell/em-glob.el
index 36e4f90aed2..b95204c7e1e 100644
--- a/lisp/eshell/em-glob.el
+++ b/lisp/eshell/em-glob.el
@@ -182,7 +182,6 @@ interpretation."
(buffer-substring-no-properties (1- (point)) (1+ end))
(goto-char (1+ end))))))))))
-(defvar eshell-glob-chars-regexp nil)
(defvar eshell-glob-matches)
(defvar message-shown)
@@ -190,11 +189,12 @@ interpretation."
'(("**/" . recurse)
("***/" . recurse-symlink)))
+(defvar eshell-glob-chars-regexp nil)
(defsubst eshell-glob-chars-regexp ()
"Return the lazily-created value for `eshell-glob-chars-regexp'."
(or eshell-glob-chars-regexp
(setq-local eshell-glob-chars-regexp
- (format "[%s]+" (apply 'string eshell-glob-chars-list)))))
+ (rx-to-string `(+ (any ,@eshell-glob-chars-list)) t))))
(defun eshell-glob-regexp (pattern)
"Convert glob-pattern PATTERN to a regular expression.
diff --git a/lisp/eshell/esh-arg.el b/lisp/eshell/esh-arg.el
index 6e4c0df7526..4ea25f7f202 100644
--- a/lisp/eshell/esh-arg.el
+++ b/lisp/eshell/esh-arg.el
@@ -53,8 +53,6 @@ yield the values intended."
(defvar eshell-current-quoted nil)
(defvar eshell-current-argument-plain nil
"If non-nil, the current argument is \"plain\", and not part of a command.")
-(defvar eshell-inside-quote-regexp nil)
-(defvar eshell-outside-quote-regexp nil)
;;; User Variables:
@@ -89,66 +87,25 @@ If POS is nil, the location of point is checked."
(memq (char-after pos) eshell-delimiter-argument-list))))
(defcustom eshell-parse-argument-hook
- (list
- ;; a term such as #<buffer NAME>, or #<process NAME> is a buffer
- ;; or process reference
- 'eshell-parse-special-reference
-
- ;; numbers convert to numbers if they stand alone
- (lambda ()
- (when (and (not eshell-current-argument)
- (not eshell-current-quoted)
- (looking-at eshell-number-regexp)
- (eshell-arg-delimiter (match-end 0)))
- (goto-char (match-end 0))
- (let ((str (match-string 0)))
- (if (> (length str) 0)
- (add-text-properties 0 (length str) '(number t) str))
- str)))
-
- ;; parse any non-special characters, based on the current context
- (lambda ()
- (unless eshell-inside-quote-regexp
- (setq eshell-inside-quote-regexp
- (format "[^%s]+"
- (apply 'string eshell-special-chars-inside-quoting))))
- (unless eshell-outside-quote-regexp
- (setq eshell-outside-quote-regexp
- (format "[^%s]+"
- (apply 'string eshell-special-chars-outside-quoting))))
- (when (looking-at (if eshell-current-quoted
- eshell-inside-quote-regexp
- eshell-outside-quote-regexp))
- (goto-char (match-end 0))
- (let ((str (match-string 0)))
- (if str
- (set-text-properties 0 (length str) nil str))
- str)))
-
- ;; whitespace or a comment is an argument delimiter
- (lambda ()
- (let (comment-p)
- (when (or (looking-at "[ \t]+")
- (and (not eshell-current-argument)
- (looking-at "#\\([^<'].*\\|$\\)")
- (setq comment-p t)))
- (if comment-p
- (add-text-properties (match-beginning 0) (match-end 0)
- '(comment t)))
- (goto-char (match-end 0))
- (eshell-finish-arg))))
-
- ;; parse backslash and the character after
- 'eshell-parse-backslash
-
- ;; text beginning with ' is a literally quoted
- 'eshell-parse-literal-quote
-
- ;; text beginning with " is interpolably quoted
- 'eshell-parse-double-quote
-
- ;; argument delimiter
- 'eshell-parse-delimiter)
+ '(;; A term such as #<buffer NAME>, or #<process NAME> is a buffer
+ ;; or process reference.
+ eshell-parse-special-reference
+ ;; Numbers convert to numbers if they stand alone.
+ eshell-parse-number
+ ;; Parse any non-special characters, based on the current context.
+ eshell-parse-non-special
+ ;; Whitespace is an argument delimiter.
+ eshell-parse-whitespace
+ ;; ... so is a comment.
+ eshell-parse-comment
+ ;; Parse backslash and the character after.
+ eshell-parse-backslash
+ ;; Text beginning with ' is a literally quoted.
+ eshell-parse-literal-quote
+ ;; Text beginning with " is interpolably quoted.
+ eshell-parse-double-quote
+ ;; Delimiters that separate individual commands.
+ eshell-parse-delimiter)
"Define how to process Eshell command line arguments.
When each function on this hook is called, point will be at the
current position within the argument list. The function should either
@@ -218,13 +175,24 @@ Eshell will expand special refs like \"#<ARG...>\" into
(defun eshell-arg-initialize () ;Called from `eshell-mode' via intern-soft!
"Initialize the argument parsing code."
(eshell-arg-mode)
- (setq-local eshell-inside-quote-regexp nil)
- (setq-local eshell-outside-quote-regexp nil)
-
(when (eshell-using-module 'eshell-cmpl)
(add-hook 'pcomplete-try-first-hook
#'eshell-complete-special-reference nil t)))
+(defvar eshell--non-special-inside-quote-regexp nil)
+(defsubst eshell--non-special-inside-quote-regexp ()
+ (or eshell--non-special-inside-quote-regexp
+ (setq-local eshell--non-special-inside-quote-regexp
+ (rx-to-string
+ `(+ (not (any ,@eshell-special-chars-inside-quoting))) t))))
+
+(defvar eshell--non-special-outside-quote-regexp nil)
+(defsubst eshell--non-special-outside-quote-regexp ()
+ (or eshell--non-special-outside-quote-regexp
+ (setq-local eshell--non-special-outside-quote-regexp
+ (rx-to-string
+ `(+ (not (any ,@eshell-special-chars-outside-quoting)))
t))))
+
(defsubst eshell-escape-arg (string)
"Return STRING with the `escaped' property on it."
(if (stringp string)
@@ -447,6 +415,46 @@ Point is left at the end of the arguments."
"A stub function that generates an error if a floating splice is found."
(error "Splice operator is not permitted in this context"))
+(defun eshell-parse-number ()
+ "Parse a numeric argument.
+Eshell can treat unquoted arguments matching `eshell-number-regexp' as
+their numeric values."
+ (when (and (not eshell-current-argument)
+ (not eshell-current-quoted)
+ (looking-at eshell-number-regexp)
+ (eshell-arg-delimiter (match-end 0)))
+ (goto-char (match-end 0))
+ (let ((str (match-string 0)))
+ (when (> (length str) 0)
+ (add-text-properties 0 (length str) '(number t) str))
+ str)))
+
+(defun eshell-parse-non-special ()
+ "Parse any non-special characters, depending on the current context."
+ (when (looking-at (if eshell-current-quoted
+ (eshell--non-special-inside-quote-regexp)
+ (eshell--non-special-outside-quote-regexp)))
+ (goto-char (match-end 0))
+ (let ((str (match-string 0)))
+ (when str
+ (set-text-properties 0 (length str) nil str))
+ str)))
+
+(defun eshell-parse-whitespace ()
+ "Parse any whitespace, finishing the current argument.
+These are treated as argument delimiters and so finish the current argument."
+ (when (looking-at "[ \t]+")
+ (goto-char (match-end 0))
+ (eshell-finish-arg)))
+
+(defun eshell-parse-comment ()
+ "Parse a comment, finishing the current argument."
+ (when (and (not eshell-current-argument)
+ (looking-at "#\\([^<'].*\\|$\\)"))
+ (add-text-properties (match-beginning 0) (match-end 0) '(comment t))
+ (goto-char (match-end 0))
+ (eshell-finish-arg)))
+
(defsubst eshell-looking-at-backslash-return (pos)
"Test whether a backslash-return sequence occurs at POS."
(declare (obsolete nil "30.1"))
@@ -553,7 +561,7 @@ leaves point where it was."
(apply #'concat (nreverse strings))))))
(defun eshell-parse-delimiter ()
- "Parse an argument delimiter, which is essentially a command operator."
+ "Parse a command delimiter, which is essentially a command operator."
;; this `eshell-operator' keyword gets parsed out by
;; `eshell-split-commands'. Right now the only possibility for
;; error is an incorrect output redirection specifier.
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index c9096b0d159..137abe6eb75 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -488,7 +488,7 @@ command hooks should be run before and after the command."
(grouped-terms (eshell-prepare-splice terms)))
(cond
(grouped-terms
- `(let ((new-terms (nconc ,@grouped-terms)))
+ `(let ((new-terms (append ,@grouped-terms)))
(,sym (car new-terms) (cdr new-terms))))
;; If no terms are spliced, use a simpler command form.
((cdr terms)
diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el
index df490dd4c6c..e3ff76abc26 100644
--- a/lisp/eshell/esh-var.el
+++ b/lisp/eshell/esh-var.el
@@ -607,8 +607,6 @@ Possible variable references are:
(t
(error "Invalid variable reference"))))
-(defvar eshell-glob-function)
-
(defun eshell-parse-indices ()
"Parse and return a list of index-lists.
This produces a series of Lisp forms to be processed by
@@ -625,7 +623,7 @@ For example, \"[0 1][2]\" becomes:
(forward-char)
(eshell-with-temp-command (or (eshell-unescape-inner-double-quote
end)
(cons (point) end))
- (let (eshell-glob-function (eshell-current-quoted nil))
+ (let ((eshell-current-quoted nil))
(setq indices (cons (eshell-parse-arguments
(point-min) (point-max))
indices))))
diff --git a/test/lisp/eshell/esh-var-tests.el
b/test/lisp/eshell/esh-var-tests.el
index 70f6e9c7777..38f90e615a8 100644
--- a/test/lisp/eshell/esh-var-tests.el
+++ b/test/lisp/eshell/esh-var-tests.el
@@ -217,7 +217,8 @@ nil, use FUNCTION instead."
"Splice-interpolate list variable."
(let ((eshell-test-value '(1 2 3)))
(eshell-command-result-equal "echo a $@eshell-test-value z"
- '("a" 1 2 3 "z"))))
+ '("a" 1 2 3 "z"))
+ (should (equal eshell-test-value '(1 2 3)))))
(ert-deftest esh-var-test/interp-var-splice-concat ()
"Splice-interpolate and concat list variable."
@@ -428,7 +429,8 @@ nil, use FUNCTION instead."
"Splice-interpolate list variable inside double-quotes."
(let ((eshell-test-value '(1 2 3)))
(eshell-command-result-equal "echo a \"$@eshell-test-value\" z"
- '("a" "1 2 3" "z"))))
+ '("a" "1 2 3" "z"))
+ (should (equal eshell-test-value '(1 2 3)))))
(ert-deftest esh-var-test/quoted-interp-var-splice-concat ()
"Splice-interpolate and concat list variable inside double-quotes"