0
|
1 ;;; page.el --- page motion commands for emacs.
|
|
2
|
|
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Maintainer: FSF
|
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
72
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
22 ;; 02111-1307, USA.
|
0
|
23
|
72
|
24 ;;; Synched up with: FSF 19.34.
|
0
|
25
|
|
26 ;;; Commentary:
|
|
27
|
|
28 ;; This code provides the page-oriented movement and selection commands
|
|
29 ;; documented in the XEmacs Reference Manual.
|
|
30
|
|
31 ;;; Code:
|
|
32
|
|
33 (defun forward-page (&optional count)
|
|
34 "Move forward to page boundary. With arg, repeat, or go back if negative.
|
|
35 A page boundary is any line whose beginning matches the regexp
|
|
36 `page-delimiter'."
|
72
|
37 (interactive "_p") ; XEmacs
|
0
|
38 (or count (setq count 1))
|
|
39 (while (and (> count 0) (not (eobp)))
|
|
40 ;; In case the page-delimiter matches the null string,
|
|
41 ;; don't find a match without moving.
|
|
42 (if (bolp) (forward-char 1))
|
|
43 (if (re-search-forward page-delimiter nil t)
|
|
44 nil
|
|
45 (goto-char (point-max)))
|
|
46 (setq count (1- count)))
|
|
47 (while (and (< count 0) (not (bobp)))
|
72
|
48 ;; In case the page-delimiter matches the null string,
|
|
49 ;; don't find a match without moving.
|
|
50 (and (save-excursion (re-search-backward page-delimiter nil t))
|
|
51 (= (match-end 0) (point))
|
|
52 (goto-char (match-beginning 0)))
|
0
|
53 (forward-char -1)
|
72
|
54 (if (re-search-backward page-delimiter nil t)
|
|
55 ;; We found one--move to the end of it.
|
|
56 (goto-char (match-end 0))
|
|
57 ;; We found nothing--go to beg of buffer.
|
|
58 (goto-char (point-min)))
|
0
|
59 (setq count (1+ count))))
|
|
60
|
|
61 (defun backward-page (&optional count)
|
|
62 "Move backward to page boundary. With arg, repeat, or go fwd if negative.
|
|
63 A page boundary is any line whose beginning matches the regexp
|
|
64 `page-delimiter'."
|
72
|
65 (interactive "_p") ; XEmacs
|
0
|
66 (or count (setq count 1))
|
|
67 (forward-page (- count)))
|
|
68
|
|
69 (defun mark-page (&optional arg)
|
|
70 "Put mark at end of page, point at beginning.
|
|
71 A numeric arg specifies to move forward or backward by that many pages,
|
|
72 thus marking a page other than the one point was originally in."
|
|
73 (interactive "P")
|
|
74 (setq arg (if arg (prefix-numeric-value arg) 0))
|
|
75 (if (> arg 0)
|
|
76 (forward-page arg)
|
|
77 (if (< arg 0)
|
|
78 (forward-page (1- arg))))
|
|
79 (forward-page)
|
|
80 (push-mark nil t t)
|
|
81 (forward-page -1))
|
|
82
|
|
83 (defun narrow-to-page (&optional arg)
|
|
84 "Make text outside current page invisible.
|
|
85 A numeric arg specifies to move forward or backward by that many pages,
|
|
86 thus showing a page other than the one point was originally in."
|
|
87 (interactive "P")
|
|
88 (setq arg (if arg (prefix-numeric-value arg) 0))
|
|
89 (save-excursion
|
|
90 (widen)
|
|
91 (if (> arg 0)
|
|
92 (forward-page arg)
|
|
93 (if (< arg 0)
|
|
94 (forward-page (1- arg))))
|
|
95 ;; Find the end of the page.
|
|
96 (forward-page)
|
|
97 ;; If we stopped due to end of buffer, stay there.
|
|
98 ;; If we stopped after a page delimiter, put end of restriction
|
|
99 ;; at the beginning of that line.
|
|
100 (if (save-excursion
|
|
101 (goto-char (match-beginning 0)) ; was (beginning-of-line)
|
|
102 (looking-at page-delimiter))
|
|
103 (beginning-of-line))
|
|
104 (narrow-to-region (point)
|
|
105 (progn
|
|
106 ;; Find the top of the page.
|
|
107 (forward-page -1)
|
|
108 ;; If we found beginning of buffer, stay there.
|
|
109 ;; If extra text follows page delimiter on same line,
|
|
110 ;; include it.
|
|
111 ;; Otherwise, show text starting with following line.
|
|
112 (if (and (eolp) (not (bobp)))
|
|
113 (forward-line 1))
|
|
114 (point)))))
|
72
|
115 (put 'narrow-to-page 'disabled t)
|
0
|
116
|
|
117 (defun count-lines-page ()
|
|
118 "Report number of lines on current page, and how many are before or after point."
|
72
|
119 (interactive "_") ; XEmacs
|
0
|
120 (save-excursion
|
|
121 (let ((opoint (point)) beg end
|
|
122 total before after)
|
|
123 (forward-page)
|
|
124 (beginning-of-line)
|
|
125 (or (looking-at page-delimiter)
|
|
126 (end-of-line))
|
|
127 (setq end (point))
|
|
128 (backward-page)
|
|
129 (setq beg (point))
|
|
130 (setq total (count-lines beg end)
|
|
131 before (count-lines beg opoint)
|
|
132 after (count-lines opoint end))
|
|
133 (message "Page has %d lines (%d + %d)" total before after))))
|
|
134
|
|
135 (defun what-page ()
|
|
136 "Print page and line number of point."
|
72
|
137 (interactive "_") ; XEmacs
|
0
|
138 (save-restriction
|
|
139 (widen)
|
|
140 (save-excursion
|
|
141 (beginning-of-line)
|
|
142 (let ((count 1)
|
|
143 (opoint (point)))
|
|
144 (goto-char 1)
|
|
145 (while (re-search-forward page-delimiter opoint t)
|
|
146 (setq count (1+ count)))
|
|
147 (message "Page %d, line %d"
|
|
148 count
|
|
149 (1+ (count-lines (point) opoint)))))))
|
|
150
|
|
151 ;;; Place `provide' at end of file.
|
|
152 (provide 'page)
|
|
153
|
|
154 ;;; page.el ends here
|