aboutsummaryrefslogtreecommitdiffstats
path: root/.emacs.d/modules/et-navigation.el
blob: e434adefa160cd242cd976d240fc973dec0fb2c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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