annotate lisp/textmodes/ooutline.el @ 294:97aa6a6f9aa5

*** empty log message ***
author Roland McGrath <roland@gnu.org>
date Thu, 20 Jun 1991 12:32:05 +0000
parents 1e0bc00dca7a
children 505130d1ddf8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
1 ;; Outline mode commands for Emacs
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1986 Free Software Foundation, Inc.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
3
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
4 ;; This file is part of GNU Emacs.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
5
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
7 ;; it under the terms of the GNU General Public License as published by
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
8 ;; the Free Software Foundation; either version 1, or (at your option)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
9 ;; any later version.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
10
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is distributed in the hope that it will be useful,
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
14 ;; GNU General Public License for more details.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
15
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
19
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
20 ;; Jan '86, Some new features added by Peter Desnoyers and rewritten by RMS.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
21
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
22 (defvar outline-regexp "[*\^l]+"
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
23 "*Regular expression to match the beginning of a heading.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
24 Any line whose beginning matches this regexp is considered to start a heading.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
25 The recommended way to set this is with a Local Variables: list
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
26 in the file it applies to. See also outline-heading-end-regexp.")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
27
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
28 (defvar outline-heading-end-regexp "[\n^M]"
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
29 "*Regular expression to match the end of a heading line.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
30 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
31 regexp is searched for. The heading ends at the end of the match.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
32 The recommended way to set this is with a \"Local Variables:\" list
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
33 in the file it applies to.")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
34
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
35 (defvar outline-mode-map nil "")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
36
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
37 (if outline-mode-map
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
38 nil
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
39 (setq outline-mode-map (nconc (make-sparse-keymap) text-mode-map))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
40 (define-key outline-mode-map "\C-c\C-n" 'outline-next-visible-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
41 (define-key outline-mode-map "\C-c\C-p" 'outline-previous-visible-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
42 (define-key outline-mode-map "\C-c\C-i" 'show-children)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
43 (define-key outline-mode-map "\C-c\C-s" 'show-subtree)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
44 (define-key outline-mode-map "\C-c\C-h" 'hide-subtree)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
45 (define-key outline-mode-map "\C-c\C-u" 'outline-up-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
46 (define-key outline-mode-map "\C-c\C-f" 'outline-forward-same-level)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
47 (define-key outline-mode-map "\C-c\C-b" 'outline-backward-same-level))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
48
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
49 (defvar outline-minor-mode nil
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
50 "Non-nil if using Outline mode as a minor mode of some other mode.")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
51 (setq minor-mode-alist (append minor-mode-alist
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
52 (list '(outline-minor-mode " Outl"))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
53
258
1e0bc00dca7a *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 234
diff changeset
54 ;;;###autoload
234
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
55 (defun outline-mode ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
56 "Set major mode for editing outlines with selective display.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
57 Headings are lines which start with asterisks: one for major headings,
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
58 two for subheadings, etc. Lines not starting with asterisks are body lines.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
59
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
60 Body text or subheadings under a heading can be made temporarily
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
61 invisible, or visible again. Invisible lines are attached to the end
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
62 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
63 back. A heading with text hidden under it is marked with an ellipsis (...).
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
64
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
65 Commands:\\<outline-mode-map>
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
66 \\[outline-next-visible-heading] outline-next-visible-heading move by visible headings
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
67 \\[outline-previous-visible-heading] outline-previous-visible-heading
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
68 \\[outline-forward-same-level] outline-forward-same-level similar but skip subheadings
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
69 \\[outline-backward-same-level] outline-backward-same-level
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
70 \\[outline-up-heading] outline-up-heading move from subheading to heading
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
71
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
72 M-x hide-body make all text invisible (not headings).
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
73 M-x show-all make everything in buffer visible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
74
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
75 The remaining commands are used when point is on a heading line.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
76 They apply to some of the body or subheadings of that heading.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
77 \\[hide-subtree] hide-subtree make body and subheadings invisible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
78 \\[show-subtree] show-subtree make body and subheadings visible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
79 \\[show-children] show-children make direct subheadings visible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
80 No effect on body, or subheadings 2 or more levels down.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
81 With arg N, affects subheadings N levels down.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
82 M-x hide-entry make immediately following body invisible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
83 M-x show-entry make it visible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
84 M-x hide-leaves make body under heading and under its subheadings invisible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
85 The subheadings remain visible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
86 M-x show-branches make all subheadings at all levels visible.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
87
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
88 The variable `outline-regexp' can be changed to control what is a heading.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
89 A line is a heading if `outline-regexp' matches something at the
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
90 beginning of the line. The longer the match, the deeper the level.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
91
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
92 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
93 `outline-mode-hook', if they are non-nil."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
94 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
95 (kill-all-local-variables)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
96 (setq selective-display t)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
97 (use-local-map outline-mode-map)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
98 (setq mode-name "Outline")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
99 (setq major-mode 'outline-mode)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
100 (define-abbrev-table 'text-mode-abbrev-table ())
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
101 (setq local-abbrev-table text-mode-abbrev-table)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
102 (set-syntax-table text-mode-syntax-table)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
103 (make-local-variable 'paragraph-start)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
104 (setq paragraph-start (concat paragraph-start "\\|^\\("
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
105 outline-regexp "\\)"))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
106 ;; Inhibit auto-filling of header lines.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
107 (make-local-variable 'auto-fill-inhibit-regexp)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
108 (setq auto-fill-inhibit-regexp outline-regexp)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
109 (make-local-variable 'paragraph-separate)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
110 (setq paragraph-separate (concat paragraph-separate "\\|^\\("
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
111 outline-regexp "\\)"))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
112 (run-hooks 'text-mode-hook 'outline-mode-hook))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
113
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
114 (defun outline-minor-mode (arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
115 (interactive "P")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
116 (setq outline-minor-mode
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
117 (if (null arg) (not outline-minor-mode)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
118 (> (prefix-numeric-value arg) 0)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
119 (if outline-minor-mode
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
120 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
121 (setq selective-display t)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
122 (make-local-variable 'outline-old-map)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
123 (setq outline-old-map (current-local-map))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
124 (let ((new-map (copy-keymap outline-old-map)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
125 (define-key new-map "\C-c"
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
126 (lookup-key outline-mode-map "\C-c"))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
127 (use-local-map new-map))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
128 (make-local-variable 'outline-regexp)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
129 (setq outline-regexp "[ \t]*/\\*")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
130 (make-local-variable 'outline-heading-end-regexp)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
131 (setq outline-heading-end-regexp "\\*/[^\n\^M]*[\n\^M]")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
132 (run-hooks 'outline-minor-mode-hook))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
133 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
134 (setq selective-display nil)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
135 (use-local-map outline-old-map))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
136
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
137 (defun outline-level ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
138 "Return the depth to which a statement is nested in the outline.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
139 Point must be at the beginning of a header line. This is actually
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
140 the column number of the end of what `outline-regexp matches'."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
141 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
142 (looking-at outline-regexp)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
143 (save-excursion (goto-char (match-end 0)) (current-column))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
144
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
145 (defun outline-next-preface ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
146 "Skip forward to just before the next heading line."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
147 (if (re-search-forward (concat "[\n\^M]\\(" outline-regexp "\\)")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
148 nil 'move)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
149 (goto-char (match-beginning 0)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
150 (if (memq (preceding-char) '(?\n ?\^M))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
151 (forward-char -1)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
152
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
153 (defun outline-next-heading ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
154 "Move to the next (possibly invisible) heading line."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
155 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
156 (if (re-search-forward (concat "[\n\^M]\\(" outline-regexp "\\)")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
157 nil 'move)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
158 (goto-char (1+ (match-beginning 0)))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
159
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
160 (defun outline-back-to-heading ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
161 "Move to previous (possibly invisible) heading line,
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
162 or to the beginning of this line if it is a heading line."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
163 (beginning-of-line)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
164 (or (outline-on-heading-p)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
165 (re-search-backward (concat "^\\(" outline-regexp "\\)") nil 'move)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
166
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
167 (defun outline-on-heading-p ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
168 "Return T if point is on a header line."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
169 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
170 (beginning-of-line)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
171 (and (eq (preceding-char) ?\n)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
172 (looking-at outline-regexp))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
173
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
174 (defun outline-end-of-heading ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
175 (if (re-search-forward outline-heading-end-regexp nil 'move)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
176 (forward-char -1)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
177
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
178 (defun outline-next-visible-heading (arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
179 "Move to the next visible heading line.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
180 With argument, repeats or can move backward if negative.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
181 A heading line is one that starts with a `*' (or that
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
182 `outline-regexp' matches)."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
183 (interactive "p")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
184 (if (< arg 0)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
185 (beginning-of-line)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
186 (end-of-line))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
187 (re-search-forward (concat "^\\(" outline-regexp "\\)") nil nil arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
188 (beginning-of-line))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
189
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
190 (defun outline-previous-visible-heading (arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
191 "Move to the previous heading line.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
192 With argument, repeats or can move forward if negative.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
193 A heading line is one that starts with a `*' (or that
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
194 `outline-regexp' matches)."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
195 (interactive "p")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
196 (outline-next-visible-heading (- arg)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
197
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
198 (defun outline-flag-region (from to flag)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
199 "Hides or shows lines from FROM to TO, according to FLAG.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
200 If FLAG is `\\n' (newline character) then text is shown,
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
201 while if FLAG is `\\^M' (control-M) the text is hidden."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
202 (let ((modp (buffer-modified-p)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
203 (unwind-protect
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
204 (subst-char-in-region from to
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
205 (if (= flag ?\n) ?\^M ?\n)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
206 flag)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
207 (set-buffer-modified-p modp))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
208
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
209 (defun hide-entry ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
210 "Hide the body directly following this heading."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
211 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
212 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
213 (outline-end-of-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
214 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
215 (outline-flag-region (point) (progn (outline-next-preface) (point)) ?\^M)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
216
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
217 (defun show-entry ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
218 "Show the body directly following this heading."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
219 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
220 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
221 (outline-flag-region (point) (progn (outline-next-preface) (point)) ?\n)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
222
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
223 (defun hide-body ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
224 "Hide all of buffer except headings."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
225 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
226 (hide-region-body (point-min) (point-max)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
227
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
228 (defun hide-region-body (start end)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
229 "Hide all body lines in the region, but not headings."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
230 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
231 (save-restriction
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
232 (narrow-to-region start end)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
233 (goto-char (point-min))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
234 (if (outline-on-heading-p)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
235 (outline-end-of-heading))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
236 (while (not (eobp))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
237 (outline-flag-region (point)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
238 (progn (outline-next-preface) (point)) ?\^M)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
239 (if (not (eobp))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
240 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
241 (forward-char
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
242 (if (looking-at "[\n\^M][\n\^M]")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
243 2 1))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
244 (outline-end-of-heading)))))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
245
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
246 (defun show-all ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
247 "Show all of the text in the buffer."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
248 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
249 (outline-flag-region (point-min) (point-max) ?\n))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
250
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
251 (defun hide-subtree ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
252 "Hide everything after this heading at deeper levels."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
253 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
254 (outline-flag-subtree ?\^M))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
255
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
256 (defun hide-leaves ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
257 "Hide all body after this heading at deeper levels."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
258 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
259 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
260 (outline-end-of-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
261 (hide-region-body (point) (progn (outline-end-of-subtree) (point))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
262
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
263 (defun show-subtree ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
264 "Show everything after this heading at deeper levels."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
265 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
266 (outline-flag-subtree ?\n))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
267
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
268 (defun outline-flag-subtree (flag)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
269 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
270 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
271 (outline-end-of-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
272 (outline-flag-region (point)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
273 (progn (outline-end-of-subtree) (point))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
274 flag)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
275
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
276 (defun outline-end-of-subtree ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
277 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
278 (let ((opoint (point))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
279 (first t)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
280 (level (outline-level)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
281 (while (and (not (eobp))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
282 (or first (> (outline-level) level)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
283 (setq first nil)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
284 (outline-next-heading))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
285 (forward-char -1)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
286 (if (memq (preceding-char) '(?\n ?\^M))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
287 (forward-char -1))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
288
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
289 (defun show-branches ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
290 "Show all subheadings of this heading, but not their bodies."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
291 (interactive)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
292 (show-children 1000))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
293
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
294 (defun show-children (&optional level)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
295 "Show all direct subheadings of this heading.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
296 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
297 Default is enough to cause the following heading to appear."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
298 (interactive "P")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
299 (setq level
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
300 (if level (prefix-numeric-value level)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
301 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
302 (beginning-of-line)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
303 (let ((start-level (outline-level)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
304 (outline-next-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
305 (max 1 (- (outline-level) start-level))))))
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 (save-restriction
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
308 (beginning-of-line)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
309 (setq level (+ level (outline-level)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
310 (narrow-to-region (point)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
311 (progn (outline-end-of-subtree) (1+ (point))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
312 (goto-char (point-min))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
313 (while (and (not (eobp))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
314 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
315 (outline-next-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
316 (not (eobp))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
317 (if (<= (outline-level) level)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
318 (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
319 (outline-flag-region (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
320 (forward-char -1)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
321 (if (memq (preceding-char) '(?\n ?\^M))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
322 (forward-char -1))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
323 (point))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
324 (progn (outline-end-of-heading) (point))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
325 ?\n)))))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
326
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
327 (defun outline-up-heading (arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
328 "Move to the heading line of which the present line is a subheading.
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
329 With argument, move up ARG levels."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
330 (interactive "p")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
331 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
332 (if (eq (outline-level) 1)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
333 (error ""))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
334 (while (and (> (outline-level) 1)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
335 (> arg 0)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
336 (not (bobp)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
337 (let ((present-level (outline-level)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
338 (while (not (< (outline-level) present-level))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
339 (outline-previous-visible-heading 1))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
340 (setq arg (- arg 1)))))
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 outline-forward-same-level (arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
343 "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
344 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
345 (interactive "p")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
346 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
347 (while (> arg 0)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
348 (let ((point-to-move-to (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
349 (outline-get-next-sibling))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
350 (if point-to-move-to
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
351 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
352 (goto-char point-to-move-to)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
353 (setq arg (1- arg)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
354 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
355 (setq arg 0)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
356 (error ""))))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
357
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
358 (defun outline-get-next-sibling ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
359 "Position the point at the next heading of the same level,
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
360 and return that position or nil if it cannot be found."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
361 (let ((level (outline-level)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
362 (outline-next-visible-heading 1)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
363 (while (and (> (outline-level) level)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
364 (not (eobp)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
365 (outline-next-visible-heading 1))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
366 (if (< (outline-level) level)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
367 nil
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
368 (point))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
369
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
370 (defun outline-backward-same-level (arg)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
371 "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
372 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
373 (interactive "p")
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
374 (outline-back-to-heading)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
375 (while (> arg 0)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
376 (let ((point-to-move-to (save-excursion
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
377 (outline-get-last-sibling))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
378 (if point-to-move-to
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
379 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
380 (goto-char point-to-move-to)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
381 (setq arg (1- arg)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
382 (progn
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
383 (setq arg 0)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
384 (error ""))))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
385
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
386 (defun outline-get-last-sibling ()
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
387 "Position the point at the previous heading of the same level,
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
388 and return that position or nil if it cannot be found."
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
389 (let ((level (outline-level)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
390 (outline-previous-visible-heading 1)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
391 (while (and (> (outline-level) level)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
392 (not (bobp)))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
393 (outline-previous-visible-heading 1))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
394 (if (< (outline-level) level)
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
395 nil
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
396 (point))))
ae820c28cee2 Initial revision
Brian Preble <rassilon@gnu.org>
parents:
diff changeset
397