diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-04-02 21:43:04 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-04-02 21:48:04 -0400 |
| commit | 0b9f1e5d460202c33f165274d6e244c6c891e922 (patch) | |
| tree | 609e7727b15bf3b4e01ebc63d96796c9e26817cc | |
| parent | Add et-insert-elisp-template function to emacs config (diff) | |
| download | dotfiles-0b9f1e5d460202c33f165274d6e244c6c891e922.zip | |
Add scroll up and down half page key mappings to emacs
| -rw-r--r-- | .emacs.d/init.el | 1 | ||||
| -rw-r--r-- | .emacs.d/modules/et-navigation.el | 39 |
2 files changed, 40 insertions, 0 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el index b59b82c..e728f6e 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -23,6 +23,7 @@ (require 'et-appearance) (require 'et-vc) (require 'et-completion) +(require 'et-navigation) (require 'et-format) (require 'et-lsp) diff --git a/.emacs.d/modules/et-navigation.el b/.emacs.d/modules/et-navigation.el new file mode 100644 index 0000000..e434ade --- /dev/null +++ b/.emacs.d/modules/et-navigation.el @@ -0,0 +1,39 @@ +;;; et-navigation.el --- Emacs navigation utiltiies -*- lexical-binding: t; -*- +;; +;;; Commentary: +;; +;; This module overrides the "scroll up page" and "scroll down page" +;; default Emacs key mappings to only scroll up and down half a page. +;; +;;; Code: + +(global-set-key (kbd "C-v") + 'et-scroll-down-half-page) + +(global-set-key (kbd "M-v") + 'et-scroll-up-half-page) + +(defun et-scroll-down-half-page () + "Scroll down half a page while keeping the cursor centered." + (interactive) + (let ((ln (line-number-at-pos)) + (lmax (line-number-at-pos (point-max)))) + (cond ((= ln 1) (move-to-window-line nil)) + ((= ln lmax) (recenter (window-end))) + (t (progn + (move-to-window-line -1) + (recenter)))))) + +(defun et-scroll-up-half-page () + "Scroll up half a page while keeping the cursor centered." + (interactive) + (let ((ln (line-number-at-pos)) + (lmax (line-number-at-pos (point-max)))) + (cond ((= ln 1) nil) + ((= ln lmax) (move-to-window-line nil)) + (t (progn + (move-to-window-line 0) + (recenter)))))) + +(provide 'et-navigation) +;;; et-navigation.el ends here |