1 ;;; page.el --- page motion commands for emacs.
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 1, or (at your option)
12 ;; GNU Emacs 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.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 (defun forward-page (&optional count
)
23 "Move forward to page boundary. With arg, repeat, or go back if negative.
24 A page boundary is any line whose beginning matches the regexp
27 (or count
(setq count
1))
28 (while (and (> count
0) (not (eobp)))
29 (if (re-search-forward page-delimiter nil t
)
31 (goto-char (point-max)))
32 (setq count
(1- count
)))
33 (while (and (< count
0) (not (bobp)))
35 (if (re-search-backward page-delimiter nil t
)
36 (goto-char (match-end 0))
37 (goto-char (point-min)))
38 (setq count
(1+ count
))))
40 (defun backward-page (&optional count
)
41 "Move backward to page boundary. With arg, repeat, or go fwd if negative.
42 A page boundary is any line whose beginning matches the regexp
45 (or count
(setq count
1))
46 (forward-page (- count
)))
48 (defun mark-page (&optional arg
)
49 "Put mark at end of page, point at beginning.
50 A numeric arg specifies to move forward or backward by that many pages,
51 thus marking a page other than the one point was originally in."
53 (setq arg
(if arg
(prefix-numeric-value arg
) 0))
57 (forward-page (1- arg
))))
62 (defun narrow-to-page (&optional arg
)
63 "Make text outside current page invisible.
64 A numeric arg specifies to move forward or backward by that many pages,
65 thus showing a page other than the one point was originally in."
67 (setq arg
(if arg
(prefix-numeric-value arg
) 0))
73 (forward-page (1- arg
))))
74 ;; Find the end of the page.
76 ;; If we stopped due to end of buffer, stay there.
77 ;; If we stopped after a page delimiter, put end of restriction
78 ;; at the beginning of that line.
79 (if (save-excursion (beginning-of-line)
80 (looking-at page-delimiter
))
82 (narrow-to-region (point)
84 ;; Find the top of the page.
86 ;; If we found beginning of buffer, stay there.
87 ;; If extra text follows page delimiter on same line,
89 ;; Otherwise, show text starting with following line.
90 (if (and (eolp) (not (bobp)))
93 (put 'narrow-to-page
'disabled t
)
95 (defun count-lines-page ()
96 "Report number of lines on current page, and how many are before or after point."
99 (let ((opoint (point)) beg end
103 (or (looking-at page-delimiter
)
108 (setq total
(count-lines beg end
)
109 before
(count-lines beg opoint
)
110 after
(count-lines opoint end
))
111 (message "Page has %d lines (%d + %d)" total before after
))))
114 "Print page and line number of point."
123 (while (re-search-forward page-delimiter opoint t
)
124 (setq count
(1+ count
)))
125 (message "Page %d, line %d"
127 (1+ (count-lines (point) opoint
)))))))
129 ;;; page.el ends here