Correctly wrap auto-fill-function when it's toggled on later

* yasnippet.el (yas--auto-fill-wrapper): New function, extracted from
`yas-minor-mode'.
(yas-minor-mode): Call it, and it to `auto-fill-mode-hook'.
This commit is contained in:
Noam Postavsky 2017-03-26 13:30:28 -04:00
parent b4d2f9cb4e
commit 5043a96121

View File

@ -768,6 +768,12 @@ which decides on the snippet to expand.")
(defvar yas-minor-mode-hook nil (defvar yas-minor-mode-hook nil
"Hook run when `yas-minor-mode' is turned on.") "Hook run when `yas-minor-mode' is turned on.")
(defun yas--auto-fill-wrapper ()
(when (and auto-fill-function
(not (eq auto-fill-function #'yas--auto-fill)))
(setq yas--original-auto-fill-function auto-fill-function)
(setq auto-fill-function #'yas--auto-fill)))
;;;###autoload ;;;###autoload
(define-minor-mode yas-minor-mode (define-minor-mode yas-minor-mode
"Toggle YASnippet mode. "Toggle YASnippet mode.
@ -802,14 +808,13 @@ Key bindings:
;; Perform JIT loads ;; Perform JIT loads
(yas--load-pending-jits) (yas--load-pending-jits)
;; Install auto-fill handler. ;; Install auto-fill handler.
(when (and auto-fill-function (yas--auto-fill-wrapper) ; Now...
(not (eq auto-fill-function #'yas--auto-fill))) (add-hook 'auto-fill-mode-hook #'yas--auto-fill-wrapper)) ; or later.
(setq yas--original-auto-fill-function auto-fill-function)
(setq auto-fill-function #'yas--auto-fill)))
(t (t
;; Uninstall the direct keymaps, post-command hook, and ;; Uninstall the direct keymaps, post-command hook, and
;; auto-fill handler. ;; auto-fill handler.
(remove-hook 'post-command-hook #'yas--post-command-handler t) (remove-hook 'post-command-hook #'yas--post-command-handler t)
(remove-hook 'auto-fill-mode-hook #'yas--auto-fill-wrapper)
(when (local-variable-p 'yas--original-auto-fill-function) (when (local-variable-p 'yas--original-auto-fill-function)
(setq auto-fill-function yas--original-auto-fill-function)) (setq auto-fill-function yas--original-auto-fill-function))
(setq emulation-mode-map-alists (setq emulation-mode-map-alists