diff --git a/core/autoload/editor.el b/core/autoload/editor.el index 0aeddfa54..c304405db 100644 --- a/core/autoload/editor.el +++ b/core/autoload/editor.el @@ -283,12 +283,12 @@ with weak native support." (defun doom|enable-delete-trailing-whitespace () "Enables the automatic deletion of trailing whitespaces upon file save. -i.e. adds `delete-trailing-whitespace' to `write-file-functions', buffer-locally." - (add-hook 'write-file-functions #'delete-trailing-whitespace nil t)) +i.e. enables `ws-butler-mode' in the current buffer." + (ws-butler-mode +1)) ;;;###autoload (defun doom|disable-delete-trailing-whitespace () "Disables the automatic deletion of trailing whitespaces upon file save. -i.e. removes `delete-trailing-whitespace' from `write-file-functions'." - (remove-hook 'write-file-functions #'delete-trailing-whitespace t)) +i.e. disables `ws-butler-mode' in the current buffer." + (ws-butler-mode -1)) diff --git a/core/core-editor.el b/core/core-editor.el index f1a98ace7..3141d9142 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -81,11 +81,6 @@ fundamental-mode) for performance sake." (add-hook 'after-save-hook #'executable-make-buffer-file-executable-if-script-p) -;; Deleting trailing whitespace is on by default, but must be set on -;; write-file-functions, so that editorconfig can see it (so it doesn't add it -;; redundantly and can remove it when needed). -(add-hook 'write-file-functions #'delete-trailing-whitespace) - ;; revert buffers for changed files (def-package! autorevert :after-call after-find-file @@ -300,5 +295,12 @@ savehist file." [remap describe-variable] #'helpful-variable [remap describe-key] #'helpful-key) +;; `ws-butler' --- a better `delete-trailing-whitespaces' +(def-package! ws-butler + :after-call (after-find-file) + :config + (nconc ws-butler-global-exempt-modes '(special-mode comint-mode term-mode eshell-mode)) + (ws-butler-global-mode)) + (provide 'core-editor) ;;; core-editor.el ends here diff --git a/core/packages.el b/core/packages.el index 6ad7e7f87..d49ab3d04 100644 --- a/core/packages.el +++ b/core/packages.el @@ -32,6 +32,7 @@ (package! pcre2el) (package! smartparens) (package! undo-tree) +(package! ws-butler) ;; core-projects.el (package! projectile) diff --git a/modules/tools/editorconfig/config.el b/modules/tools/editorconfig/config.el index 82d4966f0..5bc85a54a 100644 --- a/modules/tools/editorconfig/config.el +++ b/modules/tools/editorconfig/config.el @@ -42,7 +42,15 @@ extension, try to guess one." (apply orig-fn args))) (advice-add #'editorconfig-call-editorconfig-exec :around #'doom*editorconfig-smart-detection) + (defun +editorconfig|disable-ws-butler-maybe (props) + "Disable `ws-butler-mode' if trim_trailing_whitespace is true." + (when (equal (gethash 'trim_trailing_whitespace props) "true") + (ws-butler-mode -1))) + (add-hook 'editorconfig-custom-hooks #'+editorconfig|disable-ws-butler-maybe) + (defun +editorconfig|disable-indent-detection (props) + "Inhibit `dtrt-indent' if an explicit indent_style and indent_size is +specified by editorconfig." (when (or (gethash 'indent_style props) (gethash 'indent_size props)) (setq doom-inhibit-indent-detection t)))