unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Morgan Willcock <morgan@ice9.digital>
To: 75072@debbugs.gnu.org
Subject: bug#75072: [PATCH] Set marker insertion type for Imenu markers
Date: Tue, 24 Dec 2024 22:58:08 +0000	[thread overview]
Message-ID: <87ldw4664f.fsf@ice9.digital> (raw)

[-- Attachment #1: Type: text/plain, Size: 1286 bytes --]

Tags: patch

The internal Imenu function for creating an Imenu index uses markers by
default, but the marker insertion type is left at the default type which
does not advance the marker position when additional characters are
inserted at the marker position.  Attached is a patch which sets the
marker insertion type to advance the marker position in the same
scenario.

This change means that the Imenu index will continue to be valid instead
of the marker becoming desynced from the buffer contents, i.e. jumping
to an index position and inserting characters will keep the marker in
the correct place.

I can't think of a situation where the previous marker behaviour was
intentional, but it is likely that the issue wouldn't be seen by anyone
who sets imenu-auto-rescan to t or in modes which do not use both
imenu-prev-index-position-function and imenu-extract-index-name-function
to create the Imenu index.

I've assumed this would go on the master branch.

Thanks,
Morgan


In GNU Emacs 30.0.93 (build 2, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.16.0, Xaw3d scroll bars) of 2024-12-20 built on inspiron
System Description: Debian GNU/Linux 12 (bookworm)

Configured using:
 'configure --with-native-compilation=aot --with-xml2
 --with-x-toolkit=lucid --with-tree-sitter'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Set-marker-insertion-type-for-Imenu-markers.patch --]
[-- Type: text/patch, Size: 1168 bytes --]

From 814ace3cda2c793a1d772f64c200d1f533cc94e5 Mon Sep 17 00:00:00 2001
From: Morgan Willcock <morgan@ice9.digital>
Date: Tue, 24 Dec 2024 21:39:43 +0000
Subject: [PATCH] Set marker insertion type for Imenu markers

* lisp/imenu.el (imenu-default-create-index-function): Configure
Imenu markers to advance their position when text is inserted at
the marker position.
---
 lisp/imenu.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/imenu.el b/lisp/imenu.el
index ba1ba5fcd00..0c6a7080e17 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -583,7 +583,11 @@ imenu-default-create-index-function
 	     (and (stringp name)
  		  ;; [ydi] Updated for imenu-use-markers.
 		  (push (cons name
-                              (if imenu-use-markers (point-marker) (point)))
+                              (if imenu-use-markers
+                                  (let ((marker (point-marker)))
+                                    (set-marker-insertion-type marker t)
+                                    marker)
+                                (point)))
 			index-alist)))
 	   index-alist))
 	;; Use generic expression if possible.
-- 
2.39.5


             reply	other threads:[~2024-12-24 22:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-24 22:58 Morgan Willcock [this message]
2024-12-25 10:02 ` bug#75072: [PATCH] Set marker insertion type for Imenu markers Morgan Willcock
2024-12-26  9:00   ` Eli Zaretskii
2024-12-25 12:00 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ldw4664f.fsf@ice9.digital \
    --to=morgan@ice9.digital \
    --cc=75072@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).