changeset 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 9ef4cd44aaab
children fa083a5fbf0c
files lisp/comint.el
diffstat 1 files changed, 20 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/comint.el	Fri Sep 29 01:53:42 2000 +0000
+++ b/lisp/comint.el	Fri Sep 29 02:05:07 2000 +0000
@@ -388,7 +388,7 @@
   :group 'comint)
 
 (defcustom comint-mode-hook '()
-  "Called upon entry into comint-mode
+  "Called upon entry into `comint-mode'
 This is run before the process is cranked up."
   :type 'hook
   :group 'comint)
@@ -439,7 +439,7 @@
 
 (put 'comint-mode 'mode-class 'special)
 
-(defun comint-mode ()
+(define-derived-mode comint-mode fundamental-mode "Comint"
   "Major mode for interacting with an inferior interpreter.
 Interpreter name is same as buffer name, sans the asterisks.
 Return at end of buffer sends line as input.
@@ -475,13 +475,7 @@
 \\{comint-mode-map}
 
 Entry to this mode runs the hooks on `comint-mode-hook'."
-  (interactive)
-  ;; Do not remove this.  All major modes must do this.
-  (kill-all-local-variables)
-  (setq major-mode 'comint-mode)
-  (setq mode-name "Comint")
   (setq mode-line-process '(":%s"))
-  (use-local-map comint-mode-map)
   (make-local-variable 'comint-last-input-start)
   (setq comint-last-input-start (make-marker))
   (set-marker comint-last-input-start (point-min))
@@ -528,8 +522,7 @@
   (make-local-variable 'comint-file-name-quote-list)
   (make-local-variable 'comint-accum-marker)
   (setq comint-accum-marker (make-marker))
-  (set-marker comint-accum-marker nil)
-  (run-hooks 'comint-mode-hook))
+  (set-marker comint-accum-marker nil))
 
 (if comint-mode-map
     nil
@@ -563,8 +556,6 @@
   (define-key comint-mode-map "\C-c\C-p" 'comint-previous-prompt)
   (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof)
   ;; Mouse Buttons:
-  ;; Note, if you change this, you will have to change
-  ;; comint-insert-clicked-input as well
   (define-key comint-mode-map [mouse-2] 'comint-insert-clicked-input)
   ;; Menu bars:
   ;; completion:
@@ -658,11 +649,10 @@
   (let ((buffer (get-buffer-create (concat "*" name "*"))))
     ;; If no process, or nuked process, crank up a new one and put buffer in
     ;; comint mode.  Otherwise, leave buffer and existing process alone.
-    (cond ((not (comint-check-proc buffer))
-	   (save-excursion
-	     (set-buffer buffer)
-	     (comint-mode)) ; Install local vars, mode, keymap, ...
-	   (comint-exec buffer name program startfile switches)))
+    (unless (comint-check-proc buffer)
+      (with-current-buffer buffer
+	(comint-mode)) ; Install local vars, mode, keymap, ...
+      (comint-exec buffer name program startfile switches))
     buffer))
 
 ;;;###autoload
@@ -767,27 +757,25 @@
 (defun comint-insert-clicked-input (event)
   "In a comint buffer, set the current input to the clicked-on previous input."
   (interactive "e")
-  ;; This won't play nicely with other overlays...
-  (let ((overs (overlays-at (posn-point (event-end event)))))
+  (let ((over (catch 'found
+		;; Ignore non-input overlays
+		(dolist (ov (overlays-at (posn-point (event-end event))))
+		  (when (eq (overlay-get ov 'field) 'input)
+		    (throw 'found ov))))))
     ;; do we have input in this area?
-    (if overs
-	(let ((input-str (buffer-substring (overlay-start (car overs))
-					   (overlay-end (car overs)))))
-	  (if (not (comint-after-pmark-p))
-	      (error "Not at command line"))
-	  (delete-region 
+    (if over
+	(let ((input-str (buffer-substring (overlay-start over)
+					   (overlay-end over))))
+	  (delete-region
 	   ;; Can't use kill-region as it sets this-command
 	   (or  (marker-position comint-accum-marker)
 		(process-mark (get-buffer-process (current-buffer))))
-	   (point))	  
+	   (point))
 	  (insert input-str))
       ;; fall back to the user's previous definition if we aren't
-      ;; on previous input region (note, if you change [mouse-2]
-      ;; to something else, you should also change the default
-      ;; keybinding above)
-      (let ((fun (lookup-key global-map [mouse-2])))
-	(if fun
-	    (call-interactively fun event nil))))))
+      ;; on previous input region.
+      (let ((fun (lookup-key global-map (this-command-keys))))
+	(if fun (call-interactively fun))))))
   
 
 ;; Input history processing in a buffer