1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-13 16:38:14 +00:00

(comint-arguments): Use just one regexp to find end of arg

and detect whether it has any quotes.
(comint-delim-arg): Don't check for quotes.  Use loop, not regexps.
(comint-delimiter-argument-list): List now has chars, not strings.
This commit is contained in:
Richard M. Stallman 1994-03-02 22:00:24 +00:00
parent f6807db3d6
commit 3f4b7c3602

View File

@ -152,10 +152,9 @@ This is a good thing to set in mode hooks.")
Strings comprising a character in this list will separate the arguments Strings comprising a character in this list will separate the arguments
surrounding them, and also be regarded as arguments in their own right (unlike surrounding them, and also be regarded as arguments in their own right (unlike
whitespace). See `comint-arguments'. whitespace). See `comint-arguments'.
Defaults to (), the empty list. Defaults to the empty list.
Good choices: For shells, a good value is (?\\| ?& ?< ?> ?\\( ?\\) ?;).
shell: \(\"|\" \"&\" \"<\" \">\" \"\(\" \")\" \";\")
This is a good thing to set in mode hooks.") This is a good thing to set in mode hooks.")
@ -982,47 +981,45 @@ Quotes are single and double."
(t nth)))) (t nth))))
(comint-arguments string nth mth))))) (comint-arguments string nth mth)))))
;; Return a list of arguments from ARG. Break it up at the
;; delimiters in comint-delimiter-argument-list. Returned list is backwards.
(defun comint-delim-arg (arg) (defun comint-delim-arg (arg)
;; Return a list of arguments from ARG. If there's a quote in there, just (if (null comint-delimiter-argument-list)
;; a list of the arg, otherwise try and break up using characters in
;; comint-delimiter-argument-list. Returned list is backwards.
(if (or (null comint-delimiter-argument-list)
(string-match "[\"\'\`]" arg))
(list arg) (list arg)
(let ((not-delim (concat (let ((args nil)
(format "\\([^%s]" (mapconcat (pos 0)
(function (lambda (d) (regexp-quote d))) (len (length arg)))
comint-delimiter-argument-list "")) (while (< pos len)
"\\|" (let ((char (aref arg pos))
(mapconcat (function (lambda (d) (start pos))
(concat "\\\\" (regexp-quote d)))) (if (memq char comint-delimiter-argument-list)
comint-delimiter-argument-list "\\|") (while (and (< pos len) (eq (aref arg pos) char))
"\\)+")) (setq pos (1+ pos)))
(delim-str (mapconcat (function (lambda (d) (while (and (< pos len)
(concat (regexp-quote d) "+"))) (not (memq (aref arg pos)
comint-delimiter-argument-list "\\|")) comint-delimiter-argument-list)))
(args ()) (pos 0)) (setq pos (1+ pos))))
(while (or (eq pos (string-match not-delim arg pos)) (setq args (cons (substring arg start pos) args))))
(eq pos (string-match delim-str arg pos)))
(setq pos (match-end 0)
args (cons (substring arg (match-beginning 0) pos) args)))
args))) args)))
(defun comint-arguments (string nth mth) (defun comint-arguments (string nth mth)
"Return from STRING the NTH to MTH arguments. "Return from STRING the NTH to MTH arguments.
NTH and/or MTH can be nil, which means the last argument. NTH and/or MTH can be nil, which means the last argument.
Returned arguments are separated by single spaces. Arguments are assumed to be Returned arguments are separated by single spaces.
delimited by whitespace. Strings comprising characters in the variable We assume whitespace separates arguments, except within quotes.
`comint-delimiter-argument-list' are treated as delimiters and arguments. Also, a run of one or more of a single character
in `comint-delimiter-argument-list' is a separate argument.
Argument 0 is the command name." Argument 0 is the command name."
(let ((arg "\\(\\S \\|\\(\"[^\"]*\"\\|\'[^\']*\'\\|\`[^\`]*\`\\)\\)+") (let ((arg "\\(\\(\"[^\"]*\"\\|\'[^\']*\'\\|\`[^\`]*\`\\)\\|\\S \\)+")
(args ()) (pos 0) (str nil)) (args ()) (pos 0) (str nil))
;; We build a list of all the args. Unnecessary, but more efficient, when ;; We build a list of all the args. Unnecessary, but more efficient, when
;; ranges of args are required, than picking out one by one and recursing. ;; ranges of args are required, than picking out one by one and recursing.
(while (string-match arg string pos) (while (string-match arg string pos)
(setq pos (match-end 0) (setq pos (match-end 0)
str (substring string (match-beginning 0) pos) str (substring string (match-beginning 0) pos)
args (nconc (comint-delim-arg str) args))) ;; (match-end 2) is non-nil if we found quotes.
args (if (match-end 2) (cons str args)
(nconc (comint-delim-arg str) args))))
(let ((n (or nth (1- (length args)))) (let ((n (or nth (1- (length args))))
(m (if mth (1- (- (length args) mth)) 0))) (m (if mth (1- (- (length args) mth)) 0)))
(mapconcat (mapconcat