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