Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
marvel
GitHub Repository: marvel/qnf
Path: blob/master/elisp/pager.el
987 views
1
;;; pager.el --- windows-scroll commands
2
;;; Version 2.0 - 97-10-06
3
;;; Copyright (C) 1992-1997 Mikael Sj�din ([email protected])
4
;;;
5
;;; Author: Mikael Sj�din -- [email protected]
6
;;;
7
;;; This file is NOT part of GNU Emacs.
8
;;; You may however redistribute it and/or modify it under the terms of the GNU
9
;;; General Public License as published by the Free Software Foundation; either
10
;;; version 2, or (at your option) any later version.
11
;;;
12
;;; pager.el is distributed in the hope that it will be useful,
13
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
;;; GNU General Public License for more details.
16
17
;;; ----------------------------------------------------------------------
18
;;; Description:
19
;;;
20
;;; pager.el defines alternative commands to the Emacs builtins: scroll-down
21
;;; and scroll-up. It also contains commands to scroll the screen one row at
22
;;; the time.
23
;;;
24
;;; The Emacs builtins for scrolling are worthless! The commands in pager.el
25
;;; works the way the builtins should have done from the beginning. For
26
;;; instance, doing a pg-up followed by a pg-down (when using pager.el) will
27
;;; return point to the original place.
28
;;;
29
;;; This file has been tested under Emacs 19.34 and 20.2 but I belive it should
30
;;; work on most Emacs versions and Emacs derivatives.
31
;;;
32
;;; This file can be obtained from http://www.docs.uu.se/~mic/emacs.html
33
34
;;; ----------------------------------------------------------------------
35
;;; Installation:
36
;;;
37
;;; o Place this file in a directory in your load-path.
38
;;; o Put the following in your .emacs file:
39
;;; (require 'pager)
40
;;; (global-set-key "\C-v" 'pager-page-down)
41
;;; (global-set-key [next] 'pager-page-down)
42
;;; (global-set-key "\ev" 'pager-page-up)
43
;;; (global-set-key [prior] 'pager-page-up)
44
;;; (global-set-key '[M-up] 'pager-row-up)
45
;;; (global-set-key '[M-kp-8] 'pager-row-up)
46
;;; (global-set-key '[M-down] 'pager-row-down)
47
;;; (global-set-key '[M-kp-2] 'pager-row-down)
48
;;; o Restart your Emacs.
49
;;; o pager.el is now installed. Use the normal keys to scroll a full page and
50
;;; M-up resp. M-down to scroll just one row up or down.
51
52
;;; ----------------------------------------------------------------------
53
;;; Versions:
54
;;; 2.0 Renamed interface functions (kept old-ones as aliases)
55
;;; Complete reimplementation, old version where not working well in Emacs
56
;;; 20.
57
;;;
58
;;; 1.0 Initial Release
59
60
;;; ======================================================================
61
;;; Internal variables
62
63
(defvar pager-temporary-goal-column 0
64
"Similat to temporary-goal-column byt used by the pager.el functions")
65
;(make-variable-buffer-local 'pager-temporary-goal-column)
66
67
(defconst pager-keep-column-commands
68
'(pager-row-down pager-row-up row-dn row-up
69
pager-page-down pager-page-up pg-dn pg-up)
70
"Commands which when called without any other intervening command should
71
keep the `pager-temporary-goal-column'")
72
73
;;; ======================================================================
74
;;; Commands
75
76
;;; pager 1.0 compatibility
77
(defalias 'pg-dn 'pager-page-down)
78
(defalias 'pg-up 'pager-page-up)
79
(defalias 'row-dn 'pager-row-down)
80
(defalias 'row-up 'pager-row-up)
81
82
;; ----------------------------------------------------------------------
83
84
(defun pager-page-down ()
85
"Like scroll-up, but moves a fixed amount of lines (fixed relative the
86
`window-height') so that pager-page-up moves back to the same line."
87
(interactive)
88
(if (not (pos-visible-in-window-p (point-max)))
89
(pager-scroll-screen (- (1- (window-height))
90
next-screen-context-lines))))
91
92
(defun pager-page-up ()
93
"Like scroll-down, but moves a fixed amount of lines (fixed relative the
94
`window-height') so that pager-page-down moves back to the same line."
95
(interactive)
96
(if (not (pos-visible-in-window-p (point-min)))
97
(pager-scroll-screen (- next-screen-context-lines
98
(1- (window-height))))))
99
100
;; ------------------------------
101
102
(defun pager-scroll-screen (lines)
103
"Scroll screen LINES, but keep the cursors position on screen."
104
(if (not (memq last-command pager-keep-column-commands))
105
(setq pager-temporary-goal-column (current-column)))
106
(save-excursion
107
(goto-char (window-start))
108
(forward-line lines)
109
(set-window-start (selected-window) (point)))
110
(forward-line lines)
111
(move-to-column pager-temporary-goal-column))
112
113
114
;; ----------------------------------------------------------------------
115
116
(defun pager-row-up ()
117
"Move point to previous line while scrolling screen down one line.
118
The effect is that the cursor stays in the same position on the screen."
119
(interactive)
120
(if (not (memq last-command pager-keep-column-commands))
121
(setq pager-temporary-goal-column (current-column)))
122
(if (not (pos-visible-in-window-p (point-min)))
123
(scroll-down 1))
124
(forward-line -1)
125
(move-to-column pager-temporary-goal-column)
126
)
127
128
(defun pager-row-down ()
129
"Move point to next line while scrolling screen up one line.
130
The effect is that the cursor stays in the same position on the screen."
131
(interactive)
132
(if (not (memq last-command pager-keep-column-commands))
133
(setq pager-temporary-goal-column (current-column)))
134
(if (not (pos-visible-in-window-p (point-max)))
135
(scroll-up 1))
136
(if (<= (point) (point-max))
137
(forward-line 1))
138
(move-to-column pager-temporary-goal-column)
139
)
140
141
;; ----------------------------------------------------------------------
142
143
(provide 'pager)
144
145
146
147