Mercurial > emacs
annotate lisp/textmodes/page.el @ 783:59dc833c4e0c
*** empty log message ***
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Wed, 15 Jul 1992 18:48:42 +0000 |
parents | 505130d1ddf8 |
children | 4f28bd14272c |
rev | line source |
---|---|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
236
diff
changeset
|
1 ;;; page.el --- page motion commands for emacs. |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
236
diff
changeset
|
2 |
36 | 3 ;; Copyright (C) 1985 Free Software Foundation, Inc. |
4 | |
5 ;; This file is part of GNU Emacs. | |
6 | |
7 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
8 ;; it under the terms of the GNU General Public License as published by | |
9 ;; the Free Software Foundation; either version 1, or (at your option) | |
10 ;; any later version. | |
11 | |
12 ;; GNU Emacs is distributed in the hope that it will be useful, | |
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 ;; GNU General Public License for more details. | |
16 | |
17 ;; You should have received a copy of the GNU General Public License | |
18 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | |
21 | |
22 (defun forward-page (&optional count) | |
23 "Move forward to page boundary. With arg, repeat, or go back if negative. | |
236 | 24 A page boundary is any line whose beginning matches the regexp |
25 `page-delimiter'." | |
36 | 26 (interactive "p") |
27 (or count (setq count 1)) | |
28 (while (and (> count 0) (not (eobp))) | |
29 (if (re-search-forward page-delimiter nil t) | |
30 nil | |
31 (goto-char (point-max))) | |
32 (setq count (1- count))) | |
33 (while (and (< count 0) (not (bobp))) | |
34 (forward-char -1) | |
35 (if (re-search-backward page-delimiter nil t) | |
36 (goto-char (match-end 0)) | |
37 (goto-char (point-min))) | |
38 (setq count (1+ count)))) | |
39 | |
40 (defun backward-page (&optional count) | |
41 "Move backward to page boundary. With arg, repeat, or go fwd if negative. | |
236 | 42 A page boundary is any line whose beginning matches the regexp |
43 `page-delimiter'." | |
36 | 44 (interactive "p") |
45 (or count (setq count 1)) | |
46 (forward-page (- count))) | |
47 | |
48 (defun mark-page (&optional arg) | |
49 "Put mark at end of page, point at beginning. | |
50 A numeric arg specifies to move forward or backward by that many pages, | |
51 thus marking a page other than the one point was originally in." | |
52 (interactive "P") | |
53 (setq arg (if arg (prefix-numeric-value arg) 0)) | |
54 (if (> arg 0) | |
55 (forward-page arg) | |
56 (if (< arg 0) | |
57 (forward-page (1- arg)))) | |
58 (forward-page) | |
59 (push-mark nil t) | |
60 (forward-page -1)) | |
61 | |
62 (defun narrow-to-page (&optional arg) | |
63 "Make text outside current page invisible. | |
64 A numeric arg specifies to move forward or backward by that many pages, | |
65 thus showing a page other than the one point was originally in." | |
66 (interactive "P") | |
67 (setq arg (if arg (prefix-numeric-value arg) 0)) | |
68 (save-excursion | |
69 (widen) | |
70 (if (> arg 0) | |
71 (forward-page arg) | |
72 (if (< arg 0) | |
73 (forward-page (1- arg)))) | |
74 ;; Find the end of the page. | |
75 (forward-page) | |
76 ;; If we stopped due to end of buffer, stay there. | |
77 ;; If we stopped after a page delimiter, put end of restriction | |
78 ;; at the beginning of that line. | |
79 (if (save-excursion (beginning-of-line) | |
80 (looking-at page-delimiter)) | |
81 (beginning-of-line)) | |
82 (narrow-to-region (point) | |
83 (progn | |
84 ;; Find the top of the page. | |
85 (forward-page -1) | |
86 ;; If we found beginning of buffer, stay there. | |
87 ;; If extra text follows page delimiter on same line, | |
88 ;; include it. | |
89 ;; Otherwise, show text starting with following line. | |
90 (if (and (eolp) (not (bobp))) | |
91 (forward-line 1)) | |
92 (point))))) | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
236
diff
changeset
|
93 (put 'narrow-to-page 'disabled t) |
36 | 94 |
95 (defun count-lines-page () | |
96 "Report number of lines on current page, and how many are before or after point." | |
97 (interactive) | |
98 (save-excursion | |
99 (let ((opoint (point)) beg end | |
100 total before after) | |
101 (forward-page) | |
102 (beginning-of-line) | |
103 (or (looking-at page-delimiter) | |
104 (end-of-line)) | |
105 (setq end (point)) | |
106 (backward-page) | |
107 (setq beg (point)) | |
108 (setq total (count-lines beg end) | |
109 before (count-lines beg opoint) | |
110 after (count-lines opoint end)) | |
111 (message "Page has %d lines (%d + %d)" total before after)))) | |
112 | |
113 (defun what-page () | |
114 "Print page and line number of point." | |
115 (interactive) | |
116 (save-restriction | |
117 (widen) | |
118 (save-excursion | |
119 (beginning-of-line) | |
120 (let ((count 1) | |
121 (opoint (point))) | |
122 (goto-char 1) | |
123 (while (re-search-forward page-delimiter opoint t) | |
124 (setq count (1+ count))) | |
125 (message "Page %d, line %d" | |
126 count | |
127 (1+ (count-lines (point) opoint))))))) | |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
236
diff
changeset
|
128 |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
236
diff
changeset
|
129 ;;; page.el ends here |