reddit / emacs
Looking for better alternative to auto-hscroll-mode set to current-line
pa2ees · 2022-08-04 22:37
I like the idea of only horizontally scrolling the current line, ie. `(setq auto-hscroll-mode 'current-line)`, but it has a few quirks.
First, if you scroll to the end of a long line, and then move to the next line, it will horizontally scroll that line, even if it easily fits on the screen. This pushes most of the short line off the left edge of the screen.
Second, It would be nice for point to stay as far right as possible (at the left edge of the right margin) when horizontally scrolling. This would make it so point would stay a few columns from the right edge the entire time the line is horizontally scrolled. So even when moving point left, the line under point would horizontally scroll to the right until the line is no longer horizontally scrolling, then point would actually start moving toward the left edge of the screen.
Does anyone know of such a thing? or can anyone help point me in the right direction to create a minor mode that would do this?
https://i.redd.it/b5hfog093bh91.gif
https://i.redd.it/2dcu5g093bh91.gif
eli-zaretskii · 2022-08-05 19:05
> First, if you scroll to the end of a long line, and then move to the next line, it will horizontally scroll that line, even if it easily fits on the screen. This pushes most of the short line off the left edge of the screen.
Did you try setting `track-eol` non-nil?
> Second, It would be nice for point to stay as far right as possible
Did you try to set `hscroll-margin` and `hscroll-step` to a small value, like 1?
pa2ees · 2022-08-05 20:36
I tried setting `track-eol` to `t`, but I like the behavior better when set to `nil`. When set to `t`, emacs is even more likely to scroll short lines off the left side of the screen, and that's what I'm trying to avoid.
`hscroll-margin` is set to 5 (I like having point stay a little away from the right side), and `hscroll-step` is set to 1, so it only scrolls one character at a time.
Excellent suggestions, but it's not the behavior I'm looking for.
eli-zaretskii · 2022-08-06 15:41
TBH, I didn't really understand the behavior you are looking for.
pa2ees · 2022-08-11 14:16
Sorry I wasn't very clear. My biggest problem is when I'm on a line (ex. line number 50) that's hscrolled (because it's really long) and then I move point to the line below (line number 51), and that line is short enough that it doesn't need to be hscrolled, it still hscrolls most of that line (line number 51) off the left side of the screen even though it doesn't need to.
It would be nice if the hscrolling functionality could detect that a line is short enough to fit completely on the screen, and if that's the case, not hscroll at all.
It looks like the hscrolling is done in `dispnew.c`, which makes it a bit more difficult for me to change its behavior. I'm comfortable modifying c, but understanding the paradigms in the code base is challenging. If you have some tips on how to understand what is going on in the c code, or can point me to some good documentation, that would be great.
eli-zaretskii · 2022-08-12 07:20
> and then I move point to the line below (line number 51), and that line is short enough that it doesn't need to be hscrolled, it still hscrolls most of that line (line number 51) off the left side of the screen even though it doesn't need to.
I cannot reproduce this: on my system the short line is not hscrolled.
pa2ees · 2022-08-12 16:02
I have seen this on 27.1, 27.2, and 28.1. Also I see it when I run emacs without configs using `emacs -q`
I have some screen captures that are saved as animated gifs. I added them to my original post because I couldn't see how to add them to this comment.
eli-zaretskii · 2022-08-12 19:13
I see what you describe in the GIFs, but not on my system. On my system, the short lines don't get hscrolled.
Does this happen for you in `emacs -Q`? If not, maybe some of your customizations cause that?
pa2ees · 2022-08-12 19:31
It does still happen with `emacs -Q`
eli-zaretskii · 2022-08-13 15:18
Then I'm stumped, sorry.
pa2ees · 2022-08-18 04:14
I think the key to this issue is `hscroll-step`
When I set `hscroll-step` to `0` (which is default) then I don't get the weird behavior. but when I set it to something like `1` or `3`, then I do get the weird behavior above.
This behavior also happens when `auto-scroll-mode` is not `current-line`, but it's less noticeable.