unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* merging results from completion-at-point-functions
@ 2022-04-29 10:25 Eric S Fraga
  2022-04-29 15:08 ` Eric Abrahamsen
  0 siblings, 1 reply; 16+ messages in thread
From: Eric S Fraga @ 2022-04-29 10:25 UTC (permalink / raw)
  To: help-gnu-emacs

Hello all,

I currently use '(cape-dabbrev cape-ispell cape-dict) as the list for
completion-at-point-functions when writing prose.

I keep trying different orderings of these entries as the behaviour
changes significantly, not surprisingly given the /greedy/ nature of
completing-at-point, if I understand things correctly.  Ideally, I would
like a merged search for potential completions, such as I believe
company-mode does if you group backends.

Is it possible to specify a grouping or merge operation?  Or is there a
generalised capf that does this, I guess?

Thank you,
eric

-- 
Professor Eric S Fraga, UCL; GnuPG: 0xc89193d8fffcf67d




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-04-29 10:25 merging results from completion-at-point-functions Eric S Fraga
@ 2022-04-29 15:08 ` Eric Abrahamsen
  2022-04-29 17:05   ` Eric S Fraga
  0 siblings, 1 reply; 16+ messages in thread
From: Eric Abrahamsen @ 2022-04-29 15:08 UTC (permalink / raw)
  To: help-gnu-emacs

Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> Hello all,
>
> I currently use '(cape-dabbrev cape-ispell cape-dict) as the list for
> completion-at-point-functions when writing prose.
>
> I keep trying different orderings of these entries as the behaviour
> changes significantly, not surprisingly given the /greedy/ nature of
> completing-at-point, if I understand things correctly.  Ideally, I would
> like a merged search for potential completions, such as I believe
> company-mode does if you group backends.
>
> Is it possible to specify a grouping or merge operation?  Or is there a
> generalised capf that does this, I guess?

Two possibilities: since you're using cape, use `cape-super-capf' to
merge a bunch of cape capf functions into one.

Other possibility: use `completion-table-merge' in exactly the same way.
This should be the general version of what `cape-super-capf' does.

Please try both and report back! I'm very curious, as well.

Eric





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-04-29 15:08 ` Eric Abrahamsen
@ 2022-04-29 17:05   ` Eric S Fraga
  2022-04-29 18:26     ` Eric Abrahamsen
  0 siblings, 1 reply; 16+ messages in thread
From: Eric S Fraga @ 2022-04-29 17:05 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Eric,

thank you for the quick response.

On Friday, 29 Apr 2022 at 08:08, Eric Abrahamsen wrote:
> Two possibilities: since you're using cape, use `cape-super-capf' to
> merge a bunch of cape capf functions into one.

First of all, apologies: this is in the cape documentation which I
forgot to look at again.  Nevertheless, this doesn't work at all.  If I
do

