annotate lisp/prim/page.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents b82b59fe008d
children b9518feda344
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
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
20 ;; along with XEmacs; see the file COPYING. If not, write to the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
21 ;; Free Software Foundation, 59 Temple Place - Suite 330,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
22 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
24 ;;; Synched up with: FSF 19.30.
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'."
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
37 (interactive "_p")
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)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (forward-char -1)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
49 (let (result (end (point)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
50 ;; If we find a match that ends where we started searching,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
51 ;; look for another one.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
52 (while (and (setq result (re-search-backward page-delimiter nil t))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
53 (= (match-end 0) end))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
54 ;; Just search again.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
55 )
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
56 (if result
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
57 ;; We found one--move to the end of it.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
58 (goto-char (match-end 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
59 ;; We found nothing--go to beg of buffer.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
60 (goto-char (point-min))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (setq count (1+ count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (defun backward-page (&optional count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 "Move backward to page boundary. With arg, repeat, or go fwd if negative.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 A page boundary is any line whose beginning matches the regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 `page-delimiter'."
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
67 (interactive "p")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (or count (setq count 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (forward-page (- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (defun mark-page (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 "Put mark at end of page, point at beginning.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 A numeric arg specifies to move forward or backward by that many pages,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 thus marking a page other than the one point was originally in."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (setq arg (if arg (prefix-numeric-value arg) 0))
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 arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (forward-page (1- arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (forward-page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (push-mark nil t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (forward-page -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (defun narrow-to-page (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 "Make text outside current page invisible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 A numeric arg specifies to move forward or backward by that many pages,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 thus showing a page other than the one point was originally in."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (setq arg (if arg (prefix-numeric-value arg) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (widen)
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 arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (forward-page (1- arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; Find the end of the page.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (forward-page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; If we stopped due to end of buffer, stay there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;; If we stopped after a page delimiter, put end of restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;; at the beginning of that line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (goto-char (match-beginning 0)) ; was (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (looking-at page-delimiter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (narrow-to-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; Find the top of the page.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (forward-page -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; If we found beginning of buffer, stay there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; If extra text follows page delimiter on same line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; include it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; Otherwise, show text starting with following line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (if (and (eolp) (not (bobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (defun count-lines-page ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 "Report number of lines on current page, and how many are before or after point."
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
120 (interactive "_")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (let ((opoint (point)) beg end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 total before after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (forward-page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (or (looking-at page-delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (backward-page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (setq total (count-lines beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 before (count-lines beg opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 after (count-lines opoint end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (message "Page has %d lines (%d + %d)" total before after))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (defun what-page ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 "Print page and line number of point."
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 4
diff changeset
138 (interactive "_")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (let ((count 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (while (re-search-forward page-delimiter opoint t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (setq count (1+ count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (message "Page %d, line %d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (1+ (count-lines (point) opoint)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;;; Place `provide' at end of file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (provide 'page)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;;; page.el ends here