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