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 00:36:49 +0100 Message-ID: <87bjyc15da.fsf@daniel-mendler.de> References: <87y11hefdb.fsf@daniel-mendler.de> <87v7wle77p.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="35448"; 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 00:40:28 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 1tDBM3-00093v-Oz for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Nov 2024 00:40:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDBLn-0002wU-0F; Mon, 18 Nov 2024 18:40:11 -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 1tDBLe-0002w1-Gp for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 18:40:02 -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 1tDBLd-00005P-Vv for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 18:40: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=I4USCfAfeoXWzWBwzGV8VNT98KvtdMNVqZX82MShdXU=; b=dSfnpvMJfTd1t6KK3eUUq14KR8eJ64GNSIu2LDw/0b0ESwQYRtCuT0JYBUf3q26j8EDgRhqaEmW9ZZ49RyHMPgv8aLjkMFeeFt/nZF2DNt01bfJzv7DuHZ7OdUJLzJDu8zp6T5GONYQmZ8wG6o/NHQLnvW7YNtd7VHLl+LrNugvujK2xF/UQmv2OcEHc9vd5AJtDatLF+0N7SPtbqYw9gpDj7MOTF81/F0dPYtd70NuhUk2YcidvjTzPCzejdq0aEZdufHyUryXSdVkSQ5A6JSDGj0j05yA0ytWlJqdXkDkOlOSzq2pEcBPPFEqqbJ11KvB6wIi/gCkqzcXqGaua+g==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tDBLd-0001K4-RF for bug-gnu-emacs@gnu.org; Mon, 18 Nov 2024 18:40:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 18 Nov 2024 23:40:01 +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.17319731515001 (code B ref 74408); Mon, 18 Nov 2024 23:40:01 +0000 Original-Received: (at 74408) by debbugs.gnu.org; 18 Nov 2024 23:39:11 +0000 Original-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 Original-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=; In-Reply-To: (Stefan Monnier's message of "Mon, 18 Nov 2024 18:25:31 -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:295616 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. 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 --=-=-=--