From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Mendler via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74408: 30.0.92; FR: Add a function completion-list-candidate-at-point Date: Tue, 19 Nov 2024 11:03:09 +0100 Message-ID: <874j431qxu.fsf@daniel-mendler.de> References: <87y11hefdb.fsf@daniel-mendler.de> <87v7wle77p.fsf@daniel-mendler.de> <87bjyc15da.fsf@daniel-mendler.de> Reply-To: Daniel Mendler 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="34522"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 74408@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 19 11:06:38 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1tDL80-0008pv-LZ for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Nov 2024 11:06:36 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDL7e-0006sC-CP; Tue, 19 Nov 2024 05:06:14 -0500 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 1tDL7S-0006pz-Vr for bug-gnu-emacs@gnu.org; Tue, 19 Nov 2024 05:06:04 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tDL7S-0007YK-MM for bug-gnu-emacs@gnu.org; Tue, 19 Nov 2024 05:06:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=klRQeP10HlleRAWUrf8hrz0s9TabkMi/O8IMEweN1z0=; b=aY3CQlwh1OIPZ32R2J93826lLKDWUPOVOBklbp73+BgFEvkN3x4opNSDuGQA73BF/iG56ZQasOCO8xpE3o2hyWTIUN72xCIbNyxEbb9XqZvZunS4FXq5lvGm9dJTqlZclcMqSH3rIyk2x4ZLIdp2Tm26+IaItszF0Lg/barm7vsQ8rjlIr+sGpsolygWnrUMLwSeDihKHrlauCuAvwoadjYQ9Ztr1dm4ZqrICXOlv6NjZ+TvJxfkxIFWknQFfBes93B/rDkxPG4u/v3JLgYdsYQO+/N0rkg7eo0ALYkrLZR1KNFP8VpIh6Ss6iN9aQ33Q1mZug1BoL6P+HXojOQteA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tDL7S-0005Nh-Bl for bug-gnu-emacs@gnu.org; Tue, 19 Nov 2024 05:06:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 19 Nov 2024 10:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74408 X-GNU-PR-Package: emacs Original-Received: via spool by 74408-submit@debbugs.gnu.org id=B74408.173201073220643 (code B ref 74408); Tue, 19 Nov 2024 10:06:02 +0000 Original-Received: (at 74408) by debbugs.gnu.org; 19 Nov 2024 10:05:32 +0000 Original-Received: from localhost ([127.0.0.1]:41138 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDL6y-0005Ms-4V for submit@debbugs.gnu.org; Tue, 19 Nov 2024 05:05:32 -0500 Original-Received: from server.qxqx.de ([49.12.34.165]:54941 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDL6v-0005Me-6W for 74408@debbugs.gnu.org; Tue, 19 Nov 2024 05:05:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=daniel-mendler.de; s=key; h=Content-Type:MIME-Version:Message-ID:Date: References:In-Reply-To:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=klRQeP10HlleRAWUrf8hrz0s9TabkMi/O8IMEweN1z0=; b=U3jbgXjdUaO4g/sDA1g9Jbl5Li u95ZIL4kLJnIo2txgwCNLrO88FVCNFEb5LMEUzrbUONB3X2mxOhq2sN5Epp1dNT0MK5u6z1XF23Mh 0uLWUPXCmjEh0j6iDirIFKyfy0RnzNeHWnY0JEyVydhMbfJlx+w85wUhD73YHBso02GY=; In-Reply-To: (Stefan Monnier's message of "Mon, 18 Nov 2024 21:59:15 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:295630 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier writes: >>> AFAICT, it's easy to make `completion-list-candidate-at-point` accept an >>> optional position argument (which would default to point), which would >>> be helpful in the two places where we use that function. >>> WDYT? >> Indeed. Updated patch attached. > > LGTM, if there are no objections, I'll install it into `master` in > a few days. Thanks. I've attached the latest version of the patch, where the function is simplified without save-excursion. Daniel --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-New-function-completion-list-candidate-at-point.patch >From 8501d7cf9b81d03b2f00d738a6320d417917eca4 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Mon, 18 Nov 2024 00:58:48 +0100 Subject: [PATCH] New function `completion-list-candidate-at-point' Replace `completions--start-of-candidate-at' with the new function `completion-list-candidate-at-point' which returns the candidate string and the candidate bounds as a list in the format (STR BEG END). * lisp/simple.el (completions--start-of-candidate-at): Remove. (completion-list-candidate-at-point): New function. (choose-completion): Use it. * lisp/minibuffer.el (minibuffer-completion-help): Use it. --- lisp/minibuffer.el | 5 +++-- lisp/simple.el | 39 ++++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 9b498615926..405ee21cdb2 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2628,8 +2628,9 @@ minibuffer-completion-help (when-let* ((buffer (get-buffer "*Completions*")) (window (get-buffer-window buffer 0))) (with-current-buffer buffer - (when-let* ((beg (completions--start-of-candidate-at (window-point window)))) - (cons (get-text-property beg 'completion--string) (- (point) beg)))))) + (when-let* ((cand (completion-list-candidate-at-point + (window-point window)))) + (cons (car cand) (- (point) (cadr cand))))))) ;; If the *Completions* buffer is shown in a new ;; window, mark it as softly-dedicated, so bury-buffer in ;; minibuffer-hide-completions will know whether to diff --git a/lisp/simple.el b/lisp/simple.el index 3a142ef14b3..32ac8af627c 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -10246,22 +10246,21 @@ choose-completion-deselect-if-after This makes `completions--deselect' effective.") -(defun completions--start-of-candidate-at (position) - "Return the start position of the completion candidate at POSITION." - (save-excursion - (goto-char position) - (let (beg) - (cond - ((and (not (eobp)) - (get-text-property (point) 'completion--string)) - (setq beg (1+ (point)))) - ((and (not (bobp)) - (get-text-property (1- (point)) 'completion--string)) - (setq beg (point)))) - (when beg - (or (previous-single-property-change - beg 'completion--string) - beg))))) +(defun completion-list-candidate-at-point (&optional pt) + "Candidate string and bounds at PT in completions buffer. +The return value has the format (STR BEG END). +The optional argument PT defaults to (point)." + (setq pt (or pt (point))) + (when (cond + ((and (/= pt (point-max)) + (get-text-property pt 'completion--string)) + (cl-incf pt)) + ((and (/= pt (point-min)) + (get-text-property (1- pt) 'completion--string)))) + (setq pt (or (previous-single-property-change pt 'completion--string) pt)) + (list (get-text-property pt 'completion--string) pt + (or (next-single-property-change pt 'completion--string) + (point-max))))) (defun choose-completion (&optional event no-exit no-quit) "Choose the completion at point. @@ -10286,11 +10285,9 @@ choose-completion (or (get-text-property (posn-point (event-start event)) 'completion--string) (error "No completion here")) - (if-let* ((candidate-start - (completions--start-of-candidate-at - (posn-point (event-start event))))) - (get-text-property candidate-start 'completion--string) - (error "No completion here"))))) + (or (car (completion-list-candidate-at-point + (posn-point (event-start event)))) + (error "No completion here"))))) (unless (buffer-live-p buffer) (error "Destination buffer is dead")) -- 2.45.2 --=-=-=--