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