From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: miha--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#49484: 27.2; [PATCH] Undoing a 'RET' in comint and eshell Date: Sun, 18 Jul 2021 09:42:28 +0200 Message-ID: <86zgukf4pn.fsf@miha-pc> References: <87eec7c01w.fsf@miha-pc> <87fswmnmsl.fsf@gnus.org> Reply-To: Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24833"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 49484@debbugs.gnu.org, Stefan Monnier To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 18 09:37:10 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m51ML-0006HD-KZ for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Jul 2021 09:37:09 +0200 Original-Received: from localhost ([::1]:40028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m51MK-0006d3-4Q for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Jul 2021 03:37:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m51ME-0006cr-8A for bug-gnu-emacs@gnu.org; Sun, 18 Jul 2021 03:37:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43561) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m51MD-00044k-Tn for bug-gnu-emacs@gnu.org; Sun, 18 Jul 2021 03:37:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m51MD-0008O7-Mr for bug-gnu-emacs@gnu.org; Sun, 18 Jul 2021 03:37:01 -0400 X-Loop: help-debbugs@gnu.org 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 Original-Received: via spool by 49484-submit@debbugs.gnu.org id=B49484.162659378132193 (code B ref 49484); Sun, 18 Jul 2021 07:37:01 +0000 Original-Received: (at 49484) by debbugs.gnu.org; 18 Jul 2021 07:36:21 +0000 Original-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 Original-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 Original-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== In-Reply-To: <87fswmnmsl.fsf@gnus.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:210163 Archived-At: --==-=-= 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----- --==-=-=--