From: Juri Linkov <juri@linkov.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
me@eshelyaron.com, emacs-devel@gnu.org
Subject: Re: master 431f8ff1e38: * lisp/imenu.el: Support more values for imenu-flatten (bug#70846)
Date: Wed, 15 May 2024 19:51:25 +0300 [thread overview]
Message-ID: <86bk572e6a.fsf@mail.linkov.net> (raw)
In-Reply-To: <86o798x5hz.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 14 May 2024 09:38:32 +0300")
[-- Attachment #1: Type: text/plain, Size: 473 bytes --]
>> +(defcustom completion-allow-text-properties nil
>> + "Non-nil means `choose-completion' should not discard text properties.
>> +This also affects `completing-read' and any of the functions that do
>> +minibuffer input with completion."
>
> This new user option should be announced in NEWS.
>
> I also wonder whether it should be a user option
So here it's a variable, that will later help to select Imenu
completion candidates with same names from different groups.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: completion-allow-text-properties.patch --]
[-- Type: text/x-diff, Size: 4075 bytes --]
diff --git a/etc/NEWS b/etc/NEWS
index 34052764f5f..0db85410ebe 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1784,6 +1784,13 @@ A major mode based on the tree-sitter library for editing Lua files.
** Minibuffer and Completions
+*** New variable 'completion-allow-text-properties'.
+Like non-nil 'minibuffer-allow-text-properties' that doesn't discard
+text properties, it does the same by keeping text properties
+on the selected completion candidate. So when these two variables
+both are non-nil then 'completing-read' returns a selected completion
+with the initial text properties kept intact.
+
+++
*** New global minor mode 'minibuffer-regexp-mode'.
This is a minor mode for editing regular expressions in the minibuffer.
diff --git a/lisp/simple.el b/lisp/simple.el
index cdbbd876e3b..8793e590733 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -10102,6 +10102,11 @@ choose-completion-deselect-if-after
This makes `completions--deselect' effective.")
+(defvar completion-allow-text-properties nil
+ "Non-nil means `choose-completion' should not discard text properties.
+This affects `completing-read' and any of the functions that do
+minibuffer input with completion.")
+
(defun choose-completion (&optional event no-exit no-quit)
"Choose the completion at point.
If EVENT, use EVENT's position to determine the starting position.
@@ -10122,8 +10127,10 @@ choose-completion
(completion-no-auto-exit (if no-exit t completion-no-auto-exit))
(choice
(if choose-completion-deselect-if-after
- (if-let ((str (get-text-property (posn-point (event-start event)) 'completion--string)))
- (substring-no-properties str)
+ (if-let ((str (get-text-property (posn-point (event-start event))
+ 'completion--string)))
+ (if completion-allow-text-properties str
+ (substring-no-properties str))
(error "No completion here"))
(save-excursion
(goto-char (posn-point (event-start event)))
@@ -10139,8 +10146,9 @@ choose-completion
(setq beg (or (previous-single-property-change
beg 'completion--string)
beg))
- (substring-no-properties
- (get-text-property beg 'completion--string)))))))
+ (let ((str (get-text-property beg 'completion--string)))
+ (if completion-allow-text-properties str
+ (substring-no-properties str))))))))
(unless (buffer-live-p buffer)
(error "Destination buffer is dead"))
diff --git a/lisp/imenu.el b/lisp/imenu.el
index ea097f5da3a..952c3dc8969 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -732,6 +732,8 @@ imenu--completion-buffer
;; Create a list for this buffer only when needed.
(let ((name (thing-at-point 'symbol))
choice
+ (minibuffer-allow-text-properties t)
+ (completion-allow-text-properties t)
(prepared-index-alist
(if (not imenu-space-replacement) index-alist
(mapcar
@@ -765,10 +767,12 @@ imenu--completion-buffer
nil t nil 'imenu--history-list name)))
(when (stringp name)
- (setq choice (assoc name prepared-index-alist))
- (if (imenu--subalist-p choice)
- (imenu--completion-buffer (cdr choice) prompt)
- choice))))
+ (or (get-text-property 0 'imenu-choice name)
+ (progn
+ (setq choice (assoc name prepared-index-alist))
+ (if (imenu--subalist-p choice)
+ (imenu--completion-buffer (cdr choice) prompt)
+ choice))))))
(defun imenu--mouse-menu (index-alist event &optional title)
"Let the user select from a buffer index from a mouse menu.
@@ -803,7 +807,8 @@ imenu--flatten-index-alist
((not (imenu--subalist-p item))
(list (cons (if (and (eq imenu-flatten 'annotation) prefix)
(propertize name 'imenu-section
- (format " (%s)" prefix))
+ (format " (%s)" prefix)
+ 'imenu-choice item)
new-prefix)
pos)))
(t
next prev parent reply other threads:[~2024-05-15 16:51 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <171558357066.26019.9766615061719600757@vcs2.savannah.gnu.org>
[not found] ` <20240513065931.0D83AC12C31@vcs2.savannah.gnu.org>
2024-05-13 9:22 ` master 431f8ff1e38: * lisp/imenu.el: Support more values for imenu-flatten (bug#70846) Eshel Yaron
2024-05-13 16:30 ` Juri Linkov
2024-05-14 6:08 ` Juri Linkov
2024-05-14 6:38 ` Eli Zaretskii
2024-05-14 13:10 ` Stefan Monnier
2024-05-14 16:46 ` Juri Linkov
2024-05-14 20:58 ` Daniel Mendler via Emacs development discussions.
2024-05-14 23:26 ` FW: [External] : " Drew Adams
2024-05-15 16:51 ` Juri Linkov [this message]
2024-05-15 18:03 ` Eli Zaretskii
2024-05-15 18:30 ` Eshel Yaron
2024-05-16 6:08 ` Juri Linkov
2024-05-16 9:51 ` Eli Zaretskii
2024-05-17 6:48 ` Juri Linkov
2024-05-17 15:36 ` Stefan Monnier
2024-05-17 16:43 ` Juri Linkov
2024-05-18 15:12 ` Stefan Monnier
2024-05-20 6:46 ` Juri Linkov
2024-05-27 18:18 ` Juri Linkov
2024-07-14 6:28 ` Eshel Yaron
2024-07-14 6:53 ` Juri Linkov
2024-07-14 10:55 ` Eshel Yaron
2024-07-14 17:00 ` Juri Linkov
2024-07-16 6:57 ` Eshel Yaron
2024-08-07 6:51 ` Juri Linkov
2024-08-07 8:33 ` Eshel Yaron
2024-08-07 16:46 ` Juri Linkov
2024-08-09 6:59 ` Juri Linkov
2024-08-09 7:11 ` Eli Zaretskii
2024-08-09 16:10 ` Juri Linkov
2024-08-09 17:43 ` Eli Zaretskii
2024-08-07 6:56 ` Completions group metadata [was: master 431f8ff1e38: * lisp/imenu.el: Support more values for imenu-flatten (bug#70846)] Juri Linkov
2024-08-09 16:16 ` Completions group metadata [ Juri Linkov
2024-08-14 1:41 ` master 431f8ff1e38: * lisp/imenu.el: Support more values for imenu-flatten (bug#70846) Stefan Monnier
2024-08-20 17:51 ` Juri Linkov
2024-05-14 15:26 ` [External] : " Drew Adams
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=86bk572e6a.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=me@eshelyaron.com \
--cc=monnier@iro.umontreal.ca \
/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).