13

In a big C++ project I use dabberv-expand (aka M-/). Rtags, ctags, csope etc do not work by different reasons. Unfortunately I do not know how to enforce dabbrev to use a fuzzy search. So I decided to use ivy. The following code does almost everything I want:

(defun ivy-complete ()
  (interactive)
  (dabbrev--reset-global-variables)
  (let* ((abbrev (dabbrev--abbrev-at-point))
         (candidates (dabbrev--find-all-expansions abbrev t)))
    (when (not (null candidates))
      (let* ((found-match (ivy-read "matches " candidates
                                :preselect (thing-at-point 'word)
                                :sort t))
            (abbrev-length (length abbrev)))
        (insert (substring found-match abbrev-length))))))

One thing is missed. The completion shows the candidates in the minibuffer. I want them to be displayed in a popup window near the entry point. I tried to use ivy-display-function-popup and ivy-display-function-overlay but failed.

Questions: how to show the candidates in a popup or overlay window? May be it is possible to use ivy as a backend for some other packet like company?

1 Answer 1

11

What you want can be achieved by adding a new source to completion-at-point-functions. This isn't specific to ivy, but ivy makes use of it:

(defun dabbrev-complation-at-point ()
  (dabbrev--reset-global-variables)
  (let* ((abbrev (dabbrev--abbrev-at-point))
         (candidates (dabbrev--find-all-expansions abbrev t))
         (bnd (bounds-of-thing-at-point 'symbol)))
    (list (car bnd) (cdr bnd) candidates)))
(add-to-list 'completion-at-point-functions 'dabbrev-complation-at-point)

After this setup (make sure to do it for the proper major-mode using its hook), press C-M-i (complete-symbol) to get the list of completions. If you have ivy-mode on, this list will be shown inline for recent versions of ivy.

1
  • You're welcome. On this site, if the anwer works, you should mark it as "accepted".
    – abo-abo
    Feb 14, 2017 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.