Mercurial > emacs
annotate lisp/textmodes/ooutline.el @ 3448:b7d345eaae47
(calendar-mode): Doc fix.
(calendar-mark-ring): New defvar.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 03 Jun 1993 06:12:46 +0000 |
parents | 898d7a33c038 |
children | 0732700eb6c0 |
rev | line source |
---|---|
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
1 ;;; outline.el --- outline mode commands for Emacs |
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
2 |
845 | 3 ;; Copyright (C) 1986 Free Software Foundation, Inc. |
4 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
730
diff
changeset
|
5 ;; Maintainer: FSF |
234 | 6 |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; 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:
730
diff
changeset
|
11 ;; the Free Software Foundation; either version 2, or (at your option) |
234 | 12 ;; any later version. |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
2308
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
23 ;;; Commentary: |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
24 |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
25 ;; This package is a major mode for editing outline-format documents. |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
26 ;; An outline can be `abstracted' to show headers at any given level, |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
27 ;; with all stuff below hidden. See the Emacs manual for details. |
f287613dfc28
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
28 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
730
diff
changeset
|
29 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
730
diff
changeset
|
30 |
234 | 31 ;; Jan '86, Some new features added by Peter Desnoyers and rewritten by RMS. |
32 | |
33 (defvar outline-regexp "[*\^l]+" | |
34 "*Regular expression to match the beginning of a heading. | |
35 Any line whose beginning matches this regexp is considered to start a heading. | |
36 The recommended way to set this is with a Local Variables: list | |
37 in the file it applies to. See also outline-heading-end-regexp.") | |
38 | |
2900
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
39 (defvar outline-heading-end-regexp "[\n\^M]" |
234 | 40 "*Regular expression to match the end of a heading line. |
41 You can assume that point is at the beginning of a heading when this | |
42 regexp is searched for. The heading ends at the end of the match. | |
43 The recommended way to set this is with a \"Local Variables:\" list | |
44 in the file it applies to.") | |
45 | |
46 (defvar outline-mode-map nil "") | |
47 | |
48 (if outline-mode-map | |
49 nil | |
50 (setq outline-mode-map (nconc (make-sparse-keymap) text-mode-map)) | |
51 (define-key outline-mode-map "\C-c\C-n" 'outline-next-visible-heading) | |
52 (define-key outline-mode-map "\C-c\C-p" 'outline-previous-visible-heading) | |
53 (define-key outline-mode-map "\C-c\C-i" 'show-children) | |
54 (define-key outline-mode-map "\C-c\C-s" 'show-subtree) | |
55 (define-key outline-mode-map "\C-c\C-h" 'hide-subtree) | |
56 (define-key outline-mode-map "\C-c\C-u" 'outline-up-heading) | |
57 (define-key outline-mode-map "\C-c\C-f" 'outline-forward-same-level) | |
58 (define-key outline-mode-map "\C-c\C-b" 'outline-backward-same-level)) | |
59 | |
60 (defvar outline-minor-mode nil | |
61 "Non-nil if using Outline mode as a minor mode of some other mode.") | |
2934
7c4226d1ea65
(outline-minor-mode): Make var permanent local in all buffers.
Richard M. Stallman <rms@gnu.org>
parents:
2900
diff
changeset
|
62 (make-variable-buffer-local 'outline-minor-mode) |
7c4226d1ea65
(outline-minor-mode): Make var permanent local in all buffers.
Richard M. Stallman <rms@gnu.org>
parents:
2900
diff
changeset
|
63 (put 'outline-minor-mode 'permanent-local t) |
234 | 64 (setq minor-mode-alist (append minor-mode-alist |
65 (list '(outline-minor-mode " Outl")))) | |
66 | |
258 | 67 ;;;###autoload |
234 | 68 (defun outline-mode () |
69 "Set major mode for editing outlines with selective display. | |
70 Headings are lines which start with asterisks: one for major headings, | |
71 two for subheadings, etc. Lines not starting with asterisks are body lines. | |
72 | |
73 Body text or subheadings under a heading can be made temporarily | |
74 invisible, or visible again. Invisible lines are attached to the end | |
75 of the heading, so they move with it, if the line is killed and yanked | |
76 back. A heading with text hidden under it is marked with an ellipsis (...). | |
77 | |
78 Commands:\\<outline-mode-map> | |
79 \\[outline-next-visible-heading] outline-next-visible-heading move by visible headings | |
80 \\[outline-previous-visible-heading] outline-previous-visible-heading | |
81 \\[outline-forward-same-level] outline-forward-same-level similar but skip subheadings | |
82 \\[outline-backward-same-level] outline-backward-same-level | |
83 \\[outline-up-heading] outline-up-heading move from subheading to heading | |
84 | |
85 M-x hide-body make all text invisible (not headings). | |
86 M-x show-all make everything in buffer visible. | |
87 | |
88 The remaining commands are used when point is on a heading line. | |
89 They apply to some of the body or subheadings of that heading. | |
90 \\[hide-subtree] hide-subtree make body and subheadings invisible. | |
91 \\[show-subtree] show-subtree make body and subheadings visible. | |
92 \\[show-children] show-children make direct subheadings visible. | |
93 No effect on body, or subheadings 2 or more levels down. | |
94 With arg N, affects subheadings N levels down. | |
95 M-x hide-entry make immediately following body invisible. | |
96 M-x show-entry make it visible. | |
97 M-x hide-leaves make body under heading and under its subheadings invisible. | |
98 The subheadings remain visible. | |
99 M-x show-branches make all subheadings at all levels visible. | |
100 | |
101 The variable `outline-regexp' can be changed to control what is a heading. | |
102 A line is a heading if `outline-regexp' matches something at the | |
103 beginning of the line. The longer the match, the deeper the level. | |
104 | |
105 Turning on outline mode calls the value of `text-mode-hook' and then of | |
106 `outline-mode-hook', if they are non-nil." | |
107 (interactive) | |
108 (kill-all-local-variables) | |
109 (setq selective-display t) | |
110 (use-local-map outline-mode-map) | |
111 (setq mode-name "Outline") | |
112 (setq major-mode 'outline-mode) | |
113 (define-abbrev-table 'text-mode-abbrev-table ()) | |
114 (setq local-abbrev-table text-mode-abbrev-table) | |
115 (set-syntax-table text-mode-syntax-table) | |
116 (make-local-variable 'paragraph-start) | |
117 (setq paragraph-start (concat paragraph-start "\\|^\\(" | |
118 outline-regexp "\\)")) | |
119 ;; Inhibit auto-filling of header lines. | |
120 (make-local-variable 'auto-fill-inhibit-regexp) | |
121 (setq auto-fill-inhibit-regexp outline-regexp) | |
122 (make-local-variable 'paragraph-separate) | |
123 (setq paragraph-separate (concat paragraph-separate "\\|^\\(" | |
124 outline-regexp "\\)")) | |
125 (run-hooks 'text-mode-hook 'outline-mode-hook)) | |
126 | |
2900
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
127 (defvar outline-minor-mode-map nil) |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
128 (if outline-minor-mode-map |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
129 nil |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
130 (setq outline-minor-mode-map (make-sparse-keymap)) |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
131 (define-key outline-minor-mode-map "\C-c" |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
132 (lookup-key outline-mode-map "\C-c"))) |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
133 |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
134 (or (assq 'outline-minor-mode minor-mode-map-alist) |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
135 (setq minor-mode-map-alist |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
136 (cons (cons 'outline-minor-mode outline-minor-mode-map) |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
137 minor-mode-map-alist))) |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
138 |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
139 (defun outline-minor-mode (&optional arg) |
2934
7c4226d1ea65
(outline-minor-mode): Make var permanent local in all buffers.
Richard M. Stallman <rms@gnu.org>
parents:
2900
diff
changeset
|
140 "Toggle Outline minor mode. |
7c4226d1ea65
(outline-minor-mode): Make var permanent local in all buffers.
Richard M. Stallman <rms@gnu.org>
parents:
2900
diff
changeset
|
141 With arg, turn Outline minor mode on if arg is positive, off otherwise. |
7c4226d1ea65
(outline-minor-mode): Make var permanent local in all buffers.
Richard M. Stallman <rms@gnu.org>
parents:
2900
diff
changeset
|
142 See the command `outline-mode' for more information on this mode." |
234 | 143 (interactive "P") |
144 (setq outline-minor-mode | |
145 (if (null arg) (not outline-minor-mode) | |
146 (> (prefix-numeric-value arg) 0))) | |
147 (if outline-minor-mode | |
148 (progn | |
149 (setq selective-display t) | |
150 (run-hooks 'outline-minor-mode-hook)) | |
2900
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
151 (setq selective-display nil))) |
234 | 152 |
153 (defun outline-level () | |
154 "Return the depth to which a statement is nested in the outline. | |
155 Point must be at the beginning of a header line. This is actually | |
156 the column number of the end of what `outline-regexp matches'." | |
157 (save-excursion | |
158 (looking-at outline-regexp) | |
159 (save-excursion (goto-char (match-end 0)) (current-column)))) | |
160 | |
161 (defun outline-next-preface () | |
162 "Skip forward to just before the next heading line." | |
163 (if (re-search-forward (concat "[\n\^M]\\(" outline-regexp "\\)") | |
164 nil 'move) | |
165 (goto-char (match-beginning 0))) | |
166 (if (memq (preceding-char) '(?\n ?\^M)) | |
167 (forward-char -1))) | |
168 | |
169 (defun outline-next-heading () | |
170 "Move to the next (possibly invisible) heading line." | |
171 (interactive) | |
172 (if (re-search-forward (concat "[\n\^M]\\(" outline-regexp "\\)") | |
173 nil 'move) | |
174 (goto-char (1+ (match-beginning 0))))) | |
175 | |
176 (defun outline-back-to-heading () | |
177 "Move to previous (possibly invisible) heading line, | |
178 or to the beginning of this line if it is a heading line." | |
179 (beginning-of-line) | |
180 (or (outline-on-heading-p) | |
181 (re-search-backward (concat "^\\(" outline-regexp "\\)") nil 'move))) | |
182 | |
183 (defun outline-on-heading-p () | |
184 "Return T if point is on a header line." | |
185 (save-excursion | |
186 (beginning-of-line) | |
187 (and (eq (preceding-char) ?\n) | |
188 (looking-at outline-regexp)))) | |
189 | |
190 (defun outline-end-of-heading () | |
191 (if (re-search-forward outline-heading-end-regexp nil 'move) | |
192 (forward-char -1))) | |
193 | |
194 (defun outline-next-visible-heading (arg) | |
195 "Move to the next visible heading line. | |
196 With argument, repeats or can move backward if negative. | |
197 A heading line is one that starts with a `*' (or that | |
198 `outline-regexp' matches)." | |
199 (interactive "p") | |
200 (if (< arg 0) | |
201 (beginning-of-line) | |
202 (end-of-line)) | |
203 (re-search-forward (concat "^\\(" outline-regexp "\\)") nil nil arg) | |
204 (beginning-of-line)) | |
205 | |
206 (defun outline-previous-visible-heading (arg) | |
207 "Move to the previous heading line. | |
208 With argument, repeats or can move forward if negative. | |
209 A heading line is one that starts with a `*' (or that | |
210 `outline-regexp' matches)." | |
211 (interactive "p") | |
212 (outline-next-visible-heading (- arg))) | |
213 | |
214 (defun outline-flag-region (from to flag) | |
215 "Hides or shows lines from FROM to TO, according to FLAG. | |
216 If FLAG is `\\n' (newline character) then text is shown, | |
217 while if FLAG is `\\^M' (control-M) the text is hidden." | |
3376
898d7a33c038
(outline-flag-region): Pass t as NOUNDO arg
Richard M. Stallman <rms@gnu.org>
parents:
2934
diff
changeset
|
218 (let (buffer-read-only) |
898d7a33c038
(outline-flag-region): Pass t as NOUNDO arg
Richard M. Stallman <rms@gnu.org>
parents:
2934
diff
changeset
|
219 (subst-char-in-region from to |
898d7a33c038
(outline-flag-region): Pass t as NOUNDO arg
Richard M. Stallman <rms@gnu.org>
parents:
2934
diff
changeset
|
220 (if (= flag ?\n) ?\^M ?\n) |
898d7a33c038
(outline-flag-region): Pass t as NOUNDO arg
Richard M. Stallman <rms@gnu.org>
parents:
2934
diff
changeset
|
221 flag t))) |
234 | 222 |
223 (defun hide-entry () | |
224 "Hide the body directly following this heading." | |
225 (interactive) | |
226 (outline-back-to-heading) | |
227 (outline-end-of-heading) | |
228 (save-excursion | |
229 (outline-flag-region (point) (progn (outline-next-preface) (point)) ?\^M))) | |
230 | |
231 (defun show-entry () | |
232 "Show the body directly following this heading." | |
233 (interactive) | |
234 (save-excursion | |
235 (outline-flag-region (point) (progn (outline-next-preface) (point)) ?\n))) | |
236 | |
237 (defun hide-body () | |
238 "Hide all of buffer except headings." | |
239 (interactive) | |
240 (hide-region-body (point-min) (point-max))) | |
241 | |
242 (defun hide-region-body (start end) | |
243 "Hide all body lines in the region, but not headings." | |
244 (save-excursion | |
245 (save-restriction | |
246 (narrow-to-region start end) | |
247 (goto-char (point-min)) | |
248 (if (outline-on-heading-p) | |
249 (outline-end-of-heading)) | |
250 (while (not (eobp)) | |
251 (outline-flag-region (point) | |
252 (progn (outline-next-preface) (point)) ?\^M) | |
253 (if (not (eobp)) | |
254 (progn | |
255 (forward-char | |
256 (if (looking-at "[\n\^M][\n\^M]") | |
257 2 1)) | |
258 (outline-end-of-heading))))))) | |
259 | |
260 (defun show-all () | |
261 "Show all of the text in the buffer." | |
262 (interactive) | |
263 (outline-flag-region (point-min) (point-max) ?\n)) | |
264 | |
265 (defun hide-subtree () | |
266 "Hide everything after this heading at deeper levels." | |
267 (interactive) | |
268 (outline-flag-subtree ?\^M)) | |
269 | |
270 (defun hide-leaves () | |
271 "Hide all body after this heading at deeper levels." | |
272 (interactive) | |
273 (outline-back-to-heading) | |
274 (outline-end-of-heading) | |
275 (hide-region-body (point) (progn (outline-end-of-subtree) (point)))) | |
276 | |
277 (defun show-subtree () | |
278 "Show everything after this heading at deeper levels." | |
279 (interactive) | |
280 (outline-flag-subtree ?\n)) | |
281 | |
282 (defun outline-flag-subtree (flag) | |
283 (save-excursion | |
284 (outline-back-to-heading) | |
285 (outline-end-of-heading) | |
286 (outline-flag-region (point) | |
287 (progn (outline-end-of-subtree) (point)) | |
288 flag))) | |
289 | |
290 (defun outline-end-of-subtree () | |
291 (outline-back-to-heading) | |
292 (let ((opoint (point)) | |
293 (first t) | |
294 (level (outline-level))) | |
295 (while (and (not (eobp)) | |
296 (or first (> (outline-level) level))) | |
297 (setq first nil) | |
298 (outline-next-heading)) | |
299 (forward-char -1) | |
300 (if (memq (preceding-char) '(?\n ?\^M)) | |
301 (forward-char -1)))) | |
302 | |
303 (defun show-branches () | |
304 "Show all subheadings of this heading, but not their bodies." | |
305 (interactive) | |
306 (show-children 1000)) | |
307 | |
308 (defun show-children (&optional level) | |
309 "Show all direct subheadings of this heading. | |
310 Prefix arg LEVEL is how many levels below the current level should be shown. | |
311 Default is enough to cause the following heading to appear." | |
312 (interactive "P") | |
313 (setq level | |
314 (if level (prefix-numeric-value level) | |
315 (save-excursion | |
316 (beginning-of-line) | |
317 (let ((start-level (outline-level))) | |
318 (outline-next-heading) | |
319 (max 1 (- (outline-level) start-level)))))) | |
320 (save-excursion | |
321 (save-restriction | |
322 (beginning-of-line) | |
323 (setq level (+ level (outline-level))) | |
324 (narrow-to-region (point) | |
325 (progn (outline-end-of-subtree) (1+ (point)))) | |
326 (goto-char (point-min)) | |
327 (while (and (not (eobp)) | |
328 (progn | |
329 (outline-next-heading) | |
330 (not (eobp)))) | |
331 (if (<= (outline-level) level) | |
332 (save-excursion | |
333 (outline-flag-region (save-excursion | |
334 (forward-char -1) | |
335 (if (memq (preceding-char) '(?\n ?\^M)) | |
336 (forward-char -1)) | |
337 (point)) | |
338 (progn (outline-end-of-heading) (point)) | |
339 ?\n))))))) | |
340 | |
341 (defun outline-up-heading (arg) | |
342 "Move to the heading line of which the present line is a subheading. | |
343 With argument, move up ARG levels." | |
344 (interactive "p") | |
345 (outline-back-to-heading) | |
346 (if (eq (outline-level) 1) | |
347 (error "")) | |
348 (while (and (> (outline-level) 1) | |
349 (> arg 0) | |
350 (not (bobp))) | |
351 (let ((present-level (outline-level))) | |
352 (while (not (< (outline-level) present-level)) | |
353 (outline-previous-visible-heading 1)) | |
354 (setq arg (- arg 1))))) | |
355 | |
356 (defun outline-forward-same-level (arg) | |
357 "Move forward to the ARG'th subheading from here of the same level as the | |
358 present one. It stops at the first and last subheadings of a superior heading." | |
359 (interactive "p") | |
360 (outline-back-to-heading) | |
361 (while (> arg 0) | |
362 (let ((point-to-move-to (save-excursion | |
363 (outline-get-next-sibling)))) | |
364 (if point-to-move-to | |
365 (progn | |
366 (goto-char point-to-move-to) | |
367 (setq arg (1- arg))) | |
368 (progn | |
369 (setq arg 0) | |
370 (error "")))))) | |
371 | |
372 (defun outline-get-next-sibling () | |
373 "Position the point at the next heading of the same level, | |
374 and return that position or nil if it cannot be found." | |
375 (let ((level (outline-level))) | |
376 (outline-next-visible-heading 1) | |
377 (while (and (> (outline-level) level) | |
378 (not (eobp))) | |
379 (outline-next-visible-heading 1)) | |
380 (if (< (outline-level) level) | |
381 nil | |
382 (point)))) | |
383 | |
384 (defun outline-backward-same-level (arg) | |
385 "Move backward to the ARG'th subheading from here of the same level as the | |
386 present one. It stops at the first and last subheadings of a superior heading." | |
387 (interactive "p") | |
388 (outline-back-to-heading) | |
389 (while (> arg 0) | |
390 (let ((point-to-move-to (save-excursion | |
391 (outline-get-last-sibling)))) | |
392 (if point-to-move-to | |
393 (progn | |
394 (goto-char point-to-move-to) | |
395 (setq arg (1- arg))) | |
396 (progn | |
397 (setq arg 0) | |
398 (error "")))))) | |
399 | |
400 (defun outline-get-last-sibling () | |
401 "Position the point at the previous heading of the same level, | |
402 and return that position or nil if it cannot be found." | |
403 (let ((level (outline-level))) | |
404 (outline-previous-visible-heading 1) | |
405 (while (and (> (outline-level) level) | |
406 (not (bobp))) | |
407 (outline-previous-visible-heading 1)) | |
408 (if (< (outline-level) level) | |
409 nil | |
410 (point)))) | |
411 | |
2900
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
412 (provide 'outline) |
443ebd8f59d2
(outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents:
2308
diff
changeset
|
413 |
659
505130d1ddf8
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
258
diff
changeset
|
414 ;;; outline.el ends here |