GNU bug report logs - #74408
30.0.92; FR: Add a function completion-list-candidate-at-point

Previous Next

Package: emacs;

Reported by: Daniel Mendler <mail <at> daniel-mendler.de>

Date: Sun, 17 Nov 2024 21:11:02 UTC

Severity: wishlist

Found in version 30.0.92

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 74408 in the body.
You can then email your comments to 74408 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org:
bug#74408; Package emacs. (Sun, 17 Nov 2024 21:11:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Daniel Mendler <mail <at> daniel-mendler.de>:
New bug report received and forwarded. Copy sent to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org. (Sun, 17 Nov 2024 21:11:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Daniel Mendler <mail <at> daniel-mendler.de>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.0.92; FR: Add a function completion-list-candidate-at-point
Date: Sun, 17 Nov 2024 22:10:08 +0100
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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74408; Package emacs. (Sun, 17 Nov 2024 21:47:02 GMT) Full text and rfc822 format available.

Message #8 received at 74408 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Daniel Mendler <mail <at> daniel-mendler.de>
Cc: 74408 <at> debbugs.gnu.org
Subject: Re: bug#74408: 30.0.92; FR: Add a function
 completion-list-candidate-at-point
Date: Sun, 17 Nov 2024 16:46:08 -0500
> 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





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74408; Package emacs. (Mon, 18 Nov 2024 00:09:02 GMT) Full text and rfc822 format available.

Message #11 received at 74408 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Mendler <mail <at> daniel-mendler.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 74408 <at> debbugs.gnu.org
Subject: Re: bug#74408: 30.0.92; FR: Add a function
 completion-list-candidate-at-point
Date: Mon, 18 Nov 2024 01:06:18 +0100
[Message part 1 (text/plain, inline)]
Stefan Monnier <monnier <at> iro.umontreal.ca> 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

[0001-New-function-completion-list-candidate-at-point.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74408; Package emacs. (Mon, 18 Nov 2024 23:26:01 GMT) Full text and rfc822 format available.

Message #14 received at 74408 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Daniel Mendler <mail <at> daniel-mendler.de>
Cc: 74408 <at> debbugs.gnu.org
Subject: Re: bug#74408: 30.0.92; FR: Add a function
 completion-list-candidate-at-point
Date: Mon, 18 Nov 2024 18:25:31 -0500
> 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





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74408; Package emacs. (Mon, 18 Nov 2024 23:40:01 GMT) Full text and rfc822 format available.

Message #17 received at 74408 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Mendler <mail <at> daniel-mendler.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 74408 <at> debbugs.gnu.org
Subject: Re: bug#74408: 30.0.92; FR: Add a function
 completion-list-candidate-at-point
Date: Tue, 19 Nov 2024 00:36:49 +0100
[Message part 1 (text/plain, inline)]
Stefan Monnier <monnier <at> iro.umontreal.ca> 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

[0001-New-function-completion-list-candidate-at-point.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74408; Package emacs. (Tue, 19 Nov 2024 03:00:02 GMT) Full text and rfc822 format available.

Message #20 received at 74408 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Daniel Mendler <mail <at> daniel-mendler.de>
Cc: 74408 <at> debbugs.gnu.org
Subject: Re: bug#74408: 30.0.92; FR: Add a function
 completion-list-candidate-at-point
Date: Mon, 18 Nov 2024 21:59:15 -0500
>> 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





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#74408; Package emacs. (Tue, 19 Nov 2024 10:06:02 GMT) Full text and rfc822 format available.

Message #23 received at 74408 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Mendler <mail <at> daniel-mendler.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 74408 <at> debbugs.gnu.org
Subject: Re: bug#74408: 30.0.92; FR: Add a function
 completion-list-candidate-at-point
Date: Tue, 19 Nov 2024 11:03:09 +0100
[Message part 1 (text/plain, inline)]
Stefan Monnier <monnier <at> iro.umontreal.ca> 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

[0001-New-function-completion-list-candidate-at-point.patch (text/x-diff, attachment)]

Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Fri, 29 Nov 2024 17:28:02 GMT) Full text and rfc822 format available.

Notification sent to Daniel Mendler <mail <at> daniel-mendler.de>:
bug acknowledged by developer. (Fri, 29 Nov 2024 17:28:02 GMT) Full text and rfc822 format available.

Message #28 received at 74408-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Daniel Mendler <mail <at> daniel-mendler.de>
Cc: 74408-done <at> debbugs.gnu.org
Subject: Re: bug#74408: 30.0.92; FR: Add a function
 completion-list-candidate-at-point
Date: Fri, 29 Nov 2024 12:27:06 -0500
> Thanks. I've attached the latest version of the patch, where the
> function is simplified without save-excursion.

Merged, closing, thank you,


        Stefan





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 28 Dec 2024 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 172 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.