diff --git a/lisp/imenu.el b/lisp/imenu.el index 93a544ff550..af344e5e250 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -729,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 @@ -762,10 +768,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. @@ -800,7 +808,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 diff --git a/lisp/simple.el b/lisp/simple.el index deab52c4201..fa180323963 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -10102,6 +10102,14 @@ choose-completion-deselect-if-after This makes `completions--deselect' effective.") +(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." + :type 'boolean + :version "30.1" + :group '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. @@ -10123,7 +10131,9 @@ choose-completion (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 completion-allow-text-properties + (substring str) + (substring-no-properties str)) (error "No completion here")) (save-excursion (goto-char (posn-point (event-start event))) @@ -10139,8 +10149,11 @@ choose-completion (setq beg (or (previous-single-property-change beg 'completion--string) beg)) - (substring-no-properties - (get-text-property beg 'completion--string))))))) + (if completion-allow-text-properties + (substring + (get-text-property beg 'completion--string)) + (substring-no-properties + (get-text-property beg 'completion--string)))))))) (unless (buffer-live-p buffer) (error "Destination buffer is dead"))