annotate lisp/textmodes/ooutline.el @ 6080:2f02deab5b9e

(hide-sublevels): Doc fix. Rename arg.
author Richard M. Stallman <rms@gnu.org>
date Thu, 24 Feb 1994 23:43:30 +0000
parents 7c17887a0daf
children 340f5eb2e8b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
1 ;;; outline.el --- outline mode commands for Emacs
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
2
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
213978acbc1e entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
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
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
10
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
12
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
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
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
16 ;; any later version.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
17
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
22
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
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
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
35 ;; Jan '86, Some new features added by Peter Desnoyers and rewritten by RMS.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
36
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
37 (defvar outline-regexp "[*\^l]+"
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
38 "*Regular expression to match the beginning of a heading.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
39 Any line whose beginning matches this regexp is considered to start a heading.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
40 The recommended way to set this is with a Local Variables: list
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
41 in the file it applies to. See also outline-heading-end-regexp.")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
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
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
44 "*Regular expression to match the end of a heading line.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
45 You can assume that point is at the beginning of a heading when this
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
46 regexp is searched for. The heading ends at the end of the match.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
47 The recommended way to set this is with a \"Local Variables:\" list
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
48 in the file it applies to.")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
49
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
50 (defvar outline-mode-map nil "")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
51
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
52 (if outline-mode-map
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
53 nil
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
54 (setq outline-mode-map (nconc (make-sparse-keymap) text-mode-map))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
55 (define-key outline-mode-map "\C-c\C-n" 'outline-next-visible-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
56 (define-key outline-mode-map "\C-c\C-p" 'outline-previous-visible-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
57 (define-key outline-mode-map "\C-c\C-i" 'show-children)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
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
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
60 (define-key outline-mode-map "\C-c\C-u" 'outline-up-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
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)
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-q" 'outline-hide-sublevels)
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-o" 'outline-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
6077
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
75 (define-key outline-mode-map [menu-bar hide hide-other]
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
76 '("Hide Other" . outline-hide-other))
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
77 (define-key outline-mode-map [menu-bar hide hide-sublevels]
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
78 '("Hide Sublevels" . outline-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
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
115
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
116 (defvar outline-minor-mode nil
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
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
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
123
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 234
diff changeset
124 ;;;###autoload
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
125 (defun outline-mode ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
126 "Set major mode for editing outlines with selective display.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
127 Headings are lines which start with asterisks: one for major headings,
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
128 two for subheadings, etc. Lines not starting with asterisks are body lines.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
129
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
130 Body text or subheadings under a heading can be made temporarily
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
131 invisible, or visible again. Invisible lines are attached to the end
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
132 of the heading, so they move with it, if the line is killed and yanked
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
133 back. A heading with text hidden under it is marked with an ellipsis (...).
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
134
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
135 Commands:\\<outline-mode-map>
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
136 \\[outline-next-visible-heading] outline-next-visible-heading move by visible headings
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
137 \\[outline-previous-visible-heading] outline-previous-visible-heading
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
138 \\[outline-forward-same-level] outline-forward-same-level similar but skip subheadings
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
139 \\[outline-backward-same-level] outline-backward-same-level
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
140 \\[outline-up-heading] outline-up-heading move from subheading to heading
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
141
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
142 M-x hide-body make all text invisible (not headings).
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
143 M-x show-all make everything in buffer visible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
144
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
145 The remaining commands are used when point is on a heading line.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
146 They apply to some of the body or subheadings of that heading.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
147 \\[hide-subtree] hide-subtree make body and subheadings invisible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
148 \\[show-subtree] show-subtree make body and subheadings visible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
149 \\[show-children] show-children make direct subheadings visible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
150 No effect on body, or subheadings 2 or more levels down.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
151 With arg N, affects subheadings N levels down.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
152 M-x hide-entry make immediately following body invisible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
153 M-x show-entry make it visible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
154 M-x hide-leaves make body under heading and under its subheadings invisible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
155 The subheadings remain visible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
156 M-x show-branches make all subheadings at all levels visible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
157
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
158 The variable `outline-regexp' can be changed to control what is a heading.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
159 A line is a heading if `outline-regexp' matches something at the
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
160 beginning of the line. The longer the match, the deeper the level.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
161
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
162 Turning on outline mode calls the value of `text-mode-hook' and then of
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
163 `outline-mode-hook', if they are non-nil."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
164 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
165 (kill-all-local-variables)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
166 (setq selective-display t)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
167 (use-local-map outline-mode-map)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
168 (setq mode-name "Outline")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
169 (setq major-mode 'outline-mode)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
170 (define-abbrev-table 'text-mode-abbrev-table ())
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
171 (setq local-abbrev-table text-mode-abbrev-table)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
172 (set-syntax-table text-mode-syntax-table)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
173 (make-local-variable 'paragraph-start)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
174 (setq paragraph-start (concat paragraph-start "\\|^\\("
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
175 outline-regexp "\\)"))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
176 ;; Inhibit auto-filling of header lines.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
177 (make-local-variable 'auto-fill-inhibit-regexp)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
178 (setq auto-fill-inhibit-regexp outline-regexp)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
179 (make-local-variable 'paragraph-separate)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
180 (setq paragraph-separate (concat paragraph-separate "\\|^\\("
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
181 outline-regexp "\\)"))
5876
82e1a78ab625 (outline-mode): Fix spelling of add-hook.
Karl Heuer <kwzh@gnu.org>
parents: 5855
diff changeset
182 (add-hook 'change-major-mode-hook 'show-all)
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
183 (run-hooks 'text-mode-hook 'outline-mode-hook))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
184
6077
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
185 (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
186 "*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
187
2900
443ebd8f59d2 (outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 2308
diff changeset
188 (defvar outline-minor-mode-map nil)
443ebd8f59d2 (outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 2308
diff changeset
189 (if outline-minor-mode-map
443ebd8f59d2 (outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 2308
diff changeset
190 nil
443ebd8f59d2 (outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 2308
diff changeset
191 (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
192 (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
193 (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
194 (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
195 (lookup-key outline-mode-map "\C-c")))
443ebd8f59d2 (outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 2308
diff changeset
196
443ebd8f59d2 (outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 2308
diff changeset
197 (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
198 (setq minor-mode-map-alist
443ebd8f59d2 (outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 2308
diff changeset
199 (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
200 minor-mode-map-alist)))
443ebd8f59d2 (outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 2308
diff changeset
201
3531
0732700eb6c0 (outline-minor-mode): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents: 3376
diff changeset
202 ;;;###autoload
2900
443ebd8f59d2 (outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 2308
diff changeset
203 (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
204 "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
205 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
206 See the command `outline-mode' for more information on this mode."
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
207 (interactive "P")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
208 (setq outline-minor-mode
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
209 (if (null arg) (not outline-minor-mode)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
210 (> (prefix-numeric-value arg) 0)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
211 (if outline-minor-mode
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
212 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
213 (setq selective-display t)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
214 (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
215 (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
216 ;; 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
217 (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
218 (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
219 (set-buffer-modified-p (buffer-modified-p)))
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
220
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
221 (defvar outline-level 'outline-level
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
222 "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
223 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
224
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
225 (defun outline-level ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
226 "Return the depth to which a statement is nested in the outline.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
227 Point must be at the beginning of a header line. This is actually
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
228 the column number of the end of what `outline-regexp matches'."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
229 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
230 (looking-at outline-regexp)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
231 (save-excursion (goto-char (match-end 0)) (current-column))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
232
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
233 (defun outline-next-preface ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
234 "Skip forward to just before the next heading line."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
235 (if (re-search-forward (concat "[\n\^M]\\(" outline-regexp "\\)")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
236 nil 'move)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
237 (goto-char (match-beginning 0)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
238 (if (memq (preceding-char) '(?\n ?\^M))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
239 (forward-char -1)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
240
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
241 (defun outline-next-heading ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
242 "Move to the next (possibly invisible) heading line."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
243 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
244 (if (re-search-forward (concat "[\n\^M]\\(" outline-regexp "\\)")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
245 nil 'move)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
246 (goto-char (1+ (match-beginning 0)))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
247
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
248 (defun outline-back-to-heading ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
249 "Move to previous (possibly invisible) heading line,
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
250 or to the beginning of this line if it is a heading line."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
251 (beginning-of-line)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
252 (or (outline-on-heading-p)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
253 (re-search-backward (concat "^\\(" outline-regexp "\\)") nil 'move)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
254
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
255 (defun outline-on-heading-p ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
256 "Return T if point is on a header line."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
257 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
258 (beginning-of-line)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
259 (and (eq (preceding-char) ?\n)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
260 (looking-at outline-regexp))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
261
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
262 (defun outline-end-of-heading ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
263 (if (re-search-forward outline-heading-end-regexp nil 'move)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
264 (forward-char -1)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
265
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
266 (defun outline-next-visible-heading (arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
267 "Move to the next visible heading line.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
268 With argument, repeats or can move backward if negative.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
269 A heading line is one that starts with a `*' (or that
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
270 `outline-regexp' matches)."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
271 (interactive "p")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
272 (if (< arg 0)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
273 (beginning-of-line)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
274 (end-of-line))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
275 (re-search-forward (concat "^\\(" outline-regexp "\\)") nil nil arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
276 (beginning-of-line))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
277
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
278 (defun outline-previous-visible-heading (arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
279 "Move to the previous heading line.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
280 With argument, repeats or can move forward if negative.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
281 A heading line is one that starts with a `*' (or that
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
282 `outline-regexp' matches)."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
283 (interactive "p")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
284 (outline-next-visible-heading (- arg)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
285
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
286 (defun outline-flag-region (from to flag)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
287 "Hides or shows lines from FROM to TO, according to FLAG.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
288 If FLAG is `\\n' (newline character) then text is shown,
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
289 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
290 (let (buffer-read-only)
898d7a33c038 (outline-flag-region): Pass t as NOUNDO arg
Richard M. Stallman <rms@gnu.org>
parents: 2934
diff changeset
291 (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
292 (if (= flag ?\n) ?\^M ?\n)
898d7a33c038 (outline-flag-region): Pass t as NOUNDO arg
Richard M. Stallman <rms@gnu.org>
parents: 2934
diff changeset
293 flag t)))
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
294
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
295 (defun hide-entry ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
296 "Hide the body directly following this heading."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
297 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
298 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
299 (outline-end-of-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
300 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
301 (outline-flag-region (point) (progn (outline-next-preface) (point)) ?\^M)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
302
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
303 (defun show-entry ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
304 "Show the body directly following this heading."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
305 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
306 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
307 (outline-flag-region (point) (progn (outline-next-preface) (point)) ?\n)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
308
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
309 (defun hide-body ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
310 "Hide all of buffer except headings."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
311 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
312 (hide-region-body (point-min) (point-max)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
313
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
314 (defun hide-region-body (start end)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
315 "Hide all body lines in the region, but not headings."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
316 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
317 (save-restriction
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
318 (narrow-to-region start end)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
319 (goto-char (point-min))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
320 (if (outline-on-heading-p)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
321 (outline-end-of-heading))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
322 (while (not (eobp))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
323 (outline-flag-region (point)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
324 (progn (outline-next-preface) (point)) ?\^M)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
325 (if (not (eobp))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
326 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
327 (forward-char
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
328 (if (looking-at "[\n\^M][\n\^M]")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
329 2 1))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
330 (outline-end-of-heading)))))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
331
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
332 (defun show-all ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
333 "Show all of the text in the buffer."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
334 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
335 (outline-flag-region (point-min) (point-max) ?\n))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
336
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
337 (defun hide-subtree ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
338 "Hide everything after this heading at deeper levels."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
339 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
340 (outline-flag-subtree ?\^M))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
341
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
342 (defun hide-leaves ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
343 "Hide all body after this heading at deeper levels."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
344 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
345 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
346 (outline-end-of-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
347 (hide-region-body (point) (progn (outline-end-of-subtree) (point))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
348
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
349 (defun show-subtree ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
350 "Show everything after this heading at deeper levels."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
351 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
352 (outline-flag-subtree ?\n))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
353
6080
2f02deab5b9e (hide-sublevels): Doc fix. Rename arg.
Richard M. Stallman <rms@gnu.org>
parents: 6077
diff changeset
354 (defun hide-sublevels (levels)
2f02deab5b9e (hide-sublevels): Doc fix. Rename arg.
Richard M. Stallman <rms@gnu.org>
parents: 6077
diff changeset
355 "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
356 (interactive "p")
6080
2f02deab5b9e (hide-sublevels): Doc fix. Rename arg.
Richard M. Stallman <rms@gnu.org>
parents: 6077
diff changeset
357 (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
358 (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
359 (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
360 (save-excursion
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
361 (goto-char (point-min))
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
362 (hide-subtree)
6080
2f02deab5b9e (hide-sublevels): Doc fix. Rename arg.
Richard M. Stallman <rms@gnu.org>
parents: 6077
diff changeset
363 (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
364 (condition-case err
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
365 (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
366 (hide-subtree)
6080
2f02deab5b9e (hide-sublevels): Doc fix. Rename arg.
Richard M. Stallman <rms@gnu.org>
parents: 6077
diff changeset
367 (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
368 (error nil))))
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
369
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
370 (defun hide-other ()
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
371 "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
372 (interactive)
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
373 (outline-hide-sublevels 1)
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
374 (let ((last (point))
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
375 (pos (point)))
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
376 (while (save-excursion
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
377 (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
378 (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
379 (save-excursion
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
380 (beginning-of-line)
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
381 (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
382 (progn
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
383 (outline-next-heading)
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
384 (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
385 (show-children)
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
386 (setq last (point)))))))
7c17887a0daf (outline-minor-mode-prefix): Change to C-c C-o.
Richard M. Stallman <rms@gnu.org>
parents: 5876
diff changeset
387
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
388 (defun outline-flag-subtree (flag)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
389 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
390 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
391 (outline-end-of-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
392 (outline-flag-region (point)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
393 (progn (outline-end-of-subtree) (point))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
394 flag)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
395
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
396 (defun outline-end-of-subtree ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
397 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
398 (let ((opoint (point))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
399 (first t)
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
400 (level (funcall outline-level)))
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
401 (while (and (not (eobp))
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
402 (or first (> (funcall outline-level) level)))
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
403 (setq first nil)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
404 (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
405 (if (eobp)
730053369cab (outline-end-of-subtree): If loop leaves us at eob,
Richard M. Stallman <rms@gnu.org>
parents: 5781
diff changeset
406 nil
730053369cab (outline-end-of-subtree): If loop leaves us at eob,
Richard M. Stallman <rms@gnu.org>
parents: 5781
diff changeset
407 ;; 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
408 (forward-char -1)
730053369cab (outline-end-of-subtree): If loop leaves us at eob,
Richard M. Stallman <rms@gnu.org>
parents: 5781
diff changeset
409 ;; 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
410 (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
411 (forward-char -1)))))
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
412
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
413 (defun show-branches ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
414 "Show all subheadings of this heading, but not their bodies."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
415 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
416 (show-children 1000))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
417
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
418 (defun show-children (&optional level)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
419 "Show all direct subheadings of this heading.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
420 Prefix arg LEVEL is how many levels below the current level should be shown.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
421 Default is enough to cause the following heading to appear."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
422 (interactive "P")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
423 (setq level
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
424 (if level (prefix-numeric-value level)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
425 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
426 (beginning-of-line)
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
427 (let ((start-level (funcall outline-level)))
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
428 (outline-next-heading)
5711
6f772d7f1289 (show-children): Don't call outline-level at eob.
Richard M. Stallman <rms@gnu.org>
parents: 5693
diff changeset
429 (if (eobp)
6f772d7f1289 (show-children): Don't call outline-level at eob.
Richard M. Stallman <rms@gnu.org>
parents: 5693
diff changeset
430 1
6f772d7f1289 (show-children): Don't call outline-level at eob.
Richard M. Stallman <rms@gnu.org>
parents: 5693
diff changeset
431 (max 1 (- (funcall outline-level) start-level)))))))
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
432 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
433 (save-restriction
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
434 (beginning-of-line)
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
435 (setq level (+ level (funcall outline-level)))
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
436 (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
437 (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
438 (if (eobp) (point-max) (1+ (point)))))
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
439 (goto-char (point-min))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
440 (while (and (not (eobp))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
441 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
442 (outline-next-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
443 (not (eobp))))
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
444 (if (<= (funcall outline-level) level)
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
445 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
446 (outline-flag-region (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
447 (forward-char -1)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
448 (if (memq (preceding-char) '(?\n ?\^M))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
449 (forward-char -1))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
450 (point))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
451 (progn (outline-end-of-heading) (point))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
452 ?\n)))))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
453
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
454 (defun outline-up-heading (arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
455 "Move to the heading line of which the present line is a subheading.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
456 With argument, move up ARG levels."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
457 (interactive "p")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
458 (outline-back-to-heading)
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
459 (if (eq (funcall outline-level) 1)
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
460 (error ""))
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
461 (while (and (> (funcall outline-level) 1)
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
462 (> arg 0)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
463 (not (bobp)))
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
464 (let ((present-level (funcall outline-level)))
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
465 (while (not (< (funcall outline-level) present-level))
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
466 (outline-previous-visible-heading 1))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
467 (setq arg (- arg 1)))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
468
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
469 (defun outline-forward-same-level (arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
470 "Move forward to the ARG'th subheading from here of the same level as the
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
471 present one. It stops at the first and last subheadings of a superior heading."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
472 (interactive "p")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
473 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
474 (while (> arg 0)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
475 (let ((point-to-move-to (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
476 (outline-get-next-sibling))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
477 (if point-to-move-to
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
478 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
479 (goto-char point-to-move-to)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
480 (setq arg (1- arg)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
481 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
482 (setq arg 0)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
483 (error ""))))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
484
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
485 (defun outline-get-next-sibling ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
486 "Position the point at the next heading of the same level,
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
487 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
488 (let ((level (funcall outline-level)))
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
489 (outline-next-visible-heading 1)
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
490 (while (and (> (funcall outline-level) level)
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
491 (not (eobp)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
492 (outline-next-visible-heading 1))
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
493 (if (< (funcall outline-level) level)
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
494 nil
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
495 (point))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
496
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
497 (defun outline-backward-same-level (arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
498 "Move backward to the ARG'th subheading from here of the same level as the
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
499 present one. It stops at the first and last subheadings of a superior heading."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
500 (interactive "p")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
501 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
502 (while (> arg 0)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
503 (let ((point-to-move-to (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
504 (outline-get-last-sibling))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
505 (if point-to-move-to
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
506 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
507 (goto-char point-to-move-to)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
508 (setq arg (1- arg)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
509 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
510 (setq arg 0)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
511 (error ""))))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
512
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
513 (defun outline-get-last-sibling ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
514 "Position the point at the previous heading of the same level,
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
515 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
516 (let ((level (funcall outline-level)))
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
517 (outline-previous-visible-heading 1)
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
518 (while (and (> (funcall outline-level) level)
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
519 (not (bobp)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
520 (outline-previous-visible-heading 1))
4623
3c1c4e9a4464 (outline-level): New var. Everything funcalls this
Richard M. Stallman <rms@gnu.org>
parents: 4622
diff changeset
521 (if (< (funcall outline-level) level)
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
522 nil
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
523 (point))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
524
2900
443ebd8f59d2 (outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 2308
diff changeset
525 (provide 'outline)
443ebd8f59d2 (outline-heading-end-regexp): Fix typo.
Richard M. Stallman <rms@gnu.org>
parents: 2308
diff changeset
526
659
505130d1ddf8 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 258
diff changeset
527 ;;; outline.el ends here