I'm a big fan of rainbow-delimiters. Even when I do not code in Lisp I can quickly and easily find matching bracket just looking at the code. My method works better on dark backgrounds, but can be tweaked to work on light backgrounds as well. The thing that still needs doing is automatic change of bracket colours after the theme change.
My code so far:
(require 'color)
(defun hsl-to-hex (h s l)
"Convert H S L to hex colours."
(let (rgb)
(setq rgb (color-hsl-to-rgb h s l))
(color-rgb-to-hex (nth 0 rgb)
(nth 1 rgb)
(nth 2 rgb))))
(defun bracket-colors ()
"Calculate the bracket colours based on background."
(let (hexcolors lightvals)
(if (>= (color-distance "white"
(face-attribute 'default :background))
(color-distance "black"
(face-attribute 'default :background)))
(setq lightvals (list 0.65 0.55))
(setq lightvals (list 0.35 0.30)))
(concatenate 'list
(dolist (n'(.71 .3 .11 .01))
(push (hsl-to-hex (+ n 0.0) 1.0 (nth 0 lightvals)) hexcolors))
(dolist (n '(.81 .49 .17 .05))
(push (hsl-to-hex (+ n 0.0) 1.0 (nth 1 lightvals)) hexcolors)))
(reverse hexcolors)))
(defun colorise-brackets ()
"Apply my own colours to rainbow delimiters."
(require 'rainbow-delimiters)
(custom-set-faces
;; or use (list-colors-display)
`(rainbow-delimiters-depth-1-face ((t (:foreground "#888"))))
`(rainbow-delimiters-depth-2-face ((t (:foreground ,(nth 0 (bracket-colors))))))
`(rainbow-delimiters-depth-3-face ((t (:foreground ,(nth 1 (bracket-colors))))))
`(rainbow-delimiters-depth-4-face ((t (:foreground ,(nth 2 (bracket-colors))))))
`(rainbow-delimiters-depth-5-face ((t (:foreground ,(nth 3 (bracket-colors))))))
`(rainbow-delimiters-depth-6-face ((t (:foreground ,(nth 4 (bracket-colors))))))
`(rainbow-delimiters-depth-7-face ((t (:foreground ,(nth 5 (bracket-colors))))))
`(rainbow-delimiters-depth-8-face ((t (:foreground ,(nth 6 (bracket-colors))))))
`(rainbow-delimiters-depth-9-face ((t (:foreground ,(nth 7 (bracket-colors))))))
`(rainbow-delimiters-unmatched-face ((t (:foreground "white" :background "red"))))
`(highlight ((t (:foreground "#ff0000" :background "#888"))))
))
(colorise-brackets)
After changing from dark to light theme, or vice versa I need to manually eval following in the scratch buffer:
(colorise-brackets)
How do I make it automatic? What other improvements would you suggest?
M-:
and just type it into the minibuffer, instead of typing into the*scratch*
buffer. You could also make your function forcolorise-brackets
interactive and add it to a keyboard shortcut. – lawlist Mar 30 '16 at 00:44enable-theme
,load-theme
,disable-theme
. I don't use themes, but if I did, I would probably submit an enhancement request to the Emacs development team. I don't see it in the functions, and I don't see it in the manual: https://www.gnu.org/software/emacs/manual/html_node/emacs/Custom-Themes.html – lawlist Mar 30 '16 at 01:32