elfsternberg · 2022-03-24 15:29
Hi! I use Emacs to write documentation, and a lot of times my files end up with some internal markup that looks like this: `[TK: Where is the event handler defined?]` in-line with the text. (["TK" is writer speak for "to come"](https://en.wikipedia.org/wiki/To_come_(publishing)), since the only common English words that have 'tk' in them are "pocketknife" and "hotkey", and case sensitivity matters.)
I added "TK" to `hl-todo-keyword-faces`, but I discovered that hl-todo uses a regexp like `(^|\s)(<keyword>)`, so the opening bracket confuses hl-todo and it doesn't show up in the todo lists.
I wrote a quick perl script to place a space before the bracket, and it worked, and now the magit-status buffer says my documentation folder has 59 TODOs over 41 markdown files-- which is great!-- but it won't list them! Which is not great.
So:
1. Remembering to include the space in `[ TK: ...]` is a pain in the neck, and looks terrible. Is there a way to modify the regexp such that the opening bracket is a legal character to hl-todo without hacking hl-todo's source in the elpa folder?
2. Has anyone seen this where Magit-todo won't list the TODOs? What do I do? I'm not the world's greatest elisp hacker, and it's always good to task first before trying to figure out for myself.
Thanks it advance.
organic-bookworm · 2022-03-24 16:47
>1. \[...\] Is there a way to modify the regexp \[...\]?
Which major mode do you use?
Keywords are [highlighted](https://github.com/tarsius/hl-todo/blob/42f744ffb513cf2b95517144c64dbf3fc69f711a/hl-todo.el#L230-L231) **anywhere** in modes derived from modes in the [hl-todo-text-modes](https://github.com/tarsius/hl-todo/blob/42f744ffb513cf2b95517144c64dbf3fc69f711a/hl-todo.el#L98) variable, but only in **strings** and **comments** in other modes.
For me `(push '("TK" warning bold) hl-todo-keyword-faces)` highlights `[TK: ...]` as expected.
I use [hl-todo@42f744ffb513c](https://github.com/tarsius/hl-todo/tree/42f744ffb513cf2b95517144c64dbf3fc69f711a/hl-todo.el).
elfsternberg · 2022-03-24 18:01
So this is weird. I've figured out what I was doing wrong with Magit not giving me the list, so that's done. (I had a bad keystroke configuration.) And you're right, hl-todo does show me the [TK: ...] entries in a buffer. Thanks for pointing that out!
But Magit doesn't. It still needs that space in front of the keyword. So something weird is going on here. I'm still tracking it down, but now I'm head-deep into magit-todo's source code.
elfsternberg · 2022-03-24 18:46
Continuing my quest to understand the issue, I've found it. hl-todos uses Emacs' internal regexp, but magit-todos wants to scan the project and multiple files, so it uses `rg` or a PCRE-compatible grep, and this is the string it uses (dumped using prn1-to-string):
```
^(\\*+)[[:blank:]]+(DEPRECATED|FIXME|HACK|REVIEW|T(?:[K]|ODO)|XXX)[[:space:]]+(.+)|(?:^|[[:blank:]]+)(DEPRECATED|FIXME|HACK|REVIEW|T(?:[K]|ODO)|XXX)(?:\\([^)]+\\))?:?(?:[[:blank:]]+(.+))?
```
It's that `[[:blank:]]` at the beginning of expression that's causing the disconnect. Now to track down how it's being built.
00-11 · 2022-03-24 19:00
https://emacs.stackexchange.com/q/71105/105
elfsternberg · 2022-03-24 19:03
And I have solved the problem. Unfortunately, it WILL require a patch to magit-todos. The sequence defining how the regular expression is defined for non-ORG mode searches (lines 1195-1999 in magit-todos-20210811.459) has to be changed from :
``` lisp
(seq (or bol (1+ blank))
(group (or ,@keywords))
(regexp ,magit-todos-keyword-suffix)
(optional (1+ blank)
(group (1+ not-newline)))))))
```
to:
``` lisp
(seq (or bol (1+ (not alphanumeric)))
(group (or ,@keywords))
(regexp ,magit-todos-keyword-suffix)
(optional (1+ blank)
(group (1+ not-newline)))))))
```
... and now it behaves more like hl-todo. The change is in the first line, replacing the `blank` symbol with `(not alphanumeric)`.
Time for some hot forking action, as Github use to say before Microsoft bought them.
[EDIT] And [now there's a pull request](https://github.com/alphapapa/magit-todos/pull/125).
ideasman_42 · 2022-03-24 22:24
Realize this isn't addressing the `hl-todo` question, I'm the author of [hl-prog-extra](https://gitlab.com/ideasman42/emacs-hl-prog-extra) which lets you define your own regex on comments/code/strings/doc-strings etc, I use it with [sidecar-locals](https://gitlab.com/ideasman42/emacs-sidecar-locals) for per-project highlighting (highlighting bug ticket's spesific to the bug tracker for example). You might find it handy.
organic-bookworm · 2022-03-25 06:39
I don't use `magit-todos`, but thanks for reporting back and PR.