emacs: make rainbow-mode use :inverse-video

This is the better design for me, as it works with hl-line-mode.
Otherwise, hl-line-mode overrides the background colour on display.
This commit is contained in:
Protesilaos Stavrou 2025-06-09 07:52:42 +03:00
parent 04ab537fff
commit 1446fbbbb3
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA
2 changed files with 24 additions and 0 deletions

View file

@ -97,6 +97,18 @@
((derived-mode-p 'emacs-lisp-mode))
((string-match-p "-theme" file)))
(rainbow-mode 1)))
:config
(defun prot/rainbow-colorize-match (color &optional match)
"Like `rainbow-colorize-match' but works with `hl-line-mode'."
(let ((match (or match 0)))
(put-text-property
(match-beginning match) (match-end match)
'face `((:background ,(if (> 0.5 (rainbow-x-color-luminance color))
"white" "black"))
(:foreground ,color)
(:inverse-video t)))))
(advice-add #'rainbow-colorize-match :override #'prot/rainbow-colorize-match)
:bind ( :map ctl-x-x-map
("c" . rainbow-mode)) ; C-x x c
:hook (emacs-lisp-mode . prot/rainbow-mode-in-themes))

View file

@ -1931,6 +1931,18 @@ to activate ~rainbow-mode~ if I am editing a theme file.
((derived-mode-p 'emacs-lisp-mode))
((string-match-p "-theme" file)))
(rainbow-mode 1)))
:config
(defun prot/rainbow-colorize-match (color &optional match)
"Like `rainbow-colorize-match' but works with `hl-line-mode'."
(let ((match (or match 0)))
(put-text-property
(match-beginning match) (match-end match)
'face `((:background ,(if (> 0.5 (rainbow-x-color-luminance color))
"white" "black"))
(:foreground ,color)
(:inverse-video t)))))
(advice-add #'rainbow-colorize-match :override #'prot/rainbow-colorize-match)
:bind ( :map ctl-x-x-map
("c" . rainbow-mode)) ; C-x x c
:hook (emacs-lisp-mode . prot/rainbow-mode-in-themes))