unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Daniele Nicolodi <daniele@grinta.net>
To: emacs-devel@gnu.org
Subject: Re: Documentation about the completion framework
Date: Mon, 21 Jan 2019 15:21:15 -0700	[thread overview]
Message-ID: <2411a612-1468-3997-8fc7-e195d5c53a79@grinta.net> (raw)
In-Reply-To: <jwvef95btxe.fsf-monnier+emacs@gnu.org>

Hi Stefan,

thank you for the detailed answer.

On 21/01/2019 14:17, Stefan Monnier wrote:
>> Unfortunately docstring of the relevant elisp functions are not always
>> detailed and in some cases not complete. I would also really appreciate
>> some documentation on how the framework can be used and how is it
>> supposed to be used, even better if there would be some hints on how to
>> keep it efficient.
>>
>> Does such documentation exist somewhere? Does anyone have any resource
>> to recommend?
> 
> It's mostly available in docstrings.

Indeed, but, for example, I was unable to find how a completion table
should be defined or what it should return. Maybe missed it, but I would
have expected this to be linked from the completion-at-point-functions
docstring. Also, I was unable to find what is the role of the start and
end markers. In the specific, what's the purpose of specifying an end
that is past (point) ?

> For example, C-h o completion-at-point-functions says:
> 
>     [...]
>     NOTE: These functions should be cheap to run since they’re sometimes
>     run from ‘post-command-hook’; and they should ideally only choose
>     which kind of completion table to use, and not pre-filter it based
>     on the current text between START and END (e.g., they should not
>     obey ‘completion-styles’).
> 
>> One specific question I have: in some circumstances completion-at-point
>> enters a mode in which it is called for each keystroke (I think this is
>> completion-in-region-mode). How does this happen and why?  I would like
>> to avoid that my function to collect completion targets get called on
>> each keystroke. Is there a way to do that?
> 
> Yes: don't collect candidates when that function is called.
> Instead, the function should return a completion table which will
> compute the candidates only if it's called.

How is a completion table defined? what are the string, pred, action
arguments passed to it? What should it return?

>  E.g.:
> 
>     (defun my-completion-at-point-function ()
>       (when (relevant)
>         (let (candidates
>               (candidates-computed nil)
>               (start ...)
>               (end ...)
>               (completion-table
>                (lambda (string pred action)
>                  (unless candidates-computed
>                    (setq candidates-computed t)
>                    (setq candidates (my-collect-candidates)))
>                  (complete-with-action action candidates string pred))))
>           (list start end completion-table))))
> 
> tho you probably want to cache your completion candidates elsewhere
> (exactly where to cache them depends on when they need to be
> recomputed, so often it's best to cache them in a global variable and
> flush them from other places in the code).

This is good advice, but a bit too high level for me to be able to
translate it into code. Where should I look for examples of this sort of
caching?

Thank you!

Cheers,
Dan



  reply	other threads:[~2019-01-21 22:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-21 19:22 Documentation about the completion framework Daniele Nicolodi
2019-01-21 19:49 ` Eric Abrahamsen
2019-01-21 22:33   ` Daniele Nicolodi
2019-01-21 23:11     ` Eric Abrahamsen
2019-01-21 23:13   ` Drew Adams
2019-01-22 16:31     ` Eric Abrahamsen
2019-01-22 20:22       ` Drew Adams
2019-01-21 21:17 ` Stefan Monnier
2019-01-21 22:21   ` Daniele Nicolodi [this message]
2019-01-22  2:02   ` Daniele Nicolodi
2019-01-22  3:37     ` Stefan Monnier
2019-01-22  3:53       ` Daniele Nicolodi
2019-01-22 12:11         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2411a612-1468-3997-8fc7-e195d5c53a79@grinta.net \
    --to=daniele@grinta.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).