1 ;;; page.el --- page motion commands for emacs.
4 ;; Last-Modified: 01 May 1992
6 ;; Copyright (C) 1985 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it 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 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 (defun forward-page (&optional count
)
27 "Move forward to page boundary. With arg, repeat, or go back if negative.
28 A page boundary is any line whose beginning matches the regexp
31 (or count
(setq count
1))
32 (while (and (> count
0) (not (eobp)))
33 (if (re-search-forward page-delimiter nil t
)
35 (goto-char (point-max)))
36 (setq count
(1- count
)))
37 (while (and (< count
0) (not (bobp)))
39 (if (re-search-backward page-delimiter nil t
)
40 (goto-char (match-end 0))
41 (goto-char (point-min)))
42 (setq count
(1+ count
))))
44 (defun backward-page (&optional count
)
45 "Move backward to page boundary. With arg, repeat, or go fwd if negative.
46 A page boundary is any line whose beginning matches the regexp
49 (or count
(setq count
1))
50 (forward-page (- count
)))
52 (defun mark-page (&optional arg
)
53 "Put mark at end of page, point at beginning.
54 A numeric arg specifies to move forward or backward by that many pages,
55 thus marking a page other than the one point was originally in."
57 (setq arg
(if arg
(prefix-numeric-value arg
) 0))
61 (forward-page (1- arg
))))
66 (defun narrow-to-page (&optional arg
)
67 "Make text outside current page invisible.
68 A numeric arg specifies to move forward or backward by that many pages,
69 thus showing a page other than the one point was originally in."
71 (setq arg
(if arg
(prefix-numeric-value arg
) 0))
77 (forward-page (1- arg
))))
78 ;; Find the end of the page.
80 ;; If we stopped due to end of buffer, stay there.
81 ;; If we stopped after a page delimiter, put end of restriction
82 ;; at the beginning of that line.
83 (if (save-excursion (beginning-of-line)
84 (looking-at page-delimiter
))
86 (narrow-to-region (point)
88 ;; Find the top of the page.
90 ;; If we found beginning of buffer, stay there.
91 ;; If extra text follows page delimiter on same line,
93 ;; Otherwise, show text starting with following line.
94 (if (and (eolp) (not (bobp)))
97 (put 'narrow-to-page
'disabled t
)
99 (defun count-lines-page ()
100 "Report number of lines on current page, and how many are before or after point."
103 (let ((opoint (point)) beg end
107 (or (looking-at page-delimiter
)
112 (setq total
(count-lines beg end
)
113 before
(count-lines beg opoint
)
114 after
(count-lines opoint end
))
115 (message "Page has %d lines (%d + %d)" total before after
))))
118 "Print page and line number of point."
127 (while (re-search-forward page-delimiter opoint t
)
128 (setq count
(1+ count
)))
129 (message "Page %d, line %d"
131 (1+ (count-lines (point) opoint
)))))))
133 ;;; page.el ends here