Make auto-completion activate/deactivate smartparens properly

auto-completion did not respect the smartparens-mode
defined in the dotfile when disabling/restoring it.

In addition when starting a yasnippet expansion
smartparens-mode was not properly restored resulting
in having smartparens always disabled.

This PR tries to fix both issues. Though judging from
the comments this could kill `hippie-expand` expansion.
However as yasnippet is more common I think this is
to be preferred.
This commit is contained in:
Maximilian Wolff 2021-03-16 22:21:40 +01:00
parent 9ff2004706
commit 8f854da649
No known key found for this signature in database
GPG key ID: 2DD07025BFDBD89A
3 changed files with 28 additions and 26 deletions

View file

@ -96,16 +96,16 @@ Available PROPS:
(push `(add-to-list ',raw-backends-var-name ',backend) result))
;; define initialization hook function
(push `(defun ,init-func-name ()
,(format "Initialize company for %S." mode)
(if auto-completion-enable-snippets-in-popup
(setq ,backends-var-name
(mapcar 'spacemacs//show-snippets-in-company
,raw-backends-var-name))
(setq ,backends-var-name ,raw-backends-var-name))
(set (make-variable-buffer-local 'auto-completion-front-end)
'company)
(set (make-variable-buffer-local 'company-backends)
,backends-var-name)) result)
,(format "Initialize company for %S." mode)
(if auto-completion-enable-snippets-in-popup
(setq ,backends-var-name
(mapcar 'spacemacs//show-snippets-in-company
,raw-backends-var-name))
(setq ,backends-var-name ,raw-backends-var-name))
(set (make-variable-buffer-local 'auto-completion-front-end)
'company)
(set (make-variable-buffer-local 'company-backends)
,backends-var-name)) result)
(when call-hooks
(push `(,init-func-name) result))
(when hooks
@ -384,24 +384,26 @@ MODE parameter must match the :modes values used in the call to
;; but NOT for the nested ones.
;;
;; That's why we introduce `spacemacs--yasnippet-expanding' below.
;;
;; MWO 2021-03-16
;; I have removed spacemacs--yasnippet-expanding as it prevents
;; default yasnippet expansions from seeing the value of smartparens-mode.
;; This will effectively disable smartparens with the first yasnippet expand.
;; As `hippie-expand' is less frequently used than yasnippet I think it is
;; better to have smartparens state preserved with the default case.
(defvar spacemacs--smartparens-enabled-initially t
"Stored whether smartparens is originally enabled or not.")
(defvar spacemacs--yasnippet-expanding nil
"Whether the snippet expansion is in progress.")
(defun spacemacs//smartparens-disable-before-expand-snippet ()
"Handler for `yas-before-expand-snippet-hook'.
Disable smartparens and remember its initial state."
;; Remember the initial smartparens state only once, when expanding a top-level snippet.
(unless spacemacs--yasnippet-expanding
(setq spacemacs--yasnippet-expanding t
spacemacs--smartparens-enabled-initially smartparens-mode))
(smartparens-mode -1))
(setq spacemacs--smartparens-enabled-initially (or smartparens-mode smartparens-strict-mode))
(spacemacs//deactivate-smartparens))
(defun spacemacs//smartparens-restore-after-exit-snippet ()
"Handler for `yas-after-exit-snippet-hook'.
Restore the initial state of smartparens."
(setq spacemacs--yasnippet-expanding nil)
(when spacemacs--smartparens-enabled-initially
(smartparens-mode 1)))
(spacemacs//activate-smartparens)))

View file

@ -27,8 +27,8 @@
(ivy-yasnippet :requires ivy)
smartparens
yasnippet
yasnippet-snippets
))
yasnippet-snippets))
;; TODO replace by company-ispell which comes with company
;; to be moved to spell-checking layer as well
@ -39,9 +39,9 @@
(progn
(setq ac-ispell-requires 4)
(with-eval-after-load 'auto-complete
(ac-ispell-setup))
;; (add-hook 'markdown-mode-hook 'ac-ispell-ac-setup)
)))
(ac-ispell-setup)))))
;; (add-hook 'markdown-mode-hook 'ac-ispell-ac-setup)
(defun auto-completion/init-auto-complete ()
(use-package auto-complete
@ -337,8 +337,8 @@
(spacemacs|require-when-dumping 'yasnippet)
(spacemacs/add-to-hooks 'spacemacs/load-yasnippet '(prog-mode-hook
markdown-mode-hook
org-mode-hook))
)
org-mode-hook)))
:config (spacemacs|diminish yas-minor-mode "" " y")))
(defun auto-completion/init-yasnippet-snippets ())

View file

@ -90,7 +90,7 @@
;; enable fuzzy matching in code buffer and SLIME REPL
(setq slime-complete-symbol*-fancy t)
(setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol)
(add-hook 'slime-repl-mode-hook #'spacemacs//disable-smartparens)
(add-hook 'slime-repl-mode-hook #'spacemacs//deactivate-smartparens)
(spacemacs/add-to-hooks 'slime-mode '(lisp-mode-hook)))
:config
(progn