From 8a420de892029a778c92b8d6c61a73a4dca02f11 Mon Sep 17 00:00:00 2001 From: Terje Larsen Date: Sat, 17 Nov 2018 23:16:12 +0100 Subject: [PATCH 1/2] Use ws-butler when enabled and available. When having auto-save on and you edit text the cleaning up of white-space is a bit intrusive and removes the space at the end of the line where you are writing. `ws-butler-mode` is an alternative that does take this into account. --- editorconfig.el | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/editorconfig.el b/editorconfig.el index eb56df62..aae5f025 100644 --- a/editorconfig.el +++ b/editorconfig.el @@ -277,6 +277,11 @@ properties." :type '(repeat string) :group 'editorconfig) +(defcustom editorconfig-use-ws-butler nil + "Use command `ws-butler-mode' for trimming trailing whitespace." + :type 'boolean + :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 @@ -302,6 +307,11 @@ number - `lisp-indent-offset' is not set only if indent_size is (and (stringp string) (string-match-p "\\`[0-9]+\\'" string))) +(defun editorconfig-use-ws-butler-p () + "Return non-nil if `editorconfig-use-ws-butler' is enabled and +`ws-butler' is available." + (and editorconfig-use-ws-butler (fboundp 'ws-butler-mode))) + (defun editorconfig-set-indentation/python-mode (size) "Set `python-mode' indent size to SIZE." (set (make-local-variable (if (or (> emacs-major-version 24) @@ -424,18 +434,22 @@ TRIM-TRAILING-WS." (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-use-ws-butler-p) + (ws-butler-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 - (setq - write-file-functions - (delete - 'delete-trailing-whitespace - write-file-functions)))) + (if (editorconfig-use-ws-butler-p) + (ws-butler-mode 0) + (setq + write-file-functions + (delete + 'delete-trailing-whitespace + write-file-functions))))) (defun editorconfig-set-line-length (length) "Set the max line length (`fill-column') to LENGTH." From 041cc76cdcc0f29df00ea33fb414cb0a5a398a31 Mon Sep 17 00:00:00 2001 From: 10sr <8.slashes@gmail.com> Date: Sat, 15 Dec 2018 16:46:07 +0900 Subject: [PATCH 2/2] Add variable editorconfig-trim-whitespaces-mode --- editorconfig.el | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/editorconfig.el b/editorconfig.el index aae5f025..97e1b33e 100644 --- a/editorconfig.el +++ b/editorconfig.el @@ -277,9 +277,12 @@ properties." :type '(repeat string) :group 'editorconfig) -(defcustom editorconfig-use-ws-butler nil - "Use command `ws-butler-mode' for trimming trailing whitespace." - :type 'boolean +(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 @@ -307,11 +310,6 @@ number - `lisp-indent-offset' is not set only if indent_size is (and (stringp string) (string-match-p "\\`[0-9]+\\'" string))) -(defun editorconfig-use-ws-butler-p () - "Return non-nil if `editorconfig-use-ws-butler' is enabled and -`ws-butler' is available." - (and editorconfig-use-ws-butler (fboundp 'ws-butler-mode))) - (defun editorconfig-set-indentation/python-mode (size) "Set `python-mode' indent size to SIZE." (set (make-local-variable (if (or (> emacs-major-version 24) @@ -427,15 +425,14 @@ 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 - (if (editorconfig-use-ws-butler-p) - (ws-butler-mode 1) + (if editorconfig-trim-whitespaces-mode + (funcall editorconfig-trim-whitespaces-mode 1) (add-to-list 'write-file-functions 'delete-trailing-whitespace))) @@ -443,13 +440,13 @@ TRIM-TRAILING-WS." buffer-read-only) ;; when false we remove every delete-trailing-whitespace ;; from write-file-functions - (if (editorconfig-use-ws-butler-p) - (ws-butler-mode 0) - (setq - write-file-functions - (delete - 'delete-trailing-whitespace - write-file-functions))))) + (when editorconfig-trim-whitespaces-mode + (funcall editorconfig-trim-whitespaces-mode 0)) + (setq + write-file-functions + (delete + 'delete-trailing-whitespace + write-file-functions)))) (defun editorconfig-set-line-length (length) "Set the max line length (`fill-column') to LENGTH."