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
(process-mark (get-buffer-process (current-buffer))))
(point))
;; Insert the input at point
- (insert (field-string-no-properties pos)))))
-
+ (insert input))))
\f
;; Input history processing in a buffer
;; ===========================================================================