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