Skip to content

Commit

Permalink
core: special toggle API for minor modes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBB authored and syl20bnr committed Jun 1, 2016
1 parent 1da124f commit 62fc64f
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 111 deletions.
10 changes: 7 additions & 3 deletions core/core-toggle.el
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ Avaiblabe PROPS:
`:on-message EXPRESSION'
EXPRESSION is evaluated and displayed when the \"on\" toggle is activated.
`:mode SYMBOL'
If given, must be a minor mode. This overrides `:on', `:off' and `:status'.
All properties supported by `spacemacs//create-key-binding-form' can be
used."
(declare (indent 1))
(let* ((wrapper-func (intern (format "spacemacs/toggle-%s"
(symbol-name name))))
(wrapper-func-on (intern (format "%s-on" wrapper-func)))
(wrapper-func-off (intern (format "%s-off" wrapper-func)))
(status (plist-get props :status))
(mode (plist-get props :mode))
(status (or mode (plist-get props :status)))
(condition (plist-get props :if))
(doc (plist-get props :documentation))
(on-body (spacemacs/mplist-get props :on))
(off-body (spacemacs/mplist-get props :off))
(on-body (if mode `((,mode)) (spacemacs/mplist-get props :on)))
(off-body (if mode `((,mode -1)) (spacemacs/mplist-get props :off)))
(prefix-arg-var (plist-get props :prefix))
(on-message (plist-get props :on-message))
(bindkeys (spacemacs//create-key-binding-form props wrapper-func))
Expand Down
4 changes: 1 addition & 3 deletions layers/+checkers/syntax-checking/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
flycheck-global-modes nil)

(spacemacs|add-toggle syntax-checking
:status flycheck-mode
:on (flycheck-mode)
:off (flycheck-mode -1)
:mode flycheck-mode
:documentation "Enable error and syntax checking."
:evil-leader "ts")

Expand Down
4 changes: 1 addition & 3 deletions layers/+completion/auto-completion/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,7 @@
markdown-mode-hook
org-mode-hook))
(spacemacs|add-toggle yasnippet
:status yas-minor-mode
:on (yas-minor-mode)
:off (yas-minor-mode -1)
:mode yas-minor-mode
:documentation "Enable snippets."
:evil-leader "ty")

Expand Down
20 changes: 5 additions & 15 deletions layers/+distribution/spacemacs-base/keybindings.el
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@
"nw" 'widen)
;; toggle ---------------------------------------------------------------------
(spacemacs|add-toggle highlight-current-line-globally
:status global-hl-line-mode
:on (global-hl-line-mode)
:off (global-hl-line-mode -1)
:mode global-hl-line-mode
:documentation "Globally highlight the current line."
:evil-leader "thh")
(spacemacs|add-toggle truncate-lines
Expand Down Expand Up @@ -290,28 +288,20 @@
:evil-leader "TT")
(spacemacs|add-toggle tool-bar
:if window-system
:status tool-bar-mode
:on (tool-bar-mode)
:off (tool-bar-mode -1)
:mode tool-bar-mode
:documentation "Display the tool bar in GUI mode."
:evil-leader "Tt")
(spacemacs|add-toggle menu-bar
:if (or window-system (version<= "24.3.1" emacs-version))
:status menu-bar-mode
:on (menu-bar-mode)
:off (menu-bar-mode -1)
:mode menu-bar-mode
:documentation "Display the menu bar."
:evil-leader "Tm")
(spacemacs|add-toggle semantic-stickyfunc
:status semantic-stickyfunc-mode
:on (semantic-stickyfunc-mode)
:off (semantic-stickyfunc-mode -1)
:mode semantic-stickyfunc-mode
:documentation "Enable semantic-stickyfunc."
:evil-leader "TS")
(spacemacs|add-toggle semantic-stickyfunc-globally
:status global-semantic-stickyfunc-mode
:on (global-semantic-stickyfunc-mode)
:off (global-semantic-stickyfunc-mode -1)
:mode global-semantic-stickyfunc-mode
:documentation "Enable semantic-stickyfunc globally."
:evil-leader "T C-S")
;; quit -----------------------------------------------------------------------
Expand Down
20 changes: 5 additions & 15 deletions layers/+distribution/spacemacs-base/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@
(add-hook 'text-mode-hook 'linum-mode))
(setq linum-format "%4d")
(spacemacs|add-toggle line-numbers
:status linum-mode
:on (linum-mode)
:off (linum-mode -1)
:mode linum-mode
:documentation "Show the line numbers."
:evil-leader "tn"))

Expand Down Expand Up @@ -347,15 +345,11 @@
(default-value 'evil-cjk-word-separating-categories))))
(add-hook 'subword-mode-hook 'spacemacs//subword-enable-camel-case)
(spacemacs|add-toggle camel-case-motion
:status subword-mode
:on (subword-mode +1)
:off (subword-mode -1)
:mode subword-mode
:documentation "Toggle CamelCase motions."
:evil-leader "tc")
(spacemacs|add-toggle camel-case-motion-globally
:status subword-mode
:on (global-subword-mode +1)
:off (global-subword-mode -1)
:mode global-subword-mode
:documentation "Globally toggle CamelCase motions."
:evil-leader "t C-c"))
:config
Expand Down Expand Up @@ -394,15 +388,11 @@
(add-hook 'prog-mode-hook 'spacemacs//show-trailing-whitespace)

(spacemacs|add-toggle whitespace
:status whitespace-mode
:on (whitespace-mode)
:off (whitespace-mode -1)
:mode whitespace-mode
:documentation "Display whitespace."
:evil-leader "tw")
(spacemacs|add-toggle whitespace-globally
:status global-whitespace-mode
:on (global-whitespace-mode)
:off (global-whitespace-mode -1)
:mode global-whitespace-mode
:documentation "Display whitespace globally."
:evil-leader "t C-w")

Expand Down
4 changes: 1 addition & 3 deletions layers/+distribution/spacemacs-bootstrap/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@
(require 'which-key)

(spacemacs|add-toggle which-key
:status which-key-mode
:on (which-key-mode)
:off (which-key-mode -1)
:mode which-key-mode
:documentation
"Display a buffer with available key bindings."
:evil-leader "tK")
Expand Down
8 changes: 2 additions & 6 deletions layers/+emacs/typography/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
(add-hook 'text-mode-hook 'typo-mode))

(spacemacs|add-toggle typographic-substitutions
:status typo-mode
:on (typo-mode)
:off (typo-mode -1)
:mode typo-mode
:documentation "Enable typographic substitutions"
:evil-leader "tT")
(spacemacs|diminish typo-mode "" " T"))
Expand All @@ -50,9 +48,7 @@
(add-hook 'LaTeX-mode-hook 'typography/tildify-latex-space)

(spacemacs|add-toggle tildify-space
:status tildify-mode
:on (tildify-mode)
:off (tildify-mode -1)
:mode tildify-mode
:documentation "Enable electric non-breaking space"
:evil-leader "t~")
(spacemacs|diminish tildify-mode " ~" " ~"))))
4 changes: 1 addition & 3 deletions layers/+lang/javascript/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@
(use-package livid-mode
:defer t
:init (spacemacs|add-toggle javascript-repl-live-evaluation
:status livid-mode
:on (livid-mode)
:off (livid-mode -1)
:mode livid-mode
:documentation "Live evaluation of JS buffer change."
:evil-leader-for-mode (js2-mode . "sa"))))
4 changes: 1 addition & 3 deletions layers/+misc/nlinum/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
(add-hook 'text-mode-hook 'nlinum-mode))
(setq nlinum-format "%4d")
(spacemacs|add-toggle line-numbers
:status nlinum-mode
:on (nlinum-mode)
:off (nlinum-mode -1)
:mode nlinum-mode
:documentation "Show the line numbers."
:evil-leader "tn"))))

Expand Down
20 changes: 5 additions & 15 deletions layers/+spacemacs/spacemacs-editing-visual/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,7 @@
:documentation "Highlight the characters past the 80th column."
:evil-leader "t8")
(spacemacs|add-toggle highlight-long-lines-globally
:status global-column-enforce-mode
:on (global-column-enforce-mode)
:off (global-column-enforce-mode -1)
:mode global-column-enforce-mode
:documentation "Globally Highlight the characters past the 80th column."
:evil-leader "t C-8"))
:config (spacemacs|diminish column-enforce-mode "" "8")))
Expand All @@ -287,15 +285,11 @@
:init
(progn
(spacemacs|add-toggle highlight-indentation
:status highlight-indentation-mode
:on (highlight-indentation-mode)
:off (highlight-indentation-mode -1)
:mode highlight-indentation-mode
:documentation "Highlight indentation levels."
:evil-leader "thi")
(spacemacs|add-toggle highlight-indentation-current-column
:status highlight-indentation-current-column-mode
:on (highlight-indentation-current-column-mode)
:off (highlight-indentation-current-column-mode -1)
:mode highlight-indentation-current-column-mode
:documentation "Highlight indentation level at point."
:evil-leader "thc"))
:config
Expand Down Expand Up @@ -353,16 +347,12 @@
(progn
(setq indent-guide-delay 0.3)
(spacemacs|add-toggle indent-guide
:status indent-guide-mode
:on (indent-guide-mode)
:off (indent-guide-mode -1)
:mode indent-guide-mode
:documentation
"Highlight indentation level at point. (alternative to highlight-indentation)."
:evil-leader "ti")
(spacemacs|add-toggle indent-guide-globally
:status indent-guide-mode
:on (indent-guide-global-mode)
:off (indent-guide-global-mode -1)
:mode indent-guide-global-mode
:documentation
"Highlight indentation level at point globally. (alternative to highlight-indentation)."
:evil-leader "t TAB"))
Expand Down
20 changes: 5 additions & 15 deletions layers/+spacemacs/spacemacs-editing/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@
:init
(progn
(spacemacs|add-toggle aggressive-indent
:status aggressive-indent-mode
:on (aggressive-indent-mode)
:off (aggressive-indent-mode -1)
:mode aggressive-indent-mode
:documentation "Always keep code indented."
:evil-leader "tI")
(spacemacs|add-toggle aggressive-indent-globally
:status aggressive-indent-mode
:on (global-aggressive-indent-mode)
:off (global-aggressive-indent-mode -1)
:mode aggressive-indent-mode
:documentation "Always keep code indented globally."
:evil-leader "t C-I"))
:config
Expand Down Expand Up @@ -161,9 +157,7 @@
:defer t
:init
(spacemacs|add-toggle hungry-delete
:status hungry-delete-mode
:on (hungry-delete-mode)
:off (hungry-delete-mode -1)
:mode hungry-delete-mode
:documentation "Delete consecutive horizontal whitespace with a single key."
:evil-leader "td")
:config
Expand Down Expand Up @@ -251,16 +245,12 @@
(add-hook 'minibuffer-setup-hook 'conditionally-enable-smartparens-mode)

(spacemacs|add-toggle smartparens
:status smartparens-mode
:on (smartparens-mode)
:off (smartparens-mode -1)
:mode smartparens-mode
:documentation "Enable smartparens."
:evil-leader "tp")

(spacemacs|add-toggle smartparens-globally
:status smartparens-mode
:on (smartparens-global-mode)
:off (smartparens-global-mode -1)
:mode smartparens-mode
:documentation "Enable smartparens globally."
:evil-leader "t C-p")

Expand Down
8 changes: 2 additions & 6 deletions layers/+spacemacs/spacemacs-evil/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,7 @@
:defer t
:init
(spacemacs|add-toggle evil-visual-mark-mode
:status evil-visual-mark-mode
:on (evil-visual-mark-mode)
:off (evil-visual-mark-mode -1)
:mode evil-visual-mark-mode
:documentation "Enable evil visual marks mode."
:evil-leader "t`")))

Expand All @@ -350,9 +348,7 @@
(progn
(global-vi-tilde-fringe-mode)
(spacemacs|add-toggle vi-tilde-fringe
:status vi-tilde-fringe-mode
:on (global-vi-tilde-fringe-mode)
:off (global-vi-tilde-fringe-mode -1)
:mode global-vi-tilde-fringe-mode
:documentation
"Globally display a ~ on empty lines in the fringe."
:evil-leader "T~")
Expand Down
4 changes: 1 addition & 3 deletions layers/+spacemacs/spacemacs-ui-visual/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
:init
(progn
(spacemacs|add-toggle mode-line-battery
:status fancy-battery-mode
:on (fancy-battery-mode)
:off (fancy-battery-mode -1)
:mode fancy-battery-mode
:documentation "Display battery info in mode-line."
:evil-leader "tmb")
(setq-default fancy-battery-show-percentage t))))
Expand Down
8 changes: 2 additions & 6 deletions layers/+spacemacs/spacemacs-ui/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,12 @@
:init
(progn
(spacemacs|add-toggle centered-point
:status centered-cursor-mode
:on (centered-cursor-mode)
:off (centered-cursor-mode -1)
:mode centered-cursor-mode
:documentation
"Keep point at the center of the window."
:evil-leader "t-")
(spacemacs|add-toggle centered-point-globally
:status centered-cursor-mode
:on (global-centered-cursor-mode)
:off (global-centered-cursor-mode -1)
:mode global-centered-cursor-mode
:documentation
"Keep point at the center of the window globally."
:evil-leader "t C--"))
Expand Down
8 changes: 2 additions & 6 deletions layers/+themes/colors/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
(nyan-mode))

