core: add toggle for whitespace cleanup

This commit is contained in:
Eivind Fonn 2016-06-02 14:32:26 +02:00 committed by syl20bnr
parent 29bae4026a
commit 5a4e8a3f01
3 changed files with 69 additions and 34 deletions

View File

@ -1137,33 +1137,34 @@ toggle them.
Some toggle have two flavors: local and global. The global version of the toggle
can be reached using the =control= key.
| Key Binding | Unicode | ASCII | Mode |
|-------------+---------+-------+------------------------------------------------------|
| ~SPC t -~ | =⊝= | - | [[http://emacswiki.org/emacs/centered-cursor-mode.el][centered-cursor]] mode |
| ~SPC t 8~ | =⑧= | 8 | toggle highlight of characters for long lines |
| ~SPC t C-8~ | =⑧= | 8 | global toggle highlight of characters for long lines |
| ~SPC t C--~ | =⊝= | - | global centered cursor |
| ~SPC t a~ | =ⓐ= | a | auto-completion |
| ~SPC t c~ | =ⓒ= | c | camel case motion with subword mode |
| =none= | =ⓔ= | e | [[https://github.com/edwtjo/evil-org-mode][evil-org]] mode |
| ~SPC t E e~ | =Ⓔe= | Ee | emacs editing style (holy mode) |
| ~SPC t E h~ | =Ⓔh= | Eh | hybrid editing style (hybrid mode) |
| ~SPC t f~ | =ⓕ= | f | fill-column-indicator mode |
| ~SPC t F~ | =Ⓕ= | F | auto-fill mode |
| ~SPC t g~ | =ⓖ= | g | [[https://github.com/roman/golden-ratio.el][golden-ratio]] mode |
| ~SPC t h i~ | =ⓗi= | hi | toggle highlight indentation levels |
| ~SPC t h c~ | =ⓗc= | hc | toggle highlight indentation current column |
| ~SPC t i~ | =ⓘ= | i | indentation guide |
| ~SPC t C-i~ | =ⓘ= | i | global indentation guide |
| ~SPC t I~ | =Ⓘ= | I | aggressive indent mode |
| ~SPC t K~ | =Ⓚ= | K | which-key mode |
| ~SPC t p~ | =ⓟ= | p | [[https://github.com/Fuco1/smartparens][smartparens]] mode |
| ~SPC t C-p~ | =ⓟ= | p | global smartparens |
| ~SPC t s~ | =ⓢ= | s | syntax checking (flycheck) |
| ~SPC t S~ | =Ⓢ= | S | enabled in [[../layers/spell-checking][spell checking layer]] (flyspell) |
| ~SPC t w~ | =ⓦ= | w | whitespace mode |
| ~SPC t C-w~ | =ⓦ= | w | global whitespace |
| ~SPC t y~ | =ⓨ= | y | [[https://github.com/capitaomorte/yasnippet][yasnippet]] mode |
| Key Binding | Unicode | ASCII | Mode |
|-------------+---------+-------+----------------------------------------------------------------------|
| ~SPC t -~ | =⊝= | - | [[http://emacswiki.org/emacs/centered-cursor-mode.el][centered-cursor]] mode |
| ~SPC t 8~ | =⑧= | 8 | toggle highlight of characters for long lines |
| ~SPC t C-8~ | =⑧= | 8 | global toggle highlight of characters for long lines |
| ~SPC t C--~ | =⊝= | - | global centered cursor |
| ~SPC t a~ | =ⓐ= | a | auto-completion |
| ~SPC t c~ | =ⓒ= | c | camel case motion with subword mode |
| =none= | =ⓔ= | e | [[https://github.com/edwtjo/evil-org-mode][evil-org]] mode |
| ~SPC t E e~ | =Ⓔe= | Ee | emacs editing style (holy mode) |
| ~SPC t E h~ | =Ⓔh= | Eh | hybrid editing style (hybrid mode) |
| ~SPC t f~ | =ⓕ= | f | fill-column-indicator mode |
| ~SPC t F~ | =Ⓕ= | F | auto-fill mode |
| ~SPC t g~ | =ⓖ= | g | [[https://github.com/roman/golden-ratio.el][golden-ratio]] mode |
| ~SPC t h i~ | =ⓗi= | hi | toggle highlight indentation levels |
| ~SPC t h c~ | =ⓗc= | hc | toggle highlight indentation current column |
| ~SPC t i~ | =ⓘ= | i | indentation guide |
| ~SPC t C-i~ | =ⓘ= | i | global indentation guide |
| ~SPC t I~ | =Ⓘ= | I | aggressive indent mode |
| ~SPC t K~ | =Ⓚ= | K | which-key mode |
| ~SPC t p~ | =ⓟ= | p | [[https://github.com/Fuco1/smartparens][smartparens]] mode |
| ~SPC t C-p~ | =ⓟ= | p | global smartparens |
| ~SPC t s~ | =ⓢ= | s | syntax checking (flycheck) |
| ~SPC t S~ | =Ⓢ= | S | enabled in [[../layers/spell-checking][spell checking layer]] (flyspell) |
| ~SPC t w~ | =ⓦ= | w | whitespace mode |
| ~SPC t C-w~ | =ⓦ= | w | global whitespace |
| ~SPC t W~ | | | automatic whitespace cleanup (see =dotspacemacs-whitespace-cleanup=) |
| ~SPC t y~ | =ⓨ= | y | [[https://github.com/capitaomorte/yasnippet][yasnippet]] mode |
**** Customizing the mode-line
Spacemacs uses [[https://github.com/TheBB/spaceline][Spaceline]] to provide its mode-line. It consists of a number of

View File

@ -105,9 +105,42 @@ It runs `tabulated-list-revert-hook', then calls `tabulated-list-print'."
(add-hook 'find-file-hook 'spacemacs/check-large-file)
;; whitespace-cleanup configuration
(pcase dotspacemacs-whitespace-cleanup
(`all (add-hook 'before-save-hook 'whitespace-cleanup))
(`trailing (add-hook 'before-save-hook 'delete-trailing-whitespace)))
;; This is a local toggle, so it makes `before-save-hook' buffer-local
(spacemacs|add-toggle whitespace-cleanup
:documentation "Clean up whitespace automatically."
:if dotspacemacs-whitespace-cleanup
:evil-leader "tW"
:status
(pcase dotspacemacs-whitespace-cleanup
(`all (memq 'whitespace-cleanup before-save-hook))
(`trailing (memq 'delete-trailing-whitespace before-save-hook))
(`changed (bound-and-true-p ws-butler-mode)))
:on
(pcase dotspacemacs-whitespace-cleanup
(`all
(make-local-variable 'before-save-hook)
(add-hook 'before-save-hook 'whitespace-cleanup))
(`trailing
(make-local-variable 'before-save-hook)
(add-hook 'before-save-hook 'delete-trailing-whitespace))
(`changed (when (fboundp 'ws-butler-mode) (ws-butler-mode))))
:off
(pcase dotspacemacs-whitespace-cleanup
(`all
(make-local-variable 'before-save-hook)
(remove-hook 'before-save-hook 'whitespace-cleanup))
(`trailing
(make-local-variable 'before-save-hook)
(remove-hook 'before-save-hook 'delete-trailing-whitespace))
(`changed (when (fboundp 'ws-butler-mode) (ws-butler-mode -1))))
:on-message
(pcase dotspacemacs-whitespace-cleanup
(`all "whitespace-cleanup enabled (all whitespace)")
(`trailing "whitespace-cleanup enabled (trailing whitespace)")
(`changed "whitespace-cleanup enabled (changed lines)")))
;; Turning on for `changed' is handled by the `ws-butler' package.
(when (memq dotspacemacs-whitespace-cleanup '(all trailing))
(spacemacs/toggle-whitespace-cleanup-on))
;; ---------------------------------------------------------------------------
;; UI

View File

@ -379,8 +379,9 @@
(defun spacemacs-editing/init-ws-butler ()
(use-package ws-butler
:if (eq 'changed dotspacemacs-whitespace-cleanup)
:defer t
:init
(when (eq 'change dotspacemacs-whitespace-cleanup)
(ws-butler-global-mode 1))
:config
(progn
(ws-butler-global-mode 1)
(spacemacs|hide-lighter ws-butler-mode))))
(spacemacs|hide-lighter ws-butler-mode)))