;;; pager.el --- windows-scroll commands ;;; Version 1.0 - 96-08-16 ;;; Copyright (C) 1992-1996 Mikael Sjödin (mic@docs.uu.se) ;;; ;;; Author: Mikael Sjödin -- mic@docs.uu.se ;;; ;;; This file is NOT part of GNU Emacs. ;;; You may however redistribute it and/or modify it under the terms of the GNU ;;; General Public License as published by the Free Software Foundation; either ;;; version 2, or (at your option) any later version. ;;; ;;; pager.el is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ---------------------------------------------------------------------- ;;; Description: ;;; ;;; pager.el defines alternative commands to the Emacs builtins: scroll-down ;;; and scroll-up. It also contains commands to scroll the screen one row at ;;; the time. ;;; ;;; The Emacs builtins for scrolling are worthless! The commands in pager.el ;;; works the way the builtins should have done from the beginning. For ;;; instance, doing a pg-up followed by a pg-down (when using pager.el) will ;;; return point to the original place. ;;; ;;; This file contains even more functions than the ones in the installation ;;; instructions below. Have a peek in this file to see what functions are ;;; available and install them in your Emacs. ;;; ;;; I've used this file for years now and Have never had any problems neither ;;; under Emacs 18, 19 or Lucid Emacs. How ever I can not make any changes ;;; needed for it to run on other systems that Emacs 19. Sorry, all you ;;; Emacs-clone users... ;;; ;;; This file can be obtained from http://www.docs.uu.se/~mic/emacs.html ;;; ---------------------------------------------------------------------- ;;; Installation: ;;; ;;; o Place this file in a directory in your 'load-path. ;;; o Put the following in your .emacs file: ;;; (require 'pager) ;;; (global-set-key "\C-v" 'pg-dn) ;;; (global-set-key [next] 'pg-dn) ;;; (global-set-key "\ev" 'pg-up) ;;; (global-set-key [prior] 'pg-up) ;;; (global-set-key '[M-up] 'row-up) ;;; (global-set-key '[M-kp-8] 'row-up) ;;; (global-set-key '[M-down] 'row-dn) ;;; (global-set-key '[M-kp-2] 'row-dn) ;;; o Restart your Emacs. ;;; o pager.el is now installed. Use the normal keys to scroll a full page and ;;; M-up resp. M-down to scroll just one row up or down. ;;; ====================================================================== ;;; Declarations ;; This is 'cause I couldn't find out how to use the 'temporary-goal-column ;; used by emacs. It should behave just the same (setq pager-temporary-goal-column 0) (make-variable-buffer-local 'pager-temporary-goal-column) ;;; ====================================================================== ;;; Commands (defun pg-dn () "Like scroll-up, but moves a fixed amount of lines (fixed relative the window-height) so that pg-dn moves back to the same line." (interactive) (if (not (pos-visible-in-window-p (point-max))) (scroll-screen (- (1- (window-height)) next-screen-context-lines)))) (defun pg-up () "Like scroll-down, but moves a fixed amount of lines (fixed relative the window-height) so that pg-up moves back to the same line." (interactive) (if (not (pos-visible-in-window-p (point-min))) (scroll-screen (- next-screen-context-lines (1- (window-height)))))) (defun row-dn () "Scrolls the screen up, one line but widthout moving the cursor." (interactive) (if (not (pos-visible-in-window-p (point-max))) (progn (move-screen 1) (next-line 1)))) (defun row-up () "Scrolls the screen down, one line but widthout moving the cursor." (interactive) (if (not (pos-visible-in-window-p (point-min))) (progn (move-screen -1) (previous-line 1)))) (defun pg-dn-other-window () "Like pg-dn, but operaes on the 'other window'" (interactive) (other-window 1) (pg-dn) (other-window -1)) (defun pg-up-other-window () "Like pg-up, but operaes on the 'other window'" (interactive) (other-window 1) (pg-up) (other-window -1)) (defun row-dn-other-window () "Like row-dn, but operaes on the 'other window'" (interactive) (other-window 1) (row-dn) (other-window -1)) (defun row-up-other-window () "Like row-up, but operaes on the 'other window'" (interactive) (other-window 1) (row-up) (other-window -1)) ;;; ---------------------------------------------------------------------- ;;; Functionality (defun scroll-screen (lines) "Scroll screen LINES, but keep the cursors position on screen. (Requres that the variable 'pager-temporary-goal-column' is an integer.)" (if (not (memq last-command '(pg-up pg-dn row-up row-dn))) (setq pager-temporary-goal-column (current-column))) (save-excursion (goto-char (window-start)) (forward-line lines) (set-window-start (selected-window) (point))) (forward-line lines) (move-to-column pager-temporary-goal-column)) (defun move-screen (lines) "Scroll screen LINES, and keep the cursors position in text. (Requres that the variable 'pager-temporary-goal-column' is an integer.)" (if (not (memq last-command '(pg-up pg-dn row-up row-dn))) (setq pager-temporary-goal-column (current-column))) (save-excursion (goto-char (window-start)) (forward-line lines) (set-window-start (selected-window) (point))) (move-to-column pager-temporary-goal-column)) (provide 'pager)