annotate lisp/modes/outline.el @ 0:376386a54a3c r19-14

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