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