diff options
| author | Miles Bader | 2001-10-09 02:26:00 +0000 |
|---|---|---|
| committer | Miles Bader | 2001-10-09 02:26:00 +0000 |
| commit | a277229e6b95a3610a88fcd5cd6f58d99414b95f (patch) | |
| tree | 9e583d862ece51281f0f6a5975e051c34d7d44b1 | |
| parent | 76ba8dafafca61a90eccf5671e8ec84d5b817acd (diff) | |
| download | emacs-a277229e6b95a3610a88fcd5cd6f58d99414b95f.tar.gz emacs-a277229e6b95a3610a88fcd5cd6f58d99414b95f.zip | |
(comint-insert-previous-argument): New function.
(comint-mode-map): Bind `C-c .' to `comint-input-previous-argument'.
(comint-insert-previous-argument-last-start-pos)
(comint-insert-previous-argument-last-index): New variables.
| -rw-r--r-- | lisp/comint.el | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lisp/comint.el b/lisp/comint.el index 71d0cae28ea..4be70c63dfa 100644 --- a/lisp/comint.el +++ b/lisp/comint.el | |||
| @@ -559,6 +559,7 @@ Entry to this mode runs the hooks on `comint-mode-hook'." | |||
| 559 | (define-key comint-mode-map "\C-c\C-p" 'comint-previous-prompt) | 559 | (define-key comint-mode-map "\C-c\C-p" 'comint-previous-prompt) |
| 560 | (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof) | 560 | (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof) |
| 561 | (define-key comint-mode-map "\C-c\C-s" 'comint-write-output) | 561 | (define-key comint-mode-map "\C-c\C-s" 'comint-write-output) |
| 562 | (define-key comint-mode-map "\C-c." 'comint-insert-previous-argument) | ||
| 562 | ;; Mouse Buttons: | 563 | ;; Mouse Buttons: |
| 563 | (define-key comint-mode-map [mouse-2] 'comint-insert-clicked-input) | 564 | (define-key comint-mode-map [mouse-2] 'comint-insert-clicked-input) |
| 564 | ;; Menu bars: | 565 | ;; Menu bars: |
| @@ -1970,6 +1971,7 @@ This function could be in the list `comint-output-filter-functions'." | |||
| 1970 | (comint-snapshot-last-prompt)) | 1971 | (comint-snapshot-last-prompt)) |
| 1971 | (comint-snapshot-last-prompt)) | 1972 | (comint-snapshot-last-prompt)) |
| 1972 | (process-send-region process start end)) | 1973 | (process-send-region process start end)) |
| 1974 | |||
| 1973 | 1975 | ||
| 1974 | ;; Random input hackage | 1976 | ;; Random input hackage |
| 1975 | 1977 | ||
| @@ -2197,6 +2199,58 @@ the beginning of the Nth previous `input' field, otherwise, it means the Nth | |||
| 2197 | occurance of text matching `comint-prompt-regexp'." | 2199 | occurance of text matching `comint-prompt-regexp'." |
| 2198 | (interactive "p") | 2200 | (interactive "p") |
| 2199 | (comint-next-prompt (- n))) | 2201 | (comint-next-prompt (- n))) |
| 2202 | |||
| 2203 | ;; State used by `comint-insert-previous-argument' when cycling. | ||
| 2204 | (defvar comint-insert-previous-argument-last-start-pos nil) | ||
| 2205 | (make-variable-buffer-local 'comint-insert-previous-argument-last-start-pos) | ||
| 2206 | (defvar comint-insert-previous-argument-last-index nil) | ||
| 2207 | (make-variable-buffer-local 'comint-insert-previous-argument-last-index) | ||
| 2208 | |||
| 2209 | ;; Needs fixing: | ||
| 2210 | ;; make comint-arguments understand negative indices as bash does | ||
| 2211 | (defun comint-insert-previous-argument (index) | ||
| 2212 | "Insert the INDEXth argument from the previous comint command-line at point. | ||
| 2213 | Spaces are added at beginning and/or end of the inserted string if | ||
| 2214 | necessary to ensure that it's separated from adjacent arguments. | ||
| 2215 | Interactively, if no prefix argument is given, the last argument is inserted. | ||
| 2216 | Repeated interactive invocations will cycle through the same argument | ||
| 2217 | from progressively earlier commands (using the value of INDEX specified | ||
| 2218 | with the first command). | ||
| 2219 | This command is like `M-.' in bash." | ||
| 2220 | (interactive "P") | ||
| 2221 | (unless (null index) | ||
| 2222 | (setq index (prefix-numeric-value index))) | ||
| 2223 | (cond ((eq last-command this-command) | ||
| 2224 | ;; Delete last input inserted by this command. | ||
| 2225 | (delete-region comint-insert-previous-argument-last-start-pos (point)) | ||
| 2226 | (setq index comint-insert-previous-argument-last-index)) | ||
| 2227 | (t | ||
| 2228 | ;; This is a non-repeat invocation, so initialize state. | ||
| 2229 | (setq comint-input-ring-index nil) | ||
| 2230 | (setq comint-insert-previous-argument-last-index index) | ||
| 2231 | (when (null comint-insert-previous-argument-last-start-pos) | ||
| 2232 | ;; First usage; initialize to a marker | ||
| 2233 | (setq comint-insert-previous-argument-last-start-pos | ||
| 2234 | (make-marker))))) | ||
| 2235 | ;; Make sure we're not in the prompt, and add a beginning space if necess. | ||
| 2236 | (if (<= (point) (comint-line-beginning-position)) | ||
| 2237 | (comint-bol) | ||
| 2238 | (just-one-space)) | ||
| 2239 | ;; Remember the beginning of what we insert, so we can delete it if | ||
| 2240 | ;; the command is repeated. | ||
| 2241 | (set-marker comint-insert-previous-argument-last-start-pos (point)) | ||
| 2242 | ;; Insert the argument. | ||
| 2243 | (let ((input-string (comint-previous-input-string 0))) | ||
| 2244 | (when (string-match "[ \t\n]*&" input-string) | ||
| 2245 | ;; strip terminating '&' | ||
| 2246 | (setq input-string (substring input-string 0 (match-beginning 0)))) | ||
| 2247 | (insert (comint-arguments input-string index index))) | ||
| 2248 | ;; Make next invocation return arg from previous input | ||
| 2249 | (setq comint-input-ring-index (1+ (or comint-input-ring-index 0))) | ||
| 2250 | ;; Add a terminating space if necessary. | ||
| 2251 | (unless (eolp) | ||
| 2252 | (just-one-space))) | ||
| 2253 | |||
| 2200 | 2254 | ||
| 2201 | ;; Support for source-file processing commands. | 2255 | ;; Support for source-file processing commands. |
| 2202 | ;;============================================================================ | 2256 | ;;============================================================================ |
| @@ -2745,6 +2799,7 @@ Typing SPC flushes the help buffer." | |||
| 2745 | (if (eq first ?\ ) | 2799 | (if (eq first ?\ ) |
| 2746 | (set-window-configuration conf) | 2800 | (set-window-configuration conf) |
| 2747 | (setq unread-command-events (listify-key-sequence key))))))) | 2801 | (setq unread-command-events (listify-key-sequence key))))))) |
| 2802 | |||
| 2748 | 2803 | ||
| 2749 | (defun comint-get-next-from-history () | 2804 | (defun comint-get-next-from-history () |
| 2750 | "After fetching a line from input history, this fetches the following line. | 2805 | "After fetching a line from input history, this fetches the following line. |
| @@ -3161,6 +3216,7 @@ REGEXP-GROUP is the regular expression group in REGEXP to use." | |||
| 3161 | "^No history$" | 3216 | "^No history$" |
| 3162 | "^Not found$" ; Too common? | 3217 | "^Not found$" ; Too common? |
| 3163 | "^Current buffer has no process$")) | 3218 | "^Current buffer has no process$")) |
| 3219 | |||
| 3164 | 3220 | ||
| 3165 | ;; Converting process modes to use comint mode | 3221 | ;; Converting process modes to use comint mode |
| 3166 | ;; =========================================================================== | 3222 | ;; =========================================================================== |
| @@ -3245,6 +3301,7 @@ REGEXP-GROUP is the regular expression group in REGEXP to use." | |||
| 3245 | ;; You could use comint-dynamic-simple-complete to do the bulk of the | 3301 | ;; You could use comint-dynamic-simple-complete to do the bulk of the |
| 3246 | ;; completion job. | 3302 | ;; completion job. |
| 3247 | 3303 | ||
| 3304 | |||
| 3248 | (provide 'comint) | 3305 | (provide 'comint) |
| 3249 | 3306 | ||
| 3250 | ;;; comint.el ends here | 3307 | ;;; comint.el ends here |