Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict with whitespace.el #107

Open
johannes-mueller opened this issue Dec 27, 2020 · 5 comments
Open

Conflict with whitespace.el #107

johannes-mueller opened this issue Dec 27, 2020 · 5 comments

Comments

@johannes-mueller
Copy link

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)
  1. Open a file with with .py name extension and paste the following content into it
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
Copy link

jimeh commented May 9, 2021

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
Copy link

jimeh commented May 9, 2021

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

  • highlight-indent-guides-mode is enabled
  • highlight-indent-guides-method is set to 'character or 'bitmap
  • whitespace-mode is enabled
  • cursor is placed at the beginning of a line (column 0)
  • most recent cursor movement command was not a up/down cursor movement command

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.

jimeh added a commit to jimeh/.emacs.d that referenced this issue Jun 17, 2022
As I'm no longer using whitespace-mode in prog-mode derived modes, the
cursor movement bug affecting highlight-indent-guides when
whitespace-mode is enabled is no longer an issue for me.

Further details about the highlight-indent-guides conflict with
whitespace-mode is available in this issue:
DarthFennec/highlight-indent-guides#107
@chenl
Copy link

chenl commented Feb 21, 2023

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
Copy link

jimeh commented Feb 23, 2023

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants