Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check editorconfig configs when read only state changes #168

Merged
merged 3 commits into from
Jul 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions editorconfig.el
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,15 @@ number - `lisp-indent-offset' is not set only if indent_size is
"Set up trimming of trailing whitespace at end of lines by
TRIM-TRAILING-WS."
(make-local-variable 'write-file-functions) ;; just current buffer
(when (equal trim-trailing-ws "true")
(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))
(when (equal trim-trailing-ws "false")
(when (or (equal trim-trailing-ws "false")
buffer-read-only)
;; when false we remove every delete-trailing-whitespace
;; from write-file-functions
(setq
Expand Down Expand Up @@ -585,7 +587,8 @@ mode is not listed in `editorconfig-exclude-modes'."
:lighter editorconfig-mode-lighter
;; See https://github.com/editorconfig/editorconfig-emacs/issues/141 for why
;; not `after-change-major-mode-hook'
(dolist (hook '(change-major-mode-after-body-hook))
(dolist (hook '(change-major-mode-after-body-hook
read-only-mode-hook))
(if editorconfig-mode
(add-hook hook 'editorconfig-mode-apply)
(remove-hook hook 'editorconfig-mode-apply))))
Expand Down
13 changes: 13 additions & 0 deletions ert-tests/editorconfig.el
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,16 @@
"2_space.el")
(should (eq lisp-indent-offset 2))))
(editorconfig-mode -1))

(ert-deftest test-trim-trailing-ws nil
(editorconfig-mode 1)
(with-visit-file (concat editorconfig-ert-dir
"trim.txt")
(should (memq 'delete-trailing-whitespace
write-file-functions)))
(with-visit-file (concat editorconfig-ert-dir
"trim.txt")
(read-only-mode 1)
(should (not (memq 'delete-trailing-whitespace
write-file-functions))))
(editorconfig-mode -1))