purcell / whitespace-cleanup-mode

In Emacs, intelligently call whitespace-cleanup on save
126 stars 8 forks source link

Add support for enabling the mode locally #15

Closed akirak closed 5 years ago

akirak commented 5 years ago

This patch solves #9. That is, it allows the user to turn on whitespace-cleanup-mode only in specific files and/or directories via local variables.

Usage

To turn on whitespace-cleanup-mode only in specific files and directories, follow this instruction:

  1. Set whitespace-cleanup-mode-enabled, which is non-nil by default, to nil.
  2. Turn on global-whitespace-mode.

An example configuration with use-package:

(use-package whitespace-cleanup-mode
  :custom
  (whitespace-cleanup-mode-enabled nil)
  :config
  (global-whitespace-cleanup-mode t))

Then you can set whitespace-cleanup-mode-enabled to non-nil in specific files/projects where you want to turn on whitespace-cleanup-mode automatically. The following is an example of .dir-locals.el which enables the mode in emacs-lisp-mode:

((emacs-lisp-mode
  (whitespace-cleanup-mode-enabled . t)))
purcell commented 5 years ago

But it already works fine to use:

((emacs-lisp-mode
  (mode . whitespace-cleanup-mode)))

in .dir-locals.el, whatever the emacs manual says. I'm really wary about adding an -enabled var for a minor mode, which is already an "enabled or not" thing.

akirak commented 5 years ago

Your solution now seems to work, even though it didn't seem to work before. I don't know why, but I will close this PR.