GNU bug report logs - #78965
31.0.50; exchange-point-and-mark can create duplicate adjacent entries in mark-ring

Previous Next

Package: emacs;

Reported by: Jake <jforst.mailman <at> gmail.com>

Date: Sun, 6 Jul 2025 03:10:03 UTC

Severity: normal

Found in version 31.0.50

To reply to this bug, email your comments to 78965 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#78965; Package emacs. (Sun, 06 Jul 2025 03:10:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jake <jforst.mailman <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 06 Jul 2025 03:10:04 GMT) Full text and rfc822 format available.

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

From: Jake <jforst.mailman <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; exchange-point-and-mark can create duplicate adjacent
 entries in mark-ring
Date: Sun, 6 Jul 2025 03:09:26 +0000
Hello

If you have >= 1 mark in the local mark ring, use `set-mark-command`
with prefix argument ("C-u C-SPC") and then `exchange-point-and-mark`
("C-x C-x"), mark is equal to the last element in the local mark ring.
If you then "C-u C-SPC", the last 2 elements in the local mark ring
contain the same marker position.

Is that useful for anything?  It seems suboptimal when cycling through
the mark ring.  I think it would be similar to if `set-mark-command`
allowed the same marker position to be repeatedly pushed onto the mark
ring, which it doesn't.

Any thoughts?

The below patch seems to address the issue.

Thanks
Jake

diff --git a/lisp/simple.el b/lisp/simple.el
index fa173b26289..1da9c816ef3 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7531,6 +7531,8 @@ temporarily."
     (if (null omark)
         (user-error "No mark set in this buffer"))
     (set-mark (point))
+    (if (equal (mark) (marker-position (car (last mark-ring))))
+        (setq mark-ring (butlast mark-ring)))
     (goto-char omark)
     (cond (temp-highlight)
           ((xor arg (if exchange-point-and-mark-highlight-region




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78965; Package emacs. (Sun, 06 Jul 2025 05:11:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Jake <jforst.mailman <at> gmail.com>
Cc: 78965 <at> debbugs.gnu.org
Subject: Re: bug#78965: 31.0.50;
 exchange-point-and-mark can create duplicate adjacent entries in
 mark-ring
Date: Sun, 06 Jul 2025 08:09:53 +0300
> From: Jake <jforst.mailman <at> gmail.com>
> Date: Sun, 6 Jul 2025 03:09:26 +0000
> 
> If you have >= 1 mark in the local mark ring, use `set-mark-command`
> with prefix argument ("C-u C-SPC") and then `exchange-point-and-mark`
> ("C-x C-x"), mark is equal to the last element in the local mark ring.
> If you then "C-u C-SPC", the last 2 elements in the local mark ring
> contain the same marker position.
> 
> Is that useful for anything?  It seems suboptimal when cycling through
> the mark ring.

How is it suboptimal?  Can you show a recipe, from "emacs -Q", which
illustrates the suboptimal nature of this?

> I think it would be similar to if `set-mark-command`
> allowed the same marker position to be repeatedly pushed onto the mark
> ring, which it doesn't.
> 
> Any thoughts?

Since this is very old behavior, I'd prefer not to touch it, unless it
shows a clear bug in  some case.  Who knows what optional features out
there could rely on this?

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78965; Package emacs. (Sun, 06 Jul 2025 06:52:04 GMT) Full text and rfc822 format available.

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

From: Jake <jforst.mailman <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 78965 <at> debbugs.gnu.org
Subject: Re: bug#78965: 31.0.50; exchange-point-and-mark can create duplicate
 adjacent entries in mark-ring
Date: Sun, 6 Jul 2025 06:51:19 +0000
Hi Eli

> How is it suboptimal?

Having duplicate *adjacent* entries in the mark ring could be
suboptimal for a couple of reasons:
1. When navigating back through the mark ring, you have to do an extra
C-u C-SPC to get to the next unique position.
2. The mark ring is supposed to store valuable/significant/important
positions and it has finite size (mark-ring-max is 16 by default), so
having an adjacent duplicate could take up valuable space in the mark
ring.

From emacs -Q,
- C-SPC C-SPC
- C-p
- C-SPC C-SPC
- C-p
- C-SPC C-SPC (mark ring now has 2 unique elements)
- C-u C-SPC
- C-x C-x
- C-u C-SPC (mark ring now has 2 elements and they are equal)

Also, I think this might be a better and more expressive patch than my
previous one:

diff --git a/lisp/simple.el b/lisp/simple.el
index fa173b26289..486901cea9d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -7490,7 +7490,9 @@ In Transient Mark mode, activate mark if
optional third arg ACTIVATE non-nil."
   "Pop off mark ring into the buffer's actual mark.
 Does not set point.  Does nothing if mark ring is empty."
   (when mark-ring
-    (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker)))))
+    (unless (equal (marker-position (mark-marker))
+                   (marker-position (car (last mark-ring))))
+      (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker))))))
     (set-marker (mark-marker) (car mark-ring))
     (set-marker (car mark-ring) nil)
     (pop mark-ring))