(spacemacs|add-toggle nyan-cat-progress-bar
:status nyan-mode
:on (nyan-mode)
:off (nyan-mode -1)
:mode nyan-mode
:documentation "Show a nyan cat progress bar in the mode-line."
:evil-leader "tmn"))))

Expand All @@ -60,9 +58,7 @@
(spacemacs/declare-prefix "Ci" "colors-identifiers")

(spacemacs|add-toggle rainbow-identifier-globally
:status rainbow-identifiers-mode
:on (rainbow-identifiers-mode)
:off (rainbow-identifiers-mode -1)
:mode rainbow-identifiers-mode
:documentation "Colorize identifiers globally."
:evil-leader "tCi")

Expand Down
4 changes: 1 addition & 3 deletions layers/+vim/evil-cleverparens/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
(progn
(setq evil-cleverparens-use-regular-insert t)
(spacemacs|add-toggle evil-cleverparens
:status evil-cleverparens-mode
:on (evil-cleverparens-mode)
:off (evil-cleverparens-mode -1)
:mode evil-cleverparens-mode
:documentation "Enable evil-cleverparens."))))
4 changes: 1 addition & 3 deletions layers/+vim/vim-empty-lines/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
(progn
(global-vim-empty-lines-mode)
(spacemacs|add-toggle vim-empty-lines-mode
:status vim-empty-lines-mode
:on (global-vim-empty-lines-mode)
:off (global-vim-empty-lines-mode -1)
:mode global-vim-empty-lines-mode
:documentation
"Display an overlay of ~ on empty lines."
:evil-leader "t~")
Expand Down

0 comments on commit 62fc64f

Please sign in to comment.