Subject: 30.0.50; undo confusion

From: Richard Stallman <[email-masked]>
Date: Thu, 23 Feb 2023 22:57:36 -0500

I got incorrect behavior from undo.

I start sending a message and the buffer looks like this:

======================================================================
Content-Type: text/plain; charset=Utf-8
From: Richard Stallman <[email-masked]>
To: 
Subject: 
Reply-To: [email-masked]

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)
======================================================================

The last 5 lines were from `mail-signature'.

I move to the second blank line
and insert `foo bar this is a test.\n'.
I move to after `bar' and type M-, which runs `copy-to-mail':

(defun copy-to-mail ()
  (interactive)
  (let ((string
	 (save-excursion
	   (if (not (memq major-mode '(rmail-mode)))
	       (with-current-buffer (get-buffer "RMAIL")
		 (buffer-substring (point) (mark)))
	     (buffer-substring (region-beginning) (region-end)))))
	(obuf (current-buffer))
	(mailbuf (if (eq major-mode 'mail-mode) (current-buffer)
		   (choose-mail-buffer))))
    (if (get-buffer-window mailbuf)
	(select-window (get-buffer-window mailbuf))
      (switch-to-buffer-other-window mailbuf))
    (let ((opoint (point)))
      (if (and (not (string-match "\`\n" string))
	       (not (bolp)))
	  (insert "\n"))
      (insert string)
      (push-mark opoint)
      (let ((comment-start "  > "))
	(comment-region opoint (point))))))

That inserts the selected region from my RMAIL buffer.  The region starts at
the start of the displayed message.  In my last test, that contained
`From:'.

foo bar
  > From:
this is a test.

I type C-underscore to undo it, but it only partly undoes.
I get this:

foo bar
From:
 this is a test.

Further use of C-understore oscillates between those two.

I have a `mail-setup-hook' function, but I no-op'd it for this test.

I first saw the bug with different text at the start of the message
selected, in various messages.

I've tried it with text not at the start of the message
and it fails the same way.

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 2.24.32, cairo version 1.16.0) of 2022-12-28 built on freetop
Repository revision: efc44727daaee4d3f9aeb19864074472e99b296a
Repository branch: master
System Description: Trisquel GNU/Linux Nabia (10.0)

Configured using:
 'configure x86_64-linux-gnu 'CFLAGS--O0 -g'
 --with-gnutls=ifavailable'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GPM GSETTINGS HARFBUZZ JPEG LIBOTF
LIBSELINUX LIBXML2 M17N_FLT MODULES NOTIFY INOTIFY PDUMPER PNG RSVG
SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XINPUT2
XPM GTK2 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: RMAIL

Minor modes in effect:
  shell-dirtrack-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  buffer-read-only: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: linux
  auto-encryption-mode: t
  auto-compression-mode: t
  abbrev-mode: t

Load-path shadows:
None found.

Features:
(shadow emacsbug find-func shortdoc help-fns radix-tree pulse etags
fileloop generator quail rect xref project novice mule-util
display-line-numbers smerge-mode diff vc cl-extra help-mode parse-time
iso8601 vc-cvs vc-rcs log-view pcvs-util mhtml-mode css-mode smie eww
xdg url-queue mm-url gnus nnheader range wid-edit color js treesit
imenu cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align
cc-engine cc-vars cc-defs sgml-mode facemenu epa-mail goto-addr vc-git
diff-mode easy-mmode vc-dispatcher bug-reference noutline outline
icons misearch multi-isearch rmailkwd rmailout textsec uni-scripts
idna-mapping ucs-normalize uni-confusable textsec-check shr pixel-fill
kinsoku url-file svg xml dom shell pcomplete thingatpt files-x grep
compile comint ansi-osc ansi-color ring jka-compr dabbrev mailalias qp
rmailmm message sendmail yank-media puny rfc822 mml mml-sec epa epg
rfc6068 epg-config gnus-util text-property-search time-date mm-decode
mm-bodies mm-encode mailabbrev gmm-utils mailheader mail-parse rfc2231
dired-aux dired dired-loaddefs term/linux view derived disp-table
advice rmailsum rmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils finder-inf package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie generate-lisp-file
url-domsuf url-util mailcap url-handlers url-parse auth-source cl-seq
eieio eieio-core cl-macs password-cache json subr-x map byte-opt gv
bytecomp byte-compile url-vars cl-loaddefs cl-lib rmc iso-transl
tooltip cconv eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win
x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list
replace newcomment text-mode lisp-mode prog-mode register page tab-bar
menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse
jit-lock font-lock syntax font-core term/tty-colors frame minibuffer
nadvice seq simple cl-generic indonesian philippine cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray
oclosure cl-preloaded button loaddefs theme-loaddefs faces cus-face
macroexp files window text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget keymap hashtable-print-readable
backquote threads dbusbind inotify dynamic-setting system-font-setting
font-render-setting cairo move-toolbar gtk x-toolkit xinput2 x
multi-tty make-network-process emacs)

Memory information:
((conses 16 594416 96510)
 (symbols 48 18080 13)
 (strings 32 87018 9516)
 (string-bytes 1 2276726)
 (vectors 16 69285)
 (vector-slots 8 1633811 188463)
 (floats 8 242 344)
 (intervals 56 61093 913)
 (buffers 976 151))
[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)