Scrolling half a page

Hi all. I am trying to figure out how to scroll half a page. I have limited experience with CL, so I am trying to use some elisp knowledge (but failing).

Here is what I have so far:

(define-configuration buffer
		((override-map (let ((map (make-keymap "override-map")))
										 (define-key map
												 "C-v" (lambda () (scroll-distance 10)))))))

Hello @joshcho welcome to our community!

I would start by first defining a little command to scroll half a page:

We could start by looking at the command scroll-page-down

(define-command scroll-page-down ()
  "Scroll down by one page height."
  (pflet ((scroll-page-down ()
            (ps:chain window (scroll-by 0 (* (ps:lisp (page-scroll-ratio (current-buffer)))
                                             (ps:@ window inner-height))))))
    (scroll-page-down)))

If we want to make it half the height of a page we can multiply by 0.5

(define-command-global scroll-half-page-down ()
  "Scroll down by half a page height."
  (pflet ((scroll-page-down ()
            (ps:chain window (scroll-by 0 (* (ps:lisp (page-scroll-ratio (current-buffer)))
                                             ;; calculate half the height
                                             (* 0.5 (ps:@ window inner-height)))))))
    (scroll-page-down)))

we make it a global command so that it can be accessible outside of any mode.

Now, all we have to do is bind to our override-map:

(define-configuration buffer
    ((override-map (let ((map (make-keymap "my-override-map")))
                     (define-key map
                       "M-n" 'scroll-half-page-down)
                     map))))

et voila! I hope that helps :slight_smile:

2 Likes

Wow! This is incredibly helpful, thank you :slight_smile:

Is there a way to look up documentation within nyxt? I tried C-h f but it’s not all too helpful. (For instance, I am trying to look up what pflet does, but it’s hard to find the docs).

Hm, things like pflet still would have to be looked up in the source code itself. So far we only have documentation on commands, variables, classes, slots, modes.

We still would need to add macros and functions to our documentation. We’ll get to it :slight_smile:

1 Like

To just quickly give a hint about pflet, it is like the regular lisp flet but with support for parenscript.