5

I use Spacemacs, and for some time I've rebound C-v and M-v to spacemacs/scroll-half-page-down and spacemacs/scroll-half-page-up, respectively, to aid my understanding of the buffer as I move through it.

After a recent update, though, these functions seem to no longer be defined. How can I get them back, or something reasonably similar?

4 Answers 4

9

I actually managed to find the equivalent functions. They are

  • View-scroll-half-page-forward
  • View-scroll-half-page-backward

So, I've updated my dotfile's user-config section to contain

(global-set-key (kbd "C-v") 'View-scroll-half-page-forward)
(global-set-key (kbd "M-v") 'View-scroll-half-page-backward)

and this seems to work fine!

3
  • Didn't work for me, I got command-execute: Wrong type argument: commandp, View-scroll-half-page-forward Oct 18, 2018 at 15:28
  • 4
    @ShaneCreighton-Young You need to add (autoload 'View-scroll-half-page-forward "view") (autoload 'View-scroll-half-page-backward "view") to your init file. This will load the needed view library when you use those commands.
    – clemera
    Dec 11, 2018 at 15:54
  • @clemera That works! Thank you for your help. Dec 11, 2018 at 16:50
3

I personally recommend you to use a package named golden-ratio-scroll-screen. You can add melpa to your package-list if you have not.

(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))

and then M-x package-list-packages, search for golden-ratio-,

or go to https://github.com/jixiuf/golden-ratio-scroll-screen to get it.

It will do the following two things, which are to me excellent, maybe also what you want:

  1. Scroll half screen down or up, and
  2. highlight current line before or after scrolling.
2
  • wow this is an amazing little package :) I actually like this more than default behaviour of scroll-up and scroll-down Feb 22, 2017 at 12:04
  • Personally I like to highlight the bottom/top line shortly and after that the new position after the scroll, see my blog
    – clemera
    Mar 5, 2019 at 7:39
2

You can also write pretty simple elisp code to achieve this :-

(defun scroll-half-page-down ()
  "scroll down half the page"
  (interactive)
  (scroll-down (/ (window-body-height) 2)))

(defun scroll-half-page-up ()
  "scroll up half the page"
  (interactive)
  (scroll-up (/ (window-body-height) 2)))
0

I use

(defun advice/scroll-context (proc &rest r)
  (let ((next-screen-context-lines (/ (window-text-height) 2)))
    (apply proc r)))

(mapc
 (lambda (sym) (advice-add sym :around #'advice/scroll-context))
 '(scroll-up scroll-down image-scroll-up image-scroll-down))

in my emacs.el profile to achive this.

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.