DarthFennec / highlight-indent-guides

Emacs minor mode to highlight indentation
571 stars 27 forks source link

Error: void-variable start #52

Closed seagle0128 closed 5 years ago

seagle0128 commented 5 years ago

While using swiper on GNU Emacs 27.0.50 with Ubuntu, I got this error:

Debugger entered--Lisp error: (void-variable start)
  highlight-indent-guides--character-highlighter()
  eval((highlight-indent-guides--character-highlighter))
  font-lock-fontify-keywords-region(1 4773 nil)
  font-lock-default-fontify-region(1 4773 nil)
  font-lock-fontify-region(1 4773)
  #f(compiled-function (fun) #<bytecode 0x1b7faf1>)(font-lock-fontify-region)
  run-hook-wrapped(#f(compiled-function (fun) #<bytecode 0x1b7faf1>) font-lock-fontify-region)
  jit-lock--run-functions(1 4773)
  jit-lock-fontify-now(1 72721)
  font-lock-ensure()
  swiper-font-lock-ensure()
  swiper--candidates()
  swiper(nil)
  counsel-grep-or-swiper()
  funcall-interactively(counsel-grep-or-swiper)
  call-interactively(counsel-grep-or-swiper nil nil)
  #f(compiled-function (cmd &optional record-flag keys special) "Execute CMD as an editor command.\nCMD must be a symbol that satisfies the `commandp' predicate.\nOptional second arg RECORD-FLAG non-nil\nmeans unconditionally put this command in the variable `command-history'.\nOtherwise, that is done only if an arg is read using the minibuffer.\nThe argument KEYS specifies the value to use instead of (this-command-keys)\nwhen reading the arguments; if it is nil, (this-command-keys) is used.\nThe argument SPECIAL, if non-nil, means that this command is executing\na special event, so ignore the prefix argument and don't clear it." #<bytecode 0x2506ad>)(counsel-grep-or-swiper nil nil nil)
  ad-Advice-command-execute(#f(compiled-function (cmd &optional record-flag keys special) "Execute CMD as an editor command.\nCMD must be a symbol that satisfies the `commandp' predicate.\nOptional second arg RECORD-FLAG non-nil\nmeans unconditionally put this command in the variable `command-history'.\nOtherwise, that is done only if an arg is read using the minibuffer.\nThe argument KEYS specifies the value to use instead of (this-command-keys)\nwhen reading the arguments; if it is nil, (this-command-keys) is used.\nThe argument SPECIAL, if non-nil, means that this command is executing\na special event, so ignore the prefix argument and don't clear it." #<bytecode 0x2506ad>) counsel-grep-or-swiper)
  apply(ad-Advice-command-execute #f(compiled-function (cmd &optional record-flag keys special) "Execute CMD as an editor command.\nCMD must be a symbol that satisfies the `commandp' predicate.\nOptional second arg RECORD-FLAG non-nil\nmeans unconditionally put this command in the variable `command-history'.\nOtherwise, that is done only if an arg is read using the minibuffer.\nThe argument KEYS specifies the value to use instead of (this-command-keys)\nwhen reading the arguments; if it is nil, (this-command-keys) is used.\nThe argument SPECIAL, if non-nil, means that this command is executing\na special event, so ignore the prefix argument and don't clear it." #<bytecode 0x2506ad>) counsel-grep-or-swiper)
  command-execute(counsel-grep-or-swiper)
DarthFennec commented 5 years ago

Well that's really weird. Try doing C-h f font-lock-fontify-keywords-region RET, should bring up help for the function. The second paragraph should look something like this:

(font-lock-fontify-keywords-region START END &optional LOUDLY)

The function calls highlight-indent-guides--character-highlighter, which reads from that START parameter (which is possible because elisp is dynamically scoped). Your error is saying that START doesn't exist, but font-lock-fontify-keywords-region is in the stacktrace, so as long as it still has that parameter everything should be fine. If you check the help and see whether the parameter is gone or perhaps called something different, that'll tell you for sure. I seriously doubt that's the case though, since I'm running 26.1 in Linux and it's fine.

I doubt you're doing anything weird that changes the scoping rules, because that should only have per-file effects. I also don't think it's related to advice, because that would show up in the stacktrace. I really don't know what's going on.

You say this only happens when you use swiper? I don't see how that would be related, but I suppose it must be. I guess I'll have to look more into it.

jgkamat commented 5 years ago

Vincent Zhang writes:

While using swiper on GNU Emacs 26.1 with macOS, I got this error:

I also use swiper with 26.1 and highlight-indent-guides and I don't see this issue.

Maybe (somehow) lexical scope was forced on when this package was byte compiled? Can you reproduce this with a minimal config?

seagle0128 commented 5 years ago

@jgkamat This issue doesn't occur always actually. I didn't encounter it on my macOS, while on Linux Mint in VM. Exact same configurations (https://github.com/seagle0128/.emacs.d). Don't know why...

dakra commented 5 years ago

I have the same problem since I updated my Emacs from master. I think this commit could be the problem: http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=70926a3e8671034fd5cb1a546f9c107feda729a3

PS: highlight-indent-guides is not working for me at all, so I don't think it has anything to do with swiper. Invoking swiper shows the error message though, maybe I wouldn't even have realised otherwise.

DarthFennec commented 5 years ago

@dakra Oh wow, you're probably right about that commit. Setting font-lock.el to use lexical scope would definitely cause this issue. I guess I don't notice because I haven't updated my emacs in a couple months.

Assuming this is the issue, I'll need to find some alternate way to access the value in START. I have a few ideas, but I'll need to try things out and see what's actually viable ...

seagle0128 commented 5 years ago

Yes, it should be the root cause. I just realize it just happens with 27, while not 26. I updated the description above.

CSRaghunandan commented 5 years ago

I also notice this issue on emacs 27.0.50 on archlinux

DarthFennec commented 5 years ago

@seagle0128 @jgkamat @dakra @CSRaghunandan I pushed a fix. Please give it a try, as I can't properly test it right now; I'm reasonably certain it works equivalently in Emacs 26, but due to external factors I can't try it in 27 at the moment.

I switched it to using (match-beginning 0), which as far as I can tell will always have the same value as START when this function is called, and it is also globally accessible. (point) should also be equivalent, and usually is, but I found some situations where that approach would break, and I don't really know the reason for that at the moment.

If this doesn't work, I can add a global variable to contain this state, which the matcher function sets and the highlighter function reads from. That feels like a hacky solution, but it's technically equivalent to the current solution, except with a custom variable instead of the global match state. It may also be more future-proof.

dakra commented 5 years ago

I just tested it briefly and it seems to work. Thanks.

seagle0128 commented 5 years ago

It works for me as well. Thanks!

DarthFennec commented 5 years ago

Awesome, then I'm closing this. If the fix turns out not to work for someone, feel free to reopen.