reddit / emacs

Highlighting backticks in comments

[deleted] · 2022-09-05 06:30
A regex understander recently helped me solve the last problem I had getting this to work, so I thought I'd share in case anyone else wants this feature. There's a cool package named [hl-prog-extra](https://melpa.org/#/hl-prog-extra) which lets you write regexes for highlighting some things extra specially. In comments, I wanted words surrounded by backticks to be highlighted like GitHub or `lsp-ui-mode` do. My `init.el` contains: (setq hl-prog-extra-list (list ;; Match `symbol`. '("`[^`\n]+`" 0 comment lsp-face-semhl-namespace))) Which gives me cool highlighting like: https://preview.redd.it/6b4y5wpjhzl91.png?width=723&format=png&auto=webp&s=60ca6e30cf16688802a31e62a28a5a284bab6da3 As you can see, everything within backticks is purple, but the words between them are still grayed out. Just thought I'd mention, in case anyone here wants this too.
Atemu12 · 2022-09-05 10:05
Could you add this solution as an answer to https://emacs.stackexchange.com/questions/73293/highlight-variables-functions-in-commens-of-all-prog-modes?
elimik31 · 2022-09-05 14:04
In python (and some other modes) I use [tree-sitter-hl-mode](https://emacs-tree-sitter.github.io/syntax-highlighting) for tree-sitter based syntax highlighting so I was wondering if that's compatible with these extras. I found that the above snippet for normal comments works. However, the package comes with some presets for python doc-strings, to highlight sphynx-style markup, and that didn't work, that only appeared when I disabled `tree-sitter-hl-mode`. I'm wondering if one can make those two work together or there's fundamental icompatibility. Anyway, I created [issue #5](https://codeberg.org/ideasman42/emacs-hl-prog-extra/issues/5) for that. Note: In general, if you want to use the pre-sets, I would prefer `add-to-list` over `setq`, e.g.: (customize-set-variable 'hl-prog-extra-preset t) (add-to-list 'hl-prog-extra-list '("`[^`\n]+`" 0 comment lsp-face-semhl-namespace)) (global-hl-prog-extra-mode)
[deleted] · 2022-09-05 16:34
Thanks for the tip!