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
|
70
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
0
|
23
|
70
|
24 ;;; Synched up with: FSF 19.30.
|
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'."
|
70
|
37 (interactive "_p")
|
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)))
|
|
48 (forward-char -1)
|
70
|
49 (let (result (end (point)))
|
|
50 ;; If we find a match that ends where we started searching,
|
|
51 ;; look for another one.
|
|
52 (while (and (setq result (re-search-backward page-delimiter nil t))
|
|
53 (= (match-end 0) end))
|
|
54 ;; Just search again.
|
|
55 )
|
|
56 (if result
|
|
57 ;; We found one--move to the end of it.
|
|
58 (goto-char (match-end 0))
|
|
59 ;; We found nothing--go to beg of buffer.
|
|
60 (goto-char (point-min))))
|
0
|
61 (setq count (1+ count))))
|
|
62
|
|
63 (defun backward-page (&optional count)
|
|
64 "Move backward to page boundary. With arg, repeat, or go fwd if negative.
|
|
65 A page boundary is any line whose beginning matches the regexp
|
|
66 `page-delimiter'."
|
70
|
67 (interactive "p")
|
0
|
68 (or count (setq count 1))
|
|
69 (forward-page (- count)))
|
|
70
|
|
71 (defun mark-page (&optional arg)
|
|
72 "Put mark at end of page, point at beginning.
|
|
73 A numeric arg specifies to move forward or backward by that many pages,
|
|
74 thus marking a page other than the one point was originally in."
|
|
75 (interactive "P")
|
|
76 (setq arg (if arg (prefix-numeric-value arg) 0))
|
|
77 (if (> arg 0)
|
|
78 (forward-page arg)
|
|
79 (if (< arg 0)
|
|
80 (forward-page (1- arg))))
|
|
81 (forward-page)
|
|
82 (push-mark nil t t)
|
|
83 (forward-page -1))
|
|
84
|
|
85 (defun narrow-to-page (&optional arg)
|
|
86 "Make text outside current page invisible.
|
|
87 A numeric arg specifies to move forward or backward by that many pages,
|
|
88 thus showing a page other than the one point was originally in."
|
|
89 (interactive "P")
|
|
90 (setq arg (if arg (prefix-numeric-value arg) 0))
|
|
91 (save-excursion
|
|
92 (widen)
|
|
93 (if (> arg 0)
|
|
94 (forward-page arg)
|
|
95 (if (< arg 0)
|
|
96 (forward-page (1- arg))))
|
|
97 ;; Find the end of the page.
|
|
98 (forward-page)
|
|
99 ;; If we stopped due to end of buffer, stay there.
|
|
100 ;; If we stopped after a page delimiter, put end of restriction
|
|
101 ;; at the beginning of that line.
|
|
102 (if (save-excursion
|
|
103 (goto-char (match-beginning 0)) ; was (beginning-of-line)
|
|
104 (looking-at page-delimiter))
|
|
105 (beginning-of-line))
|
|
106 (narrow-to-region (point)
|
|
107 (progn
|
|
108 ;; Find the top of the page.
|
|
109 (forward-page -1)
|
|
110 ;; If we found beginning of buffer, stay there.
|
|
111 ;; If extra text follows page delimiter on same line,
|
|
112 ;; include it.
|
|
113 ;; Otherwise, show text starting with following line.
|
|
114 (if (and (eolp) (not (bobp)))
|
|
115 (forward-line 1))
|
|
116 (point)))))
|
|
117
|
|
118 (defun count-lines-page ()
|
|
119 "Report number of lines on current page, and how many are before or after point."
|
70
|
120 (interactive "_")
|
0
|
121 (save-excursion
|
|
122 (let ((opoint (point)) beg end
|
|
123 total before after)
|
|
124 (forward-page)
|
|
125 (beginning-of-line)
|
|
126 (or (looking-at page-delimiter)
|
|
127 (end-of-line))
|
|
128 (setq end (point))
|
|
129 (backward-page)
|
|
130 (setq beg (point))
|
|
131 (setq total (count-lines beg end)
|
|
132 before (count-lines beg opoint)
|
|
133 after (count-lines opoint end))
|
|
134 (message "Page has %d lines (%d + %d)" total before after))))
|
|
135
|
|
136 (defun what-page ()
|
|
137 "Print page and line number of point."
|
70
|
138 (interactive "_")
|
0
|
139 (save-restriction
|
|
140 (widen)
|
|
141 (save-excursion
|
|
142 (beginning-of-line)
|
|
143 (let ((count 1)
|
|
144 (opoint (point)))
|
|
145 (goto-char 1)
|
|
146 (while (re-search-forward page-delimiter opoint t)
|
|
147 (setq count (1+ count)))
|
|
148 (message "Page %d, line %d"
|
|
149 count
|
|
150 (1+ (count-lines (point) opoint)))))))
|
|
151
|
|
152 ;;; Place `provide' at end of file.
|
|
153 (provide 'page)
|
|
154
|
|
155 ;;; page.el ends here
|