aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1993-05-06 14:30:09 +0000
committerRichard M. Stallman1993-05-06 14:30:09 +0000
commit0c5c1f34219a3ce6c9dd1f8c250a0fb235ac301d (patch)
treeb651f6cf8355bef609bddd1c92841537f8c0889d
parenta3666e471931be86729da627ef57f1dafb4070fc (diff)
downloademacs-0c5c1f34219a3ce6c9dd1f8c250a0fb235ac301d.tar.gz
emacs-0c5c1f34219a3ce6c9dd1f8c250a0fb235ac301d.zip
(comint-previous-matching-input): New command, on M-r.
(comint-next-matching-input): New command, on M-s. (comint-previous-similar-input): Commented out. (comint-next-similar-input): Likewise. (comint-previous-input-matching): Deleted. (comint-last-input-match): Var commented out. (comint-mode): Don't make comint-last-input-match local.
-rw-r--r--lisp/comint.el197
1 files changed, 118 insertions, 79 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index faa27f64d4d..c787d5386e5 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -65,9 +65,8 @@
65;;; 65;;;
66;;; m-p comint-previous-input Cycle backwards in input history 66;;; m-p comint-previous-input Cycle backwards in input history
67;;; m-n comint-next-input Cycle forwards 67;;; m-n comint-next-input Cycle forwards
68;;; m-r comint-previous-similar-input Previous similar input 68;;; m-r comint-previous-matching-input Previous input matching a regexp
69;;; m-s comint-next-similar-input Next similar input 69;;; m-s comint-next-matching-input Next input that matches
70;;; c-m-r comint-previous-input-matching Search backwards in input history
71;;; return comint-send-input 70;;; return comint-send-input
72;;; c-a comint-bol Beginning of line; skip prompt. 71;;; c-a comint-bol Beginning of line; skip prompt.
73;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff. 72;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff.
@@ -114,7 +113,7 @@
114;;; comint-last-input-end - marker For comint-kill-output command 113;;; comint-last-input-end - marker For comint-kill-output command
115;;; comint-input-ring-size - integer For the input history 114;;; comint-input-ring-size - integer For the input history
116;;; comint-input-ring - ring mechanism 115;;; comint-input-ring - ring mechanism
117;;; comint-input-ring-index - marker ... 116;;; comint-input-ring-index - number ...
118;;; comint-last-input-match - string ... 117;;; comint-last-input-match - string ...
119;;; comint-get-old-input - function Hooks for specific 118;;; comint-get-old-input - function Hooks for specific
120;;; comint-input-sentinel - function process-in-a-buffer 119;;; comint-input-sentinel - function process-in-a-buffer
@@ -193,9 +192,9 @@ executed once when the buffer is created.")
193 "True if communications via pty; false if by pipe. Buffer local. 192 "True if communications via pty; false if by pipe. Buffer local.
194This is to work around a bug in emacs process signalling.") 193This is to work around a bug in emacs process signalling.")
195 194
196(defvar comint-last-input-match "" 195;;(defvar comint-last-input-match ""
197 "Last string searched for by comint input history search, for defaulting. 196;; "Last string searched for by comint input history search, for defaulting.
198Buffer local variable.") 197;;Buffer local variable.")
199 198
200(defvar comint-input-ring nil) 199(defvar comint-input-ring nil)
201(defvar comint-last-input-start) 200(defvar comint-last-input-start)
@@ -241,8 +240,8 @@ Entry to this mode runs the hooks on comint-mode-hook"
241 (setq comint-last-input-start (make-marker)) 240 (setq comint-last-input-start (make-marker))
242 (make-local-variable 'comint-last-input-end) 241 (make-local-variable 'comint-last-input-end)
243 (setq comint-last-input-end (make-marker)) 242 (setq comint-last-input-end (make-marker))
244 (make-local-variable 'comint-last-input-match) 243;;; (make-local-variable 'comint-last-input-match)
245 (setq comint-last-input-match "") 244;;; (setq comint-last-input-match "")
246 (make-local-variable 'comint-prompt-regexp) ; Don't set; default 245 (make-local-variable 'comint-prompt-regexp) ; Don't set; default
247 (make-local-variable 'comint-input-ring-size) ; ...to global val. 246 (make-local-variable 'comint-input-ring-size) ; ...to global val.
248 (make-local-variable 'comint-input-ring) 247 (make-local-variable 'comint-input-ring)
@@ -265,8 +264,8 @@ Entry to this mode runs the hooks on comint-mode-hook"
265 (setq comint-mode-map (make-sparse-keymap)) 264 (setq comint-mode-map (make-sparse-keymap))
266 (define-key comint-mode-map "\ep" 'comint-previous-input) 265 (define-key comint-mode-map "\ep" 'comint-previous-input)
267 (define-key comint-mode-map "\en" 'comint-next-input) 266 (define-key comint-mode-map "\en" 'comint-next-input)
268 (define-key comint-mode-map "\er" 'comint-previous-similar-input) 267 (define-key comint-mode-map "\er" 'comint-previous-matching-input)
269 (define-key comint-mode-map "\es" 'comint-next-similar-input) 268 (define-key comint-mode-map "\es" 'comint-next-matching-input)
270 (define-key comint-mode-map "\C-m" 'comint-send-input) 269 (define-key comint-mode-map "\C-m" 'comint-send-input)
271 (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof) 270 (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof)
272 (define-key comint-mode-map "\C-a" 'comint-bol) 271 (define-key comint-mode-map "\C-a" 'comint-bol)
@@ -276,7 +275,6 @@ Entry to this mode runs the hooks on comint-mode-hook"
276 (define-key comint-mode-map "\C-c\C-z" 'comint-stop-subjob) 275 (define-key comint-mode-map "\C-c\C-z" 'comint-stop-subjob)
277 (define-key comint-mode-map "\C-c\C-\\" 'comint-quit-subjob) 276 (define-key comint-mode-map "\C-c\C-\\" 'comint-quit-subjob)
278 (define-key comint-mode-map "\C-c\C-o" 'comint-kill-output) 277 (define-key comint-mode-map "\C-c\C-o" 'comint-kill-output)
279 (define-key comint-mode-map "\C-\M-r" 'comint-previous-input-matching)
280 (define-key comint-mode-map "\C-c\C-r" 'comint-show-output) 278 (define-key comint-mode-map "\C-c\C-r" 'comint-show-output)
281 ;;; prompt-search commands commented out 3/90 -Olin 279 ;;; prompt-search commands commented out 3/90 -Olin
282; (define-key comint-mode-map "\eP" 'comint-msearch-input) 280; (define-key comint-mode-map "\eP" 'comint-msearch-input)
@@ -421,30 +419,70 @@ buffer. The hook comint-exec-hook is run after each exec."
421 (interactive "*p") 419 (interactive "*p")
422 (comint-previous-input (- arg))) 420 (comint-previous-input (- arg)))
423 421
424(defun comint-previous-input-matching (str) 422(defun comint-previous-matching-input (regexp arg)
425 "Searches backwards through input history for substring match." 423 "Search backwards through input history for match for REGEXP.
426 (interactive (let* ((last-command last-command) ; preserve around r-f-m 424\(Previous history elements are earlier commands.)
427 (s (read-from-minibuffer 425With prefix argument N, search for Nth previous match.
428 (format "Command substring (default %s): " 426If N is negative, find the next or Nth next match."
429 comint-last-input-match)))) 427 (interactive
430 (list (if (string= s "") comint-last-input-match s)))) 428 (let ((minibuffer-history-sexp-flag nil)
431; (interactive "sCommand substring: ") 429 ;; Don't clobber this.
432 (setq comint-last-input-match str) ; update default 430 (last-command last-command)
431 (regexp (read-from-minibuffer "Previous input matching (regexp): "
432 nil
433 minibuffer-local-map
434 nil
435 'minibuffer-history-search-history)))
436 (list (if (string= regexp "")
437 (setcar minibuffer-history-search-history
438 (nth 1 minibuffer-history-search-history))
439 regexp)
440 (prefix-numeric-value current-prefix-arg))))
433 (if (null comint-input-ring-index) 441 (if (null comint-input-ring-index)
434 (setq comint-input-ring-index -1)) 442 (setq comint-input-ring-index -1))
435 (let ((str (regexp-quote str)) 443 (let* ((len (ring-length comint-input-ring))
436 (len (ring-length comint-input-ring)) 444 (motion (if (> arg 0) 1 -1))
437 (n (+ comint-input-ring-index 1))) 445 (n comint-input-ring-index))
438 (while (and (< n len) (not (string-match str (ring-ref comint-input-ring n)))) 446 ;; Do the whole search as many times as the argument says.
439 (setq n (+ n 1))) 447 (while (/= arg 0)
440 (cond ((< n len) 448 (let ((prev n))
441 (comint-previous-input (- n comint-input-ring-index))) 449 ;; Step once.
442 (t (error "Not found"))))) 450 (setq n (ring-mod (+ n motion) len))
443 451 ;; If we haven't reached a match, step some more.
444 452 (while (and (< n len)
453 (not (string-match regexp (ring-ref comint-input-ring n))))
454 (setq n (ring-mod (+ n motion) len))
455 ;; If we have gone all the way around in this search, error.
456 (if (= n prev)
457 (error "Not found"))))
458 (setq arg (if (> arg 0) (1- arg) (1+ arg))))
459 ;; Now that we know which ring element to use,
460 ;; substitute that for the current input.
461 (comint-previous-input (- n comint-input-ring-index))))
462
463(defun comint-next-matching-input (regexp arg)
464 "Search forwards through input history for match for REGEXP.
465\(Later history elements are more recent commands.)
466With prefix argument N, search for Nth following match.
467If N is negative, find the previous or Nth previous match."
468 (interactive
469 (let ((minibuffer-history-sexp-flag nil)
470 ;; Don't clobber this.
471 (last-command last-command)
472 (regexp (read-from-minibuffer "Previous input matching (regexp): "
473 nil
474 minibuffer-local-map
475 nil
476 'minibuffer-history-search-history)))
477 (list (if (string= regexp "")
478 (setcar minibuffer-history-search-history
479 (nth 1 minibuffer-history-search-history))
480 regexp)
481 (prefix-numeric-value current-prefix-arg))))
482 (comint-previous-matching-input regexp (- arg)))
483
445;;; These next three commands are alternatives to the input history commands 484;;; These next three commands are alternatives to the input history commands
446;;; -- comint-next-input, comint-previous-input and 485;;; They search through the process buffer
447;;; comint-previous-input-matching. They search through the process buffer
448;;; text looking for occurrences of the prompt. Bound to M-P, M-N, and C-c R 486;;; text looking for occurrences of the prompt. Bound to M-P, M-N, and C-c R
449;;; (uppercase P, N, and R) for now. Try'em out. Go with what you like... 487;;; (uppercase P, N, and R) for now. Try'em out. Go with what you like...
450 488
@@ -501,52 +539,53 @@ buffer. The hook comint-exec-hook is run after each exec."
501;;; 539;;;
502;;; Reenter input, removing back to the last insert point if it exists. 540;;; Reenter input, removing back to the last insert point if it exists.
503;;; 541;;;
504(defvar comint-last-similar-string "" 542;;(defvar comint-last-similar-string ""
505 "The string last used in a similar string search.") 543;; "The string last used in a similar string search.")
506(defun comint-previous-similar-input (arg) 544
507 "Fetch the previous (older) input that matches the string typed so far. 545;;(defun comint-previous-similar-input (arg)
508Successive repetitions find successively older matching inputs. 546;; "Fetch the previous (older) input that matches the string typed so far.
509A prefix argument serves as a repeat count; a negative argument 547;;Successive repetitions find successively older matching inputs.
510fetches following (more recent) inputs." 548;;A prefix argument serves as a repeat count; a negative argument
511 (interactive "p") 549;;fetches following (more recent) inputs."
512 (if (not (comint-after-pmark-p)) 550;; (interactive "p")
513 (error "Not after process mark")) 551;; (if (not (comint-after-pmark-p))
514 (if (null comint-input-ring-index) 552;; (error "Not after process mark"))
515 (setq comint-input-ring-index 553;; (if (null comint-input-ring-index)
516 (if (> arg 0) -1 554;; (setq comint-input-ring-index
517 (if (< arg 0) 1 0)))) 555;; (if (> arg 0) -1
518 (if (not (or (eq last-command 'comint-previous-similar-input) 556;; (if (< arg 0) 1 0))))
519 (eq last-command 'comint-next-similar-input))) 557;; (if (not (or (eq last-command 'comint-previous-similar-input)
520 (setq comint-last-similar-string 558;; (eq last-command 'comint-next-similar-input)))
521 (buffer-substring 559;; (setq comint-last-similar-string
522 (process-mark (get-buffer-process (current-buffer))) 560;; (buffer-substring
523 (point)))) 561;; (process-mark (get-buffer-process (current-buffer)))
524 (let* ((size (length comint-last-similar-string)) 562;; (point))))
525 (len (ring-length comint-input-ring)) 563;; (let* ((size (length comint-last-similar-string))
526 (n (+ comint-input-ring-index arg)) 564;; (len (ring-length comint-input-ring))
527 entry) 565;; (n (+ comint-input-ring-index arg))
528 (while (and (< n len) 566;; entry)
529 (or (< (length (setq entry (ring-ref comint-input-ring n))) size) 567;; (while (and (< n len)
530 (not (equal comint-last-similar-string 568;; (or (< (length (setq entry (ring-ref comint-input-ring n))) size)
531 (substring entry 0 size))))) 569;; (not (equal comint-last-similar-string
532 (setq n (+ n arg))) 570;; (substring entry 0 size)))))
533 (cond ((< n len) 571;; (setq n (+ n arg)))
534 (setq comint-input-ring-index n) 572;; (cond ((< n len)
535 (if (or (eq last-command 'comint-previous-similar-input) 573;; (setq comint-input-ring-index n)
536 (eq last-command 'comint-next-similar-input)) 574;; (if (or (eq last-command 'comint-previous-similar-input)
537 (delete-region (mark) (point)) ; repeat 575;; (eq last-command 'comint-next-similar-input))
538 (push-mark (point))) ; 1st time 576;; (delete-region (mark) (point)) ; repeat
539 (insert (substring entry size))) 577;; (push-mark (point))) ; 1st time
540 (t (error "Not found"))) 578;; (insert (substring entry size)))
541 (message "%d" (1+ comint-input-ring-index)))) 579;; (t (error "Not found")))
542 580;; (message "%d" (1+ comint-input-ring-index))))
543(defun comint-next-similar-input (arg) 581
544 "Fetch the next (newer) input that matches the string typed so far. 582;;(defun comint-next-similar-input (arg)
545Successive repetitions find successively newer matching inputs. 583;; "Fetch the next (newer) input that matches the string typed so far.
546A prefix argument serves as a repeat count; a negative argument 584;;Successive repetitions find successively newer matching inputs.
547fetches previous (older) inputs." 585;;A prefix argument serves as a repeat count; a negative argument
548 (interactive "p") 586;;fetches previous (older) inputs."
549 (comint-previous-similar-input (- arg))) 587;; (interactive "p")
588;; (comint-previous-similar-input (- arg)))
550 589
551(defun comint-send-input () 590(defun comint-send-input ()
552 "Send input to process. 591 "Send input to process.