hl-todo icon indicating copy to clipboard operation
hl-todo copied to clipboard

flymake integration not working with certain files

Open vishesh opened this issue 3 months ago • 9 comments

I'm registering hl-todo with flymake using:

(add-hook 'flymake-diagnostic-functions #'hl-todo-flymake nil t)

However, on certain files (e.g. https://github.com/apple/foundationdb/blob/main/fdbrpc/FlowTransport.actor.cpp) flymake disables this backend. With debug-on-error on I'm getting this stacktrace:

Debugger entered--Lisp error: (error "Invalid search bound (wrong side of point)")
  looking-back("// \\s-+" 11872)
  hl-todo-flymake(#f(compiled-function (&rest args) #<bytecode 0xb156aa8fee800fd>))
  apply(hl-todo-flymake #f(compiled-function (&rest args) #<bytecode 0xb156aa8fee800fd>) nil)
  flymake--run-backend(hl-todo-flymake nil)
  #f(compiled-function (backend) #<bytecode -0x1f3e933b59f071b>)(hl-todo-flymake)
  flymake-start((on-display) nil)
  #f(compiled-function () #<bytecode 0xc8542e3d59a8f11>)()

vishesh avatar Nov 18 '25 02:11 vishesh

Initial attempts at reproducing this did not succeed.

Are you sure you are using the latest version of hl-todo? What Emacs version do you use? Are all hl-todo options at their default values?

tarsius avatar Nov 18 '25 11:11 tarsius

Thank you or looking into it. Here is the information you asked;

Emacs: GNU Emacs 30.2 (build 2, aarch64-apple-darwin24.6.0, NS appkit-2575.70 Version 15.6 (Build 24G84)) of 2025-08-15

Hl-TODO: 20251101.2019

This is all configuration I've done with hl-todo. Face the same issue if I remove defer and commands either or if I instead use global-hl-todo-mode. And mostly it works, its just rarely with random files including the ones I sent. If I restart flymake-mode it will start working most times.

(use-package hl-todo
  :defer 1
  :commands (hl-todo-mode)
  :hook (prog-mode . (lambda ()
                       (hl-todo-mode +1)
                       (add-hook 'flymake-diagnostic-functions #'hl-todo-flymake nil t)
                       (flymake-mode +1)))
  :init
  (setq hl-todo-keyword-faces
        '(("TODO"   . "#FF0000")
          ("FIXME"  . "#FF4500")
          ("NOTE"   . "#1E90FF")
          ("HACK"   . "#FFD700")))
  :config
  (dolist (keyword '("BUG" "DEFECT" "ISSUE" "WORKAROUND"))
    (cl-pushnew `(,keyword . "#cd5c5c") hl-todo-keyword-faces)))

and

(use-package flymake
  :bind (("C-c l a" . flymake-show-project-diagnostics)
         ("C-c l b" . flymake-show-buffer-diagnostics)
         ("C-c l l" . flymake-mode)
         ("C-x ]"   . flymake-goto-next-error)
         ("C-x ["   . flymake-goto-prev-error)))

vishesh avatar Nov 18 '25 16:11 vishesh

its just rarely with random files including the ones I sent.

When I said that I could not reproduce it, I meant that I could not do so with that exact file. I also noticed that 11872 is the position at the end of the file and that there aren't any keywords around there.

I do not use flymake. This feature was contributed by @minad in #74. I've noticed that the initial version limited search to some region and later, in #75 he stopped doing that. But maybe the limiting is necessary after all, I don't know. @minad could you please have a look?

I do not spot anything in your configuration that I would suspect playing a role in this (but it never hurts to remove unnecessary customization while debugging, just in case). Also it is weird that you edit hl-todo-keywords-faces twice, using different approaches, once in :init and then again in :config.

tarsius avatar Nov 19 '25 17:11 tarsius

Oh, it is over two years ago that I contributed this. I don't remember any of the details. I never had problems with it. But by inspection I am not sure about this code anymore (why did I write it like this??):

              (let ((keyword (match-string 1))
                    (beg (match-beginning 0))
                    (end (pos-eol))
                    (bol (pos-bol)))
                ;; Take whole line when keyword is not at the start of comment.
                (save-excursion
                  (goto-char beg)
                  (unless (looking-back comment bol)
                    (goto-char bol)

Shouldn't we first go to beg before we compute (pos-bol) and (pos-eol)? Then I think the "Invalid search bound" error should go away.

minad avatar Nov 19 '25 18:11 minad

That sounds reasonable. Not sure why I didn't spot that this doesn't jump to the match first. Would you like to contribute a patch, or should I do it?

tarsius avatar Nov 19 '25 18:11 tarsius

I tried changing the code above, and unfortunately it doesn't work.

minad avatar Nov 19 '25 19:11 minad

Thanks for looking into it @minad.

Well, I guess then I have to investigate. @vishesh, I won't have time for that until next year.

tarsius avatar Nov 21 '25 21:11 tarsius

No worries at all. Totally understand. Really appreciate you two for writing these packages.

I will try to pick up some elisp during holiday season as well :)

vishesh avatar Nov 21 '25 21:11 vishesh

tarsius avatar Nov 21 '25 22:11 tarsius