annotate lisp/prim/page.el @ 123:c77884c6318d

Added tag r20-1b14 for changeset d2f30a177268
author cvs
date Mon, 13 Aug 2007 09:26:04 +0200
parents b9518feda344
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; page.el --- page motion commands for emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
22 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
24 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; This code provides the page-oriented movement and selection commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; documented in the XEmacs Reference Manual.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (defun forward-page (&optional count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 "Move forward to page boundary. With arg, repeat, or go back if negative.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 A page boundary is any line whose beginning matches the regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 `page-delimiter'."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
37 (interactive "_p") ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (or count (setq count 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (while (and (> count 0) (not (eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; In case the page-delimiter matches the null string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; don't find a match without moving.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (if (bolp) (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (if (re-search-forward page-delimiter nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (setq count (1- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (while (and (< count 0) (not (bobp)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
48 ;; In case the page-delimiter matches the null string,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
49 ;; don't find a match without moving.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
50 (and (save-excursion (re-search-backward page-delimiter nil t))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
51 (= (match-end 0) (point))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
52 (goto-char (match-beginning 0)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (forward-char -1)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
54 (if (re-search-backward page-delimiter nil t)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
55 ;; We found one--move to the end of it.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
56 (goto-char (match-end 0))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
57 ;; We found nothing--go to beg of buffer.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
58 (goto-char (point-min)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (setq count (1+ count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defun backward-page (&optional count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "Move backward to page boundary. With arg, repeat, or go fwd if negative.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 A page boundary is any line whose beginning matches the regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 `page-delimiter'."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
65 (interactive "_p") ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (or count (setq count 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (forward-page (- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defun mark-page (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 "Put mark at end of page, point at beginning.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 A numeric arg specifies to move forward or backward by that many pages,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 thus marking a page other than the one point was originally in."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (setq arg (if arg (prefix-numeric-value arg) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (forward-page arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (forward-page (1- arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (forward-page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (push-mark nil t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (forward-page -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (defun narrow-to-page (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 "Make text outside current page invisible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 A numeric arg specifies to move forward or backward by that many pages,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 thus showing a page other than the one point was originally in."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (setq arg (if arg (prefix-numeric-value arg) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (forward-page arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (forward-page (1- arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; Find the end of the page.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (forward-page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; If we stopped due to end of buffer, stay there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;; If we stopped after a page delimiter, put end of restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; at the beginning of that line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (goto-char (match-beginning 0)) ; was (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (looking-at page-delimiter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (narrow-to-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; Find the top of the page.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (forward-page -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; If we found beginning of buffer, stay there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;; If extra text follows page delimiter on same line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; include it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; Otherwise, show text starting with following line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (if (and (eolp) (not (bobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (point)))))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
115 (put 'narrow-to-page 'disabled t)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (defun count-lines-page ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 "Report number of lines on current page, and how many are before or after point."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
119 (interactive "_") ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (let ((opoint (point)) beg end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 total before after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (forward-page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (or (looking-at page-delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (backward-page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (setq total (count-lines beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 before (count-lines beg opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 after (count-lines opoint end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (message "Page has %d lines (%d + %d)" total before after))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (defun what-page ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 "Print page and line number of point."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
137 (interactive "_") ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (let ((count 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (while (re-search-forward page-delimiter opoint t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (setq count (1+ count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (message "Page %d, line %d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (1+ (count-lines (point) opoint)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;;; Place `provide' at end of file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (provide 'page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;;; page.el ends here