Mercurial > emacs
comparison lisp/comint.el @ 2673:27dd7479b158
(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.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 06 May 1993 14:30:09 +0000 |
parents | bc86243d1361 |
children | ac4af95b962f |
comparison
equal
deleted
inserted
replaced
2672:b69eef4cf31d | 2673:27dd7479b158 |
---|---|
63 ;;; Comint Mode Commands: (common to all derived modes, like shell & cmulisp | 63 ;;; Comint Mode Commands: (common to all derived modes, like shell & cmulisp |
64 ;;; mode) | 64 ;;; mode) |
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. |
74 ;;; c-c c-u comint-kill-input ^u | 73 ;;; c-c c-u comint-kill-input ^u |
75 ;;; c-c c-w backward-kill-word ^w | 74 ;;; c-c c-w backward-kill-word ^w |
112 ;;; comint-prompt-regexp - string comint-bol uses to match prompt. | 111 ;;; comint-prompt-regexp - string comint-bol uses to match prompt. |
113 ;;; comint-last-input-start - marker Handy if inferior always echos | 112 ;;; comint-last-input-start - marker Handy if inferior always echos |
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 |
121 ;;; comint-input-filter - function modes. | 120 ;;; comint-input-filter - function modes. |
122 ;;; comint-input-send - function | 121 ;;; comint-input-send - function |
191 | 190 |
192 (defvar comint-ptyp t | 191 (defvar comint-ptyp t |
193 "True if communications via pty; false if by pipe. Buffer local. | 192 "True if communications via pty; false if by pipe. Buffer local. |
194 This is to work around a bug in emacs process signalling.") | 193 This 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. |
198 Buffer 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) |
202 (defvar comint-last-input-end) | 201 (defvar comint-last-input-end) |
203 (defvar comint-input-ring-index) | 202 (defvar comint-input-ring-index) |
239 (use-local-map comint-mode-map) | 238 (use-local-map comint-mode-map) |
240 (make-local-variable 'comint-last-input-start) | 239 (make-local-variable 'comint-last-input-start) |
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) |
249 (make-local-variable 'comint-input-ring-index) | 248 (make-local-variable 'comint-input-ring-index) |
250 (setq comint-input-ring-index 0) | 249 (setq comint-input-ring-index 0) |
263 (if comint-mode-map | 262 (if comint-mode-map |
264 nil | 263 nil |
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) |
273 (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input) | 272 (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input) |
274 (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word) | 273 (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word) |
275 (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob) | 274 (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob) |
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) |
283 ; (define-key comint-mode-map "\eN" 'comint-psearch-input) | 281 ; (define-key comint-mode-map "\eN" 'comint-psearch-input) |
284 ; (define-key comint-mode-map "\C-cR" 'comint-msearch-input-matching) | 282 ; (define-key comint-mode-map "\C-cR" 'comint-msearch-input-matching) |
419 (defun comint-next-input (arg) | 417 (defun comint-next-input (arg) |
420 "Cycle forwards through input history." | 418 "Cycle forwards through input history." |
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 | 425 With prefix argument N, search for Nth previous match. |
428 (format "Command substring (default %s): " | 426 If 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.) | |
466 With prefix argument N, search for Nth following match. | |
467 If 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 |
451 ;;; comint-msearch-input-matching prompts for a string, not a regexp. | 489 ;;; comint-msearch-input-matching prompts for a string, not a regexp. |
452 ;;; This could be considered to be the wrong thing. I decided to keep it | 490 ;;; This could be considered to be the wrong thing. I decided to keep it |
499 ;;; | 537 ;;; |
500 ;;; Similar input -- contributed by ccm and highly winning. | 538 ;;; Similar input -- contributed by ccm and highly winning. |
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) |
508 Successive repetitions find successively older matching inputs. | 546 ;; "Fetch the previous (older) input that matches the string typed so far. |
509 A prefix argument serves as a repeat count; a negative argument | 547 ;;Successive repetitions find successively older matching inputs. |
510 fetches 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) |
545 Successive repetitions find successively newer matching inputs. | 583 ;; "Fetch the next (newer) input that matches the string typed so far. |
546 A prefix argument serves as a repeat count; a negative argument | 584 ;;Successive repetitions find successively newer matching inputs. |
547 fetches 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. |
553 After the process output mark, sends all text from the process mark to | 592 After the process output mark, sends all text from the process mark to |
554 point as input to the process. Before the process output mark, calls value | 593 point as input to the process. Before the process output mark, calls value |