From 5017fc508ecce8a6a9dc3368bc33b6b9da3c3d9e Mon Sep 17 00:00:00 2001 From: 10sr <8.slashes@gmail.com> Date: Sun, 8 Jul 2018 18:10:03 +0900 Subject: [PATCH 1/3] Add trim-trailing-ws tests With case where read-only-mode is enabled --- ert-tests/editorconfig.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ert-tests/editorconfig.el b/ert-tests/editorconfig.el index 154a0f37..8010d72f 100644 --- a/ert-tests/editorconfig.el +++ b/ert-tests/editorconfig.el @@ -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)) From 962a1955affbf8463da0c0a5fbd716f514258d4a Mon Sep 17 00:00:00 2001 From: 10sr <8.slashes@gmail.com> Date: Sun, 8 Jul 2018 17:53:50 +0900 Subject: [PATCH 2/3] Check editorconfig configs when read only state changes --- editorconfig.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/editorconfig.el b/editorconfig.el index 2d502b13..e28066ca 100644 --- a/editorconfig.el +++ b/editorconfig.el @@ -585,7 +585,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)))) From 80f554192a1d5e3df9af642641afa1a46feb1c57 Mon Sep 17 00:00:00 2001 From: 10sr <8.slashes@gmail.com> Date: Sun, 8 Jul 2018 18:00:37 +0900 Subject: [PATCH 3/3] Disable delete-trailing-whitespace when buffer-read-only is nil --- editorconfig.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/editorconfig.el b/editorconfig.el index e28066ca..03d2531e 100644 --- a/editorconfig.el +++ b/editorconfig.el @@ -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