comparison lisp/textmodes/page.el @ 36:9697c13298e5

Initial revision
author Joseph Arceneaux <jla@gnu.org>
date Tue, 31 Oct 1989 16:00:07 +0000
parents
children 25644943fb13
comparison
equal deleted inserted replaced
35:63b375f17a65 36:9697c13298e5
1 ;; Page motion commands for emacs.
2 ;; Copyright (C) 1985 Free Software Foundation, Inc.
3
4 ;; This file is part of GNU Emacs.
5
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)
9 ;; any later version.
10
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.
15
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.
19
20
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."
24 (interactive "p")
25 (or count (setq count 1))
26 (while (and (> count 0) (not (eobp)))
27 (if (re-search-forward page-delimiter nil t)
28 nil
29 (goto-char (point-max)))
30 (setq count (1- count)))
31 (while (and (< count 0) (not (bobp)))
32 (forward-char -1)
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))))
37
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."
41 (interactive "p")
42 (or count (setq count 1))
43 (forward-page (- count)))
44
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."
49 (interactive "P")
50 (setq arg (if arg (prefix-numeric-value arg) 0))
51 (if (> arg 0)
52 (forward-page arg)
53 (if (< arg 0)
54 (forward-page (1- arg))))
55 (forward-page)
56 (push-mark nil t)
57 (forward-page -1))
58
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."
63 (interactive "P")
64 (setq arg (if arg (prefix-numeric-value arg) 0))
65 (save-excursion
66 (widen)
67 (if (> arg 0)
68 (forward-page arg)
69 (if (< arg 0)
70 (forward-page (1- arg))))
71 ;; Find the end of the page.
72 (forward-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))
78 (beginning-of-line))
79 (narrow-to-region (point)
80 (progn
81 ;; Find the top of the page.
82 (forward-page -1)
83 ;; If we found beginning of buffer, stay there.
84 ;; If extra text follows page delimiter on same line,
85 ;; include it.
86 ;; Otherwise, show text starting with following line.
87 (if (and (eolp) (not (bobp)))
88 (forward-line 1))
89 (point)))))
90
91 (defun count-lines-page ()
92 "Report number of lines on current page, and how many are before or after point."
93 (interactive)
94 (save-excursion
95 (let ((opoint (point)) beg end
96 total before after)
97 (forward-page)
98 (beginning-of-line)
99 (or (looking-at page-delimiter)
100 (end-of-line))
101 (setq end (point))
102 (backward-page)
103 (setq beg (point))
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))))
108
109 (defun what-page ()
110 "Print page and line number of point."
111 (interactive)
112 (save-restriction
113 (widen)
114 (save-excursion
115 (beginning-of-line)
116 (let ((count 1)
117 (opoint (point)))
118 (goto-char 1)
119 (while (re-search-forward page-delimiter opoint t)
120 (setq count (1+ count)))
121 (message "Page %d, line %d"
122 count
123 (1+ (count-lines (point) opoint)))))))