From fd19698927d1976c40a1a24b34542a832ab5d4db Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 29 Sep 2018 14:57:17 -0400 Subject: [PATCH] doom|hack-local-variables => MODE-local-vars-hook Uses a less destructive method (the same that Spacemacs uses) than the one introduced in 13cee68, by introducing MODE-local-vars-hook hooks, which run after local vars have been initialized. The old method was to call `hack-local-variables` *before* mode hooks run, however, this causes variables set by modes to have higher precedence than local vars, which is unacceptable. Also moved intero-mode & dante-mode to haskell-mode-local-vars-hook --- core/core.el | 17 ++++++++--------- modules/lang/haskell/+dante.el | 2 +- modules/lang/haskell/+intero.el | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/core.el b/core/core.el index 134b27061..ad2eb1813 100644 --- a/core/core.el +++ b/core/core.el @@ -302,15 +302,14 @@ original value of `symbol-file'." (add-hook 'minibuffer-setup-hook #'doom|defer-garbage-collection) (add-hook 'minibuffer-exit-hook #'doom|restore-garbage-collection) -;; The default behavior is to read file+directory-local variables after the -;; major mode and its hooks have run. I think this is backwards. What if we want -;; to use these local variables to customize the things running in hooks? -(defun doom|hack-local-variables () - (with-demoted-errors "File local-variables error: %s" - (hack-local-variables 'no-mode))) -;; `change-major-mode-hook' is too soon (runs before `kill-all-local-variables' -;; is run). `after-change-major-mode-hook' is too late (runs after mode hooks). -(add-hook 'change-major-mode-after-body-hook #'doom|hack-local-variables) +;; File+dir local variables are initialized after the major mode and its hooks +;; have run. If you want hook functions to be aware of these customizations, add +;; them to MODE-local-vars-hook instead. +(defun doom|run-local-var-hooks () + "Run MODE-local-vars-hook after local variables are initialized." + (run-hook-wrapped (intern-soft (format "%s-local-vars-hook" major-mode)) + #'doom-try-run-hook)) +(add-hook 'hack-local-variables-hook #'doom|run-local-var-hooks) ;; diff --git a/modules/lang/haskell/+dante.el b/modules/lang/haskell/+dante.el index dcc4b7e97..e52f49c2f 100644 --- a/modules/lang/haskell/+dante.el +++ b/modules/lang/haskell/+dante.el @@ -2,7 +2,7 @@ ;;;###if (featurep! +dante) (def-package! dante - :hook (haskell-mode . dante-mode) + :hook (haskell-mode-local-vars . dante-mode) :init (setq dante-load-flags '(;; defaults: "+c" diff --git a/modules/lang/haskell/+intero.el b/modules/lang/haskell/+intero.el index b92a20c2a..e1985fc23 100644 --- a/modules/lang/haskell/+intero.el +++ b/modules/lang/haskell/+intero.el @@ -11,7 +11,7 @@ This is necessary because `intero-mode' doesn't do its own error checks." (if (executable-find "stack") (intero-mode +1) (message "Couldn't find stack. Refusing to enable intero-mode.")))) - (add-hook 'haskell-mode-hook #'+haskell|init-intero) + (add-hook 'haskell-mode-local-vars-hook #'+haskell|init-intero) :config (setq haskell-compile-cabal-build-command "stack build --fast") (set-lookup-handlers! 'intero-mode :definition #'intero-goto-definition)