Mercurial > emacs
annotate lisp/textmodes/outline.el @ 10996:356f658dbd65
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 14 Mar 1995 00:33:40 +0000 |
parents | d1990c517cc9 |
children | 2c184ff2351d |
rev | line source |
---|---|
10950 | 1 ;;; outline.el --- outline mode commands for Emacs |
2 ;; Copyright (C) 1986, 1993, 1994 Free Software Foundation, Inc. | |
3 | |
4 ;; Maintainer: FSF | |
5 | |
6 ;; This file is part of GNU Emacs. | |
7 | |
8 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
9 ;; it under the terms of the GNU General Public License as published by | |
10 ;; the Free Software Foundation; either version 2, or (at your option) | |
11 ;; any later version. | |
12 | |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | |
22 ;;; Commentary: | |
23 | |
24 ;; This package is a major mode for editing outline-format documents. | |
25 ;; An outline can be `abstracted' to show headers at any given level, | |
26 ;; with all stuff below hidden. See the Emacs manual for details. | |
27 | |
28 ;;; Code: | |
29 | |
30 ;; Jan '86, Some new features added by Peter Desnoyers and rewritten by RMS. | |
31 | |
32 (defvar outline-regexp nil | |
33 "*Regular expression to match the beginning of a heading. | |
34 Any line whose beginning matches this regexp is considered to start a heading. | |
35 The recommended way to set this is with a Local Variables: list | |
36 in the file it applies to. See also outline-heading-end-regexp.") | |
37 | |
38 ;; Can't initialize this in the defvar above -- some major modes have | |
39 ;; already assigned a local value to it. | |
40 (or (default-value 'outline-regexp) | |
41 (setq-default outline-regexp "[*\^L]+")) | |
42 | |
43 (defvar outline-heading-end-regexp "\n" | |
44 "*Regular expression to match the end of a heading line. | |
45 You can assume that point is at the beginning of a heading when this | |
46 regexp is searched for. The heading ends at the end of the match. | |
47 The recommended way to set this is with a `Local Variables:' list | |
48 in the file it applies to.") | |
49 | |
50 (defvar outline-mode-prefix-map nil) | |
51 | |
52 (if outline-mode-prefix-map | |
53 nil | |
54 (setq outline-mode-prefix-map (make-sparse-keymap)) | |
55 (define-key outline-mode-prefix-map "\C-n" 'outline-next-visible-heading) | |
56 (define-key outline-mode-prefix-map "\C-p" 'outline-previous-visible-heading) | |
57 (define-key outline-mode-prefix-map "\C-i" 'show-children) | |
58 (define-key outline-mode-prefix-map "\C-s" 'show-subtree) | |
59 (define-key outline-mode-prefix-map "\C-d" 'hide-subtree) | |
60 (define-key outline-mode-prefix-map "\C-u" 'outline-up-heading) | |
61 (define-key outline-mode-prefix-map "\C-f" 'outline-forward-same-level) | |
62 (define-key outline-mode-prefix-map "\C-b" 'outline-backward-same-level) | |
63 (define-key outline-mode-prefix-map "\C-t" 'hide-body) | |
64 (define-key outline-mode-prefix-map "\C-a" 'show-all) | |
65 (define-key outline-mode-prefix-map "\C-c" 'hide-entry) | |
66 (define-key outline-mode-prefix-map "\C-e" 'show-entry) | |
67 (define-key outline-mode-prefix-map "\C-l" 'hide-leaves) | |
68 (define-key outline-mode-prefix-map "\C-k" 'show-branches) | |
69 (define-key outline-mode-prefix-map "\C-q" 'hide-sublevels) | |
70 (define-key outline-mode-prefix-map "\C-o" 'hide-other)) | |
71 | |
72 (defvar outline-mode-menu-bar-map nil) | |
73 (if outline-mode-menu-bar-map | |
74 nil | |
75 (setq outline-mode-menu-bar-map (make-sparse-keymap)) | |
76 | |
77 (define-key outline-mode-menu-bar-map [hide] | |
78 (cons "Hide" (make-sparse-keymap "Hide"))) | |
79 | |
80 (define-key outline-mode-menu-bar-map [hide hide-other] | |
81 '("Hide Other" . hide-other)) | |
82 (define-key outline-mode-menu-bar-map [hide hide-sublevels] | |
83 '("Hide Sublevels" . hide-sublevels)) | |
84 (define-key outline-mode-menu-bar-map [hide hide-subtree] | |
85 '("Hide Subtree" . hide-subtree)) | |
86 (define-key outline-mode-menu-bar-map [hide hide-entry] | |
87 '("Hide Entry" . hide-entry)) | |
88 (define-key outline-mode-menu-bar-map [hide hide-body] | |
89 '("Hide Body" . hide-body)) | |
90 (define-key outline-mode-menu-bar-map [hide hide-leaves] | |
91 '("Hide Leaves" . hide-leaves)) | |
92 | |
93 (define-key outline-mode-menu-bar-map [show] | |
94 (cons "Show" (make-sparse-keymap "Show"))) | |
95 | |
96 (define-key outline-mode-menu-bar-map [show show-subtree] | |
97 '("Show Subtree" . show-subtree)) | |
98 (define-key outline-mode-menu-bar-map [show show-children] | |
99 '("Show Children" . show-children)) | |
100 (define-key outline-mode-menu-bar-map [show show-branches] | |
101 '("Show Branches" . show-branches)) | |
102 (define-key outline-mode-menu-bar-map [show show-entry] | |
103 '("Show Entry" . show-entry)) | |
104 (define-key outline-mode-menu-bar-map [show show-all] | |
105 '("Show All" . show-all)) | |
106 | |
107 (define-key outline-mode-menu-bar-map [headings] | |
108 (cons "Headings" (make-sparse-keymap "Headings"))) | |
109 | |
110 (define-key outline-mode-menu-bar-map [headings outline-backward-same-level] | |
111 '("Previous Same Level" . outline-backward-same-level)) | |
112 (define-key outline-mode-menu-bar-map [headings outline-forward-same-level] | |
113 '("Next Same Level" . outline-forward-same-level)) | |
114 (define-key outline-mode-menu-bar-map [headings outline-previous-visible-heading] | |
115 '("Previous" . outline-previous-visible-heading)) | |
116 (define-key outline-mode-menu-bar-map [headings outline-next-visible-heading] | |
117 '("Next" . outline-next-visible-heading)) | |
118 (define-key outline-mode-menu-bar-map [headings outline-up-heading] | |
119 '("Up" . outline-up-heading))) | |
120 | |
121 (defvar outline-mode-map nil "") | |
122 | |
123 (if outline-mode-map | |
124 nil | |
125 (setq outline-mode-map (nconc (make-sparse-keymap) text-mode-map)) | |
126 (define-key outline-mode-map "\C-c" outline-mode-prefix-map) | |
127 (define-key outline-mode-map [menu-bar] outline-mode-menu-bar-map)) | |
128 | |
129 (defvar outline-minor-mode nil | |
130 "Non-nil if using Outline mode as a minor mode of some other mode.") | |
131 (make-variable-buffer-local 'outline-minor-mode) | |
132 (put 'outline-minor-mode 'permanent-local t) | |
133 (or (assq 'outline-minor-mode minor-mode-alist) | |
134 (setq minor-mode-alist (append minor-mode-alist | |
135 (list '(outline-minor-mode " Outl"))))) | |
136 | |
137 (defvar outline-font-lock-keywords | |
138 '(;; Highlight headings according to the level. | |
139 ("^\\(\\*+\\)[ \t]*\\(.+\\)?[ \t]*$" | |
140 (1 font-lock-string-face) | |
141 (2 (let ((len (- (match-end 1) (match-beginning 1)))) | |
142 (or (cdr (assq len '((1 . font-lock-function-name-face) | |
143 (2 . font-lock-keyword-face) | |
144 (3 . font-lock-comment-face)))) | |
145 font-lock-variable-name-face)) | |
146 nil t)) | |
147 ;; Highight citations of the form [1] and [Mar94]. | |
148 ("\\[\\([A-Z][A-Za-z]+\\)*[0-9]+\\]" . font-lock-type-face)) | |
149 "Additional expressions to highlight in Outline mode.") | |
150 | |
151 ;;;###autoload | |
152 (defun outline-mode () | |
153 "Set major mode for editing outlines with selective display. | |
154 Headings are lines which start with asterisks: one for major headings, | |
155 two for subheadings, etc. Lines not starting with asterisks are body lines. | |
156 | |
157 Body text or subheadings under a heading can be made temporarily | |
158 invisible, or visible again. Invisible lines are attached to the end | |
159 of the heading, so they move with it, if the line is killed and yanked | |
160 back. A heading with text hidden under it is marked with an ellipsis (...). | |
161 | |
162 Commands:\\<outline-mode-map> | |
163 \\[outline-next-visible-heading] outline-next-visible-heading move by visible headings | |
164 \\[outline-previous-visible-heading] outline-previous-visible-heading | |
165 \\[outline-forward-same-level] outline-forward-same-level similar but skip subheadings | |
166 \\[outline-backward-same-level] outline-backward-same-level | |
167 \\[outline-up-heading] outline-up-heading move from subheading to heading | |
168 | |
169 \\[hide-body] make all text invisible (not headings). | |
170 \\[show-all] make everything in buffer visible. | |
171 | |
172 The remaining commands are used when point is on a heading line. | |
173 They apply to some of the body or subheadings of that heading. | |
174 \\[hide-subtree] hide-subtree make body and subheadings invisible. | |
175 \\[show-subtree] show-subtree make body and subheadings visible. | |
176 \\[show-children] show-children make direct subheadings visible. | |
177 No effect on body, or subheadings 2 or more levels down. | |
178 With arg N, affects subheadings N levels down. | |
179 \\[hide-entry] make immediately following body invisible. | |
180 \\[show-entry] make it visible. | |
181 \\[hide-leaves] make body under heading and under its subheadings invisible. | |
182 The subheadings remain visible. | |
183 \\[show-branches] make all subheadings at all levels visible. | |
184 | |
185 The variable `outline-regexp' can be changed to control what is a heading. | |
186 A line is a heading if `outline-regexp' matches something at the | |
187 beginning of the line. The longer the match, the deeper the level. | |
188 | |
189 Turning on outline mode calls the value of `text-mode-hook' and then of | |
190 `outline-mode-hook', if they are non-nil." | |
191 (interactive) | |
192 (kill-all-local-variables) | |
193 (use-local-map outline-mode-map) | |
194 (setq mode-name "Outline") | |
195 (setq major-mode 'outline-mode) | |
196 (define-abbrev-table 'text-mode-abbrev-table ()) | |
197 (setq local-abbrev-table text-mode-abbrev-table) | |
198 (set-syntax-table text-mode-syntax-table) | |
199 (make-local-variable 'line-move-ignore-invisible) | |
200 (setq line-move-ignore-invisible t) | |
201 ;; Cause use of ellipses for invisible text. | |
202 (setq buffer-invisibility-spec '((t . t))) | |
203 (make-local-variable 'paragraph-start) | |
204 (setq paragraph-start (concat paragraph-start "\\|\\(" | |
205 outline-regexp "\\)")) | |
206 ;; Inhibit auto-filling of header lines. | |
207 (make-local-variable 'auto-fill-inhibit-regexp) | |
208 (setq auto-fill-inhibit-regexp outline-regexp) | |
209 (make-local-variable 'paragraph-separate) | |
210 (setq paragraph-separate (concat paragraph-separate "\\|\\(" | |
211 outline-regexp "\\)")) | |
212 (make-local-variable 'font-lock-defaults) | |
213 (setq font-lock-defaults '(outline-font-lock-keywords t)) | |
214 (make-local-variable 'change-major-mode-hook) | |
215 (add-hook 'change-major-mode-hook 'show-all) | |
216 (run-hooks 'text-mode-hook 'outline-mode-hook)) | |
217 | |
218 (defvar outline-minor-mode-prefix "\C-c\C-o" | |
219 "*Prefix key to use for Outline commands in Outline minor mode. | |
220 The value of this variable is checked as part of loading Outline mode. | |
221 After that, changing the prefix key requires manipulating keymaps.") | |
222 | |
223 (defvar outline-minor-mode-map nil) | |
224 (if outline-minor-mode-map | |
225 nil | |
226 (setq outline-minor-mode-map (make-sparse-keymap)) | |
227 (define-key outline-minor-mode-map [menu-bar] | |
228 outline-mode-menu-bar-map) | |
229 (define-key outline-minor-mode-map outline-minor-mode-prefix | |
230 outline-mode-prefix-map)) | |
231 | |
232 (or (assq 'outline-minor-mode minor-mode-map-alist) | |
233 (setq minor-mode-map-alist | |
234 (cons (cons 'outline-minor-mode outline-minor-mode-map) | |
235 minor-mode-map-alist))) | |
236 | |
237 ;;;###autoload | |
238 (defun outline-minor-mode (&optional arg) | |
239 "Toggle Outline minor mode. | |
240 With arg, turn Outline minor mode on if arg is positive, off otherwise. | |
241 See the command `outline-mode' for more information on this mode." | |
242 (interactive "P") | |
243 (setq outline-minor-mode | |
244 (if (null arg) (not outline-minor-mode) | |
245 (> (prefix-numeric-value arg) 0))) | |
246 (if outline-minor-mode | |
247 (progn | |
248 (make-local-variable 'line-move-ignore-invisible) | |
249 (setq line-move-ignore-invisible t) | |
250 ;; Cause use of ellipses for invisible text. | |
251 (setq buffer-invisibility-spec '((t . t)))) | |
252 (run-hooks 'outline-minor-mode-hook) | |
253 (setq line-move-ignore-invisible nil) | |
254 ;; Cause use of ellipses for invisible text. | |
255 (setq buffer-invisibility-spec t)) | |
256 ;; When turning off outline mode, get rid of any invisible props. | |
257 (or outline-minor-mode | |
258 (outline-flag-region (point-min) (point-max) nil)) | |
259 (set-buffer-modified-p (buffer-modified-p))) | |
260 | |
261 (defvar outline-level 'outline-level | |
262 "Function of no args to compute a header's nesting level in an outline. | |
263 It can assume point is at the beginning of a header line.") | |
264 | |
265 ;; This used to count columns rather than characters, but that made ^L | |
266 ;; appear to be at level 2 instead of 1. Columns would be better for | |
267 ;; tab handling, but the default regexp doesn't use tabs, and anyone | |
268 ;; who changes the regexp can also redefine the outline-level variable | |
269 ;; as appropriate. | |
270 (defun outline-level () | |
271 "Return the depth to which a statement is nested in the outline. | |
272 Point must be at the beginning of a header line. This is actually | |
273 the number of characters that `outline-regexp' matches." | |
274 (save-excursion | |
275 (looking-at outline-regexp) | |
276 (- (match-end 0) (match-beginning 0)))) | |
277 | |
278 (defun outline-next-preface () | |
279 "Skip forward to just before the next heading line. | |
280 If there's no following heading line, stop before the newline | |
281 at the end of the buffer." | |
282 (if (re-search-forward (concat "\n\\(" outline-regexp "\\)") | |
283 nil 'move) | |
284 (goto-char (match-beginning 0))) | |
285 (if (bolp) | |
286 (forward-char -1))) | |
287 | |
288 (defun outline-next-heading () | |
289 "Move to the next (possibly invisible) heading line." | |
290 (interactive) | |
291 (if (re-search-forward (concat "^\\(" outline-regexp "\\)") | |
292 nil 'move) | |
293 (goto-char (1+ (match-beginning 0))))) | |
294 | |
295 (defsubst outline-visible () | |
296 "Non-nil if the character after point is visible." | |
297 (not (get-char-property (point) 'invisible))) | |
298 | |
299 (defun outline-back-to-heading () | |
300 "Move to previous heading line, or beg of this line if it's a heading. | |
301 Only visible heading lines are considered." | |
302 (beginning-of-line) | |
303 (or (outline-on-heading-p) | |
304 (let (found) | |
305 (while (not found) | |
306 (setq found | |
307 (and (re-search-backward (concat "^\\(" outline-regexp "\\)") | |
308 nil t) | |
309 (outline-visible)))) | |
310 found) | |
311 (error "before first heading"))) | |
312 | |
313 (defun outline-on-heading-p () | |
314 "Return t if point is on a (visible) heading line." | |
315 (save-excursion | |
316 (beginning-of-line) | |
317 (and (bolp) (outline-visible) | |
318 (looking-at outline-regexp)))) | |
319 | |
320 (defun outline-end-of-heading () | |
321 (if (re-search-forward outline-heading-end-regexp nil 'move) | |
322 (forward-char -1))) | |
323 | |
324 (defun outline-next-visible-heading (arg) | |
325 "Move to the next visible heading line. | |
326 With argument, repeats or can move backward if negative. | |
327 A heading line is one that starts with a `*' (or that | |
328 `outline-regexp' matches)." | |
329 (interactive "p") | |
330 (if (< arg 0) | |
331 (beginning-of-line) | |
332 (end-of-line)) | |
333 (let (found) | |
334 (or (while (and found (> arg 0)) | |
335 (setq found nil) | |
336 (while (not found) | |
337 (setq found | |
338 (and (re-search-backward (concat "^\\(" outline-regexp "\\)") | |
339 nil t) | |
340 (outline-visible)))) | |
341 (setq arg (1- arg))) | |
342 (error ""))) | |
343 (beginning-of-line)) | |
344 | |
345 (defun outline-previous-visible-heading (arg) | |
346 "Move to the previous heading line. | |
347 With argument, repeats or can move forward if negative. | |
348 A heading line is one that starts with a `*' (or that | |
349 `outline-regexp' matches)." | |
350 (interactive "p") | |
351 (outline-next-visible-heading (- arg))) | |
352 | |
353 (defun outline-flag-region (from to flag) | |
354 "Hides or shows lines from FROM to TO, according to FLAG. | |
355 If FLAG is nil then text is shown, while if FLAG is t the text is hidden." | |
356 (let ((inhibit-read-only t)) | |
357 (save-excursion | |
358 (goto-char from) | |
359 (end-of-line) | |
10996
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
360 (outline-discard-overlays (point) to 'outline) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
361 (if flag |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
362 (let ((o (make-overlay (point) to))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
363 (overlay-put o 'invisible flag) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
364 (overlay-put o 'outline t)))))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
365 |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
366 (defun outline-discard-overlays (beg end prop) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
367 (if (< end beg) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
368 (setq beg (prog1 end (setq end beg)))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
369 (save-excursion |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
370 (goto-char beg) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
371 (while (< (point) end) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
372 (let ((overlays (overlays-at (point)))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
373 (while overlays |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
374 (let ((o (car overlays))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
375 (if (overlay-get o prop) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
376 ;; Either push this overlay outside beg...end |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
377 ;; or split it to exclude beg...end |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
378 ;; or delete it entirely (if it is contained in beg...end). |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
379 (if (< (overlay-start o) beg) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
380 (if (> (overlay-end o) end) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
381 (let ((o1 (outline-copy-overlay o))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
382 (move-overlay o1 (overlay-start o1) beg) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
383 (move-overlay o (overlay-start o) beg))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
384 (if (> (overlay-end o) end) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
385 (move-overlay o end (overlay-end o)) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
386 (delete-overlay o))))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
387 (setq overlays (cdr overlays)))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
388 (goto-char (next-overlay-change (point)))))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
389 |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
390 (defun outline-copy-overlay (o) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
391 (let ((o1 (make-overlay (overlay-start o) (overlay-end o))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
392 (props (overlay-properties o))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
393 (while props |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
394 (overlay-put o1 (car props) (nth 1 props)) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
395 (setq props (cdr (cdr props)))) |
356f658dbd65
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
10950
diff
changeset
|
396 o1)) |
10950 | 397 |
398 (defun hide-entry () | |
399 "Hide the body directly following this heading." | |
400 (interactive) | |
401 (outline-back-to-heading) | |
402 (outline-end-of-heading) | |
403 (save-excursion | |
404 (outline-flag-region (point) (progn (outline-next-preface) (point)) t))) | |
405 | |
406 (defun show-entry () | |
407 "Show the body directly following this heading." | |
408 (interactive) | |
409 (save-excursion | |
410 (outline-flag-region (point) (progn (outline-next-preface) (point)) nil))) | |
411 | |
412 (defun hide-body () | |
413 "Hide all of buffer except headings." | |
414 (interactive) | |
415 (hide-region-body (point-min) (point-max))) | |
416 | |
417 (defun hide-region-body (start end) | |
418 "Hide all body lines in the region, but not headings." | |
419 (save-excursion | |
420 (save-restriction | |
421 (narrow-to-region start end) | |
422 (goto-char (point-min)) | |
423 (if (outline-on-heading-p) | |
424 (outline-end-of-heading)) | |
425 (while (not (eobp)) | |
426 (outline-flag-region (point) | |
427 (progn (outline-next-preface) (point)) t) | |
428 (if (not (eobp)) | |
429 (progn | |
430 (forward-char | |
431 (if (looking-at "\n\n") | |
432 2 1)) | |
433 (outline-end-of-heading))))))) | |
434 | |
435 (defun show-all () | |
436 "Show all of the text in the buffer." | |
437 (interactive) | |
438 (outline-flag-region (point-min) (point-max) nil)) | |
439 | |
440 (defun hide-subtree () | |
441 "Hide everything after this heading at deeper levels." | |
442 (interactive) | |
443 (outline-flag-subtree t)) | |
444 | |
445 (defun hide-leaves () | |
446 "Hide all body after this heading at deeper levels." | |
447 (interactive) | |
448 (outline-back-to-heading) | |
449 (outline-end-of-heading) | |
450 (hide-region-body (point) (progn (outline-end-of-subtree) (point)))) | |
451 | |
452 (defun show-subtree () | |
453 "Show everything after this heading at deeper levels." | |
454 (interactive) | |
455 (outline-flag-subtree nil)) | |
456 | |
457 (defun hide-sublevels (levels) | |
458 "Hide everything but the top LEVELS levels of headers, in whole buffer." | |
459 (interactive "p") | |
460 (if (< levels 1) | |
461 (error "Must keep at least one level of headers")) | |
462 (setq levels (1- levels)) | |
463 (save-excursion | |
464 (goto-char (point-min)) | |
465 ;; Keep advancing to the next top-level heading. | |
466 (while (or (and (bobp) (outline-on-heading-p)) | |
467 (outline-next-heading)) | |
468 (let ((end (save-excursion (outline-end-of-subtree) (point)))) | |
469 ;; Hide everything under that. | |
470 (outline-flag-region (point) end t) | |
471 ;; Show the first LEVELS levels under that. | |
472 (if (> levels 0) | |
473 (show-children levels)) | |
474 ;; Move to the next, since we already found it. | |
475 (goto-char end))))) | |
476 | |
477 (defun hide-other () | |
478 "Hide everything except for the current body and the parent headings." | |
479 (interactive) | |
480 (hide-sublevels 1) | |
481 (let ((last (point)) | |
482 (pos (point))) | |
483 (while (save-excursion | |
484 (and (end-of-line 0) | |
485 (not (outline-visible)))) | |
486 (save-excursion | |
487 (beginning-of-line) | |
488 (if (eq last (point)) | |
489 (progn | |
490 (outline-next-heading) | |
491 (outline-flag-region last (point) nil)) | |
492 (show-children) | |
493 (setq last (point))))))) | |
494 | |
495 (defun outline-flag-subtree (flag) | |
496 (save-excursion | |
497 (outline-back-to-heading) | |
498 (outline-end-of-heading) | |
499 (outline-flag-region (point) | |
500 (progn (outline-end-of-subtree) (point)) | |
501 flag))) | |
502 | |
503 (defun outline-end-of-subtree () | |
504 (outline-back-to-heading) | |
505 (let ((opoint (point)) | |
506 (first t) | |
507 (level (funcall outline-level))) | |
508 (while (and (not (eobp)) | |
509 (or first (> (funcall outline-level) level))) | |
510 (setq first nil) | |
511 (outline-next-heading)) | |
512 (if (bolp) | |
513 (progn | |
514 ;; Go to end of line before heading | |
515 (forward-char -1) | |
516 (if (bolp) | |
517 ;; leave blank line before heading | |
518 (forward-char -1)))))) | |
519 | |
520 (defun show-branches () | |
521 "Show all subheadings of this heading, but not their bodies." | |
522 (interactive) | |
523 (show-children 1000)) | |
524 | |
525 (defun show-children (&optional level) | |
526 "Show all direct subheadings of this heading. | |
527 Prefix arg LEVEL is how many levels below the current level should be shown. | |
528 Default is enough to cause the following heading to appear." | |
529 (interactive "P") | |
530 (setq level | |
531 (if level (prefix-numeric-value level) | |
532 (save-excursion | |
533 (outline-back-to-heading) | |
534 (let ((start-level (funcall outline-level))) | |
535 (outline-next-heading) | |
536 (if (eobp) | |
537 1 | |
538 (max 1 (- (funcall outline-level) start-level))))))) | |
539 (save-excursion | |
540 (save-restriction | |
541 (outline-back-to-heading) | |
542 (setq level (+ level (funcall outline-level))) | |
543 (narrow-to-region (point) | |
544 (progn (outline-end-of-subtree) | |
545 (if (eobp) (point-max) (1+ (point))))) | |
546 (goto-char (point-min)) | |
547 (while (and (not (eobp)) | |
548 (progn | |
549 (outline-next-heading) | |
550 (not (eobp)))) | |
551 (if (<= (funcall outline-level) level) | |
552 (save-excursion | |
553 (outline-flag-region (save-excursion | |
554 (forward-char -1) | |
555 (if (bolp) | |
556 (forward-char -1)) | |
557 (point)) | |
558 (progn (outline-end-of-heading) (point)) | |
559 nil))))))) | |
560 | |
561 (defun outline-up-heading (arg) | |
562 "Move to the heading line of which the present line is a subheading. | |
563 With argument, move up ARG levels." | |
564 (interactive "p") | |
565 (outline-back-to-heading) | |
566 (if (eq (funcall outline-level) 1) | |
567 (error "")) | |
568 (while (and (> (funcall outline-level) 1) | |
569 (> arg 0) | |
570 (not (bobp))) | |
571 (let ((present-level (funcall outline-level))) | |
572 (while (not (< (funcall outline-level) present-level)) | |
573 (outline-previous-visible-heading 1)) | |
574 (setq arg (- arg 1))))) | |
575 | |
576 (defun outline-forward-same-level (arg) | |
577 "Move forward to the ARG'th subheading at same level as this one. | |
578 Stop at the first and last subheadings of a superior heading." | |
579 (interactive "p") | |
580 (outline-back-to-heading) | |
581 (while (> arg 0) | |
582 (let ((point-to-move-to (save-excursion | |
583 (outline-get-next-sibling)))) | |
584 (if point-to-move-to | |
585 (progn | |
586 (goto-char point-to-move-to) | |
587 (setq arg (1- arg))) | |
588 (progn | |
589 (setq arg 0) | |
590 (error "")))))) | |
591 | |
592 (defun outline-get-next-sibling () | |
593 "Move to next heading of the same level, and return point or nil if none." | |
594 (let ((level (funcall outline-level))) | |
595 (outline-next-visible-heading 1) | |
596 (while (and (> (funcall outline-level) level) | |
597 (not (eobp))) | |
598 (outline-next-visible-heading 1)) | |
599 (if (< (funcall outline-level) level) | |
600 nil | |
601 (point)))) | |
602 | |
603 (defun outline-backward-same-level (arg) | |
604 "Move backward to the ARG'th subheading at same level as this one. | |
605 Stop at the first and last subheadings of a superior heading." | |
606 (interactive "p") | |
607 (outline-back-to-heading) | |
608 (while (> arg 0) | |
609 (let ((point-to-move-to (save-excursion | |
610 (outline-get-last-sibling)))) | |
611 (if point-to-move-to | |
612 (progn | |
613 (goto-char point-to-move-to) | |
614 (setq arg (1- arg))) | |
615 (progn | |
616 (setq arg 0) | |
617 (error "")))))) | |
618 | |
619 (defun outline-get-last-sibling () | |
620 "Move to next heading of the same level, and return point or nil if none." | |
621 (let ((level (funcall outline-level))) | |
622 (outline-previous-visible-heading 1) | |
623 (while (and (> (funcall outline-level) level) | |
624 (not (bobp))) | |
625 (outline-previous-visible-heading 1)) | |
626 (if (< (funcall outline-level) level) | |
627 nil | |
628 (point)))) | |
629 | |
630 (provide 'outline) | |
631 | |
632 ;;; outline.el ends here |