Skip to content

Commit

Permalink
feat: use colorful-mode instead of rainbow-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
seagle0128 committed Jun 26, 2024
1 parent 51f0ce8 commit 711fdb5
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions lisp/init-highlight.el
Original file line number Diff line number Diff line change
Expand Up @@ -166,31 +166,36 @@ FACE defaults to inheriting from default and highlight."
(highlight-indent-guides-mode 1)))))))

;; Colorize color names in buffers
(use-package rainbow-mode
:diminish
:defines helpful-mode-map
:bind (:map help-mode-map
("w" . rainbow-mode))
:hook ((html-mode php-mode helpful-mode) . rainbow-mode)
:init (with-eval-after-load 'helpful
(bind-key "w" #'rainbow-mode helpful-mode-map))
:config
(with-no-warnings
;; HACK: Use overlay instead of text properties to override `hl-line' faces.
;; @see https://emacs.stackexchange.com/questions/36420
(defun my-rainbow-colorize-match (color &optional match)
(let* ((match (or match 0))
(ov (make-overlay (match-beginning match) (match-end match))))
(overlay-put ov 'ovrainbow t)
(overlay-put ov 'face `((:foreground ,(if (> 0.5 (rainbow-x-color-luminance color))
"white" "black"))
(:background ,color)))))
(advice-add #'rainbow-colorize-match :override #'my-rainbow-colorize-match)

(defun my-rainbow-clear-overlays ()
"Clear all rainbow overlays."
(remove-overlays (point-min) (point-max) 'ovrainbow t))
(advice-add #'rainbow-turn-off :after #'my-rainbow-clear-overlays)))
(if emacs/>=28p
(use-package colorful-mode
:diminish
:hook ((mhtml-mode html-mode html-ts-mode php-mode latex-mode help-mode helpful-mode) . colorful-mode)
:init (setq colorful-use-prefix t))
(use-package rainbow-mode
:diminish
:defines helpful-mode-map
:bind (:map help-mode-map
("w" . rainbow-mode))
:hook ((mhtml-mode html-mode html-ts-mode php-mode latex-mode help-mode helpful-mode) . rainbow-mode)
:init (with-eval-after-load 'helpful
(bind-key "w" #'rainbow-mode helpful-mode-map))
:config
(with-no-warnings
;; HACK: Use overlay instead of text properties to override `hl-line' faces.
;; @see https://emacs.stackexchange.com/questions/36420
(defun my-rainbow-colorize-match (color &optional match)
(let* ((match (or match 0))
(ov (make-overlay (match-beginning match) (match-end match))))
(overlay-put ov 'ovrainbow t)
(overlay-put ov 'face `((:foreground ,(if (> 0.5 (rainbow-x-color-luminance color))
"white" "black"))
(:background ,color)))))
(advice-add #'rainbow-colorize-match :override #'my-rainbow-colorize-match)

(defun my-rainbow-clear-overlays ()
"Clear all rainbow overlays."
(remove-overlays (point-min) (point-max) 'ovrainbow t))
(advice-add #'rainbow-turn-off :after #'my-rainbow-clear-overlays))))

;; Highlight brackets according to their depth
(use-package rainbow-delimiters
Expand Down

0 comments on commit 711fdb5

Please sign in to comment.