Fix yasnippet+hippie-expand interop

This commit is contained in:
Henrik Lissner 2020-07-23 00:55:51 -04:00
parent 1dfe690f36
commit 7a868b1537
No known key found for this signature in database
GPG Key ID: 5F6C0EA160557395

View File

@ -93,6 +93,31 @@
:filter-return #'yas--all-templates
(cl-delete-duplicates templates :test #'equal))
;; HACK Smartparens will interfere with snippets expanded by `hippie-expand`,
;; so temporarily disable smartparens during snippet expansion.
(after! hippie-exp
(defvar +snippets--smartparens-enabled-p t)
(defvar +snippets--expanding-p nil)
;; Is called for all snippet expansions,
(add-hook! 'yas-before-expand-snippet-hook
(defun +snippets--disable-smartparens-before-expand-h ()
;; Remember the initial smartparens state only once, when expanding a
;; top-level snippet.
(unless +snippets--expanding-p
(setq +snippets--expanding-p t
+snippets--smartparens-enabled-p smartparens-mode))
(when smartparens-mode
(smartparens-mode -1))))
;; Is called only for the top level snippet, but not for the nested ones.
;; Hence `+snippets--expanding-p'.
(add-hook! 'yas-after-exit-snippet-hook
(defun +snippets--restore-smartparens-after-expand-h ()
(setq +snippets--expanding-p nil)
(when +snippets--smartparens-enabled-p
(smartparens-mode 1)))))
;; If in a daemon session, front-load this expensive work:
(if (daemonp) (yas-reload-all)))