GNU bug report logs - #79551
[PATCH] Improve undo behavior in Rcirc

Previous Next

Package: emacs;

Reported by: Alcor <alcor <at> tilde.club>

Date: Wed, 1 Oct 2025 18:38:02 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 79551 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#79551; Package emacs. (Wed, 01 Oct 2025 18:38:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alcor <alcor <at> tilde.club>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 01 Oct 2025 18:38:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Alcor <alcor <at> tilde.club>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Improve undo behavior in Rcirc
Date: Wed, 01 Oct 2025 20:36:58 +0200
[Message part 1 (text/plain, inline)]
Tags: patch

Hello,

The attached minimal patch improves the undo behavior in Rcirc by
restricting changes to `buffer-undo-list' in such a way that Rcirc's own
display routines no longer affect it.

It does so by binding `buffer-undo-list' to t within Rcirc's own display
procedures. Additionally, the undo offsets within the `buffer-undo-list'
are also shifted accordingly whenever Rcirc inserts text before the
prompt (such as when receiving messages).

The patch is fairly compact and straightforward. Please note that the
new procedure `rcirc-update-undo-list' is a renamed verbatim copy of
`erc-update-undo-list' from lisp/erc/erc.el.

Cheers,
-A

In GNU Emacs 30.2 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.41,
 cairo version 1.18.0) of 2025-09-22 built on lcy02-amd64-009
Repository revision: ff7d3f02b943af29afb1c68a2b31f88441dee928
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12302006
System Description: Ubuntu 24.04.3 LTS

Configured using:
 'configure --prefix=/snap/emacs/current/usr --with-x-toolkit=gtk3
 --without-xaw3d --with-modules --with-cairo
 --with-native-compilation=aot --without-pgtk --with-xinput2
 --with-tree-sitter 'CFLAGS=-isystem
 /build/emacs/parts/emacs/install/usr/include -isystem
 /build/emacs/parts/emacs/install/usr/include/x86_64-linux-gnu -isystem
 /build/emacs/stage/usr/include -O2' 'CPPFLAGS=-isystem
 /build/emacs/parts/emacs/install/usr/include -isystem
 /build/emacs/parts/emacs/install/usr/include/x86_64-linux-gnu -isystem
 /build/emacs/stage/usr/include'
 'LDFLAGS=-L/build/emacs/parts/emacs/install/lib
 -L/build/emacs/parts/emacs/install/usr/lib
 -L/build/emacs/parts/emacs/install/lib/x86_64-linux-gnu
 -L/build/emacs/parts/emacs/install/usr/lib/x86_64-linux-gnu
 -L/build/emacs/stage/usr/lib''

[0001-Improve-undo-behavior-in-Rcirc.patch (text/patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79551; Package emacs. (Fri, 10 Oct 2025 21:33:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: Alcor via "Bug reports for GNU Emacs, the Swiss army knife of text
 editors" <bug-gnu-emacs <at> gnu.org>
Cc: 79551 <at> debbugs.gnu.org, Alcor <alcor <at> tilde.club>
Subject: Re: bug#79551: [PATCH] Improve undo behavior in Rcirc
Date: Fri, 10 Oct 2025 21:32:12 +0000
Alcor via "Bug reports for GNU Emacs, the Swiss army knife of text
editors" <bug-gnu-emacs <at> gnu.org> writes:

> Tags: patch
>
> Hello,
>
> The attached minimal patch improves the undo behavior in Rcirc by
> restricting changes to `buffer-undo-list' in such a way that Rcirc's own
> display routines no longer affect it.
>
> It does so by binding `buffer-undo-list' to t within Rcirc's own display
> procedures. Additionally, the undo offsets within the `buffer-undo-list'
> are also shifted accordingly whenever Rcirc inserts text before the
> prompt (such as when receiving messages).
>
> The patch is fairly compact and straightforward. Please note that the
> new procedure `rcirc-update-undo-list' is a renamed verbatim copy of
> `erc-update-undo-list' from lisp/erc/erc.el.
>
> Cheers,
> -A
>
> In GNU Emacs 30.2 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.41,
>  cairo version 1.18.0) of 2025-09-22 built on lcy02-amd64-009
> Repository revision: ff7d3f02b943af29afb1c68a2b31f88441dee928
> Repository branch: master
> Windowing system distributor 'The X.Org Foundation', version 11.0.12302006
> System Description: Ubuntu 24.04.3 LTS
>
> Configured using:
>  'configure --prefix=/snap/emacs/current/usr --with-x-toolkit=gtk3
>  --without-xaw3d --with-modules --with-cairo
>  --with-native-compilation=aot --without-pgtk --with-xinput2
>  --with-tree-sitter 'CFLAGS=-isystem
>  /build/emacs/parts/emacs/install/usr/include -isystem
>  /build/emacs/parts/emacs/install/usr/include/x86_64-linux-gnu -isystem
>  /build/emacs/stage/usr/include -O2' 'CPPFLAGS=-isystem
>  /build/emacs/parts/emacs/install/usr/include -isystem
>  /build/emacs/parts/emacs/install/usr/include/x86_64-linux-gnu -isystem
>  /build/emacs/stage/usr/include'
>  'LDFLAGS=-L/build/emacs/parts/emacs/install/lib
>  -L/build/emacs/parts/emacs/install/usr/lib
>  -L/build/emacs/parts/emacs/install/lib/x86_64-linux-gnu
>  -L/build/emacs/parts/emacs/install/usr/lib/x86_64-linux-gnu
>  -L/build/emacs/stage/usr/lib''
>
> From fb3a8b70448a21d359d104071085d0f7d1985531 Mon Sep 17 00:00:00 2001
> From: Alcor <alcor <at> tilde.club>
> Date: Wed, 1 Oct 2025 20:05:53 +0200
> Subject: [PATCH] Improve undo behavior in Rcirc
>
> * lisp/net/rcirc.el (rcirc-update-prompt): Don't track undo info.
> (rcirc-send-input): Clear undo list after message is sent.
> (rcirc-update-undo-list): Add new function (copied from erc.el).
> (rcirc-print): Update (shift) undo list instead of clearing it.
> ---
>  lisp/net/rcirc.el | 41 +++++++++++++++++++++++++++++++++++------
>  1 file changed, 35 insertions(+), 6 deletions(-)
>
> diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
> index a7f1d8b..f6bf4a3 100644
> --- a/lisp/net/rcirc.el
> +++ b/lisp/net/rcirc.el
> @@ -1577,7 +1577,8 @@ If ALL is non-nil, update prompts in all IRC buffers."
>                      (with-rcirc-process-buffer process
>                        (mapcar 'cdr rcirc-buffer-alist))))
>              (rcirc-process-list))
> -    (let ((inhibit-read-only t)
> +    (let ((buffer-undo-list t)
> +          (inhibit-read-only t)
>            (prompt (or rcirc-prompt "")))
>        (mapc (lambda (rep)
>                (setq prompt
> @@ -1729,6 +1730,7 @@ Create the buffer if it doesn't exist."
>                      rcirc-prompt-end-marker (point))))
>          (dolist (line (split-string input "\n"))
>            (rcirc-process-input-line line))
> +        (setq buffer-undo-list nil)
>          ;; add to input-ring
>          (save-excursion
>            (ring-insert rcirc-input-ring input)
> @@ -2014,6 +2016,30 @@ PROCESS is the process object for the current connection."
>                 (> last-activity-line 0))
>        (- rcirc-current-line last-activity-line))))
>  
> +(defun rcirc-update-undo-list (shift)
> +  ;; Translate buffer positions in buffer-undo-list by SHIFT.

Please write this as a proper docstring!

> +  ;; Copied from erc.el
> +  (unless (or (zerop shift) (atom buffer-undo-list))
> +    (let ((list buffer-undo-list) elt)
> +      (while list
> +        (setq elt (car list))
> +        (cond ((integerp elt)           ; POSITION
> +               (cl-incf (car list) shift))

As we would apply the patch on master, you can just use `incf'.

> +              ((or (atom elt)           ; nil, EXTENT
> +                   ;; (eq t (car elt))  ; (t . TIME)
> +                   (markerp (car elt))) ; (MARKER . DISTANCE)
> +               nil)
> +              ((integerp (car elt))     ; (BEGIN . END)
> +               (cl-incf (car elt) shift)
> +               (cl-incf (cdr elt) shift))
> +              ((stringp (car elt))      ; (TEXT . POSITION)
> +               (cl-incf (cdr elt) (* (if (natnump (cdr elt)) 1 -1) shift)))
> +              ((null (car elt))         ; (nil PROPERTY VALUE BEG . END)
> +               (let ((cons (nthcdr 3 elt)))
> +                 (cl-incf (car cons) shift)
> +                 (cl-incf (cdr cons) shift))))
> +        (setq list (cdr list))))))
> +
>  (defvar rcirc-markup-text-functions
>    '(rcirc-markup-attributes
>      rcirc-color-attributes
> @@ -2042,13 +2068,16 @@ connection."
>                             rcirc-ignore-list))
>                 ;; do not ignore if we sent the message
>                 (not (string= sender (rcirc-nick process))))
> -    (let* ((buffer (rcirc-target-buffer process sender response target text))
> +    (let* (preinsert-prompt-end-position
> +           (buffer (rcirc-target-buffer process sender response target text))
>             (time (if-let* ((time (rcirc-get-tag "time")))
>                       (parse-iso8601-time-string time t)
>                     (current-time)))
>             (inhibit-read-only t))
>        (with-current-buffer buffer
> -        (let ((moving (= (point) rcirc-prompt-end-marker))
> +        (setq preinsert-prompt-end-position (marker-position rcirc-prompt-end-marker))
> +        (let ((buffer-undo-list t)
> +              (moving (= (point) rcirc-prompt-end-marker))
>                (old-point (point-marker)))
>  
>            (setq text (decode-coding-string text rcirc-decode-coding-system))
> @@ -2154,9 +2183,9 @@ connection."
>                              0)
>                      (recenter -1)))))))
>  
> -        ;; flush undo (can we do something smarter here?)
> -        (buffer-disable-undo)
> -        (buffer-enable-undo)
> +        ;; shift undo positions
> +        (rcirc-update-undo-list (- rcirc-prompt-end-marker
> +                                   preinsert-prompt-end-position))
>  
>          ;; record mode line activity
>          (when (and activity

I'll have to try it out, but the rest seems fine.  It it also blocked by
your CA process, unless there has been news that I have missed?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79551; Package emacs. (Fri, 10 Oct 2025 21:33:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79551; Package emacs. (Mon, 13 Oct 2025 18:03:02 GMT) Full text and rfc822 format available.

Message #14 received at 79551 <at> debbugs.gnu.org (full text, mbox):

From: alcor <at> tilde.club
To: "Philip Kaludercic" <philipk <at> posteo.net>, "Bug reports for GNU Emacs, the
 Swiss army knife of text  editors" <bug-gnu-emacs <at> gnu.org>
Cc: 79551 <at> debbugs.gnu.org
Subject: Re: bug#79551: [PATCH] Improve undo behavior in Rcirc
Date: Mon, 13 Oct 2025 18:02:55 +0000
[Message part 1 (text/plain, inline)]
Am 10. Oktober 2025 um 23:32 schrieb "Philip Kaludercic" <philipk <at> posteo.net>:

> Please write this as a proper docstring!

Done in the revised patch (see attachment).

> As we would apply the patch on master, you can just use `incf'.

Also done in the revised patch.

> I'll have to try it out, but the rest seems fine. It it also blocked by
> your CA process, unless there has been news that I have missed?

The required documents have been sent off-list.

Cheers,
-F.M.
[0001-Improve-undo-behavior-in-Rcirc.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79551; Package emacs. (Mon, 13 Oct 2025 18:04:01 GMT) Full text and rfc822 format available.

This bug report was last modified 24 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.