;; This file: http://user.it.uu.se/~embe8573/conf/emacs-init/scroll.el (require 'cl-macs) ;; civilized scrolling - one line at a time (setq scroll-conservatively 10000) (setq auto-window-vscroll nil) ;; scroll the current window (defun scroll-up-1 () (interactive) (scroll-down 1) ) (defun scroll-down-1 () (interactive) (scroll-up 1) ) ;; automatic scrolling (defun start-automatic-scroll-down () (interactive) (let ((win)) (cl-loop do (progn (setq win (window-end)) (scroll-down-1) (sleep-for 1) ; put speed here in seconds (redisplay) ) until (= win (window-end)) ))) ;; (start-automatic-scroll-down) ;; ^ test here ;; scroll up/down the other window (defun scroll-up-other-window () (interactive) (scroll-other-window-down 1) ) (defun scroll-down-other-window () (interactive) (scroll-other-window 1) ) ;; scroll one chunk (pane) of text (defun get-window-lines () (let*((edges (window-inside-edges)) (top (nth 1 edges)) (bottom (nth 3 edges)) (lines (- bottom top)) ) (if (member major-mode '(Buffer-menu-mode package-menu-mode w3m-mode)) (1- lines) lines) )) (defun scroll-up-pane () (interactive) (scroll-down (get-window-lines) )) (defun scroll-down-pane () (interactive) (scroll-up (get-window-lines)) ) ;; scroll horizontally (put 'scroll-left 'disabled nil) (put 'scroll-right 'disabled nil) (setq hscroll-margin 1) (setq hscroll-step 1) (defun scroll-left-1 () (interactive) (scroll-right 1 0) ) ; yes, "the opposite" here (defun scroll-right-1 () (interactive) (scroll-left 1 0) ) ; ditto (defun scroll-left-home () (interactive) (while (> (scroll-left-1) 0)) ) ;; functions to assign certain keys those functions in many modes (defun set-pane-scroll-keys (map) "Set MAP keys for vertical scrolling in panes." (define-key map "I" #'scroll-up-pane) (define-key map "K" #'scroll-down-pane) ) (defun set-scroll-keys (map &optional horizontally) "Set MAP keys for scrolling, vertically and optionally HORIZONTALLY. Also invoke `set-pane-scroll-keys'." (when horizontally (define-key map "j" #'scroll-left-1) (define-key map "l" #'scroll-right-1) ) (define-key map "i" #'scroll-up-1) (define-key map "k" #'scroll-down-1) (set-pane-scroll-keys map) ) (defun set-vertical-keys (map) "Set MAP keys for moving point vertically." (define-key map "i" #'previous-line) (define-key map "k" #'next-line) ) (provide 'scroll)