1

I use emacs and evil. If I set a marker using 'evil-set-marker, scroll elsewhere in the file, and then execute 'evil-goto-mark or 'evil-goto-mark-line, the window will scroll back until the position I’ve jumped to is visible, but will not return it to the same screen position. For example, the line I started from may have been the 3rd line from the top of the window, but will not necessarily be that anymore.

Is there a library that will restore windows to the same screen position when I execute 'evil-goto-mark or 'evil-goto-mark-line? For an additional refinement, I would like this behaviour only if jumping to the marker involves scrolling.

From a similar question, it looks like what I want to happen is for evil to store (window-start) when making a marker, and then set it again (using 'set-window-start) when jumping to that marker. I will probably code this up now that I know this, but I would still like to know if there is a library that will handle it for me.

1 Answer 1

0

Save and restore the value of point in the window you're interested in.

  • Function window-point gives you the current value for a given window.
  • Function set-window-point sets the value for a given window.
3
  • I don’t believe this answers my question. point is the position of the cursor relative to the start of the file, not relative to the screen. If I run (set-window-start (get-buffer-window) (+ 20 (window-start))), for example, the screen position of the current line changes (it moves up towards the top of the screen), but point remains the same – therefore restoring it is not sufficient.
    – emdash
    Aug 20, 2022 at 18:11
  • To explain a bit further: say point is on the last line visible in my window. I save it (say its value is 19900), and then scroll down further into the file. If I call (set-window-point (get-buffer-window) 19900), point will be successfully restored to its previous value, but will now be on the first line visible in my window – I would like it instead to be on the last line, as that's the line it was on before I navigated away. When I jump back with 'evil-goto-mark, I would like the visible screen area to be the same as it was when I called 'evil-set-marker.
    – emdash
    Aug 20, 2022 at 18:26
  • 1
    In that case, do what you say in your question's last paragraph. That assumes that your window remains the same height. (There's no function set-window-end.)
    – Drew
    Aug 20, 2022 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.