Files
.emacs.d/modules/text-editing/siren-yasnippet.el
Jim Myhrberg f70de31989 fix(completion/yasnippet): fix completion issues caused by yasnippet
This somewhat works around some changes to cape, which I was abusing to
effectively get a capf yasnippet function that would only return results
on exact matches. This allows normal lsp completion to work just fine,
except for exact matches against specific snippets.

Now we use the yasnippet-capf package instead, no longer needing the
company-yasnippet package, and hacking it to also only give a single
result back, with some caveats.
2024-10-18 02:47:37 +01:00

69 lines
2.0 KiB
EmacsLisp

;;; siren-yasnippet.el --- jimeh's Emacs Siren: yasnippet configuration.
;;; Commentary:
;; Basic configuration for yasnippet.
;;; Code:
(require 'cl-lib)
(use-package yasnippet
:diminish yas-minor-mode
:hook (emacs-startup . yas-reload-all)
:config
(yas-global-mode))
(use-package yasnippet-snippets
:after yasnippet
:config
(let ((skip-file (expand-file-name "prog-mode/.yas-skip"
yasnippet-snippets-dir)))
(when (not (file-exists-p skip-file))
(make-empty-file skip-file t))))
(use-package yasnippet-capf
:preface
(defgroup siren-yasnippet-capf nil
"Siren specific tweaks to yasnippet-capf."
:group 'yasnippet-capf)
(defcustom siren-yasnippet-capf-exact-match t
"Only return exact matches.
When non-nil, only exact matches will be returned by `yasnippet-capf'.
When nil, all matches will be returned.
Annoyingly, when enabled this seems to hide all completion results for
yasnippet, cause the capf function is run twice, once with the given
prefix, and once without any at all.
It seems like the first call is used to determine if the next capf function
should be used or not, and the second call is what company-mode uses to render
completions.
For my use-case, this is fine, as I only want `yasnippet-capf' triggered
for exact matches, and for everything else move on to the lsp-mode's
`lsp-completion-at-point' function."
:type 'boolean
:group 'siren-yasnippet-capf)
(defun siren-yasnippet-capf--advice-exact-match-only (orig-fun &rest args)
"Advice to filter out non-exact matches."
(let ((candidates (apply orig-fun args))
(prefix (nth 0 args)))
(if siren-yasnippet-capf-exact-match
(cl-remove-if-not (lambda (candidate)
(string= prefix (substring-no-properties candidate)))
candidates)
candidates)))
:config
(advice-add 'yasnippet-capf-candidates
:around #'siren-yasnippet-capf--advice-exact-match-only))
(provide 'siren-yasnippet)
;;; siren-yasnippet.el ends here