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