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