From 7869f1a77f2b85bab08c6d09feb92d89c63ae408 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Thu, 17 Oct 2024 20:02:28 -0700 Subject: [PATCH] Make all the entries in 'eshell-parse-argument-hook' named functions * lisp/eshell/esh-arg.el (eshell-parse-number, eshell-parse-non-special) (eshell-parse-whitespace, eshell-parse-comment): New functions... (eshell-parse-argument-hook): ... use them. (cherry picked from commit 212cf3125611b123707feac6f7ffd55a230bc568) --- lisp/eshell/esh-arg.el | 129 ++++++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 61 deletions(-) diff --git a/lisp/eshell/esh-arg.el b/lisp/eshell/esh-arg.el index 6e4c0df7526..8785f5216fd 100644 --- a/lisp/eshell/esh-arg.el +++ b/lisp/eshell/esh-arg.el @@ -89,66 +89,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 #, or # 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 #, or # 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 @@ -447,6 +406,54 @@ 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." + (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))) + (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 +560,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. -- 2.39.2