diff options
| -rw-r--r-- | lisp/comint.el | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/lisp/comint.el b/lisp/comint.el index cd5a9a9c13a..26b0add8b76 100644 --- a/lisp/comint.el +++ b/lisp/comint.el | |||
| @@ -803,17 +803,27 @@ buffer. The hook `comint-exec-hook' is run after each exec." | |||
| 803 | proc)) | 803 | proc)) |
| 804 | 804 | ||
| 805 | (defun comint-insert-input (event) | 805 | (defun comint-insert-input (event) |
| 806 | "In a Comint buffer, set the current input to the previous input at point." | 806 | "In a Comint buffer, set the current input to the previous input at point. |
| 807 | If there is no previous input at point, run the command specified | ||
| 808 | by the global keymap (usually `mouse-yank-at-point')." | ||
| 807 | (interactive "e") | 809 | (interactive "e") |
| 808 | (mouse-set-point event) | 810 | (let ((pos (posn-point (event-end event))) |
| 809 | (let ((pos (point))) | 811 | field input) |
| 810 | (if (not (eq (field-at-pos pos) 'input)) | 812 | (with-selected-window (posn-window (event-end event)) |
| 811 | ;; No input at POS, fall back to the global definition. | 813 | (and (setq field (field-at-pos pos)) |
| 814 | (setq input (field-string-no-properties pos)))) | ||
| 815 | (if (or (null comint-accum-marker) | ||
| 816 | (not (eq field 'input))) | ||
| 817 | ;; Fall back to the global definition if (i) the selected | ||
| 818 | ;; buffer is not a comint buffer (which can happen if a | ||
| 819 | ;; non-comint window was selected and we clicked in a comint | ||
| 820 | ;; window), or (ii) there is no input at POS. | ||
| 812 | (let* ((keys (this-command-keys)) | 821 | (let* ((keys (this-command-keys)) |
| 813 | (last-key (and (vectorp keys) (aref keys (1- (length keys))))) | 822 | (last-key (and (vectorp keys) (aref keys (1- (length keys))))) |
| 814 | (fun (and last-key (lookup-key global-map (vector last-key))))) | 823 | (fun (and last-key (lookup-key global-map (vector last-key))))) |
| 815 | (and fun (call-interactively fun))) | 824 | (and fun (not (eq fun 'comint-insert-input)) |
| 816 | ;; There's previous input at POS, insert it at the end of the buffer. | 825 | (call-interactively fun))) |
| 826 | ;; Otherwise, insert the previous input. | ||
| 817 | (goto-char (point-max)) | 827 | (goto-char (point-max)) |
| 818 | ;; First delete any old unsent input at the end | 828 | ;; First delete any old unsent input at the end |
| 819 | (delete-region | 829 | (delete-region |
| @@ -821,8 +831,7 @@ buffer. The hook `comint-exec-hook' is run after each exec." | |||
| 821 | (process-mark (get-buffer-process (current-buffer)))) | 831 | (process-mark (get-buffer-process (current-buffer)))) |
| 822 | (point)) | 832 | (point)) |
| 823 | ;; Insert the input at point | 833 | ;; Insert the input at point |
| 824 | (insert (field-string-no-properties pos))))) | 834 | (insert input)))) |
| 825 | |||
| 826 | 835 | ||
| 827 | ;; Input history processing in a buffer | 836 | ;; Input history processing in a buffer |
| 828 | ;; =========================================================================== | 837 | ;; =========================================================================== |