colors: remove colors-enable-rainbow-identifiers and new layer variable colors-colorize-identifiers

You have to replace in your dotfile the layer variable
colors-enable-rainbow-identifiers t
by
colors-colorize-identifiers 'all

color-colorize-identifiers can take 3 values:
- variables -> colorize only variables via color-identifiers mode
- all -> colorize all identifiers
- nil -> no colorisation

New key bindings:

SPC t C a -> colorize all
SPC t C C-a -> colorize all globally

SPC t C v -> colorize variables
SPC t C C-v -> colorize variables globally
This commit is contained in:
syl20bnr 2016-06-03 23:29:59 -04:00
parent 49fc0d533d
commit dde9eef487
4 changed files with 198 additions and 134 deletions

View File

@ -5,18 +5,19 @@
* Table of Contents :TOC_4_gh:noexport:
- [[#description][Description]]
- [[#install][Install]]
- [[#enable-rainbow-identifiers][Enable rainbow-identifiers]]
- [[#configuration][Configuration]]
- [[#colorize-identifiers][Colorize identifiers]]
- [[#enable-nyan-cat][Enable Nyan cat]]
- [[#key-bindings][Key bindings]]
- [[#rainbow-identifiers][Rainbow Identifiers]]
- [[#colorize-identifiers-1][Colorize Identifiers]]
- [[#rainbow-mode][Rainbow Mode]]
- [[#nyan-mode][Nyan Mode]]
* Description
This layer colors your life with:
- [[https://github.com/Fanael/rainbow-identifiers][rainbow identifiers]] mode will colorize each variables and functions with an
almost unique color. The keywords and the declaration of function colors are
disabled in order to make the colorized variables and functions stand out.
- [[https://github.com/Fanael/rainbow-identifiers][rainbow identifiers]] mode will colorize all identifiers (christmas tree mode :-))
with an almost unique color.
- [[https://github.com/ankurdave/color-identifiers-mode][color-identifiers]] mode will colorize only identifiers recognized as variables.
- [[https://julien.danjou.info/projects/emacs-packages][rainbow mode]] displays strings representing colors with the color they
represent as background.
- [[https://github.com/syl20bnr/nyan-mode][nyan mode]] display a Nyan cat progress bar in the mode-line.
@ -26,19 +27,24 @@ To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =colors= to the existing =dotspacemacs-configuration-layers= list in this
file.
** Enable rainbow-identifiers
To enable =rainbow-identifiers-mode= by default in programing language buffers,
set the variable =colors-enable-rainbow-identifiers-by-default= to =t=:
* Configuration
** Colorize identifiers
To colorize some identifiers by default in programming language buffers, set
the layer variables =colors-colorize-identifiers= to either =variables= or
=all=. =variables= will colorize only words recognized as variables, =all=
will colorize all the words.
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(
(colors :variables colors-enable-rainbow-identifiers-by-default t)))
(colors :variables colors-colorize-identifiers 'all)))
#+END_SRC
Saturation and lightness of identifiers can be set per theme by adding
an entry in the variable =colors-theme-identifiers-sat&light=. This
is an alist where the key is a theme symbol and the value is a pair
=(saturation lightness)=.
When using the value =all= the Saturation and lightness of can be set per theme
by adding an entry in the variable =colors-theme-identifiers-sat&light=. This is
an alist where the key is a theme symbol and the value is a pair =(saturation
lightness)=.
For now saturation and lightness are not supported with the =variables= value.
Example:
@ -47,7 +53,6 @@ Example:
#+END_SRC
** Enable Nyan cat
To enable the package =nyan-mode= set the variable
=colors-enable-nyan-cat-progress-bar= to =t=:
@ -68,18 +73,17 @@ a quasi-quoted list:
* Key bindings
The prefix associated with colors is ~C~.
** Rainbow Identifiers
** Colorize Identifiers
[[file:img/theme-tweaks-python.png]]
=rainbow-identifiers= mode can be toggled on and off with:
~SPC t C i~
Note that the toggle is local to the current buffer.
| Key Binding | Description |
|-------------+-----------------------------------------------------------------|
| ~SPC C a~ | colorize all idendifiers in current buffer |
| ~SPC C C-a~ | globally colorize all idendifiers and all subsequent buffers |
| ~SPC C v~ | colorize all variables only in current buffer |
| ~SPC C C-v~ | globally colorize all variables only and all subsequent buffers |
The =saturation= and =lightness= of identifier colors can be adjusted live
with the transient-state:
when colorizing all the identifiers with the transient-state:
| Key Binding | Description |
|-----------------+------------------------------------------|

View File

@ -11,8 +11,9 @@
;; Variables
(defvar colors-enable-rainbow-identifiers-by-default nil
"If non nil the `rainbow-identifers' package is enabled.")
(defvar colors-colorize-identifiers nil
"If `variables' colorize variables, if `all' colorize all identifiers in
programming language buffers.")
(defvar colors-enable-nyan-cat-progress-bar nil
"If non nil all nyan cat packges are enabled (for now only `nyan-mode').")

View File

@ -0,0 +1,116 @@
;;; funcs.el --- Colors Layer functions File
;;
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
;; rainbow-identifiers
(defun colors//rainbow-identifiers-mode-maybe ()
"Enable rainbow identifiers if the major mode is a prog mode."
(when (derived-mode-p 'prog-mode)
(rainbow-identifiers-mode)))
(defun colors//tweak-theme-colors (theme)
"Tweak color themes by adjusting rainbow-identifiers."
(interactive)
;; tweak the saturation and lightness of identifier colors
(let ((sat&light (assq theme colors-theme-identifiers-sat&light)))
(if sat&light
(setq rainbow-identifiers-cie-l*a*b*-saturation (cadr sat&light)
rainbow-identifiers-cie-l*a*b*-lightness (caddr sat&light))
(setq rainbow-identifiers-cie-l*a*b*-saturation 80
rainbow-identifiers-cie-l*a*b*-lightness 45))))
(defun colors//change-color-mini-mode-doc (component)
"Display a short documentation in the mini buffer."
(let ((var (intern (format
"rainbow-identifiers-cie-l*a*b*-%s" component))))
(spacemacs/echo "Change color %s mini-mode (value: %s)
+ to increase %s
- to decrease %s
= to reset
Press any other key to exit." component (eval var) component component)))
(defun colors/change-color-component-overlay-map (component)
"Set a temporary overlay map to easily change a color COMPONENT from
rainbow-identifier mode. The color COMPONENT can be 'saturation' or
'lightness'."
(set-temporary-overlay-map
(let ((map (make-sparse-keymap))
(up-func (intern (format "colors/change-color-%s-up" component)))
(down-func (intern (format "colors/change-color-%s-down" component)))
(reset-func (intern (format "colors/change-color-%s-reset" component))))
(define-key map (kbd "+") up-func)
(define-key map (kbd "-") down-func)
(define-key map (kbd "=") reset-func)
map) t)
(colors//change-color-mini-mode-doc component))
(defun colors/init-rainbow-mode ()
(use-package rainbow-mode
:commands rainbow-mode
:init (spacemacs/set-leader-keys "tCc" 'rainbow-mode)
:config (spacemacs|hide-lighter rainbow-mode)))
(defun colors/start-change-color-saturation ()
"Initiate the overlay map to change the saturation."
(interactive)
(colors/change-color-component-overlay-map "saturation"))
(defun colors/change-color-saturation-up ()
"Increase the saturation by 5 units."
(interactive)
(colors//change-color-component-func "saturation" 5))
(defun colors/change-color-saturation-down ()
"Decrease the saturation by 5 units."
(interactive)
(colors//change-color-component-func "saturation" -5))
(defun colors/change-color-saturation-reset ()
"Reset the saturation to 100."
(interactive)
(colors//change-color-component-func "saturation" 100 t))
(defun colors/start-change-color-lightness ()
"Initiate the overlay map to change the lightness."
(interactive)
(colors/change-color-component-overlay-map "lightness"))
(defun colors/change-color-lightness-up ()
"Increase the lightness by 5 units."
(interactive)
(colors//change-color-component-func "lightness" 5))
(defun colors/change-color-lightness-down ()
"Decrease the lightness by 5 units."
(interactive)
(colors//change-color-component-func "lightness" -5))
(defun colors/change-color-lightness-reset ()
"Reset the lightness to 40."
(interactive)
(colors//change-color-component-func "lightness" 40 t))
(defun colors//change-color-component-func
(component inc &optional reset)
"Change the color component by adding INC value to it. If RESET is not
nil the color component is set to INC."
(let* ((var (intern (format
"rainbow-identifiers-cie-l*a*b*-%s" component)))
(new-value (+ (eval var) inc)))
(if reset
(set var inc)
(progn
(if (< new-value 0)
(setq new-value 0))
(set var new-value)))
(font-lock-fontify-buffer)
(colors/change-color-component-overlay-map component)))

View File

@ -48,17 +48,33 @@
:defer t
:init
(progn
(spacemacs|diminish color-identifiers-mode "© " "C ")
(when (eq 'variables colors-colorize-identifiers)
(global-color-identifiers-mode))
(spacemacs/declare-prefix "Ci" "colors-identifiers")
(spacemacs|add-toggle color-identifiers-mode
:status color-identifiers-mode
:on (progn
(when (bound-and-true-p rainbow-identifiers-mode)
(rainbow-identifiers-mode -1))
(color-identifiers-mode))
:off (color-identifiers-mode -1)
:documentation "Colorize variables."
:evil-leader "tCv")
(spacemacs|add-toggle global-color-identifiers-mode
:status global-color-identifiers-mode
:on (global-color-identifiers-mode)
:on (progn
(when (bound-and-true-p global-rainbow-identifiers-mode)
(global-rainbow-identifiers-mode -1))
(global-color-identifiers-mode))
:off (global-color-identifiers-mode -1)
:documentation "Colorize identifiers globally."
:evil-leader "tCI"))))
:documentation "Colorize variables globally."
:evil-leader "tC C-v"))
:config (spacemacs|hide-lighter color-identifiers-mode)))
(defun colors/init-rainbow-identifiers ()
(use-package rainbow-identifiers
:commands rainbow-identifiers-mode
:commands (global-rainbow-identifiers-mode
rainbow-identifiers-mode)
:init
(progn
(setq rainbow-identifiers-choose-face-function 'rainbow-identifiers-cie-l*a*b*-choose-face
@ -69,114 +85,41 @@
font-lock-keyword-face
font-lock-function-name-face
font-lock-variable-name-face))
(spacemacs/declare-prefix "Ci" "colors-identifiers")
(spacemacs|add-toggle rainbow-identifier-globally
:mode rainbow-identifiers-mode
:documentation "Colorize identifiers globally."
:evil-leader "tCi")
(when colors-enable-rainbow-identifiers-by-default
(add-hook 'prog-mode-hook 'rainbow-identifiers-mode))
(defun colors//tweak-theme-colors (theme)
"Tweak color themes by adjusting rainbow-identifiers."
(interactive)
;; tweak the saturation and lightness of identifier colors
(let ((sat&light (assq theme colors-theme-identifiers-sat&light)))
(if sat&light
(setq rainbow-identifiers-cie-l*a*b*-saturation (cadr sat&light)
rainbow-identifiers-cie-l*a*b*-lightness (caddr sat&light))
(setq rainbow-identifiers-cie-l*a*b*-saturation 80
rainbow-identifiers-cie-l*a*b*-lightness 45)))))
(colors//tweak-theme-colors spacemacs--cur-theme)
(defadvice spacemacs/post-theme-init (after colors/post-theme-init activate)
"Adjust lightness and brightness of rainbow-identifiers on post theme init."
(colors//tweak-theme-colors spacemacs--cur-theme))
:config
(progn
;; functions to change saturation and lightness of colors
(defun colors//change-color-mini-mode-doc (component)
"Display a short documentation in the mini buffer."
(let ((var (intern (format
"rainbow-identifiers-cie-l*a*b*-%s" component))))
(spacemacs/echo "Change color %s mini-mode (value: %s)
+ to increase %s
- to decrease %s
= to reset
Press any other key to exit." component (eval var) component component)))
(defun colors/change-color-component-overlay-map (component)
"Set a temporary overlay map to easily change a color COMPONENT from
rainbow-identifier mode. The color COMPONENT can be 'saturation' or
'lightness'."
(set-temporary-overlay-map
(let ((map (make-sparse-keymap))
(up-func (intern (format "colors/change-color-%s-up" component)))
(down-func (intern (format "colors/change-color-%s-down" component)))
(reset-func (intern (format "colors/change-color-%s-reset" component))))
(define-key map (kbd "+") up-func)
(define-key map (kbd "-") down-func)
(define-key map (kbd "=") reset-func)
map) t)
(colors//change-color-mini-mode-doc component))
(defun colors/start-change-color-saturation ()
"Initiate the overlay map to change the saturation."
(interactive)
(colors/change-color-component-overlay-map "saturation"))
(defun colors/change-color-saturation-up ()
"Increase the saturation by 5 units."
(interactive)
(colors//change-color-component-func "saturation" 5))
(defun colors/change-color-saturation-down ()
"Decrease the saturation by 5 units."
(interactive)
(colors//change-color-component-func "saturation" -5))
(defun colors/change-color-saturation-reset ()
"Reset the saturation to 100."
(interactive)
(colors//change-color-component-func "saturation" 100 t))
(defun colors/start-change-color-lightness ()
"Initiate the overlay map to change the lightness."
(interactive)
(colors/change-color-component-overlay-map "lightness"))
(defun colors/change-color-lightness-up ()
"Increase the lightness by 5 units."
(interactive)
(colors//change-color-component-func "lightness" 5))
(defun colors/change-color-lightness-down ()
"Decrease the lightness by 5 units."
(interactive)
(colors//change-color-component-func "lightness" -5))
(defun colors/change-color-lightness-reset ()
"Reset the lightness to 40."
(interactive)
(colors//change-color-component-func "lightness" 40 t))
(defun colors//change-color-component-func
(component inc &optional reset)
"Change the color component by adding INC value to it. If RESET is not
nil the color component is set to INC."
(let* ((var (intern (format
"rainbow-identifiers-cie-l*a*b*-%s" component)))
(new-value (+ (eval var) inc)))
(if reset
(set var inc)
(progn
(if (< new-value 0)
(setq new-value 0))
(set var new-value)))
(font-lock-fontify-buffer)
(colors/change-color-component-overlay-map component)))
(defadvice spacemacs/post-theme-init (after colors/post-theme-init activate)
"Adjust lightness and brightness of rainbow-identifiers on post theme init."
(colors//tweak-theme-colors spacemacs--cur-theme))
;; key bindings
(spacemacs/declare-prefix "Ci" "colors-identifiers")
(spacemacs|add-toggle rainbow-identifier
:status rainbow-identifiers-mode
:on (progn
(when (bound-and-true-p color-identifiers-mode)
(color-identifiers-mode -1))
(rainbow-identifiers-mode))
:off (rainbow-identifiers-mode -1)
:documentation "Colorize all identifiers."
:evil-leader "tCa")
(with-eval-after-load 'rainbow-identifiers
(define-global-minor-mode global-rainbow-identifiers-mode
rainbow-identifiers-mode colors//rainbow-identifiers-mode-maybe))
(spacemacs|add-toggle global-rainbow-identifiers-mode
:status global-rainbow-identifiers-mode
:on (progn
(when (bound-and-true-p global-color-identifiers-mode)
(global-color-identifiers-mode -1))
(global-rainbow-identifiers-mode))
:off (global-rainbow-identifiers-mode -1)
:documentation "Colorize identifiers globally."
:evil-leader "tC C-a")
(spacemacs/set-leader-keys "Cis" 'colors/start-change-color-saturation)
(spacemacs/set-leader-keys "Cil" 'colors/start-change-color-lightness))))
(spacemacs/set-leader-keys "Cil" 'colors/start-change-color-lightness)
;; tweak colors of current theme
(colors//tweak-theme-colors spacemacs--cur-theme)
(when (eq 'all colors-colorize-identifiers)
(global-rainbow-identifiers-mode)))))
(defun colors/init-rainbow-mode ()
(use-package rainbow-mode
:commands rainbow-mode
:defer t
:init (spacemacs/set-leader-keys "tCc" 'rainbow-mode)
:config (spacemacs|hide-lighter rainbow-mode)))