diff options
| author | Richard M. Stallman | 1994-08-24 23:31:55 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-08-24 23:31:55 +0000 |
| commit | d91f490d2b745c44ed3be3d6ad297996fc48eaa7 (patch) | |
| tree | 5fe934aa636097e60850f40b687cb216bc05e9c2 | |
| parent | 8deebe898398b4f366b03454c868afd8022d3b51 (diff) | |
| download | emacs-d91f490d2b745c44ed3be3d6ad297996fc48eaa7.tar.gz emacs-d91f490d2b745c44ed3be3d6ad297996fc48eaa7.zip | |
(comint-arguments): Rewrite for speed.
Don't keep parsing once we have enough args.
| -rw-r--r-- | lisp/comint.el | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/lisp/comint.el b/lisp/comint.el index c18e84e70b2..b0135faf980 100644 --- a/lisp/comint.el +++ b/lisp/comint.el | |||
| @@ -1043,18 +1043,34 @@ We assume whitespace separates arguments, except within quotes. | |||
| 1043 | Also, a run of one or more of a single character | 1043 | Also, a run of one or more of a single character |
| 1044 | in `comint-delimiter-argument-list' is a separate argument. | 1044 | in `comint-delimiter-argument-list' is a separate argument. |
| 1045 | Argument 0 is the command name." | 1045 | Argument 0 is the command name." |
| 1046 | (let ((arg "\\(\\(\"[^\"]*\"\\|\'[^\']*\'\\|\`[^\`]*\`\\)\\|\\S \\)+") | 1046 | (let ((argpart "[^ \"'`]+\\|\\(\"[^\"]*\"\\|'[^']*'\\|`[^`]*`\\)") |
| 1047 | (args ()) (pos 0) (str nil)) | 1047 | (args ()) (pos 0) |
| 1048 | ;; We build a list of all the args. Unnecessary, but more efficient, when | 1048 | (count 0) |
| 1049 | ;; ranges of args are required, than picking out one by one and recursing. | 1049 | beg str value quotes) |
| 1050 | (while (string-match arg string pos) | 1050 | ;; Build a list of all the args until we have as many as we want. |
| 1051 | (setq pos (match-end 0) | 1051 | (while (and (or (null mth) (<= count mth)) |
| 1052 | str (substring string (match-beginning 0) pos) | 1052 | (string-match argpart string pos)) |
| 1053 | ;; (match-end 2) is non-nil if we found quotes. | 1053 | (if (and beg (= pos (match-beginning 0))) |
| 1054 | args (if (match-end 2) (cons str args) | 1054 | ;; It's contiguous, part of the same arg. |
| 1055 | (nconc (comint-delim-arg str) args)))) | 1055 | (setq pos (match-end 0) |
| 1056 | (let ((n (or nth (1- (length args)))) | 1056 | quotes (or quotes (match-beginning 1))) |
| 1057 | (m (if mth (1- (- (length args) mth)) 0))) | 1057 | ;; It's a new separate arg. |
| 1058 | (if beg | ||
| 1059 | ;; Put the previous arg, if there was one, onto ARGS. | ||
| 1060 | (setq str (substring string beg pos) | ||
| 1061 | args (if quotes (cons str args) | ||
| 1062 | (nconc (comint-delim-arg str) args)) | ||
| 1063 | count (1+ count))) | ||
| 1064 | (setq quotes (match-beginning 1)) | ||
| 1065 | (setq beg (match-beginning 0)) | ||
| 1066 | (setq pos (match-end 0)))) | ||
| 1067 | (if beg | ||
| 1068 | (setq str (substring string beg pos) | ||
| 1069 | args (if quotes (cons str args) | ||
| 1070 | (nconc (comint-delim-arg str) args)) | ||
| 1071 | count (1+ count))) | ||
| 1072 | (let ((n (or nth (1- count))) | ||
| 1073 | (m (if mth (1- (- count mth)) 0))) | ||
| 1058 | (mapconcat | 1074 | (mapconcat |
| 1059 | (function (lambda (a) a)) (nthcdr n (nreverse (nthcdr m args))) " ")))) | 1075 | (function (lambda (a) a)) (nthcdr n (nreverse (nthcdr m args))) " ")))) |
| 1060 | 1076 | ||