* bug#75072: [PATCH] Set marker insertion type for Imenu markers
@ 2024-12-24 22:58 Morgan Willcock
2024-12-25 10:02 ` Morgan Willcock
2024-12-25 12:00 ` Eli Zaretskii
0 siblings, 2 replies; 4+ messages in thread
From: Morgan Willcock @ 2024-12-24 22:58 UTC (permalink / raw)
To: 75072
[-- 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.
---
| 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
--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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#75072: [PATCH] Set marker insertion type for Imenu markers
2024-12-24 22:58 bug#75072: [PATCH] Set marker insertion type for Imenu markers Morgan Willcock
@ 2024-12-25 10:02 ` Morgan Willcock
2024-12-26 9:00 ` Eli Zaretskii
2024-12-25 12:00 ` Eli Zaretskii
1 sibling, 1 reply; 4+ messages in thread
From: Morgan Willcock @ 2024-12-25 10:02 UTC (permalink / raw)
To: 75072
[-- Attachment #1: Type: text/plain, Size: 276 bytes --]
I hadn't realised that copy-marker could be used to create a marker and
set the insertion type in a single step.
Attached is a replacement patch which uses copy-marker and also makes
the same change for Imenu markers created by imenu-generic-expression.
--
Morgan Willcock
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Set-marker-insertion-type-for-Imenu-markers.patch --]
[-- Type: text/x-patch, Size: 1398 bytes --]
From 7b3767d5ed824b8a5f347bf46001917008173fe0 Mon Sep 17 00:00:00 2001
From: Morgan Willcock <morgan@ice9.digital>
Date: Wed, 25 Dec 2024 09:47:42 +0000
Subject: [PATCH] Set marker insertion type for Imenu markers
* lisp/imenu.el (imenu-default-create-index-function)
(imenu--generic-function): Configure Imenu markers to advance
their position when characters are inserted at the marker
position.
---
| 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
--git a/lisp/imenu.el b/lisp/imenu.el
index ba1ba5fcd00..12bc89cb159 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -583,7 +583,9 @@ 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
+ (copy-marker (point) t)
+ (point)))
index-alist)))
index-alist))
;; Use generic expression if possible.
@@ -688,7 +690,7 @@ imenu--generic-function
(unless (assoc menu-title index-alist)
(push (list menu-title) index-alist))
(if imenu-use-markers
- (setq beg (copy-marker beg)))
+ (setq beg (copy-marker beg t)))
(let ((item
(if function
(nconc (list (match-string-no-properties index)
--
2.47.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#75072: [PATCH] Set marker insertion type for Imenu markers
2024-12-25 10:02 ` Morgan Willcock
@ 2024-12-26 9:00 ` Eli Zaretskii
0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-12-26 9:00 UTC (permalink / raw)
To: Morgan Willcock; +Cc: 75072-done
> From: Morgan Willcock <morgan@ice9.digital>
> Date: Wed, 25 Dec 2024 10:02:53 +0000
>
> I hadn't realised that copy-marker could be used to create a marker and
> set the insertion type in a single step.
>
> Attached is a replacement patch which uses copy-marker and also makes
> the same change for Imenu markers created by imenu-generic-expression.
Thanks, installed on the master branch, and closing the bug.
Please in the future try to mention the bug number in the commit log
message (when the number is known, which should be so for messages you
post after the initial one).
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#75072: [PATCH] Set marker insertion type for Imenu markers
2024-12-24 22:58 bug#75072: [PATCH] Set marker insertion type for Imenu markers Morgan Willcock
2024-12-25 10:02 ` Morgan Willcock
@ 2024-12-25 12:00 ` Eli Zaretskii
1 sibling, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-12-25 12:00 UTC (permalink / raw)
To: Morgan Willcock; +Cc: 75072
> From: Morgan Willcock <morgan@ice9.digital>
> Date: Tue, 24 Dec 2024 22:58:08 +0000
>
> 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.
Yes. But I have one comment below.
> - (if imenu-use-markers (point-marker) (point)))
> + (if imenu-use-markers
> + (let ((marker (point-marker)))
> + (set-marker-insertion-type marker t)
> + marker)
> + (point)))
I think it is cleaner to use copy-marker here.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-12-26 9:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-24 22:58 bug#75072: [PATCH] Set marker insertion type for Imenu markers Morgan Willcock
2024-12-25 10:02 ` Morgan Willcock
2024-12-26 9:00 ` Eli Zaretskii
2024-12-25 12:00 ` Eli Zaretskii
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.