diff options
| author | Miha Rihtaršič | 2021-11-08 00:10:03 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-11-08 00:10:03 +0100 |
| commit | 4268d9a2b6bc96c0ae2448c6694bbd765fc577a7 (patch) | |
| tree | 635a5716671301718d8459698fb8f2dee879aa4a /lisp | |
| parent | 5f70682d7b8a3550bf6b9366329ad3418ab0a95f (diff) | |
| download | emacs-4268d9a2b6bc96c0ae2448c6694bbd765fc577a7.tar.gz emacs-4268d9a2b6bc96c0ae2448c6694bbd765fc577a7.zip | |
Improve undoing of RET in comint and eshell
* lisp/comint.el (comint-send-input):
(comint-accumulate):
* lisp/eshell/esh-mode.el (eshell-send-input): Before sending input to
the process, delete it and reinsert it again. Undoing this
insertion with 'C-/' will delete the region, moving the process mark
back to its original position (bug#49484).
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/comint.el | 24 | ||||
| -rw-r--r-- | lisp/eshell/esh-mode.el | 8 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lisp/comint.el b/lisp/comint.el index adae971eff2..544f0b8b820 100644 --- a/lisp/comint.el +++ b/lisp/comint.el | |||
| @@ -1907,6 +1907,14 @@ Similarly for Soar, Scheme, etc." | |||
| 1907 | (delete-region pmark start) | 1907 | (delete-region pmark start) |
| 1908 | copy)))) | 1908 | copy)))) |
| 1909 | 1909 | ||
| 1910 | ;; Delete and reinsert input. This seems like a no-op, except | ||
| 1911 | ;; for the resulting entries in the undo list: undoing this | ||
| 1912 | ;; insertion will delete the region, moving the process mark | ||
| 1913 | ;; back to its original position. | ||
| 1914 | (let ((inhibit-read-only t)) | ||
| 1915 | (delete-region pmark (point)) | ||
| 1916 | (insert input)) | ||
| 1917 | |||
| 1910 | (unless no-newline | 1918 | (unless no-newline |
| 1911 | (insert ?\n)) | 1919 | (insert ?\n)) |
| 1912 | 1920 | ||
| @@ -1950,7 +1958,7 @@ Similarly for Soar, Scheme, etc." | |||
| 1950 | ;; in case we get output amidst sending the input. | 1958 | ;; in case we get output amidst sending the input. |
| 1951 | (set-marker comint-last-input-start pmark) | 1959 | (set-marker comint-last-input-start pmark) |
| 1952 | (set-marker comint-last-input-end (point)) | 1960 | (set-marker comint-last-input-end (point)) |
| 1953 | (set-marker (process-mark proc) (point)) | 1961 | (set-marker pmark (point)) |
| 1954 | ;; clear the "accumulation" marker | 1962 | ;; clear the "accumulation" marker |
| 1955 | (set-marker comint-accum-marker nil) | 1963 | (set-marker comint-accum-marker nil) |
| 1956 | (let ((comint-input-sender-no-newline no-newline)) | 1964 | (let ((comint-input-sender-no-newline no-newline)) |
| @@ -3520,6 +3528,20 @@ to send all the accumulated input, at once. | |||
| 3520 | The entire accumulated text becomes one item in the input history | 3528 | The entire accumulated text becomes one item in the input history |
| 3521 | when you send it." | 3529 | when you send it." |
| 3522 | (interactive) | 3530 | (interactive) |
| 3531 | (when-let* ((proc (get-buffer-process (current-buffer))) | ||
| 3532 | (pmark (process-mark proc)) | ||
| 3533 | ((or (marker-position comint-accum-marker) | ||
| 3534 | (set-marker comint-accum-marker pmark) | ||
| 3535 | t)) | ||
| 3536 | ((>= (point) comint-accum-marker pmark))) | ||
| 3537 | ;; Delete and reinsert input. This seems like a no-op, except for | ||
| 3538 | ;; the resulting entries in the undo list: undoing this insertion | ||
| 3539 | ;; will delete the region, moving the accumulation marker back to | ||
| 3540 | ;; its original position. | ||
| 3541 | (let ((text (buffer-substring comint-accum-marker (point))) | ||
| 3542 | (inhibit-read-only t)) | ||
| 3543 | (delete-region comint-accum-marker (point)) | ||
| 3544 | (insert text))) | ||
| 3523 | (insert "\n") | 3545 | (insert "\n") |
| 3524 | (set-marker comint-accum-marker (point)) | 3546 | (set-marker comint-accum-marker (point)) |
| 3525 | (if comint-input-ring-index | 3547 | (if comint-input-ring-index |
diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el index 2b5a4647e06..a054cd66e27 100644 --- a/lisp/eshell/esh-mode.el +++ b/lisp/eshell/esh-mode.el | |||
| @@ -616,6 +616,14 @@ newline." | |||
| 616 | (and eshell-send-direct-to-subprocesses | 616 | (and eshell-send-direct-to-subprocesses |
| 617 | proc-running-p)) | 617 | proc-running-p)) |
| 618 | (insert-before-markers-and-inherit ?\n)) | 618 | (insert-before-markers-and-inherit ?\n)) |
| 619 | ;; Delete and reinsert input. This seems like a no-op, except | ||
| 620 | ;; for the resulting entries in the undo list: undoing this | ||
| 621 | ;; insertion will delete the region, moving the process mark | ||
| 622 | ;; back to its original position. | ||
| 623 | (let ((text (buffer-substring eshell-last-output-end (point))) | ||
| 624 | (inhibit-read-only t)) | ||
| 625 | (delete-region eshell-last-output-end (point)) | ||
| 626 | (insert text)) | ||
| 619 | (if proc-running-p | 627 | (if proc-running-p |
| 620 | (progn | 628 | (progn |
| 621 | (eshell-update-markers eshell-last-output-end) | 629 | (eshell-update-markers eshell-last-output-end) |