1 ;; Page motion commands for emacs.
2 ;; Copyright (C) 1985 Free Software Foundation, Inc.
4 ;; This file is part of GNU Emacs.
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 1, or (at your option)
11 ;; GNU Emacs is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 (defun forward-page (&optional count)
22 "Move forward to page boundary. With arg, repeat, or go back if negative.
23 A page boundary is any line whose beginning matches the regexp page-delimiter."
25 (or count (setq count 1))
26 (while (and (> count 0) (not (eobp)))
27 (if (re-search-forward page-delimiter nil t)
29 (goto-char (point-max)))
30 (setq count (1- count)))
31 (while (and (< count 0) (not (bobp)))
33 (if (re-search-backward page-delimiter nil t)
34 (goto-char (match-end 0))
35 (goto-char (point-min)))
36 (setq count (1+ count))))
38 (defun backward-page (&optional count)
39 "Move backward to page boundary. With arg, repeat, or go fwd if negative.
40 A page boundary is any line whose beginning matches the regexp page-delimiter."
42 (or count (setq count 1))
43 (forward-page (- count)))
45 (defun mark-page (&optional arg)
46 "Put mark at end of page, point at beginning.
47 A numeric arg specifies to move forward or backward by that many pages,
48 thus marking a page other than the one point was originally in."
50 (setq arg (if arg (prefix-numeric-value arg) 0))
54 (forward-page (1- arg))))
59 (defun narrow-to-page (&optional arg)
60 "Make text outside current page invisible.
61 A numeric arg specifies to move forward or backward by that many pages,
62 thus showing a page other than the one point was originally in."
64 (setq arg (if arg (prefix-numeric-value arg) 0))
70 (forward-page (1- arg))))
71 ;; Find the end of the page.
73 ;; If we stopped due to end of buffer, stay there.
74 ;; If we stopped after a page delimiter, put end of restriction
75 ;; at the beginning of that line.
76 (if (save-excursion (beginning-of-line)
77 (looking-at page-delimiter))
79 (narrow-to-region (point)
81 ;; Find the top of the page.
83 ;; If we found beginning of buffer, stay there.
84 ;; If extra text follows page delimiter on same line,
86 ;; Otherwise, show text starting with following line.
87 (if (and (eolp) (not (bobp)))
91 (defun count-lines-page ()
92 "Report number of lines on current page, and how many are before or after point."
95 (let ((opoint (point)) beg end
99 (or (looking-at page-delimiter)
104 (setq total (count-lines beg end)
105 before (count-lines beg opoint)
106 after (count-lines opoint end))
107 (message "Page has %d lines (%d + %d)" total before after))))
110 "Print page and line number of point."
119 (while (re-search-forward page-delimiter opoint t)
120 (setq count (1+ count)))
121 (message "Page %d, line %d"
123 (1+ (count-lines (point) opoint)))))))