From 2860441f7e4289606ead46e2ce4876baa58a711e Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Mon, 25 Mar 2013 17:35:00 -0500 Subject: [PATCH 1/2] Allow configuring cleaning white space on save This condition is checked when saving if the existing whitespace-cleanup is set instead of when the when prog-mode is is entered. This way it can be over-ridden by either dir-locals or file-local variables. --- core/prelude-editor.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/prelude-editor.el b/core/prelude-editor.el index 4136e3d..22e242c 100644 --- a/core/prelude-editor.el +++ b/core/prelude-editor.el @@ -53,6 +53,12 @@ :type 'boolean :group 'prelude) +(defcustom prelude-clean-whitespace-on-save t + "Cleanup whitespace from file before it's saved. Will only occur if prelude-whitespace is also enabled" + :type 'boolean + :group 'prelude +) + (defcustom prelude-flyspell t "Non-nil values enable Prelude's flyspell support." :type 'boolean @@ -218,10 +224,13 @@ (when (and prelude-flyspell (executable-find ispell-program-name)) (flyspell-mode +1))) +(defun prelude-cleanup-maybe () + (when prelude-clean-whitespace-on-save (whitespace-cleanup))) + (defun prelude-enable-whitespace () (when prelude-whitespace ;; keep the whitespace decent all the time (in this buffer) - (add-hook 'before-save-hook 'whitespace-cleanup nil t) + (add-hook 'before-save-hook 'prelude-cleanup-maybe nil t) (whitespace-mode +1))) (add-hook 'text-mode-hook 'prelude-enable-flyspell) From fcdae17485f50a2b9c6fe6cbb3083c6ab4c13c1e Mon Sep 17 00:00:00 2001 From: Nathan Stitt Date: Wed, 27 Mar 2013 12:29:52 -0500 Subject: [PATCH 2/2] Add prelude-clean-whitespace-on-save to README.md Also fix incorrect indentation in prelude-editor.el changes. Good catch bbotsov! --- README.md | 13 +++++++++++++ core/prelude-editor.el | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5fc1770..43c454f 100644 --- a/README.md +++ b/README.md @@ -312,6 +312,19 @@ personal config with the following bit of code: (setq prelude-whitespace nil) ``` +If you like `whitespace-mode` but prefer it to not automatically +cleanup your file on save, you can disable that behavior by setting +prelude-clean-whitespace-on-save to nil in your config file with: + +```lisp +(setq prelude-clean-whitespace-on-save nil) +``` + +The prelude-clean-whitespace-on-save setting can also be set on a +per-file or directory basis by using a file variable or a +.dir-locals.el file. + + #### Disable flyspell-mode If you're not fond of spellchecking on the fly: diff --git a/core/prelude-editor.el b/core/prelude-editor.el index 22e242c..9d3e13e 100644 --- a/core/prelude-editor.el +++ b/core/prelude-editor.el @@ -225,7 +225,7 @@ (flyspell-mode +1))) (defun prelude-cleanup-maybe () - (when prelude-clean-whitespace-on-save (whitespace-cleanup))) + (when prelude-clean-whitespace-on-save (whitespace-cleanup))) (defun prelude-enable-whitespace () (when prelude-whitespace