From 499877fcff31139ef0604d69a72f82165e95a578 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 21 Feb 2019 19:11:07 -0500 Subject: [PATCH] lang/haskell: restore modified flag after flycheck Dante quietly saves the current buffer (without triggering save hooks) before invoking flycheck, unexpectedly leaving the buffer in an unmodified state. This is annoying if we depend on save hooks to do work on the buffer (like reformatting), so we restore a (false) modified state. --- modules/lang/haskell/+dante.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/lang/haskell/+dante.el b/modules/lang/haskell/+dante.el index 7ae27e319..8b1f3cb82 100644 --- a/modules/lang/haskell/+dante.el +++ b/modules/lang/haskell/+dante.el @@ -19,6 +19,16 @@ (set-company-backend! 'dante-mode #'dante-company) + (defun +haskell*restore-modified-state (orig-fn &rest args) + "Dante quietly saves the current buffer (without triggering save hooks) before +invoking flycheck, unexpectedly leaving the buffer in an unmodified state. This +is annoying if we depend on save hooks to do work on the buffer (like +reformatting), so we restore a (false) modified state." + (let ((modified-p (buffer-modified-p))) + (apply orig-fn args) + (if modified-p (set-buffer-modified-p t)))) + (advice-add #'dante-async-load-current-buffer :around #'+haskell*restore-modified-state) + (when (featurep 'evil) (add-hook 'dante-mode-hook #'evil-normalize-keymaps)) (map! :map dante-mode-map