I just recently found the "rainbow-delimiters-mode" package and found it quite useful, however I seem to have run into a snag with it when using it in C-like languages:
Naturally, I'd prefer to enable it for all programming modes, so I added the following to my config:
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode)
This apparently worked fine for everything but C-like languages.
I guess cc-mode
is derived from prog-mode
, hence prog-mode-hook
is run before cc-mode, overriding some settings. The cc-mode settings I want are basically the ones in this snippet:
(defun my-cc-mode-common-hook ()
"Setup common utilities for all C-like modes."
(setq-local c-doc-comment-style
'((java-mode . javadoc)
(pike-mode . autodoc)
(c-mode . javadoc)
(c++-mode . javadoc)))
(face-remap-add-relative 'font-lock-doc-face
:foreground (face-foreground font-lock-comment-face)))
(add-hook 'c-mode-common-hook 'my-cc-mode-common-hook)
However, with the rainbow-delimiters-mode in prog-mode-hook
, the above snippet breaks. I thought I could fix this by temporarily disabling the mode at the beginning of the hook and then re-enable it again at the end:
(defun my-cc-mode-common-hook ()
(rainbow-delimiters-mode 0)
;; ...
(rainbow-delimiter-mode))
This doesn't work at all however, so I guess I have to do something else to enable the configuration in cc-mode to fix this issue. Anyone have any ideas?
Also, simply disabling rainbow-delimiters-mode
doesn't re-enable the cc-mode settings I listed above, that is:
(defun my-cc-mode-common-hook ()
(rainbow-delimiters-mode 0)
;; ...
)
Doesn't work, at least not on it's own.
I should note that it is possible to fix this by not having rainbow-delimiters-mode in the prog-mode-hook
and instead place it in c-mode-common-hook
or any other major-mode hook. It does however seem like a hassle to add it to every new programming mode instead of fixing it where it breaks.