Skip to content

Commit

Permalink
Add variable editorconfig-trim-whitespaces-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
10sr committed Dec 15, 2018
1 parent 8a420de commit 041cc76
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions editorconfig.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -427,29 +425,28 @@ 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)))
(when (or (equal trim-trailing-ws "false")
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."
Expand Down

0 comments on commit 041cc76

Please sign in to comment.