From unknown Fri Jun 20 07:22:07 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#74408 <74408@debbugs.gnu.org> To: bug#74408 <74408@debbugs.gnu.org> Subject: Status: 30.0.92; FR: Add a function completion-list-candidate-at-point Reply-To: bug#74408 <74408@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:22:07 +0000 retitle 74408 30.0.92; FR: Add a function completion-list-candidate-at-point reassign 74408 emacs submitter 74408 Daniel Mendler severity 74408 wishlist thanks From debbugs-submit-bounces@debbugs.gnu.org Sun Nov 17 16:10:35 2024 Received: (at submit) by debbugs.gnu.org; 17 Nov 2024 21:10:35 +0000 Received: from localhost ([127.0.0.1]:58821 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tCmXT-00070F-CL for submit@debbugs.gnu.org; Sun, 17 Nov 2024 16:10:35 -0500 Received: from lists.gnu.org ([209.51.188.17]:41808) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tCmXR-000707-PP for submit@debbugs.gnu.org; Sun, 17 Nov 2024 16:10:34 -0500 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 1tCmXQ-0003xt-QA for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2024 16:10:32 -0500 Received: from server.qxqx.de ([2a01:4f8:c012:9177::1] helo=mail.qxqx.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tCmXO-0002tG-JJ for bug-gnu-emacs@gnu.org; Sun, 17 Nov 2024 16:10:32 -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: Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=2Oe+sZsS/Cbux4FlztqscKtsh7bwF+Sa2YKsGuqlMew=; b=kch58DBU086DQ+yN+ueimFJAGm 06KEDzHRH9fuuBsWxYH8wVRVgpTUjveBWZE5oMEf9TKy8RKJ02vDVoCe844YBeJHCTIgs2NzO2aJy nIp/FiYrKpa2NElA9YXJIFNoMeRXoswMm5NDk2obQw5LGlIg7y53JBID67oyRFNyxFPU=; From: Daniel Mendler To: bug-gnu-emacs@gnu.org Subject: 30.0.92; FR: Add a function completion-list-candidate-at-point X-Debbugs-Cc: Stefan Monnier Date: Sun, 17 Nov 2024 22:10:08 +0100 Message-ID: <87y11hefdb.fsf@daniel-mendler.de> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2a01:4f8:c012:9177::1; envelope-from=mail@daniel-mendler.de; helo=mail.qxqx.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) Emacs 31 comes with the internal function `completions--start-of-candidate-at' in simple.el, which returns the position of the completion candidate at point in the completions buffer. I propose to replace this function with a slightly improved version, which returns the candidate string in addition to the candidate bounds. It could be made part of the public API: (defun completion-list-candidate-at-point () "Return completion candidate string at point with bounds in completions buffer." (let (beg end) (when (cond ((and (not (eobp)) (get-text-property (point) 'completion--string)) (setq end (point) beg (1+ (point)))) ((and (not (bobp)) (get-text-property (1- (point)) 'completion--string)) (setq end (1- (point)) beg (point)))) (list (get-text-property (previous-single-property-change beg 'completion--string) 'completion--string) beg end)))) For a few years, the GNU ELPA packages like Embark and Consult had versions of this function. These packages need to obtain the completion candidate at point when acting on the candidate. If `completion-list-candidate-at-point' is made available in Emacs, I can port it back via the GNU ELPA Compat package, such that external packages can take advantage of the new function, and don't have to rely on internals like the `completion--string' property. If there is interest, I can provide a patch for simple.el which replaces `completions--start-of-candidate-at'. Thank you for your consideration. Daniel From debbugs-submit-bounces@debbugs.gnu.org Sun Nov 17 16:46:21 2024 Received: (at 74408) by debbugs.gnu.org; 17 Nov 2024 21:46:21 +0000 Received: from localhost ([127.0.0.1]:58871 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tCn65-0000HT-Em for submit@debbugs.gnu.org; Sun, 17 Nov 2024 16:46:21 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:3341) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tCn62-0000HB-QG for 74408@debbugs.gnu.org; Sun, 17 Nov 2024 16:46:20 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 32E38443842; Sun, 17 Nov 2024 16:46:12 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1731879970; bh=Ak9RxDkjjIiVoV2M1UTU6dRvmQALhA++rTNAIoUNQDc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=SfgA6iKpiVKRE4AvgYeNvOExRBCBo54cwRYP3Plj3z3LKCyZV8UUo76BH2yOC1ARv mhqy8kP0ilYES/oZRsi5sErPchTxwVgRUNO1QLpfeZz1a+by6QNzXptoYIaR604r/Y /PN9ZmjLKoEhYUmcBJHeXtUvM/rIffsGfk3rl9WkhNLJ1Y9mSB9oQA82/4B1ncpmXl iRyfTQqDQxSZt/XexoGrjxZNchBmzrJ80Y+s41DxShl6m4W27ngtBxJ8j5NPy1iQFv UONyyVWO1V/V/vEx8wVlCSLP0qIGLvp+twZrHAj8Ehea2FjPtz6NeiHpbksW2erR/N eN9ko6Aue2/6Q== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id B72FA443775; Sun, 17 Nov 2024 16:46:10 -0500 (EST) Received: from pastel (104-195-225-43.cpe.teksavvy.com [104.195.225.43]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 8AC9E120480; Sun, 17 Nov 2024 16:46:10 -0500 (EST) From: Stefan Monnier To: Daniel Mendler Subject: Re: bug#74408: 30.0.92; FR: Add a function completion-list-candidate-at-point In-Reply-To: <87y11hefdb.fsf@daniel-mendler.de> (Daniel Mendler's message of "Sun, 17 Nov 2024 22:10:08 +0100") Message-ID: References: <87y11hefdb.fsf@daniel-mendler.de> Date: Sun, 17 Nov 2024 16:46:08 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.020 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 74408 Cc: 74408@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Emacs 31 comes with the internal function > `completions--start-of-candidate-at' in simple.el, which returns the > position of the completion candidate at point in the completions buffer. > I propose to replace this function with a slightly improved version, > which returns the candidate string in addition to the candidate bounds. > It could be made part of the public API: Sounds fine to me. Stefan From debbugs-submit-bounces@debbugs.gnu.org Sun Nov 17 19:08:40 2024 Received: (at 74408) by debbugs.gnu.org; 18 Nov 2024 00:08:40 +0000 Received: from localhost ([127.0.0.1]:59149 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tCpJn-0006oi-RH for submit@debbugs.gnu.org; Sun, 17 Nov 2024 19:08:40 -0500 Received: from server.qxqx.de ([49.12.34.165]:58239 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tCpJk-0006oR-OE for 74408@debbugs.gnu.org; Sun, 17 Nov 2024 19:08:38 -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=+Qacyot2PEQgJOczDnoBcY/xCiFUHmYDvMWfCedQHeM=; b=Lha50GpBgA57M4A7NTsufJFVTs K5563uEiDN3gyl6oKaEIlEh3JHoB0EV43NdnmKGy+gO2OurUTK9R62qusJufz5PT4IndAw0cgZI+k D0uW7zAR5l9k1mExRjewN6PU3Bh+rlwPZK40h5irIYdtgePZD1jPGHQVnqYZYbi/8EfM=; From: Daniel Mendler To: Stefan Monnier Subject: Re: bug#74408: 30.0.92; FR: Add a function completion-list-candidate-at-point In-Reply-To: (Stefan Monnier's message of "Sun, 17 Nov 2024 16:46:08 -0500") References: <87y11hefdb.fsf@daniel-mendler.de> Date: Mon, 18 Nov 2024 01:06:18 +0100 Message-ID: <87v7wle77p.fsf@daniel-mendler.de> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 74408 Cc: 74408@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= Content-Type: text/plain Stefan Monnier writes: >> Emacs 31 comes with the internal function >> `completions--start-of-candidate-at' in simple.el, which returns the >> position of the completion candidate at point in the completions buffer. >> I propose to replace this function with a slightly improved version, >> which returns the candidate string in addition to the candidate bounds. >> It could be made part of the public API: > > Sounds fine to me. Thanks. Patch attached. Daniel --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-New-function-completion-list-candidate-at-point.patch >From 97dbfca1562b5d416617331617ebbc1594f683fd 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 both the candidate string and the candidate bounds. * 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 | 6 ++++-- lisp/simple.el | 41 ++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 9b498615926..ed0c5142b17 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2628,8 +2628,10 @@ 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 (save-excursion + (goto-char (window-point window)) + (completion-list-candidate-at-point)))) + (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..5687c16387c 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -10246,22 +10246,22 @@ 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 () + "Return candidate string at point and bounds in completions buffer." + (let (beg) + (when (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)))) + (setq beg (or (previous-single-property-change + beg 'completion--string) + beg)) + (list (get-text-property beg 'completion--string) beg + (or (next-single-property-change beg 'completion--string) + (point-max)))))) (defun choose-completion (&optional event no-exit no-quit) "Choose the completion at point. @@ -10286,11 +10286,10 @@ 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 (save-excursion + (goto-char (posn-point (event-start event))) + (car (completion-list-candidate-at-point))) + (error "No completion here"))))) (unless (buffer-live-p buffer) (error "Destination buffer is dead")) -- 2.45.2 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 18 18:25:43 2024 Received: (at 74408) by debbugs.gnu.org; 18 Nov 2024 23:25:44 +0000 Received: from localhost ([127.0.0.1]:39651 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDB7n-0000gH-KC for submit@debbugs.gnu.org; Mon, 18 Nov 2024 18:25:43 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:64812) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDB7k-0000g2-GD for 74408@debbugs.gnu.org; Mon, 18 Nov 2024 18:25:41 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id EED0480821; Mon, 18 Nov 2024 18:25:33 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1731972333; bh=ZGGCFcOfJPkS+T09h9HGheCjh8pTR3P9t1wJjv9H0s4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=XX7tpSn3ZXSHRNng/L/ODU63fclrIyEDn0Fs3JpSMvEjBR7cA6tokAnHVAkivK+Ta S/qvJRF3ySZCYXItrTn9W2DkCcuettfixH0OXmDB7t8B1+i4fWG05CHTd9bPvhY+ZE +zmdU565OHZjbbcQdnIQqMRUFZoDVRrX9o2Pbt1m9xOXGOi7OzEU2lMIWUA9EqgDbL P8F2I4dKidsrKcA3YNN776zsV6nHjraG5MDxn6PBPlbxJtFSqrq0qJJ6BW7cJG8uMp g4/TwUtZgyln0unCP6AW4eW/OmvGzJRvGYmb9Sczt746hMzZPnZbAeRwUspQ7XEJ5J E1inuHg/op+tQ== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id F30E9803CA; Mon, 18 Nov 2024 18:25:32 -0500 (EST) Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id E05D31204C2; Mon, 18 Nov 2024 18:25:32 -0500 (EST) From: Stefan Monnier To: Daniel Mendler Subject: Re: bug#74408: 30.0.92; FR: Add a function completion-list-candidate-at-point In-Reply-To: <87v7wle77p.fsf@daniel-mendler.de> (Daniel Mendler's message of "Mon, 18 Nov 2024 01:06:18 +0100") Message-ID: References: <87y11hefdb.fsf@daniel-mendler.de> <87v7wle77p.fsf@daniel-mendler.de> Date: Mon, 18 Nov 2024 18:25:31 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.175 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 74408 Cc: 74408@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Thanks. Patch attached. Thanks, Daniel. Minor comments below. > @@ -2628,8 +2628,10 @@ 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 (save-excursion > + (goto-char (window-point window)) > + (completion-list-candidate-at-point)))) > + (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 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? > +(defun completion-list-candidate-at-point () > + "Return candidate string at point and bounds in completions buffer." I suggest you use something like "(STRING BEG END)" to describe the format. Stefan From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 18 18:39:11 2024 Received: (at 74408) by debbugs.gnu.org; 18 Nov 2024 23:39:11 +0000 Received: from localhost ([127.0.0.1]:39698 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDBKp-0001Ib-4K for submit@debbugs.gnu.org; Mon, 18 Nov 2024 18:39:11 -0500 Received: from server.qxqx.de ([49.12.34.165]:40879 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDBKm-0001IH-GA for 74408@debbugs.gnu.org; Mon, 18 Nov 2024 18:39:09 -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=I4USCfAfeoXWzWBwzGV8VNT98KvtdMNVqZX82MShdXU=; b=Gl2IUuxytmaY+hC2qwC2Zo36BK t9PPxFJxylpC2o5kvpiG//tcoWWLJj7bCWt5soh22ECBX+XyMlqjI/u5YSDEdt9etOlqhRP8n0JoD KKhj3CI11lo/N8BWfbBnInrg7ygv9kTSRpXUKrgFi/8suLHp9QAo88XrZe3nF44O9UZg=; From: Daniel Mendler To: Stefan Monnier Subject: Re: bug#74408: 30.0.92; FR: Add a function completion-list-candidate-at-point In-Reply-To: (Stefan Monnier's message of "Mon, 18 Nov 2024 18:25:31 -0500") References: <87y11hefdb.fsf@daniel-mendler.de> <87v7wle77p.fsf@daniel-mendler.de> Date: Tue, 19 Nov 2024 00:36:49 +0100 Message-ID: <87bjyc15da.fsf@daniel-mendler.de> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 74408 Cc: 74408@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= 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. Daniel --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-New-function-completion-list-candidate-at-point.patch >From bd755ae662e6cc5815e795d3c54dd7bda3cdc4e2 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 | 40 +++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 21 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..443a848b0ab 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -10246,22 +10246,26 @@ 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." +(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)." (save-excursion - (goto-char position) + (when pt (goto-char pt)) (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))))) + (when (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)))) + (setq beg (or (previous-single-property-change + beg 'completion--string) + beg)) + (list (get-text-property beg 'completion--string) beg + (or (next-single-property-change beg 'completion--string) + (point-max))))))) (defun choose-completion (&optional event no-exit no-quit) "Choose the completion at point. @@ -10286,11 +10290,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 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon Nov 18 21:59:36 2024 Received: (at 74408) by debbugs.gnu.org; 19 Nov 2024 02:59:36 +0000 Received: from localhost ([127.0.0.1]:39984 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDESm-0002A1-CT for submit@debbugs.gnu.org; Mon, 18 Nov 2024 21:59:36 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:39016) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDESj-00029l-9T for 74408@debbugs.gnu.org; Mon, 18 Nov 2024 21:59:34 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 906C3444F48; Mon, 18 Nov 2024 21:59:26 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1731985165; bh=sRMG0oYl82VPvTZMClUwURcq6QndsY00wIofgicOUyQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=JtIwM/hVscspireAYIPZ0N7BxQcoS5X2M4/RZqJovrlJVeaVnYRaAone4DPCXOMas OP9ulegKc7SUJ9L+5BA08sJXZRR6EYa2lS3++pxbNPFvnbXuyh9tlzsjNMEcaqmILh c7snPFwjeCd78uxHypRL3Dwy0aUNORiLJXyhcJKkqmfCs3Mgq5IrDFhnC9w2M0ebq/ N2VvTfqOMyWlgQdlePQZhc5/wCZIZan9WQ1lRZNQm1WGPoRgPhmFqtHpajHNiLBpIX 218u8fM1rAsNizl9bJ1DPC5f00mTnsnqaKO2E8BZ2z4gb4FME1x+v092LLkwyojrlu fRj2Jlbp0JB6w== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 70E6F444EF4; Mon, 18 Nov 2024 21:59:25 -0500 (EST) Received: from pastel (104-195-225-43.cpe.teksavvy.com [104.195.225.43]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 26EBC120313; Mon, 18 Nov 2024 21:59:25 -0500 (EST) From: Stefan Monnier To: Daniel Mendler Subject: Re: bug#74408: 30.0.92; FR: Add a function completion-list-candidate-at-point In-Reply-To: <87bjyc15da.fsf@daniel-mendler.de> (Daniel Mendler's message of "Tue, 19 Nov 2024 00:36:49 +0100") Message-ID: References: <87y11hefdb.fsf@daniel-mendler.de> <87v7wle77p.fsf@daniel-mendler.de> <87bjyc15da.fsf@daniel-mendler.de> Date: Mon, 18 Nov 2024 21:59:15 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.019 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 74408 Cc: 74408@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) >> 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. Stefan From debbugs-submit-bounces@debbugs.gnu.org Tue Nov 19 05:05:32 2024 Received: (at 74408) by debbugs.gnu.org; 19 Nov 2024 10:05:32 +0000 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 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=; From: Daniel Mendler To: Stefan Monnier Subject: Re: bug#74408: 30.0.92; FR: Add a function completion-list-candidate-at-point In-Reply-To: (Stefan Monnier's message of "Mon, 18 Nov 2024 21:59:15 -0500") References: <87y11hefdb.fsf@daniel-mendler.de> <87v7wle77p.fsf@daniel-mendler.de> <87bjyc15da.fsf@daniel-mendler.de> Date: Tue, 19 Nov 2024 11:03:09 +0100 Message-ID: <874j431qxu.fsf@daniel-mendler.de> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 74408 Cc: 74408@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) --=-=-= 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 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Nov 29 12:27:20 2024 Received: (at 74408-done) by debbugs.gnu.org; 29 Nov 2024 17:27:20 +0000 Received: from localhost ([127.0.0.1]:44270 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tH4m0-0004Ti-Fj for submit@debbugs.gnu.org; Fri, 29 Nov 2024 12:27:20 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:64381) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tH4ly-0004TP-VE for 74408-done@debbugs.gnu.org; Fri, 29 Nov 2024 12:27:19 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 77DF0802B3; Fri, 29 Nov 2024 12:27:12 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1732901227; bh=8sF9+VT1uicrsSUowr7HU2rv/jA0mzFOOgqpd+0KvMs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=bst19djYpxn7ej6lSpu77QyFOK14RJct2muPjiVL/hfo881p+k+uR8rdZFhCFHiTD DRjSDkWtfjq2Y1xuHqTBhC/gb+bqrx9DpnbpNTbfF/LzCHRzsaLZUK5xtVQSzY4M7r iCsg6HQuuX0+PwJluIBuVFAEUoXtSwqiBg7+Aexfa9N74olc2AsrGP7KtLWS2JK/Tw uBcFKHtL9YC1Vr6ZbDqrGEglEN8zmEtGVq46tcGXLiwthkZUh5pDX6hOOYQahmldpB EQ/qUGf6sPehyAAPTreUr9MlwcUZ42yf76mhZbbBz2RE3ubpFvw2knCIhy4O3xSG76 6SavYStUkrHEg== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 96AF1801B7; Fri, 29 Nov 2024 12:27:07 -0500 (EST) Received: from alfajor (unknown [23.233.149.155]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 7A33A12026C; Fri, 29 Nov 2024 12:27:07 -0500 (EST) From: Stefan Monnier To: Daniel Mendler Subject: Re: bug#74408: 30.0.92; FR: Add a function completion-list-candidate-at-point In-Reply-To: <874j431qxu.fsf@daniel-mendler.de> (Daniel Mendler's message of "Tue, 19 Nov 2024 11:03:09 +0100") Message-ID: References: <87y11hefdb.fsf@daniel-mendler.de> <87v7wle77p.fsf@daniel-mendler.de> <87bjyc15da.fsf@daniel-mendler.de> <874j431qxu.fsf@daniel-mendler.de> Date: Fri, 29 Nov 2024 12:27:06 -0500 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL 0.053 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 74408-done Cc: 74408-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Thanks. I've attached the latest version of the patch, where the > function is simplified without save-excursion. Merged, closing, thank you, Stefan From unknown Fri Jun 20 07:22:07 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 28 Dec 2024 12:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator