company-flx icon indicating copy to clipboard operation
company-flx copied to clipboard

Dabbrev support

Open cartolari opened this issue 10 years ago • 4 comments
trafficstars

One thing I miss in company-flx is support for the company-dabbrev backend, so I implemented a really simple function for completion-at-point-functions in terms of dabbrev.

The capf function, my/dabbrev-capf, can be found in my dotfiles, inside init-company.el.

Maybe company-flx could add something like this as an alternative to the company-dabbrev backend.

cartolari avatar Nov 02 '15 22:11 cartolari

Hi there.

So far, this works really well, with the following caveats:

  • The current prefix also shows as a candidate, which is not a useful completion.
  • The message Scanning for dabbrevs...done is echoed constantly.

It's super fast, though, which is something my alternative method isn't yet. Don't worry about fixing your code. If my method doesn't work out, I can fix it myself.

PythonNut avatar Nov 06 '15 17:11 PythonNut

Thanks for the reponse.

Regarding the issues:

  • I couldn't find a way to get all abbreviations without passing an argument (with an empty string for example), so the better way I've found was to pass the first char of the thing-at-point.
  • Yes, it's pretty annoying for me too, so I rebound message with flet inside the my/dabbrev-find-all, and the issue is gone.

One thing I've noted, and please correct me if I'm wrong, is that the completion-at-point-functions return every possible completion (when company-flx is enabled) and you sort and filter them in a company transform, company-flx-transformer, right? So when you have two completion-at-point-functions and the first provides no matching candidates there'd be no way for the next one to be used, because at the point that the flx score is calculated it's to late for the next one to be called. The case I detected this was with the ggtags-completion-at-point and with my/dabbrev-capf.

cartolari avatar Nov 08 '15 17:11 cartolari

@cartolari it seems that the snippet you originally posted is gone now. Do you still have it?

PythonNut avatar Apr 24 '16 00:04 PythonNut

Sorry for the delay, I should have left the snippet here in the issue. One thing I've noticed is that this code is not so fast for large buffers, so it may require some tweaks to be implemented in company-flx.

(defun my/dabbrev-find-all (abbrev)
  "Return a list of expansions matched by ABBREV."
  (let ((dabbrev-check-other-buffers t)
        (dabbrev-check-all-buffers nil))
    (flet ((message (&rest args)))
      (dabbrev--reset-global-variables)
      (dabbrev--find-all-expansions abbrev t))))

(defun my/dabbrev-capf ()
  "Dabbrev 'complete-at-point-functions' implementation."
  (let ((bounds (bounds-of-thing-at-point 'symbol)))
    (list
     (car bounds)
     (cdr bounds)
     (my/dabbrev-find-all (substring (thing-at-point 'symbol t) 0 1))
     :exclusive 'no)))

cartolari avatar May 11 '16 18:05 cartolari