DarthFennec / highlight-indent-guides

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

Conflict with whitespace.el #107

Open johannes-mueller opened 3 years ago

johannes-mueller commented 3 years ago

I am getting a glitch when I use hightlight-indent-guides.el in combination with whitespace.el regarding cursor movement.

Steps to reproduce

  1. Start an emacs installation without init file but with hightlight-indent-guides.el installed (e.g. in .emacs.d/elpa
  2. create a buffer with the following content and eval-buffer it:
    
    (setq highlight-indent-guides-method 'character)

(add-hook 'prog-mode-hook #'whitespace-mode) (add-hook 'prog-mode-hook #'highlight-indent-guides-mode)

3. Open a file with with `.py` name extension and paste the following content into it
```python
def foo:
    if bar==foo:
        scream()
  1. Navigate with the cursor to line 2 column 1
  2. Press C-SPC
  3. Press arrow-down down or C-n

Expected behavior

The cursor should end up in line 3, column 1

Observed behavior

The cursor ends up in line 3 column 10

System information

emacs-27.1 ubuntu 20.4 amd64 highlight-indent-guides 20200820.2328

jimeh commented 3 years ago

I've have this same issue, only workaround I've found is to set highlight-indent-guides-method to'column. Any other method causes this issue.

jimeh commented 3 years ago

Ok, I've done some digging. And I can confirm it happens when:

The cause of the incorrect cursor movement is the temporary-goal-column variable being set to the number of characters +1 from the line above the current line, instead of the cursor position in the current line (0). This happens inside of the line-move-visual function, which uses the posn-at-point function to get current position of the cursor visually within the current window.

For some reason, when the above listed conditions are true, posn-at-point returns a X positional value equal to the end of the previous line, rather than the beginning of the current line.

This is sadly where both my time and knowledge runs out at the moment. posn-at-point is implemented in C, which I don't really know, and it's also outside of my knowledge of Emac's internals.

If it helps anyone, I started debugging this by doing M-x debug-watch RET temporary-goal-column, and following the rabbit hole downwards.

chenl commented 1 year ago

Since this issue is open since 2020-12-27 - and resolution seems to be illusive, perhaps a good-enough-solution should be to let highlight-indent-guides have the option to distinguish between tabs and spaces.

jimeh commented 1 year ago

I need to find some time to double check, I believe I found the part of the cause of this issue a while back while debugging an issue with copilot.el.

Basically, removing newline-mark from whitespace-style should avoid this issue. Obviously not a great fix if you really want to keep newline-mark though.

hexadecagram commented 1 year ago

I am also experiencing this issue and it does seem to be a conflict between whitespace-mode and highlight-indent-guides-mode.

The example given in the introductory post for this issue doesn't seem to get across just how disruptive this issue can be. On large files, inter-line cursor movements can be completely unpredictable: sometimes it stays in the same column, sometimes it's shifted some arbitrary number of spaces, and sometimes it's clear at the end (or beginning) of the line. Obviously, this can be extremely frustrating.

I agree that disabling newline-mark is not ideal. In fact, a big reason I use whitespace-mode is for the additional markup, including but not limited to newline-mark (for example, I also use space-mark). However, I have tried disabling whitespace-mode entirely and found it helpful enough, so thanks for that.

I suspect that it's more than just newline-mark that is affecting cursor movements. And just thinking about it without digging into the source code, I think that the fix would involve highlight-indent-guides-mode accounting for the extra number of characters that are being inserted by whitespace-mode. If you've only been running with newline-mark, try enabling space-mark or tab-mark in addition and see if the problem becomes more pronounced.