DarthFennec / highlight-indent-guides

Emacs minor mode to highlight indentation
573 stars 28 forks source link

Conflict with origami #102

Open jcs090218 opened 4 years ago

jcs090218 commented 4 years ago

I am getting this error while using origami.

Error during redisplay: (jit-lock-function 322) signaled (wrong-type-argument listp t)

Steps to reproduce:

  1. Open a file with indentation available. For instance,
public class Foo {
|   <- 4 spaces and the indent guide symbol at the very beginning.
}
  1. Close the node with origami; then you should see.
public class Foo {...}
  1. Call M-x delete-trailing-whitespace

I think the issue is that the guide is deleted inside origami's folding overlay after calling delete-trailing-whitespace; then this package is trying to display a deleted guide? 😕

DarthFennec commented 4 years ago

Hmm ... can't seem to reproduce. I'm not entirely sure why it would happen the way you describe, seeing as delete-trailing-whitespace only deals with trailing whitespace, and highlight-indent-guides never draws on trailing whitespace (only leading whitespace), so a guide should never be deleted in a situation like this. Also origami apparently uses overlays to display folds without actually changing the content, and highlight-indent-guides works directly on the content itself and ignores overlays, so they shouldn't interfere with each other at all.

Given this, it seems very unlikely that this would be the cause, but in that case I'm really not sure why you're getting this error. Is anything actually not working properly, or are you just getting an error message? Is there anything else in your setup that might be getting in the way?

jcs090218 commented 4 years ago

Oops, sorry. Try this then,

public class Foo {
    int x = 0;
    <--  spaces ready for `delete-trailing-whitespace`
}

I guess you need at least a line inside the block. I don't know why! 😕

and highlight-indent-guides works directly on the content itself and ignores overlays, so they shouldn't interfere with each other at all.

Got it. This make sense! Base on the error, I think there is something wrong when trying to redisplay? My best guess is, Emacs is trying to redisplay guide inside the block but it couldn't because of the overlay? But there is indeed a modification inside the overlay.

Given this, it seems very unlikely that this would be the cause, but in that case I'm really not sure why you're getting this error. Is anything actually not working properly, or are you just getting an error message? Is there anything else in your setup that might be getting in the way?

No worries! This isn't a big issue since this isn't a breaking bug. I have tried with emacs -q but I am still getting the same error. 😕

DarthFennec commented 4 years ago

Okay cool, I'm getting the error now. I noticed this only happens when delete-trailing-whitespace actually deletes something, including space at the end of a line where there are no indentation guides ... highlight-indent-guides shouldn't be touching those characters, but clearly something is going on there ...

Looking back through the code, I'm noticing that a number of the functions I have to use to either check or modify information about a character only work when the cursor is on top of that character. Because of this, I use save-excursion and then move the cursor to wherever I need it, which is pretty standard practice and works well. However, after playing with the commands, I noticed that if I move the cursor into the hidden part of the buffer programmatically, some of those commands give me what I expect and others don't. For example, current-column always gives me 0 when I'm inside the hidden area, even when it really shouldn't. This seems like a good guess as to why the error is happening, or at least a reason for highlight-indent-guides to act differently within a fold.

I'm still not entirely sure why deleting those spaces would get it confused, though. Once the spaces are deleted, it should no longer be aware that they were ever there to begin with, so it wouldn't be trying to draw to them. I think you may be right, and the overlay is interfering with the guide calculations (due to functions like current-column giving the wrong results). Perhaps it has nothing to do with the spaces being deleted, and this just happens any time there's a reason to refresh guides inside the fold (for example, whenever the text in the fold changes). Or maybe that's way off track. I'll have to look into it more to be sure.

In any case, it doesn't really seem like something that can be fixed, just from a cursory glance. Since it also doesn't seem to be causing any real damage, it's probably safe to just ignore. I'll look further into this when I have the time, so let me know if it starts breaking things.