From unknown Sun Jun 22 00:08:07 2025 X-Loop: help-debbugs@gnu.org Subject: bug#49484: 27.2; [PATCH] Undoing a 'RET' in comint and eshell Resent-From: miha@kamnitnik.top Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 09 Jul 2021 09:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49484 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 49484@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.162582255415488 (code B ref -1); Fri, 09 Jul 2021 09:23:02 +0000 Received: (at submit) by debbugs.gnu.org; 9 Jul 2021 09:22:34 +0000 Received: from localhost ([127.0.0.1]:58356 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m1miP-00041k-Lj for submit@debbugs.gnu.org; Fri, 09 Jul 2021 05:22:34 -0400 Received: from lists.gnu.org ([209.51.188.17]:45922) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m1miK-00041X-RU for submit@debbugs.gnu.org; Fri, 09 Jul 2021 05:22:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1miK-0000Ez-Kl for bug-gnu-emacs@gnu.org; Fri, 09 Jul 2021 05:22:28 -0400 Received: from kamnitnik.top ([209.250.245.214]:44166 helo=mail.kamnitnik.top) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1miH-0002DE-RQ for bug-gnu-emacs@gnu.org; Fri, 09 Jul 2021 05:22:28 -0400 Received: from localhost (unknown [IPv6:2a00:ee2:e04:9300:e609:6c46:d026:8c47]) by mail.kamnitnik.top (Postfix) with ESMTPSA id 28526BBB71 for ; Fri, 9 Jul 2021 09:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kamnitnik.top; s=mail; t=1625822535; bh=Age9peYTinAecLUOoMJOo/9L0tvjsni+ljDgCxdh0sU=; h=From:To:Subject:Date:From; b=gnp6/9Y64D1YeNZ58JdIMPWLAa7ap+lq5OndbGB3jIeTJIli522uYG++LkuW155vm F3swRVWIdTaJn7wJDHgHs4VzsbNOnSCbmD4JnFpr52wUAdwP+0eWtWPX48Y/kIxUPl 7BO5ZUngjC1LOg1ygp3aYhPe3AymcJWJ/BSPUPA/QxBzXJnngqU1T2nZyLm8kC6KFb tfzBPNlgGX0XnAw6VYQJsh22toJ9zUYm/mq5X/4ypu7UMWCoZm+C/T0FLN80ToiRCW lMH7tin3B3c+QdY6vK53CPJpnGhwLmRUDWWYbOQYFEPLw1DAs8K9WdHjWAZcLANQbK H9vxJ0L18Omtg== From: miha@kamnitnik.top Date: Fri, 09 Jul 2021 11:24:11 +0200 Message-ID: <87eec7c01w.fsf@miha-pc> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=209.250.245.214; envelope-from=miha@kamnitnik.top; helo=mail.kamnitnik.top X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.499, FROM_SUSPICIOUS_NTLD_FP=2, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_PDS_OTHER_BAD_TLD=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.1 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 1) M-x shell 2) echo foo RET 3) C-/ to undo this 'RET' The buffer now contain the shell's prompt and "echo foo". However, the process mark is located at eob after "echo foo" 4) Type bar The buffer now [...] Content analysis details: (1.1 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: kamnitnik.top (top)] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 0.9 SPF_FAIL SPF: sender does not match SPF record (fail) [SPF failed: Please see http://www.openspf.org/Why?s=mfrom; id=miha%40kamnitnik.top; ip=209.51.188.17; r=debbugs.gnu.org] -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [209.51.188.17 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [209.51.188.17 listed in wl.mailspike.net] 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 2.0 FROM_SUSPICIOUS_NTLD_FP From abused NTLD X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.9 (-) --=-=-= Content-Type: text/plain 1) M-x shell 2) echo foo RET 3) C-/ to undo this 'RET' The buffer now contain the shell's prompt and "echo foo". However, the process mark is located at eob after "echo foo" 4) Type bar The buffer now contain the shell's prompt and "echo foobar" 5) RET Shell will output "bar: command not found", because the process mark is located before "bar" after "foo". Similar behaviour can be observed with C-c SPC (comint-accumulate) and with eshell. My idea to solve this is to record process mark and related marker positions as `apply' entries in the undo list. Attached patch implements this for comint and eshell. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Improve-undo-in-comint-and-eshell.patch >From fde3b5ce8964e001a9019feff83e267b2cf367dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miha=20Rihtar=C5=A1i=C4=8D?= Date: Fri, 9 Jul 2021 10:57:11 +0200 Subject: [PATCH] Improve undo in comint and eshell * lisp/simple.el (marker-record-undo): New function. * etc/NEWS: * doc/lispref/markers.texi (Moving Markers): Document it. * lisp/comint.el (comint-send-input): (comint-accumulate): (comint-set-process-mark): * lisp/eshell/esh-mode.el (eshell-reset): (eshell-update-markers): Use it to record adjustments to various marker positions in undo list. --- doc/lispref/markers.texi | 17 +++++++++++++++++ etc/NEWS | 5 +++++ lisp/comint.el | 14 ++++++++++---- lisp/eshell/esh-mode.el | 15 ++++++++++----- lisp/simple.el | 18 ++++++++++++++++++ 5 files changed, 60 insertions(+), 9 deletions(-) diff --git a/doc/lispref/markers.texi b/doc/lispref/markers.texi index 80f79b67e5..b0c454be8d 100644 --- a/doc/lispref/markers.texi +++ b/doc/lispref/markers.texi @@ -395,6 +395,23 @@ Moving Markers @defun move-marker marker position &optional buffer This is another name for @code{set-marker}. +@end defun + + Function @code{set-marker} does not record marker movement in the +undo list. Before moving a marker, you can explicitly record its +original position as an undo list entry with +@code{marker-record-undo}. + +@defun marker-record-undo &rest markers +This function records the current position and buffer of each marker +in MARKERS as an entry in the undo list. Undoing it will relocate +these markers to point back to their recorded positions. Passing +markers that currently point nowhere is allowed and undoing will +simply make them point nowhere again. + +Undo in region will always ignore entries made with this function. +Also, this function doesn't do anything if undo is disabled in the +current buffer. @end defun @node The Mark diff --git a/etc/NEWS b/etc/NEWS index da5524a555..2e0e7abc47 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2945,6 +2945,11 @@ The former is now declared obsolete. * Lisp Changes in Emacs 28.1 ++++ +** New function 'marker-record-undo'. +To make marker movement undoable, use this function to store a +marker's current position in the undo list before moving the marker. + --- *** ':safe' settings in 'defcustom' are now propagated to the loaddefs files. diff --git a/lisp/comint.el b/lisp/comint.el index 9e406614b9..f464ecbbe4 100644 --- a/lisp/comint.el +++ b/lisp/comint.el @@ -1931,9 +1931,12 @@ comint-send-input (setq comint-input-ring-index nil) ;; Update the markers before we send the input ;; in case we get output amidst sending the input. + (marker-record-undo + pmark comint-last-input-start comint-last-input-end + comint-accum-marker) (set-marker comint-last-input-start pmark) (set-marker comint-last-input-end (point)) - (set-marker (process-mark proc) (point)) + (set-marker pmark (point)) ;; clear the "accumulation" marker (set-marker comint-accum-marker nil) (let ((comint-input-sender-no-newline no-newline)) @@ -3490,6 +3493,7 @@ comint-accumulate when you send it." (interactive) (insert "\n") + (marker-record-undo comint-accum-marker) (set-marker comint-accum-marker (point)) (if comint-input-ring-index (setq comint-save-input-ring-index @@ -3525,9 +3529,11 @@ comint-bol-or-process-mark (defun comint-set-process-mark () "Set the process mark at point." (interactive) - (let ((proc (or (get-buffer-process (current-buffer)) - (user-error "Current buffer has no process")))) - (set-marker (process-mark proc) (point)) + (let* ((proc (or (get-buffer-process (current-buffer)) + (user-error "Current buffer has no process"))) + (pmark (process-mark proc))) + (marker-record-undo pmark) + (set-marker pmark (point)) (message "Process mark set"))) diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el index f9dbce9770..9aa00016c0 100644 --- a/lisp/eshell/esh-mode.el +++ b/lisp/eshell/esh-mode.el @@ -534,11 +534,14 @@ eshell-reset "Output a prompt on a new line, aborting any current input. If NO-HOOKS is non-nil, then `eshell-post-command-hook' won't be run." (goto-char (point-max)) - (setq eshell-last-input-start (point-marker) - eshell-last-input-end (point-marker) - eshell-last-output-start (point-marker) - eshell-last-output-block-begin (point) - eshell-last-output-end (point-marker)) + (marker-record-undo + eshell-last-input-start eshell-last-input-end + eshell-last-output-start eshell-last-output-end) + (set-marker eshell-last-input-start (point)) + (set-marker eshell-last-input-end (point)) + (set-marker eshell-last-output-start (point)) + (set-marker eshell-last-output-end (point)) + (setq eshell-last-output-block-begin (point)) (eshell-begin-on-new-line) (unless no-hooks (run-hooks 'eshell-post-command-hook) @@ -568,6 +571,8 @@ eshell-parse-command-input (defun eshell-update-markers (pmark) "Update the input and output markers relative to point and PMARK." + (marker-record-undo eshell-last-input-start eshell-last-input-end + eshell-last-output-end) (set-marker eshell-last-input-start pmark) (set-marker eshell-last-input-end (point)) (set-marker eshell-last-output-end (point))) diff --git a/lisp/simple.el b/lisp/simple.el index f746d738a6..337cfe6234 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3466,6 +3466,24 @@ undo-adjust-pos ;; comments. (max (car d) (- pos (cdr d))))))) +(defun marker-record-undo (&rest markers) + "Record positions of MARKERS in the undo list. +Undoing this entry will make each marker in MARKERS point to its +recorded position and buffer, or nowhere if it currently points +nowhere. Undo in region will always ignore these entries. + +If undo is disabled in the current buffer, this function does +nothing." + (let ((undo-list buffer-undo-list)) + (unless (eq undo-list t) + (dolist (marker markers) + (push (list 'apply #'set-marker marker + (marker-position marker) (marker-buffer marker)) + undo-list)) + (setq buffer-undo-list + `((apply ,#'marker-record-undo ,@markers) + ,@undo-list))))) + ;; Return the first affected buffer position and the delta for an undo element ;; delta is defined as the change in subsequent buffer positions if we *did* ;; the undo. -- 2.32.0 --=-=-=-- From unknown Sun Jun 22 00:08:07 2025 X-Loop: help-debbugs@gnu.org Subject: bug#49484: 27.2; [PATCH] Undoing a 'RET' in comint and eshell Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Jul 2021 16:43:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49484 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: miha@kamnitnik.top Cc: 49484@debbugs.gnu.org, Stefan Monnier Received: via spool by 49484-submit@debbugs.gnu.org id=B49484.162593534630467 (code B ref 49484); Sat, 10 Jul 2021 16:43:01 +0000 Received: (at 49484) by debbugs.gnu.org; 10 Jul 2021 16:42:26 +0000 Received: from localhost ([127.0.0.1]:33321 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m2G3d-0007vL-N8 for submit@debbugs.gnu.org; Sat, 10 Jul 2021 12:42:25 -0400 Received: from quimby.gnus.org ([95.216.78.240]:57156) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m2G3a-0007v6-Pr for 49484@debbugs.gnu.org; Sat, 10 Jul 2021 12:42:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Jw3/Hq7AldPnxo5eUjzszSIPbc4m+e4ojubcj+AX5Y0=; b=T1p05Ec0Q3sknwHG9VHOkPgjm+ dP6yhcw5KisV0rcrNnGJHJWIUs16s9PmBg5VVTXTLxYAdGzks5119Y9bxNiBNLHCugwxI2AvUIXh5 zuJjBq39g7w82FSMQ5BaT3JlReVuC1jkFZjte00WVbgCGk8hB+kyKCoB7BTB9Q3oV4EU=; Received: from cm-84.212.220.105.getinternet.no ([84.212.220.105] helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m2G3H-0005m7-Db; Sat, 10 Jul 2021 18:42:09 +0200 From: Lars Ingebrigtsen References: <87eec7c01w.fsf@miha-pc> X-Now-Playing: Suzanne Vega's _Suzanne Vega_: "Cracking" Date: Sat, 10 Jul 2021 18:42:02 +0200 In-Reply-To: <87eec7c01w.fsf@miha-pc> (miha@kamnitnik.top's message of "Fri, 09 Jul 2021 11:24:11 +0200") Message-ID: <87fswmnmsl.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: miha@kamnitnik.top writes: > My idea to solve this is to record process mark and related marker > positions as `apply' entries in the undo list. Attached patch implements > this for comint and eshell. Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -0.3 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) miha@kamnitnik.top writes: > My idea to solve this is to record process mark and related marker > positions as `apply' entries in the undo list. Attached patch implements > this for comint and eshell. Hm, interesting... The patch looks good to me, but I'm not really that familiar with undo internals myself, so it'd be good to get more opinions on this first. So I've added Stefan to the CCs. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From unknown Sun Jun 22 00:08:07 2025 X-Loop: help-debbugs@gnu.org Subject: bug#49484: 27.2; [PATCH] Undoing a 'RET' in comint and eshell Resent-From: Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 18 Jul 2021 07:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49484 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Lars Ingebrigtsen Cc: 49484@debbugs.gnu.org, Stefan Monnier Received: via spool by 49484-submit@debbugs.gnu.org id=B49484.162659378132193 (code B ref 49484); Sun, 18 Jul 2021 07:37:01 +0000 Received: (at 49484) by debbugs.gnu.org; 18 Jul 2021 07:36:21 +0000 Received: from localhost ([127.0.0.1]:55107 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m51LZ-0008NB-EE for submit@debbugs.gnu.org; Sun, 18 Jul 2021 03:36:21 -0400 Received: from kamnitnik.top ([209.250.245.214]:52392 helo=mail.kamnitnik.top) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m51LW-0008N1-Ip for 49484@debbugs.gnu.org; Sun, 18 Jul 2021 03:36:20 -0400 Received: from localhost (unknown [IPv6:2a00:ee2:e04:9300:b7eb:7ae7:cc56:e0da]) by mail.kamnitnik.top (Postfix) with ESMTPSA id 8FB04BBB71; Sun, 18 Jul 2021 07:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kamnitnik.top; s=mail; t=1626593776; bh=mummWhsxgMX19KyZWBqRhJ4Ks+HQNyjJTwHZB/tqMHU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=NR9XtV8drZ1p1lY1yrlahyYNSi7x1dpx9fLCERtxBi050j/ApDGUFvxHo6HMW0Nyh 62LCG1t2mUe9pAyTn6QlaDqxJCp8+JGJ1F9GIBpnhKct22JSfSFYbqChk1p+8c3fzG uqJ5LeaiAGMSpgNNl7GHtlRXv8H8nIKDiyITDRAYy9cKxpIKJEm2iU0009ztbUlvjr rIBr+dQol1Jtig9KlsV+UCjSSp5m7JGRxZIWezQ4OuHuFFlFEMCJfD4ulQOVnWqRli 2d2job5npc9DOcKEDr26/gHSAnC4tcHxK2SpSOBBcjeB7lz/sfLYIJMtSLlUROj7AJ pl8pLvftNOHAQ== From: In-Reply-To: <87fswmnmsl.fsf@gnus.org> References: <87eec7c01w.fsf@miha-pc> <87fswmnmsl.fsf@gnus.org> Date: Sun, 18 Jul 2021 09:42:28 +0200 Message-ID: <86zgukf4pn.fsf@miha-pc> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Lars Ingebrigtsen writes: > miha@kamnitnik.top writes: > >> My idea to solve this is to record process mark and related marker >> positions as `apply' entries in the undo list. Attached patch implements >> this for comint and [...] Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: kamnitnik.top (top)] 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 2.5 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Lars Ingebrigtsen writes: > miha@kamnitnik.top writes: > >> My idea to solve this is to record process mark and related marker >> positions as `apply' entries in the undo list. Attached patch implements >> this for comint and [...] Content analysis details: (2.5 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 2.0 PDS_OTHER_BAD_TLD Untrustworthy TLDs [URI: kamnitnik.top (top)] 1.0 BULK_RE_SUSP_NTLD Precedence bulk and RE: from a suspicious TLD 0.5 FROM_SUSPICIOUS_NTLD From abused NTLD -1.0 MAILING_LIST_MULTI Multiple indicators imply a widely-seen list manager --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: > miha@kamnitnik.top writes: > >> My idea to solve this is to record process mark and related marker >> positions as `apply' entries in the undo list. Attached patch implements >> this for comint and eshell. > > Hm, interesting... The patch looks good to me, but I'm not really that > familiar with undo internals myself, so it'd be good to get more > opinions on this first. So I've added Stefan to the CCs. So after thinking about this some more, I arrived at a simpler solution: deleting and reinserting text to generate suitable undo list entries instead of adding them explicitly. As opposed to the first patch, this one should also handle undo-in-region reasonably well. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Improve-undoing-of-RET-in-comint-and-eshell.patch Content-Transfer-Encoding: quoted-printable From=20ad98e21545e5d248e13ef8b124b42ca4f0215f6e Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Miha=3D20Rihtar=3DC5=3DA1i=3DC4=3D8D?=3D Date: Fri, 16 Jul 2021 17:08:12 +0200 Subject: [PATCH] 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. =2D-- lisp/comint.el | 24 +++++++++++++++++++++++- lisp/eshell/esh-mode.el | 8 ++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lisp/comint.el b/lisp/comint.el index 9e406614b9..f24ec4b6bf 100644 =2D-- a/lisp/comint.el +++ b/lisp/comint.el @@ -1890,6 +1890,14 @@ comint-send-input (delete-region pmark start) copy)))) =20 + ;; Delete and reinsert input. This seems like a no-op, except + ;; for the resulting entries in the undo list: undoing this + ;; insertion will delete the region, moving the process mark + ;; back to its original position. + (let ((inhibit-read-only t)) + (delete-region pmark (point)) + (insert input)) + (unless no-newline (insert ?\n)) =20 @@ -1933,7 +1941,7 @@ comint-send-input ;; in case we get output amidst sending the input. (set-marker comint-last-input-start pmark) (set-marker comint-last-input-end (point)) =2D (set-marker (process-mark proc) (point)) + (set-marker pmark (point)) ;; clear the "accumulation" marker (set-marker comint-accum-marker nil) (let ((comint-input-sender-no-newline no-newline)) @@ -3489,6 +3497,20 @@ comint-accumulate The entire accumulated text becomes one item in the input history when you send it." (interactive) + (when-let* ((proc (get-buffer-process (current-buffer))) + (pmark (process-mark proc)) + ((or (marker-position comint-accum-marker) + (set-marker comint-accum-marker pmark) + t)) + ((>=3D (point) comint-accum-marker pmark))) + ;; Delete and reinsert input. This seems like a no-op, except for + ;; the resulting entries in the undo list: undoing this insertion + ;; will delete the region, moving the accumulation marker back to + ;; its original position. + (let ((text (buffer-substring comint-accum-marker (point))) + (inhibit-read-only t)) + (delete-region comint-accum-marker (point)) + (insert text))) (insert "\n") (set-marker comint-accum-marker (point)) (if comint-input-ring-index diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el index f9dbce9770..92e1e9eb6a 100644 =2D-- a/lisp/eshell/esh-mode.el +++ b/lisp/eshell/esh-mode.el @@ -614,6 +614,14 @@ eshell-send-input (and eshell-send-direct-to-subprocesses proc-running-p)) (insert-before-markers-and-inherit ?\n)) + ;; Delete and reinsert input. This seems like a no-op, except + ;; for the resulting entries in the undo list: undoing this + ;; insertion will delete the region, moving the process mark + ;; back to its original position. + (let ((text (buffer-substring eshell-last-output-end (point))) + (inhibit-read-only t)) + (delete-region eshell-last-output-end (point)) + (insert text)) (if proc-running-p (progn (eshell-update-markers eshell-last-output-end) =2D-=20 2.32.0 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJHBAEBCAAxFiEEmxVnesoT5rQXvVXnswkaGpIVmT8FAmDz22UTHG1paGFAa2Ft bml0bmlrLnRvcAAKCRCzCRoakhWZP2vED/47E/0KpeMbj4NrQo4piK3d4NOZUSV0 /e6zM+QOat67jxno9e12lInChUT4k6NEDovMemAVNIAw6bxCX+qjI3bVGX9jmrX+ Q3hV+8DyM6MLDgLwbYRaxw7yfiCjiJkQxFyTOooJNUZiffu99lrT9PJEPGBjMAe8 5Buy3bTshFlFy4Z6XgzZ6U5ghUjy93mWLE7mugaLhU6r9Vfx+6uXFl3rTFRCVoi9 bDPFz6d6aP67TX9lSZSdXngdAUMlWNzMEKTo2qhvUNXd8cP5To4gFoajyZw1EKXD GJQmNAtbSy6O+dR5y6tcLkM714bVVYZ+080KMlUvf9LAEqK+ChIPs8mMSpCFvPRP T79bURZue4GWB8kDBSBuu6koa4EQbYRtzu1W2TDc5yNHiaQC7lw5yDwQJ+LUFrZe J7SsMBN7lklMb3QId21zSX31h7Hy9nNfAhyjf0YLilzXxf9XNXxnka2NcOoEeLHs fTQiDrgwltFXlq/wZpcq1SKMExqBngTKWvv8cE3gQ4R3pfl3czCid4jy+Retx+WU sICh+jFRmLhxuNR1YLadNJU33pCZZrjDnPE9tTi14QeJV8MRL8ouEzrptzjwB2U/ GuNhkTnJJXROIQzT9qvyYwvcUMxf5FmHrJS6wLi37fOcCvFAl/vBMolhBw0v7Cht FRapGjA+1rbhJQ== =jlk0 -----END PGP SIGNATURE----- --==-=-=-- From unknown Sun Jun 22 00:08:07 2025 X-Loop: help-debbugs@gnu.org Subject: bug#49484: 27.2; [PATCH] Undoing a 'RET' in comint and eshell Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 07 Nov 2021 23:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49484 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Cc: 49484@debbugs.gnu.org, Stefan Monnier Received: via spool by 49484-submit@debbugs.gnu.org id=B49484.163632671826202 (code B ref 49484); Sun, 07 Nov 2021 23:12:02 +0000 Received: (at 49484) by debbugs.gnu.org; 7 Nov 2021 23:11:58 +0000 Received: from localhost ([127.0.0.1]:55217 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mjrKP-0006oY-Sv for submit@debbugs.gnu.org; Sun, 07 Nov 2021 18:11:58 -0500 Received: from quimby.gnus.org ([95.216.78.240]:39912) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mjrKO-0006oI-2Z for 49484@debbugs.gnu.org; Sun, 07 Nov 2021 18:11:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ihvMrg+jVhA0/N1Q4AfFWwf2me4BUs1fuT/a/Uy9LZM=; b=K3K6OtlsLxCB9u++j/W0ynYy1a 2c2pF054C4InW4iKD5AY0lHI2Zy9V6T300h6827FXD53UcMCIoo8ZeIXP0JvBvOHxGYL6zySMmMhw BTPfhFDlFxVz9BtPe7/b3yEVE3Iaim4o2O+EHTUWLK3Dq+vvRFT2EQH03vAt630l4Bpg=; Received: from [84.212.220.105] (helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mjrKD-0004em-Tv; Mon, 08 Nov 2021 00:11:48 +0100 From: Lars Ingebrigtsen References: <87eec7c01w.fsf@miha-pc> <87fswmnmsl.fsf@gnus.org> <86zgukf4pn.fsf@miha-pc> X-Now-Playing: Leslie Winer's _When I Hit You, You'll Feel It_: "He Was" Date: Mon, 08 Nov 2021 00:11:45 +0100 In-Reply-To: <86zgukf4pn.fsf@miha-pc> (miha@kamnitnik.top's message of "Sun, 18 Jul 2021 09:42:28 +0200") Message-ID: <878rxzef2m.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: writes: > So after thinking about this some more, I arrived at a simpler solution: > deleting and reinserting text to generate suitable undo list entries > instead of adding them explicitly. > As opposed to t [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -0.3 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.3 (-) writes: > So after thinking about this some more, I arrived at a simpler solution: > deleting and reinserting text to generate suitable undo list entries > instead of adding them explicitly. > As opposed to the first patch, this one should also handle > undo-in-region reasonably well. Thanks, I've now finally tested this, and it seems to work perfectly, so I've now pushed it to Emacs 29. Sorry for the delay. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From debbugs-submit-bounces@debbugs.gnu.org Sun Nov 07 18:12:02 2021 Received: (at control) by debbugs.gnu.org; 7 Nov 2021 23:12:02 +0000 Received: from localhost ([127.0.0.1]:55220 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mjrKU-0006or-3X for submit@debbugs.gnu.org; Sun, 07 Nov 2021 18:12:02 -0500 Received: from quimby.gnus.org ([95.216.78.240]:39924) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mjrKS-0006oQ-BM for control@debbugs.gnu.org; Sun, 07 Nov 2021 18:12:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Subject:From:To:Message-Id:Date:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=kWU+JyYHiICSK2gZpxKtrAwXZJygDklfMY0vA02Tvmk=; b=aoanUJhJ7RnfHnHO2GkaZ4e51J 7is/YtGBc2qI9EoFuQ4Jo5jggY+V7GyjtYpKx4XczLYolwyTwUHMijWixuYJ7UNRECJ7C6+G9Nw/5 54kTmGy7i4bsv4Bbjnw2w1VDqHv4eNCUsMkxJ01pC6Sv3O8yGTrH7/UZzhJ6M02MsVjM=; Received: from [84.212.220.105] (helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mjrKK-0004et-RW for control@debbugs.gnu.org; Mon, 08 Nov 2021 00:11:54 +0100 Date: Mon, 08 Nov 2021 00:11:52 +0100 Message-Id: <877ddjef2f.fsf@gnus.org> To: control@debbugs.gnu.org From: Lars Ingebrigtsen Subject: control message for bug #49484 X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: close 49484 29.1 quit Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) close 49484 29.1 quit