[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: /srv/bzr/emacs/elpa r395: * company.el (company-capf): Add support f

From: Stefan Monnier
Subject: Re: /srv/bzr/emacs/elpa r395: * company.el (company-capf): Add support for `sorted' and `post-completion'.
Date: Sun, 05 May 2013 02:32:36 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

>> ;; (defun company-my-backend (command &optional arg &rest ignored)
>> -;;   (case command
>> -;;     (prefix (when (looking-back "foo\\>")
>> +;;   (pcase command
>> +;;     (`prefix (when (looking-back "foo\\>")
>> ;;               (match-string 0)))
>> -;;     (candidates (list "foobar" "foobaz" "foobarbaz"))
>> -;;     (meta (format "This value is named %s" arg))))
>> +;;     (`candidates (list "foobar" "foobaz" "foobarbaz"))
>> +;;     (`meta (format "This value is named %s" arg))))

> Like the header in company.el says, we still try to support Emacs 22 and
> 23. `pcase' was only added in 23.3, I believe.

But this is in a comment, so it's not a problem.

>> +(defun company-capf (command &optional arg &rest _args)
> ...
>> +    (duplicates nil) ;Don't bother.
>> +    (no-cache t)     ;FIXME: Improve!
>> +    (meta nil)       ;FIXME: Return one-line docstring for `arg'.
>> +    (doc-buffer nil) ;FIXME: Return help buffer for `arg'.
>> +    (location nil)   ;FIXME: Return (BUF . POS) or (FILE . LINENB) of `arg'.
>> +    (init nil)      ;Don't bother: plenty of other ways to initialize
>> the code.
> a) There's no need to return nils explicitly, other backends don't.

Indeed, I only need them to have a place where to put the FIXMEs.

> b) Who are these FIXMEs for?

Whoever takes on the challenge.

> I guess `meta' can be implemented by
> calling `:annotation-function' (don't know if it's appropriate), but
> `doc-buffer' and `location' don't have anything corresponding in
> `completion-extra-properties'.

`completion-extra-properties' can have anything you want in it.
Same for `completion-metadata'.  Of course, new entries in these
alists/plists won't be understood by other users of
completion-at-point-functions, but that's not a problem in itself.

>> +    (require-match nil)            ;This should be a property of the
>> front-end!
> Should it really?

Hmm... after writing an answer and throwing it away a few times, I think
you're right: this definitely makes sense for a backend and basically
means "I, as a backend, know that only those elements make sense here".

But in most cases the front-end can't use it to *prevent* the user from
writing something else (Emacs likes to let the user shoot himself in the
foot, on the assumption that the user knows better).  It could use it to
highlight a non-matching entry, OTOH.

>> +(defvar company-backend)
> This variable is declared about ~30 lines below that. Is it appropriate
> to have both declarations in the same file?

No, it was a quick fix.  Moving the declaration is probably a better option.

> It probably should, but, again, lexical-binding is not available in
> Emacs < 24. ATM I'm only using it to improve some logic that uses
> `boundp' in `company-elisp'.

I work under the assumption that my time is better spent if
I concentrate on users of Emacs-24 (users who want the newer features of
company can upgrade to Emacs-24).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]