On Sun, Jul 6, 2025 at 5:10 AM Eli Zaretskii <eliz <at> gnu.org> wrote:
>
> > From: Jake <jforst.mailman <at> gmail.com>
> > Date: Sun, 6 Jul 2025 03:09:26 +0000
> >
> > If you have >= 1 mark in the local mark ring, use `set-mark-command`
> > with prefix argument ("C-u C-SPC") and then `exchange-point-and-mark`
> > ("C-x C-x"), mark is equal to the last element in the local mark ring.
> > If you then "C-u C-SPC", the last 2 elements in the local mark ring
> > contain the same marker position.
> >
> > Is that useful for anything?  It seems suboptimal when cycling through
> > the mark ring.
>
> How is it suboptimal?  Can you show a recipe, from "emacs -Q", which
> illustrates the suboptimal nature of this?
>
> > I think it would be similar to if `set-mark-command`
> > allowed the same marker position to be repeatedly pushed onto the mark
> > ring, which it doesn't.
> >
> > Any thoughts?
>
> Since this is very old behavior, I'd prefer not to touch it, unless it
> shows a clear bug in  some case.  Who knows what optional features out
> there could rely on this?
>
> Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78965; Package emacs. (Sun, 06 Jul 2025 07:05:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Jake <jforst.mailman <at> gmail.com>
Cc: 78965 <at> debbugs.gnu.org
Subject: Re: bug#78965: 31.0.50; exchange-point-and-mark can create duplicate
 adjacent entries in mark-ring
Date: Sun, 06 Jul 2025 10:04:28 +0300
> From: Jake <jforst.mailman <at> gmail.com>
> Date: Sun, 6 Jul 2025 06:51:19 +0000
> Cc: 78965 <at> debbugs.gnu.org
> 
> > How is it suboptimal?
> 
> Having duplicate *adjacent* entries in the mark ring could be
> suboptimal for a couple of reasons:
> 1. When navigating back through the mark ring, you have to do an extra
> C-u C-SPC to get to the next unique position.

IMO, it's a minor annoyance in a relatively rare use case.

> 2. The mark ring is supposed to store valuable/significant/important
> positions and it has finite size (mark-ring-max is 16 by default), so
> having an adjacent duplicate could take up valuable space in the mark
> ring.

You can enlarge the ring size if you have problems with the default
size.

And I don't think I agree with the "valuable/significant/important"
part.

> > Since this is very old behavior, I'd prefer not to touch it, unless it
> > shows a clear bug in  some case.  Who knows what optional features out
> > there could rely on this?

This is still a prevailing consideration, from where I stand.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#78965; Package emacs. (Sun, 06 Jul 2025 07:19:02 GMT) Full text and rfc822 format available.

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

From: Jake <jforst.mailman <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 78965 <at> debbugs.gnu.org
Subject: Re: bug#78965: 31.0.50; exchange-point-and-mark can create duplicate
 adjacent entries in mark-ring
Date: Sun, 6 Jul 2025 07:18:01 +0000
> You can enlarge the ring size if you have problems with the default
size.

Someone who likes to navigate with the mark-ring would be more likely
to customise mark-ring-max to be smaller, so they get back to where
they started quicker.  In that case, space in the mark ring becomes
more valuable, and this issue becomes more of a problem.

Having said that, I agree that it's a minor issue, so I understand if
you don't want to change long-standing behaviour or introduce an
option for it.

Thanks again
Jake

On Sun, Jul 6, 2025 at 7:04 AM Eli Zaretskii <eliz <at> gnu.org> wrote:
>
> > From: Jake <jforst.mailman <at> gmail.com>
> > Date: Sun, 6 Jul 2025 06:51:19 +0000
> > Cc: 78965 <at> debbugs.gnu.org
> >
> > > How is it suboptimal?
> >
> > Having duplicate *adjacent* entries in the mark ring could be
> > suboptimal for a couple of reasons:
> > 1. When navigating back through the mark ring, you have to do an extra
> > C-u C-SPC to get to the next unique position.
>
> IMO, it's a minor annoyance in a relatively rare use case.
>
> > 2. The mark ring is supposed to store valuable/significant/important
> > positions and it has finite size (mark-ring-max is 16 by default), so
> > having an adjacent duplicate could take up valuable space in the mark
> > ring.
>
> You can enlarge the ring size if you have problems with the default
> size.
>
> And I don't think I agree with the "valuable/significant/important"
> part.
>
> > > Since this is very old behavior, I'd prefer not to touch it, unless it
> > > shows a clear bug in  some case.  Who knows what optional features out
> > > there could rely on this?
>
> This is still a prevailing consideration, from where I stand.




This bug report was last modified 1 day ago.

Previous Next


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