Function: comint-insert-input

comint-insert-input is an interactive and byte-compiled function defined in comint.el.gz.

Signature

(comint-insert-input EVENT)

Documentation

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-click).

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/comint.el.gz
(defun comint-insert-input (event)
  "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-click')."
  (interactive "e")
  ;; Don't set the mouse here, since it may otherwise change the behavior
  ;; of the command on which we fallback if there's no field at point.
  ;; (mouse-set-point event)
  (let ((pos (posn-point (event-end event)))
	field input)
    (with-selected-window (posn-window (event-end event))
      ;; If pos is at the very end of a field, the mouse-click was
      ;; probably outside (to the right) of the field.
      (and (< pos (field-end pos))
	   (< (field-end pos) (point-max))
           (progn (setq field (field-at-pos pos))
		  (setq input (field-string-no-properties pos)))))
    (if (or (null input) (null comint-accum-marker) field)
	;; 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 (not (eq fun 'comint-insert-input))
	       (call-interactively fun)))
      (with-selected-window (posn-window (event-end event))
        ;; Otherwise, insert the previous input.
        (goto-char (point-max))
        ;; First delete any old unsent input at the end
        (delete-region
         (or (marker-position comint-accum-marker)
             (process-mark (get-buffer-process (current-buffer))))
         (point))
        ;; Insert the input at point
        (insert input)))))