From 7a868b1537303fa39907b6500aa3d2fc92836651 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 23 Jul 2020 00:55:51 -0400 Subject: [PATCH] Fix yasnippet+hippie-expand interop --- modules/editor/snippets/config.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/modules/editor/snippets/config.el b/modules/editor/snippets/config.el index f16a1f53a..f4d69ed27 100644 --- a/modules/editor/snippets/config.el +++ b/modules/editor/snippets/config.el @@ -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)))