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?

Alex
  • 133
  • 1
  • 4

1 Answers1

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.

abo-abo
  • 13,943
  • 1
  • 29
  • 43