hydra icon indicating copy to clipboard operation
hydra copied to clipboard

Bad interaction with company-mode when editing hydra

Open justbur opened this issue 7 years ago • 3 comments

  1. emacs -Q
  2. M-x package-initialize
  3. M-x toggle-debug-on-error
  4. M-x company-mode
  5. After "a" start typing in the code below
(defhydra simple (nil nil :hint nil :foreign-keys run)
  "
_a_: A"
  ("a" asd))

You get trapped in a loop with backtrace. company is trying to expand the macro which throws an error each time. Is there any way to avoid an error on macro expansion?

Debugger entered--Lisp error: (error "An run Hydra must have at least one blue head in order to exit")
  signal(error ("An run Hydra must have at least one blue head in order to exit"))
  error("An %S Hydra must have at least one blue head in order to exit" run)
  #[898 "C\302!\262;\204* :\203\"

justbur avatar May 18 '17 12:05 justbur

Works fine for me. In any case, seems like a company-mode issue rather than hydra.

abo-abo avatar May 18 '17 13:05 abo-abo

It's not just company-mode, although that is what's causing the headache here. The call that triggers it is elisp--local-variables which tries to expand any surrounding macros. If you just try to macroexpand a bad hydra, an error is thrown. Here for example.

The issue is that there are some cases (eg company-mode) in which the macro gets expanded before the user has finished it and defhydra throws errors at expansion time. I tend to leave debug-on-error on, but I can see that everything is fine with it off. What if the macro just expanded to the error without executing it in this case? Would that be bad?

Now that I understand the problem, I can just leave debug-on-error off, but this is the first time it's caused a problem when there wasn't an actual bug.

justbur avatar May 18 '17 16:05 justbur

What if the macro just expanded to the error without executing it in this case? Would that be bad?

You can change it to a warning as far as I'm concerned. The error was intended as a hint to the user to fix the code.

abo-abo avatar May 18 '17 16:05 abo-abo