annotate lisp/textmodes/ooutline.el @ 4027:afa1ecd408e1

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