comparison lisp/comint.el @ 39713:25d48943cd58

(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.
author Miles Bader <miles@gnu.org>
date Tue, 09 Oct 2001 02:26:00 +0000
parents e2d428b5bfea
children 066f92cdfebf
comparison
equal deleted inserted replaced
39712:a040a5379006 39713:25d48943cd58
557 (define-key comint-mode-map "\C-c\C-l" 'comint-dynamic-list-input-ring) 557 (define-key comint-mode-map "\C-c\C-l" 'comint-dynamic-list-input-ring)
558 (define-key comint-mode-map "\C-c\C-n" 'comint-next-prompt) 558 (define-key comint-mode-map "\C-c\C-n" 'comint-next-prompt)
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:
565 ;; completion: 566 ;; completion:
566 (define-key comint-mode-map [menu-bar completion] 567 (define-key comint-mode-map [menu-bar completion]
1968 (process-buffer process) 1969 (process-buffer process)
1969 (get-buffer process)) 1970 (get-buffer process))
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
1976 (defun comint-delete-output () 1978 (defun comint-delete-output ()
1977 "Delete all output from interpreter since last input. 1979 "Delete all output from interpreter since last input.
2195 If `comint-use-prompt-regexp-instead-of-fields' is nil, then this means 2197 If `comint-use-prompt-regexp-instead-of-fields' is nil, then this means
2196 the beginning of the Nth previous `input' field, otherwise, it means the Nth 2198 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 ;;============================================================================
2203 ;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have 2257 ;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have
2204 ;; commands that process files of source text (e.g. loading or compiling 2258 ;; commands that process files of source text (e.g. loading or compiling
2743 (mouse-choose-completion first) 2797 (mouse-choose-completion first)
2744 (set-window-configuration conf)) 2798 (set-window-configuration conf))
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.
2751 In other words, this recalls the input line after the line you recalled last. 2806 In other words, this recalls the input line after the line you recalled last.
2752 You can use this to repeat a sequence of input lines." 2807 You can use this to repeat a sequence of input lines."
3159 '("^Not at command line$" 3214 '("^Not at command line$"
3160 "^Empty input ring$" 3215 "^Empty input ring$"
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 ;; ===========================================================================
3167 ;; The code in the Emacs 19 distribution has all been modified to use comint 3223 ;; The code in the Emacs 19 distribution has all been modified to use comint
3168 ;; where needed. However, there are `third-party' packages out there that 3224 ;; where needed. However, there are `third-party' packages out there that
3243 ;; hook to add completion functions to. Functions on this list should return 3299 ;; hook to add completion functions to. Functions on this list should return
3244 ;; non-nil if completion occurs (i.e., further completion should not occur). 3300 ;; non-nil if completion occurs (i.e., further completion should not occur).
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