The wiki solution didn’t cut it for me, so I went with this small snippet.
hook -group todohighlight global BufCreate .* %{
add-highlighter buffer/ dynregex "%opt{comment_line}[ \t]*\b(TODO|FIXME|MAYBE)\b" 1:default+bu@comment
}
This is still flawed however, as TODOs in multi-line comments won’t be highlighted.
FWIW dynregex has fallen from grace.
I think it’s possible to implement the same beavior with a WinSetOption comment_line=.*
hook. That hook will be more efficient. In theory Kakoune could optimize the dynregex pattern the same way but that’s surely not worth the code complexity.
2 Likes
Thanks for that information !
Modify the snippet to work without dynregex :
hook -group todohighlight global BufCreate %opt{regular_buffers} %{
evaluate-commands %sh{
printf '%s\n' "add-highlighter buffer/ regex '${kak_opt_comment_line}[ \t]*\b(TODO|FIXME|MAYBE)\b' 1:default+bu@comment"
}
}
I’m still using BufCreate
since WinSetOption
triggers the hook multiple times if I have the same buffer opened in multiple windows.
I scope the highlighter to window/
, but is there a good reason to repeat do so ?
Another update, the shell call is non-necessary here :
hook -group todohighlight global BufCreate %opt{regular_buffers} %{
evaluate-commands "add-highlighter buffer/ regex '%opt{comment_line}[ \t]*\b(TODO|FIXME|MAYBE)\b' 1:default+bu@comment"
}