elken / yasnippet-capf

Completion-At-Point Extension for YASnippet
GNU General Public License v3.0
40 stars 9 forks source link
emacs

+title: yasnippet-capf

A simple [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Completion-in-Buffers.html][capf]] (Completion-At-Point Function) for completing [[https://github.com/joaotavora/yasnippet][yasnippet]] snippets.

=packages.el=

+begin_src emacs-lisp

(package! yasnippet-capf :recipe (:host github :repo "elken/yasnippet-capf"))

+end_src

Use the below recipe for =use-package= managers

+begin_src emacs-lisp

(use-package yasnippet-capf :after cape :config (add-to-list 'completion-at-point-functions #'yasnippet-capf))

+end_src

If you're struggling to get completions using this approach, or you only want them available in certain modes, you might have better luck instead registering a hook.

+begin_src emacs-lisp

(use-package yasnippet-capf :after cape :init (defun my/yasnippet-capf-h () (add-to-list 'completion-at-point-function #'yasnippet-capf)) :hook (emacs-lisp-mode . my/yasnippet-capf-h))

+end_src

** =yasnippet-capf-lookup-by= Which lookup method to use to query snippets. By default, this uses the key to query against but if preferred you can also set this to use the name of the snippet.

+begin_src emacs-lisp

(setq yasnippet-capf-lookup-by 'name) ;; Prefer the name of the snippet instead

+end_src