1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-02-02 21:52:04 -08:00

(comint-insert-input): Handle situation where the selected buffer is

not the clicked buffer.
This commit is contained in:
Chong Yidong 2007-01-29 02:31:22 +00:00
parent 0e66b003a7
commit 445de73cf6

View file

@ -803,17 +803,27 @@ buffer. The hook `comint-exec-hook' is run after each exec."
proc))
(defun comint-insert-input (event)
"In a Comint buffer, set the current input to the previous input at point."
"In a Comint buffer, set the current input to the previous input at point.
If there is no previous input at point, run the command specified
by the global keymap (usually `mouse-yank-at-point')."
(interactive "e")
(mouse-set-point event)
(let ((pos (point)))
(if (not (eq (field-at-pos pos) 'input))
;; No input at POS, fall back to the global definition.
(let ((pos (posn-point (event-end event)))
field input)
(with-selected-window (posn-window (event-end event))
(and (setq field (field-at-pos pos))
(setq input (field-string-no-properties pos))))
(if (or (null comint-accum-marker)
(not (eq field 'input)))
;; Fall back to the global definition if (i) the selected
;; buffer is not a comint buffer (which can happen if a
;; non-comint window was selected and we clicked in a comint
;; window), or (ii) there is no input at POS.
(let* ((keys (this-command-keys))
(last-key (and (vectorp keys) (aref keys (1- (length keys)))))
(fun (and last-key (lookup-key global-map (vector last-key)))))
(and fun (call-interactively fun)))
;; There's previous input at POS, insert it at the end of the buffer.
(and fun (not (eq fun 'comint-insert-input))
(call-interactively fun)))
;; Otherwise, insert the previous input.
(goto-char (point-max))
;; First delete any old unsent input at the end
(delete-region
@ -821,8 +831,7 @@ buffer. The hook `comint-exec-hook' is run after each exec."
(process-mark (get-buffer-process (current-buffer))))
(point))
;; Insert the input at point
(insert (field-string-no-properties pos)))))
(insert input))))
;; Input history processing in a buffer
;; ===========================================================================