diff --git a/editorconfig.el b/editorconfig.el index eb56df62..97e1b33e 100644 --- a/editorconfig.el +++ b/editorconfig.el @@ -277,6 +277,14 @@ properties." :type '(repeat string) :group 'editorconfig) +(defcustom editorconfig-trim-whitespaces-mode nil + "Buffer local minor-mode to use to trim trailing whitespaces. + +If set, enable that mode when `trim_trailing_whitespace` is set to true. +Otherwise, use `delete-trailing-whitespace'." + :type 'symbol + :group 'editorconfig) + (defvar editorconfig-properties-hash nil "Hash object of EditorConfig properties for current buffer. Set by `editorconfig-apply' and nil if that is not invoked in @@ -417,20 +425,23 @@ number - `lisp-indent-offset' is not set only if indent_size is (set (make-local-variable 'mode-require-final-newline) nil)))) (defun editorconfig-set-trailing-ws (trim-trailing-ws) - "Set up trimming of trailing whitespace at end of lines by -TRIM-TRAILING-WS." + "Set up trimming of trailing whitespace at end of lines by TRIM-TRAILING-WS." (make-local-variable 'write-file-functions) ;; just current buffer (when (and (equal trim-trailing-ws "true") (not buffer-read-only)) ;; when true we push delete-trailing-whitespace (emacs > 21) ;; to write-file-functions - (add-to-list - 'write-file-functions - 'delete-trailing-whitespace)) + (if editorconfig-trim-whitespaces-mode + (funcall editorconfig-trim-whitespaces-mode 1) + (add-to-list + 'write-file-functions + 'delete-trailing-whitespace))) (when (or (equal trim-trailing-ws "false") buffer-read-only) ;; when false we remove every delete-trailing-whitespace ;; from write-file-functions + (when editorconfig-trim-whitespaces-mode + (funcall editorconfig-trim-whitespaces-mode 0)) (setq write-file-functions (delete