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