lem icon indicating copy to clipboard operation
lem copied to clipboard

Add central screen scroll

Open Sasanidas opened this issue 2 years ago • 4 comments

Basically mimic the functionality of https://github.com/aspiers/smooth-scrolling/ , keeping the scroll always in the center of the screen

Sasanidas avatar Aug 20 '23 18:08 Sasanidas

I wrote almost the same extension at #1035 for vi-mode. It is called scrolloff in Vim world.

fukamachi avatar Sep 01 '23 09:09 fukamachi

Oh interesting, can this be ported to be used outside of vi-mode?

Sasanidas avatar Sep 07 '23 17:09 Sasanidas

Sure. I'm happy if Lem gets more convenience.

fukamachi avatar Sep 08 '23 06:09 fukamachi

It looks like the current implementation of scrolloff is very computational intensive and should be revisited. I noticed some lags when using vi-mode, which I did not notice in emacs-mode. I did the following test, using cl-flamegraph and got the following result:

setting scrolloff to 0 and positioning the cursor on the last line of the screen. The screen should show at least 50 lines, so that no scrolling is done during the execution of foo. line-wrapping is on. foo is called using M-:.

(defun foo (path)
  (flamegraph:save-flame-graph (path)
    (dotimes (_ 50)
      (dotimes (_ 50)
        (lem:call-command (lem:find-command "vi-previous-line") nil))
      (dotimes (_ 50)
        (lem:call-command (lem:find-command "vi-next-line") nil)))))

The test basically moves the cursor up 50 lines and then down 50 times. This is repeated 50 times. The whole process is profiled in sbcl using sb-sprof (needs to added to lem.asd). The flame graph looks like this:

1

70% of the time is spent in adjust-window-scroll, which handles the vi-mode scrolloff option, even though no scrolling appears. Computing the window-cursor-y is very expensive when line-wrapping is on and is done after each and every command.

mychris avatar Jan 07 '24 16:01 mychris