]> git.eshelyaron.com Git - emacs.git/commitdiff
; Make utility functions for getting the Eshell non-special regexps
authorJim Porter <jporterbugs@gmail.com>
Sun, 20 Oct 2024 23:58:44 +0000 (16:58 -0700)
committerEshel Yaron <me@eshelyaron.com>
Tue, 22 Oct 2024 19:02:16 +0000 (21:02 +0200)
* lisp/eshell/esh-arg.el (eshell-inside-quote-regexp)
(eshell-outside-quote-regexp): Rename to...
(eshell--non-special-inside-quote-regexp)
(eshell--non-special-outside-quote-regexp): ... these, and add
defsubsts.
(eshell-arg-initialize): Don't initialize regexp variables.
(eshell-parse-non-special): ... use them.

* lisp/eshell/em-glob.el (eshell-glob-chars-regexp): Use 'rx-to-string'.

(cherry picked from commit b573aaab76b55ec276b9190570b3ca3ae72cb416)

lisp/eshell/em-glob.el
lisp/eshell/esh-arg.el

index 36e4f90aed2c1d2a362b95c50d96a135ab361503..b95204c7e1e34eb46ed99045c4afdcb65c019bdd 100644 (file)
@@ -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.
index 8785f5216fd3c601a765bde9e17a0b229077a6ae..4ea25f7f2027743dfc7737ea1c1755f2022ccb17 100644 (file)
@@ -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:
 
@@ -177,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)
@@ -422,17 +431,9 @@ their numeric values."
 
 (defun eshell-parse-non-special ()
   "Parse any non-special characters, depending on the current context."
-  (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))
+                        (eshell--non-special-inside-quote-regexp)
+                      (eshell--non-special-outside-quote-regexp)))
     (goto-char (match-end 0))
     (let ((str (match-string 0)))
       (when str