2016-06-04 03:29:59 +00:00
|
|
|
|
;;; funcs.el --- Colors Layer functions File
|
|
|
|
|
;;
|
2018-01-04 07:00:25 +00:00
|
|
|
|
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
2016-06-04 03:29:59 +00:00
|
|
|
|
;;
|
|
|
|
|
;; 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
|
2016-06-08 13:18:04 +00:00
|
|
|
|
(when (not (assq theme (get 'rainbow-identifiers-cie-l*a*b*-saturation
|
|
|
|
|
'theme-value)))
|
|
|
|
|
(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))
|
2016-12-07 23:10:56 +00:00
|
|
|
|
;; fall back to our defaults if there are no per-theme settings
|
|
|
|
|
(setq rainbow-identifiers-cie-l*a*b*-saturation colors-default-rainbow-identifiers-sat
|
2016-12-12 05:33:40 +00:00
|
|
|
|
rainbow-identifiers-cie-l*a*b*-lightness colors-default-rainbow-identifiers-light))))
|
|
|
|
|
;; it isn't enough to just update the variables! we must now refresh the "font
|
|
|
|
|
;; locking" (syntax highlighting) in all buffers that have rainbow-identifiers-mode
|
|
|
|
|
;; currently active, so that they instantly re-paint with their per-theme values.
|
|
|
|
|
;; this loops through all buffers and marks matching ones for re-painting,
|
|
|
|
|
;; starting with the current buffer first so that the user sees quick results!
|
|
|
|
|
(when (featurep 'rainbow-identifiers)
|
|
|
|
|
(dolist ($buf (buffer-list (current-buffer)))
|
|
|
|
|
(with-current-buffer $buf
|
|
|
|
|
(when (and rainbow-identifiers-mode font-lock-mode)
|
|
|
|
|
(if (fboundp 'font-lock-flush)
|
|
|
|
|
(font-lock-flush) ; use flush if available
|
|
|
|
|
(with-no-warnings (font-lock-fontify-buffer))))))))
|
2016-06-04 03:29:59 +00:00
|
|
|
|
|
|
|
|
|
(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 ()
|
2016-12-07 23:28:52 +00:00
|
|
|
|
"Reset the saturation to default."
|
2016-06-04 03:29:59 +00:00
|
|
|
|
(interactive)
|
2016-12-07 23:28:52 +00:00
|
|
|
|
(colors//change-color-component-func "saturation" colors-default-rainbow-identifiers-sat t))
|
2016-06-04 03:29:59 +00:00
|
|
|
|
|
|
|
|
|
(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 ()
|
2016-12-07 23:28:52 +00:00
|
|
|
|
"Reset the lightness to default."
|
2016-06-04 03:29:59 +00:00
|
|
|
|
(interactive)
|
2016-12-07 23:28:52 +00:00
|
|
|
|
(colors//change-color-component-func "lightness" colors-default-rainbow-identifiers-light t))
|
2016-06-04 03:29:59 +00:00
|
|
|
|
|
|
|
|
|
(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)))
|
2016-12-12 05:35:26 +00:00
|
|
|
|
(if (fboundp 'font-lock-flush)
|
|
|
|
|
(font-lock-flush) ; use flush if available
|
|
|
|
|
(with-no-warnings (font-lock-fontify-buffer)))
|
2016-06-04 03:29:59 +00:00
|
|
|
|
(colors/change-color-component-overlay-map component)))
|
2016-12-14 01:59:26 +00:00
|
|
|
|
|
2017-05-24 08:18:19 +00:00
|
|
|
|
(defun colors/add-theme-sat&light (theme-name sat-light)
|
2016-12-14 01:59:26 +00:00
|
|
|
|
"Easily add personal per-theme rainbow-identifiers
|
|
|
|
|
saturation & lightness settings. Your new values will
|
|
|
|
|
override any previous definitions for that theme.
|
|
|
|
|
|
|
|
|
|
Remember to always refresh the look of your theme after
|
|
|
|
|
you've added any new settings!
|
|
|
|
|
|
|
|
|
|
Example usage:
|
|
|
|
|
(colors/add-theme-sat&light 'leuven '(30 50))
|
|
|
|
|
(colors/add-theme-sat&light 'anothertheme '(90 20))
|
|
|
|
|
(colors/refresh-theme-look)"
|
2017-05-24 08:18:19 +00:00
|
|
|
|
(push (cons theme-name sat-light) colors-theme-identifiers-sat&light))
|
2016-12-14 01:59:26 +00:00
|
|
|
|
|
|
|
|
|
(defun colors/refresh-theme-look ()
|
|
|
|
|
"Refresh and re-apply the look of your current theme.
|
|
|
|
|
Always run this after adding new per-theme settings!"
|
|
|
|
|
(interactive)
|
|
|
|
|
(colors//tweak-theme-colors spacemacs--cur-theme))
|