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