Commit | Line | Data |
---|---|---|
6a05d05f | 1 | ;;; allout.el --- extensive outline mode for use alone and with other modes |
19b84ba3 | 2 | |
aad94676 | 3 | ;; Copyright (C) 1992, 1993, 1994, 2001, 2002 Free Software Foundation, Inc. |
1977b8f6 | 4 | |
968bc2c9 RS |
5 | ;; Author: Ken Manheimer <klm@python.org> |
6 | ;; Maintainer: Ken Manheimer <klm@python.org> | |
c567ac01 | 7 | ;; Created: Dec 1991 - first release to usenet |
9471aeec | 8 | ;; Version: $Id: allout.el,v 1.37 2002/12/16 00:42:23 rost Exp $|| |
660a1df5 | 9 | ;; Keywords: outlines mode wp languages |
1977b8f6 RS |
10 | |
11 | ;; This file is part of GNU Emacs. | |
12 | ||
59243403 RS |
13 | ;; GNU Emacs is free software; you can redistribute it and/or modify |
14 | ;; it under the terms of the GNU General Public License as published by | |
15 | ;; the Free Software Foundation; either version 2, or (at your option) | |
16 | ;; any later version. | |
17 | ||
1977b8f6 | 18 | ;; GNU Emacs is distributed in the hope that it will be useful, |
59243403 RS |
19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | ;; GNU General Public License for more details. | |
22 | ||
23 | ;; You should have received a copy of the GNU General Public License | |
b578f267 EN |
24 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
25 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
26 | ;; Boston, MA 02111-1307, USA. | |
1977b8f6 | 27 | |
6a05d05f | 28 | ;;; Commentary: |
19b84ba3 RS |
29 | |
30 | ;; Allout outline mode provides extensive outline formatting and | |
9179616f DL |
31 | ;; and manipulation beyond standard emacs outline mode. It provides |
32 | ;; for structured editing of outlines, as well as navigation and | |
33 | ;; exposure. It also provides for syntax-sensitive text like | |
34 | ;; programming languages. (For an example, see the allout code | |
35 | ;; itself, which is organized in ;; an outline framework.) | |
36 | ;; | |
37 | ;; In addition to outline navigation and exposure, allout includes: | |
38 | ;; | |
39 | ;; - topic-oriented repositioning, cut, and paste | |
40 | ;; - integral outline exposure-layout | |
41 | ;; - incremental search with dynamic exposure and reconcealment of hidden text | |
42 | ;; - automatic topic-number maintenance | |
43 | ;; - "Hot-spot" operation, for single-keystroke maneuvering and | |
fd5359c6 | 44 | ;; exposure control. (See the `allout-mode' docstring.) |
9179616f DL |
45 | ;; |
46 | ;; and many other features. | |
47 | ;; | |
48 | ;; The outline menubar additions provide quick reference to many of | |
aad94676 | 49 | ;; the features, and see the docstring of the function `allout-init' |
9179616f | 50 | ;; for instructions on priming your emacs session for automatic |
fd5359c6 | 51 | ;; activation of `allout-mode'. |
9179616f | 52 | ;; |
fd5359c6 MR |
53 | ;; See the docstring of the variables `allout-layout' and |
54 | ;; `allout-auto-activation' for details on automatic activation of | |
55 | ;; allout `allout-mode' as a minor mode. (It has changed since allout | |
19b84ba3 | 56 | ;; 3.x, for those of you that depend on the old method.) |
c567ac01 | 57 | ;; |
353e2ef2 KH |
58 | ;; Note - the lines beginning with `;;;_' are outline topic headers. |
59 | ;; Just `ESC-x eval-current-buffer' to give it a whirl. | |
19b84ba3 | 60 | |
9179616f | 61 | ;; Ken Manheimer klm@python.org |
c567ac01 | 62 | |
6a05d05f PJ |
63 | ;;; Code: |
64 | ||
19b84ba3 | 65 | ;;;_* Provide |
19b84ba3 RS |
66 | (provide 'allout) |
67 | ||
68 | ;;;_* USER CUSTOMIZATION VARIABLES: | |
4bef9110 SE |
69 | (defgroup allout nil |
70 | "Extensive outline mode for use alone and with other modes." | |
fd5359c6 | 71 | :prefix "allout-" |
aad94676 | 72 | :group 'editing) |
19b84ba3 RS |
73 | |
74 | ;;;_ + Layout, Mode, and Topic Header Configuration | |
75 | ||
fd5359c6 MR |
76 | ;;;_ = allout-auto-activation |
77 | (defcustom allout-auto-activation nil | |
78 | "*Regulates auto-activation modality of allout outlines - see `allout-init'. | |
19b84ba3 | 79 | |
fd5359c6 | 80 | Setq-default by `allout-init' to regulate whether or not allout |
19b84ba3 | 81 | outline mode is automatically activated when the buffer-specific |
fd5359c6 MR |
82 | variable `allout-layout' is non-nil, and whether or not the layout |
83 | dictated by `allout-layout' should be imposed on mode activation. | |
19b84ba3 RS |
84 | |
85 | With value `t', auto-mode-activation and auto-layout are enabled. | |
aad94676 | 86 | \(This also depends on `allout-find-file-hook' being installed in |
fd5359c6 | 87 | `find-file-hooks', which is also done by `allout-init'.) |
19b84ba3 RS |
88 | |
89 | With value `ask', auto-mode-activation is enabled, and endorsement for | |
90 | performing auto-layout is asked of the user each time. | |
91 | ||
9179616f | 92 | With value `activate', only auto-mode-activation is enabled, |
353e2ef2 | 93 | auto-layout is not. |
19b84ba3 RS |
94 | |
95 | With value `nil', neither auto-mode-activation nor auto-layout are | |
96 | enabled. | |
97 | ||
fd5359c6 | 98 | See the docstring for `allout-init' for the proper interface to |
9179616f DL |
99 | this variable." |
100 | :type '(choice (const :tag "On" t) | |
101 | (const :tag "Ask about layout" "ask") | |
102 | (const :tag "Mode only" "activate") | |
103 | (const :tag "Off" nil)) | |
104 | :group 'allout) | |
fd5359c6 MR |
105 | ;;;_ = allout-layout |
106 | (defvar allout-layout nil | |
19b84ba3 | 107 | "*Layout specification and provisional mode trigger for allout outlines. |
1977b8f6 | 108 | |
19b84ba3 RS |
109 | Buffer-specific. |
110 | ||
111 | A list value specifies a default layout for the current buffer, to be | |
aad94676 MR |
112 | applied upon activation of `allout-mode'. Any non-nil value will |
113 | automatically trigger `allout-mode', provided `allout-init' | |
353e2ef2 | 114 | has been called to enable it. |
19b84ba3 | 115 | |
fd5359c6 MR |
116 | See the docstring for `allout-init' for details on setting up for |
117 | auto-mode-activation, and for `allout-expose-topic' for the format of | |
19b84ba3 RS |
118 | the layout specification. |
119 | ||
120 | You can associate a particular outline layout with a file by setting | |
121 | this var via the file's local variables. For example, the following | |
41e798a9 | 122 | lines at the bottom of an Emacs Lisp file: |
19b84ba3 RS |
123 | |
124 | ;;;Local variables: | |
fd5359c6 | 125 | ;;;allout-layout: \(0 : -1 -1 0) |
19b84ba3 RS |
126 | ;;;End: |
127 | ||
128 | will, modulo the above-mentioned conditions, cause the mode to be | |
129 | activated when the file is visited, followed by the equivalent of | |
fd5359c6 | 130 | `\(allout-expose-topic 0 : -1 -1 0)'. \(This is the layout used for |
19b84ba3 RS |
131 | the allout.el, itself.) |
132 | ||
353e2ef2 KH |
133 | Also, allout's mode-specific provisions will make topic prefixes default |
134 | to the comment-start string, if any, of the language of the file. This | |
fd5359c6 MR |
135 | is modulo the setting of `allout-use-mode-specific-leader', which see.") |
136 | (make-variable-buffer-local 'allout-layout) | |
137 | ;;;_ = allout-show-bodies | |
138 | (defcustom allout-show-bodies nil | |
9179616f DL |
139 | "*If non-nil, show entire body when exposing a topic, rather than |
140 | just the header." | |
141 | :type 'boolean | |
142 | :group 'allout) | |
fd5359c6 | 143 | (make-variable-buffer-local 'allout-show-bodies) |
1977b8f6 | 144 | |
fd5359c6 MR |
145 | ;;;_ = allout-header-prefix |
146 | (defcustom allout-header-prefix "." | |
19b84ba3 RS |
147 | "*Leading string which helps distinguish topic headers. |
148 | ||
149 | Outline topic header lines are identified by a leading topic | |
c567ac01 RS |
150 | header prefix, which mostly have the value of this var at their front. |
151 | \(Level 1 topics are exceptions. They consist of only a single | |
2265e017 | 152 | character, which is typically set to the `allout-primary-bullet'. Many |
4bef9110 SE |
153 | outlines start at level 2 to avoid this discrepancy." |
154 | :type 'string | |
155 | :group 'allout) | |
fd5359c6 MR |
156 | (make-variable-buffer-local 'allout-header-prefix) |
157 | ;;;_ = allout-primary-bullet | |
158 | (defcustom allout-primary-bullet "*" | |
19b84ba3 RS |
159 | "Bullet used for top-level outline topics. |
160 | ||
161 | Outline topic header lines are identified by a leading topic header | |
c567ac01 | 162 | prefix, which is concluded by bullets that includes the value of this |
fd5359c6 | 163 | var and the respective allout-*-bullets-string vars. |
c567ac01 | 164 | |
353e2ef2 | 165 | The value of an asterisk (`*') provides for backwards compatibility |
2265e017 MR |
166 | with the original emacs outline mode. See `allout-plain-bullets-string' |
167 | and `allout-distinctive-bullets-string' for the range of available | |
4bef9110 SE |
168 | bullets." |
169 | :type 'string | |
170 | :group 'allout) | |
fd5359c6 MR |
171 | (make-variable-buffer-local 'allout-primary-bullet) |
172 | ;;;_ = allout-plain-bullets-string | |
173 | (defcustom allout-plain-bullets-string ".:,;" | |
19b84ba3 RS |
174 | "*The bullets normally used in outline topic prefixes. |
175 | ||
fd5359c6 | 176 | See `allout-distinctive-bullets-string' for the other kind of |
c567ac01 | 177 | bullets. |
1977b8f6 | 178 | |
353e2ef2 | 179 | DO NOT include the close-square-bracket, `]', as a bullet. |
1977b8f6 | 180 | |
c567ac01 | 181 | Outline mode has to be reactivated in order for changes to the value |
4bef9110 SE |
182 | of this var to take effect." |
183 | :type 'string | |
184 | :group 'allout) | |
fd5359c6 MR |
185 | (make-variable-buffer-local 'allout-plain-bullets-string) |
186 | ;;;_ = allout-distinctive-bullets-string | |
187 | (defcustom allout-distinctive-bullets-string "*+-=>([{}&!?#%\"X@$~_\\" | |
19b84ba3 | 188 | "*Persistent outline header bullets used to distinguish special topics. |
1977b8f6 | 189 | |
9179616f DL |
190 | These bullets are used to distinguish topics from the run-of-the-mill |
191 | ones. They are not used in the standard topic headers created by | |
192 | the topic-opening, shifting, and rebulleting \(eg, on topic shift, | |
193 | topic paste, blanket rebulleting) routines, but are offered among the | |
194 | choices for rebulleting. They are not altered by the above automatic | |
195 | rebulleting, so they can be used to characterize topics, eg: | |
196 | ||
197 | `?' question topics | |
198 | `\(' parenthetic comment \(with a matching close paren inside) | |
199 | `[' meta-note \(with a matching close ] inside) | |
200 | `\"' a quote | |
201 | `=' value settings | |
202 | `~' \"more or less\" | |
203 | ||
204 | ... just for example. (`#' typically has a special meaning to the | |
fd5359c6 | 205 | software, according to the value of `allout-numbered-bullet'.) |
9179616f | 206 | |
fd5359c6 | 207 | See `allout-plain-bullets-string' for the selection of |
9179616f | 208 | alternating bullets. |
1977b8f6 | 209 | |
fd5359c6 | 210 | You must run `set-allout-regexp' in order for outline mode to |
9179616f | 211 | reconcile to changes of this value. |
19b84ba3 | 212 | |
353e2ef2 | 213 | DO NOT include the close-square-bracket, `]', on either of the bullet |
4bef9110 SE |
214 | strings." |
215 | :type 'string | |
216 | :group 'allout) | |
fd5359c6 | 217 | (make-variable-buffer-local 'allout-distinctive-bullets-string) |
1977b8f6 | 218 | |
fd5359c6 MR |
219 | ;;;_ = allout-use-mode-specific-leader |
220 | (defcustom allout-use-mode-specific-leader t | |
19b84ba3 RS |
221 | "*When non-nil, use mode-specific topic-header prefixes. |
222 | ||
fd5359c6 | 223 | Allout outline mode will use the mode-specific `allout-mode-leaders' |
19b84ba3 | 224 | and/or comment-start string, if any, to lead the topic prefix string, |
353e2ef2 | 225 | so topic headers look like comments in the programming language. |
19b84ba3 RS |
226 | |
227 | String values are used as they stand. | |
228 | ||
fd5359c6 | 229 | Value `t' means to first check for assoc value in `allout-mode-leaders' |
19b84ba3 | 230 | alist, then use comment-start string, if any, then use default \(`.'). |
9179616f | 231 | \(See note about use of comment-start strings, below.) |
19b84ba3 | 232 | |
fd5359c6 | 233 | Set to the symbol for either of `allout-mode-leaders' or |
19b84ba3 RS |
234 | `comment-start' to use only one of them, respectively. |
235 | ||
9179616f | 236 | Value `nil' means to always use the default \(`.'). |
19b84ba3 RS |
237 | |
238 | comment-start strings that do not end in spaces are tripled, and an | |
353e2ef2 | 239 | `_' underscore is tacked on the end, to distinguish them from regular |
19b84ba3 | 240 | comment strings. comment-start strings that do end in spaces are not |
9179616f | 241 | tripled, but an underscore is substituted for the space. [This |
19b84ba3 | 242 | presumes that the space is for appearance, not comment syntax. You |
fd5359c6 | 243 | can use `allout-mode-leaders' to override this behavior, when |
4bef9110 SE |
244 | incorrect.]" |
245 | :type '(choice (const t) (const nil) string | |
fd5359c6 | 246 | (const allout-mode-leaders) |
4bef9110 SE |
247 | (const comment-start)) |
248 | :group 'allout) | |
fd5359c6 MR |
249 | ;;;_ = allout-mode-leaders |
250 | (defvar allout-mode-leaders '() | |
251 | "Specific allout-prefix leading strings per major modes. | |
19b84ba3 | 252 | |
9179616f | 253 | Entries will be used instead or in lieu of mode-specific |
fd5359c6 | 254 | comment-start strings. See also `allout-use-mode-specific-leader'. |
19b84ba3 RS |
255 | |
256 | If you're constructing a string that will comment-out outline | |
257 | structuring so it can be included in program code, append an extra | |
258 | character, like an \"_\" underscore, to distinguish the lead string | |
259 | from regular comments that start at bol.") | |
260 | ||
fd5359c6 MR |
261 | ;;;_ = allout-old-style-prefixes |
262 | (defcustom allout-old-style-prefixes nil | |
aad94676 | 263 | "*When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes. |
19b84ba3 RS |
264 | |
265 | Non-nil restricts the topic creation and modification | |
c567ac01 RS |
266 | functions to asterix-padded prefixes, so they look exactly |
267 | like the original emacs-outline style prefixes. | |
1977b8f6 | 268 | |
c567ac01 | 269 | Whatever the setting of this variable, both old and new style prefixes |
4bef9110 SE |
270 | are always respected by the topic maneuvering functions." |
271 | :type 'boolean | |
272 | :group 'allout) | |
fd5359c6 MR |
273 | (make-variable-buffer-local 'allout-old-style-prefixes) |
274 | ;;;_ = allout-stylish-prefixes - alternating bullets | |
275 | (defcustom allout-stylish-prefixes t | |
19b84ba3 | 276 | "*Do fancy stuff with topic prefix bullets according to level, etc. |
c567ac01 | 277 | |
19b84ba3 RS |
278 | Non-nil enables topic creation, modification, and repositioning |
279 | functions to vary the topic bullet char (the char that marks the topic | |
280 | depth) just preceding the start of the topic text) according to level. | |
353e2ef2 | 281 | Otherwise, only asterisks (`*') and distinctive bullets are used. |
19b84ba3 RS |
282 | |
283 | This is how an outline can look (but sans indentation) with stylish | |
284 | prefixes: | |
c567ac01 RS |
285 | |
286 | * Top level | |
287 | .* A topic | |
288 | . + One level 3 subtopic | |
289 | . . One level 4 subtopic | |
19b84ba3 | 290 | . . A second 4 subtopic |
c567ac01 | 291 | . + Another level 3 subtopic |
19b84ba3 RS |
292 | . #1 A numbered level 4 subtopic |
293 | . #2 Another | |
294 | . ! Another level 4 subtopic with a different distinctive bullet | |
295 | . #4 And another numbered level 4 subtopic | |
c567ac01 | 296 | |
19b84ba3 RS |
297 | This would be an outline with stylish prefixes inhibited (but the |
298 | numbered and other distinctive bullets retained): | |
c567ac01 RS |
299 | |
300 | * Top level | |
301 | .* A topic | |
19b84ba3 RS |
302 | . * One level 3 subtopic |
303 | . * One level 4 subtopic | |
304 | . * A second 4 subtopic | |
305 | . * Another level 3 subtopic | |
306 | . #1 A numbered level 4 subtopic | |
307 | . #2 Another | |
308 | . ! Another level 4 subtopic with a different distinctive bullet | |
309 | . #4 And another numbered level 4 subtopic | |
c567ac01 RS |
310 | |
311 | Stylish and constant prefixes (as well as old-style prefixes) are | |
312 | always respected by the topic maneuvering functions, regardless of | |
313 | this variable setting. | |
314 | ||
2265e017 | 315 | The setting of this var is not relevant when `allout-old-style-prefixes' |
4bef9110 SE |
316 | is non-nil." |
317 | :type 'boolean | |
318 | :group 'allout) | |
fd5359c6 | 319 | (make-variable-buffer-local 'allout-stylish-prefixes) |
1977b8f6 | 320 | |
fd5359c6 MR |
321 | ;;;_ = allout-numbered-bullet |
322 | (defcustom allout-numbered-bullet "#" | |
19b84ba3 RS |
323 | "*String designating bullet of topics that have auto-numbering; nil for none. |
324 | ||
a0776d6b | 325 | Topics having this bullet have automatic maintenance of a sibling |
19b84ba3 | 326 | sequence-number tacked on, just after the bullet. Conventionally set |
c567ac01 | 327 | to \"#\", you can set it to a bullet of your choice. A nil value |
4bef9110 SE |
328 | disables numbering maintenance." |
329 | :type '(choice (const nil) string) | |
330 | :group 'allout) | |
fd5359c6 MR |
331 | (make-variable-buffer-local 'allout-numbered-bullet) |
332 | ;;;_ = allout-file-xref-bullet | |
333 | (defcustom allout-file-xref-bullet "@" | |
334 | "*Bullet signifying file cross-references, for `allout-resolve-xref'. | |
19b84ba3 | 335 | |
9179616f | 336 | Set this var to the bullet you want to use for file cross-references." |
4bef9110 SE |
337 | :type '(choice (const nil) string) |
338 | :group 'allout) | |
c567ac01 | 339 | |
fd5359c6 MR |
340 | ;;;_ = allout-presentation-padding |
341 | (defcustom allout-presentation-padding 2 | |
9179616f DL |
342 | "*Presentation-format white-space padding factor, for greater indent." |
343 | :type 'integer | |
344 | :group 'allout) | |
345 | ||
fd5359c6 | 346 | (make-variable-buffer-local 'allout-presentation-padding) |
9179616f | 347 | |
fd5359c6 MR |
348 | ;;;_ = allout-abbreviate-flattened-numbering |
349 | (defcustom allout-abbreviate-flattened-numbering nil | |
350 | "*If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic | |
9179616f DL |
351 | numbers to minimal amount with some context. Otherwise, entire |
352 | numbers are always used." | |
353 | :type 'boolean | |
354 | :group 'allout) | |
355 | ||
c567ac01 | 356 | ;;;_ + LaTeX formatting |
fd5359c6 MR |
357 | ;;;_ - allout-number-pages |
358 | (defcustom allout-number-pages nil | |
4bef9110 SE |
359 | "*Non-nil turns on page numbering for LaTeX formatting of an outline." |
360 | :type 'boolean | |
361 | :group 'allout) | |
fd5359c6 MR |
362 | ;;;_ - allout-label-style |
363 | (defcustom allout-label-style "\\large\\bf" | |
4bef9110 SE |
364 | "*Font and size of labels for LaTeX formatting of an outline." |
365 | :type 'string | |
366 | :group 'allout) | |
fd5359c6 MR |
367 | ;;;_ - allout-head-line-style |
368 | (defcustom allout-head-line-style "\\large\\sl " | |
4bef9110 SE |
369 | "*Font and size of entries for LaTeX formatting of an outline." |
370 | :type 'string | |
371 | :group 'allout) | |
fd5359c6 MR |
372 | ;;;_ - allout-body-line-style |
373 | (defcustom allout-body-line-style " " | |
4bef9110 SE |
374 | "*Font and size of entries for LaTeX formatting of an outline." |
375 | :type 'string | |
376 | :group 'allout) | |
fd5359c6 MR |
377 | ;;;_ - allout-title-style |
378 | (defcustom allout-title-style "\\Large\\bf" | |
4bef9110 SE |
379 | "*Font and size of titles for LaTeX formatting of an outline." |
380 | :type 'string | |
381 | :group 'allout) | |
fd5359c6 MR |
382 | ;;;_ - allout-title |
383 | (defcustom allout-title '(or buffer-file-name (current-buffer-name)) | |
c567ac01 | 384 | "*Expression to be evaluated to determine the title for LaTeX |
4bef9110 SE |
385 | formatted copy." |
386 | :type 'sexp | |
387 | :group 'allout) | |
fd5359c6 MR |
388 | ;;;_ - allout-line-skip |
389 | (defcustom allout-line-skip ".05cm" | |
4bef9110 SE |
390 | "*Space between lines for LaTeX formatting of an outline." |
391 | :type 'string | |
392 | :group 'allout) | |
fd5359c6 MR |
393 | ;;;_ - allout-indent |
394 | (defcustom allout-indent ".3cm" | |
4bef9110 SE |
395 | "*LaTeX formatted depth-indent spacing." |
396 | :type 'string | |
397 | :group 'allout) | |
c567ac01 RS |
398 | |
399 | ;;;_ + Miscellaneous customization | |
400 | ||
fd5359c6 MR |
401 | ;;;_ = allout-command-prefix |
402 | (defcustom allout-command-prefix "\C-c" | |
9179616f DL |
403 | "*Key sequence to be used as prefix for outline mode command key bindings." |
404 | :type 'string | |
405 | :group 'allout) | |
406 | ||
fd5359c6 MR |
407 | ;;;_ = allout-keybindings-list |
408 | ;;; You have to reactivate allout-mode - `(allout-mode t)' - to | |
c567ac01 | 409 | ;;; institute changes to this var. |
fd5359c6 | 410 | (defvar allout-keybindings-list () |
2265e017 | 411 | "*List of `allout-mode' key / function bindings, for `allout-mode-map'. |
19b84ba3 | 412 | |
2265e017 | 413 | String or vector key will be prefaced with `allout-command-prefix', |
9179616f | 414 | unless optional third, non-nil element is present.") |
fd5359c6 | 415 | (setq allout-keybindings-list |
1977b8f6 RS |
416 | '( |
417 | ; Motion commands: | |
fd5359c6 MR |
418 | ("\C-n" allout-next-visible-heading) |
419 | ("\C-p" allout-previous-visible-heading) | |
420 | ("\C-u" allout-up-current-level) | |
421 | ("\C-f" allout-forward-current-level) | |
422 | ("\C-b" allout-backward-current-level) | |
423 | ("\C-a" allout-beginning-of-current-entry) | |
424 | ("\C-e" allout-end-of-current-entry) | |
1977b8f6 | 425 | ; Exposure commands: |
fd5359c6 MR |
426 | ("\C-i" allout-show-children) |
427 | ("\C-s" allout-show-current-subtree) | |
428 | ("\C-h" allout-hide-current-subtree) | |
429 | ("\C-o" allout-show-current-entry) | |
430 | ("!" allout-show-all) | |
1977b8f6 | 431 | ; Alteration commands: |
fd5359c6 MR |
432 | (" " allout-open-sibtopic) |
433 | ("." allout-open-subtopic) | |
434 | ("," allout-open-supertopic) | |
435 | ("'" allout-shift-in) | |
436 | (">" allout-shift-in) | |
437 | ("<" allout-shift-out) | |
438 | ("\C-m" allout-rebullet-topic) | |
439 | ("*" allout-rebullet-current-heading) | |
440 | ("#" allout-number-siblings) | |
441 | ("\C-k" allout-kill-line t) | |
442 | ("\C-y" allout-yank t) | |
443 | ("\M-y" allout-yank-pop t) | |
444 | ("\C-k" allout-kill-topic) | |
1977b8f6 | 445 | ; Miscellaneous commands: |
fd5359c6 MR |
446 | ;([?\C-\ ] allout-mark-topic) |
447 | ("@" allout-resolve-xref) | |
448 | ("=c" allout-copy-exposed-to-buffer) | |
449 | ("=i" allout-indented-exposed-to-buffer) | |
450 | ("=t" allout-latexify-exposed) | |
451 | ("=p" allout-flatten-exposed-to-buffer))) | |
452 | ||
453 | ;;;_ = allout-isearch-dynamic-expose | |
454 | (defcustom allout-isearch-dynamic-expose t | |
9179616f DL |
455 | "*Non-nil enable dynamic exposure of hidden incremental-search |
456 | targets as they're encountered." | |
4bef9110 SE |
457 | :type 'boolean |
458 | :group 'allout) | |
fd5359c6 | 459 | (make-variable-buffer-local 'allout-isearch-dynamic-expose) |
c567ac01 | 460 | |
fd5359c6 MR |
461 | ;;;_ = allout-use-hanging-indents |
462 | (defcustom allout-use-hanging-indents t | |
19b84ba3 RS |
463 | "*If non-nil, topic body text auto-indent defaults to indent of the header. |
464 | Ie, it is indented to be just past the header prefix. This is | |
465 | relevant mostly for use with indented-text-mode, or other situations | |
466 | where auto-fill occurs. | |
c567ac01 | 467 | |
353e2ef2 | 468 | \[This feature no longer depends in any way on the `filladapt.el' |
4bef9110 SE |
469 | lisp-archive package.\]" |
470 | :type 'boolean | |
471 | :group 'allout) | |
fd5359c6 | 472 | (make-variable-buffer-local 'allout-use-hanging-indents) |
c567ac01 | 473 | |
fd5359c6 MR |
474 | ;;;_ = allout-reindent-bodies |
475 | (defcustom allout-reindent-bodies (if allout-use-hanging-indents | |
8d118843 | 476 | 'text) |
19b84ba3 | 477 | "*Non-nil enables auto-adjust of topic body hanging indent with depth shifts. |
1977b8f6 | 478 | |
8d118843 RS |
479 | When active, topic body lines that are indented even with or beyond |
480 | their topic header are reindented to correspond with depth shifts of | |
481 | the header. | |
482 | ||
483 | A value of `t' enables reindent in non-programming-code buffers, ie | |
484 | those that do not have the variable `comment-start' set. A value of | |
4bef9110 SE |
485 | `force' enables reindent whether or not `comment-start' is set." |
486 | :type '(choice (const nil) (const t) (const text) (const force)) | |
487 | :group 'allout) | |
8d118843 | 488 | |
fd5359c6 | 489 | (make-variable-buffer-local 'allout-reindent-bodies) |
c567ac01 | 490 | |
fd5359c6 MR |
491 | ;;;_ = allout-inhibit-protection |
492 | (defcustom allout-inhibit-protection nil | |
19b84ba3 RS |
493 | "*Non-nil disables warnings and confirmation-checks for concealed-text edits. |
494 | ||
495 | Outline mode uses emacs change-triggered functions to detect unruly | |
496 | changes to concealed regions. Set this var non-nil to disable the | |
497 | protection, potentially increasing text-entry responsiveness a bit. | |
c567ac01 | 498 | |
2265e017 | 499 | This var takes effect at `allout-mode' activation, so you may have to |
19b84ba3 | 500 | deactivate and then reactivate the mode if you want to toggle the |
4bef9110 SE |
501 | behavior." |
502 | :type 'boolean | |
503 | :group 'allout) | |
c567ac01 | 504 | |
19b84ba3 | 505 | ;;;_* CODE - no user customizations below. |
c567ac01 | 506 | |
9179616f DL |
507 | ;;;_ #1 Internal Outline Formatting and Configuration |
508 | ;;;_ : Version | |
fd5359c6 MR |
509 | ;;;_ = allout-version |
510 | (defvar allout-version | |
9471aeec | 511 | (let ((rcs-rev "$Revision: 1.37 $")) |
19b84ba3 RS |
512 | (condition-case err |
513 | (save-match-data | |
8d118843 | 514 | (string-match "Revision: \\([0-9]+\\.[0-9]+\\)" rcs-rev) |
19b84ba3 | 515 | (substring rcs-rev (match-beginning 1) (match-end 1))) |
9179616f | 516 | ('error rcs-rev))) |
8d118843 | 517 | "Revision number of currently loaded outline package. \(allout.el)") |
fd5359c6 MR |
518 | ;;;_ > allout-version |
519 | (defun allout-version (&optional here) | |
19b84ba3 RS |
520 | "Return string describing the loaded outline version." |
521 | (interactive "P") | |
fd5359c6 | 522 | (let ((msg (concat "Allout Outline Mode v " allout-version))) |
eac9cf5f | 523 | (if here (insert msg)) |
19b84ba3 RS |
524 | (message "%s" msg) |
525 | msg)) | |
9179616f | 526 | ;;;_ : Topic header format |
fd5359c6 MR |
527 | ;;;_ = allout-regexp |
528 | (defvar allout-regexp "" | |
c567ac01 | 529 | "*Regular expression to match the beginning of a heading line. |
19b84ba3 | 530 | |
c567ac01 RS |
531 | Any line whose beginning matches this regexp is considered a |
532 | heading. This var is set according to the user configuration vars | |
2265e017 | 533 | by `set-allout-regexp'.") |
fd5359c6 MR |
534 | (make-variable-buffer-local 'allout-regexp) |
535 | ;;;_ = allout-bullets-string | |
536 | (defvar allout-bullets-string "" | |
19b84ba3 RS |
537 | "A string dictating the valid set of outline topic bullets. |
538 | ||
fd5359c6 MR |
539 | This var should *not* be set by the user - it is set by `set-allout-regexp', |
540 | and is produced from the elements of `allout-plain-bullets-string' | |
541 | and `allout-distinctive-bullets-string'.") | |
542 | (make-variable-buffer-local 'allout-bullets-string) | |
543 | ;;;_ = allout-bullets-string-len | |
544 | (defvar allout-bullets-string-len 0 | |
2265e017 | 545 | "Length of current buffers' `allout-plain-bullets-string'.") |
fd5359c6 MR |
546 | (make-variable-buffer-local 'allout-bullets-string-len) |
547 | ;;;_ = allout-line-boundary-regexp | |
548 | (defvar allout-line-boundary-regexp () | |
aad94676 | 549 | "`allout-regexp' with outline style beginning-of-line anchor. |
19b84ba3 | 550 | |
a4e104bf | 551 | \(Ie, C-j, *or* C-m, for prefixes of hidden topics). This is properly |
2265e017 | 552 | set when `allout-regexp' is produced by `set-allout-regexp', so |
c567ac01 | 553 | that (match-beginning 2) and (match-end 2) delimit the prefix.") |
fd5359c6 MR |
554 | (make-variable-buffer-local 'allout-line-boundary-regexp) |
555 | ;;;_ = allout-bob-regexp | |
556 | (defvar allout-bob-regexp () | |
2265e017 | 557 | "Like `allout-line-boundary-regexp', for headers at beginning of buffer. |
9179616f | 558 | \(match-beginning 2) and \(match-end 2) delimit the prefix.") |
fd5359c6 MR |
559 | (make-variable-buffer-local 'allout-bob-regexp) |
560 | ;;;_ = allout-header-subtraction | |
561 | (defvar allout-header-subtraction (1- (length allout-header-prefix)) | |
562 | "Allout-header prefix length to subtract when computing topic depth.") | |
563 | (make-variable-buffer-local 'allout-header-subtraction) | |
564 | ;;;_ = allout-plain-bullets-string-len | |
565 | (defvar allout-plain-bullets-string-len (length allout-plain-bullets-string) | |
2265e017 | 566 | "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.") |
fd5359c6 MR |
567 | (make-variable-buffer-local 'allout-plain-bullets-string-len) |
568 | ||
569 | ||
570 | ;;;_ X allout-reset-header-lead (header-lead) | |
571 | (defun allout-reset-header-lead (header-lead) | |
c567ac01 | 572 | "*Reset the leading string used to identify topic headers." |
1977b8f6 | 573 | (interactive "sNew lead string: ") |
fd5359c6 MR |
574 | (setq allout-header-prefix header-lead) |
575 | (setq allout-header-subtraction (1- (length allout-header-prefix))) | |
576 | (set-allout-regexp)) | |
577 | ;;;_ X allout-lead-with-comment-string (header-lead) | |
578 | (defun allout-lead-with-comment-string (&optional header-lead) | |
19b84ba3 RS |
579 | "*Set the topic-header leading string to specified string. |
580 | ||
581 | Useful when for encapsulating outline structure in programming | |
582 | language comments. Returns the leading string." | |
1977b8f6 RS |
583 | |
584 | (interactive "P") | |
585 | (if (not (stringp header-lead)) | |
586 | (setq header-lead (read-string | |
587 | "String prefix for topic headers: "))) | |
fd5359c6 MR |
588 | (setq allout-reindent-bodies nil) |
589 | (allout-reset-header-lead header-lead) | |
1977b8f6 | 590 | header-lead) |
fd5359c6 MR |
591 | ;;;_ > allout-infer-header-lead () |
592 | (defun allout-infer-header-lead () | |
593 | "Determine appropriate `allout-header-prefix'. | |
19b84ba3 RS |
594 | |
595 | Works according to settings of: | |
596 | ||
8d118843 | 597 | `comment-start' |
fd5359c6 MR |
598 | `allout-header-prefix' (default) |
599 | `allout-use-mode-specific-leader' | |
600 | and `allout-mode-leaders'. | |
19b84ba3 | 601 | |
fd5359c6 | 602 | Apply this via \(re)activation of `allout-mode', rather than |
8d118843 | 603 | invoking it directly." |
fd5359c6 MR |
604 | (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader) |
605 | (if (or (stringp allout-use-mode-specific-leader) | |
606 | (memq allout-use-mode-specific-leader | |
607 | '(allout-mode-leaders | |
19b84ba3 RS |
608 | comment-start |
609 | t))) | |
fd5359c6 | 610 | allout-use-mode-specific-leader |
19b84ba3 RS |
611 | ;; Oops - garbled value, equate with effect of 't: |
612 | t))) | |
613 | (leader | |
614 | (cond | |
615 | ((not use-leader) nil) | |
616 | ;; Use the explicitly designated leader: | |
617 | ((stringp use-leader) use-leader) | |
fd5359c6 | 618 | (t (or (and (memq use-leader '(t allout-mode-leaders)) |
19b84ba3 | 619 | ;; Get it from outline mode leaders? |
fd5359c6 MR |
620 | (cdr (assq major-mode allout-mode-leaders))) |
621 | ;; ... didn't get from allout-mode-leaders... | |
19b84ba3 RS |
622 | (and (memq use-leader '(t comment-start)) |
623 | comment-start | |
624 | ;; Use comment-start, maybe tripled, and with | |
353e2ef2 | 625 | ;; underscore: |
19b84ba3 RS |
626 | (concat |
627 | (if (string= " " | |
628 | (substring comment-start | |
629 | (1- (length comment-start)))) | |
630 | ;; Use comment-start, sans trailing space: | |
631 | (substring comment-start 0 -1) | |
632 | (concat comment-start comment-start comment-start)) | |
633 | ;; ... and append underscore, whichever: | |
634 | "_"))))))) | |
635 | (if (not leader) | |
636 | nil | |
fd5359c6 | 637 | (if (string= leader allout-header-prefix) |
19b84ba3 | 638 | nil ; no change, nothing to do. |
fd5359c6 MR |
639 | (setq allout-header-prefix leader) |
640 | allout-header-prefix)))) | |
641 | ;;;_ > allout-infer-body-reindent () | |
642 | (defun allout-infer-body-reindent () | |
643 | "Determine proper setting for `allout-reindent-bodies'. | |
8d118843 | 644 | |
fd5359c6 | 645 | Depends on default setting of `allout-reindent-bodies' \(which see) |
8d118843 RS |
646 | and presence of setting for `comment-start', to tell whether the |
647 | file is programming code." | |
fd5359c6 | 648 | (if (and allout-reindent-bodies |
8d118843 | 649 | comment-start |
fd5359c6 MR |
650 | (not (eq 'force allout-reindent-bodies))) |
651 | (setq allout-reindent-bodies nil))) | |
652 | ;;;_ > set-allout-regexp () | |
653 | (defun set-allout-regexp () | |
19b84ba3 RS |
654 | "Generate proper topic-header regexp form for outline functions. |
655 | ||
fd5359c6 MR |
656 | Works with respect to `allout-plain-bullets-string' and |
657 | `allout-distinctive-bullets-string'." | |
1977b8f6 RS |
658 | |
659 | (interactive) | |
fd5359c6 MR |
660 | ;; Derive allout-bullets-string from user configured components: |
661 | (setq allout-bullets-string "") | |
662 | (let ((strings (list 'allout-plain-bullets-string | |
663 | 'allout-distinctive-bullets-string | |
664 | 'allout-primary-bullet)) | |
1977b8f6 RS |
665 | cur-string |
666 | cur-len | |
c567ac01 | 667 | cur-char |
1977b8f6 RS |
668 | cur-char-string |
669 | index | |
670 | new-string) | |
671 | (while strings | |
672 | (setq new-string "") (setq index 0) | |
673 | (setq cur-len (length (setq cur-string (symbol-value (car strings))))) | |
674 | (while (< index cur-len) | |
675 | (setq cur-char (aref cur-string index)) | |
fd5359c6 MR |
676 | (setq allout-bullets-string |
677 | (concat allout-bullets-string | |
1977b8f6 RS |
678 | (cond |
679 | ; Single dash would denote a | |
680 | ; sequence, repeated denotes | |
681 | ; a dash: | |
682 | ((eq cur-char ?-) "--") | |
683 | ; literal close-square-bracket | |
684 | ; doesn't work right in the | |
685 | ; expr, exclude it: | |
686 | ((eq cur-char ?\]) "") | |
687 | (t (regexp-quote (char-to-string cur-char)))))) | |
688 | (setq index (1+ index))) | |
689 | (setq strings (cdr strings))) | |
690 | ) | |
fd5359c6 MR |
691 | ;; Derive next for repeated use in allout-pending-bullet: |
692 | (setq allout-plain-bullets-string-len (length allout-plain-bullets-string)) | |
693 | (setq allout-header-subtraction (1- (length allout-header-prefix))) | |
694 | ;; Produce the new allout-regexp: | |
695 | (setq allout-regexp (concat "\\(\\" | |
696 | allout-header-prefix | |
1977b8f6 | 697 | "[ \t]*[" |
fd5359c6 | 698 | allout-bullets-string |
1977b8f6 | 699 | "]\\)\\|\\" |
fd5359c6 | 700 | allout-primary-bullet |
1977b8f6 | 701 | "+\\|\^l")) |
fd5359c6 MR |
702 | (setq allout-line-boundary-regexp |
703 | (concat "\\([\n\r]\\)\\(" allout-regexp "\\)")) | |
704 | (setq allout-bob-regexp | |
705 | (concat "\\(\\`\\)\\(" allout-regexp "\\)")) | |
1977b8f6 | 706 | ) |
9179616f | 707 | ;;;_ : Key bindings |
fd5359c6 MR |
708 | ;;;_ = allout-mode-map |
709 | (defvar allout-mode-map nil "Keybindings for (allout) outline minor mode.") | |
710 | ;;;_ > produce-allout-mode-map (keymap-alist &optional base-map) | |
711 | (defun produce-allout-mode-map (keymap-list &optional base-map) | |
712 | "Produce keymap for use as allout-mode-map, from keymap-list. | |
19b84ba3 RS |
713 | |
714 | Built on top of optional BASE-MAP, or empty sparse map if none specified. | |
fd5359c6 | 715 | See doc string for allout-keybindings-list for format of binding list." |
9179616f | 716 | (let ((map (or base-map (make-sparse-keymap))) |
fd5359c6 | 717 | (pref (list allout-command-prefix))) |
9179616f DL |
718 | (mapcar (function |
719 | (lambda (cell) | |
720 | (let ((add-pref (null (cdr (cdr cell)))) | |
721 | (key-suff (list (car cell)))) | |
722 | (apply 'define-key | |
723 | (list map | |
724 | (apply 'concat (if add-pref | |
725 | (append pref key-suff) | |
726 | key-suff)) | |
727 | (car (cdr cell))))))) | |
19b84ba3 RS |
728 | keymap-list) |
729 | map)) | |
fd5359c6 MR |
730 | ;;;_ = allout-prior-bindings - being deprecated. |
731 | (defvar allout-prior-bindings nil | |
2265e017 | 732 | "Variable for use in V18, with `allout-added-bindings', for |
c567ac01 | 733 | resurrecting, on mode deactivation, bindings that existed before |
19b84ba3 | 734 | activation. Being deprecated.") |
fd5359c6 MR |
735 | ;;;_ = allout-added-bindings - being deprecated |
736 | (defvar allout-added-bindings nil | |
2265e017 | 737 | "Variable for use in V18, with `allout-prior-bindings', for |
c567ac01 | 738 | resurrecting, on mode deactivation, bindings that existed before |
19b84ba3 | 739 | activation. Being deprecated.") |
9179616f | 740 | ;;;_ : Menu bar |
fd5359c6 | 741 | (defun produce-allout-mode-menubar-entries () |
9179616f | 742 | (require 'easymenu) |
fd5359c6 MR |
743 | (easy-menu-define allout-mode-exposure-menu |
744 | allout-mode-map | |
9179616f DL |
745 | "Allout outline exposure menu." |
746 | '("Exposure" | |
fd5359c6 MR |
747 | ["Show Entry" allout-show-current-entry t] |
748 | ["Show Children" allout-show-children t] | |
749 | ["Show Subtree" allout-show-current-subtree t] | |
750 | ["Hide Subtree" allout-hide-current-subtree t] | |
751 | ["Hide Leaves" allout-hide-current-leaves t] | |
9179616f | 752 | "----" |
fd5359c6 MR |
753 | ["Show All" allout-show-all t])) |
754 | (easy-menu-define allout-mode-editing-menu | |
755 | allout-mode-map | |
9179616f DL |
756 | "Allout outline editing menu." |
757 | '("Headings" | |
fd5359c6 MR |
758 | ["Open Sibling" allout-open-sibtopic t] |
759 | ["Open Subtopic" allout-open-subtopic t] | |
760 | ["Open Supertopic" allout-open-supertopic t] | |
9179616f | 761 | "----" |
fd5359c6 MR |
762 | ["Shift Topic In" allout-shift-in t] |
763 | ["Shift Topic Out" allout-shift-out t] | |
764 | ["Rebullet Topic" allout-rebullet-topic t] | |
765 | ["Rebullet Heading" allout-rebullet-current-heading t] | |
766 | ["Number Siblings" allout-number-siblings t])) | |
767 | (easy-menu-define allout-mode-navigation-menu | |
768 | allout-mode-map | |
9179616f DL |
769 | "Allout outline navigation menu." |
770 | '("Navigation" | |
fd5359c6 | 771 | ["Next Visible Heading" allout-next-visible-heading t] |
9179616f | 772 | ["Previous Visible Heading" |
fd5359c6 | 773 | allout-previous-visible-heading t] |
9179616f | 774 | "----" |
fd5359c6 MR |
775 | ["Up Level" allout-up-current-level t] |
776 | ["Forward Current Level" allout-forward-current-level t] | |
9179616f | 777 | ["Backward Current Level" |
fd5359c6 | 778 | allout-backward-current-level t] |
9179616f DL |
779 | "----" |
780 | ["Beginning of Entry" | |
fd5359c6 MR |
781 | allout-beginning-of-current-entry t] |
782 | ["End of Entry" allout-end-of-current-entry t] | |
783 | ["End of Subtree" allout-end-of-current-subtree t])) | |
784 | (easy-menu-define allout-mode-misc-menu | |
785 | allout-mode-map | |
9179616f DL |
786 | "Allout outlines miscellaneous bindings." |
787 | '("Misc" | |
fd5359c6 | 788 | ["Version" allout-version t] |
9179616f | 789 | "----" |
fd5359c6 | 790 | ["Duplicate Exposed" allout-copy-exposed-to-buffer t] |
9179616f | 791 | ["Duplicate Exposed, numbered" |
fd5359c6 | 792 | allout-flatten-exposed-to-buffer t] |
9179616f | 793 | ["Duplicate Exposed, indented" |
fd5359c6 | 794 | allout-indented-exposed-to-buffer t] |
9179616f | 795 | "----" |
fd5359c6 MR |
796 | ["Set Header Lead" allout-reset-header-lead t] |
797 | ["Set New Exposure" allout-expose-topic t]))) | |
9179616f | 798 | ;;;_ : Mode-Specific Variable Maintenance Utilities |
fd5359c6 MR |
799 | ;;;_ = allout-mode-prior-settings |
800 | (defvar allout-mode-prior-settings nil | |
aad94676 | 801 | "Internal `allout-mode' use; settings to be resumed on mode deactivation.") |
fd5359c6 MR |
802 | (make-variable-buffer-local 'allout-mode-prior-settings) |
803 | ;;;_ > allout-resumptions (name &optional value) | |
804 | (defun allout-resumptions (name &optional value) | |
1977b8f6 | 805 | |
2265e017 | 806 | "Registers or resumes settings over `allout-mode' activation/deactivation. |
19b84ba3 RS |
807 | |
808 | First arg is NAME of variable affected. Optional second arg is list | |
fd5359c6 | 809 | containing allout-mode-specific VALUE to be imposed on named |
19b84ba3 RS |
810 | variable, and to be registered. (It's a list so you can specify |
811 | registrations of null values.) If no value is specified, the | |
812 | registered value is returned (encapsulated in the list, so the caller | |
813 | can distinguish nil vs no value), and the registration is popped | |
c567ac01 | 814 | from the list." |
1977b8f6 | 815 | |
fd5359c6 | 816 | (let ((on-list (assq name allout-mode-prior-settings)) |
353e2ef2 | 817 | prior-capsule ; By `capsule' i mean a list |
1977b8f6 RS |
818 | ; containing a value, so we can |
819 | ; distinguish nil from no value. | |
820 | ) | |
821 | ||
822 | (if value | |
823 | ||
824 | ;; Registering: | |
825 | (progn | |
826 | (if on-list | |
827 | nil ; Already preserved prior value - don't mess with it. | |
828 | ;; Register the old value, or nil if previously unbound: | |
fd5359c6 | 829 | (setq allout-mode-prior-settings |
1977b8f6 RS |
830 | (cons (list name |
831 | (if (boundp name) (list (symbol-value name)))) | |
fd5359c6 | 832 | allout-mode-prior-settings))) |
c567ac01 RS |
833 | ; And impose the new value, locally: |
834 | (progn (make-local-variable name) | |
835 | (set name (car value)))) | |
1977b8f6 RS |
836 | |
837 | ;; Relinquishing: | |
838 | (if (not on-list) | |
839 | ||
840 | ;; Oops, not registered - leave it be: | |
841 | nil | |
842 | ||
843 | ;; Some registration: | |
844 | ; reestablish it: | |
845 | (setq prior-capsule (car (cdr on-list))) | |
846 | (if prior-capsule | |
847 | (set name (car prior-capsule)) ; Some prior value - reestablish it. | |
848 | (makunbound name)) ; Previously unbound - demolish var. | |
849 | ; Remove registration: | |
850 | (let (rebuild) | |
fd5359c6 MR |
851 | (while allout-mode-prior-settings |
852 | (if (not (eq (car allout-mode-prior-settings) | |
1977b8f6 RS |
853 | on-list)) |
854 | (setq rebuild | |
fd5359c6 | 855 | (cons (car allout-mode-prior-settings) |
1977b8f6 | 856 | rebuild))) |
fd5359c6 MR |
857 | (setq allout-mode-prior-settings |
858 | (cdr allout-mode-prior-settings))) | |
859 | (setq allout-mode-prior-settings rebuild))))) | |
1977b8f6 | 860 | ) |
9179616f | 861 | ;;;_ : Mode-specific incidentals |
fd5359c6 MR |
862 | ;;;_ = allout-during-write-cue nil |
863 | (defvar allout-during-write-cue nil | |
19b84ba3 | 864 | "Used to inhibit outline change-protection during file write. |
c567ac01 | 865 | |
fd5359c6 MR |
866 | See also `allout-post-command-business', `allout-write-file-hook', |
867 | `allout-before-change-protect', and `allout-post-command-business' | |
19b84ba3 | 868 | functions.") |
fd5359c6 MR |
869 | ;;;_ = allout-pre-was-isearching nil |
870 | (defvar allout-pre-was-isearching nil | |
9179616f | 871 | "Cue for isearch-dynamic-exposure mechanism, implemented in |
fd5359c6 MR |
872 | allout-pre- and -post-command-hooks.") |
873 | (make-variable-buffer-local 'allout-pre-was-isearching) | |
874 | ;;;_ = allout-isearch-prior-pos nil | |
875 | (defvar allout-isearch-prior-pos nil | |
876 | "Cue for isearch-dynamic-exposure tracking, used by allout-isearch-expose.") | |
877 | (make-variable-buffer-local 'allout-isearch-prior-pos) | |
878 | ;;;_ = allout-isearch-did-quit | |
879 | (defvar allout-isearch-did-quit nil | |
9179616f DL |
880 | "Distinguishes isearch conclusion and cancellation. |
881 | ||
2265e017 MR |
882 | Maintained by `allout-isearch-abort' \(which is wrapped around the real |
883 | isearch-abort), and monitored by `allout-isearch-expose' for action.") | |
fd5359c6 MR |
884 | (make-variable-buffer-local 'allout-isearch-did-quit) |
885 | ;;;_ = allout-override-protect nil | |
886 | (defvar allout-override-protect nil | |
2265e017 | 887 | "Used in `allout-mode' for regulate of concealed-text protection mechanism. |
19b84ba3 RS |
888 | |
889 | Allout outline mode regulates alteration of concealed text to protect | |
a0776d6b | 890 | against inadvertent, unnoticed changes. This is for use by specific, |
19b84ba3 RS |
891 | native outline functions to temporarily override that protection. |
892 | It's automatically reset to nil after every buffer modification.") | |
fd5359c6 MR |
893 | (make-variable-buffer-local 'allout-override-protect) |
894 | ;;;_ > allout-unprotected (expr) | |
895 | (defmacro allout-unprotected (expr) | |
896 | "Evaluate EXPRESSION with `allout-override-protect' let-bound `t'." | |
897 | `(let ((allout-override-protect t)) | |
9179616f | 898 | ,expr)) |
fd5359c6 MR |
899 | ;;;_ = allout-undo-aggregation |
900 | (defvar allout-undo-aggregation 30 | |
c567ac01 | 901 | "Amount of successive self-insert actions to bunch together per undo. |
19b84ba3 | 902 | |
c567ac01 | 903 | This is purely a kludge variable, regulating the compensation for a bug in |
9179616f | 904 | the way that before-change-functions and undo interact.") |
fd5359c6 | 905 | (make-variable-buffer-local 'allout-undo-aggregation) |
19b84ba3 | 906 | ;;;_ = file-var-bug hack |
fd5359c6 | 907 | (defvar allout-v18/19-file-var-hack nil |
c567ac01 | 908 | "Horrible hack used to prevent invalid multiple triggering of outline |
2265e017 | 909 | mode from prop-line file-var activation. Used by `allout-mode' function |
c567ac01 | 910 | to track repeats.") |
fd5359c6 MR |
911 | ;;;_ > allout-write-file-hook () |
912 | (defun allout-write-file-hook () | |
aad94676 | 913 | "In `allout-mode', run as a `local-write-file-hooks' activity. |
19b84ba3 | 914 | |
aad94676 | 915 | Currently just sets `allout-during-write-cue', so outline change-protection |
353e2ef2 | 916 | knows to keep inactive during file write." |
fd5359c6 | 917 | (setq allout-during-write-cue t) |
19b84ba3 RS |
918 | nil) |
919 | ||
920 | ;;;_ #2 Mode activation | |
fd5359c6 MR |
921 | ;;;_ = allout-mode |
922 | (defvar allout-mode () "Allout outline mode minor-mode flag.") | |
923 | (make-variable-buffer-local 'allout-mode) | |
924 | ;;;_ > allout-mode-p () | |
925 | (defmacro allout-mode-p () | |
2265e017 | 926 | "Return t if `allout-mode' is active in current buffer." |
fd5359c6 MR |
927 | 'allout-mode) |
928 | ;;;_ = allout-explicitly-deactivated | |
929 | (defvar allout-explicitly-deactivated nil | |
aad94676 | 930 | "Non-nil if `allout-mode' was last deliberately deactivated. |
2265e017 | 931 | So `allout-post-command-business' should not reactivate it...") |
fd5359c6 MR |
932 | (make-variable-buffer-local 'allout-explicitly-deactivated) |
933 | ;;;_ > allout-init (&optional mode) | |
aad94676 | 934 | ;;;###autoload |
fd5359c6 | 935 | (defun allout-init (&optional mode) |
2265e017 | 936 | "Prime `allout-mode' to enable/disable auto-activation, wrt `allout-layout'. |
19b84ba3 | 937 | |
8d118843 | 938 | MODE is one of the following symbols: |
19b84ba3 | 939 | |
353e2ef2 KH |
940 | - nil \(or no argument) deactivate auto-activation/layout; |
941 | - `activate', enable auto-activation only; | |
942 | - `ask', enable auto-activation, and enable auto-layout but with | |
a0776d6b | 943 | confirmation for layout operation solicited from user each time; |
353e2ef2 | 944 | - `report', just report and return the current auto-activation state; |
8d118843 RS |
945 | - anything else \(eg, t) for auto-activation and auto-layout, without |
946 | any confirmation check. | |
19b84ba3 RS |
947 | |
948 | Use this function to setup your emacs session for automatic activation | |
949 | of allout outline mode, contingent to the buffer-specific setting of | |
fd5359c6 MR |
950 | the `allout-layout' variable. (See `allout-layout' and |
951 | `allout-expose-topic' docstrings for more details on auto layout). | |
19b84ba3 | 952 | |
aad94676 MR |
953 | `allout-init' works by setting up (or removing) |
954 | `allout-find-file-hook' in `find-file-hooks', and giving | |
955 | `allout-auto-activation' a suitable setting. | |
19b84ba3 RS |
956 | |
957 | To prime your emacs session for full auto-outline operation, include | |
958 | the following two lines in your emacs init file: | |
959 | ||
960 | \(require 'allout) | |
fd5359c6 | 961 | \(allout-init t)" |
19b84ba3 | 962 | |
8d118843 RS |
963 | (interactive) |
964 | (if (interactive-p) | |
19b84ba3 | 965 | (progn |
8d118843 RS |
966 | (setq mode |
967 | (completing-read | |
968 | (concat "Select outline auto setup mode " | |
969 | "(empty for report, ? for options) ") | |
970 | '(("nil")("full")("activate")("deactivate") | |
971 | ("ask") ("report") ("")) | |
972 | nil | |
973 | t)) | |
974 | (if (string= mode "") | |
975 | (setq mode 'report) | |
976 | (setq mode (intern-soft mode))))) | |
977 | (let | |
978 | ;; convenience aliases, for consistent ref to respective vars: | |
fd5359c6 MR |
979 | ((hook 'allout-find-file-hook) |
980 | (curr-mode 'allout-auto-activation)) | |
353e2ef2 | 981 | |
8d118843 RS |
982 | (cond ((not mode) |
983 | (setq find-file-hooks (delq hook find-file-hooks)) | |
984 | (if (interactive-p) | |
985 | (message "Allout outline mode auto-activation inhibited."))) | |
986 | ((eq mode 'report) | |
9471aeec MR |
987 | (if (memq hook find-file-hooks) |
988 | ;; Just punt and use the reports from each of the modes: | |
989 | (allout-init (symbol-value curr-mode)) | |
990 | (allout-init nil) | |
991 | (message "Allout outline mode auto-activation inhibited."))) | |
8d118843 | 992 | (t (add-hook 'find-file-hooks hook) |
353e2ef2 | 993 | (set curr-mode ; `set', not `setq'! |
8d118843 RS |
994 | (cond ((eq mode 'activate) |
995 | (message | |
996 | "Outline mode auto-activation enabled.") | |
997 | 'activate) | |
998 | ((eq mode 'report) | |
999 | ;; Return the current mode setting: | |
fd5359c6 | 1000 | (allout-init mode)) |
8d118843 RS |
1001 | ((eq mode 'ask) |
1002 | (message | |
1003 | (concat "Outline mode auto-activation and " | |
1004 | "-layout \(upon confirmation) enabled.")) | |
1005 | 'ask) | |
1006 | ((message | |
1007 | "Outline mode auto-activation and -layout enabled.") | |
1008 | 'full))))))) | |
9179616f | 1009 | |
fd5359c6 MR |
1010 | ;;;_ > allout-setup-menubar () |
1011 | (defun allout-setup-menubar () | |
aad94676 | 1012 | "Populate the current buffer's menubar with `allout-mode' stuff." |
fd5359c6 MR |
1013 | (let ((menus (list allout-mode-exposure-menu |
1014 | allout-mode-editing-menu | |
1015 | allout-mode-navigation-menu | |
1016 | allout-mode-misc-menu)) | |
9179616f DL |
1017 | cur) |
1018 | (while menus | |
1019 | (setq cur (car menus) | |
1020 | menus (cdr menus)) | |
1021 | (easy-menu-add cur)))) | |
fd5359c6 | 1022 | ;;;_ > allout-mode (&optional toggle) |
19b84ba3 | 1023 | ;;;_ : Defun: |
fd5359c6 | 1024 | (defun allout-mode (&optional toggle) |
c567ac01 | 1025 | ;;;_ . Doc string: |
19b84ba3 RS |
1026 | "Toggle minor mode for controlling exposure and editing of text outlines. |
1027 | ||
9179616f DL |
1028 | Optional arg forces mode to re-initialize iff arg is positive num or |
1029 | symbol. Allout outline mode always runs as a minor mode. | |
19b84ba3 | 1030 | |
aad94676 | 1031 | Allout outline mode provides extensive outline oriented formatting and |
9179616f DL |
1032 | manipulation. It enables structural editing of outlines, as well as |
1033 | navigation and exposure. It also is specifically aimed at | |
1034 | accommodating syntax-sensitive text like programming languages. \(For | |
1035 | an example, see the allout code itself, which is organized as an allout | |
1036 | outline.) | |
19b84ba3 | 1037 | |
9179616f | 1038 | In addition to outline navigation and exposure, allout includes: |
19b84ba3 | 1039 | |
9179616f DL |
1040 | - topic-oriented repositioning, cut, and paste |
1041 | - integral outline exposure-layout | |
1042 | - incremental search with dynamic exposure and reconcealment of hidden text | |
1043 | - automatic topic-number maintenance | |
1044 | - \"Hot-spot\" operation, for single-keystroke maneuvering and | |
fd5359c6 | 1045 | exposure control. \(See the allout-mode docstring.) |
9179616f DL |
1046 | |
1047 | and many other features. | |
19b84ba3 RS |
1048 | |
1049 | Below is a description of the bindings, and then explanation of | |
2265e017 | 1050 | special `allout-mode' features and terminology. See also the outline |
9179616f | 1051 | menubar additions for quick reference to many of the features, and see |
fd5359c6 | 1052 | the docstring of the variable `allout-init' for instructions on |
2265e017 | 1053 | priming your emacs session for automatic activation of `allout-mode'. |
9179616f | 1054 | |
19b84ba3 | 1055 | |
fd5359c6 MR |
1056 | The bindings are dictated by the `allout-keybindings-list' and |
1057 | `allout-command-prefix' variables. | |
19b84ba3 RS |
1058 | |
1059 | Navigation: Exposure Control: | |
1060 | ---------- ---------------- | |
fd5359c6 MR |
1061 | C-c C-n allout-next-visible-heading | C-c C-h allout-hide-current-subtree |
1062 | C-c C-p allout-previous-visible-heading | C-c C-i allout-show-children | |
1063 | C-c C-u allout-up-current-level | C-c C-s allout-show-current-subtree | |
1064 | C-c C-f allout-forward-current-level | C-c C-o allout-show-current-entry | |
1065 | C-c C-b allout-backward-current-level | ^U C-c C-s allout-show-all | |
1066 | C-c C-e allout-end-of-current-entry | allout-hide-current-leaves | |
1067 | C-c C-a allout-beginning-of-current-entry, alternately, goes to hot-spot | |
19b84ba3 RS |
1068 | |
1069 | Topic Header Production: | |
1070 | ----------------------- | |
fd5359c6 MR |
1071 | C-c<SP> allout-open-sibtopic Create a new sibling after current topic. |
1072 | C-c . allout-open-subtopic ... an offspring of current topic. | |
1073 | C-c , allout-open-supertopic ... a sibling of the current topic's parent. | |
19b84ba3 RS |
1074 | |
1075 | Topic Level and Prefix Adjustment: | |
1076 | --------------------------------- | |
fd5359c6 MR |
1077 | C-c > allout-shift-in Shift current topic and all offspring deeper. |
1078 | C-c < allout-shift-out ... less deep. | |
1079 | C-c<CR> allout-rebullet-topic Reconcile bullets of topic and its offspring | |
19b84ba3 RS |
1080 | - distinctive bullets are not changed, others |
1081 | alternated according to nesting depth. | |
fd5359c6 | 1082 | C-c b allout-rebullet-current-heading Prompt for alternate bullet for |
19b84ba3 | 1083 | current topic. |
fd5359c6 | 1084 | C-c # allout-number-siblings Number bullets of topic and siblings - the |
1977b8f6 RS |
1085 | offspring are not affected. With repeat |
1086 | count, revoke numbering. | |
1087 | ||
19b84ba3 RS |
1088 | Topic-oriented Killing and Yanking: |
1089 | ---------------------------------- | |
fd5359c6 MR |
1090 | C-c C-k allout-kill-topic Kill current topic, including offspring. |
1091 | C-k allout-kill-line Like kill-line, but reconciles numbering, etc. | |
1092 | C-y allout-yank Yank, adjusting depth of yanked topic to | |
1977b8f6 | 1093 | depth of heading if yanking into bare topic |
19b84ba3 | 1094 | heading (ie, prefix sans text). |
fd5359c6 | 1095 | M-y allout-yank-pop Is to allout-yank as yank-pop is to yank |
1977b8f6 | 1096 | |
19b84ba3 RS |
1097 | Misc commands: |
1098 | ------------- | |
19b84ba3 RS |
1099 | M-x outlineify-sticky Activate outline mode for current buffer, |
1100 | and establish a default file-var setting | |
fd5359c6 MR |
1101 | for `allout-layout'. |
1102 | C-c C-SPC allout-mark-topic | |
1103 | C-c = c allout-copy-exposed-to-buffer | |
9179616f DL |
1104 | Duplicate outline, sans concealed text, to |
1105 | buffer with name derived from derived from | |
1106 | that of current buffer - \"*XXX exposed*\". | |
fd5359c6 | 1107 | C-c = p allout-flatten-exposed-to-buffer |
9179616f DL |
1108 | Like above 'copy-exposed', but convert topic |
1109 | prefixes to section.subsection... numeric | |
1110 | format. | |
fd5359c6 | 1111 | ESC ESC (allout-init t) Setup emacs session for outline mode |
19b84ba3 | 1112 | auto-activation. |
1977b8f6 | 1113 | |
19b84ba3 | 1114 | HOT-SPOT Operation |
c567ac01 | 1115 | |
19b84ba3 RS |
1116 | Hot-spot operation provides a means for easy, single-keystroke outline |
1117 | navigation and exposure control. | |
c567ac01 | 1118 | |
fd5359c6 | 1119 | \\<allout-mode-map> |
19b84ba3 RS |
1120 | When the text cursor is positioned directly on the bullet character of |
1121 | a topic, regular characters (a to z) invoke the commands of the | |
fd5359c6 | 1122 | corresponding allout-mode keymap control chars. For example, \"f\" |
19b84ba3 | 1123 | would invoke the command typically bound to \"C-c C-f\" |
fd5359c6 | 1124 | \(\\[allout-forward-current-level] `allout-forward-current-level'). |
19b84ba3 RS |
1125 | |
1126 | Thus, by positioning the cursor on a topic bullet, you can execute | |
c567ac01 | 1127 | the outline navigation and manipulation commands with a single |
19b84ba3 RS |
1128 | keystroke. Non-literal chars never get this special translation, so |
1129 | you can use them to get away from the hot-spot, and back to normal | |
1130 | operation. | |
c567ac01 | 1131 | |
fd5359c6 | 1132 | Note that the command `allout-beginning-of-current-entry' \(\\[allout-beginning-of-current-entry]\) |
c567ac01 | 1133 | will move to the hot-spot when the cursor is already located at the |
fd5359c6 | 1134 | beginning of the current entry, so you can simply hit \\[allout-beginning-of-current-entry] |
c567ac01 | 1135 | twice in a row to get to the hot-spot. |
1977b8f6 | 1136 | |
19b84ba3 | 1137 | Terminology |
1977b8f6 | 1138 | |
c567ac01 RS |
1139 | Topic hierarchy constituents - TOPICS and SUBTOPICS: |
1140 | ||
1141 | TOPIC: A basic, coherent component of an emacs outline. It can | |
1142 | contain other topics, and it can be subsumed by other topics, | |
1143 | CURRENT topic: | |
1144 | The visible topic most immediately containing the cursor. | |
19b84ba3 RS |
1145 | DEPTH: The degree of nesting of a topic; it increases with |
1146 | containment. Also called the: | |
c567ac01 RS |
1147 | LEVEL: The same as DEPTH. |
1148 | ||
1149 | ANCESTORS: | |
1150 | The topics that contain a topic. | |
1151 | PARENT: A topic's immediate ancestor. It has a depth one less than | |
1152 | the topic. | |
1153 | OFFSPRING: | |
19b84ba3 RS |
1154 | The topics contained by a topic; |
1155 | SUBTOPIC: | |
1156 | An immediate offspring of a topic; | |
c567ac01 RS |
1157 | CHILDREN: |
1158 | The immediate offspring of a topic. | |
1159 | SIBLINGS: | |
19b84ba3 | 1160 | Topics having the same parent and depth. |
353e2ef2 | 1161 | |
c567ac01 RS |
1162 | Topic text constituents: |
1163 | ||
1164 | HEADER: The first line of a topic, include the topic PREFIX and header | |
353e2ef2 | 1165 | text. |
c567ac01 RS |
1166 | PREFIX: The leading text of a topic which which distinguishes it from |
1167 | normal text. It has a strict form, which consists of a | |
1168 | prefix-lead string, padding, and a bullet. The bullet may be | |
1169 | followed by a number, indicating the ordinal number of the | |
1170 | topic among its siblings, a space, and then the header text. | |
1171 | ||
1172 | The relative length of the PREFIX determines the nesting depth | |
1173 | of the topic. | |
1174 | PREFIX-LEAD: | |
353e2ef2 | 1175 | The string at the beginning of a topic prefix, normally a `.'. |
c567ac01 | 1176 | It can be customized by changing the setting of |
2265e017 | 1177 | `allout-header-prefix' and then reinitializing `allout-mode'. |
c567ac01 RS |
1178 | |
1179 | By setting the prefix-lead to the comment-string of a | |
aad94676 | 1180 | programming language, you can embed outline structuring in |
c567ac01 | 1181 | program code without interfering with the language processing |
fd5359c6 | 1182 | of that code. See `allout-use-mode-specific-leader' |
19b84ba3 | 1183 | docstring for more detail. |
c567ac01 RS |
1184 | PREFIX-PADDING: |
1185 | Spaces or asterisks which separate the prefix-lead and the | |
1186 | bullet, according to the depth of the topic. | |
1187 | BULLET: A character at the end of the topic prefix, it must be one of | |
fd5359c6 MR |
1188 | the characters listed on `allout-plain-bullets-string' or |
1189 | `allout-distinctive-bullets-string'. (See the documentation | |
c567ac01 RS |
1190 | for these variables for more details.) The default choice of |
1191 | bullet when generating varies in a cycle with the depth of the | |
1192 | topic. | |
1193 | ENTRY: The text contained in a topic before any offspring. | |
1194 | BODY: Same as ENTRY. | |
1195 | ||
1196 | ||
1197 | EXPOSURE: | |
1198 | The state of a topic which determines the on-screen visibility | |
353e2ef2 | 1199 | of its offspring and contained text. |
c567ac01 RS |
1200 | CONCEALED: |
1201 | Topics and entry text whose display is inhibited. Contiguous | |
353e2ef2 KH |
1202 | units of concealed text is represented by `...' ellipses. |
1203 | (Ref the `selective-display' var.) | |
c567ac01 RS |
1204 | |
1205 | Concealed topics are effectively collapsed within an ancestor. | |
1206 | CLOSED: A topic whose immediate offspring and body-text is concealed. | |
353e2ef2 | 1207 | OPEN: A topic that is not closed, though its offspring or body may be." |
c567ac01 | 1208 | ;;;_ . Code |
1977b8f6 RS |
1209 | (interactive "P") |
1210 | ||
c567ac01 | 1211 | (let* ((active (and (not (equal major-mode 'outline)) |
fd5359c6 | 1212 | (allout-mode-p))) |
353e2ef2 | 1213 | ; Massage universal-arg `toggle' val: |
c567ac01 | 1214 | (toggle (and toggle |
19b84ba3 RS |
1215 | (or (and (listp toggle)(car toggle)) |
1216 | toggle))) | |
a0776d6b | 1217 | ; Activation specifically demanded? |
c567ac01 | 1218 | (explicit-activation (or |
19b84ba3 RS |
1219 | ;; |
1220 | (and toggle | |
1221 | (or (symbolp toggle) | |
1222 | (and (natnump toggle) | |
1223 | (not (zerop toggle))))))) | |
fd5359c6 MR |
1224 | ;; allout-mode already called once during this complex command? |
1225 | (same-complex-command (eq allout-v18/19-file-var-hack | |
19b84ba3 RS |
1226 | (car command-history))) |
1227 | do-layout | |
1228 | ) | |
c567ac01 | 1229 | |
19b84ba3 | 1230 | ; See comments below re v19.18,.19 bug. |
fd5359c6 | 1231 | (setq allout-v18/19-file-var-hack (car command-history)) |
c567ac01 | 1232 | |
1977b8f6 RS |
1233 | (cond |
1234 | ||
19b84ba3 | 1235 | ;; Provision for v19.18, 19.19 bug - |
c567ac01 RS |
1236 | ;; Emacs v 19.18, 19.19 file-var code invokes prop-line-designated |
1237 | ;; modes twice when file is visited. We have to avoid toggling mode | |
1238 | ;; off on second invocation, so we detect it as best we can, and | |
1239 | ;; skip everything. | |
1240 | ((and same-complex-command ; Still in same complex command | |
aad94676 | 1241 | ; as last time `allout-mode' invoked. |
19b84ba3 RS |
1242 | active ; Already activated. |
1243 | (not explicit-activation) ; Prop-line file-vars don't have args. | |
1244 | (string-match "^19.1[89]" ; Bug only known to be in v19.18 and | |
1245 | emacs-version)); 19.19. | |
c567ac01 | 1246 | t) |
353e2ef2 | 1247 | |
19b84ba3 | 1248 | ;; Deactivation: |
c567ac01 | 1249 | ((and (not explicit-activation) |
19b84ba3 RS |
1250 | (or active toggle)) |
1251 | ; Activation not explicitly | |
1252 | ; requested, and either in | |
1253 | ; active state or *de*activation | |
1254 | ; specifically requested: | |
fd5359c6 | 1255 | (setq allout-explicitly-deactivated t) |
c567ac01 | 1256 | (if (string-match "^18\." emacs-version) |
19b84ba3 RS |
1257 | ; Revoke those keys that remain |
1258 | ; as we set them: | |
c567ac01 | 1259 | (let ((curr-loc (current-local-map))) |
9179616f DL |
1260 | (mapcar (function |
1261 | (lambda (cell) | |
19b84ba3 RS |
1262 | (if (eq (lookup-key curr-loc (car cell)) |
1263 | (car (cdr cell))) | |
1264 | (define-key curr-loc (car cell) | |
fd5359c6 MR |
1265 | (assq (car cell) allout-prior-bindings))))) |
1266 | allout-added-bindings) | |
1267 | (allout-resumptions 'allout-added-bindings) | |
1268 | (allout-resumptions 'allout-prior-bindings))) | |
c567ac01 | 1269 | |
fd5359c6 | 1270 | (if allout-old-style-prefixes |
c567ac01 | 1271 | (progn |
fd5359c6 MR |
1272 | (allout-resumptions 'allout-primary-bullet) |
1273 | (allout-resumptions 'allout-old-style-prefixes))) | |
1274 | (allout-resumptions 'selective-display) | |
9179616f | 1275 | (if (and (boundp 'before-change-functions) before-change-functions) |
fd5359c6 | 1276 | (allout-resumptions 'before-change-functions)) |
c567ac01 | 1277 | (setq local-write-file-hooks |
fd5359c6 | 1278 | (delq 'allout-write-file-hook |
19b84ba3 | 1279 | local-write-file-hooks)) |
fd5359c6 MR |
1280 | (allout-resumptions 'paragraph-start) |
1281 | (allout-resumptions 'paragraph-separate) | |
1282 | (allout-resumptions (if (string-match "^18" emacs-version) | |
19b84ba3 RS |
1283 | 'auto-fill-hook |
1284 | 'auto-fill-function)) | |
fd5359c6 MR |
1285 | (allout-resumptions 'allout-former-auto-filler) |
1286 | (setq allout-mode nil)) | |
1977b8f6 | 1287 | |
19b84ba3 | 1288 | ;; Activation: |
1977b8f6 | 1289 | ((not active) |
fd5359c6 MR |
1290 | (setq allout-explicitly-deactivated nil) |
1291 | (if allout-old-style-prefixes | |
c567ac01 | 1292 | (progn ; Inhibit all the fancy formatting: |
fd5359c6 MR |
1293 | (allout-resumptions 'allout-primary-bullet '("*")) |
1294 | (allout-resumptions 'allout-old-style-prefixes '(())))) | |
19b84ba3 | 1295 | |
fd5359c6 MR |
1296 | (allout-infer-header-lead) |
1297 | (allout-infer-body-reindent) | |
19b84ba3 | 1298 | |
fd5359c6 | 1299 | (set-allout-regexp) |
19b84ba3 RS |
1300 | |
1301 | ; Produce map from current version | |
fd5359c6 | 1302 | ; of allout-keybindings-list: |
c567ac01 RS |
1303 | (if (boundp 'minor-mode-map-alist) |
1304 | ||
1305 | (progn ; V19, and maybe lucid and | |
19b84ba3 | 1306 | ; epoch, minor-mode key bindings: |
fd5359c6 MR |
1307 | (setq allout-mode-map |
1308 | (produce-allout-mode-map allout-keybindings-list)) | |
1309 | (produce-allout-mode-menubar-entries) | |
1310 | (fset 'allout-mode-map allout-mode-map) | |
19b84ba3 RS |
1311 | ; Include on minor-mode-map-alist, |
1312 | ; if not already there: | |
fd5359c6 | 1313 | (if (not (member '(allout-mode . allout-mode-map) |
19b84ba3 RS |
1314 | minor-mode-map-alist)) |
1315 | (setq minor-mode-map-alist | |
fd5359c6 | 1316 | (cons '(allout-mode . allout-mode-map) |
19b84ba3 RS |
1317 | minor-mode-map-alist)))) |
1318 | ||
1319 | ; V18 minor-mode key bindings: | |
1320 | ; Stash record of added bindings | |
1321 | ; for later revocation: | |
fd5359c6 MR |
1322 | (allout-resumptions 'allout-added-bindings |
1323 | (list allout-keybindings-list)) | |
1324 | (allout-resumptions 'allout-prior-bindings | |
19b84ba3 RS |
1325 | (list (current-local-map))) |
1326 | ; and add them: | |
fd5359c6 | 1327 | (use-local-map (produce-allout-mode-map allout-keybindings-list |
19b84ba3 | 1328 | (current-local-map))) |
c567ac01 | 1329 | ) |
353e2ef2 | 1330 | |
19b84ba3 RS |
1331 | ; selective-display is the |
1332 | ; emacs conditional exposure | |
1333 | ; mechanism: | |
fd5359c6 MR |
1334 | (allout-resumptions 'selective-display '(t)) |
1335 | (if allout-inhibit-protection | |
c567ac01 | 1336 | t |
fd5359c6 MR |
1337 | (allout-resumptions 'before-change-functions |
1338 | '(allout-before-change-protect))) | |
1339 | (add-hook 'pre-command-hook 'allout-pre-command-business) | |
1340 | (add-hook 'post-command-hook 'allout-post-command-business) | |
19b84ba3 RS |
1341 | ; Temporarily set by any outline |
1342 | ; functions that can be trusted to | |
1343 | ; deal properly with concealed text. | |
fd5359c6 | 1344 | (add-hook 'local-write-file-hooks 'allout-write-file-hook) |
19b84ba3 RS |
1345 | ; Custom auto-fill func, to support |
1346 | ; respect for topic headline, | |
1347 | ; hanging-indents, etc: | |
c567ac01 | 1348 | (let* ((fill-func-var (if (string-match "^18" emacs-version) |
19b84ba3 RS |
1349 | 'auto-fill-hook |
1350 | 'auto-fill-function)) | |
1351 | (fill-func (symbol-value fill-func-var))) | |
fd5359c6 MR |
1352 | ;; Register prevailing fill func for use by allout-auto-fill: |
1353 | (allout-resumptions 'allout-former-auto-filler (list fill-func)) | |
1354 | ;; Register allout-auto-fill to be used if filling is active: | |
1355 | (allout-resumptions fill-func-var '(allout-auto-fill))) | |
c567ac01 | 1356 | ;; Paragraphs are broken by topic headlines. |
1977b8f6 | 1357 | (make-local-variable 'paragraph-start) |
fd5359c6 | 1358 | (allout-resumptions 'paragraph-start |
9179616f | 1359 | (list (concat paragraph-start "\\|^\\(" |
fd5359c6 | 1360 | allout-regexp "\\)"))) |
1977b8f6 | 1361 | (make-local-variable 'paragraph-separate) |
fd5359c6 | 1362 | (allout-resumptions 'paragraph-separate |
9179616f | 1363 | (list (concat paragraph-separate "\\|^\\(" |
fd5359c6 | 1364 | allout-regexp "\\)"))) |
c567ac01 | 1365 | |
fd5359c6 | 1366 | (or (assq 'allout-mode minor-mode-alist) |
c567ac01 | 1367 | (setq minor-mode-alist |
aad94676 | 1368 | (cons '(allout-mode " Allout") minor-mode-alist))) |
19b84ba3 | 1369 | |
fd5359c6 | 1370 | (allout-setup-menubar) |
9179616f | 1371 | |
fd5359c6 | 1372 | (if allout-layout |
19b84ba3 | 1373 | (setq do-layout t)) |
1977b8f6 | 1374 | |
fd5359c6 MR |
1375 | (if (and allout-isearch-dynamic-expose |
1376 | (not (fboundp 'allout-real-isearch-abort))) | |
1377 | (allout-enwrap-isearch)) | |
19b84ba3 | 1378 | |
fd5359c6 MR |
1379 | (run-hooks 'allout-mode-hook) |
1380 | (setq allout-mode t)) | |
19b84ba3 RS |
1381 | |
1382 | ;; Reactivation: | |
8d118843 | 1383 | ((setq do-layout t) |
fd5359c6 | 1384 | (allout-infer-body-reindent)) |
c567ac01 | 1385 | ) ; cond |
19b84ba3 RS |
1386 | |
1387 | (if (and do-layout | |
fd5359c6 MR |
1388 | allout-auto-activation |
1389 | (listp allout-layout) | |
1390 | (and (not (eq allout-auto-activation 'activate)) | |
1391 | (if (eq allout-auto-activation 'ask) | |
19b84ba3 RS |
1392 | (if (y-or-n-p (format "Expose %s with layout '%s'? " |
1393 | (buffer-name) | |
fd5359c6 | 1394 | allout-layout)) |
19b84ba3 | 1395 | t |
8d118843 | 1396 | (message "Skipped %s layout." (buffer-name)) |
19b84ba3 RS |
1397 | nil) |
1398 | t))) | |
1399 | (save-excursion | |
1400 | (message "Adjusting '%s' exposure..." (buffer-name)) | |
1401 | (goto-char 0) | |
fd5359c6 | 1402 | (allout-this-or-next-heading) |
8d118843 | 1403 | (condition-case err |
353e2ef2 | 1404 | (progn |
fd5359c6 | 1405 | (apply 'allout-expose-topic (list allout-layout)) |
8d118843 RS |
1406 | (message "Adjusting '%s' exposure... done." (buffer-name))) |
1407 | ;; Problem applying exposure - notify user, but don't | |
1408 | ;; interrupt, eg, file visit: | |
1409 | (error (message "%s" (car (cdr err))) | |
1410 | (sit-for 1))))) | |
fd5359c6 | 1411 | allout-mode |
c567ac01 | 1412 | ) ; let* |
19b84ba3 | 1413 | ) ; defun |
fd5359c6 | 1414 | ;;;_ > allout-minor-mode |
9179616f | 1415 | ;;; XXX released verion doesn't do this? |
fd5359c6 | 1416 | (defalias 'allout-minor-mode 'allout-mode) |
1977b8f6 | 1417 | |
fd5359c6 | 1418 | ;;;_ #3 Internal Position State-Tracking - "allout-recent-*" funcs |
19b84ba3 | 1419 | ;;; All the basic outline functions that directly do string matches to |
1977b8f6 | 1420 | ;;; evaluate heading prefix location set the variables |
fd5359c6 MR |
1421 | ;;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end' |
1422 | ;;; when successful. Functions starting with `allout-recent-' all | |
19b84ba3 RS |
1423 | ;;; use this state, providing the means to avoid redundant searches |
1424 | ;;; for just-established data. This optimization can provide | |
1425 | ;;; significant speed improvement, but it must be employed carefully. | |
fd5359c6 MR |
1426 | ;;;_ = allout-recent-prefix-beginning |
1427 | (defvar allout-recent-prefix-beginning 0 | |
c567ac01 | 1428 | "Buffer point of the start of the last topic prefix encountered.") |
fd5359c6 MR |
1429 | (make-variable-buffer-local 'allout-recent-prefix-beginning) |
1430 | ;;;_ = allout-recent-prefix-end | |
1431 | (defvar allout-recent-prefix-end 0 | |
c567ac01 | 1432 | "Buffer point of the end of the last topic prefix encountered.") |
fd5359c6 MR |
1433 | (make-variable-buffer-local 'allout-recent-prefix-end) |
1434 | ;;;_ = allout-recent-end-of-subtree | |
1435 | (defvar allout-recent-end-of-subtree 0 | |
2265e017 | 1436 | "Buffer point last returned by `allout-end-of-current-subtree'.") |
fd5359c6 MR |
1437 | (make-variable-buffer-local 'allout-recent-end-of-subtree) |
1438 | ;;;_ > allout-prefix-data (beg end) | |
1439 | (defmacro allout-prefix-data (beg end) | |
1440 | "Register allout-prefix state data - BEGINNING and END of prefix. | |
1441 | ||
1442 | For reference by `allout-recent' funcs. Returns BEGINNING." | |
1443 | `(setq allout-recent-prefix-end ,end | |
1444 | allout-recent-prefix-beginning ,beg)) | |
1445 | ;;;_ > allout-recent-depth () | |
1446 | (defmacro allout-recent-depth () | |
19b84ba3 | 1447 | "Return depth of last heading encountered by an outline maneuvering function. |
c567ac01 RS |
1448 | |
1449 | All outline functions which directly do string matches to assess | |
2265e017 MR |
1450 | headings set the variables `allout-recent-prefix-beginning' and |
1451 | `allout-recent-prefix-end' if successful. This function uses those settings | |
c567ac01 RS |
1452 | to return the current depth." |
1453 | ||
fd5359c6 MR |
1454 | '(max 1 (- allout-recent-prefix-end |
1455 | allout-recent-prefix-beginning | |
1456 | allout-header-subtraction))) | |
1457 | ;;;_ > allout-recent-prefix () | |
1458 | (defmacro allout-recent-prefix () | |
2265e017 | 1459 | "Like `allout-recent-depth', but returns text of last encountered prefix. |
c567ac01 RS |
1460 | |
1461 | All outline functions which directly do string matches to assess | |
2265e017 MR |
1462 | headings set the variables `allout-recent-prefix-beginning' and |
1463 | `allout-recent-prefix-end' if successful. This function uses those settings | |
c567ac01 | 1464 | to return the current depth." |
fd5359c6 MR |
1465 | '(buffer-substring allout-recent-prefix-beginning |
1466 | allout-recent-prefix-end)) | |
1467 | ;;;_ > allout-recent-bullet () | |
1468 | (defmacro allout-recent-bullet () | |
1469 | "Like allout-recent-prefix, but returns bullet of last encountered prefix. | |
c567ac01 RS |
1470 | |
1471 | All outline functions which directly do string matches to assess | |
2265e017 MR |
1472 | headings set the variables `allout-recent-prefix-beginning' and |
1473 | `allout-recent-prefix-end' if successful. This function uses those settings | |
c567ac01 | 1474 | to return the current depth of the most recently matched topic." |
fd5359c6 MR |
1475 | '(buffer-substring (1- allout-recent-prefix-end) |
1476 | allout-recent-prefix-end)) | |
c567ac01 | 1477 | |
19b84ba3 | 1478 | ;;;_ #4 Navigation |
c567ac01 RS |
1479 | |
1480 | ;;;_ - Position Assessment | |
1481 | ;;;_ : Location Predicates | |
fd5359c6 MR |
1482 | ;;;_ > allout-on-current-heading-p () |
1483 | (defun allout-on-current-heading-p () | |
19b84ba3 RS |
1484 | "Return non-nil if point is on current visible topics' header line. |
1485 | ||
1486 | Actually, returns prefix beginning point." | |
1977b8f6 RS |
1487 | (save-excursion |
1488 | (beginning-of-line) | |
fd5359c6 MR |
1489 | (and (looking-at allout-regexp) |
1490 | (allout-prefix-data (match-beginning 0) (match-end 0))))) | |
1491 | ;;;_ > allout-on-heading-p () | |
1492 | (defalias 'allout-on-heading-p 'allout-on-current-heading-p) | |
1493 | ;;;_ > allout-e-o-prefix-p () | |
1494 | (defun allout-e-o-prefix-p () | |
19b84ba3 | 1495 | "True if point is located where current topic prefix ends, heading begins." |
c567ac01 | 1496 | (and (save-excursion (beginning-of-line) |
fd5359c6 MR |
1497 | (looking-at allout-regexp)) |
1498 | (= (point)(save-excursion (allout-end-of-prefix)(point))))) | |
1499 | ;;;_ > allout-hidden-p () | |
1500 | (defmacro allout-hidden-p () | |
1977b8f6 | 1501 | "True if point is in hidden text." |
c567ac01 RS |
1502 | '(save-excursion |
1503 | (and (re-search-backward "[\n\r]" () t) | |
1504 | (= ?\r (following-char))))) | |
fd5359c6 MR |
1505 | ;;;_ > allout-visible-p () |
1506 | (defmacro allout-visible-p () | |
c567ac01 | 1507 | "True if point is not in hidden text." |
1977b8f6 | 1508 | (interactive) |
fd5359c6 | 1509 | '(not (allout-hidden-p))) |
c567ac01 | 1510 | ;;;_ : Location attributes |
fd5359c6 MR |
1511 | ;;;_ > allout-depth () |
1512 | (defsubst allout-depth () | |
2265e017 | 1513 | "Like `allout-current-depth', but respects hidden as well as visible topics." |
9179616f | 1514 | (save-excursion |
fd5359c6 MR |
1515 | (if (allout-goto-prefix) |
1516 | (allout-recent-depth) | |
9179616f DL |
1517 | (progn |
1518 | ;; Oops, no prefix, zero prefix data: | |
fd5359c6 | 1519 | (allout-prefix-data (point)(point)) |
9179616f DL |
1520 | ;; ... and return 0: |
1521 | 0)))) | |
fd5359c6 MR |
1522 | ;;;_ > allout-current-depth () |
1523 | (defmacro allout-current-depth () | |
19b84ba3 | 1524 | "Return nesting depth of visible topic most immediately containing point." |
c567ac01 | 1525 | '(save-excursion |
fd5359c6 | 1526 | (if (allout-back-to-current-heading) |
c567ac01 | 1527 | (max 1 |
fd5359c6 MR |
1528 | (- allout-recent-prefix-end |
1529 | allout-recent-prefix-beginning | |
1530 | allout-header-subtraction)) | |
c567ac01 | 1531 | 0))) |
fd5359c6 MR |
1532 | ;;;_ > allout-get-current-prefix () |
1533 | (defun allout-get-current-prefix () | |
c567ac01 | 1534 | "Topic prefix of the current topic." |
1977b8f6 | 1535 | (save-excursion |
fd5359c6 MR |
1536 | (if (allout-goto-prefix) |
1537 | (allout-recent-prefix)))) | |
1538 | ;;;_ > allout-get-bullet () | |
1539 | (defun allout-get-bullet () | |
c567ac01 | 1540 | "Return bullet of containing topic (visible or not)." |
1977b8f6 | 1541 | (save-excursion |
fd5359c6 MR |
1542 | (and (allout-goto-prefix) |
1543 | (allout-recent-bullet)))) | |
1544 | ;;;_ > allout-current-bullet () | |
1545 | (defun allout-current-bullet () | |
c567ac01 | 1546 | "Return bullet of current (visible) topic heading, or none if none found." |
1977b8f6 RS |
1547 | (condition-case err |
1548 | (save-excursion | |
fd5359c6 MR |
1549 | (allout-back-to-current-heading) |
1550 | (buffer-substring (- allout-recent-prefix-end 1) | |
1551 | allout-recent-prefix-end)) | |
1977b8f6 | 1552 | ;; Quick and dirty provision, ostensibly for missing bullet: |
9179616f | 1553 | ('args-out-of-range nil)) |
1977b8f6 | 1554 | ) |
fd5359c6 MR |
1555 | ;;;_ > allout-get-prefix-bullet (prefix) |
1556 | (defun allout-get-prefix-bullet (prefix) | |
c567ac01 | 1557 | "Return the bullet of the header prefix string PREFIX." |
1977b8f6 RS |
1558 | ;; Doesn't make sense if we're old-style prefixes, but this just |
1559 | ;; oughtn't be called then, so forget about it... | |
fd5359c6 | 1560 | (if (string-match allout-regexp prefix) |
1977b8f6 | 1561 | (substring prefix (1- (match-end 0)) (match-end 0)))) |
fd5359c6 MR |
1562 | ;;;_ > allout-sibling-index (&optional depth) |
1563 | (defun allout-sibling-index (&optional depth) | |
9179616f DL |
1564 | "Item number of this prospective topic among its siblings. |
1565 | ||
1566 | If optional arg depth is greater than current depth, then we're | |
1567 | opening a new level, and return 0. | |
1568 | ||
1569 | If less than this depth, ascend to that depth and count..." | |
1570 | ||
1571 | (save-excursion | |
1572 | (cond ((and depth (<= depth 0) 0)) | |
fd5359c6 | 1573 | ((or (not depth) (= depth (allout-depth))) |
9179616f | 1574 | (let ((index 1)) |
fd5359c6 | 1575 | (while (allout-previous-sibling (allout-recent-depth) nil) |
9179616f DL |
1576 | (setq index (1+ index))) |
1577 | index)) | |
fd5359c6 MR |
1578 | ((< depth (allout-recent-depth)) |
1579 | (allout-ascend-to-depth depth) | |
1580 | (allout-sibling-index)) | |
9179616f | 1581 | (0)))) |
fd5359c6 MR |
1582 | ;;;_ > allout-topic-flat-index () |
1583 | (defun allout-topic-flat-index () | |
9179616f DL |
1584 | "Return a list indicating point's numeric section.subsect.subsubsect... |
1585 | Outermost is first." | |
fd5359c6 MR |
1586 | (let* ((depth (allout-depth)) |
1587 | (next-index (allout-sibling-index depth)) | |
9179616f DL |
1588 | (rev-sibls nil)) |
1589 | (while (> next-index 0) | |
1590 | (setq rev-sibls (cons next-index rev-sibls)) | |
1591 | (setq depth (1- depth)) | |
fd5359c6 | 1592 | (setq next-index (allout-sibling-index depth))) |
9179616f DL |
1593 | rev-sibls) |
1594 | ) | |
1977b8f6 | 1595 | |
c567ac01 | 1596 | ;;;_ - Navigation macros |
fd5359c6 MR |
1597 | ;;;_ > allout-next-heading () |
1598 | (defsubst allout-next-heading () | |
c567ac01 RS |
1599 | "Move to the heading for the topic \(possibly invisible) before this one. |
1600 | ||
1601 | Returns the location of the heading, or nil if none found." | |
1602 | ||
9179616f | 1603 | (if (and (bobp) (not (eobp))) |
c567ac01 RS |
1604 | (forward-char 1)) |
1605 | ||
fd5359c6 MR |
1606 | (if (re-search-forward allout-line-boundary-regexp nil 0) |
1607 | (allout-prefix-data ; Got valid location state - set vars: | |
9179616f | 1608 | (goto-char (or (match-beginning 2) |
fd5359c6 MR |
1609 | allout-recent-prefix-beginning)) |
1610 | (or (match-end 2) allout-recent-prefix-end)))) | |
1611 | ;;;_ : allout-this-or-next-heading | |
1612 | (defun allout-this-or-next-heading () | |
8d118843 | 1613 | "Position cursor on current or next heading." |
fd5359c6 MR |
1614 | ;; A throwaway non-macro that is defined after allout-next-heading |
1615 | ;; and usable by allout-mode. | |
1616 | (if (not (allout-goto-prefix)) (allout-next-heading))) | |
1617 | ;;;_ > allout-previous-heading () | |
1618 | (defmacro allout-previous-heading () | |
19b84ba3 | 1619 | "Move to the prior \(possibly invisible) heading line. |
c567ac01 RS |
1620 | |
1621 | Return the location of the beginning of the heading, or nil if not found." | |
1622 | ||
1623 | '(if (bobp) | |
1624 | nil | |
fd5359c6 | 1625 | (allout-goto-prefix) |
c567ac01 RS |
1626 | (if |
1627 | ;; searches are unbounded and return nil if failed: | |
fd5359c6 MR |
1628 | (or (re-search-backward allout-line-boundary-regexp nil 0) |
1629 | (looking-at allout-bob-regexp)) | |
19b84ba3 | 1630 | (progn ; Got valid location state - set vars: |
fd5359c6 | 1631 | (allout-prefix-data |
c567ac01 | 1632 | (goto-char (or (match-beginning 2) |
fd5359c6 MR |
1633 | allout-recent-prefix-beginning)) |
1634 | (or (match-end 2) allout-recent-prefix-end)))))) | |
c567ac01 RS |
1635 | |
1636 | ;;;_ - Subtree Charting | |
1637 | ;;;_ " These routines either produce or assess charts, which are | |
1638 | ;;; nested lists of the locations of topics within a subtree. | |
1639 | ;;; | |
1640 | ;;; Use of charts enables efficient navigation of subtrees, by | |
1641 | ;;; requiring only a single regexp-search based traversal, to scope | |
1642 | ;;; out the subtopic locations. The chart then serves as the basis | |
9179616f DL |
1643 | ;;; for assessment or adjustment of the subtree, without redundant |
1644 | ;;; traversal of the structure. | |
c567ac01 | 1645 | |
fd5359c6 MR |
1646 | ;;;_ > allout-chart-subtree (&optional levels orig-depth prev-depth) |
1647 | (defun allout-chart-subtree (&optional levels orig-depth prev-depth) | |
19b84ba3 RS |
1648 | "Produce a location \"chart\" of subtopics of the containing topic. |
1649 | ||
a0776d6b | 1650 | Optional argument LEVELS specifies the depth \(relative to start |
9179616f | 1651 | depth) for the chart. Subsequent optional args are not for public |
19b84ba3 RS |
1652 | use. |
1653 | ||
aad94676 | 1654 | Charts are used to capture outline structure, so that outline altering |
19b84ba3 RS |
1655 | routines need assess the structure only once, and then use the chart |
1656 | for their elaborate manipulations. | |
1657 | ||
1658 | Topics are entered in the chart so the last one is at the car. | |
1659 | The entry for each topic consists of an integer indicating the point | |
1660 | at the beginning of the topic. Charts for offspring consists of a | |
1661 | list containing, recursively, the charts for the respective subtopics. | |
1662 | The chart for a topics' offspring precedes the entry for the topic | |
1663 | itself. | |
1664 | ||
1665 | The other function parameters are for internal recursion, and should | |
1666 | not be specified by external callers. ORIG-DEPTH is depth of topic at | |
1667 | starting point, and PREV-DEPTH is depth of prior topic." | |
1668 | ||
353e2ef2 | 1669 | (let ((original (not orig-depth)) ; `orig-depth' set only in recursion. |
19b84ba3 RS |
1670 | chart curr-depth) |
1671 | ||
1672 | (if original ; Just starting? | |
1673 | ; Register initial settings and | |
1674 | ; position to first offspring: | |
fd5359c6 | 1675 | (progn (setq orig-depth (allout-depth)) |
19b84ba3 | 1676 | (or prev-depth (setq prev-depth (1+ orig-depth))) |
fd5359c6 | 1677 | (allout-next-heading))) |
c567ac01 | 1678 | |
19b84ba3 RS |
1679 | ;; Loop over the current levels' siblings. Besides being more |
1680 | ;; efficient than tail-recursing over a level, it avoids exceeding | |
1681 | ;; the typically quite constrained emacs max-lisp-eval-depth. | |
9179616f | 1682 | ;; |
19b84ba3 RS |
1683 | ;; Probably would speed things up to implement loop-based stack |
1684 | ;; operation rather than recursing for lower levels. Bah. | |
9179616f | 1685 | |
c567ac01 | 1686 | (while (and (not (eobp)) |
19b84ba3 | 1687 | ; Still within original topic? |
fd5359c6 | 1688 | (< orig-depth (setq curr-depth (allout-recent-depth))) |
19b84ba3 RS |
1689 | (cond ((= prev-depth curr-depth) |
1690 | ;; Register this one and move on: | |
1691 | (setq chart (cons (point) chart)) | |
1692 | (if (and levels (<= levels 1)) | |
1693 | ;; At depth limit - skip sublevels: | |
fd5359c6 | 1694 | (or (allout-next-sibling curr-depth) |
19b84ba3 RS |
1695 | ;; or no more siblings - proceed to |
1696 | ;; next heading at lesser depth: | |
e6a9aec7 | 1697 | (while (and (<= curr-depth |
fd5359c6 MR |
1698 | (allout-recent-depth)) |
1699 | (allout-next-heading)))) | |
1700 | (allout-next-heading))) | |
19b84ba3 RS |
1701 | |
1702 | ((and (< prev-depth curr-depth) | |
1703 | (or (not levels) | |
1704 | (> levels 0))) | |
1705 | ;; Recurse on deeper level of curr topic: | |
1706 | (setq chart | |
fd5359c6 | 1707 | (cons (allout-chart-subtree (and levels |
19b84ba3 RS |
1708 | (1- levels)) |
1709 | orig-depth | |
1710 | curr-depth) | |
1711 | chart)) | |
1712 | ;; ... then continue with this one. | |
1713 | ) | |
1714 | ||
1715 | ;; ... else nil if we've ascended back to prev-depth. | |
1716 | ||
1717 | ))) | |
1718 | ||
1719 | (if original ; We're at the last sibling on | |
1720 | ; the original level. Position | |
1721 | ; to the end of it: | |
c567ac01 | 1722 | (progn (and (not (eobp)) (forward-char -1)) |
9179616f | 1723 | (and (memq (preceding-char) '(?\n ?\r)) |
c567ac01 RS |
1724 | (memq (aref (buffer-substring (max 1 (- (point) 3)) |
1725 | (point)) | |
1726 | 1) | |
9179616f | 1727 | '(?\n ?\r)) |
19b84ba3 | 1728 | (forward-char -1)) |
fd5359c6 | 1729 | (setq allout-recent-end-of-subtree (point)))) |
353e2ef2 | 1730 | |
c567ac01 RS |
1731 | chart ; (nreverse chart) not necessary, |
1732 | ; and maybe not preferable. | |
1733 | )) | |
fd5359c6 MR |
1734 | ;;;_ > allout-chart-siblings (&optional start end) |
1735 | (defun allout-chart-siblings (&optional start end) | |
c567ac01 | 1736 | "Produce a list of locations of this and succeeding sibling topics. |
fd5359c6 | 1737 | Effectively a top-level chart of siblings. See `allout-chart-subtree' |
c567ac01 RS |
1738 | for an explanation of charts." |
1739 | (save-excursion | |
fd5359c6 | 1740 | (if (allout-goto-prefix) |
c567ac01 | 1741 | (let ((chart (list (point)))) |
fd5359c6 | 1742 | (while (allout-next-sibling) |
c567ac01 | 1743 | (setq chart (cons (point) chart))) |
19b84ba3 | 1744 | (if chart (setq chart (nreverse chart))))))) |
fd5359c6 MR |
1745 | ;;;_ > allout-chart-to-reveal (chart depth) |
1746 | (defun allout-chart-to-reveal (chart depth) | |
c567ac01 | 1747 | |
19b84ba3 | 1748 | "Return a flat list of hidden points in subtree CHART, up to DEPTH. |
c567ac01 | 1749 | |
19b84ba3 | 1750 | Note that point can be left at any of the points on chart, or at the |
c567ac01 RS |
1751 | start point." |
1752 | ||
1753 | (let (result here) | |
1754 | (while (and (or (eq depth t) (> depth 0)) | |
1755 | chart) | |
1756 | (setq here (car chart)) | |
1757 | (if (listp here) | |
fd5359c6 | 1758 | (let ((further (allout-chart-to-reveal here (or (eq depth t) |
c567ac01 RS |
1759 | (1- depth))))) |
1760 | ;; We're on the start of a subtree - recurse with it, if there's | |
1761 | ;; more depth to go: | |
1762 | (if further (setq result (append further result))) | |
1763 | (setq chart (cdr chart))) | |
1764 | (goto-char here) | |
1765 | (if (= (preceding-char) ?\r) | |
1766 | (setq result (cons here result))) | |
1767 | (setq chart (cdr chart)))) | |
1768 | result)) | |
fd5359c6 MR |
1769 | ;;;_ X allout-chart-spec (chart spec &optional exposing) |
1770 | (defun allout-chart-spec (chart spec &optional exposing) | |
9179616f | 1771 | "Not yet \(if ever) implemented. |
19b84ba3 RS |
1772 | |
1773 | Produce exposure directives given topic/subtree CHART and an exposure SPEC. | |
1774 | ||
1775 | Exposure spec indicates the locations to be exposed and the prescribed | |
1776 | exposure status. Optional arg EXPOSING is an integer, with 0 | |
1777 | indicating pending concealment, anything higher indicating depth to | |
c567ac01 RS |
1778 | which subtopic headers should be exposed, and negative numbers |
1779 | indicating (negative of) the depth to which subtopic headers and | |
1780 | bodies should be exposed. | |
1781 | ||
1782 | The produced list can have two types of entries. Bare numbers | |
1783 | indicate points in the buffer where topic headers that should be | |
1784 | exposed reside. | |
19b84ba3 | 1785 | |
c567ac01 RS |
1786 | - bare negative numbers indicates that the topic starting at the |
1787 | point which is the negative of the number should be opened, | |
1788 | including their entries. | |
1789 | - bare positive values indicate that this topic header should be | |
a0776d6b | 1790 | opened. |
c567ac01 | 1791 | - Lists signify the beginning and end points of regions that should |
353e2ef2 | 1792 | be flagged, and the flag to employ. (For concealment: `\(\?r\)', and |
c567ac01 RS |
1793 | exposure:" |
1794 | (while spec | |
353e2ef2 | 1795 | (cond ((listp spec) |
c567ac01 RS |
1796 | ) |
1797 | ) | |
1798 | (setq spec (cdr spec))) | |
1799 | ) | |
1800 | ||
1801 | ;;;_ - Within Topic | |
fd5359c6 MR |
1802 | ;;;_ > allout-goto-prefix () |
1803 | (defun allout-goto-prefix () | |
9179616f | 1804 | "Put point at beginning of immediately containing outline topic. |
19b84ba3 | 1805 | |
9179616f | 1806 | Goes to most immediate subsequent topic if none immediately containing. |
19b84ba3 RS |
1807 | |
1808 | Not sensitive to topic visibility. | |
c567ac01 | 1809 | |
d27081f5 | 1810 | Returns the point at the beginning of the prefix, or nil if none." |
c567ac01 | 1811 | |
19b84ba3 RS |
1812 | (let (done) |
1813 | (while (and (not done) | |
1814 | (re-search-backward "[\n\r]" nil 1)) | |
1815 | (forward-char 1) | |
fd5359c6 MR |
1816 | (if (looking-at allout-regexp) |
1817 | (setq done (allout-prefix-data (match-beginning 0) | |
19b84ba3 RS |
1818 | (match-end 0))) |
1819 | (forward-char -1))) | |
1820 | (if (bobp) | |
fd5359c6 MR |
1821 | (cond ((looking-at allout-regexp) |
1822 | (allout-prefix-data (match-beginning 0)(match-end 0))) | |
1823 | ((allout-next-heading)) | |
19b84ba3 RS |
1824 | (done)) |
1825 | done))) | |
fd5359c6 MR |
1826 | ;;;_ > allout-end-of-prefix () |
1827 | (defun allout-end-of-prefix (&optional ignore-decorations) | |
19b84ba3 RS |
1828 | "Position cursor at beginning of header text. |
1829 | ||
1830 | If optional IGNORE-DECORATIONS is non-nil, put just after bullet, | |
1831 | otherwise skip white space between bullet and ensuing text." | |
c567ac01 | 1832 | |
fd5359c6 | 1833 | (if (not (allout-goto-prefix)) |
1977b8f6 RS |
1834 | nil |
1835 | (let ((match-data (match-data))) | |
1836 | (goto-char (match-end 0)) | |
c567ac01 RS |
1837 | (if ignore-decorations |
1838 | t | |
1839 | (while (looking-at "[0-9]") (forward-char 1)) | |
1840 | (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1))) | |
9179616f | 1841 | (store-match-data match-data)) |
1977b8f6 | 1842 | ;; Reestablish where we are: |
fd5359c6 MR |
1843 | (allout-current-depth))) |
1844 | ;;;_ > allout-current-bullet-pos () | |
1845 | (defun allout-current-bullet-pos () | |
c567ac01 RS |
1846 | "Return position of current \(visible) topic's bullet." |
1847 | ||
fd5359c6 | 1848 | (if (not (allout-current-depth)) |
c567ac01 RS |
1849 | nil |
1850 | (1- (match-end 0)))) | |
fd5359c6 MR |
1851 | ;;;_ > allout-back-to-current-heading () |
1852 | (defun allout-back-to-current-heading () | |
19b84ba3 RS |
1853 | "Move to heading line of current topic, or beginning if already on the line." |
1854 | ||
1977b8f6 | 1855 | (beginning-of-line) |
fd5359c6 MR |
1856 | (prog1 (or (allout-on-current-heading-p) |
1857 | (and (re-search-backward (concat "^\\(" allout-regexp "\\)") | |
1977b8f6 RS |
1858 | nil |
1859 | 'move) | |
fd5359c6 MR |
1860 | (allout-prefix-data (match-beginning 1)(match-end 1)))) |
1861 | (if (interactive-p) (allout-end-of-prefix)))) | |
1862 | ;;;_ > allout-back-to-heading () | |
1863 | (defalias 'allout-back-to-heading 'allout-back-to-current-heading) | |
1864 | ;;;_ > allout-pre-next-preface () | |
1865 | (defun allout-pre-next-preface () | |
1977b8f6 RS |
1866 | "Skip forward to just before the next heading line. |
1867 | ||
c567ac01 | 1868 | Returns that character position." |
1977b8f6 | 1869 | |
fd5359c6 | 1870 | (if (re-search-forward allout-line-boundary-regexp nil 'move) |
c567ac01 | 1871 | (prog1 (goto-char (match-beginning 0)) |
fd5359c6 MR |
1872 | (allout-prefix-data (match-beginning 2)(match-end 2))))) |
1873 | ;;;_ > allout-end-of-current-subtree () | |
1874 | (defun allout-end-of-current-subtree () | |
c567ac01 | 1875 | "Put point at the end of the last leaf in the currently visible topic." |
1977b8f6 | 1876 | (interactive) |
fd5359c6 MR |
1877 | (allout-back-to-current-heading) |
1878 | (let ((level (allout-recent-depth))) | |
1879 | (allout-next-heading) | |
1977b8f6 | 1880 | (while (and (not (eobp)) |
fd5359c6 MR |
1881 | (> (allout-recent-depth) level)) |
1882 | (allout-next-heading)) | |
c567ac01 | 1883 | (and (not (eobp)) (forward-char -1)) |
9179616f | 1884 | (and (memq (preceding-char) '(?\n ?\r)) |
c567ac01 | 1885 | (memq (aref (buffer-substring (max 1 (- (point) 3)) (point)) 1) |
9179616f | 1886 | '(?\n ?\r)) |
c567ac01 | 1887 | (forward-char -1)) |
fd5359c6 MR |
1888 | (setq allout-recent-end-of-subtree (point)))) |
1889 | ;;;_ > allout-beginning-of-current-entry () | |
1890 | (defun allout-beginning-of-current-entry () | |
19b84ba3 | 1891 | "When not already there, position point at beginning of current topic's body. |
c567ac01 RS |
1892 | |
1893 | If already there, move cursor to bullet for hot-spot operation. | |
2265e017 | 1894 | \(See `allout-mode' doc string for details on hot-spot operation.)" |
1977b8f6 | 1895 | (interactive) |
c567ac01 | 1896 | (let ((start-point (point))) |
fd5359c6 | 1897 | (allout-end-of-prefix) |
c567ac01 RS |
1898 | (if (and (interactive-p) |
1899 | (= (point) start-point)) | |
fd5359c6 MR |
1900 | (goto-char (allout-current-bullet-pos))))) |
1901 | ;;;_ > allout-end-of-current-entry () | |
1902 | (defun allout-end-of-current-entry () | |
c567ac01 | 1903 | "Position the point at the end of the current topics' entry." |
1977b8f6 | 1904 | (interactive) |
fd5359c6 MR |
1905 | (allout-show-entry) |
1906 | (prog1 (allout-pre-next-preface) | |
1977b8f6 | 1907 | (if (and (not (bobp))(looking-at "^$")) |
19b84ba3 | 1908 | (forward-char -1)))) |
fd5359c6 MR |
1909 | ;;;_ > allout-end-of-current-heading () |
1910 | (defun allout-end-of-current-heading () | |
9179616f | 1911 | (interactive) |
fd5359c6 | 1912 | (allout-beginning-of-current-entry) |
9179616f DL |
1913 | (forward-line -1) |
1914 | (end-of-line)) | |
fd5359c6 | 1915 | (defalias 'allout-end-of-heading 'allout-end-of-current-heading) |
1977b8f6 | 1916 | |
c567ac01 | 1917 | ;;;_ - Depth-wise |
fd5359c6 MR |
1918 | ;;;_ > allout-ascend-to-depth (depth) |
1919 | (defun allout-ascend-to-depth (depth) | |
c567ac01 | 1920 | "Ascend to depth DEPTH, returning depth if successful, nil if not." |
fd5359c6 | 1921 | (if (and (> depth 0)(<= depth (allout-depth))) |
1977b8f6 | 1922 | (let ((last-good (point))) |
fd5359c6 | 1923 | (while (and (< depth (allout-depth)) |
1977b8f6 | 1924 | (setq last-good (point)) |
fd5359c6 MR |
1925 | (allout-beginning-of-level) |
1926 | (allout-previous-heading))) | |
1927 | (if (= (allout-recent-depth) depth) | |
1928 | (progn (goto-char allout-recent-prefix-beginning) | |
1977b8f6 RS |
1929 | depth) |
1930 | (goto-char last-good) | |
1931 | nil)) | |
fd5359c6 MR |
1932 | (if (interactive-p) (allout-end-of-prefix)))) |
1933 | ;;;_ > allout-ascend () | |
1934 | (defun allout-ascend () | |
9179616f DL |
1935 | "Ascend one level, returning t if successful, nil if not." |
1936 | (prog1 | |
fd5359c6 MR |
1937 | (if (allout-beginning-of-level) |
1938 | (allout-previous-heading)) | |
1939 | (if (interactive-p) (allout-end-of-prefix)))) | |
1940 | ;;;_ > allout-descend-to-depth (depth) | |
1941 | (defun allout-descend-to-depth (depth) | |
19b84ba3 RS |
1942 | "Descend to depth DEPTH within current topic. |
1943 | ||
1944 | Returning depth if successful, nil if not." | |
1977b8f6 | 1945 | (let ((start-point (point)) |
fd5359c6 | 1946 | (start-depth (allout-depth))) |
1977b8f6 | 1947 | (while |
fd5359c6 MR |
1948 | (and (> (allout-depth) 0) |
1949 | (not (= depth (allout-recent-depth))) ; ... not there yet | |
1950 | (allout-next-heading) ; ... go further | |
1951 | (< start-depth (allout-recent-depth)))) ; ... still in topic | |
1952 | (if (and (> (allout-depth) 0) | |
1953 | (= (allout-recent-depth) depth)) | |
1977b8f6 RS |
1954 | depth |
1955 | (goto-char start-point) | |
1956 | nil)) | |
1957 | ) | |
fd5359c6 MR |
1958 | ;;;_ > allout-up-current-level (arg &optional dont-complain) |
1959 | (defun allout-up-current-level (arg &optional dont-complain) | |
19b84ba3 RS |
1960 | "Move out ARG levels from current visible topic. |
1961 | ||
1962 | Positions on heading line of containing topic. Error if unable to | |
1963 | ascend that far, or nil if unable to ascend but optional arg | |
1964 | DONT-COMPLAIN is non-nil." | |
1977b8f6 | 1965 | (interactive "p") |
fd5359c6 MR |
1966 | (allout-back-to-current-heading) |
1967 | (let ((present-level (allout-recent-depth)) | |
19b84ba3 RS |
1968 | (last-good (point)) |
1969 | failed | |
1970 | return) | |
1977b8f6 | 1971 | ;; Loop for iterating arg: |
fd5359c6 | 1972 | (while (and (> (allout-recent-depth) 1) |
1977b8f6 | 1973 | (> arg 0) |
19b84ba3 RS |
1974 | (not (bobp)) |
1975 | (not failed)) | |
1976 | (setq last-good (point)) | |
1977b8f6 | 1977 | ;; Loop for going back over current or greater depth: |
fd5359c6 MR |
1978 | (while (and (not (< (allout-recent-depth) present-level)) |
1979 | (or (allout-previous-visible-heading 1) | |
19b84ba3 | 1980 | (not (setq failed present-level))))) |
fd5359c6 | 1981 | (setq present-level (allout-current-depth)) |
1977b8f6 | 1982 | (setq arg (- arg 1))) |
19b84ba3 RS |
1983 | (if (or failed |
1984 | (> arg 0)) | |
1985 | (progn (goto-char last-good) | |
fd5359c6 | 1986 | (if (interactive-p) (allout-end-of-prefix)) |
19b84ba3 | 1987 | (if (not dont-complain) |
6a05d05f | 1988 | (error "Can't ascend past outermost level") |
fd5359c6 | 1989 | (if (interactive-p) (allout-end-of-prefix)) |
19b84ba3 | 1990 | nil)) |
fd5359c6 MR |
1991 | (if (interactive-p) (allout-end-of-prefix)) |
1992 | allout-recent-prefix-beginning))) | |
1977b8f6 | 1993 | |
c567ac01 | 1994 | ;;;_ - Linear |
fd5359c6 MR |
1995 | ;;;_ > allout-next-sibling (&optional depth backward) |
1996 | (defun allout-next-sibling (&optional depth backward) | |
2265e017 | 1997 | "Like `allout-forward-current-level', but respects invisible topics. |
1977b8f6 | 1998 | |
c567ac01 | 1999 | Traverse at optional DEPTH, or current depth if none specified. |
1977b8f6 | 2000 | |
c567ac01 | 2001 | Go backward if optional arg BACKWARD is non-nil. |
1977b8f6 | 2002 | |
c567ac01 | 2003 | Return depth if successful, nil otherwise." |
1977b8f6 RS |
2004 | |
2005 | (if (and backward (bobp)) | |
2006 | nil | |
fd5359c6 | 2007 | (let ((start-depth (or depth (allout-depth))) |
1977b8f6 | 2008 | (start-point (point)) |
c567ac01 | 2009 | last-depth) |
1977b8f6 | 2010 | (while (and (not (if backward (bobp) (eobp))) |
fd5359c6 MR |
2011 | (if backward (allout-previous-heading) |
2012 | (allout-next-heading)) | |
2013 | (> (setq last-depth (allout-recent-depth)) start-depth))) | |
1977b8f6 | 2014 | (if (and (not (eobp)) |
fd5359c6 MR |
2015 | (and (> (or last-depth (allout-depth)) 0) |
2016 | (= (allout-recent-depth) start-depth))) | |
2017 | allout-recent-prefix-beginning | |
1977b8f6 | 2018 | (goto-char start-point) |
fd5359c6 | 2019 | (if depth (allout-depth) start-depth) |
c567ac01 | 2020 | nil)))) |
fd5359c6 MR |
2021 | ;;;_ > allout-previous-sibling (&optional depth backward) |
2022 | (defun allout-previous-sibling (&optional depth backward) | |
aad94676 | 2023 | "Like `allout-forward-current-level', but backwards & respect invisible topics. |
1977b8f6 | 2024 | |
c567ac01 | 2025 | Optional DEPTH specifies depth to traverse, default current depth. |
1977b8f6 | 2026 | |
c567ac01 | 2027 | Optional BACKWARD reverses direction. |
1977b8f6 | 2028 | |
c567ac01 | 2029 | Return depth if successful, nil otherwise." |
fd5359c6 | 2030 | (allout-next-sibling depth (not backward)) |
1977b8f6 | 2031 | ) |
fd5359c6 MR |
2032 | ;;;_ > allout-snug-back () |
2033 | (defun allout-snug-back () | |
19b84ba3 RS |
2034 | "Position cursor at end of previous topic |
2035 | ||
2036 | Presumes point is at the start of a topic prefix." | |
c567ac01 RS |
2037 | (if (or (bobp) (eobp)) |
2038 | nil | |
2039 | (forward-char -1)) | |
9179616f | 2040 | (if (or (bobp) (not (memq (preceding-char) '(?\n ?\r)))) |
c567ac01 RS |
2041 | nil |
2042 | (forward-char -1) | |
9179616f | 2043 | (if (or (bobp) (not (memq (preceding-char) '(?\n ?\r)))) |
c567ac01 RS |
2044 | (forward-char -1))) |
2045 | (point)) | |
fd5359c6 MR |
2046 | ;;;_ > allout-beginning-of-level () |
2047 | (defun allout-beginning-of-level () | |
c567ac01 | 2048 | "Go back to the first sibling at this level, visible or not." |
fd5359c6 MR |
2049 | (allout-end-of-level 'backward)) |
2050 | ;;;_ > allout-end-of-level (&optional backward) | |
2051 | (defun allout-end-of-level (&optional backward) | |
c567ac01 | 2052 | "Go to the last sibling at this level, visible or not." |
1977b8f6 | 2053 | |
fd5359c6 MR |
2054 | (let ((depth (allout-depth))) |
2055 | (while (allout-previous-sibling depth nil)) | |
2056 | (prog1 (allout-recent-depth) | |
2057 | (if (interactive-p) (allout-end-of-prefix))))) | |
2058 | ;;;_ > allout-next-visible-heading (arg) | |
2059 | (defun allout-next-visible-heading (arg) | |
19b84ba3 | 2060 | "Move to the next ARG'th visible heading line, backward if arg is negative. |
c567ac01 | 2061 | |
19b84ba3 | 2062 | Move as far as possible in indicated direction \(beginning or end of |
9179616f | 2063 | buffer) if headings are exhausted." |
1977b8f6 | 2064 | |
1977b8f6 | 2065 | (interactive "p") |
c567ac01 RS |
2066 | (let* ((backward (if (< arg 0) (setq arg (* -1 arg)))) |
2067 | (step (if backward -1 1)) | |
19b84ba3 | 2068 | (start-point (point)) |
c567ac01 RS |
2069 | prev got) |
2070 | ||
2071 | (while (> arg 0) ; limit condition | |
2072 | (while (and (not (if backward (bobp)(eobp))) ; boundary condition | |
19b84ba3 RS |
2073 | ;; Move, skipping over all those concealed lines: |
2074 | (< -1 (forward-line step)) | |
fd5359c6 | 2075 | (not (setq got (looking-at allout-regexp))))) |
c567ac01 RS |
2076 | ;; Register this got, it may be the last: |
2077 | (if got (setq prev got)) | |
2078 | (setq arg (1- arg))) | |
2079 | (cond (got ; Last move was to a prefix: | |
fd5359c6 MR |
2080 | (allout-prefix-data (match-beginning 0) (match-end 0)) |
2081 | (allout-end-of-prefix)) | |
c567ac01 | 2082 | (prev ; Last move wasn't, but prev was: |
fd5359c6 | 2083 | (allout-prefix-data (match-beginning 0) (match-end 0))) |
c567ac01 | 2084 | ((not backward) (end-of-line) nil)))) |
fd5359c6 MR |
2085 | ;;;_ > allout-previous-visible-heading (arg) |
2086 | (defun allout-previous-visible-heading (arg) | |
c567ac01 | 2087 | "Move to the previous heading line. |
1977b8f6 | 2088 | |
c567ac01 | 2089 | With argument, repeats or can move forward if negative. |
2265e017 | 2090 | A heading line is one that starts with a `*' (or that `allout-regexp' |
c567ac01 | 2091 | matches)." |
1977b8f6 | 2092 | (interactive "p") |
fd5359c6 MR |
2093 | (allout-next-visible-heading (- arg))) |
2094 | ;;;_ > allout-forward-current-level (arg) | |
2095 | (defun allout-forward-current-level (arg) | |
19b84ba3 | 2096 | "Position point at the next heading of the same level. |
1977b8f6 | 2097 | |
19b84ba3 | 2098 | Takes optional repeat-count, goes backward if count is negative. |
1977b8f6 | 2099 | |
19b84ba3 | 2100 | Returns resulting position, else nil if none found." |
c567ac01 | 2101 | (interactive "p") |
fd5359c6 | 2102 | (let ((start-depth (allout-current-depth)) |
19b84ba3 RS |
2103 | (start-point (point)) |
2104 | (start-arg arg) | |
2105 | (backward (> 0 arg)) | |
2106 | last-depth | |
2107 | (last-good (point)) | |
2108 | at-boundary) | |
2109 | (if (= 0 start-depth) | |
2110 | (error "No siblings, not in a topic...")) | |
2111 | (if backward (setq arg (* -1 arg))) | |
2112 | (while (not (or (zerop arg) | |
2113 | at-boundary)) | |
2114 | (while (and (not (if backward (bobp) (eobp))) | |
fd5359c6 MR |
2115 | (if backward (allout-previous-visible-heading 1) |
2116 | (allout-next-visible-heading 1)) | |
2117 | (> (setq last-depth (allout-recent-depth)) start-depth))) | |
19b84ba3 RS |
2118 | (if (and last-depth (= last-depth start-depth) |
2119 | (not (if backward (bobp) (eobp)))) | |
2120 | (setq last-good (point) | |
2121 | arg (1- arg)) | |
2122 | (setq at-boundary t))) | |
2123 | (if (and (not (eobp)) | |
2124 | (= arg 0) | |
fd5359c6 MR |
2125 | (and (> (or last-depth (allout-depth)) 0) |
2126 | (= (allout-recent-depth) start-depth))) | |
2127 | allout-recent-prefix-beginning | |
19b84ba3 RS |
2128 | (goto-char last-good) |
2129 | (if (not (interactive-p)) | |
2130 | nil | |
fd5359c6 | 2131 | (allout-end-of-prefix) |
6a05d05f | 2132 | (error "Hit %s level %d topic, traversed %d of %d requested" |
19b84ba3 | 2133 | (if backward "first" "last") |
fd5359c6 | 2134 | (allout-recent-depth) |
19b84ba3 RS |
2135 | (- (abs start-arg) arg) |
2136 | (abs start-arg)))))) | |
fd5359c6 MR |
2137 | ;;;_ > allout-backward-current-level (arg) |
2138 | (defun allout-backward-current-level (arg) | |
2139 | "Inverse of `allout-forward-current-level'." | |
c567ac01 | 2140 | (interactive "p") |
19b84ba3 RS |
2141 | (if (interactive-p) |
2142 | (let ((current-prefix-arg (* -1 arg))) | |
fd5359c6 MR |
2143 | (call-interactively 'allout-forward-current-level)) |
2144 | (allout-forward-current-level (* -1 arg)))) | |
c567ac01 | 2145 | |
19b84ba3 | 2146 | ;;;_ #5 Alteration |
c567ac01 RS |
2147 | |
2148 | ;;;_ - Fundamental | |
fd5359c6 MR |
2149 | ;;;_ > allout-before-change-protect (beg end) |
2150 | (defun allout-before-change-protect (beg end) | |
19b84ba3 RS |
2151 | "Outline before-change hook, regulates changes to concealed text. |
2152 | ||
2153 | Reveal concealed text that would be changed by current command, and | |
c567ac01 RS |
2154 | offer user choice to commit or forego the change. Unchanged text is |
2155 | reconcealed. User has option to have changed text reconcealed. | |
2156 | ||
2157 | Undo commands are specially treated - the user is not prompted for | |
2158 | choice, the undoes are always committed (based on presumption that the | |
2159 | things being undone were already subject to this regulation routine), | |
2160 | and undoes always leave the changed stuff exposed. | |
2161 | ||
2162 | Changes to concealed regions are ignored while file is being written. | |
2163 | \(This is for the sake of functions that do change the file during | |
2164 | writes, like crypt and zip modes.) | |
2165 | ||
9179616f DL |
2166 | Locally bound in outline buffers to `before-change-functions', which |
2167 | in emacs 19 is run before any change to the buffer. | |
c567ac01 | 2168 | |
353e2ef2 | 2169 | Any functions which set [`this-command' to `undo', or which set] |
fd5359c6 | 2170 | `allout-override-protect' non-nil (as does, eg, allout-flag-chars) |
c567ac01 | 2171 | are exempt from this restriction." |
fd5359c6 MR |
2172 | (if (and (allout-mode-p) |
2173 | ; allout-override-protect | |
c567ac01 RS |
2174 | ; set by functions that know what |
2175 | ; they're doing, eg outline internals: | |
fd5359c6 MR |
2176 | (not allout-override-protect) |
2177 | (not allout-during-write-cue) | |
c567ac01 RS |
2178 | (save-match-data ; Preserve operation position state. |
2179 | ; Both beginning and end chars must | |
2180 | ; be exposed: | |
2181 | (save-excursion (if (memq this-command '(newline open-line)) | |
2182 | ;; Compensate for stupid emacs {new, | |
2183 | ;; open-}line display optimization: | |
2184 | (setq beg (1+ beg) | |
2185 | end (1+ end))) | |
2186 | (goto-char beg) | |
fd5359c6 | 2187 | (or (allout-hidden-p) |
c567ac01 RS |
2188 | (and (not (= beg end)) |
2189 | (goto-char end) | |
fd5359c6 | 2190 | (allout-hidden-p)))))) |
c567ac01 RS |
2191 | (save-match-data |
2192 | (if (equal this-command 'undo) | |
2193 | ;; Allow undo without inhibition. | |
2194 | ;; - Undoing new and open-line hits stupid emacs redisplay | |
2195 | ;; optimization (em 19 cmds.c, ~ line 200). | |
2196 | ;; - Presumably, undoing what was properly protected when | |
2197 | ;; done. | |
2198 | ;; - Undo may be users' only recourse in protection faults. | |
2199 | ;; So, expose what getting changed: | |
2200 | (progn (message "Undo! - exposing concealed target...") | |
fd5359c6 MR |
2201 | (if (allout-hidden-p) |
2202 | (allout-show-children)) | |
19b84ba3 | 2203 | (message "Undo!")) |
c567ac01 | 2204 | (let (response |
fd5359c6 MR |
2205 | (rehide-completely (save-excursion (allout-goto-prefix) |
2206 | (allout-hidden-p))) | |
c567ac01 | 2207 | rehide-place) |
353e2ef2 | 2208 | |
c567ac01 RS |
2209 | (save-excursion |
2210 | (if (condition-case err | |
2211 | ;; Condition case to catch keyboard quits during reads. | |
2212 | (progn | |
2213 | ; Give them a peek where | |
2214 | (save-excursion | |
2215 | (if (eolp) (setq rehide-place | |
fd5359c6 MR |
2216 | (allout-goto-prefix))) |
2217 | (allout-show-entry)) | |
c567ac01 RS |
2218 | ; Present the message, but... |
2219 | ; leave the cursor at the location | |
2220 | ; until they respond: | |
2221 | ; Then interpret the response: | |
2222 | (while | |
353e2ef2 | 2223 | (progn |
c567ac01 RS |
2224 | (message (concat "Change inside concealed" |
2225 | " region - do it? " | |
2226 | "(n or 'y'/'r'eclose)")) | |
2227 | (setq response (read-char)) | |
2228 | (not | |
2229 | (cond ((memq response '(?r ?R)) | |
2230 | (setq response 'reclose)) | |
2231 | ((memq response '(?y ?Y ? )) | |
2232 | (setq response t)) | |
2233 | ((memq response '(?n ?N 127)) | |
2234 | (setq response nil) | |
2235 | t) | |
2236 | ((eq response ??) | |
2237 | (message | |
353e2ef2 | 2238 | "`r' means `yes, then reclose'") |
c567ac01 RS |
2239 | nil) |
2240 | (t (message "Please answer y, n, or r") | |
2241 | (sit-for 1) | |
2242 | nil))))) | |
2243 | response) | |
9179616f | 2244 | ('quit nil)) |
c567ac01 RS |
2245 | ; Continue: |
2246 | (if (eq response 'reclose) | |
2247 | (save-excursion | |
2248 | (if rehide-place (goto-char rehide-place)) | |
2249 | (if rehide-completely | |
fd5359c6 MR |
2250 | (allout-hide-current-entry-completely) |
2251 | (allout-hide-current-entry))) | |
2252 | (if (allout-ascend-to-depth (1- (allout-recent-depth))) | |
2253 | (allout-show-children) | |
2254 | (allout-show-to-offshoot))) | |
c567ac01 RS |
2255 | ; Prevent: |
2256 | (if rehide-completely | |
2257 | (save-excursion | |
2258 | (if rehide-place (goto-char rehide-place)) | |
fd5359c6 MR |
2259 | (allout-hide-current-entry-completely)) |
2260 | (allout-hide-current-entry)) | |
c567ac01 RS |
2261 | (error (concat |
2262 | "Change within concealed region prevented."))))))) | |
2263 | ) ; if | |
2264 | ) ; defun | |
fd5359c6 MR |
2265 | ;;;_ = allout-post-goto-bullet |
2266 | (defvar allout-post-goto-bullet nil | |
2267 | "Outline internal var, for `allout-pre-command-business' hot-spot operation. | |
19b84ba3 RS |
2268 | |
2269 | When set, tells post-processing to reposition on topic bullet, and | |
2265e017 | 2270 | then unset it. Set by `allout-pre-command-business' when implementing |
19b84ba3 RS |
2271 | hot-spot operation, where literal characters typed over a topic bullet |
2272 | are mapped to the command of the corresponding control-key on the | |
2265e017 | 2273 | `allout-mode-map'.") |
fd5359c6 MR |
2274 | (make-variable-buffer-local 'allout-post-goto-bullet) |
2275 | ;;;_ > allout-post-command-business () | |
2276 | (defun allout-post-command-business () | |
2265e017 | 2277 | "Outline `post-command-hook' function. |
c567ac01 | 2278 | |
2265e017 | 2279 | - Null `allout-override-protect', so it's not left open. |
c567ac01 | 2280 | |
2265e017 | 2281 | - Implement (and clear) `allout-post-goto-bullet', for hot-spot |
c567ac01 RS |
2282 | outline commands. |
2283 | ||
2284 | - Massages buffer-undo-list so successive, standard character self-inserts are | |
2285 | aggregated. This kludge compensates for lack of undo bunching when | |
2265e017 | 2286 | `before-change-functions' is used." |
c567ac01 RS |
2287 | |
2288 | ; Apply any external change func: | |
fd5359c6 | 2289 | (if (not (allout-mode-p)) ; In allout-mode. |
19b84ba3 | 2290 | nil |
fd5359c6 MR |
2291 | (setq allout-override-protect nil) |
2292 | (if allout-isearch-dynamic-expose | |
2293 | (allout-isearch-rectification)) | |
2294 | (if allout-during-write-cue | |
2295 | ;; Was used by allout-before-change-protect, done with it now: | |
2296 | (setq allout-during-write-cue nil)) | |
19b84ba3 RS |
2297 | ;; Undo bunching business: |
2298 | (if (and (listp buffer-undo-list) ; Undo history being kept. | |
2299 | (equal this-command 'self-insert-command) | |
2300 | (equal last-command 'self-insert-command)) | |
2301 | (let* ((prev-stuff (cdr buffer-undo-list)) | |
2302 | (before-prev-stuff (cdr (cdr prev-stuff))) | |
2303 | cur-cell cur-from cur-to | |
2304 | prev-cell prev-from prev-to) | |
2305 | (if (and before-prev-stuff ; Goes back far enough to bother, | |
2306 | (not (car prev-stuff)) ; and break before current, | |
2307 | (not (car before-prev-stuff)) ; !and break before prev! | |
2308 | (setq prev-cell (car (cdr prev-stuff))) ; contents now, | |
2309 | (setq cur-cell (car buffer-undo-list)) ; contents prev. | |
2310 | ||
2311 | ;; cur contents denote a single char insertion: | |
2312 | (numberp (setq cur-from (car cur-cell))) | |
2313 | (numberp (setq cur-to (cdr cur-cell))) | |
2314 | (= 1 (- cur-to cur-from)) | |
2315 | ||
2316 | ;; prev contents denote fewer than aggregate-limit | |
2317 | ;; insertions: | |
2318 | (numberp (setq prev-from (car prev-cell))) | |
2319 | (numberp (setq prev-to (cdr prev-cell))) | |
c567ac01 | 2320 | ; Below threshold: |
fd5359c6 | 2321 | (> allout-undo-aggregation (- prev-to prev-from))) |
19b84ba3 RS |
2322 | (setq buffer-undo-list |
2323 | (cons (cons prev-from cur-to) | |
2324 | (cdr (cdr (cdr buffer-undo-list)))))))) | |
2325 | ;; Implement -post-goto-bullet, if set: (must be after undo business) | |
fd5359c6 MR |
2326 | (if (and allout-post-goto-bullet |
2327 | (allout-current-bullet-pos)) | |
2328 | (progn (goto-char (allout-current-bullet-pos)) | |
2329 | (setq allout-post-goto-bullet nil))) | |
19b84ba3 | 2330 | )) |
fd5359c6 MR |
2331 | ;;;_ > allout-pre-command-business () |
2332 | (defun allout-pre-command-business () | |
2265e017 | 2333 | "Outline `pre-command-hook' function for outline buffers. |
19b84ba3 | 2334 | Implements special behavior when cursor is on bullet char. |
c567ac01 RS |
2335 | |
2336 | Self-insert characters are reinterpreted control-character references | |
aad94676 | 2337 | into the `allout-mode-map'. The `allout-mode' `post-command-hook' will |
c567ac01 RS |
2338 | position a cursor that has moved as a result of such reinterpretation, |
2339 | on the destination topic's bullet, when the cursor wound up in the | |
2340 | ||
9179616f DL |
2341 | The upshot is that you can get easy, single (ie, unmodified) key |
2342 | outline maneuvering operations by positioning the cursor on the bullet | |
2343 | char. You stay in this mode until you use some regular | |
2344 | cursor-positioning command to relocate the cursor off of a bullet | |
2345 | char." | |
c567ac01 | 2346 | |
fd5359c6 MR |
2347 | (if (not (allout-mode-p)) |
2348 | ;; Shouldn't be invoked if not in allout allout-mode, but just in case: | |
9179616f DL |
2349 | nil |
2350 | ;; Register isearch status: | |
2351 | (if (and (boundp 'isearch-mode) isearch-mode) | |
fd5359c6 MR |
2352 | (setq allout-pre-was-isearching t) |
2353 | (setq allout-pre-was-isearching nil)) | |
9179616f DL |
2354 | ;; Hot-spot navigation provisions: |
2355 | (if (and (eq this-command 'self-insert-command) | |
fd5359c6 | 2356 | (eq (point)(allout-current-bullet-pos))) |
9179616f DL |
2357 | (let* ((this-key-num (cond |
2358 | ((numberp last-command-char) | |
2359 | last-command-char) | |
2360 | ;; XXX Only xemacs has characterp. | |
2361 | ((and (fboundp 'characterp) | |
2362 | (characterp last-command-char)) | |
2363 | (char-to-int last-command-char)) | |
2364 | (t 0))) | |
2365 | mapped-binding) | |
2366 | (if (zerop this-key-num) | |
2367 | nil | |
c567ac01 RS |
2368 | ; Map upper-register literals |
2369 | ; to lower register: | |
9179616f DL |
2370 | (if (<= 96 this-key-num) |
2371 | (setq this-key-num (- this-key-num 32))) | |
c567ac01 | 2372 | ; Check if we have a literal: |
9179616f DL |
2373 | (if (and (<= 64 this-key-num) |
2374 | (>= 96 this-key-num)) | |
2375 | (setq mapped-binding | |
fd5359c6 MR |
2376 | (lookup-key 'allout-mode-map |
2377 | (concat allout-command-prefix | |
9179616f DL |
2378 | (char-to-string (- this-key-num |
2379 | 64)))))) | |
2380 | (if mapped-binding | |
fd5359c6 | 2381 | (setq allout-post-goto-bullet t |
9179616f | 2382 | this-command mapped-binding))))))) |
fd5359c6 MR |
2383 | ;;;_ > allout-find-file-hook () |
2384 | (defun allout-find-file-hook () | |
2265e017 | 2385 | "Activate `allout-mode' when `allout-auto-activation' & `allout-layout' are non-nil. |
fd5359c6 MR |
2386 | |
2387 | See `allout-init' for setup instructions." | |
2388 | (if (and allout-auto-activation | |
2389 | (not (allout-mode-p)) | |
2390 | allout-layout) | |
2391 | (allout-mode t))) | |
2392 | ;;;_ > allout-isearch-rectification | |
2393 | (defun allout-isearch-rectification () | |
9179616f DL |
2394 | "Rectify outline exposure before, during, or after isearch. |
2395 | ||
2265e017 | 2396 | Called as part of `allout-post-command-business'." |
9179616f DL |
2397 | |
2398 | (let ((isearching (and (boundp 'isearch-mode) isearch-mode))) | |
fd5359c6 MR |
2399 | (cond ((and isearching (not allout-pre-was-isearching)) |
2400 | (allout-isearch-expose 'start)) | |
2401 | ((and isearching allout-pre-was-isearching) | |
2402 | (allout-isearch-expose 'continue)) | |
2403 | ((and (not isearching) allout-pre-was-isearching) | |
2404 | (allout-isearch-expose 'final)) | |
9179616f | 2405 | ;; Not and wasn't isearching: |
fd5359c6 MR |
2406 | (t (setq allout-isearch-prior-pos nil) |
2407 | (setq allout-isearch-did-quit nil))))) | |
2408 | ;;;_ = allout-isearch-was-font-lock | |
2409 | (defvar allout-isearch-was-font-lock | |
9179616f | 2410 | (and (boundp 'font-lock-mode) font-lock-mode)) |
12435002 | 2411 | |
fd5359c6 MR |
2412 | ;;;_ > allout-flag-region (from to flag) |
2413 | (defmacro allout-flag-region (from to flag) | |
12435002 GM |
2414 | "Hide or show lines from FROM to TO, via emacs selective-display FLAG char. |
2415 | Ie, text following flag C-m \(carriage-return) is hidden until the | |
2416 | next C-j (newline) char. | |
2417 | ||
2418 | Returns the endpoint of the region." | |
2419 | `(let ((buffer-read-only nil) | |
fd5359c6 | 2420 | (allout-override-protect t)) |
12435002 GM |
2421 | (subst-char-in-region ,from ,to |
2422 | (if (= ,flag ?\n) ?\r ?\n) | |
2423 | ,flag t))) | |
2424 | ||
fd5359c6 MR |
2425 | ;;;_ > allout-isearch-expose (mode) |
2426 | (defun allout-isearch-expose (mode) | |
9179616f | 2427 | "Mode is either 'clear, 'start, 'continue, or 'final." |
fd5359c6 | 2428 | ;; allout-isearch-prior-pos encodes exposure status of prior pos: |
9179616f DL |
2429 | ;; (pos was-vis header-pos end-pos) |
2430 | ;; pos - point of concern | |
2431 | ;; was-vis - t, else 'topic if entire topic was exposed, 'entry otherwise | |
2432 | ;; Do reclosure or prior pos, as necessary: | |
2433 | (if (eq mode 'start) | |
fd5359c6 | 2434 | (setq allout-isearch-was-font-lock (and (boundp 'font-lock-mode) |
9179616f DL |
2435 | font-lock-mode) |
2436 | font-lock-mode nil) | |
2437 | (if (eq mode 'final) | |
fd5359c6 MR |
2438 | (setq font-lock-mode allout-isearch-was-font-lock)) |
2439 | (if (and allout-isearch-prior-pos | |
2440 | (listp allout-isearch-prior-pos)) | |
9179616f | 2441 | ;; Conceal prior peek: |
fd5359c6 MR |
2442 | (allout-flag-region (car (cdr allout-isearch-prior-pos)) |
2443 | (car (cdr (cdr allout-isearch-prior-pos))) | |
9179616f | 2444 | ?\r))) |
fd5359c6 MR |
2445 | (if (allout-visible-p) |
2446 | (setq allout-isearch-prior-pos nil) | |
9179616f | 2447 | (if (not (eq mode 'final)) |
fd5359c6 MR |
2448 | (setq allout-isearch-prior-pos (cons (point) (allout-show-entry))) |
2449 | (if allout-isearch-did-quit | |
9179616f | 2450 | nil |
fd5359c6 MR |
2451 | (setq allout-isearch-prior-pos nil) |
2452 | (allout-show-children)))) | |
2453 | (setq allout-isearch-did-quit nil)) | |
2454 | ;;;_ > allout-enwrap-isearch () | |
2455 | (defun allout-enwrap-isearch () | |
2265e017 | 2456 | "Impose `allout-mode' isearch-abort wrapper for dynamic exposure in isearch. |
9179616f DL |
2457 | |
2458 | The function checks to ensure that the rebinding is done only once." | |
2459 | ||
fd5359c6 MR |
2460 | (add-hook 'isearch-mode-end-hook 'allout-isearch-rectification) |
2461 | (if (fboundp 'allout-real-isearch-abort) | |
9179616f DL |
2462 | ;; |
2463 | nil | |
2464 | ; Ensure load of isearch-mode: | |
2465 | (if (or (and (fboundp 'isearch-mode) | |
2466 | (fboundp 'isearch-abort)) | |
2467 | (condition-case error | |
2468 | (load-library "isearch-mode") | |
2469 | ('file-error (message | |
2470 | "Skipping isearch-mode provisions - %s '%s'" | |
2471 | (car (cdr error)) | |
2472 | (car (cdr (cdr error)))) | |
2473 | (sit-for 1) | |
2474 | ;; Inhibit subsequent tries and return nil: | |
fd5359c6 | 2475 | (setq allout-isearch-dynamic-expose nil)))) |
9179616f DL |
2476 | ;; Isearch-mode loaded, encapsulate specific entry points for |
2477 | ;; outline dynamic-exposure business: | |
2478 | (progn | |
2479 | ;; stash crucial isearch-mode funcs under known, private | |
2480 | ;; names, then register wrapper functions under the old | |
2481 | ;; names, in their stead: | |
fd5359c6 MR |
2482 | (fset 'allout-real-isearch-abort (symbol-function 'isearch-abort)) |
2483 | (fset 'isearch-abort 'allout-isearch-abort))))) | |
2484 | ;;;_ > allout-isearch-abort () | |
2485 | (defun allout-isearch-abort () | |
2265e017 | 2486 | "Wrapper for `allout-real-isearch-abort' \(which see), to register |
9179616f DL |
2487 | actual quits." |
2488 | (interactive) | |
fd5359c6 | 2489 | (setq allout-isearch-did-quit nil) |
9179616f | 2490 | (condition-case what |
fd5359c6 MR |
2491 | (allout-real-isearch-abort) |
2492 | ('quit (setq allout-isearch-did-quit t) | |
9179616f DL |
2493 | (signal 'quit nil)))) |
2494 | ||
2495 | ;;; Prevent unnecessary font-lock while isearching! | |
2496 | (defvar isearch-was-font-locking nil) | |
2497 | (defun isearch-inhibit-font-lock () | |
aad94676 | 2498 | "Inhibit `font-lock-mode' while isearching - for use on `isearch-mode-hook'." |
fd5359c6 | 2499 | (if (and (allout-mode-p) (boundp 'font-lock-mode) font-lock-mode) |
9179616f DL |
2500 | (setq isearch-was-font-locking t |
2501 | font-lock-mode nil))) | |
2502 | (add-hook 'isearch-mode-hook 'isearch-inhibit-font-lock) | |
2503 | (defun isearch-reenable-font-lock () | |
2504 | "Reenable font-lock after isearching - for use on isearch-mode-end-hook." | |
2505 | (if (and (boundp 'font-lock-mode) font-lock-mode) | |
fd5359c6 | 2506 | (if (and (allout-mode-p) isearch-was-font-locking) |
9179616f DL |
2507 | (setq isearch-was-font-locking nil |
2508 | font-lock-mode t)))) | |
2509 | (add-hook 'isearch-mode-end-hook 'isearch-reenable-font-lock) | |
c567ac01 RS |
2510 | |
2511 | ;;;_ - Topic Format Assessment | |
fd5359c6 MR |
2512 | ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet) |
2513 | (defun allout-solicit-alternate-bullet (depth &optional current-bullet) | |
1977b8f6 | 2514 | |
19b84ba3 RS |
2515 | "Prompt for and return a bullet char as an alternative to the current one. |
2516 | ||
2517 | Offer one suitable for current depth DEPTH as default." | |
1977b8f6 | 2518 | |
9179616f | 2519 | (let* ((default-bullet (or (and (stringp current-bullet) current-bullet) |
fd5359c6 MR |
2520 | (allout-bullet-for-depth depth))) |
2521 | (sans-escapes (regexp-sans-escapes allout-bullets-string)) | |
9179616f DL |
2522 | choice) |
2523 | (save-excursion | |
fd5359c6 | 2524 | (goto-char (allout-current-bullet-pos)) |
9179616f DL |
2525 | (setq choice (solicit-char-in-string |
2526 | (format "Select bullet: %s ('%s' default): " | |
2527 | sans-escapes | |
2528 | default-bullet) | |
2529 | sans-escapes | |
2530 | t))) | |
2531 | (message "") | |
1977b8f6 RS |
2532 | (if (string= choice "") default-bullet choice)) |
2533 | ) | |
fd5359c6 MR |
2534 | ;;;_ > allout-distinctive-bullet (bullet) |
2535 | (defun allout-distinctive-bullet (bullet) | |
2265e017 | 2536 | "True if bullet is one of those on `allout-distinctive-bullets-string'." |
fd5359c6 MR |
2537 | (string-match (regexp-quote bullet) allout-distinctive-bullets-string)) |
2538 | ;;;_ > allout-numbered-type-prefix (&optional prefix) | |
2539 | (defun allout-numbered-type-prefix (&optional prefix) | |
c567ac01 | 2540 | "True if current header prefix bullet is numbered bullet." |
fd5359c6 MR |
2541 | (and allout-numbered-bullet |
2542 | (string= allout-numbered-bullet | |
1977b8f6 | 2543 | (if prefix |
fd5359c6 MR |
2544 | (allout-get-prefix-bullet prefix) |
2545 | (allout-get-bullet))))) | |
2546 | ;;;_ > allout-bullet-for-depth (&optional depth) | |
2547 | (defun allout-bullet-for-depth (&optional depth) | |
19b84ba3 | 2548 | "Return outline topic bullet suited to optional DEPTH, or current depth." |
1977b8f6 | 2549 | ;; Find bullet in plain-bullets-string modulo DEPTH. |
fd5359c6 MR |
2550 | (if allout-stylish-prefixes |
2551 | (char-to-string (aref allout-plain-bullets-string | |
1977b8f6 | 2552 | (% (max 0 (- depth 2)) |
fd5359c6 MR |
2553 | allout-plain-bullets-string-len))) |
2554 | allout-primary-bullet) | |
1977b8f6 RS |
2555 | ) |
2556 | ||
c567ac01 | 2557 | ;;;_ - Topic Production |
fd5359c6 MR |
2558 | ;;;_ > allout-make-topic-prefix (&optional prior-bullet |
2559 | (defun allout-make-topic-prefix (&optional prior-bullet | |
1977b8f6 RS |
2560 | new |
2561 | depth | |
2562 | solicit | |
2563 | number-control | |
2564 | index) | |
2565 | ;; Depth null means use current depth, non-null means we're either | |
2566 | ;; opening a new topic after current topic, lower or higher, or we're | |
2567 | ;; changing level of current topic. | |
2568 | ;; Solicit dominates specified bullet-char. | |
c567ac01 | 2569 | ;;;_ . Doc string: |
19b84ba3 | 2570 | "Generate a topic prefix suitable for optional arg DEPTH, or current depth. |
c567ac01 RS |
2571 | |
2572 | All the arguments are optional. | |
2573 | ||
2574 | PRIOR-BULLET indicates the bullet of the prefix being changed, or | |
2575 | nil if none. This bullet may be preserved (other options | |
2265e017 | 2576 | notwithstanding) if it is on the `allout-distinctive-bullets-string', |
c567ac01 RS |
2577 | for instance. |
2578 | ||
2579 | Second arg NEW indicates that a new topic is being opened after the | |
2580 | topic at point, if non-nil. Default bullet for new topics, eg, may | |
2581 | be set (contingent to other args) to numbered bullets if previous | |
2582 | sibling is one. The implication otherwise is that the current topic | |
2583 | is being adjusted - shifted or rebulleted - and we don't consider | |
2584 | bullet or previous sibling. | |
2585 | ||
2586 | Third arg DEPTH forces the topic prefix to that depth, regardless of | |
2587 | the current topics' depth. | |
2588 | ||
9179616f DL |
2589 | If SOLICIT is non-nil, then the choice of bullet is solicited from |
2590 | user. If it's a character, then that character is offered as the | |
2591 | default, otherwise the one suited to the context \(according to | |
2592 | distinction or depth) is offered. \(This overrides other options, | |
2593 | including, eg, a distinctive PRIOR-BULLET.) If non-nil, then the | |
2594 | context-specific bullet is used. | |
c567ac01 | 2595 | |
fd5359c6 | 2596 | Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet' |
c567ac01 RS |
2597 | is non-nil *and* soliciting was not explicitly invoked. Then |
2598 | NUMBER-CONTROL non-nil forces prefix to either numbered or | |
2599 | denumbered format, depending on the value of the sixth arg, INDEX. | |
2600 | ||
2601 | \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...) | |
2602 | ||
2603 | If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then | |
2604 | the prefix of the topic is forced to be numbered. Non-nil | |
2605 | NUMBER-CONTROL and nil INDEX forces non-numbered format on the | |
2606 | bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means | |
2607 | that the index for the numbered prefix will be derived, by counting | |
2608 | siblings back to start of level. If INDEX is a number, then that | |
2609 | number is used as the index for the numbered prefix (allowing, eg, | |
a0776d6b | 2610 | sequential renumbering to not require this function counting back the |
c567ac01 RS |
2611 | index for each successive sibling)." |
2612 | ;;;_ . Code: | |
1977b8f6 RS |
2613 | ;; The options are ordered in likely frequence of use, most common |
2614 | ;; highest, least lowest. Ie, more likely to be doing prefix | |
2615 | ;; adjustments than soliciting, and yet more than numbering. | |
2616 | ;; Current prefix is least dominant, but most likely to be commonly | |
2617 | ;; specified... | |
2618 | ||
2619 | (let* (body | |
2620 | numbering | |
2621 | denumbering | |
fd5359c6 MR |
2622 | (depth (or depth (allout-depth))) |
2623 | (header-lead allout-header-prefix) | |
1977b8f6 RS |
2624 | (bullet-char |
2625 | ||
2626 | ;; Getting value for bullet char is practically the whole job: | |
2627 | ||
2628 | (cond | |
2629 | ; Simplest situation - level 1: | |
fd5359c6 | 2630 | ((<= depth 1) (setq header-lead "") allout-primary-bullet) |
1977b8f6 | 2631 | ; Simple, too: all asterisks: |
fd5359c6 | 2632 | (allout-old-style-prefixes |
1977b8f6 RS |
2633 | ;; Cheat - make body the whole thing, null out header-lead and |
2634 | ;; bullet-char: | |
2635 | (setq body (make-string depth | |
fd5359c6 | 2636 | (string-to-char allout-primary-bullet))) |
1977b8f6 RS |
2637 | (setq header-lead "") |
2638 | "") | |
2639 | ||
2640 | ;; (Neither level 1 nor old-style, so we're space padding. | |
2641 | ;; Sneak it in the condition of the next case, whatever it is.) | |
2642 | ||
2643 | ;; Solicitation overrides numbering and other cases: | |
2644 | ((progn (setq body (make-string (- depth 2) ?\ )) | |
2645 | ;; The actual condition: | |
2646 | solicit) | |
fd5359c6 | 2647 | (let* ((got (allout-solicit-alternate-bullet depth solicit))) |
1977b8f6 | 2648 | ;; Gotta check whether we're numbering and got a numbered bullet: |
fd5359c6 | 2649 | (setq numbering (and allout-numbered-bullet |
1977b8f6 | 2650 | (not (and number-control (not index))) |
fd5359c6 | 2651 | (string= got allout-numbered-bullet))) |
1977b8f6 RS |
2652 | ;; Now return what we got, regardless: |
2653 | got)) | |
2654 | ||
2655 | ;; Numbering invoked through args: | |
fd5359c6 | 2656 | ((and allout-numbered-bullet number-control) |
1977b8f6 | 2657 | (if (setq numbering (not (setq denumbering (not index)))) |
fd5359c6 | 2658 | allout-numbered-bullet |
19b84ba3 | 2659 | (if (and prior-bullet |
fd5359c6 | 2660 | (not (string= allout-numbered-bullet |
19b84ba3 RS |
2661 | prior-bullet))) |
2662 | prior-bullet | |
fd5359c6 | 2663 | (allout-bullet-for-depth depth)))) |
1977b8f6 RS |
2664 | |
2665 | ;;; Neither soliciting nor controlled numbering ;;; | |
2666 | ;;; (may be controlled denumbering, tho) ;;; | |
2667 | ||
2668 | ;; Check wrt previous sibling: | |
2669 | ((and new ; only check for new prefixes | |
fd5359c6 MR |
2670 | (<= depth (allout-depth)) |
2671 | allout-numbered-bullet ; ... & numbering enabled | |
1977b8f6 RS |
2672 | (not denumbering) |
2673 | (let ((sibling-bullet | |
2674 | (save-excursion | |
2675 | ;; Locate correct sibling: | |
fd5359c6 MR |
2676 | (or (>= depth (allout-depth)) |
2677 | (allout-ascend-to-depth depth)) | |
2678 | (allout-get-bullet)))) | |
1977b8f6 | 2679 | (if (and sibling-bullet |
fd5359c6 | 2680 | (string= allout-numbered-bullet sibling-bullet)) |
1977b8f6 RS |
2681 | (setq numbering sibling-bullet))))) |
2682 | ||
2683 | ;; Distinctive prior bullet? | |
2684 | ((and prior-bullet | |
fd5359c6 | 2685 | (allout-distinctive-bullet prior-bullet) |
1977b8f6 | 2686 | ;; Either non-numbered: |
fd5359c6 MR |
2687 | (or (not (and allout-numbered-bullet |
2688 | (string= prior-bullet allout-numbered-bullet))) | |
1977b8f6 RS |
2689 | ;; or numbered, and not denumbering: |
2690 | (setq numbering (not denumbering))) | |
2691 | ;; Here 'tis: | |
2692 | prior-bullet)) | |
2693 | ||
2694 | ;; Else, standard bullet per depth: | |
fd5359c6 | 2695 | ((allout-bullet-for-depth depth))))) |
1977b8f6 RS |
2696 | |
2697 | (concat header-lead | |
2698 | body | |
2699 | bullet-char | |
2700 | (if numbering | |
2701 | (format "%d" (cond ((and index (numberp index)) index) | |
fd5359c6 MR |
2702 | (new (1+ (allout-sibling-index depth))) |
2703 | ((allout-sibling-index)))))) | |
1977b8f6 RS |
2704 | ) |
2705 | ) | |
fd5359c6 MR |
2706 | ;;;_ > allout-open-topic (relative-depth &optional before use_sib_bullet) |
2707 | (defun allout-open-topic (relative-depth &optional before use_sib_bullet) | |
19b84ba3 RS |
2708 | "Open a new topic at depth DEPTH. |
2709 | ||
2710 | New topic is situated after current one, unless optional flag BEFORE | |
2711 | is non-nil, or unless current line is complete empty (not even | |
2712 | whitespace), in which case open is done on current line. | |
c567ac01 | 2713 | |
9179616f DL |
2714 | If USE_SIB_BULLET is true, use the bullet of the prior sibling. |
2715 | ||
c567ac01 RS |
2716 | Nuances: |
2717 | ||
2718 | - Creation of new topics is with respect to the visible topic | |
2719 | containing the cursor, regardless of intervening concealed ones. | |
2720 | ||
2721 | - New headers are generally created after/before the body of a | |
2722 | topic. However, they are created right at cursor location if the | |
2723 | cursor is on a blank line, even if that breaks the current topic | |
2724 | body. This is intentional, to provide a simple means for | |
2725 | deliberately dividing topic bodies. | |
2726 | ||
2727 | - Double spacing of topic lists is preserved. Also, the first | |
2728 | level two topic is created double-spaced (and so would be | |
2729 | subsequent siblings, if that's left intact). Otherwise, | |
2730 | single-spacing is used. | |
2731 | ||
2732 | - Creation of sibling or nested topics is with respect to the topic | |
2733 | you're starting from, even when creating backwards. This way you | |
2734 | can easily create a sibling in front of the current topic without | |
a0776d6b | 2735 | having to go to its preceding sibling, and then open forward |
c567ac01 | 2736 | from there." |
1977b8f6 | 2737 | |
fd5359c6 | 2738 | (let* ((depth (+ (allout-current-depth) relative-depth)) |
1977b8f6 RS |
2739 | (opening-on-blank (if (looking-at "^\$") |
2740 | (not (setq before nil)))) | |
2741 | opening-numbered ; Will get while computing ref-topic, below | |
9179616f DL |
2742 | ref-depth ; Will get while computing ref-topic, below |
2743 | ref-bullet ; Will get while computing ref-topic, next | |
1977b8f6 RS |
2744 | (ref-topic (save-excursion |
2745 | (cond ((< relative-depth 0) | |
fd5359c6 | 2746 | (allout-ascend-to-depth depth)) |
1977b8f6 | 2747 | ((>= relative-depth 1) nil) |
fd5359c6 MR |
2748 | (t (allout-back-to-current-heading))) |
2749 | (setq ref-depth (allout-recent-depth)) | |
9179616f | 2750 | (setq ref-bullet |
fd5359c6 MR |
2751 | (if (> allout-recent-prefix-end 1) |
2752 | (allout-recent-bullet) | |
9179616f | 2753 | "")) |
1977b8f6 RS |
2754 | (setq opening-numbered |
2755 | (save-excursion | |
fd5359c6 | 2756 | (and allout-numbered-bullet |
1977b8f6 | 2757 | (or (<= relative-depth 0) |
fd5359c6 MR |
2758 | (allout-descend-to-depth depth)) |
2759 | (if (allout-numbered-type-prefix) | |
2760 | allout-numbered-bullet)))) | |
1977b8f6 RS |
2761 | (point))) |
2762 | dbl-space | |
c567ac01 | 2763 | doing-beginning) |
1977b8f6 RS |
2764 | |
2765 | (if (not opening-on-blank) | |
2766 | ; Positioning and vertical | |
2767 | ; padding - only if not | |
2768 | ; opening-on-blank: | |
353e2ef2 | 2769 | (progn |
1977b8f6 RS |
2770 | (goto-char ref-topic) |
2771 | (setq dbl-space ; Determine double space action: | |
c567ac01 RS |
2772 | (or (and (<= relative-depth 0) ; not descending; |
2773 | (save-excursion | |
a0776d6b | 2774 | ;; at b-o-b or preceded by a blank line? |
c567ac01 RS |
2775 | (or (> 0 (forward-line -1)) |
2776 | (looking-at "^\\s-*$") | |
2777 | (bobp))) | |
1977b8f6 | 2778 | (save-excursion |
c567ac01 | 2779 | ;; succeeded by a blank line? |
fd5359c6 | 2780 | (allout-end-of-current-subtree) |
c567ac01 | 2781 | (bolp))) |
1977b8f6 RS |
2782 | (and (= ref-depth 1) |
2783 | (or before | |
2784 | (= depth 1) | |
2785 | (save-excursion | |
2786 | ;; Don't already have following | |
2787 | ;; vertical padding: | |
fd5359c6 | 2788 | (not (allout-pre-next-preface))))))) |
1977b8f6 RS |
2789 | |
2790 | ; Position to prior heading, | |
c567ac01 RS |
2791 | ; if inserting backwards, and |
2792 | ; not going outwards: | |
2793 | (if (and before (>= relative-depth 0)) | |
fd5359c6 | 2794 | (progn (allout-back-to-current-heading) |
1977b8f6 | 2795 | (setq doing-beginning (bobp)) |
c567ac01 | 2796 | (if (not (bobp)) |
fd5359c6 | 2797 | (allout-previous-heading))) |
c567ac01 | 2798 | (if (and before (bobp)) |
fd5359c6 | 2799 | (allout-unprotected (open-line 1)))) |
1977b8f6 | 2800 | |
c567ac01 | 2801 | (if (<= relative-depth 0) |
1977b8f6 RS |
2802 | ;; Not going inwards, don't snug up: |
2803 | (if doing-beginning | |
fd5359c6 | 2804 | (allout-unprotected (open-line (if dbl-space 2 1))) |
c567ac01 RS |
2805 | (if before |
2806 | (progn (end-of-line) | |
fd5359c6 | 2807 | (allout-pre-next-preface) |
c567ac01 RS |
2808 | (while (= ?\r (following-char)) |
2809 | (forward-char 1)) | |
2810 | (if (not (looking-at "^$")) | |
fd5359c6 MR |
2811 | (allout-unprotected (open-line 1)))) |
2812 | (allout-end-of-current-subtree))) | |
1977b8f6 RS |
2813 | ;; Going inwards - double-space if first offspring is, |
2814 | ;; otherwise snug up. | |
2815 | (end-of-line) ; So we skip any concealed progeny. | |
fd5359c6 | 2816 | (allout-pre-next-preface) |
1977b8f6 RS |
2817 | (if (bolp) |
2818 | ;; Blank lines between current header body and next | |
2819 | ;; header - get to last substantive (non-white-space) | |
2820 | ;; line in body: | |
2821 | (re-search-backward "[^ \t\n]" nil t)) | |
2822 | (if (save-excursion | |
fd5359c6 MR |
2823 | (allout-next-heading) |
2824 | (if (> (allout-recent-depth) ref-depth) | |
1977b8f6 RS |
2825 | ;; This is an offspring. |
2826 | (progn (forward-line -1) | |
2827 | (looking-at "^\\s-*$")))) | |
2828 | (progn (forward-line 1) | |
fd5359c6 | 2829 | (allout-unprotected (open-line 1)))) |
1977b8f6 RS |
2830 | (end-of-line)) |
2831 | ;;(if doing-beginning (goto-char doing-beginning)) | |
c567ac01 RS |
2832 | (if (not (bobp)) |
2833 | (progn (if (and (not (> depth ref-depth)) | |
2834 | (not before)) | |
fd5359c6 | 2835 | (allout-unprotected (open-line 1)) |
c567ac01 | 2836 | (if (> depth ref-depth) |
fd5359c6 | 2837 | (allout-unprotected (newline 1)) |
c567ac01 | 2838 | (if dbl-space |
fd5359c6 | 2839 | (allout-unprotected (open-line 1)) |
c567ac01 | 2840 | (if (not before) |
fd5359c6 | 2841 | (allout-unprotected (newline 1)))))) |
c567ac01 | 2842 | (if dbl-space |
fd5359c6 | 2843 | (allout-unprotected (newline 1))) |
c567ac01 RS |
2844 | (if (and (not (eobp)) |
2845 | (not (bolp))) | |
2846 | (forward-char 1)))) | |
1977b8f6 | 2847 | )) |
fd5359c6 | 2848 | (insert (concat (allout-make-topic-prefix opening-numbered |
eac9cf5f PJ |
2849 | t |
2850 | depth) | |
2851 | " ")) | |
1977b8f6 RS |
2852 | |
2853 | ;;(if doing-beginning (save-excursion (newline (if dbl-space 2 1)))) | |
2854 | ||
2855 | ||
fd5359c6 | 2856 | (allout-rebullet-heading (and use_sib_bullet ref-bullet);;; solicit |
9179616f DL |
2857 | depth ;;; depth |
2858 | nil ;;; number-control | |
2859 | nil ;;; index | |
1977b8f6 RS |
2860 | t) (end-of-line) |
2861 | ) | |
2862 | ) | |
c567ac01 RS |
2863 | ;;;_ . open-topic contingencies |
2864 | ;;;_ ; base topic - one from which open was issued | |
2865 | ;;;_ , beginning char | |
a0776d6b | 2866 | ;;;_ , amount of space before will be used, unless opening in place |
c567ac01 RS |
2867 | ;;;_ , end char will be used, unless opening before (and it still may) |
2868 | ;;;_ ; absolute depth of new topic | |
2869 | ;;;_ ! insert in place - overrides most stuff | |
2870 | ;;;_ ; relative depth of new re base | |
2871 | ;;;_ ; before or after base topic | |
2872 | ;;;_ ; spacing around topic, if any, prior to new topic and at same depth | |
2873 | ;;;_ ; buffer boundaries - special provisions for beginning and end ob | |
2874 | ;;;_ ; level 1 topics have special provisions also - double space. | |
2875 | ;;;_ ; location of new topic | |
fd5359c6 MR |
2876 | ;;;_ > allout-open-subtopic (arg) |
2877 | (defun allout-open-subtopic (arg) | |
c567ac01 RS |
2878 | "Open new topic header at deeper level than the current one. |
2879 | ||
2880 | Negative universal arg means to open deeper, but place the new topic | |
2881 | prior to the current one." | |
1977b8f6 | 2882 | (interactive "p") |
fd5359c6 MR |
2883 | (allout-open-topic 1 (> 0 arg))) |
2884 | ;;;_ > allout-open-sibtopic (arg) | |
2885 | (defun allout-open-sibtopic (arg) | |
19b84ba3 RS |
2886 | "Open new topic header at same level as the current one. |
2887 | ||
9179616f DL |
2888 | Positive universal arg means to use the bullet of the prior sibling. |
2889 | ||
19b84ba3 | 2890 | Negative universal arg means to place the new topic prior to the current |
c567ac01 | 2891 | one." |
1977b8f6 | 2892 | (interactive "p") |
fd5359c6 MR |
2893 | (allout-open-topic 0 (> 0 arg) (< 1 arg))) |
2894 | ;;;_ > allout-open-supertopic (arg) | |
2895 | (defun allout-open-supertopic (arg) | |
c567ac01 | 2896 | "Open new topic header at shallower level than the current one. |
19b84ba3 | 2897 | |
c567ac01 RS |
2898 | Negative universal arg means to open shallower, but place the new |
2899 | topic prior to the current one." | |
1977b8f6 RS |
2900 | |
2901 | (interactive "p") | |
fd5359c6 | 2902 | (allout-open-topic -1 (> 0 arg))) |
c567ac01 RS |
2903 | |
2904 | ;;;_ - Outline Alteration | |
2905 | ;;;_ : Topic Modification | |
fd5359c6 MR |
2906 | ;;;_ = allout-former-auto-filler |
2907 | (defvar allout-former-auto-filler nil | |
2265e017 | 2908 | "Name of modal fill function being wrapped by `allout-auto-fill'.") |
fd5359c6 MR |
2909 | ;;;_ > allout-auto-fill () |
2910 | (defun allout-auto-fill () | |
aad94676 | 2911 | "`allout-mode' autofill function. |
19b84ba3 RS |
2912 | |
2913 | Maintains outline hanging topic indentation if | |
fd5359c6 MR |
2914 | `allout-use-hanging-indents' is set." |
2915 | (let ((fill-prefix (if allout-use-hanging-indents | |
c567ac01 RS |
2916 | ;; Check for topic header indentation: |
2917 | (save-excursion | |
2918 | (beginning-of-line) | |
fd5359c6 | 2919 | (if (looking-at allout-regexp) |
c567ac01 RS |
2920 | ;; ... construct indentation to account for |
2921 | ;; length of topic prefix: | |
fd5359c6 | 2922 | (make-string (progn (allout-end-of-prefix) |
c567ac01 RS |
2923 | (current-column)) |
2924 | ?\ )))))) | |
fd5359c6 | 2925 | (if (or allout-former-auto-filler allout-use-hanging-indents) |
c567ac01 | 2926 | (do-auto-fill)))) |
fd5359c6 MR |
2927 | ;;;_ > allout-reindent-body (old-depth new-depth &optional number) |
2928 | (defun allout-reindent-body (old-depth new-depth &optional number) | |
c567ac01 RS |
2929 | "Reindent body lines which were indented at old-depth to new-depth. |
2930 | ||
2931 | Optional arg NUMBER indicates numbering is being added, and it must | |
a0776d6b | 2932 | be accommodated. |
c567ac01 RS |
2933 | |
2934 | Note that refill of indented paragraphs is not done." | |
1977b8f6 RS |
2935 | |
2936 | (save-excursion | |
fd5359c6 | 2937 | (allout-end-of-prefix) |
c567ac01 RS |
2938 | (let* ((new-margin (current-column)) |
2939 | excess old-indent-begin old-indent-end | |
2940 | curr-ind | |
2941 | ;; We want the column where the header-prefix text started | |
2942 | ;; *before* the prefix was changed, so we infer it relative | |
2943 | ;; to the new margin and the shift in depth: | |
2944 | (old-margin (+ old-depth (- new-margin new-depth)))) | |
353e2ef2 | 2945 | |
c567ac01 | 2946 | ;; Process lines up to (but excluding) next topic header: |
fd5359c6 | 2947 | (allout-unprotected |
c567ac01 RS |
2948 | (save-match-data |
2949 | (while | |
2950 | (and (re-search-forward "[\n\r]\\(\\s-*\\)" | |
2951 | nil | |
2952 | t) | |
2953 | ;; Register the indent data, before we reset the | |
353e2ef2 | 2954 | ;; match data with a subsequent `looking-at': |
c567ac01 RS |
2955 | (setq old-indent-begin (match-beginning 1) |
2956 | old-indent-end (match-end 1)) | |
fd5359c6 | 2957 | (not (looking-at allout-regexp))) |
c567ac01 RS |
2958 | (if (> 0 (setq excess (- (current-column) |
2959 | old-margin))) | |
2960 | ;; Text starts left of old margin - don't adjust: | |
2961 | nil | |
2962 | ;; Text was hanging at or right of old left margin - | |
2963 | ;; reindent it, preserving its existing indentation | |
2964 | ;; beyond the old margin: | |
2965 | (delete-region old-indent-begin old-indent-end) | |
2966 | (indent-to (+ new-margin excess))))))))) | |
fd5359c6 MR |
2967 | ;;;_ > allout-rebullet-current-heading (arg) |
2968 | (defun allout-rebullet-current-heading (arg) | |
9179616f DL |
2969 | "Solicit new bullet for current visible heading." |
2970 | (interactive "p") | |
2971 | (let ((initial-col (current-column)) | |
fd5359c6 | 2972 | (on-bullet (eq (point)(allout-current-bullet-pos))) |
9179616f DL |
2973 | (backwards (if (< arg 0) |
2974 | (setq arg (* arg -1))))) | |
2975 | (while (> arg 0) | |
fd5359c6 MR |
2976 | (save-excursion (allout-back-to-current-heading) |
2977 | (allout-end-of-prefix) | |
2978 | (allout-rebullet-heading t ;;; solicit | |
9179616f DL |
2979 | nil ;;; depth |
2980 | nil ;;; number-control | |
2981 | nil ;;; index | |
2982 | t)) ;;; do-successors | |
2983 | (setq arg (1- arg)) | |
2984 | (if (<= arg 0) | |
2985 | nil | |
2986 | (setq initial-col nil) ; Override positioning back to init col | |
2987 | (if (not backwards) | |
fd5359c6 MR |
2988 | (allout-next-visible-heading 1) |
2989 | (allout-goto-prefix) | |
2990 | (allout-next-visible-heading -1)))) | |
9179616f | 2991 | (message "Done.") |
fd5359c6 | 2992 | (cond (on-bullet (goto-char (allout-current-bullet-pos))) |
9179616f | 2993 | (initial-col (move-to-column initial-col))))) |
fd5359c6 MR |
2994 | ;;;_ > allout-rebullet-heading (&optional solicit ...) |
2995 | (defun allout-rebullet-heading (&optional solicit | |
1977b8f6 RS |
2996 | new-depth |
2997 | number-control | |
2998 | index | |
2999 | do-successors) | |
3000 | ||
c567ac01 | 3001 | "Adjust bullet of current topic prefix. |
1977b8f6 | 3002 | |
c567ac01 | 3003 | All args are optional. |
1977b8f6 | 3004 | |
9179616f DL |
3005 | If SOLICIT is non-nil, then the choice of bullet is solicited from |
3006 | user. If it's a character, then that character is offered as the | |
3007 | default, otherwise the one suited to the context \(according to | |
3008 | distinction or depth) is offered. If non-nil, then the | |
3009 | context-specific bullet is just used. | |
1977b8f6 | 3010 | |
c567ac01 | 3011 | Second arg DEPTH forces the topic prefix to that depth, regardless |
9179616f | 3012 | of the topic's current depth. |
1977b8f6 | 3013 | |
c567ac01 | 3014 | Third arg NUMBER-CONTROL can force the prefix to or away from |
fd5359c6 | 3015 | numbered form. It has effect only if `allout-numbered-bullet' is |
c567ac01 RS |
3016 | non-nil and soliciting was not explicitly invoked (via first arg). |
3017 | Its effect, numbering or denumbering, then depends on the setting | |
3018 | of the forth arg, INDEX. | |
1977b8f6 | 3019 | |
c567ac01 RS |
3020 | If NUMBER-CONTROL is non-nil and forth arg INDEX is nil, then the |
3021 | prefix of the topic is forced to be non-numbered. Null index and | |
3022 | non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and | |
3023 | non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil | |
3024 | INDEX is a number, then that number is used for the numbered | |
3025 | prefix. Non-nil and non-number means that the index for the | |
2265e017 | 3026 | numbered prefix will be derived by `allout-make-topic-prefix'. |
1977b8f6 | 3027 | |
c567ac01 RS |
3028 | Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding |
3029 | siblings. | |
1977b8f6 | 3030 | |
fd5359c6 MR |
3031 | Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes', |
3032 | and `allout-numbered-bullet', which all affect the behavior of | |
c567ac01 | 3033 | this function." |
1977b8f6 | 3034 | |
fd5359c6 | 3035 | (let* ((current-depth (allout-depth)) |
1977b8f6 | 3036 | (new-depth (or new-depth current-depth)) |
fd5359c6 MR |
3037 | (mb allout-recent-prefix-beginning) |
3038 | (me allout-recent-prefix-end) | |
1977b8f6 | 3039 | (current-bullet (buffer-substring (- me 1) me)) |
fd5359c6 | 3040 | (new-prefix (allout-make-topic-prefix current-bullet |
1977b8f6 RS |
3041 | nil |
3042 | new-depth | |
3043 | solicit | |
3044 | number-control | |
3045 | index))) | |
3046 | ||
c567ac01 | 3047 | ;; Is new one is identical to old? |
1977b8f6 RS |
3048 | (if (and (= current-depth new-depth) |
3049 | (string= current-bullet | |
3050 | (substring new-prefix (1- (length new-prefix))))) | |
c567ac01 | 3051 | ;; Nothing to do: |
1977b8f6 RS |
3052 | t |
3053 | ||
3054 | ;; New prefix probably different from old: | |
c567ac01 | 3055 | ; get rid of old one: |
fd5359c6 | 3056 | (allout-unprotected (delete-region mb me)) |
1977b8f6 | 3057 | (goto-char mb) |
c567ac01 RS |
3058 | ; Dispense with number if |
3059 | ; numbered-bullet prefix: | |
fd5359c6 MR |
3060 | (if (and allout-numbered-bullet |
3061 | (string= allout-numbered-bullet current-bullet) | |
1977b8f6 | 3062 | (looking-at "[0-9]+")) |
fd5359c6 | 3063 | (allout-unprotected |
c567ac01 | 3064 | (delete-region (match-beginning 0)(match-end 0)))) |
1977b8f6 | 3065 | |
c567ac01 | 3066 | ; Put in new prefix: |
fd5359c6 | 3067 | (allout-unprotected (insert new-prefix)) |
1977b8f6 | 3068 | |
c567ac01 | 3069 | ;; Reindent the body if elected and margin changed: |
fd5359c6 | 3070 | (if (and allout-reindent-bodies |
c567ac01 | 3071 | (not (= new-depth current-depth))) |
fd5359c6 | 3072 | (allout-reindent-body current-depth new-depth)) |
1977b8f6 | 3073 | |
c567ac01 RS |
3074 | ;; Recursively rectify successive siblings of orig topic if |
3075 | ;; caller elected for it: | |
3076 | (if do-successors | |
3077 | (save-excursion | |
fd5359c6 | 3078 | (while (allout-next-sibling new-depth nil) |
c567ac01 RS |
3079 | (setq index |
3080 | (cond ((numberp index) (1+ index)) | |
fd5359c6 MR |
3081 | ((not number-control) (allout-sibling-index)))) |
3082 | (if (allout-numbered-type-prefix) | |
3083 | (allout-rebullet-heading nil ;;; solicit | |
c567ac01 RS |
3084 | new-depth ;;; new-depth |
3085 | number-control;;; number-control | |
3086 | index ;;; index | |
3087 | nil))))) ;;;(dont!)do-successors | |
3088 | ) ; (if (and (= current-depth new-depth)...)) | |
fd5359c6 | 3089 | ) ; let* ((current-depth (allout-depth))...) |
c567ac01 | 3090 | ) ; defun |
fd5359c6 MR |
3091 | ;;;_ > allout-rebullet-topic (arg) |
3092 | (defun allout-rebullet-topic (arg) | |
2265e017 | 3093 | "Like `allout-rebullet-topic-grunt', but start from topic visible at point. |
19b84ba3 | 3094 | |
c567ac01 | 3095 | Descends into invisible as well as visible topics, however. |
1977b8f6 | 3096 | |
c567ac01 | 3097 | With repeat count, shift topic depth by that amount." |
1977b8f6 RS |
3098 | (interactive "P") |
3099 | (let ((start-col (current-column)) | |
3100 | (was-eol (eolp))) | |
3101 | (save-excursion | |
3102 | ;; Normalize arg: | |
3103 | (cond ((null arg) (setq arg 0)) | |
3104 | ((listp arg) (setq arg (car arg)))) | |
3105 | ;; Fill the user in, in case we're shifting a big topic: | |
3106 | (if (not (zerop arg)) (message "Shifting...")) | |
fd5359c6 MR |
3107 | (allout-back-to-current-heading) |
3108 | (if (<= (+ (allout-recent-depth) arg) 0) | |
1977b8f6 | 3109 | (error "Attempt to shift topic below level 1")) |
fd5359c6 | 3110 | (allout-rebullet-topic-grunt arg) |
1977b8f6 | 3111 | (if (not (zerop arg)) (message "Shifting... done."))) |
c567ac01 | 3112 | (move-to-column (max 0 (+ start-col arg))))) |
fd5359c6 MR |
3113 | ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...) |
3114 | (defun allout-rebullet-topic-grunt (&optional relative-depth | |
1977b8f6 RS |
3115 | starting-depth |
3116 | starting-point | |
3117 | index | |
3118 | do-successors) | |
3119 | ||
c567ac01 | 3120 | "Rebullet the topic at point, visible or invisible, and all |
2265e017 | 3121 | contained subtopics. See `allout-rebullet-heading' for rebulleting |
c567ac01 | 3122 | behavior. |
1977b8f6 | 3123 | |
c567ac01 | 3124 | All arguments are optional. |
1977b8f6 | 3125 | |
c567ac01 RS |
3126 | First arg RELATIVE-DEPTH means to shift the depth of the entire |
3127 | topic that amount. | |
1977b8f6 | 3128 | |
c567ac01 RS |
3129 | The rest of the args are for internal recursive use by the function |
3130 | itself. The are STARTING-DEPTH, STARTING-POINT, and INDEX." | |
1977b8f6 RS |
3131 | |
3132 | (let* ((relative-depth (or relative-depth 0)) | |
fd5359c6 | 3133 | (new-depth (allout-depth)) |
1977b8f6 RS |
3134 | (starting-depth (or starting-depth new-depth)) |
3135 | (on-starting-call (null starting-point)) | |
3136 | (index (or index | |
3137 | ;; Leave index null on starting call, so rebullet-heading | |
3138 | ;; calculates it at what might be new depth: | |
3139 | (and (or (zerop relative-depth) | |
3140 | (not on-starting-call)) | |
fd5359c6 | 3141 | (allout-sibling-index)))) |
1977b8f6 RS |
3142 | (moving-outwards (< 0 relative-depth)) |
3143 | (starting-point (or starting-point (point)))) | |
3144 | ||
3145 | ;; Sanity check for excessive promotion done only on starting call: | |
3146 | (and on-starting-call | |
3147 | moving-outwards | |
3148 | (> 0 (+ starting-depth relative-depth)) | |
6a05d05f | 3149 | (error "Attempt to shift topic out beyond level 1")) ;;; ====> |
1977b8f6 RS |
3150 | |
3151 | (cond ((= starting-depth new-depth) | |
3152 | ;; We're at depth to work on this one: | |
fd5359c6 | 3153 | (allout-rebullet-heading nil ;;; solicit |
1977b8f6 RS |
3154 | (+ starting-depth ;;; starting-depth |
3155 | relative-depth) | |
3156 | nil ;;; number | |
3157 | index ;;; index | |
3158 | ;; Every contained topic will get hit, | |
3159 | ;; and we have to get to outside ones | |
3160 | ;; deliberately: | |
3161 | nil) ;;; do-successors | |
3162 | ;; ... and work on subsequent ones which are at greater depth: | |
3163 | (setq index 0) | |
fd5359c6 | 3164 | (allout-next-heading) |
1977b8f6 | 3165 | (while (and (not (eobp)) |
fd5359c6 | 3166 | (< starting-depth (allout-recent-depth))) |
1977b8f6 | 3167 | (setq index (1+ index)) |
fd5359c6 | 3168 | (allout-rebullet-topic-grunt relative-depth ;;; relative-depth |
1977b8f6 RS |
3169 | (1+ starting-depth);;;starting-depth |
3170 | starting-point ;;; starting-point | |
3171 | index))) ;;; index | |
3172 | ||
3173 | ((< starting-depth new-depth) | |
3174 | ;; Rare case - subtopic more than one level deeper than parent. | |
3175 | ;; Treat this one at an even deeper level: | |
fd5359c6 | 3176 | (allout-rebullet-topic-grunt relative-depth ;;; relative-depth |
1977b8f6 RS |
3177 | new-depth ;;; starting-depth |
3178 | starting-point ;;; starting-point | |
3179 | index))) ;;; index | |
3180 | ||
3181 | (if on-starting-call | |
3182 | (progn | |
3183 | ;; Rectify numbering of former siblings of the adjusted topic, | |
3184 | ;; if topic has changed depth | |
3185 | (if (or do-successors | |
3186 | (and (not (zerop relative-depth)) | |
fd5359c6 MR |
3187 | (or (= (allout-recent-depth) starting-depth) |
3188 | (= (allout-recent-depth) (+ starting-depth | |
1977b8f6 | 3189 | relative-depth))))) |
fd5359c6 | 3190 | (allout-rebullet-heading nil nil nil nil t)) |
1977b8f6 RS |
3191 | ;; Now rectify numbering of new siblings of the adjusted topic, |
3192 | ;; if depth has been changed: | |
3193 | (progn (goto-char starting-point) | |
3194 | (if (not (zerop relative-depth)) | |
fd5359c6 | 3195 | (allout-rebullet-heading nil nil nil nil t))))) |
1977b8f6 RS |
3196 | ) |
3197 | ) | |
fd5359c6 MR |
3198 | ;;;_ > allout-renumber-to-depth (&optional depth) |
3199 | (defun allout-renumber-to-depth (&optional depth) | |
19b84ba3 RS |
3200 | "Renumber siblings at current depth. |
3201 | ||
3202 | Affects superior topics if optional arg DEPTH is less than current depth. | |
c567ac01 RS |
3203 | |
3204 | Returns final depth." | |
3205 | ||
3206 | ;; Proceed by level, processing subsequent siblings on each, | |
3207 | ;; ascending until we get shallower than the start depth: | |
3208 | ||
fd5359c6 | 3209 | (let ((ascender (allout-depth)) |
9179616f | 3210 | was-eobp) |
c567ac01 | 3211 | (while (and (not (eobp)) |
fd5359c6 MR |
3212 | (allout-depth) |
3213 | (>= (allout-recent-depth) depth) | |
c567ac01 RS |
3214 | (>= ascender depth)) |
3215 | ; Skip over all topics at | |
3216 | ; lesser depths, which can not | |
3217 | ; have been disturbed: | |
9179616f | 3218 | (while (and (not (setq was-eobp (eobp))) |
fd5359c6 MR |
3219 | (> (allout-recent-depth) ascender)) |
3220 | (allout-next-heading)) | |
c567ac01 | 3221 | ; Prime ascender for ascension: |
fd5359c6 MR |
3222 | (setq ascender (1- (allout-recent-depth))) |
3223 | (if (>= (allout-recent-depth) depth) | |
3224 | (allout-rebullet-heading nil ;;; solicit | |
c567ac01 RS |
3225 | nil ;;; depth |
3226 | nil ;;; number-control | |
3227 | nil ;;; index | |
9179616f DL |
3228 | t)) ;;; do-successors |
3229 | (if was-eobp (goto-char (point-max))))) | |
fd5359c6 MR |
3230 | (allout-recent-depth)) |
3231 | ;;;_ > allout-number-siblings (&optional denumber) | |
3232 | (defun allout-number-siblings (&optional denumber) | |
c567ac01 | 3233 | "Assign numbered topic prefix to this topic and its siblings. |
1977b8f6 | 3234 | |
c567ac01 RS |
3235 | With universal argument, denumber - assign default bullet to this |
3236 | topic and its siblings. | |
1977b8f6 | 3237 | |
c567ac01 RS |
3238 | With repeated universal argument (`^U^U'), solicit bullet for each |
3239 | rebulleting each topic at this level." | |
1977b8f6 RS |
3240 | |
3241 | (interactive "P") | |
3242 | ||
3243 | (save-excursion | |
fd5359c6 MR |
3244 | (allout-back-to-current-heading) |
3245 | (allout-beginning-of-level) | |
3246 | (let ((depth (allout-recent-depth)) | |
c567ac01 | 3247 | (index (if (not denumber) 1)) |
1977b8f6 RS |
3248 | (use-bullet (equal '(16) denumber)) |
3249 | (more t)) | |
3250 | (while more | |
fd5359c6 | 3251 | (allout-rebullet-heading use-bullet ;;; solicit |
c567ac01 | 3252 | depth ;;; depth |
1977b8f6 RS |
3253 | t ;;; number-control |
3254 | index ;;; index | |
3255 | nil) ;;; do-successors | |
3256 | (if index (setq index (1+ index))) | |
fd5359c6 MR |
3257 | (setq more (allout-next-sibling depth nil)))))) |
3258 | ;;;_ > allout-shift-in (arg) | |
3259 | (defun allout-shift-in (arg) | |
19b84ba3 | 3260 | "Increase depth of current heading and any topics collapsed within it." |
1977b8f6 | 3261 | (interactive "p") |
fd5359c6 MR |
3262 | (allout-rebullet-topic arg)) |
3263 | ;;;_ > allout-shift-out (arg) | |
3264 | (defun allout-shift-out (arg) | |
19b84ba3 | 3265 | "Decrease depth of current heading and any topics collapsed within it." |
1977b8f6 | 3266 | (interactive "p") |
fd5359c6 | 3267 | (allout-rebullet-topic (* arg -1))) |
c567ac01 | 3268 | ;;;_ : Surgery (kill-ring) functions with special provisions for outlines: |
fd5359c6 MR |
3269 | ;;;_ > allout-kill-line (&optional arg) |
3270 | (defun allout-kill-line (&optional arg) | |
c567ac01 | 3271 | "Kill line, adjusting subsequent lines suitably for outline mode." |
1977b8f6 RS |
3272 | |
3273 | (interactive "*P") | |
fd5359c6 MR |
3274 | (if (not (and (allout-mode-p) ; active outline mode, |
3275 | allout-numbered-bullet ; numbers may need adjustment, | |
c567ac01 | 3276 | (bolp) ; may be clipping topic head, |
fd5359c6 | 3277 | (looking-at allout-regexp))) ; are clipping topic head. |
1977b8f6 RS |
3278 | ;; Above conditions do not obtain - just do a regular kill: |
3279 | (kill-line arg) | |
3280 | ;; Ah, have to watch out for adjustments: | |
fd5359c6 | 3281 | (let* ((depth (allout-depth))) |
c567ac01 | 3282 | ; Do the kill: |
1977b8f6 | 3283 | (kill-line arg) |
c567ac01 | 3284 | ; Provide some feedback: |
1977b8f6 RS |
3285 | (sit-for 0) |
3286 | (save-excursion | |
c567ac01 RS |
3287 | ; Start with the topic |
3288 | ; following killed line: | |
fd5359c6 MR |
3289 | (if (not (looking-at allout-regexp)) |
3290 | (allout-next-heading)) | |
3291 | (allout-renumber-to-depth depth))))) | |
3292 | ;;;_ > allout-kill-topic () | |
3293 | (defun allout-kill-topic () | |
c567ac01 RS |
3294 | "Kill topic together with subtopics. |
3295 | ||
3296 | Leaves primary topic's trailing vertical whitespace, if any." | |
1977b8f6 RS |
3297 | |
3298 | ;; Some finagling is done to make complex topic kills appear faster | |
3299 | ;; than they actually are. A redisplay is performed immediately | |
3300 | ;; after the region is disposed of, though the renumbering process | |
3301 | ;; has yet to be performed. This means that there may appear to be | |
3302 | ;; a lag *after* the kill has been performed. | |
3303 | ||
3304 | (interactive) | |
fd5359c6 MR |
3305 | (let* ((beg (prog1 (allout-back-to-current-heading)(beginning-of-line))) |
3306 | (depth (allout-recent-depth))) | |
3307 | (allout-end-of-current-subtree) | |
1977b8f6 | 3308 | (if (not (eobp)) |
c567ac01 RS |
3309 | (if (or (not (looking-at "^$")) |
3310 | ;; A blank line - cut it with this topic *unless* this | |
3311 | ;; is the last topic at this level, in which case | |
3312 | ;; we'll leave the blank line as part of the | |
3313 | ;; containing topic: | |
3314 | (save-excursion | |
fd5359c6 MR |
3315 | (and (allout-next-heading) |
3316 | (>= (allout-recent-depth) depth)))) | |
c567ac01 | 3317 | (forward-char 1))) |
353e2ef2 | 3318 | |
1977b8f6 RS |
3319 | (kill-region beg (point)) |
3320 | (sit-for 0) | |
3321 | (save-excursion | |
fd5359c6 MR |
3322 | (allout-renumber-to-depth depth)))) |
3323 | ;;;_ > allout-yank-processing () | |
3324 | (defun allout-yank-processing (&optional arg) | |
c567ac01 | 3325 | |
aad94676 | 3326 | "Incidental outline specific business to be done just after text yanks. |
19b84ba3 | 3327 | |
c567ac01 | 3328 | Does depth adjustment of yanked topics, when: |
1977b8f6 | 3329 | |
c567ac01 RS |
3330 | 1 the stuff being yanked starts with a valid outline header prefix, and |
3331 | 2 it is being yanked at the end of a line which consists of only a valid | |
1977b8f6 RS |
3332 | topic prefix. |
3333 | ||
a0776d6b | 3334 | Also, adjusts numbering of subsequent siblings when appropriate. |
1977b8f6 | 3335 | |
c567ac01 RS |
3336 | Depth adjustment alters the depth of all the topics being yanked |
3337 | the amount it takes to make the first topic have the depth of the | |
3338 | header into which it's being yanked. | |
1977b8f6 | 3339 | |
c567ac01 RS |
3340 | The point is left in front of yanked, adjusted topics, rather than |
3341 | at the end (and vice-versa with the mark). Non-adjusted yanks, | |
aad94676 | 3342 | however, are left exactly like normal, not outline specific yanks." |
c567ac01 RS |
3343 | |
3344 | (interactive "*P") | |
3345 | ; Get to beginning, leaving | |
3346 | ; region around subject: | |
9179616f | 3347 | (if (< (my-mark-marker t) (point)) |
c567ac01 RS |
3348 | (exchange-point-and-mark)) |
3349 | (let* ((subj-beg (point)) | |
9179616f DL |
3350 | (subj-end (my-mark-marker t)) |
3351 | ;; 'resituate' if yanking an entire topic into topic header: | |
fd5359c6 MR |
3352 | (resituate (and (allout-e-o-prefix-p) |
3353 | (looking-at (concat "\\(" allout-regexp "\\)")) | |
3354 | (allout-prefix-data (match-beginning 1) | |
c567ac01 | 3355 | (match-end 1)))) |
353e2ef2 | 3356 | ;; `rectify-numbering' if resituating (where several topics may |
c567ac01 RS |
3357 | ;; be resituating) or yanking a topic into a topic slot (bol): |
3358 | (rectify-numbering (or resituate | |
fd5359c6 | 3359 | (and (bolp) (looking-at allout-regexp))))) |
c567ac01 RS |
3360 | (if resituate |
3361 | ; The yanked stuff is a topic: | |
3362 | (let* ((prefix-len (- (match-end 1) subj-beg)) | |
fd5359c6 MR |
3363 | (subj-depth (allout-recent-depth)) |
3364 | (prefix-bullet (allout-recent-bullet)) | |
c567ac01 RS |
3365 | (adjust-to-depth |
3366 | ;; Nil if adjustment unnecessary, otherwise depth to which | |
3367 | ;; adjustment should be made: | |
3368 | (save-excursion | |
3369 | (and (goto-char subj-end) | |
3370 | (eolp) | |
3371 | (goto-char subj-beg) | |
fd5359c6 | 3372 | (and (looking-at allout-regexp) |
c567ac01 RS |
3373 | (progn |
3374 | (beginning-of-line) | |
3375 | (not (= (point) subj-beg))) | |
fd5359c6 MR |
3376 | (looking-at allout-regexp) |
3377 | (allout-prefix-data (match-beginning 0) | |
c567ac01 | 3378 | (match-end 0))) |
fd5359c6 | 3379 | (allout-recent-depth)))) |
c567ac01 RS |
3380 | done |
3381 | (more t)) | |
fd5359c6 | 3382 | (setq rectify-numbering allout-numbered-bullet) |
c567ac01 RS |
3383 | (if adjust-to-depth |
3384 | ; Do the adjustment: | |
3385 | (progn | |
3386 | (message "... yanking") (sit-for 0) | |
3387 | (save-restriction | |
3388 | (narrow-to-region subj-beg subj-end) | |
3389 | ; Trim off excessive blank | |
3390 | ; line at end, if any: | |
3391 | (goto-char (point-max)) | |
3392 | (if (looking-at "^$") | |
fd5359c6 | 3393 | (allout-unprotected (delete-char -1))) |
c567ac01 RS |
3394 | ; Work backwards, with each |
3395 | ; shallowest level, | |
3396 | ; successively excluding the | |
3397 | ; last processed topic from | |
3398 | ; the narrow region: | |
3399 | (while more | |
fd5359c6 | 3400 | (allout-back-to-current-heading) |
c567ac01 | 3401 | ; go as high as we can in each bunch: |
fd5359c6 | 3402 | (while (allout-ascend-to-depth (1- (allout-depth)))) |
c567ac01 | 3403 | (save-excursion |
fd5359c6 | 3404 | (allout-rebullet-topic-grunt (- adjust-to-depth |
c567ac01 | 3405 | subj-depth)) |
fd5359c6 | 3406 | (allout-depth)) |
c567ac01 RS |
3407 | (if (setq more (not (bobp))) |
3408 | (progn (widen) | |
3409 | (forward-char -1) | |
3410 | (narrow-to-region subj-beg (point)))))) | |
3411 | (message "") | |
3412 | ;; Preserve new bullet if it's a distinctive one, otherwise | |
3413 | ;; use old one: | |
3414 | (if (string-match (regexp-quote prefix-bullet) | |
fd5359c6 | 3415 | allout-distinctive-bullets-string) |
c567ac01 RS |
3416 | ; Delete from bullet of old to |
3417 | ; before bullet of new: | |
3418 | (progn | |
3419 | (beginning-of-line) | |
3420 | (delete-region (point) subj-beg) | |
9179616f | 3421 | (set-marker (my-mark-marker t) subj-end) |
c567ac01 | 3422 | (goto-char subj-beg) |
fd5359c6 | 3423 | (allout-end-of-prefix)) |
c567ac01 RS |
3424 | ; Delete base subj prefix, |
3425 | ; leaving old one: | |
3426 | (delete-region (point) (+ (point) | |
3427 | prefix-len | |
3428 | (- adjust-to-depth subj-depth))) | |
3429 | ; and delete residual subj | |
3430 | ; prefix digits and space: | |
3431 | (while (looking-at "[0-9]") (delete-char 1)) | |
3432 | (if (looking-at " ") (delete-char 1)))) | |
3433 | (exchange-point-and-mark)))) | |
3434 | (if rectify-numbering | |
353e2ef2 | 3435 | (progn |
c567ac01 RS |
3436 | (save-excursion |
3437 | ; Give some preliminary feedback: | |
3438 | (message "... reconciling numbers") (sit-for 0) | |
3439 | ; ... and renumber, in case necessary: | |
3440 | (goto-char subj-beg) | |
fd5359c6 MR |
3441 | (if (allout-goto-prefix) |
3442 | (allout-rebullet-heading nil ;;; solicit | |
3443 | (allout-depth) ;;; depth | |
c567ac01 RS |
3444 | nil ;;; number-control |
3445 | nil ;;; index | |
3446 | t)) | |
3447 | (message "")))) | |
3448 | (if (not resituate) | |
3449 | (exchange-point-and-mark)))) | |
fd5359c6 MR |
3450 | ;;;_ > allout-yank (&optional arg) |
3451 | (defun allout-yank (&optional arg) | |
aad94676 | 3452 | "`allout-mode' yank, with depth and numbering adjustment of yanked topics. |
19b84ba3 | 3453 | |
a0776d6b | 3454 | Non-topic yanks work no differently than normal yanks. |
c567ac01 RS |
3455 | |
3456 | If a topic is being yanked into a bare topic prefix, the depth of the | |
3457 | yanked topic is adjusted to the depth of the topic prefix. | |
3458 | ||
2265e017 | 3459 | 1 we're yanking in an `allout-mode' buffer |
c567ac01 RS |
3460 | 2 the stuff being yanked starts with a valid outline header prefix, and |
3461 | 3 it is being yanked at the end of a line which consists of only a valid | |
3462 | topic prefix. | |
3463 | ||
3464 | If these conditions hold then the depth of the yanked topics are all | |
3465 | adjusted the amount it takes to make the first one at the depth of the | |
3466 | header into which it's being yanked. | |
3467 | ||
3468 | The point is left in front of yanked, adjusted topics, rather than | |
3469 | at the end (and vice-versa with the mark). Non-adjusted yanks, | |
3470 | however, (ones that don't qualify for adjustment) are handled | |
3471 | exactly like normal yanks. | |
3472 | ||
a0776d6b | 3473 | Numbering of yanked topics, and the successive siblings at the depth |
c567ac01 RS |
3474 | into which they're being yanked, is adjusted. |
3475 | ||
aad94676 | 3476 | `allout-yank-pop' works with `allout-yank' just like normal yank-pop |
c567ac01 | 3477 | works with normal yank in non-outline buffers." |
1977b8f6 RS |
3478 | |
3479 | (interactive "*P") | |
3480 | (setq this-command 'yank) | |
c567ac01 | 3481 | (yank arg) |
fd5359c6 MR |
3482 | (if (allout-mode-p) |
3483 | (allout-yank-processing))) | |
3484 | ;;;_ > allout-yank-pop (&optional arg) | |
3485 | (defun allout-yank-pop (&optional arg) | |
2265e017 | 3486 | "Yank-pop like `allout-yank' when popping to bare outline prefixes. |
19b84ba3 RS |
3487 | |
3488 | Adapts level of popped topics to level of fresh prefix. | |
c567ac01 RS |
3489 | |
3490 | Note - prefix changes to distinctive bullets will stick, if followed | |
3491 | by pops to non-distinctive yanks. Bug..." | |
1977b8f6 RS |
3492 | |
3493 | (interactive "*p") | |
1977b8f6 | 3494 | (setq this-command 'yank) |
c567ac01 | 3495 | (yank-pop arg) |
fd5359c6 MR |
3496 | (if (allout-mode-p) |
3497 | (allout-yank-processing))) | |
1977b8f6 | 3498 | |
c567ac01 RS |
3499 | ;;;_ - Specialty bullet functions |
3500 | ;;;_ : File Cross references | |
fd5359c6 MR |
3501 | ;;;_ > allout-resolve-xref () |
3502 | (defun allout-resolve-xref () | |
19b84ba3 RS |
3503 | "Pop to file associated with current heading, if it has an xref bullet. |
3504 | ||
fd5359c6 | 3505 | \(Works according to setting of `allout-file-xref-bullet')." |
1977b8f6 | 3506 | (interactive) |
fd5359c6 | 3507 | (if (not allout-file-xref-bullet) |
1977b8f6 | 3508 | (error |
fd5359c6 MR |
3509 | "outline cross references disabled - no `allout-file-xref-bullet'") |
3510 | (if (not (string= (allout-current-bullet) allout-file-xref-bullet)) | |
353e2ef2 | 3511 | (error "current heading lacks cross-reference bullet `%s'" |
fd5359c6 | 3512 | allout-file-xref-bullet) |
1977b8f6 RS |
3513 | (let (file-name) |
3514 | (save-excursion | |
fd5359c6 | 3515 | (let* ((text-start allout-recent-prefix-end) |
fa29cfef | 3516 | (heading-end (progn (end-of-line) (point)))) |
1977b8f6 RS |
3517 | (goto-char text-start) |
3518 | (setq file-name | |
3519 | (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t) | |
3520 | (buffer-substring (match-beginning 1) (match-end 1)))))) | |
3521 | (setq file-name | |
3522 | (if (not (= (aref file-name 0) ?:)) | |
3523 | (expand-file-name file-name) | |
353e2ef2 | 3524 | ; A registry-files ref, strip the `:' |
1977b8f6 RS |
3525 | ; and try to follow it: |
3526 | (let ((reg-ref (reference-registered-file | |
3527 | (substring file-name 1) nil t))) | |
3528 | (if reg-ref (car (cdr reg-ref)))))) | |
3529 | (if (or (file-exists-p file-name) | |
3530 | (if (file-writable-p file-name) | |
3531 | (y-or-n-p (format "%s not there, create one? " | |
3532 | file-name)) | |
3533 | (error "%s not found and can't be created" file-name))) | |
3534 | (condition-case failure | |
3535 | (find-file-other-window file-name) | |
9179616f | 3536 | ('error failure)) |
1977b8f6 RS |
3537 | (error "%s not found" file-name)) |
3538 | ) | |
3539 | ) | |
3540 | ) | |
3541 | ) | |
19b84ba3 | 3542 | |
9179616f | 3543 | ;;;_ #6 Exposure Control |
c567ac01 RS |
3544 | |
3545 | ;;;_ - Fundamental | |
fd5359c6 MR |
3546 | ;;;_ > allout-flag-current-subtree (flag) |
3547 | (defun allout-flag-current-subtree (flag) | |
19b84ba3 RS |
3548 | "Hide or show subtree of currently-visible topic. |
3549 | ||
fd5359c6 | 3550 | See `allout-flag-region' for more details." |
19b84ba3 | 3551 | |
c567ac01 | 3552 | (save-excursion |
fd5359c6 MR |
3553 | (allout-back-to-current-heading) |
3554 | (allout-flag-region (point) | |
3555 | (progn (allout-end-of-current-subtree) (1- (point))) | |
19b84ba3 | 3556 | flag))) |
c567ac01 | 3557 | |
c567ac01 | 3558 | ;;;_ - Topic-specific |
fd5359c6 MR |
3559 | ;;;_ > allout-show-entry () |
3560 | (defun allout-show-entry () | |
3561 | "Like `allout-show-current-entry', reveals entries nested in hidden topics. | |
c567ac01 RS |
3562 | |
3563 | This is a way to give restricted peek at a concealed locality without the | |
3564 | expense of exposing its context, but can leave the outline with aberrant | |
aad94676 | 3565 | exposure. `allout-hide-current-entry-completely' or `allout-show-to-offshoot' |
c567ac01 RS |
3566 | should be used after the peek to rectify the exposure." |
3567 | ||
3568 | (interactive) | |
3569 | (save-excursion | |
9179616f DL |
3570 | (let ((at (point)) |
3571 | beg end) | |
fd5359c6 | 3572 | (allout-goto-prefix) |
9179616f DL |
3573 | (setq beg (if (= (preceding-char) ?\r) (1- (point)) (point))) |
3574 | (re-search-forward "[\n\r]" nil t) | |
3575 | (setq end (1- (if (< at (point)) | |
3576 | ;; We're on topic head line - show only it: | |
3577 | (point) | |
3578 | ;; or we're in body - include it: | |
fd5359c6 MR |
3579 | (max beg (or (allout-pre-next-preface) (point)))))) |
3580 | (allout-flag-region beg end ?\n) | |
9179616f | 3581 | (list beg end)))) |
fd5359c6 MR |
3582 | ;;;_ > allout-show-children (&optional level strict) |
3583 | (defun allout-show-children (&optional level strict) | |
c567ac01 RS |
3584 | |
3585 | "If point is visible, show all direct subheadings of this heading. | |
19b84ba3 | 3586 | |
2265e017 | 3587 | Otherwise, do `allout-show-to-offshoot', and then show subheadings. |
c567ac01 RS |
3588 | |
3589 | Optional LEVEL specifies how many levels below the current level | |
3590 | should be shown, or all levels if t. Default is 1. | |
3591 | ||
3592 | Optional STRICT means don't resort to -show-to-offshoot, no matter | |
3593 | what. This is basically so -show-to-offshoot, which is called by | |
3594 | this function, can employ the pure offspring-revealing capabilities of | |
19b84ba3 RS |
3595 | it. |
3596 | ||
3597 | Returns point at end of subtree that was opened, if any. (May get a | |
3598 | point of non-opened subtree?)" | |
c567ac01 RS |
3599 | |
3600 | (interactive "p") | |
19b84ba3 RS |
3601 | (let (max-pos) |
3602 | (if (and (not strict) | |
fd5359c6 | 3603 | (allout-hidden-p)) |
c567ac01 | 3604 | |
fd5359c6 | 3605 | (progn (allout-show-to-offshoot) ; Point's concealed, open to |
19b84ba3 RS |
3606 | ; expose it. |
3607 | ;; Then recurse, but with "strict" set so we don't | |
3608 | ;; infinite regress: | |
fd5359c6 | 3609 | (setq max-pos (allout-show-children level t))) |
c567ac01 | 3610 | |
19b84ba3 RS |
3611 | (save-excursion |
3612 | (save-restriction | |
3613 | (let* ((start-pt (point)) | |
fd5359c6 MR |
3614 | (chart (allout-chart-subtree (or level 1))) |
3615 | (to-reveal (allout-chart-to-reveal chart (or level 1)))) | |
19b84ba3 RS |
3616 | (goto-char start-pt) |
3617 | (if (and strict (= (preceding-char) ?\r)) | |
3618 | ;; Concealed root would already have been taken care of, | |
3619 | ;; unless strict was set. | |
9179616f | 3620 | (progn |
fd5359c6 MR |
3621 | (allout-flag-region (point) (allout-snug-back) ?\n) |
3622 | (if allout-show-bodies | |
9179616f | 3623 | (progn (goto-char (car to-reveal)) |
fd5359c6 | 3624 | (allout-show-current-entry))))) |
19b84ba3 RS |
3625 | (while to-reveal |
3626 | (goto-char (car to-reveal)) | |
fd5359c6 MR |
3627 | (allout-flag-region (point) (allout-snug-back) ?\n) |
3628 | (if allout-show-bodies | |
9179616f | 3629 | (progn (goto-char (car to-reveal)) |
fd5359c6 | 3630 | (allout-show-current-entry))) |
19b84ba3 | 3631 | (setq to-reveal (cdr to-reveal))))))))) |
fd5359c6 MR |
3632 | ;;;_ > allout-hide-point-reconcile () |
3633 | (defun allout-hide-reconcile () | |
3634 | "Like `allout-hide-current-entry'; hides completely if within hidden region. | |
c567ac01 RS |
3635 | |
3636 | Specifically intended for aberrant exposure states, like entries that were | |
2265e017 | 3637 | exposed by `allout-show-entry' but are within otherwise concealed regions." |
c567ac01 RS |
3638 | (interactive) |
3639 | (save-excursion | |
fd5359c6 MR |
3640 | (allout-goto-prefix) |
3641 | (allout-flag-region (if (not (bobp)) (1- (point)) (point)) | |
3642 | (progn (allout-pre-next-preface) | |
c567ac01 RS |
3643 | (if (= ?\r (following-char)) |
3644 | (point) | |
3645 | (1- (point)))) | |
3646 | ?\r))) | |
fd5359c6 MR |
3647 | ;;;_ > allout-show-to-offshoot () |
3648 | (defun allout-show-to-offshoot () | |
2265e017 | 3649 | "Like `allout-show-entry', but reveals all concealed ancestors, as well. |
c567ac01 | 3650 | |
2265e017 MR |
3651 | As with `allout-hide-current-entry-completely', useful for rectifying |
3652 | aberrant exposure states produced by `allout-show-entry'." | |
c567ac01 RS |
3653 | |
3654 | (interactive) | |
3655 | (save-excursion | |
3656 | (let ((orig-pt (point)) | |
fd5359c6 | 3657 | (orig-pref (allout-goto-prefix)) |
c567ac01 RS |
3658 | (last-at (point)) |
3659 | bag-it) | |
3660 | (while (or bag-it (= (preceding-char) ?\r)) | |
3661 | (beginning-of-line) | |
3662 | (if (= last-at (setq last-at (point))) | |
3663 | ;; Oops, we're not making any progress! Show the current | |
3664 | ;; topic completely, and bag this try. | |
3665 | (progn (beginning-of-line) | |
fd5359c6 | 3666 | (allout-show-current-subtree) |
c567ac01 RS |
3667 | (goto-char orig-pt) |
3668 | (setq bag-it t) | |
3669 | (beep) | |
3670 | (message "%s: %s" | |
fd5359c6 | 3671 | "allout-show-to-offshoot: " |
c567ac01 | 3672 | "Aberrant nesting encountered."))) |
fd5359c6 | 3673 | (allout-show-children) |
c567ac01 | 3674 | (goto-char orig-pref)) |
19b84ba3 | 3675 | (goto-char orig-pt))) |
fd5359c6 MR |
3676 | (if (allout-hidden-p) |
3677 | (allout-show-entry))) | |
3678 | ;;;_ > allout-hide-current-entry () | |
3679 | (defun allout-hide-current-entry () | |
c567ac01 RS |
3680 | "Hide the body directly following this heading." |
3681 | (interactive) | |
fd5359c6 | 3682 | (allout-back-to-current-heading) |
c567ac01 | 3683 | (save-excursion |
fd5359c6 MR |
3684 | (allout-flag-region (point) |
3685 | (progn (allout-end-of-current-entry) (point)) | |
9179616f | 3686 | ?\r))) |
fd5359c6 MR |
3687 | ;;;_ > allout-show-current-entry (&optional arg) |
3688 | (defun allout-show-current-entry (&optional arg) | |
c567ac01 | 3689 | |
19b84ba3 | 3690 | "Show body following current heading, or hide the entry if repeat count." |
c567ac01 RS |
3691 | |
3692 | (interactive "P") | |
3693 | (if arg | |
fd5359c6 | 3694 | (allout-hide-current-entry) |
c567ac01 | 3695 | (save-excursion |
fd5359c6 MR |
3696 | (allout-flag-region (point) |
3697 | (progn (allout-end-of-current-entry) (point)) | |
19b84ba3 | 3698 | ?\n)))) |
fd5359c6 MR |
3699 | ;;;_ > allout-hide-current-entry-completely () |
3700 | ; ... allout-hide-current-entry-completely also for isearch dynamic exposure: | |
3701 | (defun allout-hide-current-entry-completely () | |
2265e017 | 3702 | "Like `allout-hide-current-entry', but conceal topic completely. |
c567ac01 RS |
3703 | |
3704 | Specifically intended for aberrant exposure states, like entries that were | |
2265e017 | 3705 | exposed by `allout-show-entry' but are within otherwise concealed regions." |
c567ac01 RS |
3706 | (interactive) |
3707 | (save-excursion | |
fd5359c6 MR |
3708 | (allout-goto-prefix) |
3709 | (allout-flag-region (if (not (bobp)) (1- (point)) (point)) | |
3710 | (progn (allout-pre-next-preface) | |
c567ac01 RS |
3711 | (if (= ?\r (following-char)) |
3712 | (point) | |
3713 | (1- (point)))) | |
3714 | ?\r))) | |
fd5359c6 MR |
3715 | ;;;_ > allout-show-current-subtree (&optional arg) |
3716 | (defun allout-show-current-subtree (&optional arg) | |
19b84ba3 | 3717 | "Show everything within the current topic. With a repeat-count, |
353e2ef2 | 3718 | expose this topic and its siblings." |
19b84ba3 RS |
3719 | (interactive "P") |
3720 | (save-excursion | |
fd5359c6 | 3721 | (if (<= (allout-current-depth) 0) |
19b84ba3 | 3722 | ;; Outside any topics - try to get to the first: |
fd5359c6 | 3723 | (if (not (allout-next-heading)) |
6a05d05f | 3724 | (error "No topics") |
19b84ba3 RS |
3725 | ;; got to first, outermost topic - set to expose it and siblings: |
3726 | (message "Above outermost topic - exposing all.") | |
fd5359c6 | 3727 | (allout-flag-region (point-min)(point-max) ?\n)) |
19b84ba3 | 3728 | (if (not arg) |
fd5359c6 MR |
3729 | (allout-flag-current-subtree ?\n) |
3730 | (allout-beginning-of-level) | |
3731 | (allout-expose-topic '(* :)))))) | |
3732 | ;;;_ > allout-hide-current-subtree (&optional just-close) | |
3733 | (defun allout-hide-current-subtree (&optional just-close) | |
19b84ba3 | 3734 | "Close the current topic, or containing topic if this one is already closed. |
c567ac01 | 3735 | |
19b84ba3 | 3736 | If this topic is closed and it's a top level topic, close this topic |
353e2ef2 | 3737 | and its siblings. |
19b84ba3 RS |
3738 | |
3739 | If optional arg JUST-CLOSE is non-nil, do not treat the parent or | |
3740 | siblings, even if the target topic is already closed." | |
c567ac01 RS |
3741 | |
3742 | (interactive) | |
19b84ba3 RS |
3743 | (let ((from (point)) |
3744 | (orig-eol (progn (end-of-line) | |
fd5359c6 | 3745 | (if (not (allout-goto-prefix)) |
6a05d05f | 3746 | (error "No topics found") |
19b84ba3 | 3747 | (end-of-line)(point))))) |
fd5359c6 | 3748 | (allout-flag-current-subtree ?\r) |
19b84ba3 RS |
3749 | (goto-char from) |
3750 | (if (and (= orig-eol (progn (goto-char orig-eol) | |
3751 | (end-of-line) | |
3752 | (point))) | |
3753 | (not just-close) | |
c567ac01 | 3754 | ;; Structure didn't change - try hiding current level: |
19b84ba3 | 3755 | (goto-char from) |
fd5359c6 | 3756 | (if (allout-up-current-level 1 t) |
19b84ba3 RS |
3757 | t |
3758 | (goto-char 0) | |
3759 | (let ((msg | |
3760 | "Top-level topic already closed - closing siblings...")) | |
3761 | (message msg) | |
fd5359c6 | 3762 | (allout-expose-topic '(0 :)) |
19b84ba3 RS |
3763 | (message (concat msg " Done."))) |
3764 | nil) | |
fd5359c6 MR |
3765 | (/= (allout-recent-depth) 0)) |
3766 | (allout-hide-current-subtree)) | |
19b84ba3 | 3767 | (goto-char from))) |
fd5359c6 MR |
3768 | ;;;_ > allout-show-current-branches () |
3769 | (defun allout-show-current-branches () | |
c567ac01 RS |
3770 | "Show all subheadings of this heading, but not their bodies." |
3771 | (interactive) | |
3772 | (beginning-of-line) | |
fd5359c6 MR |
3773 | (allout-show-children t)) |
3774 | ;;;_ > allout-hide-current-leaves () | |
3775 | (defun allout-hide-current-leaves () | |
353e2ef2 | 3776 | "Hide the bodies of the current topic and all its offspring." |
c567ac01 | 3777 | (interactive) |
fd5359c6 MR |
3778 | (allout-back-to-current-heading) |
3779 | (allout-hide-region-body (point) (progn (allout-end-of-current-subtree) | |
c567ac01 RS |
3780 | (point)))) |
3781 | ||
3782 | ;;;_ - Region and beyond | |
fd5359c6 MR |
3783 | ;;;_ > allout-show-all () |
3784 | (defun allout-show-all () | |
c567ac01 RS |
3785 | "Show all of the text in the buffer." |
3786 | (interactive) | |
19b84ba3 | 3787 | (message "Exposing entire buffer...") |
fd5359c6 | 3788 | (allout-flag-region (point-min) (point-max) ?\n) |
19b84ba3 | 3789 | (message "Exposing entire buffer... Done.")) |
fd5359c6 MR |
3790 | ;;;_ > allout-hide-bodies () |
3791 | (defun allout-hide-bodies () | |
c567ac01 RS |
3792 | "Hide all of buffer except headings." |
3793 | (interactive) | |
fd5359c6 MR |
3794 | (allout-hide-region-body (point-min) (point-max))) |
3795 | ;;;_ > allout-hide-region-body (start end) | |
3796 | (defun allout-hide-region-body (start end) | |
c567ac01 RS |
3797 | "Hide all body lines in the region, but not headings." |
3798 | (save-excursion | |
3799 | (save-restriction | |
3800 | (narrow-to-region start end) | |
3801 | (goto-char (point-min)) | |
3802 | (while (not (eobp)) | |
fd5359c6 MR |
3803 | (allout-flag-region (point) |
3804 | (progn (allout-pre-next-preface) (point)) ?\r) | |
c567ac01 RS |
3805 | (if (not (eobp)) |
3806 | (forward-char | |
3807 | (if (looking-at "[\n\r][\n\r]") | |
3808 | 2 1))))))) | |
c567ac01 | 3809 | |
fd5359c6 MR |
3810 | ;;;_ > allout-expose-topic (spec) |
3811 | (defun allout-expose-topic (spec) | |
19b84ba3 | 3812 | "Apply exposure specs to successive outline topic items. |
c567ac01 | 3813 | |
fd5359c6 MR |
3814 | Use the more convenient frontend, `allout-new-exposure', if you don't |
3815 | need evaluation of the arguments, or even better, the `allout-layout' | |
19b84ba3 RS |
3816 | variable-keyed mode-activation/auto-exposure feature of allout outline |
3817 | mode. See the respective documentation strings for more details. | |
c567ac01 RS |
3818 | |
3819 | Cursor is left at start position. | |
3820 | ||
19b84ba3 RS |
3821 | SPEC is either a number or a list. |
3822 | ||
3823 | Successive specs on a list are applied to successive sibling topics. | |
c567ac01 RS |
3824 | |
3825 | A simple spec \(either a number, one of a few symbols, or the null | |
19b84ba3 RS |
3826 | list) dictates the exposure for the corresponding topic. |
3827 | ||
3828 | Non-null lists recursively designate exposure specs for respective | |
3829 | subtopics of the current topic. | |
c567ac01 | 3830 | |
353e2ef2 | 3831 | The `:' repeat spec is used to specify exposure for any number of |
19b84ba3 | 3832 | successive siblings, up to the trailing ones for which there are |
353e2ef2 | 3833 | explicit specs following the `:'. |
c567ac01 RS |
3834 | |
3835 | Simple (numeric and null-list) specs are interpreted as follows: | |
3836 | ||
19b84ba3 RS |
3837 | Numbers indicate the relative depth to open the corresponding topic. |
3838 | - negative numbers force the topic to be closed before opening to the | |
3839 | absolute value of the number, so all siblings are open only to | |
3840 | that level. | |
3841 | - positive numbers open to the relative depth indicated by the | |
3842 | number, but do not force already opened subtopics to be closed. | |
3843 | - 0 means to close topic - hide all offspring. | |
353e2ef2 | 3844 | : - `repeat' |
c567ac01 | 3845 | apply prior element to all siblings at current level, *up to* |
353e2ef2 | 3846 | those siblings that would be covered by specs following the `:' |
c567ac01 RS |
3847 | on the list. Ie, apply to all topics at level but the last |
3848 | ones. \(Only first of multiple colons at same level is | |
3849 | respected - subsequent ones are discarded.) | |
19b84ba3 RS |
3850 | * - completely opens the topic, including bodies. |
3851 | + - shows all the sub headers, but not the bodies | |
3852 | - - exposes the body of the corresponding topic. | |
c567ac01 RS |
3853 | |
3854 | Examples: | |
fd5359c6 | 3855 | \(allout-expose-topic '(-1 : 0)) |
c567ac01 RS |
3856 | Close this and all following topics at current level, exposing |
3857 | only their immediate children, but close down the last topic | |
3858 | at this current level completely. | |
fd5359c6 | 3859 | \(allout-expose-topic '(-1 () : 1 0)) |
c567ac01 RS |
3860 | Close current topic so only the immediate subtopics are shown; |
3861 | show the children in the second to last topic, and completely | |
3862 | close the last one. | |
fd5359c6 | 3863 | \(allout-expose-topic '(-2 : -1 *)) |
c567ac01 RS |
3864 | Expose children and grandchildren of all topics at current |
3865 | level except the last two; expose children of the second to | |
3866 | last and completely open the last one." | |
3867 | ||
3868 | (interactive "xExposure spec: ") | |
19b84ba3 RS |
3869 | (if (not (listp spec)) |
3870 | nil | |
fd5359c6 | 3871 | (let ((depth (allout-depth)) |
19b84ba3 RS |
3872 | (max-pos 0) |
3873 | prev-elem curr-elem | |
3874 | stay done | |
3875 | snug-back | |
3876 | ) | |
3877 | (while spec | |
3878 | (setq prev-elem curr-elem | |
3879 | curr-elem (car spec) | |
3880 | spec (cdr spec)) | |
3881 | (cond ; Do current element: | |
3882 | ((null curr-elem) nil) | |
3883 | ((symbolp curr-elem) | |
fd5359c6 MR |
3884 | (cond ((eq curr-elem '*) (allout-show-current-subtree) |
3885 | (if (> allout-recent-end-of-subtree max-pos) | |
3886 | (setq max-pos allout-recent-end-of-subtree))) | |
3887 | ((eq curr-elem '+) (allout-show-current-branches) | |
3888 | (if (> allout-recent-end-of-subtree max-pos) | |
3889 | (setq max-pos allout-recent-end-of-subtree))) | |
3890 | ((eq curr-elem '-) (allout-show-current-entry)) | |
19b84ba3 RS |
3891 | ((eq curr-elem ':) |
3892 | (setq stay t) | |
353e2ef2 | 3893 | ;; Expand the `repeat' spec to an explicit version, |
19b84ba3 RS |
3894 | ;; w.r.t. remaining siblings: |
3895 | (let ((residue ; = # of sibs not covered by remaining spec | |
3896 | ;; Dang - could be nice to make use of the chart, sigh: | |
fd5359c6 | 3897 | (- (length (allout-chart-siblings)) |
19b84ba3 RS |
3898 | (length spec)))) |
3899 | (if (< 0 residue) | |
3900 | ;; Some residue - cover it with prev-elem: | |
3901 | (setq spec (append (make-list residue prev-elem) | |
3902 | spec))))))) | |
3903 | ((numberp curr-elem) | |
fd5359c6 MR |
3904 | (if (and (>= 0 curr-elem) (allout-visible-p)) |
3905 | (save-excursion (allout-hide-current-subtree t) | |
19b84ba3 RS |
3906 | (if (> 0 curr-elem) |
3907 | nil | |
fd5359c6 | 3908 | (if (> allout-recent-end-of-subtree max-pos) |
19b84ba3 | 3909 | (setq max-pos |
fd5359c6 | 3910 | allout-recent-end-of-subtree))))) |
19b84ba3 | 3911 | (if (> (abs curr-elem) 0) |
fd5359c6 MR |
3912 | (progn (allout-show-children (abs curr-elem)) |
3913 | (if (> allout-recent-end-of-subtree max-pos) | |
3914 | (setq max-pos allout-recent-end-of-subtree))))) | |
19b84ba3 | 3915 | ((listp curr-elem) |
fd5359c6 MR |
3916 | (if (allout-descend-to-depth (1+ depth)) |
3917 | (let ((got (allout-expose-topic curr-elem))) | |
19b84ba3 RS |
3918 | (if (and got (> got max-pos)) (setq max-pos got)))))) |
3919 | (cond (stay (setq stay nil)) | |
3920 | ((listp (car spec)) nil) | |
3921 | ((> max-pos (point)) | |
3922 | ;; Capitalize on max-pos state to get us nearer next sibling: | |
3923 | (progn (goto-char (min (point-max) max-pos)) | |
fd5359c6 MR |
3924 | (allout-next-heading))) |
3925 | ((allout-next-sibling depth)))) | |
19b84ba3 | 3926 | max-pos))) |
fd5359c6 MR |
3927 | ;;;_ > allout-old-expose-topic (spec &rest followers) |
3928 | (defun allout-old-expose-topic (spec &rest followers) | |
c567ac01 | 3929 | |
2265e017 | 3930 | "Deprecated. Use `allout-expose-topic' \(with different schema |
9179616f | 3931 | format) instead. |
19b84ba3 RS |
3932 | |
3933 | Dictate wholesale exposure scheme for current topic, according to SPEC. | |
c567ac01 RS |
3934 | |
3935 | SPEC is either a number or a list. Optional successive args | |
3936 | dictate exposure for subsequent siblings of current topic. | |
3937 | ||
3938 | A simple spec (either a number, a special symbol, or the null list) | |
3939 | dictates the overall exposure for a topic. Non null lists are | |
3940 | composite specs whose first element dictates the overall exposure for | |
3941 | a topic, with the subsequent elements in the list interpreted as specs | |
3942 | that dictate the exposure for the successive offspring of the topic. | |
3943 | ||
3944 | Simple (numeric and null-list) specs are interpreted as follows: | |
3945 | ||
3946 | - Numbers indicate the relative depth to open the corresponding topic: | |
3947 | - negative numbers force the topic to be close before opening to the | |
3948 | absolute value of the number. | |
3949 | - positive numbers just open to the relative depth indicated by the number. | |
3950 | - 0 just closes | |
353e2ef2 KH |
3951 | - `*' completely opens the topic, including bodies. |
3952 | - `+' shows all the sub headers, but not the bodies | |
3953 | - `-' exposes the body and immediate offspring of the corresponding topic. | |
c567ac01 RS |
3954 | |
3955 | If the spec is a list, the first element must be a number, which | |
3956 | dictates the exposure depth of the topic as a whole. Subsequent | |
3957 | elements of the list are nested SPECs, dictating the specific exposure | |
3958 | for the corresponding offspring of the topic. | |
3959 | ||
3960 | Optional FOLLOWER arguments dictate exposure for succeeding siblings." | |
3961 | ||
3962 | (interactive "xExposure spec: ") | |
fd5359c6 | 3963 | (let ((depth (allout-current-depth)) |
c567ac01 RS |
3964 | done |
3965 | max-pos) | |
3966 | (cond ((null spec) nil) | |
3967 | ((symbolp spec) | |
fd5359c6 MR |
3968 | (if (eq spec '*) (allout-show-current-subtree)) |
3969 | (if (eq spec '+) (allout-show-current-branches)) | |
3970 | (if (eq spec '-) (allout-show-current-entry))) | |
c567ac01 RS |
3971 | ((numberp spec) |
3972 | (if (>= 0 spec) | |
fd5359c6 | 3973 | (save-excursion (allout-hide-current-subtree t) |
c567ac01 RS |
3974 | (end-of-line) |
3975 | (if (or (not max-pos) | |
3976 | (> (point) max-pos)) | |
3977 | (setq max-pos (point))) | |
3978 | (if (> 0 spec) | |
3979 | (setq spec (* -1 spec))))) | |
3980 | (if (> spec 0) | |
fd5359c6 | 3981 | (allout-show-children spec))) |
c567ac01 | 3982 | ((listp spec) |
fd5359c6 | 3983 | ;(let ((got (allout-old-expose-topic (car spec)))) |
c567ac01 RS |
3984 | ; (if (and got (or (not max-pos) (> got max-pos))) |
3985 | ; (setq max-pos got))) | |
fd5359c6 | 3986 | (let ((new-depth (+ (allout-current-depth) 1)) |
c567ac01 | 3987 | got) |
fd5359c6 | 3988 | (setq max-pos (allout-old-expose-topic (car spec))) |
c567ac01 RS |
3989 | (setq spec (cdr spec)) |
3990 | (if (and spec | |
fd5359c6 MR |
3991 | (allout-descend-to-depth new-depth) |
3992 | (not (allout-hidden-p))) | |
3993 | (progn (setq got (apply 'allout-old-expose-topic spec)) | |
c567ac01 RS |
3994 | (if (and got (or (not max-pos) (> got max-pos))) |
3995 | (setq max-pos got))))))) | |
3996 | (while (and followers | |
3997 | (progn (if (and max-pos (< (point) max-pos)) | |
3998 | (progn (goto-char max-pos) | |
3999 | (setq max-pos nil))) | |
4000 | (end-of-line) | |
fd5359c6 MR |
4001 | (allout-next-sibling depth))) |
4002 | (allout-old-expose-topic (car followers)) | |
c567ac01 RS |
4003 | (setq followers (cdr followers))) |
4004 | max-pos)) | |
fd5359c6 MR |
4005 | ;;;_ > allout-new-exposure '() |
4006 | (defmacro allout-new-exposure (&rest spec) | |
4007 | "Literal frontend for `allout-expose-topic', doesn't evaluate arguments. | |
2265e017 MR |
4008 | Some arguments that would need to be quoted in `allout-expose-topic' |
4009 | need not be quoted in `allout-new-exposure'. | |
c567ac01 RS |
4010 | |
4011 | Cursor is left at start position. | |
4012 | ||
fd5359c6 | 4013 | Use this instead of obsolete `allout-exposure'. |
c567ac01 RS |
4014 | |
4015 | Examples: | |
fd5359c6 | 4016 | \(allout-exposure (-1 () () () 1) 0) |
c567ac01 RS |
4017 | Close current topic at current level so only the immediate |
4018 | subtopics are shown, except also show the children of the | |
4019 | third subtopic; and close the next topic at the current level. | |
fd5359c6 | 4020 | \(allout-exposure : -1 0) |
c567ac01 RS |
4021 | Close all topics at current level to expose only their |
4022 | immediate children, except for the last topic at the current | |
353e2ef2 | 4023 | level, in which even its immediate children are hidden. |
fd5359c6 | 4024 | \(allout-exposure -2 : -1 *) |
c567ac01 RS |
4025 | Expose children and grandchildren of first topic at current |
4026 | level, and expose children of subsequent topics at current | |
4027 | level *except* for the last, which should be opened completely." | |
4028 | (list 'save-excursion | |
fd5359c6 MR |
4029 | '(if (not (or (allout-goto-prefix) |
4030 | (allout-next-heading))) | |
4031 | (error "allout-new-exposure: Can't find any outline topics")) | |
4032 | (list 'allout-expose-topic (list 'quote spec)))) | |
4033 | ;;;_ > allout-exposure '() | |
4034 | (defmacro allout-exposure (&rest spec) | |
4035 | "Being deprecated - use more recent `allout-new-exposure' instead. | |
4036 | ||
4037 | Literal frontend for `allout-old-expose-topic', doesn't evaluate arguments | |
c567ac01 RS |
4038 | and retains start position." |
4039 | (list 'save-excursion | |
fd5359c6 MR |
4040 | '(if (not (or (allout-goto-prefix) |
4041 | (allout-next-heading))) | |
6a05d05f | 4042 | (error "Can't find any outline topics")) |
fd5359c6 | 4043 | (cons 'allout-old-expose-topic |
9179616f | 4044 | (mapcar (function (lambda (x) (list 'quote x))) spec)))) |
c567ac01 | 4045 | |
9179616f | 4046 | ;;;_ #7 Systematic outline presentation - copying, printing, flattening |
19b84ba3 | 4047 | |
9179616f DL |
4048 | ;;;_ - Mapping and processing of topics |
4049 | ;;;_ ( See also Subtree Charting, in Navigation code.) | |
fd5359c6 MR |
4050 | ;;;_ > allout-stringify-flat-index (flat-index) |
4051 | (defun allout-stringify-flat-index (flat-index &optional context) | |
9179616f DL |
4052 | "Convert list representing section/subsection/... to document string. |
4053 | ||
4054 | Optional arg CONTEXT indicates interior levels to include." | |
4055 | (let ((delim ".") | |
4056 | result | |
4057 | numstr | |
4058 | (context-depth (or (and context 2) 1))) | |
4059 | ;; Take care of the explicit context: | |
4060 | (while (> context-depth 0) | |
4061 | (setq numstr (int-to-string (car flat-index)) | |
4062 | flat-index (cdr flat-index) | |
4063 | result (if flat-index | |
4064 | (cons delim (cons numstr result)) | |
4065 | (cons numstr result)) | |
4066 | context-depth (if flat-index (1- context-depth) 0))) | |
4067 | (setq delim " ") | |
4068 | ;; Take care of the indentation: | |
4069 | (if flat-index | |
4070 | (progn | |
4071 | (while flat-index | |
4072 | (setq result | |
4073 | (cons delim | |
4074 | (cons (make-string | |
4075 | (1+ (truncate (if (zerop (car flat-index)) | |
4076 | 1 | |
4077 | (log10 (car flat-index))))) | |
4078 | ? ) | |
4079 | result))) | |
4080 | (setq flat-index (cdr flat-index))) | |
4081 | ;; Dispose of single extra delim: | |
4082 | (setq result (cdr result)))) | |
4083 | (apply 'concat result))) | |
fd5359c6 MR |
4084 | ;;;_ > allout-stringify-flat-index-plain (flat-index) |
4085 | (defun allout-stringify-flat-index-plain (flat-index) | |
9179616f DL |
4086 | "Convert list representing section/subsection/... to document string." |
4087 | (let ((delim ".") | |
4088 | result) | |
4089 | (while flat-index | |
4090 | (setq result (cons (int-to-string (car flat-index)) | |
4091 | (if result | |
4092 | (cons delim result)))) | |
4093 | (setq flat-index (cdr flat-index))) | |
4094 | (apply 'concat result))) | |
fd5359c6 MR |
4095 | ;;;_ > allout-stringify-flat-index-indented (flat-index) |
4096 | (defun allout-stringify-flat-index-indented (flat-index) | |
9179616f DL |
4097 | "Convert list representing section/subsection/... to document string." |
4098 | (let ((delim ".") | |
4099 | result | |
4100 | numstr) | |
4101 | ;; Take care of the explicit context: | |
4102 | (setq numstr (int-to-string (car flat-index)) | |
4103 | flat-index (cdr flat-index) | |
4104 | result (if flat-index | |
4105 | (cons delim (cons numstr result)) | |
4106 | (cons numstr result))) | |
4107 | (setq delim " ") | |
4108 | ;; Take care of the indentation: | |
4109 | (if flat-index | |
4110 | (progn | |
4111 | (while flat-index | |
4112 | (setq result | |
4113 | (cons delim | |
4114 | (cons (make-string | |
4115 | (1+ (truncate (if (zerop (car flat-index)) | |
4116 | 1 | |
4117 | (log10 (car flat-index))))) | |
4118 | ? ) | |
4119 | result))) | |
4120 | (setq flat-index (cdr flat-index))) | |
4121 | ;; Dispose of single extra delim: | |
4122 | (setq result (cdr result)))) | |
4123 | (apply 'concat result))) | |
fd5359c6 MR |
4124 | ;;;_ > allout-listify-exposed (&optional start end format) |
4125 | (defun allout-listify-exposed (&optional start end format) | |
19b84ba3 | 4126 | |
9179616f | 4127 | "Produce a list representing exposed topics in current region. |
c567ac01 | 4128 | |
fd5359c6 | 4129 | This list can then be used by `allout-process-exposed' to manipulate |
9179616f | 4130 | the subject region. |
353e2ef2 | 4131 | |
9179616f | 4132 | Optional START and END indicate bounds of region. |
19b84ba3 | 4133 | |
9179616f DL |
4134 | optional arg, FORMAT, designates an alternate presentation form for |
4135 | the prefix: | |
c567ac01 | 4136 | |
9179616f DL |
4137 | list - Present prefix as numeric section.subsection..., starting with |
4138 | section indicated by the list, innermost nesting first. | |
4139 | `indent' \(symbol) - Convert header prefixes to all white space, | |
4140 | except for distinctive bullets. | |
c567ac01 | 4141 | |
9179616f DL |
4142 | The elements of the list produced are lists that represents a topic |
4143 | header and body. The elements of that list are: | |
c567ac01 | 4144 | |
9179616f DL |
4145 | - a number representing the depth of the topic, |
4146 | - a string representing the header-prefix, including trailing whitespace and | |
4147 | bullet. | |
4148 | - a string representing the bullet character, | |
4149 | - and a series of strings, each containing one line of the exposed | |
4150 | portion of the topic entry." | |
c567ac01 | 4151 | |
9179616f DL |
4152 | (interactive "r") |
4153 | (save-excursion | |
4154 | (let* | |
4155 | ;; state vars: | |
4156 | (strings prefix pad result depth new-depth out gone-out bullet beg | |
4157 | next done) | |
c567ac01 | 4158 | |
9179616f DL |
4159 | (goto-char start) |
4160 | (beginning-of-line) | |
4161 | ;; Goto initial topic, and register preceeding stuff, if any: | |
fd5359c6 | 4162 | (if (> (allout-goto-prefix) start) |
9179616f DL |
4163 | ;; First topic follows beginning point - register preliminary stuff: |
4164 | (setq result (list (list 0 "" nil | |
4165 | (buffer-substring start (1- (point))))))) | |
4166 | (while (and (not done) | |
4167 | (not (eobp)) ; Loop until we've covered the region. | |
4168 | (not (> (point) end))) | |
fd5359c6 MR |
4169 | (setq depth (allout-recent-depth) ; Current topics depth, |
4170 | bullet (allout-recent-bullet) ; ... bullet, | |
4171 | prefix (allout-recent-prefix) | |
4172 | beg (progn (allout-end-of-prefix t) (point))) ; and beginning. | |
9179616f | 4173 | (setq done ; The boundary for the current topic: |
fd5359c6 MR |
4174 | (not (allout-next-visible-heading 1))) |
4175 | (setq new-depth (allout-recent-depth)) | |
9179616f DL |
4176 | (setq gone-out out |
4177 | out (< new-depth depth)) | |
4178 | (beginning-of-line) | |
4179 | (setq next (point)) | |
4180 | (goto-char beg) | |
4181 | (setq strings nil) | |
4182 | (while (> next (point)) ; Get all the exposed text in | |
4183 | (setq strings | |
4184 | (cons (buffer-substring | |
4185 | beg | |
4186 | ;To hidden text or end of line: | |
4187 | (progn | |
4188 | (search-forward "\r" | |
4189 | (save-excursion (end-of-line) | |
4190 | (point)) | |
4191 | 1) | |
4192 | (if (= (preceding-char) ?\r) | |
4193 | (1- (point)) | |
4194 | (point)))) | |
4195 | strings)) | |
4196 | (if (< (point) next) ; Resume from after hid text, if any. | |
4197 | (forward-line 1)) | |
4198 | (setq beg (point))) | |
4199 | ;; Accumulate list for this topic: | |
4200 | (setq strings (nreverse strings)) | |
4201 | (setq result | |
4202 | (cons | |
4203 | (if format | |
4204 | (let ((special (if (string-match | |
4205 | (regexp-quote bullet) | |
fd5359c6 | 4206 | allout-distinctive-bullets-string) |
9179616f DL |
4207 | bullet))) |
4208 | (cond ((listp format) | |
4209 | (list depth | |
fd5359c6 MR |
4210 | (if allout-abbreviate-flattened-numbering |
4211 | (allout-stringify-flat-index format | |
9179616f | 4212 | gone-out) |
fd5359c6 | 4213 | (allout-stringify-flat-index-plain |
9179616f DL |
4214 | format)) |
4215 | strings | |
4216 | special)) | |
4217 | ((eq format 'indent) | |
4218 | (if special | |
4219 | (list depth | |
4220 | (concat (make-string (1+ depth) ? ) | |
4221 | (substring prefix -1)) | |
4222 | strings) | |
4223 | (list depth | |
4224 | (make-string depth ? ) | |
4225 | strings))) | |
fd5359c6 | 4226 | (t (error "allout-listify-exposed: %s %s" |
9179616f DL |
4227 | "invalid format" format)))) |
4228 | (list depth prefix strings)) | |
4229 | result)) | |
4230 | ;; Reasses format, if any: | |
4231 | (if (and format (listp format)) | |
4232 | (cond ((= new-depth depth) | |
4233 | (setq format (cons (1+ (car format)) | |
4234 | (cdr format)))) | |
4235 | ((> new-depth depth) ; descending - assume by 1: | |
4236 | (setq format (cons 1 format))) | |
4237 | (t | |
4238 | ; Pop the residue: | |
4239 | (while (< new-depth depth) | |
4240 | (setq format (cdr format)) | |
4241 | (setq depth (1- depth))) | |
4242 | ; And increment the current one: | |
4243 | (setq format | |
4244 | (cons (1+ (or (car format) | |
4245 | -1)) | |
4246 | (cdr format))))))) | |
4247 | ;; Put the list with first at front, to last at back: | |
4248 | (nreverse result)))) | |
fd5359c6 | 4249 | ;;;_ > allout-process-exposed (&optional func from to frombuf |
9179616f | 4250 | ;;; tobuf format) |
fd5359c6 | 4251 | (defun allout-process-exposed (&optional func from to frombuf tobuf |
9179616f DL |
4252 | format &optional start-num) |
4253 | "Map function on exposed parts of current topic; results to another buffer. | |
353e2ef2 | 4254 | |
9179616f | 4255 | All args are options; default values itemized below. |
1977b8f6 | 4256 | |
9179616f DL |
4257 | Apply FUNCTION to exposed portions FROM position TO position in buffer |
4258 | FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an | |
4259 | alternate presentation form: | |
c567ac01 | 4260 | |
9179616f DL |
4261 | `flat' - Present prefix as numeric section.subsection..., starting with |
4262 | section indicated by the start-num, innermost nesting first. | |
4263 | X`flat-indented' - Prefix is like `flat' for first topic at each | |
4264 | X level, but subsequent topics have only leaf topic | |
4265 | X number, padded with blanks to line up with first. | |
4266 | `indent' \(symbol) - Convert header prefixes to all white space, | |
4267 | except for distinctive bullets. | |
c567ac01 | 4268 | |
9179616f | 4269 | Defaults: |
fd5359c6 | 4270 | FUNCTION: `allout-insert-listified' |
9179616f DL |
4271 | FROM: region start, if region active, else start of buffer |
4272 | TO: region end, if region active, else end of buffer | |
4273 | FROMBUF: current buffer | |
4274 | TOBUF: buffer name derived: \"*current-buffer-name exposed*\" | |
4275 | FORMAT: nil" | |
4276 | ||
4277 | ; Resolve arguments, | |
4278 | ; defaulting if necessary: | |
fd5359c6 | 4279 | (if (not func) (setq func 'allout-insert-listified)) |
9179616f DL |
4280 | (if (not (and from to)) |
4281 | (if (my-region-active-p) | |
4282 | (setq from (region-beginning) to (region-end)) | |
4283 | (setq from (point-min) to (point-max)))) | |
4284 | (if frombuf | |
4285 | (if (not (bufferp frombuf)) | |
4286 | ;; Specified but not a buffer - get it: | |
4287 | (let ((got (get-buffer frombuf))) | |
4288 | (if (not got) | |
fd5359c6 | 4289 | (error (concat "allout-process-exposed: source buffer " |
9179616f DL |
4290 | frombuf |
4291 | " not found.")) | |
4292 | (setq frombuf got)))) | |
4293 | ;; not specified - default it: | |
4294 | (setq frombuf (current-buffer))) | |
4295 | (if tobuf | |
4296 | (if (not (bufferp tobuf)) | |
4297 | (setq tobuf (get-buffer-create tobuf))) | |
4298 | ;; not specified - default it: | |
4299 | (setq tobuf (concat "*" (buffer-name frombuf) " exposed*"))) | |
4300 | (if (listp format) | |
4301 | (nreverse format)) | |
4302 | ||
4303 | (let* ((listified | |
4304 | (progn (set-buffer frombuf) | |
fd5359c6 | 4305 | (allout-listify-exposed from to format)))) |
9179616f DL |
4306 | (set-buffer tobuf) |
4307 | (mapcar func listified) | |
4308 | (pop-to-buffer tobuf))) | |
4309 | ||
4310 | ;;;_ - Copy exposed | |
fd5359c6 MR |
4311 | ;;;_ > allout-insert-listified (listified) |
4312 | (defun allout-insert-listified (listified) | |
9179616f DL |
4313 | "Insert contents of listified outline portion in current buffer. |
4314 | ||
4315 | Listified is a list representing each topic header and body: | |
4316 | ||
4317 | \`(depth prefix text)' | |
4318 | ||
4319 | or \`(depth prefix text bullet-plus)' | |
4320 | ||
4321 | If `bullet-plus' is specified, it is inserted just after the entire prefix." | |
4322 | (setq listified (cdr listified)) | |
4323 | (let ((prefix (prog1 | |
4324 | (car listified) | |
4325 | (setq listified (cdr listified)))) | |
4326 | (text (prog1 | |
4327 | (car listified) | |
4328 | (setq listified (cdr listified)))) | |
4329 | (bullet-plus (car listified))) | |
eac9cf5f PJ |
4330 | (insert prefix) |
4331 | (if bullet-plus (insert (concat " " bullet-plus))) | |
9179616f | 4332 | (while text |
eac9cf5f | 4333 | (insert (car text)) |
9179616f | 4334 | (if (setq text (cdr text)) |
eac9cf5f PJ |
4335 | (insert "\n"))) |
4336 | (insert "\n"))) | |
fd5359c6 MR |
4337 | ;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format) |
4338 | (defun allout-copy-exposed-to-buffer (&optional arg tobuf format) | |
9179616f DL |
4339 | "Duplicate exposed portions of current outline to another buffer. |
4340 | ||
4341 | Other buffer has current buffers name with \" exposed\" appended to it. | |
4342 | ||
4343 | With repeat count, copy the exposed parts of only the current topic. | |
4344 | ||
4345 | Optional second arg TOBUF is target buffer name. | |
4346 | ||
4347 | Optional third arg FORMAT, if non-nil, symbolically designates an | |
4348 | alternate presentation format for the outline: | |
4349 | ||
4350 | `flat' - Convert topic header prefixes to numeric | |
4351 | section.subsection... identifiers. | |
4352 | `indent' - Convert header prefixes to all white space, except for | |
4353 | distinctive bullets. | |
4354 | `indent-flat' - The best of both - only the first of each level has | |
4355 | the full path, the rest have only the section number | |
4356 | of the leaf, preceded by the right amount of indentation." | |
c567ac01 RS |
4357 | |
4358 | (interactive "P") | |
4359 | (if (not tobuf) | |
4360 | (setq tobuf (get-buffer-create (concat "*" (buffer-name) " exposed*")))) | |
4361 | (let* ((start-pt (point)) | |
fd5359c6 MR |
4362 | (beg (if arg (allout-back-to-current-heading) (point-min))) |
4363 | (end (if arg (allout-end-of-current-subtree) (point-max))) | |
9179616f DL |
4364 | (buf (current-buffer)) |
4365 | (start-list ())) | |
4366 | (if (eq format 'flat) | |
4367 | (setq format (if arg (save-excursion | |
4368 | (goto-char beg) | |
fd5359c6 | 4369 | (allout-topic-flat-index)) |
9179616f | 4370 | '(1)))) |
c567ac01 | 4371 | (save-excursion (set-buffer tobuf)(erase-buffer)) |
fd5359c6 | 4372 | (allout-process-exposed 'allout-insert-listified |
c567ac01 RS |
4373 | beg |
4374 | end | |
4375 | (current-buffer) | |
9179616f DL |
4376 | tobuf |
4377 | format start-list) | |
c567ac01 RS |
4378 | (goto-char (point-min)) |
4379 | (pop-to-buffer buf) | |
4380 | (goto-char start-pt))) | |
fd5359c6 MR |
4381 | ;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf) |
4382 | (defun allout-flatten-exposed-to-buffer (&optional arg tobuf) | |
9179616f DL |
4383 | "Present numeric outline of outline's exposed portions in another buffer. |
4384 | ||
4385 | The resulting outline is not compatable with outline mode - use | |
fd5359c6 | 4386 | `allout-copy-exposed-to-buffer' if you want that. |
9179616f | 4387 | |
fd5359c6 | 4388 | Use `allout-indented-exposed-to-buffer' for indented presentation. |
9179616f DL |
4389 | |
4390 | With repeat count, copy the exposed portions of only current topic. | |
4391 | ||
4392 | Other buffer has current buffers name with \" exposed\" appended to | |
4393 | it, unless optional second arg TOBUF is specified, in which case it is | |
4394 | used verbatim." | |
4395 | (interactive "P") | |
fd5359c6 MR |
4396 | (allout-copy-exposed-to-buffer arg tobuf 'flat)) |
4397 | ;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf) | |
4398 | (defun allout-indented-exposed-to-buffer (&optional arg tobuf) | |
9179616f DL |
4399 | "Present indented outline of outline's exposed portions in another buffer. |
4400 | ||
4401 | The resulting outline is not compatable with outline mode - use | |
fd5359c6 | 4402 | `allout-copy-exposed-to-buffer' if you want that. |
9179616f | 4403 | |
fd5359c6 | 4404 | Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation. |
9179616f DL |
4405 | |
4406 | With repeat count, copy the exposed portions of only current topic. | |
4407 | ||
4408 | Other buffer has current buffers name with \" exposed\" appended to | |
4409 | it, unless optional second arg TOBUF is specified, in which case it is | |
4410 | used verbatim." | |
4411 | (interactive "P") | |
fd5359c6 | 4412 | (allout-copy-exposed-to-buffer arg tobuf 'indent)) |
c567ac01 RS |
4413 | |
4414 | ;;;_ - LaTeX formatting | |
fd5359c6 MR |
4415 | ;;;_ > allout-latex-verb-quote (str &optional flow) |
4416 | (defun allout-latex-verb-quote (str &optional flow) | |
19b84ba3 RS |
4417 | "Return copy of STRING for literal reproduction across latex processing. |
4418 | Expresses the original characters \(including carriage returns) of the | |
4419 | string across latex processing." | |
9179616f DL |
4420 | (mapconcat (function |
4421 | (lambda (char) | |
c567ac01 RS |
4422 | (cond ((memq char '(?\\ ?$ ?% ?# ?& ?{ ?} ?_ ?^ ?- ?*)) |
4423 | (concat "\\char" (number-to-string char) "{}")) | |
4424 | ((= char ?\n) "\\\\") | |
9179616f | 4425 | (t (char-to-string char))))) |
c567ac01 RS |
4426 | str |
4427 | "")) | |
fd5359c6 MR |
4428 | ;;;_ > allout-latex-verbatim-quote-curr-line () |
4429 | (defun allout-latex-verbatim-quote-curr-line () | |
9179616f | 4430 | "Express line for exact \(literal) representation across latex processing. |
19b84ba3 RS |
4431 | |
4432 | Adjust line contents so it is unaltered \(from the original line) | |
353e2ef2 | 4433 | across latex processing, within the context of a `verbatim' |
c567ac01 RS |
4434 | environment. Leaves point at the end of the line." |
4435 | (beginning-of-line) | |
4436 | (let ((beg (point)) | |
4437 | (end (progn (end-of-line)(point)))) | |
4438 | (goto-char beg) | |
4439 | (while (re-search-forward "\\\\" | |
4440 | ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#" | |
4441 | end ; bounded by end-of-line | |
4442 | 1) ; no matches, move to end & return nil | |
4443 | (goto-char (match-beginning 0)) | |
eac9cf5f | 4444 | (insert "\\") |
c567ac01 RS |
4445 | (setq end (1+ end)) |
4446 | (goto-char (1+ (match-end 0)))))) | |
fd5359c6 MR |
4447 | ;;;_ > allout-insert-latex-header (buf) |
4448 | (defun allout-insert-latex-header (buf) | |
c567ac01 RS |
4449 | "Insert initial latex commands at point in BUFFER." |
4450 | ;; Much of this is being derived from the stuff in appendix of E in | |
4451 | ;; the TeXBook, pg 421. | |
4452 | (set-buffer buf) | |
4453 | (let ((doc-style (format "\n\\documentstyle{%s}\n" | |
4454 | "report")) | |
fd5359c6 | 4455 | (page-numbering (if allout-number-pages |
c567ac01 RS |
4456 | "\\pagestyle{empty}\n" |
4457 | "")) | |
4458 | (linesdef (concat "\\def\\beginlines{" | |
4459 | "\\par\\begingroup\\nobreak\\medskip" | |
4460 | "\\parindent=0pt\n" | |
4461 | " \\kern1pt\\nobreak \\obeylines \\obeyspaces " | |
4462 | "\\everypar{\\strut}}\n" | |
4463 | "\\def\\endlines{" | |
4464 | "\\kern1pt\\endgroup\\medbreak\\noindent}\n")) | |
4465 | (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n" | |
fd5359c6 | 4466 | allout-title-style)) |
c567ac01 | 4467 | (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n" |
fd5359c6 | 4468 | allout-label-style)) |
c567ac01 | 4469 | (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n" |
fd5359c6 | 4470 | allout-head-line-style)) |
c567ac01 | 4471 | (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n" |
fd5359c6 | 4472 | allout-body-line-style)) |
c567ac01 RS |
4473 | (setlength (format "%s%s%s%s" |
4474 | "\\newlength{\\stepsize}\n" | |
4475 | "\\setlength{\\stepsize}{" | |
fd5359c6 | 4476 | allout-indent |
c567ac01 RS |
4477 | "}\n")) |
4478 | (oneheadline (format "%s%s%s%s%s%s%s" | |
4479 | "\\newcommand{\\OneHeadLine}[3]{%\n" | |
4480 | "\\noindent%\n" | |
4481 | "\\hspace*{#2\\stepsize}%\n" | |
4482 | "\\labelcmd{#1}\\hspace*{.2cm}" | |
4483 | "\\headlinecmd{#3}\\\\[" | |
fd5359c6 | 4484 | allout-line-skip |
c567ac01 RS |
4485 | "]\n}\n")) |
4486 | (onebodyline (format "%s%s%s%s%s%s" | |
4487 | "\\newcommand{\\OneBodyLine}[2]{%\n" | |
4488 | "\\noindent%\n" | |
4489 | "\\hspace*{#1\\stepsize}%\n" | |
4490 | "\\bodylinecmd{#2}\\\\[" | |
fd5359c6 | 4491 | allout-line-skip |
c567ac01 RS |
4492 | "]\n}\n")) |
4493 | (begindoc "\\begin{document}\n\\begin{center}\n") | |
4494 | (title (format "%s%s%s%s" | |
4495 | "\\titlecmd{" | |
fd5359c6 | 4496 | (allout-latex-verb-quote (if allout-title |
c567ac01 | 4497 | (condition-case err |
fd5359c6 | 4498 | (eval allout-title) |
9179616f | 4499 | ('error "<unnamed buffer>")) |
c567ac01 RS |
4500 | "Unnamed Outline")) |
4501 | "}\n" | |
4502 | "\\end{center}\n\n")) | |
4503 | (hsize "\\hsize = 7.5 true in\n") | |
4504 | (hoffset "\\hoffset = -1.5 true in\n") | |
4505 | (vspace "\\vspace{.1cm}\n\n")) | |
4506 | (insert (concat doc-style | |
4507 | page-numbering | |
4508 | titlecmd | |
4509 | labelcmd | |
4510 | headlinecmd | |
4511 | bodylinecmd | |
4512 | setlength | |
4513 | oneheadline | |
4514 | onebodyline | |
4515 | begindoc | |
4516 | title | |
4517 | hsize | |
4518 | hoffset | |
4519 | vspace) | |
4520 | ))) | |
fd5359c6 MR |
4521 | ;;;_ > allout-insert-latex-trailer (buf) |
4522 | (defun allout-insert-latex-trailer (buf) | |
c567ac01 RS |
4523 | "Insert concluding latex commands at point in BUFFER." |
4524 | (set-buffer buf) | |
4525 | (insert "\n\\end{document}\n")) | |
fd5359c6 MR |
4526 | ;;;_ > allout-latexify-one-item (depth prefix bullet text) |
4527 | (defun allout-latexify-one-item (depth prefix bullet text) | |
19b84ba3 RS |
4528 | "Insert LaTeX commands for formatting one outline item. |
4529 | ||
9179616f | 4530 | Args are the topics numeric DEPTH, the header PREFIX lead string, the |
19b84ba3 | 4531 | BULLET string, and a list of TEXT strings for the body." |
c567ac01 RS |
4532 | (let* ((head-line (if text (car text))) |
4533 | (body-lines (cdr text)) | |
4534 | (curr-line) | |
4535 | body-content bop) | |
4536 | ; Do the head line: | |
eac9cf5f | 4537 | (insert (concat "\\OneHeadLine{\\verb\1 " |
fd5359c6 | 4538 | (allout-latex-verb-quote bullet) |
eac9cf5f PJ |
4539 | "\1}{" |
4540 | depth | |
4541 | "}{\\verb\1 " | |
4542 | (if head-line | |
fd5359c6 | 4543 | (allout-latex-verb-quote head-line) |
eac9cf5f PJ |
4544 | "") |
4545 | "\1}\n")) | |
c567ac01 RS |
4546 | (if (not body-lines) |
4547 | nil | |
eac9cf5f PJ |
4548 | ;;(insert "\\beginlines\n") |
4549 | (insert "\\begin{verbatim}\n") | |
c567ac01 RS |
4550 | (while body-lines |
4551 | (setq curr-line (car body-lines)) | |
4552 | (if (and (not body-content) | |
4553 | (not (string-match "^\\s-*$" curr-line))) | |
4554 | (setq body-content t)) | |
4555 | ; Mangle any occurrences of | |
4556 | ; "\end{verbatim}" in text, | |
4557 | ; it's special: | |
4558 | (if (and body-content | |
4559 | (setq bop (string-match "\\end{verbatim}" curr-line))) | |
4560 | (setq curr-line (concat (substring curr-line 0 bop) | |
4561 | ">" | |
4562 | (substring curr-line bop)))) | |
eac9cf5f PJ |
4563 | ;;(insert "|" (car body-lines) "|") |
4564 | (insert curr-line) | |
fd5359c6 | 4565 | (allout-latex-verbatim-quote-curr-line) |
eac9cf5f | 4566 | (insert "\n") |
c567ac01 RS |
4567 | (setq body-lines (cdr body-lines))) |
4568 | (if body-content | |
4569 | (setq body-content nil) | |
4570 | (forward-char -1) | |
eac9cf5f | 4571 | (insert "\\ ") |
c567ac01 | 4572 | (forward-char 1)) |
eac9cf5f PJ |
4573 | ;;(insert "\\endlines\n") |
4574 | (insert "\\end{verbatim}\n") | |
c567ac01 | 4575 | ))) |
fd5359c6 MR |
4576 | ;;;_ > allout-latexify-exposed (arg &optional tobuf) |
4577 | (defun allout-latexify-exposed (arg &optional tobuf) | |
9179616f | 4578 | "Format current topics exposed portions to TOBUF for latex processing. |
19b84ba3 RS |
4579 | TOBUF defaults to a buffer named the same as the current buffer, but |
4580 | with \"*\" prepended and \" latex-formed*\" appended. | |
c567ac01 RS |
4581 | |
4582 | With repeat count, copy the exposed portions of entire buffer." | |
4583 | ||
4584 | (interactive "P") | |
4585 | (if (not tobuf) | |
4586 | (setq tobuf | |
4587 | (get-buffer-create (concat "*" (buffer-name) " latexified*")))) | |
4588 | (let* ((start-pt (point)) | |
fd5359c6 MR |
4589 | (beg (if arg (point-min) (allout-back-to-current-heading))) |
4590 | (end (if arg (point-max) (allout-end-of-current-subtree))) | |
c567ac01 RS |
4591 | (buf (current-buffer))) |
4592 | (set-buffer tobuf) | |
1977b8f6 | 4593 | (erase-buffer) |
fd5359c6 | 4594 | (allout-insert-latex-header tobuf) |
c567ac01 | 4595 | (goto-char (point-max)) |
fd5359c6 | 4596 | (allout-process-exposed 'allout-latexify-one-item |
c567ac01 RS |
4597 | beg |
4598 | end | |
4599 | buf | |
4600 | tobuf) | |
4601 | (goto-char (point-max)) | |
fd5359c6 | 4602 | (allout-insert-latex-trailer tobuf) |
1977b8f6 | 4603 | (goto-char (point-min)) |
c567ac01 RS |
4604 | (pop-to-buffer buf) |
4605 | (goto-char start-pt))) | |
4606 | ||
9179616f | 4607 | ;;;_ #8 miscellaneous |
fd5359c6 MR |
4608 | ;;;_ > allout-mark-topic () |
4609 | (defun allout-mark-topic () | |
c567ac01 RS |
4610 | "Put the region around topic currently containing point." |
4611 | (interactive) | |
4612 | (beginning-of-line) | |
fd5359c6 | 4613 | (allout-goto-prefix) |
c567ac01 | 4614 | (push-mark (point)) |
fd5359c6 | 4615 | (allout-end-of-current-subtree) |
c567ac01 RS |
4616 | (exchange-point-and-mark)) |
4617 | ;;;_ > outlineify-sticky () | |
19b84ba3 RS |
4618 | ;; outlinify-sticky is correct spelling; provide this alias for sticklers: |
4619 | (defalias 'outlinify-sticky 'outlineify-sticky) | |
c567ac01 | 4620 | (defun outlineify-sticky (&optional arg) |
a0776d6b | 4621 | "Activate outline mode and establish file var so it is started subsequently. |
1977b8f6 | 4622 | |
fd5359c6 | 4623 | See doc-string for `allout-layout' and `allout-init' for details on |
19b84ba3 RS |
4624 | setup for auto-startup." |
4625 | ||
4626 | (interactive "P") | |
4627 | ||
fd5359c6 | 4628 | (allout-mode t) |
19b84ba3 RS |
4629 | |
4630 | (save-excursion | |
4631 | (goto-char (point-min)) | |
fd5359c6 | 4632 | (if (looking-at allout-regexp) |
19b84ba3 | 4633 | t |
fd5359c6 | 4634 | (allout-open-topic 2) |
eac9cf5f | 4635 | (insert (concat "Dummy outline topic header - see" |
fd5359c6 | 4636 | "`allout-mode' docstring: `^Hm'.")) |
9179616f | 4637 | (forward-line 1) |
1977b8f6 | 4638 | (goto-char (point-max)) |
9179616f | 4639 | (open-line 1) |
fd5359c6 | 4640 | (allout-open-topic 0) |
eac9cf5f | 4641 | (insert "Local emacs vars.\n") |
fd5359c6 MR |
4642 | (allout-open-topic 1) |
4643 | (insert "(`allout-layout' is for allout.el allout-mode)\n") | |
4644 | (allout-open-topic 0) | |
eac9cf5f | 4645 | (insert "Local variables:\n") |
fd5359c6 MR |
4646 | (allout-open-topic 0) |
4647 | (insert (format "allout-layout: %s\n" | |
4648 | (or allout-layout | |
9179616f | 4649 | '(-1 : 0)))) |
fd5359c6 | 4650 | (allout-open-topic 0) |
eac9cf5f | 4651 | (insert "End:\n")))) |
c567ac01 | 4652 | ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting) |
1977b8f6 | 4653 | (defun solicit-char-in-string (prompt string &optional do-defaulting) |
c567ac01 | 4654 | "Solicit (with first arg PROMPT) choice of a character from string STRING. |
1977b8f6 | 4655 | |
c567ac01 | 4656 | Optional arg DO-DEFAULTING indicates to accept empty input (CR)." |
1977b8f6 RS |
4657 | |
4658 | (let ((new-prompt prompt) | |
4659 | got) | |
4660 | ||
4661 | (while (not got) | |
4662 | (message "%s" new-prompt) | |
4663 | ||
4664 | ;; We do our own reading here, so we can circumvent, eg, special | |
9179616f | 4665 | ;; treatment for `?' character. (Oughta use minibuffer keymap instead.) |
1977b8f6 | 4666 | (setq got |
c567ac01 | 4667 | (char-to-string (let ((cursor-in-echo-area nil)) (read-char)))) |
1977b8f6 | 4668 | |
9179616f DL |
4669 | (setq got |
4670 | (cond ((string-match (regexp-quote got) string) got) | |
4671 | ((and do-defaulting (string= got "\r")) | |
4672 | ;; Return empty string to default: | |
4673 | "") | |
4674 | ((string= got "\C-g") (signal 'quit nil)) | |
4675 | (t | |
4676 | (setq new-prompt (concat prompt | |
4677 | got | |
4678 | " ...pick from: " | |
4679 | string | |
4680 | "")) | |
4681 | nil)))) | |
4682 | ;; got something out of loop - return it: | |
4683 | got) | |
1977b8f6 | 4684 | ) |
c567ac01 RS |
4685 | ;;;_ > regexp-sans-escapes (string) |
4686 | (defun regexp-sans-escapes (regexp &optional successive-backslashes) | |
4687 | "Return a copy of REGEXP with all character escapes stripped out. | |
19b84ba3 | 4688 | |
c567ac01 RS |
4689 | Representations of actual backslashes - '\\\\\\\\' - are left as a |
4690 | single backslash. | |
4691 | ||
4692 | Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion." | |
4693 | ||
4694 | (if (string= regexp "") | |
4695 | "" | |
4696 | ;; Set successive-backslashes to number if current char is | |
4697 | ;; backslash, or else to nil: | |
4698 | (setq successive-backslashes | |
4699 | (if (= (aref regexp 0) ?\\) | |
4700 | (if successive-backslashes (1+ successive-backslashes) 1) | |
4701 | nil)) | |
4702 | (if (or (not successive-backslashes) (= 2 successive-backslashes)) | |
4703 | ;; Include first char: | |
4704 | (concat (substring regexp 0 1) | |
4705 | (regexp-sans-escapes (substring regexp 1))) | |
4706 | ;; Exclude first char, but maintain count: | |
4707 | (regexp-sans-escapes (substring regexp 1) successive-backslashes)))) | |
9179616f DL |
4708 | ;;;_ > my-region-active-p () |
4709 | (defmacro my-region-active-p () | |
4710 | (if (fboundp 'region-active-p) | |
4711 | '(region-active-p) | |
4712 | 'mark-active)) | |
19b84ba3 | 4713 | ;;;_ - add-hook definition for divergent emacsen |
c567ac01 RS |
4714 | ;;;_ > add-hook (hook function &optional append) |
4715 | (if (not (fboundp 'add-hook)) | |
4716 | (defun add-hook (hook function &optional append) | |
19b84ba3 | 4717 | "Add to the value of HOOK the function FUNCTION unless already present. |
353e2ef2 | 4718 | \(It becomes the first hook on the list unless optional APPEND is non-nil, in |
c567ac01 RS |
4719 | which case it becomes the last). HOOK should be a symbol, and FUNCTION may be |
4720 | any valid function. HOOK's value should be a list of functions, not a single | |
4721 | function. If HOOK is void, it is first set to nil." | |
4722 | (or (boundp hook) (set hook nil)) | |
4723 | (or (if (consp function) | |
4724 | ;; Clever way to tell whether a given lambda-expression | |
4725 | ;; is equal to anything in the hook. | |
4726 | (let ((tail (assoc (cdr function) (symbol-value hook)))) | |
4727 | (equal function tail)) | |
4728 | (memq function (symbol-value hook))) | |
353e2ef2 | 4729 | (set hook |
c567ac01 RS |
4730 | (if append |
4731 | (nconc (symbol-value hook) (list function)) | |
4732 | (cons function (symbol-value hook))))))) | |
76407938 | 4733 | ;;;_ : my-mark-marker to accommodate divergent emacsen: |
9179616f | 4734 | (defun my-mark-marker (&optional force buffer) |
76407938 | 4735 | "Accommodate the different signature for mark-marker across emacsen. |
9179616f DL |
4736 | |
4737 | GNU XEmacs takes two optional args, while mainline GNU Emacs does not, | |
4738 | so pass them along when appropriate." | |
9471aeec | 4739 | (if (featurep 'xemacs) |
9179616f DL |
4740 | (mark-marker force buffer) |
4741 | (mark-marker))) | |
c567ac01 | 4742 | |
9179616f | 4743 | ;;;_ #9 Under development |
fd5359c6 MR |
4744 | ;;;_ > allout-bullet-isearch (&optional bullet) |
4745 | (defun allout-bullet-isearch (&optional bullet) | |
9179616f | 4746 | "Isearch \(regexp) for topic with bullet BULLET." |
c567ac01 RS |
4747 | (interactive) |
4748 | (if (not bullet) | |
4749 | (setq bullet (solicit-char-in-string | |
4750 | "ISearch for topic with bullet: " | |
fd5359c6 | 4751 | (regexp-sans-escapes allout-bullets-string)))) |
353e2ef2 | 4752 | |
c567ac01 RS |
4753 | (let ((isearch-regexp t) |
4754 | (isearch-string (concat "^" | |
fd5359c6 | 4755 | allout-header-prefix |
c567ac01 RS |
4756 | "[ \t]*" |
4757 | bullet))) | |
4758 | (isearch-repeat 'forward) | |
4759 | (isearch-mode t))) | |
19b84ba3 | 4760 | ;;;_ ? Re hooking up with isearch - use isearch-op-fun rather than |
353e2ef2 | 4761 | ;;; wrapping the isearch functions. |
1977b8f6 RS |
4762 | |
4763 | ;;;_* Local emacs vars. | |
fd5359c6 | 4764 | ;;; The following `allout-layout' local variable setting: |
19b84ba3 RS |
4765 | ;;; - closes all topics from the first topic to just before the third-to-last, |
4766 | ;;; - shows the children of the third to last (config vars) | |
4767 | ;;; - and the second to last (code section), | |
4768 | ;;; - and closes the last topic (this local-variables section). | |
4769 | ;;;Local variables: | |
fd5359c6 | 4770 | ;;;allout-layout: (0 : -1 -1 0) |
19b84ba3 RS |
4771 | ;;;End: |
4772 | ||
6a05d05f | 4773 | ;;; allout.el ends here |