(setq-local completion-at-point-functions
    (list (cape-super-capf #'cape-dabbrev #'cape-dict #'cape-keyword)))

when visiting an appropriate file, as the web page
(https://github.com/minad/cape) suggests, nothing happens when invoking
completion-at-point.

> Other possibility: use `completion-table-merge' in exactly the same way.

This one I cannot figure out how to use.  My elisp-fu is obviously not
up to scratch. :-(

Thanks again,
eric

-- 
Eric S Fraga with org 9.5.3 in Emacs 29.0.50 on Debian 11.3




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-04-29 17:05   ` Eric S Fraga
@ 2022-04-29 18:26     ` Eric Abrahamsen
  2022-04-29 20:52       ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-05-01 16:31       ` Eric S Fraga
  0 siblings, 2 replies; 16+ messages in thread
From: Eric Abrahamsen @ 2022-04-29 18:26 UTC (permalink / raw)
  To: help-gnu-emacs

Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> Hi Eric,
>
> thank you for the quick response.
>
> On Friday, 29 Apr 2022 at 08:08, Eric Abrahamsen wrote:
>> Two possibilities: since you're using cape, use `cape-super-capf' to
>> merge a bunch of cape capf functions into one.
>
> First of all, apologies: this is in the cape documentation which I
> forgot to look at again.  Nevertheless, this doesn't work at all.  If I
> do
>
> (setq-local completion-at-point-functions
>     (list (cape-super-capf #'cape-dabbrev #'cape-dict #'cape-keyword)))
>
> when visiting an appropriate file, as the web page
> (https://github.com/minad/cape) suggests, nothing happens when invoking
> completion-at-point.

Sounds like some kind of bug, then. I'd check the github issues (several
of the closed issues are about super capes) and maybe open a new one.

>> Other possibility: use `completion-table-merge' in exactly the same way.
>
> This one I cannot figure out how to use.  My elisp-fu is obviously not
> up to scratch. :-(

No worries! It's supposed to work the same way:

(setq my-merged-table (completion-table-merge #'cap-dabbrev
#'cape-dict))

(setq-local completion-at-point-functions (list #'my-merged-table))

That appears to be working for me (at least, it raises a "lookup-words"
error from `cape-dict', so at least it's *trying* to work).

Eric





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-04-29 18:26     ` Eric Abrahamsen
@ 2022-04-29 20:52       ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-04-29 22:02         ` Eric Abrahamsen
                           ` (2 more replies)
  2022-05-01 16:31       ` Eric S Fraga
  1 sibling, 3 replies; 16+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-04-29 20:52 UTC (permalink / raw)
  To: help-gnu-emacs

>> (setq-local completion-at-point-functions
>>     (list (cape-super-capf #'cape-dabbrev #'cape-dict #'cape-keyword)))

Note that this sets up these CAPF functions only for the buffer that's
current when the code is executed, so if you put it into your .emacs
it's probably going to affect completions in *scratch* only.

> (setq my-merged-table (completion-table-merge #'cap-dabbrev
> #'cape-dict))

I don't think so: `cape-dabbrev` is a CAPF function, not a completion table.


        Stefan




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-04-29 20:52       ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2022-04-29 22:02         ` Eric Abrahamsen
  2022-04-30 23:48         ` Ergus
  2022-05-01 16:29         ` Eric S Fraga
  2 siblings, 0 replies; 16+ messages in thread
From: Eric Abrahamsen @ 2022-04-29 22:02 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

>>> (setq-local completion-at-point-functions
>>>     (list (cape-super-capf #'cape-dabbrev #'cape-dict #'cape-keyword)))
>
> Note that this sets up these CAPF functions only for the buffer that's
> current when the code is executed, so if you put it into your .emacs
> it's probably going to affect completions in *scratch* only.
>
>> (setq my-merged-table (completion-table-merge #'cap-dabbrev
>> #'cape-dict))
>
> I don't think so: `cape-dabbrev` is a CAPF function, not a completion table.

Ooops. Misinformation! I do often forget the distinction between capf
functions and completion tables.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-04-29 20:52       ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-04-29 22:02         ` Eric Abrahamsen
@ 2022-04-30 23:48         ` Ergus
  2022-05-01  2:15           ` Stefan Monnier
  2022-05-01 16:29         ` Eric S Fraga
  2 siblings, 1 reply; 16+ messages in thread
From: Ergus @ 2022-04-30 23:48 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

On Fri, Apr 29, 2022 at 04:52:21PM -0400, Stefan Monnier via Users list for the GNU Emacs text editor wrote:
>>> (setq-local completion-at-point-functions
>>>     (list (cape-super-capf #'cape-dabbrev #'cape-dict #'cape-keyword)))
>
>Note that this sets up these CAPF functions only for the buffer that's
>current when the code is executed, so if you put it into your .emacs
>it's probably going to affect completions in *scratch* only.
>
>> (setq my-merged-table (completion-table-merge #'cap-dabbrev
>> #'cape-dict))
>
>I don't think so: `cape-dabbrev` is a CAPF function, not a completion table.
>
>
>        Stefan
>
>
Hi Stefan...

Maybe a bit off-topic... but somehow related:

Is it there a way to show the current capf backend for example in the
mode-line?? Company has such thing, and it may be useful for example, to
know which completion-at-point-functions is working better than
others... Because sometimes different functions generate similar
outputs and it may be useful to know which are the one in use, specially
when exclusive is false in some of them.

Any Idea?
Best,
Ergus.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-04-30 23:48         ` Ergus
@ 2022-05-01  2:15           ` Stefan Monnier
  2022-05-01  2:58             ` Emanuel Berg
  0 siblings, 1 reply; 16+ messages in thread
From: Stefan Monnier @ 2022-05-01  2:15 UTC (permalink / raw)
  To: Ergus; +Cc: help-gnu-emacs

> Is it there a way to show the current capf backend for example in the
> mode-line??

The code doesn't offer this feature yet, no.  Patch welcome,


        Stefan




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-05-01  2:15           ` Stefan Monnier
@ 2022-05-01  2:58             ` Emanuel Berg
  2022-05-01 17:20               ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 16+ messages in thread
From: Emanuel Berg @ 2022-05-01  2:58 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier wrote:

>> Is it there a way to show the current capf backend for
>> example in the mode-line??
>
> The code doesn't offer this feature yet, no. Patch welcome,

And when will the program come that will write this program
for us?

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-04-29 20:52       ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-04-29 22:02         ` Eric Abrahamsen
  2022-04-30 23:48         ` Ergus
@ 2022-05-01 16:29         ` Eric S Fraga
  2022-05-01 17:22           ` Stefan Monnier via Users list for the GNU Emacs text editor
  2 siblings, 1 reply; 16+ messages in thread
From: Eric S Fraga @ 2022-05-01 16:29 UTC (permalink / raw)
  To: help-gnu-emacs

On Friday, 29 Apr 2022 at 16:52, Stefan Monnier via Users list for the GNU Emacs text editor wrote:
>>> (setq-local completion-at-point-functions
>>>     (list (cape-super-capf #'cape-dabbrev #'cape-dict #'cape-keyword)))
>
> Note that this sets up these CAPF functions only for the buffer that's
> current when the code is executed, so if you put it into your .emacs
> it's probably going to affect completions in *scratch* only.

Yes, that's clear.  Thank you.

I am setting the variable in the right place to have
it set for the buffer I am writing in.  But it just doesn't do anything
when I try to complete.

To check, if I use

(setq-local completion-at-point-functions (list #'cape-dabbrev))

instead of the expression above, that particular capf does get invoked.

-- 
Eric S Fraga with org 9.5.3 in Emacs 29.0.50 on Debian 11.3




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-04-29 18:26     ` Eric Abrahamsen
  2022-04-29 20:52       ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2022-05-01 16:31       ` Eric S Fraga
  1 sibling, 0 replies; 16+ messages in thread
From: Eric S Fraga @ 2022-05-01 16:31 UTC (permalink / raw)
  To: help-gnu-emacs

On Friday, 29 Apr 2022 at 11:26, Eric Abrahamsen wrote:
> Sounds like some kind of bug, then. I'd check the github issues (several
> of the closed issues are about super capes) and maybe open a new one.

This was a good suggestion and I'm pursuing some of the suggestions in
the issues.  If/when I get a solution, I'll post here for completeness.

Thank you,
eric

-- 
Eric S Fraga with org 9.5.3 in Emacs 29.0.50 on Debian 11.3




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-05-01  2:58             ` Emanuel Berg
@ 2022-05-01 17:20               ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-05-01 17:33                 ` tomas
  0 siblings, 1 reply; 16+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-05-01 17:20 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg [2022-05-01 04:58:41] wrote:
> Stefan Monnier wrote:
>>> Is it there a way to show the current capf backend for
>>> example in the mode-line??
>> The code doesn't offer this feature yet, no. Patch welcome,
> And when will the program come that will write this program
> for us?

The future is long past.
That program you're talking about is called Emacs.


        Stefan




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-05-01 16:29         ` Eric S Fraga
@ 2022-05-01 17:22           ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-05-02 11:47             ` Eric S Fraga
  0 siblings, 1 reply; 16+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-05-01 17:22 UTC (permalink / raw)
  To: help-gnu-emacs

Eric S Fraga [2022-05-01 17:29:54] wrote:
> On Friday, 29 Apr 2022 at 16:52, Stefan Monnier via Users list for the GNU Emacs text editor wrote:
>>>> (setq-local completion-at-point-functions
>>>>     (list (cape-super-capf #'cape-dabbrev #'cape-dict #'cape-keyword)))
>>
>> Note that this sets up these CAPF functions only for the buffer that's
>> current when the code is executed, so if you put it into your .emacs
>> it's probably going to affect completions in *scratch* only.
>
> Yes, that's clear.  Thank you.
>
> I am setting the variable in the right place to have
> it set for the buffer I am writing in.  But it just doesn't do anything
> when I try to complete.
>
> To check, if I use
>
> (setq-local completion-at-point-functions (list #'cape-dabbrev))
>
> instead of the expression above, that particular capf does get invoked.

What happens if you go to the place where you want completion to take
place and then do:

    M-: (funcall (cape-super-capf #'cape-dabbrev #'cape-dict #'cape-keyword)) RET

[ It's not supposed to have any effect other than returning a value, so
  the question is what value does it return.  ]


        Stefan




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-05-01 17:20               ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2022-05-01 17:33                 ` tomas
  2022-05-01 19:54                   ` Emanuel Berg
  0 siblings, 1 reply; 16+ messages in thread
From: tomas @ 2022-05-01 17:33 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 388 bytes --]

On Sun, May 01, 2022 at 01:20:34PM -0400, Stefan Monnier via Users list for the GNU Emacs text editor wrote:
> Emanuel Berg [2022-05-01 04:58:41] wrote:

[...]

> > And when will the program come that will write this program
> > for us?
> 
> The future is long past.
> That program you're talking about is called Emacs.

You just have to tell it. Nicely :-)

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-05-01 17:33                 ` tomas
@ 2022-05-01 19:54                   ` Emanuel Berg
  0 siblings, 0 replies; 16+ messages in thread
From: Emanuel Berg @ 2022-05-01 19:54 UTC (permalink / raw)
  To: help-gnu-emacs

tomas wrote:

>>> And when will the program come that will write this
>>> program for us?
>> 
>> The future is long past.
>> That program you're talking about is called Emacs.
>
> You just have to tell it. Nicely :-)

Little by little programs take control over America.

By and by software claims all of Russia.

Cold War 3.0 - AI vs AI?

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: merging results from completion-at-point-functions
  2022-05-01 17:22           ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2022-05-02 11:47             ` Eric S Fraga
  0 siblings, 0 replies; 16+ messages in thread
From: Eric S Fraga @ 2022-05-02 11:47 UTC (permalink / raw)
  To: help-gnu-emacs

On Sunday,  1 May 2022 at 13:22, Stefan Monnier via Users list for the GNU Emacs text editor wrote:
>     M-: (funcall (cape-super-capf #'cape-dabbrev #'cape-dict #'cape-keyword)) RET

It didn't do anything.

After a lot of experimentation and some discussions on the cape github
issue pages, I have determined that cape-super-capf does not work with
vanilla completion-at-point but does if you use corfu on top of it.

The settings I now have are:

  (global-corfu-mode)
  (corfu-history-mode)

and

(setq-local completion-at-point-functions
 (list
  (cape-super-capf #'cape-tex #'cape-dabbrev #'cape-dict #'cape-ispell)))

for org mode buffers only.

I have set up corfu to be invoked with TAB as I find the auto mode too
intrusive and it imposes a small but noticeable lag in my typing.

-- 
Eric S Fraga with org 9.5.3 in Emacs 29.0.50 on Debian 11.3




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-05-02 11:47 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-29 10:25 merging results from completion-at-point-functions Eric S Fraga
2022-04-29 15:08 ` Eric Abrahamsen
2022-04-29 17:05   ` Eric S Fraga
2022-04-29 18:26     ` Eric Abrahamsen
2022-04-29 20:52       ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-04-29 22:02         ` Eric Abrahamsen
2022-04-30 23:48         ` Ergus
2022-05-01  2:15           ` Stefan Monnier
2022-05-01  2:58             ` Emanuel Berg
2022-05-01 17:20               ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-05-01 17:33                 ` tomas
2022-05-01 19:54                   ` Emanuel Berg
2022-05-01 16:29         ` Eric S Fraga
2022-05-01 17:22           ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-05-02 11:47             ` Eric S Fraga
2022-05-01 16:31       ` Eric S Fraga

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).