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