From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: master 431f8ff1e38: * lisp/imenu.el: Support more values for imenu-flatten (bug#70846) Date: Tue, 14 May 2024 09:08:01 +0300 Organization: LINKOV.NET Message-ID: <86ikzhq6ja.fsf@mail.linkov.net> References: <171558357066.26019.9766615061719600757@vcs2.savannah.gnu.org> <20240513065931.0D83AC12C31@vcs2.savannah.gnu.org> <86v83hwxjs.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37352"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: emacs-devel@gnu.org To: Eshel Yaron Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue May 14 08:09:12 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s6lLb-0009Uq-Cg for ged-emacs-devel@m.gmane-mx.org; Tue, 14 May 2024 08:09:11 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6lLH-00025G-BR; Tue, 14 May 2024 02:08:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s6lL2-00022y-SU for emacs-devel@gnu.org; Tue, 14 May 2024 02:08:38 -0400 Original-Received: from relay5-d.mail.gandi.net ([2001:4b98:dc4:8::225]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s6lL0-0000wi-NT for emacs-devel@gnu.org; Tue, 14 May 2024 02:08:36 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 805921C0002; Tue, 14 May 2024 06:08:29 +0000 (UTC) In-Reply-To: <86v83hwxjs.fsf@mail.linkov.net> (Juri Linkov's message of "Mon, 13 May 2024 19:30:59 +0300") X-GND-Sasl: juri@linkov.net Received-SPF: pass client-ip=2001:4b98:dc4:8::225; envelope-from=juri@linkov.net; helo=relay5-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:319214 Archived-At: --=-=-= Content-Type: text/plain > One way to disambiguate them is to use text properties > on the completion candidate strings. > > But unfortunately read-from-minibuffer doesn't obey > a non-nil value of minibuffer-allow-text-properties, > because choose-completion unconditionally discards all properties > by substring-no-properties. > > Maybe choose-completion should use substring instead of > substring-no-properties when minibuffer-allow-text-properties > is non-nil? Here is a new variable that helps to disambiguate completions with the same name but different annotations by using text properties: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=completion-allow-text-properties.patch 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")) --=-=-=--