Skip to content

Commit

Permalink
Merge pull request #183 from terlar/master
Browse files Browse the repository at this point in the history
Use ws-butler when enabled and available.
  • Loading branch information
10sr authored Dec 17, 2018
2 parents e3b3047 + 041cc76 commit f16d342
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions editorconfig.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f16d342

Please sign in to comment.