Mercurial > emacs
comparison lisp/comint.el @ 31970:ebe991a7d6f9
(comint-mode-hook): Docstring fix.
(comint-mode): Use define-derived-mode.
(comint-mode-map): Remove obsolete comment.
(make-comint): Minor stylistic change.
(comint-insert-clicked-input): Be more careful to find the overlay.
Use this-command-keys rather than hardcoding mouse-2.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 29 Sep 2000 02:05:07 +0000 |
parents | e4d30cac5296 |
children | 219a95f2ef05 |
comparison
equal
deleted
inserted
replaced
31969:9ef4cd44aaab | 31970:ebe991a7d6f9 |
---|---|
386 field boundaries in a natural way)." | 386 field boundaries in a natural way)." |
387 :type 'boolean | 387 :type 'boolean |
388 :group 'comint) | 388 :group 'comint) |
389 | 389 |
390 (defcustom comint-mode-hook '() | 390 (defcustom comint-mode-hook '() |
391 "Called upon entry into comint-mode | 391 "Called upon entry into `comint-mode' |
392 This is run before the process is cranked up." | 392 This is run before the process is cranked up." |
393 :type 'hook | 393 :type 'hook |
394 :group 'comint) | 394 :group 'comint) |
395 | 395 |
396 (defcustom comint-exec-hook '() | 396 (defcustom comint-exec-hook '() |
437 (put 'comint-scroll-show-maximum-output 'permanent-local t) | 437 (put 'comint-scroll-show-maximum-output 'permanent-local t) |
438 (put 'comint-ptyp 'permanent-local t) | 438 (put 'comint-ptyp 'permanent-local t) |
439 | 439 |
440 (put 'comint-mode 'mode-class 'special) | 440 (put 'comint-mode 'mode-class 'special) |
441 | 441 |
442 (defun comint-mode () | 442 (define-derived-mode comint-mode fundamental-mode "Comint" |
443 "Major mode for interacting with an inferior interpreter. | 443 "Major mode for interacting with an inferior interpreter. |
444 Interpreter name is same as buffer name, sans the asterisks. | 444 Interpreter name is same as buffer name, sans the asterisks. |
445 Return at end of buffer sends line as input. | 445 Return at end of buffer sends line as input. |
446 Return not at end copies rest of line to end and sends it. | 446 Return not at end copies rest of line to end and sends it. |
447 Setting variable `comint-eol-on-send' means jump to the end of the line | 447 Setting variable `comint-eol-on-send' means jump to the end of the line |
473 to continue it. | 473 to continue it. |
474 | 474 |
475 \\{comint-mode-map} | 475 \\{comint-mode-map} |
476 | 476 |
477 Entry to this mode runs the hooks on `comint-mode-hook'." | 477 Entry to this mode runs the hooks on `comint-mode-hook'." |
478 (interactive) | |
479 ;; Do not remove this. All major modes must do this. | |
480 (kill-all-local-variables) | |
481 (setq major-mode 'comint-mode) | |
482 (setq mode-name "Comint") | |
483 (setq mode-line-process '(":%s")) | 478 (setq mode-line-process '(":%s")) |
484 (use-local-map comint-mode-map) | |
485 (make-local-variable 'comint-last-input-start) | 479 (make-local-variable 'comint-last-input-start) |
486 (setq comint-last-input-start (make-marker)) | 480 (setq comint-last-input-start (make-marker)) |
487 (set-marker comint-last-input-start (point-min)) | 481 (set-marker comint-last-input-start (point-min)) |
488 (make-local-variable 'comint-last-input-end) | 482 (make-local-variable 'comint-last-input-end) |
489 (setq comint-last-input-end (make-marker)) | 483 (setq comint-last-input-end (make-marker)) |
526 (make-local-variable 'comint-process-echoes) | 520 (make-local-variable 'comint-process-echoes) |
527 (make-local-variable 'comint-file-name-chars) | 521 (make-local-variable 'comint-file-name-chars) |
528 (make-local-variable 'comint-file-name-quote-list) | 522 (make-local-variable 'comint-file-name-quote-list) |
529 (make-local-variable 'comint-accum-marker) | 523 (make-local-variable 'comint-accum-marker) |
530 (setq comint-accum-marker (make-marker)) | 524 (setq comint-accum-marker (make-marker)) |
531 (set-marker comint-accum-marker nil) | 525 (set-marker comint-accum-marker nil)) |
532 (run-hooks 'comint-mode-hook)) | |
533 | 526 |
534 (if comint-mode-map | 527 (if comint-mode-map |
535 nil | 528 nil |
536 ;; Keys: | 529 ;; Keys: |
537 (setq comint-mode-map (make-sparse-keymap)) | 530 (setq comint-mode-map (make-sparse-keymap)) |
561 (define-key comint-mode-map "\C-c\C-l" 'comint-dynamic-list-input-ring) | 554 (define-key comint-mode-map "\C-c\C-l" 'comint-dynamic-list-input-ring) |
562 (define-key comint-mode-map "\C-c\C-n" 'comint-next-prompt) | 555 (define-key comint-mode-map "\C-c\C-n" 'comint-next-prompt) |
563 (define-key comint-mode-map "\C-c\C-p" 'comint-previous-prompt) | 556 (define-key comint-mode-map "\C-c\C-p" 'comint-previous-prompt) |
564 (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof) | 557 (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof) |
565 ;; Mouse Buttons: | 558 ;; Mouse Buttons: |
566 ;; Note, if you change this, you will have to change | |
567 ;; comint-insert-clicked-input as well | |
568 (define-key comint-mode-map [mouse-2] 'comint-insert-clicked-input) | 559 (define-key comint-mode-map [mouse-2] 'comint-insert-clicked-input) |
569 ;; Menu bars: | 560 ;; Menu bars: |
570 ;; completion: | 561 ;; completion: |
571 (define-key comint-mode-map [menu-bar completion] | 562 (define-key comint-mode-map [menu-bar completion] |
572 (cons "Complete" (make-sparse-keymap "Complete"))) | 563 (cons "Complete" (make-sparse-keymap "Complete"))) |
656 (or (fboundp 'start-process) | 647 (or (fboundp 'start-process) |
657 (error "Multi-processing is not supported for this system")) | 648 (error "Multi-processing is not supported for this system")) |
658 (let ((buffer (get-buffer-create (concat "*" name "*")))) | 649 (let ((buffer (get-buffer-create (concat "*" name "*")))) |
659 ;; If no process, or nuked process, crank up a new one and put buffer in | 650 ;; If no process, or nuked process, crank up a new one and put buffer in |
660 ;; comint mode. Otherwise, leave buffer and existing process alone. | 651 ;; comint mode. Otherwise, leave buffer and existing process alone. |
661 (cond ((not (comint-check-proc buffer)) | 652 (unless (comint-check-proc buffer) |
662 (save-excursion | 653 (with-current-buffer buffer |
663 (set-buffer buffer) | 654 (comint-mode)) ; Install local vars, mode, keymap, ... |
664 (comint-mode)) ; Install local vars, mode, keymap, ... | 655 (comint-exec buffer name program startfile switches)) |
665 (comint-exec buffer name program startfile switches))) | |
666 buffer)) | 656 buffer)) |
667 | 657 |
668 ;;;###autoload | 658 ;;;###autoload |
669 (defun comint-run (program) | 659 (defun comint-run (program) |
670 "Run PROGRAM in a comint buffer and switch to it. | 660 "Run PROGRAM in a comint buffer and switch to it. |
765 | 755 |
766 | 756 |
767 (defun comint-insert-clicked-input (event) | 757 (defun comint-insert-clicked-input (event) |
768 "In a comint buffer, set the current input to the clicked-on previous input." | 758 "In a comint buffer, set the current input to the clicked-on previous input." |
769 (interactive "e") | 759 (interactive "e") |
770 ;; This won't play nicely with other overlays... | 760 (let ((over (catch 'found |
771 (let ((overs (overlays-at (posn-point (event-end event))))) | 761 ;; Ignore non-input overlays |
762 (dolist (ov (overlays-at (posn-point (event-end event)))) | |
763 (when (eq (overlay-get ov 'field) 'input) | |
764 (throw 'found ov)))))) | |
772 ;; do we have input in this area? | 765 ;; do we have input in this area? |
773 (if overs | 766 (if over |
774 (let ((input-str (buffer-substring (overlay-start (car overs)) | 767 (let ((input-str (buffer-substring (overlay-start over) |
775 (overlay-end (car overs))))) | 768 (overlay-end over)))) |
776 (if (not (comint-after-pmark-p)) | 769 (delete-region |
777 (error "Not at command line")) | |
778 (delete-region | |
779 ;; Can't use kill-region as it sets this-command | 770 ;; Can't use kill-region as it sets this-command |
780 (or (marker-position comint-accum-marker) | 771 (or (marker-position comint-accum-marker) |
781 (process-mark (get-buffer-process (current-buffer)))) | 772 (process-mark (get-buffer-process (current-buffer)))) |
782 (point)) | 773 (point)) |
783 (insert input-str)) | 774 (insert input-str)) |
784 ;; fall back to the user's previous definition if we aren't | 775 ;; fall back to the user's previous definition if we aren't |
785 ;; on previous input region (note, if you change [mouse-2] | 776 ;; on previous input region. |
786 ;; to something else, you should also change the default | 777 (let ((fun (lookup-key global-map (this-command-keys)))) |
787 ;; keybinding above) | 778 (if fun (call-interactively fun)))))) |
788 (let ((fun (lookup-key global-map [mouse-2]))) | |
789 (if fun | |
790 (call-interactively fun event nil)))))) | |
791 | 779 |
792 | 780 |
793 ;; Input history processing in a buffer | 781 ;; Input history processing in a buffer |
794 ;; =========================================================================== | 782 ;; =========================================================================== |
795 ;; Useful input history functions, courtesy of the Ergo group. | 783 ;; Useful input history functions, courtesy of the Ergo group. |