1 ;;; page.el --- page motion commands for emacs.
3 ;; Copyright (C) 1985, 1997 Free Software Foundation, Inc.
6 ;; Keywords: extensions, dumped
8 ;; This file is part of XEmacs.
10 ;; XEmacs is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; XEmacs is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;;; Synched up with: FSF 19.34.
29 ;; This file is dumped with XEmacs.
31 ;; This code provides the page-oriented movement and selection commands
32 ;; documented in the XEmacs Reference Manual.
36 (defun forward-page (&optional count)
37 "Move forward to page boundary. With arg, repeat, or go back if negative.
38 A page boundary is any line whose beginning matches the regexp
40 (interactive "_p") ; XEmacs
41 (or count (setq count 1))
42 (while (and (> count 0) (not (eobp)))
43 ;; In case the page-delimiter matches the null string,
44 ;; don't find a match without moving.
45 (if (bolp) (forward-char 1))
46 (if (re-search-forward page-delimiter nil t)
48 (goto-char (point-max)))
49 (setq count (1- count)))
50 (while (and (< count 0) (not (bobp)))
51 ;; In case the page-delimiter matches the null string,
52 ;; don't find a match without moving.
53 (and (save-excursion (re-search-backward page-delimiter nil t))
54 (= (match-end 0) (point))
55 (goto-char (match-beginning 0)))
57 (if (re-search-backward page-delimiter nil t)
58 ;; We found one--move to the end of it.
59 (goto-char (match-end 0))
60 ;; We found nothing--go to beg of buffer.
61 (goto-char (point-min)))
62 (setq count (1+ count))))
64 (defun backward-page (&optional count)
65 "Move backward to page boundary. With arg, repeat, or go fwd if negative.
66 A page boundary is any line whose beginning matches the regexp
68 (interactive "_p") ; XEmacs
69 (or count (setq count 1))
70 (forward-page (- count)))
72 (defun mark-page (&optional arg)
73 "Put mark at end of page, point at beginning.
74 A numeric arg specifies to move forward or backward by that many pages,
75 thus marking a page other than the one point was originally in."
77 (setq arg (if arg (prefix-numeric-value arg) 0))
81 (forward-page (1- arg))))
86 (defun narrow-to-page (&optional arg)
87 "Make text outside current page invisible.
88 A numeric arg specifies to move forward or backward by that many pages,
89 thus showing a page other than the one point was originally in."
91 (setq arg (if arg (prefix-numeric-value arg) 0))
97 (forward-page (1- arg))))
98 ;; Find the end of the page.
100 ;; If we stopped due to end of buffer, stay there.
101 ;; If we stopped after a page delimiter, put end of restriction
102 ;; at the beginning of that line.
104 (goto-char (match-beginning 0)) ; was (beginning-of-line)
105 (looking-at page-delimiter))
107 (narrow-to-region (point)
109 ;; Find the top of the page.
111 ;; If we found beginning of buffer, stay there.
112 ;; If extra text follows page delimiter on same line,
114 ;; Otherwise, show text starting with following line.
115 (if (and (eolp) (not (bobp)))
118 (put 'narrow-to-page 'disabled t)
120 (defun count-lines-page ()
121 "Report number of lines on current page, and how many are before or after point."
122 (interactive "_") ; XEmacs
124 (let ((opoint (point)) beg end
128 (or (looking-at page-delimiter)
133 (setq total (count-lines beg end)
134 before (count-lines beg opoint)
135 after (count-lines opoint end))
136 (message "Page has %d lines (%d + %d)" total before after))))
139 "Print page and line number of point."
140 (interactive "_") ; XEmacs
148 (while (re-search-forward page-delimiter opoint t)
149 (setq count (1+ count)))
150 (message "Page %d, line %d"
152 (1+ (count-lines (point) opoint)))))))
154 ;;; Place `provide' at end of file.
157 ;;; page.el ends here