1 ;;; allout.el --- extensive outline mode for use alone and with other modes
3 ;; Copyright (C) 1992, 1993, 1994, 2001 Free Software Foundation, Inc.
5 ;; Author: Ken Manheimer <klm@python.org>
6 ;; Maintainer: Ken Manheimer <klm@python.org>
7 ;; Created: Dec 1991 - first release to usenet
8 ;; Version: $Id: allout.el,v 1.30 2001/11/26 16:23:06 pj Exp $||
9 ;; Keywords: outlines mode wp languages
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)
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.
30 ;; Allout outline mode provides extensive outline formatting and
31 ;; and manipulation beyond standard emacs outline mode. It provides
32 ;; for structured editing of outlines, as well as navigation and
33 ;; exposure. It also provides for syntax-sensitive text like
34 ;; programming languages. (For an example, see the allout code
35 ;; itself, which is organized in ;; an outline framework.)
37 ;; In addition to outline navigation and exposure, allout includes:
39 ;; - topic-oriented repositioning, cut, and paste
40 ;; - integral outline exposure-layout
41 ;; - incremental search with dynamic exposure and reconcealment of hidden text
42 ;; - automatic topic-number maintenance
43 ;; - "Hot-spot" operation, for single-keystroke maneuvering and
44 ;; exposure control. (See the outline-mode docstring.)
46 ;; and many other features.
48 ;; The outline menubar additions provide quick reference to many of
49 ;; the features, and see the docstring of the variable `outline-init'
50 ;; for instructions on priming your emacs session for automatic
51 ;; activation of outline-mode.
53 ;; See the docstring of the variables `outline-layout' and
54 ;; `outline-auto-activation' for details on automatic activation of
55 ;; allout outline-mode as a minor mode. (It has changed since allout
56 ;; 3.x, for those of you that depend on the old method.)
58 ;; Note - the lines beginning with `;;;_' are outline topic headers.
59 ;; Just `ESC-x eval-current-buffer' to give it a whirl.
61 ;; Ken Manheimer klm@python.org
69 ;;;_* USER CUSTOMIZATION VARIABLES:
71 "Extensive outline mode for use alone and with other modes."
75 ;;;_ + Layout, Mode, and Topic Header Configuration
77 ;;;_ = outline-auto-activation
78 (defcustom outline-auto-activation nil
79 "*Regulates auto-activation modality of allout outlines - see `outline-init'.
81 Setq-default by `outline-init' to regulate whether or not allout
82 outline mode is automatically activated when the buffer-specific
83 variable `outline-layout' is non-nil, and whether or not the layout
84 dictated by `outline-layout' should be imposed on mode activation.
86 With value `t', auto-mode-activation and auto-layout are enabled.
87 \(This also depends on `outline-find-file-hooks' being installed in
88 `find-file-hooks', which is also done by `outline-init'.)
90 With value `ask', auto-mode-activation is enabled, and endorsement for
91 performing auto-layout is asked of the user each time.
93 With value `activate', only auto-mode-activation is enabled,
96 With value `nil', neither auto-mode-activation nor auto-layout are
99 See the docstring for `outline-init' for the proper interface to
101 :type
'(choice (const :tag
"On" t
)
102 (const :tag
"Ask about layout" "ask")
103 (const :tag
"Mode only" "activate")
104 (const :tag
"Off" nil
))
106 ;;;_ = outline-layout
107 (defvar outline-layout nil
108 "*Layout specification and provisional mode trigger for allout outlines.
112 A list value specifies a default layout for the current buffer, to be
113 applied upon activation of allout outline-mode. Any non-nil value will
114 automatically trigger allout outline-mode, provided `outline-init'
115 has been called to enable it.
117 See the docstring for `outline-init' for details on setting up for
118 auto-mode-activation, and for `outline-expose-topic' for the format of
119 the layout specification.
121 You can associate a particular outline layout with a file by setting
122 this var via the file's local variables. For example, the following
123 lines at the bottom of an Emacs Lisp file:
126 ;;;outline-layout: \(0 : -1 -1 0)
129 will, modulo the above-mentioned conditions, cause the mode to be
130 activated when the file is visited, followed by the equivalent of
131 `\(outline-expose-topic 0 : -1 -1 0)'. \(This is the layout used for
132 the allout.el, itself.)
134 Also, allout's mode-specific provisions will make topic prefixes default
135 to the comment-start string, if any, of the language of the file. This
136 is modulo the setting of `outline-use-mode-specific-leader', which see.")
137 (make-variable-buffer-local 'outline-layout
)
138 ;;;_ = outline-show-bodies
139 (defcustom outline-show-bodies nil
140 "*If non-nil, show entire body when exposing a topic, rather than
144 (make-variable-buffer-local 'outline-show-bodies
)
146 ;;;_ = outline-header-prefix
147 (defcustom outline-header-prefix
"."
148 "*Leading string which helps distinguish topic headers.
150 Outline topic header lines are identified by a leading topic
151 header prefix, which mostly have the value of this var at their front.
152 \(Level 1 topics are exceptions. They consist of only a single
153 character, which is typically set to the outline-primary-bullet. Many
154 outlines start at level 2 to avoid this discrepancy."
157 (make-variable-buffer-local 'outline-header-prefix
)
158 ;;;_ = outline-primary-bullet
159 (defcustom outline-primary-bullet
"*"
160 "Bullet used for top-level outline topics.
162 Outline topic header lines are identified by a leading topic header
163 prefix, which is concluded by bullets that includes the value of this
164 var and the respective outline-*-bullets-string vars.
166 The value of an asterisk (`*') provides for backwards compatibility
167 with the original emacs outline mode. See outline-plain-bullets-string
168 and outline-distinctive-bullets-string for the range of available
172 (make-variable-buffer-local 'outline-primary-bullet
)
173 ;;;_ = outline-plain-bullets-string
174 (defcustom outline-plain-bullets-string
".:,;"
175 "*The bullets normally used in outline topic prefixes.
177 See `outline-distinctive-bullets-string' for the other kind of
180 DO NOT include the close-square-bracket, `]', as a bullet.
182 Outline mode has to be reactivated in order for changes to the value
183 of this var to take effect."
186 (make-variable-buffer-local 'outline-plain-bullets-string
)
187 ;;;_ = outline-distinctive-bullets-string
188 (defcustom outline-distinctive-bullets-string
"*+-=>([{}&!?#%\"X@$~_\\"
189 "*Persistent outline header bullets used to distinguish special topics.
191 These bullets are used to distinguish topics from the run-of-the-mill
192 ones. They are not used in the standard topic headers created by
193 the topic-opening, shifting, and rebulleting \(eg, on topic shift,
194 topic paste, blanket rebulleting) routines, but are offered among the
195 choices for rebulleting. They are not altered by the above automatic
196 rebulleting, so they can be used to characterize topics, eg:
199 `\(' parenthetic comment \(with a matching close paren inside)
200 `[' meta-note \(with a matching close ] inside)
205 ... just for example. (`#' typically has a special meaning to the
206 software, according to the value of `outline-numbered-bullet'.)
208 See `outline-plain-bullets-string' for the selection of
211 You must run `set-outline-regexp' in order for outline mode to
212 reconcile to changes of this value.
214 DO NOT include the close-square-bracket, `]', on either of the bullet
218 (make-variable-buffer-local 'outline-distinctive-bullets-string
)
220 ;;;_ = outline-use-mode-specific-leader
221 (defcustom outline-use-mode-specific-leader t
222 "*When non-nil, use mode-specific topic-header prefixes.
224 Allout outline mode will use the mode-specific `outline-mode-leaders'
225 and/or comment-start string, if any, to lead the topic prefix string,
226 so topic headers look like comments in the programming language.
228 String values are used as they stand.
230 Value `t' means to first check for assoc value in `outline-mode-leaders'
231 alist, then use comment-start string, if any, then use default \(`.').
232 \(See note about use of comment-start strings, below.)
234 Set to the symbol for either of `outline-mode-leaders' or
235 `comment-start' to use only one of them, respectively.
237 Value `nil' means to always use the default \(`.').
239 comment-start strings that do not end in spaces are tripled, and an
240 `_' underscore is tacked on the end, to distinguish them from regular
241 comment strings. comment-start strings that do end in spaces are not
242 tripled, but an underscore is substituted for the space. [This
243 presumes that the space is for appearance, not comment syntax. You
244 can use `outline-mode-leaders' to override this behavior, when
246 :type
'(choice (const t
) (const nil
) string
247 (const outline-mode-leaders
)
248 (const comment-start
))
250 ;;;_ = outline-mode-leaders
251 (defvar outline-mode-leaders
'()
252 "Specific outline-prefix leading strings per major modes.
254 Entries will be used instead or in lieu of mode-specific
255 comment-start strings. See also `outline-use-mode-specific-leader'.
257 If you're constructing a string that will comment-out outline
258 structuring so it can be included in program code, append an extra
259 character, like an \"_\" underscore, to distinguish the lead string
260 from regular comments that start at bol.")
262 ;;;_ = outline-old-style-prefixes
263 (defcustom outline-old-style-prefixes nil
264 "*When non-nil, use only old-and-crusty outline-mode `*' topic prefixes.
266 Non-nil restricts the topic creation and modification
267 functions to asterix-padded prefixes, so they look exactly
268 like the original emacs-outline style prefixes.
270 Whatever the setting of this variable, both old and new style prefixes
271 are always respected by the topic maneuvering functions."
274 (make-variable-buffer-local 'outline-old-style-prefixes
)
275 ;;;_ = outline-stylish-prefixes - alternating bullets
276 (defcustom outline-stylish-prefixes t
277 "*Do fancy stuff with topic prefix bullets according to level, etc.
279 Non-nil enables topic creation, modification, and repositioning
280 functions to vary the topic bullet char (the char that marks the topic
281 depth) just preceding the start of the topic text) according to level.
282 Otherwise, only asterisks (`*') and distinctive bullets are used.
284 This is how an outline can look (but sans indentation) with stylish
289 . + One level 3 subtopic
290 . . One level 4 subtopic
291 . . A second 4 subtopic
292 . + Another level 3 subtopic
293 . #1 A numbered level 4 subtopic
295 . ! Another level 4 subtopic with a different distinctive bullet
296 . #4 And another numbered level 4 subtopic
298 This would be an outline with stylish prefixes inhibited (but the
299 numbered and other distinctive bullets retained):
303 . * One level 3 subtopic
304 . * One level 4 subtopic
305 . * A second 4 subtopic
306 . * Another level 3 subtopic
307 . #1 A numbered level 4 subtopic
309 . ! Another level 4 subtopic with a different distinctive bullet
310 . #4 And another numbered level 4 subtopic
312 Stylish and constant prefixes (as well as old-style prefixes) are
313 always respected by the topic maneuvering functions, regardless of
314 this variable setting.
316 The setting of this var is not relevant when outline-old-style-prefixes
320 (make-variable-buffer-local 'outline-stylish-prefixes
)
322 ;;;_ = outline-numbered-bullet
323 (defcustom outline-numbered-bullet
"#"
324 "*String designating bullet of topics that have auto-numbering; nil for none.
326 Topics having this bullet have automatic maintenance of a sibling
327 sequence-number tacked on, just after the bullet. Conventionally set
328 to \"#\", you can set it to a bullet of your choice. A nil value
329 disables numbering maintenance."
330 :type
'(choice (const nil
) string
)
332 (make-variable-buffer-local 'outline-numbered-bullet
)
333 ;;;_ = outline-file-xref-bullet
334 (defcustom outline-file-xref-bullet
"@"
335 "*Bullet signifying file cross-references, for `outline-resolve-xref'.
337 Set this var to the bullet you want to use for file cross-references."
338 :type
'(choice (const nil
) string
)
341 ;;;_ = outline-presentation-padding
342 (defcustom outline-presentation-padding
2
343 "*Presentation-format white-space padding factor, for greater indent."
347 (make-variable-buffer-local 'outline-presentation-padding
)
349 ;;;_ = outline-abbreviate-flattened-numbering
350 (defcustom outline-abbreviate-flattened-numbering nil
351 "*If non-nil, `outline-flatten-exposed-to-buffer' abbreviates topic
352 numbers to minimal amount with some context. Otherwise, entire
353 numbers are always used."
357 ;;;_ + LaTeX formatting
358 ;;;_ - outline-number-pages
359 (defcustom outline-number-pages nil
360 "*Non-nil turns on page numbering for LaTeX formatting of an outline."
363 ;;;_ - outline-label-style
364 (defcustom outline-label-style
"\\large\\bf"
365 "*Font and size of labels for LaTeX formatting of an outline."
368 ;;;_ - outline-head-line-style
369 (defcustom outline-head-line-style
"\\large\\sl "
370 "*Font and size of entries for LaTeX formatting of an outline."
373 ;;;_ - outline-body-line-style
374 (defcustom outline-body-line-style
" "
375 "*Font and size of entries for LaTeX formatting of an outline."
378 ;;;_ - outline-title-style
379 (defcustom outline-title-style
"\\Large\\bf"
380 "*Font and size of titles for LaTeX formatting of an outline."
384 (defcustom outline-title
'(or buffer-file-name
(current-buffer-name))
385 "*Expression to be evaluated to determine the title for LaTeX
389 ;;;_ - outline-line-skip
390 (defcustom outline-line-skip
".05cm"
391 "*Space between lines for LaTeX formatting of an outline."
394 ;;;_ - outline-indent
395 (defcustom outline-indent
".3cm"
396 "*LaTeX formatted depth-indent spacing."
400 ;;;_ + Miscellaneous customization
402 ;;;_ = outline-command-prefix
403 (defcustom outline-command-prefix
"\C-c"
404 "*Key sequence to be used as prefix for outline mode command key bindings."
408 ;;;_ = outline-keybindings-list
409 ;;; You have to reactivate outline-mode - `(outline-mode t)' - to
410 ;;; institute changes to this var.
411 (defvar outline-keybindings-list
()
412 "*List of outline-mode key / function bindings, for outline-mode-map.
414 String or vector key will be prefaced with outline-command-prefix,
415 unless optional third, non-nil element is present.")
416 (setq outline-keybindings-list
419 ("\C-n" outline-next-visible-heading
)
420 ("\C-p" outline-previous-visible-heading
)
421 ("\C-u" outline-up-current-level
)
422 ("\C-f" outline-forward-current-level
)
423 ("\C-b" outline-backward-current-level
)
424 ("\C-a" outline-beginning-of-current-entry
)
425 ("\C-e" outline-end-of-current-entry
)
427 ("\C-i" outline-show-children
)
428 ("\C-s" outline-show-current-subtree
)
429 ("\C-h" outline-hide-current-subtree
)
430 ("\C-o" outline-show-current-entry
)
431 ("!" outline-show-all
)
432 ; Alteration commands:
433 (" " outline-open-sibtopic
)
434 ("." outline-open-subtopic
)
435 ("," outline-open-supertopic
)
436 ("'" outline-shift-in
)
437 (">" outline-shift-in
)
438 ("<" outline-shift-out
)
439 ("\C-m" outline-rebullet-topic
)
440 ("*" outline-rebullet-current-heading
)
441 ("#" outline-number-siblings
)
442 ("\C-k" outline-kill-line t
)
443 ("\C-y" outline-yank t
)
444 ("\M-y" outline-yank-pop t
)
445 ("\C-k" outline-kill-topic
)
446 ; Miscellaneous commands:
447 ;([?\C-\ ] outline-mark-topic)
448 ("@" outline-resolve-xref
)
449 ("=c" outline-copy-exposed-to-buffer
)
450 ("=i" outline-indented-exposed-to-buffer
)
451 ("=t" outline-latexify-exposed
)
452 ("=p" outline-flatten-exposed-to-buffer
)))
454 ;;;_ = outline-isearch-dynamic-expose
455 (defcustom outline-isearch-dynamic-expose t
456 "*Non-nil enable dynamic exposure of hidden incremental-search
457 targets as they're encountered."
460 (make-variable-buffer-local 'outline-isearch-dynamic-expose
)
462 ;;;_ = outline-use-hanging-indents
463 (defcustom outline-use-hanging-indents t
464 "*If non-nil, topic body text auto-indent defaults to indent of the header.
465 Ie, it is indented to be just past the header prefix. This is
466 relevant mostly for use with indented-text-mode, or other situations
467 where auto-fill occurs.
469 \[This feature no longer depends in any way on the `filladapt.el'
470 lisp-archive package.\]"
473 (make-variable-buffer-local 'outline-use-hanging-indents
)
475 ;;;_ = outline-reindent-bodies
476 (defcustom outline-reindent-bodies
(if outline-use-hanging-indents
478 "*Non-nil enables auto-adjust of topic body hanging indent with depth shifts.
480 When active, topic body lines that are indented even with or beyond
481 their topic header are reindented to correspond with depth shifts of
484 A value of `t' enables reindent in non-programming-code buffers, ie
485 those that do not have the variable `comment-start' set. A value of
486 `force' enables reindent whether or not `comment-start' is set."
487 :type
'(choice (const nil
) (const t
) (const text
) (const force
))
490 (make-variable-buffer-local 'outline-reindent-bodies
)
492 ;;;_ = outline-inhibit-protection
493 (defcustom outline-inhibit-protection nil
494 "*Non-nil disables warnings and confirmation-checks for concealed-text edits.
496 Outline mode uses emacs change-triggered functions to detect unruly
497 changes to concealed regions. Set this var non-nil to disable the
498 protection, potentially increasing text-entry responsiveness a bit.
500 This var takes effect at outline-mode activation, so you may have to
501 deactivate and then reactivate the mode if you want to toggle the
506 ;;;_* CODE - no user customizations below.
508 ;;;_ #1 Internal Outline Formatting and Configuration
510 ;;;_ = outline-version
511 (defvar outline-version
512 (let ((rcs-rev "$Revision: 1.30 $"))
515 (string-match "Revision: \\([0-9]+\\.[0-9]+\\)" rcs-rev
)
516 (substring rcs-rev
(match-beginning 1) (match-end 1)))
518 "Revision number of currently loaded outline package. \(allout.el)")
519 ;;;_ > outline-version
520 (defun outline-version (&optional here
)
521 "Return string describing the loaded outline version."
523 (let ((msg (concat "Allout Outline Mode v " outline-version
)))
524 (if here
(insert msg
))
527 ;;;_ : Topic header format
528 ;;;_ = outline-regexp
529 (defvar outline-regexp
""
530 "*Regular expression to match the beginning of a heading line.
532 Any line whose beginning matches this regexp is considered a
533 heading. This var is set according to the user configuration vars
534 by set-outline-regexp.")
535 (make-variable-buffer-local 'outline-regexp
)
536 ;;;_ = outline-bullets-string
537 (defvar outline-bullets-string
""
538 "A string dictating the valid set of outline topic bullets.
540 This var should *not* be set by the user - it is set by `set-outline-regexp',
541 and is produced from the elements of `outline-plain-bullets-string'
542 and `outline-distinctive-bullets-string'.")
543 (make-variable-buffer-local 'outline-bullets-string
)
544 ;;;_ = outline-bullets-string-len
545 (defvar outline-bullets-string-len
0
546 "Length of current buffers' outline-plain-bullets-string.")
547 (make-variable-buffer-local 'outline-bullets-string-len
)
548 ;;;_ = outline-line-boundary-regexp
549 (defvar outline-line-boundary-regexp
()
550 "Outline-regexp with outline-style beginning-of-line anchor.
552 \(Ie, C-j, *or* C-m, for prefixes of hidden topics). This is properly
553 set when outline-regexp is produced by `set-outline-regexp', so
554 that (match-beginning 2) and (match-end 2) delimit the prefix.")
555 (make-variable-buffer-local 'outline-line-boundary-regexp
)
556 ;;;_ = outline-bob-regexp
557 (defvar outline-bob-regexp
()
558 "Like outline-line-boundary-regexp, for headers at beginning of buffer.
559 \(match-beginning 2) and \(match-end 2) delimit the prefix.")
560 (make-variable-buffer-local 'outline-bob-regexp
)
561 ;;;_ = outline-header-subtraction
562 (defvar outline-header-subtraction
(1- (length outline-header-prefix
))
563 "Outline-header prefix length to subtract when computing topic depth.")
564 (make-variable-buffer-local 'outline-header-subtraction
)
565 ;;;_ = outline-plain-bullets-string-len
566 (defvar outline-plain-bullets-string-len
(length outline-plain-bullets-string
)
567 "Length of outline-plain-bullets-string, updated by set-outline-regexp.")
568 (make-variable-buffer-local 'outline-plain-bullets-string-len
)
571 ;;;_ X outline-reset-header-lead (header-lead)
572 (defun outline-reset-header-lead (header-lead)
573 "*Reset the leading string used to identify topic headers."
574 (interactive "sNew lead string: ")
575 (setq outline-header-prefix header-lead
)
576 (setq outline-header-subtraction
(1- (length outline-header-prefix
)))
577 (set-outline-regexp))
578 ;;;_ X outline-lead-with-comment-string (header-lead)
579 (defun outline-lead-with-comment-string (&optional header-lead
)
580 "*Set the topic-header leading string to specified string.
582 Useful when for encapsulating outline structure in programming
583 language comments. Returns the leading string."
586 (if (not (stringp header-lead
))
587 (setq header-lead
(read-string
588 "String prefix for topic headers: ")))
589 (setq outline-reindent-bodies nil
)
590 (outline-reset-header-lead header-lead
)
592 ;;;_ > outline-infer-header-lead ()
593 (defun outline-infer-header-lead ()
594 "Determine appropriate `outline-header-prefix'.
596 Works according to settings of:
599 `outline-header-prefix' (default)
600 `outline-use-mode-specific-leader'
601 and `outline-mode-leaders'.
603 Apply this via \(re)activation of `outline-mode', rather than
604 invoking it directly."
605 (let* ((use-leader (and (boundp 'outline-use-mode-specific-leader
)
606 (if (or (stringp outline-use-mode-specific-leader
)
607 (memq outline-use-mode-specific-leader
608 '(outline-mode-leaders
611 outline-use-mode-specific-leader
612 ;; Oops - garbled value, equate with effect of 't:
616 ((not use-leader
) nil
)
617 ;; Use the explicitly designated leader:
618 ((stringp use-leader
) use-leader
)
619 (t (or (and (memq use-leader
'(t outline-mode-leaders
))
620 ;; Get it from outline mode leaders?
621 (cdr (assq major-mode outline-mode-leaders
)))
622 ;; ... didn't get from outline-mode-leaders...
623 (and (memq use-leader
'(t comment-start
))
625 ;; Use comment-start, maybe tripled, and with
629 (substring comment-start
630 (1- (length comment-start
))))
631 ;; Use comment-start, sans trailing space:
632 (substring comment-start
0 -
1)
633 (concat comment-start comment-start comment-start
))
634 ;; ... and append underscore, whichever:
638 (if (string= leader outline-header-prefix
)
639 nil
; no change, nothing to do.
640 (setq outline-header-prefix leader
)
641 outline-header-prefix
))))
642 ;;;_ > outline-infer-body-reindent ()
643 (defun outline-infer-body-reindent ()
644 "Determine proper setting for `outline-reindent-bodies'.
646 Depends on default setting of `outline-reindent-bodies' \(which see)
647 and presence of setting for `comment-start', to tell whether the
648 file is programming code."
649 (if (and outline-reindent-bodies
651 (not (eq 'force outline-reindent-bodies
)))
652 (setq outline-reindent-bodies nil
)))
653 ;;;_ > set-outline-regexp ()
654 (defun set-outline-regexp ()
655 "Generate proper topic-header regexp form for outline functions.
657 Works with respect to `outline-plain-bullets-string' and
658 `outline-distinctive-bullets-string'."
661 ;; Derive outline-bullets-string from user configured components:
662 (setq outline-bullets-string
"")
663 (let ((strings (list 'outline-plain-bullets-string
664 'outline-distinctive-bullets-string
665 'outline-primary-bullet
))
673 (setq new-string
"") (setq index
0)
674 (setq cur-len
(length (setq cur-string
(symbol-value (car strings
)))))
675 (while (< index cur-len
)
676 (setq cur-char
(aref cur-string index
))
677 (setq outline-bullets-string
678 (concat outline-bullets-string
680 ; Single dash would denote a
681 ; sequence, repeated denotes
683 ((eq cur-char ?-
) "--")
684 ; literal close-square-bracket
685 ; doesn't work right in the
687 ((eq cur-char ?\
]) "")
688 (t (regexp-quote (char-to-string cur-char
))))))
689 (setq index
(1+ index
)))
690 (setq strings
(cdr strings
)))
692 ;; Derive next for repeated use in outline-pending-bullet:
693 (setq outline-plain-bullets-string-len
(length outline-plain-bullets-string
))
694 (setq outline-header-subtraction
(1- (length outline-header-prefix
)))
695 ;; Produce the new outline-regexp:
696 (setq outline-regexp
(concat "\\(\\"
697 outline-header-prefix
699 outline-bullets-string
701 outline-primary-bullet
703 (setq outline-line-boundary-regexp
704 (concat "\\([\n\r]\\)\\(" outline-regexp
"\\)"))
705 (setq outline-bob-regexp
706 (concat "\\(\\`\\)\\(" outline-regexp
"\\)"))
709 ;;;_ = outline-mode-map
710 (defvar outline-mode-map nil
"Keybindings for (allout) outline minor mode.")
711 ;;;_ > produce-outline-mode-map (keymap-alist &optional base-map)
712 (defun produce-outline-mode-map (keymap-list &optional base-map
)
713 "Produce keymap for use as outline-mode-map, from keymap-list.
715 Built on top of optional BASE-MAP, or empty sparse map if none specified.
716 See doc string for outline-keybindings-list for format of binding list."
717 (let ((map (or base-map
(make-sparse-keymap)))
718 (pref (list outline-command-prefix
)))
721 (let ((add-pref (null (cdr (cdr cell
))))
722 (key-suff (list (car cell
))))
725 (apply 'concat
(if add-pref
726 (append pref key-suff
)
728 (car (cdr cell
)))))))
731 ;;;_ = outline-prior-bindings - being deprecated.
732 (defvar outline-prior-bindings nil
733 "Variable for use in V18, with outline-added-bindings, for
734 resurrecting, on mode deactivation, bindings that existed before
735 activation. Being deprecated.")
736 ;;;_ = outline-added-bindings - being deprecated
737 (defvar outline-added-bindings nil
738 "Variable for use in V18, with outline-prior-bindings, for
739 resurrecting, on mode deactivation, bindings that existed before
740 activation. Being deprecated.")
742 (defun produce-outline-mode-menubar-entries ()
744 (easy-menu-define outline-mode-exposure-menu
746 "Allout outline exposure menu."
748 ["Show Entry" outline-show-current-entry t
]
749 ["Show Children" outline-show-children t
]
750 ["Show Subtree" outline-show-current-subtree t
]
751 ["Hide Subtree" outline-hide-current-subtree t
]
752 ["Hide Leaves" outline-hide-current-leaves t
]
754 ["Show All" outline-show-all t
]))
755 (easy-menu-define outline-mode-editing-menu
757 "Allout outline editing menu."
759 ["Open Sibling" outline-open-sibtopic t
]
760 ["Open Subtopic" outline-open-subtopic t
]
761 ["Open Supertopic" outline-open-supertopic t
]
763 ["Shift Topic In" outline-shift-in t
]
764 ["Shift Topic Out" outline-shift-out t
]
765 ["Rebullet Topic" outline-rebullet-topic t
]
766 ["Rebullet Heading" outline-rebullet-current-heading t
]
767 ["Number Siblings" outline-number-siblings t
]))
768 (easy-menu-define outline-mode-navigation-menu
770 "Allout outline navigation menu."
772 ["Next Visible Heading" outline-next-visible-heading t
]
773 ["Previous Visible Heading"
774 outline-previous-visible-heading t
]
776 ["Up Level" outline-up-current-level t
]
777 ["Forward Current Level" outline-forward-current-level t
]
778 ["Backward Current Level"
779 outline-backward-current-level t
]
781 ["Beginning of Entry"
782 outline-beginning-of-current-entry t
]
783 ["End of Entry" outline-end-of-current-entry t
]
784 ["End of Subtree" outline-end-of-current-subtree t
]))
785 (easy-menu-define outline-mode-misc-menu
787 "Allout outlines miscellaneous bindings."
789 ["Version" outline-version t
]
791 ["Duplicate Exposed" outline-copy-exposed-to-buffer t
]
792 ["Duplicate Exposed, numbered"
793 outline-flatten-exposed-to-buffer t
]
794 ["Duplicate Exposed, indented"
795 outline-indented-exposed-to-buffer t
]
797 ["Set Header Lead" outline-reset-header-lead t
]
798 ["Set New Exposure" outline-expose-topic t
])))
799 ;;;_ : Mode-Specific Variable Maintenance Utilities
800 ;;;_ = outline-mode-prior-settings
801 (defvar outline-mode-prior-settings nil
802 "Internal outline mode use; settings to be resumed on mode deactivation.")
803 (make-variable-buffer-local 'outline-mode-prior-settings
)
804 ;;;_ > outline-resumptions (name &optional value)
805 (defun outline-resumptions (name &optional value
)
807 "Registers or resumes settings over outline-mode activation/deactivation.
809 First arg is NAME of variable affected. Optional second arg is list
810 containing outline-mode-specific VALUE to be imposed on named
811 variable, and to be registered. (It's a list so you can specify
812 registrations of null values.) If no value is specified, the
813 registered value is returned (encapsulated in the list, so the caller
814 can distinguish nil vs no value), and the registration is popped
817 (let ((on-list (assq name outline-mode-prior-settings
))
818 prior-capsule
; By `capsule' i mean a list
819 ; containing a value, so we can
820 ; distinguish nil from no value.
828 nil
; Already preserved prior value - don't mess with it.
829 ;; Register the old value, or nil if previously unbound:
830 (setq outline-mode-prior-settings
832 (if (boundp name
) (list (symbol-value name
))))
833 outline-mode-prior-settings
)))
834 ; And impose the new value, locally:
835 (progn (make-local-variable name
)
836 (set name
(car value
))))
841 ;; Oops, not registered - leave it be:
844 ;; Some registration:
846 (setq prior-capsule
(car (cdr on-list
)))
848 (set name
(car prior-capsule
)) ; Some prior value - reestablish it.
849 (makunbound name
)) ; Previously unbound - demolish var.
850 ; Remove registration:
852 (while outline-mode-prior-settings
853 (if (not (eq (car outline-mode-prior-settings
)
856 (cons (car outline-mode-prior-settings
)
858 (setq outline-mode-prior-settings
859 (cdr outline-mode-prior-settings
)))
860 (setq outline-mode-prior-settings rebuild
)))))
862 ;;;_ : Mode-specific incidentals
863 ;;;_ = outline-during-write-cue nil
864 (defvar outline-during-write-cue nil
865 "Used to inhibit outline change-protection during file write.
867 See also `outline-post-command-business', `outline-write-file-hook',
868 `outline-before-change-protect', and `outline-post-command-business'
870 ;;;_ = outline-pre-was-isearching nil
871 (defvar outline-pre-was-isearching nil
872 "Cue for isearch-dynamic-exposure mechanism, implemented in
873 outline-pre- and -post-command-hooks.")
874 (make-variable-buffer-local 'outline-pre-was-isearching
)
875 ;;;_ = outline-isearch-prior-pos nil
876 (defvar outline-isearch-prior-pos nil
877 "Cue for isearch-dynamic-exposure tracking, used by outline-isearch-expose.")
878 (make-variable-buffer-local 'outline-isearch-prior-pos
)
879 ;;;_ = outline-isearch-did-quit
880 (defvar outline-isearch-did-quit nil
881 "Distinguishes isearch conclusion and cancellation.
883 Maintained by outline-isearch-abort \(which is wrapped around the real
884 isearch-abort), and monitored by outline-isearch-expose for action.")
885 (make-variable-buffer-local 'outline-isearch-did-quit
)
886 ;;;_ = outline-override-protect nil
887 (defvar outline-override-protect nil
888 "Used in outline-mode for regulate of concealed-text protection mechanism.
890 Allout outline mode regulates alteration of concealed text to protect
891 against inadvertent, unnoticed changes. This is for use by specific,
892 native outline functions to temporarily override that protection.
893 It's automatically reset to nil after every buffer modification.")
894 (make-variable-buffer-local 'outline-override-protect
)
895 ;;;_ > outline-unprotected (expr)
896 (defmacro outline-unprotected
(expr)
897 "Evaluate EXPRESSION with `outline-override-protect' let-bound `t'."
898 `(let ((outline-override-protect t
))
900 ;;;_ = outline-undo-aggregation
901 (defvar outline-undo-aggregation
30
902 "Amount of successive self-insert actions to bunch together per undo.
904 This is purely a kludge variable, regulating the compensation for a bug in
905 the way that before-change-functions and undo interact.")
906 (make-variable-buffer-local 'outline-undo-aggregation
)
907 ;;;_ = file-var-bug hack
908 (defvar outline-v18
/19-file-var-hack nil
909 "Horrible hack used to prevent invalid multiple triggering of outline
910 mode from prop-line file-var activation. Used by outline-mode function
912 ;;;_ > outline-write-file-hook ()
913 (defun outline-write-file-hook ()
914 "In outline mode, run as a local-write-file-hooks activity.
916 Currently just sets `outline-during-write-cue', so outline-change-protection
917 knows to keep inactive during file write."
918 (setq outline-during-write-cue t
)
921 ;;;_ #2 Mode activation
923 (defvar outline-mode
() "Allout outline mode minor-mode flag.")
924 (make-variable-buffer-local 'outline-mode
)
925 ;;;_ > outline-mode-p ()
926 (defmacro outline-mode-p
()
927 "Return t if outline-mode is active in current buffer."
929 ;;;_ = outline-explicitly-deactivated
930 (defvar outline-explicitly-deactivated nil
931 "Outline-mode was last deliberately deactivated.
932 So outline-post-command-business should not reactivate it...")
933 (make-variable-buffer-local 'outline-explicitly-deactivated
)
934 ;;;_ > outline-init (&optional mode)
935 (defun outline-init (&optional mode
)
936 "Prime outline-mode to enable/disable auto-activation, wrt `outline-layout'.
938 MODE is one of the following symbols:
940 - nil \(or no argument) deactivate auto-activation/layout;
941 - `activate', enable auto-activation only;
942 - `ask', enable auto-activation, and enable auto-layout but with
943 confirmation for layout operation solicited from user each time;
944 - `report', just report and return the current auto-activation state;
945 - anything else \(eg, t) for auto-activation and auto-layout, without
946 any confirmation check.
948 Use this function to setup your emacs session for automatic activation
949 of allout outline mode, contingent to the buffer-specific setting of
950 the `outline-layout' variable. (See `outline-layout' and
951 `outline-expose-topic' docstrings for more details on auto layout).
953 `outline-init' works by setting up (or removing) the outline-mode
954 find-file-hook, and giving `outline-auto-activation' a suitable
957 To prime your emacs session for full auto-outline operation, include
958 the following two lines in your emacs init file:
968 (concat "Select outline auto setup mode "
969 "(empty for report, ? for options) ")
970 '(("nil")("full")("activate")("deactivate")
971 ("ask") ("report") (""))
974 (if (string= mode
"")
976 (setq mode
(intern-soft mode
)))))
978 ;; convenience aliases, for consistent ref to respective vars:
979 ((hook 'outline-find-file-hook
)
980 (curr-mode 'outline-auto-activation
))
983 (setq find-file-hooks
(delq hook find-file-hooks
))
985 (message "Allout outline mode auto-activation inhibited.")))
987 (if (not (memq hook find-file-hooks
))
989 ;; Just punt and use the reports from each of the modes:
990 (outline-init (symbol-value curr-mode
))))
991 (t (add-hook 'find-file-hooks hook
)
992 (set curr-mode
; `set', not `setq'!
993 (cond ((eq mode
'activate
)
995 "Outline mode auto-activation enabled.")
998 ;; Return the current mode setting:
1002 (concat "Outline mode auto-activation and "
1003 "-layout \(upon confirmation) enabled."))
1006 "Outline mode auto-activation and -layout enabled.")
1009 ;;;_ > outline-setup-menubar ()
1010 (defun outline-setup-menubar ()
1011 "Populate the current buffer's menubar with allout outline-mode stuff."
1012 (let ((menus (list outline-mode-exposure-menu
1013 outline-mode-editing-menu
1014 outline-mode-navigation-menu
1015 outline-mode-misc-menu
))
1018 (setq cur
(car menus
)
1020 (easy-menu-add cur
))))
1021 ;;;_ > outline-mode (&optional toggle)
1023 (defun outline-mode (&optional toggle
)
1025 "Toggle minor mode for controlling exposure and editing of text outlines.
1027 Optional arg forces mode to re-initialize iff arg is positive num or
1028 symbol. Allout outline mode always runs as a minor mode.
1030 Allout outline mode provides extensive outline-oriented formatting and
1031 manipulation. It enables structural editing of outlines, as well as
1032 navigation and exposure. It also is specifically aimed at
1033 accommodating syntax-sensitive text like programming languages. \(For
1034 an example, see the allout code itself, which is organized as an allout
1037 In addition to outline navigation and exposure, allout includes:
1039 - topic-oriented repositioning, cut, and paste
1040 - integral outline exposure-layout
1041 - incremental search with dynamic exposure and reconcealment of hidden text
1042 - automatic topic-number maintenance
1043 - \"Hot-spot\" operation, for single-keystroke maneuvering and
1044 exposure control. \(See the outline-mode docstring.)
1046 and many other features.
1048 Below is a description of the bindings, and then explanation of
1049 special outline-mode features and terminology. See also the outline
1050 menubar additions for quick reference to many of the features, and see
1051 the docstring of the variable `outline-init' for instructions on
1052 priming your emacs session for automatic activation of outline-mode.
1055 The bindings are dictated by the `outline-keybindings-list' and
1056 `outline-command-prefix' variables.
1058 Navigation: Exposure Control:
1059 ---------- ----------------
1060 C-c C-n outline-next-visible-heading | C-c C-h outline-hide-current-subtree
1061 C-c C-p outline-previous-visible-heading | C-c C-i outline-show-children
1062 C-c C-u outline-up-current-level | C-c C-s outline-show-current-subtree
1063 C-c C-f outline-forward-current-level | C-c C-o outline-show-current-entry
1064 C-c C-b outline-backward-current-level | ^U C-c C-s outline-show-all
1065 C-c C-e outline-end-of-current-entry | outline-hide-current-leaves
1066 C-c C-a outline-beginning-of-current-entry, alternately, goes to hot-spot
1068 Topic Header Production:
1069 -----------------------
1070 C-c<SP> outline-open-sibtopic Create a new sibling after current topic.
1071 C-c . outline-open-subtopic ... an offspring of current topic.
1072 C-c , outline-open-supertopic ... a sibling of the current topic's parent.
1074 Topic Level and Prefix Adjustment:
1075 ---------------------------------
1076 C-c > outline-shift-in Shift current topic and all offspring deeper.
1077 C-c < outline-shift-out ... less deep.
1078 C-c<CR> outline-rebullet-topic Reconcile bullets of topic and its offspring
1079 - distinctive bullets are not changed, others
1080 alternated according to nesting depth.
1081 C-c b outline-rebullet-current-heading Prompt for alternate bullet for
1083 C-c # outline-number-siblings Number bullets of topic and siblings - the
1084 offspring are not affected. With repeat
1085 count, revoke numbering.
1087 Topic-oriented Killing and Yanking:
1088 ----------------------------------
1089 C-c C-k outline-kill-topic Kill current topic, including offspring.
1090 C-k outline-kill-line Like kill-line, but reconciles numbering, etc.
1091 C-y outline-yank Yank, adjusting depth of yanked topic to
1092 depth of heading if yanking into bare topic
1093 heading (ie, prefix sans text).
1094 M-y outline-yank-pop Is to outline-yank as yank-pop is to yank
1098 M-x outlineify-sticky Activate outline mode for current buffer,
1099 and establish a default file-var setting
1100 for `outline-layout'.
1101 C-c C-SPC outline-mark-topic
1102 C-c = c outline-copy-exposed-to-buffer
1103 Duplicate outline, sans concealed text, to
1104 buffer with name derived from derived from
1105 that of current buffer - \"*XXX exposed*\".
1106 C-c = p outline-flatten-exposed-to-buffer
1107 Like above 'copy-exposed', but convert topic
1108 prefixes to section.subsection... numeric
1110 ESC ESC (outline-init t) Setup emacs session for outline mode
1115 Hot-spot operation provides a means for easy, single-keystroke outline
1116 navigation and exposure control.
1118 \\<outline-mode-map>
1119 When the text cursor is positioned directly on the bullet character of
1120 a topic, regular characters (a to z) invoke the commands of the
1121 corresponding outline-mode keymap control chars. For example, \"f\"
1122 would invoke the command typically bound to \"C-c C-f\"
1123 \(\\[outline-forward-current-level] `outline-forward-current-level').
1125 Thus, by positioning the cursor on a topic bullet, you can execute
1126 the outline navigation and manipulation commands with a single
1127 keystroke. Non-literal chars never get this special translation, so
1128 you can use them to get away from the hot-spot, and back to normal
1131 Note that the command `outline-beginning-of-current-entry' \(\\[outline-beginning-of-current-entry]\)
1132 will move to the hot-spot when the cursor is already located at the
1133 beginning of the current entry, so you can simply hit \\[outline-beginning-of-current-entry]
1134 twice in a row to get to the hot-spot.
1138 Topic hierarchy constituents - TOPICS and SUBTOPICS:
1140 TOPIC: A basic, coherent component of an emacs outline. It can
1141 contain other topics, and it can be subsumed by other topics,
1143 The visible topic most immediately containing the cursor.
1144 DEPTH: The degree of nesting of a topic; it increases with
1145 containment. Also called the:
1146 LEVEL: The same as DEPTH.
1149 The topics that contain a topic.
1150 PARENT: A topic's immediate ancestor. It has a depth one less than
1153 The topics contained by a topic;
1155 An immediate offspring of a topic;
1157 The immediate offspring of a topic.
1159 Topics having the same parent and depth.
1161 Topic text constituents:
1163 HEADER: The first line of a topic, include the topic PREFIX and header
1165 PREFIX: The leading text of a topic which which distinguishes it from
1166 normal text. It has a strict form, which consists of a
1167 prefix-lead string, padding, and a bullet. The bullet may be
1168 followed by a number, indicating the ordinal number of the
1169 topic among its siblings, a space, and then the header text.
1171 The relative length of the PREFIX determines the nesting depth
1174 The string at the beginning of a topic prefix, normally a `.'.
1175 It can be customized by changing the setting of
1176 `outline-header-prefix' and then reinitializing outline-mode.
1178 By setting the prefix-lead to the comment-string of a
1179 programming language, you can embed outline-structuring in
1180 program code without interfering with the language processing
1181 of that code. See `outline-use-mode-specific-leader'
1182 docstring for more detail.
1184 Spaces or asterisks which separate the prefix-lead and the
1185 bullet, according to the depth of the topic.
1186 BULLET: A character at the end of the topic prefix, it must be one of
1187 the characters listed on `outline-plain-bullets-string' or
1188 `outline-distinctive-bullets-string'. (See the documentation
1189 for these variables for more details.) The default choice of
1190 bullet when generating varies in a cycle with the depth of the
1192 ENTRY: The text contained in a topic before any offspring.
1193 BODY: Same as ENTRY.
1197 The state of a topic which determines the on-screen visibility
1198 of its offspring and contained text.
1200 Topics and entry text whose display is inhibited. Contiguous
1201 units of concealed text is represented by `...' ellipses.
1202 (Ref the `selective-display' var.)
1204 Concealed topics are effectively collapsed within an ancestor.
1205 CLOSED: A topic whose immediate offspring and body-text is concealed.
1206 OPEN: A topic that is not closed, though its offspring or body may be."
1210 (let* ((active (and (not (equal major-mode
'outline
))
1212 ; Massage universal-arg `toggle' val:
1214 (or (and (listp toggle
)(car toggle
))
1216 ; Activation specifically demanded?
1217 (explicit-activation (or
1220 (or (symbolp toggle
)
1221 (and (natnump toggle
)
1222 (not (zerop toggle
)))))))
1223 ;; outline-mode already called once during this complex command?
1224 (same-complex-command (eq outline-v18
/19-file-var-hack
1225 (car command-history
)))
1229 ; See comments below re v19.18,.19 bug.
1230 (setq outline-v18
/19-file-var-hack
(car command-history
))
1234 ;; Provision for v19.18, 19.19 bug -
1235 ;; Emacs v 19.18, 19.19 file-var code invokes prop-line-designated
1236 ;; modes twice when file is visited. We have to avoid toggling mode
1237 ;; off on second invocation, so we detect it as best we can, and
1239 ((and same-complex-command
; Still in same complex command
1240 ; as last time outline-mode invoked.
1241 active
; Already activated.
1242 (not explicit-activation
) ; Prop-line file-vars don't have args.
1243 (string-match "^19.1[89]" ; Bug only known to be in v19.18 and
1244 emacs-version
)); 19.19.
1248 ((and (not explicit-activation
)
1250 ; Activation not explicitly
1251 ; requested, and either in
1252 ; active state or *de*activation
1253 ; specifically requested:
1254 (setq outline-explicitly-deactivated t
)
1255 (if (string-match "^18\." emacs-version
)
1256 ; Revoke those keys that remain
1258 (let ((curr-loc (current-local-map)))
1261 (if (eq (lookup-key curr-loc
(car cell
))
1263 (define-key curr-loc
(car cell
)
1264 (assq (car cell
) outline-prior-bindings
)))))
1265 outline-added-bindings
)
1266 (outline-resumptions 'outline-added-bindings
)
1267 (outline-resumptions 'outline-prior-bindings
)))
1269 (if outline-old-style-prefixes
1271 (outline-resumptions 'outline-primary-bullet
)
1272 (outline-resumptions 'outline-old-style-prefixes
)))
1273 (outline-resumptions 'selective-display
)
1274 (if (and (boundp 'before-change-functions
) before-change-functions
)
1275 (outline-resumptions 'before-change-functions
))
1276 (setq local-write-file-hooks
1277 (delq 'outline-write-file-hook
1278 local-write-file-hooks
))
1279 (outline-resumptions 'paragraph-start
)
1280 (outline-resumptions 'paragraph-separate
)
1281 (outline-resumptions (if (string-match "^18" emacs-version
)
1283 'auto-fill-function
))
1284 (outline-resumptions 'outline-former-auto-filler
)
1285 (setq outline-mode nil
))
1289 (setq outline-explicitly-deactivated nil
)
1290 (if outline-old-style-prefixes
1291 (progn ; Inhibit all the fancy formatting:
1292 (outline-resumptions 'outline-primary-bullet
'("*"))
1293 (outline-resumptions 'outline-old-style-prefixes
'(()))))
1295 (outline-infer-header-lead)
1296 (outline-infer-body-reindent)
1298 (set-outline-regexp)
1300 ; Produce map from current version
1301 ; of outline-keybindings-list:
1302 (if (boundp 'minor-mode-map-alist
)
1304 (progn ; V19, and maybe lucid and
1305 ; epoch, minor-mode key bindings:
1306 (setq outline-mode-map
1307 (produce-outline-mode-map outline-keybindings-list
))
1308 (produce-outline-mode-menubar-entries)
1309 (fset 'outline-mode-map outline-mode-map
)
1310 ; Include on minor-mode-map-alist,
1311 ; if not already there:
1312 (if (not (member '(outline-mode . outline-mode-map
)
1313 minor-mode-map-alist
))
1314 (setq minor-mode-map-alist
1315 (cons '(outline-mode . outline-mode-map
)
1316 minor-mode-map-alist
))))
1318 ; V18 minor-mode key bindings:
1319 ; Stash record of added bindings
1320 ; for later revocation:
1321 (outline-resumptions 'outline-added-bindings
1322 (list outline-keybindings-list
))
1323 (outline-resumptions 'outline-prior-bindings
1324 (list (current-local-map)))
1326 (use-local-map (produce-outline-mode-map outline-keybindings-list
1327 (current-local-map)))
1330 ; selective-display is the
1331 ; emacs conditional exposure
1333 (outline-resumptions 'selective-display
'(t))
1334 (if outline-inhibit-protection
1336 (outline-resumptions 'before-change-functions
1337 '(outline-before-change-protect)))
1338 (add-hook 'pre-command-hook
'outline-pre-command-business
)
1339 (add-hook 'post-command-hook
'outline-post-command-business
)
1340 ; Temporarily set by any outline
1341 ; functions that can be trusted to
1342 ; deal properly with concealed text.
1343 (add-hook 'local-write-file-hooks
'outline-write-file-hook
)
1344 ; Custom auto-fill func, to support
1345 ; respect for topic headline,
1346 ; hanging-indents, etc:
1347 (let* ((fill-func-var (if (string-match "^18" emacs-version
)
1349 'auto-fill-function
))
1350 (fill-func (symbol-value fill-func-var
)))
1351 ;; Register prevailing fill func for use by outline-auto-fill:
1352 (outline-resumptions 'outline-former-auto-filler
(list fill-func
))
1353 ;; Register outline-auto-fill to be used if filling is active:
1354 (outline-resumptions fill-func-var
'(outline-auto-fill)))
1355 ;; Paragraphs are broken by topic headlines.
1356 (make-local-variable 'paragraph-start
)
1357 (outline-resumptions 'paragraph-start
1358 (list (concat paragraph-start
"\\|^\\("
1359 outline-regexp
"\\)")))
1360 (make-local-variable 'paragraph-separate
)
1361 (outline-resumptions 'paragraph-separate
1362 (list (concat paragraph-separate
"\\|^\\("
1363 outline-regexp
"\\)")))
1365 (or (assq 'outline-mode minor-mode-alist
)
1366 (setq minor-mode-alist
1367 (cons '(outline-mode " Outl") minor-mode-alist
)))
1369 (outline-setup-menubar)
1374 (if (and outline-isearch-dynamic-expose
1375 (not (fboundp 'outline-real-isearch-abort
)))
1376 (outline-enwrap-isearch))
1378 (run-hooks 'outline-mode-hook
)
1379 (setq outline-mode t
))
1383 (outline-infer-body-reindent))
1387 outline-auto-activation
1388 (listp outline-layout
)
1389 (and (not (eq outline-auto-activation
'activate
))
1390 (if (eq outline-auto-activation
'ask
)
1391 (if (y-or-n-p (format "Expose %s with layout '%s'? "
1395 (message "Skipped %s layout." (buffer-name))
1399 (message "Adjusting '%s' exposure..." (buffer-name))
1401 (outline-this-or-next-heading)
1404 (apply 'outline-expose-topic
(list outline-layout
))
1405 (message "Adjusting '%s' exposure... done." (buffer-name)))
1406 ;; Problem applying exposure - notify user, but don't
1407 ;; interrupt, eg, file visit:
1408 (error (message "%s" (car (cdr err
)))
1413 ;;;_ > outline-minor-mode
1414 ;;; XXX released verion doesn't do this?
1415 (defalias 'outline-minor-mode
'outline-mode
)
1417 ;;;_ #3 Internal Position State-Tracking - "outline-recent-*" funcs
1418 ;;; All the basic outline functions that directly do string matches to
1419 ;;; evaluate heading prefix location set the variables
1420 ;;; `outline-recent-prefix-beginning' and `outline-recent-prefix-end'
1421 ;;; when successful. Functions starting with `outline-recent-' all
1422 ;;; use this state, providing the means to avoid redundant searches
1423 ;;; for just-established data. This optimization can provide
1424 ;;; significant speed improvement, but it must be employed carefully.
1425 ;;;_ = outline-recent-prefix-beginning
1426 (defvar outline-recent-prefix-beginning
0
1427 "Buffer point of the start of the last topic prefix encountered.")
1428 (make-variable-buffer-local 'outline-recent-prefix-beginning
)
1429 ;;;_ = outline-recent-prefix-end
1430 (defvar outline-recent-prefix-end
0
1431 "Buffer point of the end of the last topic prefix encountered.")
1432 (make-variable-buffer-local 'outline-recent-prefix-end
)
1433 ;;;_ = outline-recent-end-of-subtree
1434 (defvar outline-recent-end-of-subtree
0
1435 "Buffer point last returned by outline-end-of-current-subtree.")
1436 (make-variable-buffer-local 'outline-recent-end-of-subtree
)
1437 ;;;_ > outline-prefix-data (beg end)
1438 (defmacro outline-prefix-data
(beg end
)
1439 "Register outline-prefix state data - BEGINNING and END of prefix.
1441 For reference by `outline-recent' funcs. Returns BEGINNING."
1442 `(setq outline-recent-prefix-end
,end
1443 outline-recent-prefix-beginning
,beg
))
1444 ;;;_ > outline-recent-depth ()
1445 (defmacro outline-recent-depth
()
1446 "Return depth of last heading encountered by an outline maneuvering function.
1448 All outline functions which directly do string matches to assess
1449 headings set the variables outline-recent-prefix-beginning and
1450 outline-recent-prefix-end if successful. This function uses those settings
1451 to return the current depth."
1453 '(max 1 (- outline-recent-prefix-end
1454 outline-recent-prefix-beginning
1455 outline-header-subtraction
)))
1456 ;;;_ > outline-recent-prefix ()
1457 (defmacro outline-recent-prefix
()
1458 "Like outline-recent-depth, but returns text of last encountered prefix.
1460 All outline functions which directly do string matches to assess
1461 headings set the variables outline-recent-prefix-beginning and
1462 outline-recent-prefix-end if successful. This function uses those settings
1463 to return the current depth."
1464 '(buffer-substring outline-recent-prefix-beginning
1465 outline-recent-prefix-end
))
1466 ;;;_ > outline-recent-bullet ()
1467 (defmacro outline-recent-bullet
()
1468 "Like outline-recent-prefix, but returns bullet of last encountered prefix.
1470 All outline functions which directly do string matches to assess
1471 headings set the variables outline-recent-prefix-beginning and
1472 outline-recent-prefix-end if successful. This function uses those settings
1473 to return the current depth of the most recently matched topic."
1474 '(buffer-substring (1- outline-recent-prefix-end
)
1475 outline-recent-prefix-end
))
1479 ;;;_ - Position Assessment
1480 ;;;_ : Location Predicates
1481 ;;;_ > outline-on-current-heading-p ()
1482 (defun outline-on-current-heading-p ()
1483 "Return non-nil if point is on current visible topics' header line.
1485 Actually, returns prefix beginning point."
1488 (and (looking-at outline-regexp
)
1489 (outline-prefix-data (match-beginning 0) (match-end 0)))))
1490 ;;;_ > outline-on-heading-p ()
1491 (defalias 'outline-on-heading-p
'outline-on-current-heading-p
)
1492 ;;;_ > outline-e-o-prefix-p ()
1493 (defun outline-e-o-prefix-p ()
1494 "True if point is located where current topic prefix ends, heading begins."
1495 (and (save-excursion (beginning-of-line)
1496 (looking-at outline-regexp
))
1497 (= (point)(save-excursion (outline-end-of-prefix)(point)))))
1498 ;;;_ > outline-hidden-p ()
1499 (defmacro outline-hidden-p
()
1500 "True if point is in hidden text."
1502 (and (re-search-backward "[\n\r]" () t
)
1503 (= ?
\r (following-char)))))
1504 ;;;_ > outline-visible-p ()
1505 (defmacro outline-visible-p
()
1506 "True if point is not in hidden text."
1508 '(not (outline-hidden-p)))
1509 ;;;_ : Location attributes
1510 ;;;_ > outline-depth ()
1511 (defsubst outline-depth
()
1512 "Like outline-current-depth, but respects hidden as well as visible topics."
1514 (if (outline-goto-prefix)
1515 (outline-recent-depth)
1517 ;; Oops, no prefix, zero prefix data:
1518 (outline-prefix-data (point)(point))
1519 ;; ... and return 0:
1521 ;;;_ > outline-current-depth ()
1522 (defmacro outline-current-depth
()
1523 "Return nesting depth of visible topic most immediately containing point."
1525 (if (outline-back-to-current-heading)
1527 (- outline-recent-prefix-end
1528 outline-recent-prefix-beginning
1529 outline-header-subtraction
))
1531 ;;;_ > outline-get-current-prefix ()
1532 (defun outline-get-current-prefix ()
1533 "Topic prefix of the current topic."
1535 (if (outline-goto-prefix)
1536 (outline-recent-prefix))))
1537 ;;;_ > outline-get-bullet ()
1538 (defun outline-get-bullet ()
1539 "Return bullet of containing topic (visible or not)."
1541 (and (outline-goto-prefix)
1542 (outline-recent-bullet))))
1543 ;;;_ > outline-current-bullet ()
1544 (defun outline-current-bullet ()
1545 "Return bullet of current (visible) topic heading, or none if none found."
1548 (outline-back-to-current-heading)
1549 (buffer-substring (- outline-recent-prefix-end
1)
1550 outline-recent-prefix-end
))
1551 ;; Quick and dirty provision, ostensibly for missing bullet:
1552 ('args-out-of-range nil
))
1554 ;;;_ > outline-get-prefix-bullet (prefix)
1555 (defun outline-get-prefix-bullet (prefix)
1556 "Return the bullet of the header prefix string PREFIX."
1557 ;; Doesn't make sense if we're old-style prefixes, but this just
1558 ;; oughtn't be called then, so forget about it...
1559 (if (string-match outline-regexp prefix
)
1560 (substring prefix
(1- (match-end 0)) (match-end 0))))
1561 ;;;_ > outline-sibling-index (&optional depth)
1562 (defun outline-sibling-index (&optional depth
)
1563 "Item number of this prospective topic among its siblings.
1565 If optional arg depth is greater than current depth, then we're
1566 opening a new level, and return 0.
1568 If less than this depth, ascend to that depth and count..."
1571 (cond ((and depth
(<= depth
0) 0))
1572 ((or (not depth
) (= depth
(outline-depth)))
1574 (while (outline-previous-sibling (outline-recent-depth) nil
)
1575 (setq index
(1+ index
)))
1577 ((< depth
(outline-recent-depth))
1578 (outline-ascend-to-depth depth
)
1579 (outline-sibling-index))
1581 ;;;_ > outline-topic-flat-index ()
1582 (defun outline-topic-flat-index ()
1583 "Return a list indicating point's numeric section.subsect.subsubsect...
1584 Outermost is first."
1585 (let* ((depth (outline-depth))
1586 (next-index (outline-sibling-index depth
))
1588 (while (> next-index
0)
1589 (setq rev-sibls
(cons next-index rev-sibls
))
1590 (setq depth
(1- depth
))
1591 (setq next-index
(outline-sibling-index depth
)))
1595 ;;;_ - Navigation macros
1596 ;;;_ > outline-next-heading ()
1597 (defsubst outline-next-heading
()
1598 "Move to the heading for the topic \(possibly invisible) before this one.
1600 Returns the location of the heading, or nil if none found."
1602 (if (and (bobp) (not (eobp)))
1605 (if (re-search-forward outline-line-boundary-regexp nil
0)
1606 (outline-prefix-data ; Got valid location state - set vars:
1607 (goto-char (or (match-beginning 2)
1608 outline-recent-prefix-beginning
))
1609 (or (match-end 2) outline-recent-prefix-end
))))
1610 ;;;_ : outline-this-or-next-heading
1611 (defun outline-this-or-next-heading ()
1612 "Position cursor on current or next heading."
1613 ;; A throwaway non-macro that is defined after outline-next-heading
1614 ;; and usable by outline-mode.
1615 (if (not (outline-goto-prefix)) (outline-next-heading)))
1616 ;;;_ > outline-previous-heading ()
1617 (defmacro outline-previous-heading
()
1618 "Move to the prior \(possibly invisible) heading line.
1620 Return the location of the beginning of the heading, or nil if not found."
1624 (outline-goto-prefix)
1626 ;; searches are unbounded and return nil if failed:
1627 (or (re-search-backward outline-line-boundary-regexp nil
0)
1628 (looking-at outline-bob-regexp
))
1629 (progn ; Got valid location state - set vars:
1630 (outline-prefix-data
1631 (goto-char (or (match-beginning 2)
1632 outline-recent-prefix-beginning
))
1633 (or (match-end 2) outline-recent-prefix-end
))))))
1635 ;;;_ - Subtree Charting
1636 ;;;_ " These routines either produce or assess charts, which are
1637 ;;; nested lists of the locations of topics within a subtree.
1639 ;;; Use of charts enables efficient navigation of subtrees, by
1640 ;;; requiring only a single regexp-search based traversal, to scope
1641 ;;; out the subtopic locations. The chart then serves as the basis
1642 ;;; for assessment or adjustment of the subtree, without redundant
1643 ;;; traversal of the structure.
1645 ;;;_ > outline-chart-subtree (&optional levels orig-depth prev-depth)
1646 (defun outline-chart-subtree (&optional levels orig-depth prev-depth
)
1647 "Produce a location \"chart\" of subtopics of the containing topic.
1649 Optional argument LEVELS specifies the depth \(relative to start
1650 depth) for the chart. Subsequent optional args are not for public
1653 Charts are used to capture outline structure, so that outline-altering
1654 routines need assess the structure only once, and then use the chart
1655 for their elaborate manipulations.
1657 Topics are entered in the chart so the last one is at the car.
1658 The entry for each topic consists of an integer indicating the point
1659 at the beginning of the topic. Charts for offspring consists of a
1660 list containing, recursively, the charts for the respective subtopics.
1661 The chart for a topics' offspring precedes the entry for the topic
1664 The other function parameters are for internal recursion, and should
1665 not be specified by external callers. ORIG-DEPTH is depth of topic at
1666 starting point, and PREV-DEPTH is depth of prior topic."
1668 (let ((original (not orig-depth
)) ; `orig-depth' set only in recursion.
1671 (if original
; Just starting?
1672 ; Register initial settings and
1673 ; position to first offspring:
1674 (progn (setq orig-depth
(outline-depth))
1675 (or prev-depth
(setq prev-depth
(1+ orig-depth
)))
1676 (outline-next-heading)))
1678 ;; Loop over the current levels' siblings. Besides being more
1679 ;; efficient than tail-recursing over a level, it avoids exceeding
1680 ;; the typically quite constrained emacs max-lisp-eval-depth.
1682 ;; Probably would speed things up to implement loop-based stack
1683 ;; operation rather than recursing for lower levels. Bah.
1685 (while (and (not (eobp))
1686 ; Still within original topic?
1687 (< orig-depth
(setq curr-depth
(outline-recent-depth)))
1688 (cond ((= prev-depth curr-depth
)
1689 ;; Register this one and move on:
1690 (setq chart
(cons (point) chart
))
1691 (if (and levels
(<= levels
1))
1692 ;; At depth limit - skip sublevels:
1693 (or (outline-next-sibling curr-depth
)
1694 ;; or no more siblings - proceed to
1695 ;; next heading at lesser depth:
1696 (while (and (<= curr-depth
1697 (outline-recent-depth))
1698 (outline-next-heading))))
1699 (outline-next-heading)))
1701 ((and (< prev-depth curr-depth
)
1704 ;; Recurse on deeper level of curr topic:
1706 (cons (outline-chart-subtree (and levels
1711 ;; ... then continue with this one.
1714 ;; ... else nil if we've ascended back to prev-depth.
1718 (if original
; We're at the last sibling on
1719 ; the original level. Position
1721 (progn (and (not (eobp)) (forward-char -
1))
1722 (and (memq (preceding-char) '(?
\n ?
\r))
1723 (memq (aref (buffer-substring (max 1 (- (point) 3))
1728 (setq outline-recent-end-of-subtree
(point))))
1730 chart
; (nreverse chart) not necessary,
1731 ; and maybe not preferable.
1733 ;;;_ > outline-chart-siblings (&optional start end)
1734 (defun outline-chart-siblings (&optional start end
)
1735 "Produce a list of locations of this and succeeding sibling topics.
1736 Effectively a top-level chart of siblings. See `outline-chart-subtree'
1737 for an explanation of charts."
1739 (if (outline-goto-prefix)
1740 (let ((chart (list (point))))
1741 (while (outline-next-sibling)
1742 (setq chart
(cons (point) chart
)))
1743 (if chart
(setq chart
(nreverse chart
)))))))
1744 ;;;_ > outline-chart-to-reveal (chart depth)
1745 (defun outline-chart-to-reveal (chart depth
)
1747 "Return a flat list of hidden points in subtree CHART, up to DEPTH.
1749 Note that point can be left at any of the points on chart, or at the
1753 (while (and (or (eq depth t
) (> depth
0))
1755 (setq here
(car chart
))
1757 (let ((further (outline-chart-to-reveal here
(or (eq depth t
)
1759 ;; We're on the start of a subtree - recurse with it, if there's
1760 ;; more depth to go:
1761 (if further
(setq result
(append further result
)))
1762 (setq chart
(cdr chart
)))
1764 (if (= (preceding-char) ?
\r)
1765 (setq result
(cons here result
)))
1766 (setq chart
(cdr chart
))))
1768 ;;;_ X outline-chart-spec (chart spec &optional exposing)
1769 (defun outline-chart-spec (chart spec
&optional exposing
)
1770 "Not yet \(if ever) implemented.
1772 Produce exposure directives given topic/subtree CHART and an exposure SPEC.
1774 Exposure spec indicates the locations to be exposed and the prescribed
1775 exposure status. Optional arg EXPOSING is an integer, with 0
1776 indicating pending concealment, anything higher indicating depth to
1777 which subtopic headers should be exposed, and negative numbers
1778 indicating (negative of) the depth to which subtopic headers and
1779 bodies should be exposed.
1781 The produced list can have two types of entries. Bare numbers
1782 indicate points in the buffer where topic headers that should be
1785 - bare negative numbers indicates that the topic starting at the
1786 point which is the negative of the number should be opened,
1787 including their entries.
1788 - bare positive values indicate that this topic header should be
1790 - Lists signify the beginning and end points of regions that should
1791 be flagged, and the flag to employ. (For concealment: `\(\?r\)', and
1797 (setq spec
(cdr spec
)))
1801 ;;;_ > outline-goto-prefix ()
1802 (defun outline-goto-prefix ()
1803 "Put point at beginning of immediately containing outline topic.
1805 Goes to most immediate subsequent topic if none immediately containing.
1807 Not sensitive to topic visibility.
1809 Returns a the point at the beginning of the prefix, or nil if none."
1812 (while (and (not done
)
1813 (re-search-backward "[\n\r]" nil
1))
1815 (if (looking-at outline-regexp
)
1816 (setq done
(outline-prefix-data (match-beginning 0)
1820 (cond ((looking-at outline-regexp
)
1821 (outline-prefix-data (match-beginning 0)(match-end 0)))
1822 ((outline-next-heading))
1825 ;;;_ > outline-end-of-prefix ()
1826 (defun outline-end-of-prefix (&optional ignore-decorations
)
1827 "Position cursor at beginning of header text.
1829 If optional IGNORE-DECORATIONS is non-nil, put just after bullet,
1830 otherwise skip white space between bullet and ensuing text."
1832 (if (not (outline-goto-prefix))
1834 (let ((match-data (match-data)))
1835 (goto-char (match-end 0))
1836 (if ignore-decorations
1838 (while (looking-at "[0-9]") (forward-char 1))
1839 (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1)))
1840 (store-match-data match-data
))
1841 ;; Reestablish where we are:
1842 (outline-current-depth)))
1843 ;;;_ > outline-current-bullet-pos ()
1844 (defun outline-current-bullet-pos ()
1845 "Return position of current \(visible) topic's bullet."
1847 (if (not (outline-current-depth))
1849 (1- (match-end 0))))
1850 ;;;_ > outline-back-to-current-heading ()
1851 (defun outline-back-to-current-heading ()
1852 "Move to heading line of current topic, or beginning if already on the line."
1855 (prog1 (or (outline-on-current-heading-p)
1856 (and (re-search-backward (concat "^\\(" outline-regexp
"\\)")
1859 (outline-prefix-data (match-beginning 1)(match-end 1))))
1860 (if (interactive-p) (outline-end-of-prefix))))
1861 ;;;_ > outline-back-to-heading ()
1862 (defalias 'outline-back-to-heading
'outline-back-to-current-heading
)
1863 ;;;_ > outline-pre-next-preface ()
1864 (defun outline-pre-next-preface ()
1865 "Skip forward to just before the next heading line.
1867 Returns that character position."
1869 (if (re-search-forward outline-line-boundary-regexp nil
'move
)
1870 (prog1 (goto-char (match-beginning 0))
1871 (outline-prefix-data (match-beginning 2)(match-end 2)))))
1872 ;;;_ > outline-end-of-current-subtree ()
1873 (defun outline-end-of-current-subtree ()
1874 "Put point at the end of the last leaf in the currently visible topic."
1876 (outline-back-to-current-heading)
1877 (let ((level (outline-recent-depth)))
1878 (outline-next-heading)
1879 (while (and (not (eobp))
1880 (> (outline-recent-depth) level
))
1881 (outline-next-heading))
1882 (and (not (eobp)) (forward-char -
1))
1883 (and (memq (preceding-char) '(?
\n ?
\r))
1884 (memq (aref (buffer-substring (max 1 (- (point) 3)) (point)) 1)
1887 (setq outline-recent-end-of-subtree
(point))))
1888 ;;;_ > outline-beginning-of-current-entry ()
1889 (defun outline-beginning-of-current-entry ()
1890 "When not already there, position point at beginning of current topic's body.
1892 If already there, move cursor to bullet for hot-spot operation.
1893 \(See outline-mode doc string for details on hot-spot operation.)"
1895 (let ((start-point (point)))
1896 (outline-end-of-prefix)
1897 (if (and (interactive-p)
1898 (= (point) start-point
))
1899 (goto-char (outline-current-bullet-pos)))))
1900 ;;;_ > outline-end-of-current-entry ()
1901 (defun outline-end-of-current-entry ()
1902 "Position the point at the end of the current topics' entry."
1904 (outline-show-entry)
1905 (prog1 (outline-pre-next-preface)
1906 (if (and (not (bobp))(looking-at "^$"))
1907 (forward-char -
1))))
1908 ;;;_ > outline-end-of-current-heading ()
1909 (defun outline-end-of-current-heading ()
1911 (outline-beginning-of-current-entry)
1914 (defalias 'outline-end-of-heading
'outline-end-of-current-heading
)
1917 ;;;_ > outline-ascend-to-depth (depth)
1918 (defun outline-ascend-to-depth (depth)
1919 "Ascend to depth DEPTH, returning depth if successful, nil if not."
1920 (if (and (> depth
0)(<= depth
(outline-depth)))
1921 (let ((last-good (point)))
1922 (while (and (< depth
(outline-depth))
1923 (setq last-good
(point))
1924 (outline-beginning-of-level)
1925 (outline-previous-heading)))
1926 (if (= (outline-recent-depth) depth
)
1927 (progn (goto-char outline-recent-prefix-beginning
)
1929 (goto-char last-good
)
1931 (if (interactive-p) (outline-end-of-prefix))))
1932 ;;;_ > outline-ascend ()
1933 (defun outline-ascend ()
1934 "Ascend one level, returning t if successful, nil if not."
1936 (if (outline-beginning-of-level)
1937 (outline-previous-heading))
1938 (if (interactive-p) (outline-end-of-prefix))))
1939 ;;;_ > outline-descend-to-depth (depth)
1940 (defun outline-descend-to-depth (depth)
1941 "Descend to depth DEPTH within current topic.
1943 Returning depth if successful, nil if not."
1944 (let ((start-point (point))
1945 (start-depth (outline-depth)))
1947 (and (> (outline-depth) 0)
1948 (not (= depth
(outline-recent-depth))) ; ... not there yet
1949 (outline-next-heading) ; ... go further
1950 (< start-depth
(outline-recent-depth)))) ; ... still in topic
1951 (if (and (> (outline-depth) 0)
1952 (= (outline-recent-depth) depth
))
1954 (goto-char start-point
)
1957 ;;;_ > outline-up-current-level (arg &optional dont-complain)
1958 (defun outline-up-current-level (arg &optional dont-complain
)
1959 "Move out ARG levels from current visible topic.
1961 Positions on heading line of containing topic. Error if unable to
1962 ascend that far, or nil if unable to ascend but optional arg
1963 DONT-COMPLAIN is non-nil."
1965 (outline-back-to-current-heading)
1966 (let ((present-level (outline-recent-depth))
1970 ;; Loop for iterating arg:
1971 (while (and (> (outline-recent-depth) 1)
1975 (setq last-good
(point))
1976 ;; Loop for going back over current or greater depth:
1977 (while (and (not (< (outline-recent-depth) present-level
))
1978 (or (outline-previous-visible-heading 1)
1979 (not (setq failed present-level
)))))
1980 (setq present-level
(outline-current-depth))
1981 (setq arg
(- arg
1)))
1984 (progn (goto-char last-good
)
1985 (if (interactive-p) (outline-end-of-prefix))
1986 (if (not dont-complain
)
1987 (error "Can't ascend past outermost level")
1988 (if (interactive-p) (outline-end-of-prefix))
1990 (if (interactive-p) (outline-end-of-prefix))
1991 outline-recent-prefix-beginning
)))
1994 ;;;_ > outline-next-sibling (&optional depth backward)
1995 (defun outline-next-sibling (&optional depth backward
)
1996 "Like outline-forward-current-level, but respects invisible topics.
1998 Traverse at optional DEPTH, or current depth if none specified.
2000 Go backward if optional arg BACKWARD is non-nil.
2002 Return depth if successful, nil otherwise."
2004 (if (and backward
(bobp))
2006 (let ((start-depth (or depth
(outline-depth)))
2007 (start-point (point))
2009 (while (and (not (if backward
(bobp) (eobp)))
2010 (if backward
(outline-previous-heading)
2011 (outline-next-heading))
2012 (> (setq last-depth
(outline-recent-depth)) start-depth
)))
2013 (if (and (not (eobp))
2014 (and (> (or last-depth
(outline-depth)) 0)
2015 (= (outline-recent-depth) start-depth
)))
2016 outline-recent-prefix-beginning
2017 (goto-char start-point
)
2018 (if depth
(outline-depth) start-depth
)
2020 ;;;_ > outline-previous-sibling (&optional depth backward)
2021 (defun outline-previous-sibling (&optional depth backward
)
2022 "Like outline-forward-current-level,but backwards & respect invisible topics.
2024 Optional DEPTH specifies depth to traverse, default current depth.
2026 Optional BACKWARD reverses direction.
2028 Return depth if successful, nil otherwise."
2029 (outline-next-sibling depth
(not backward
))
2031 ;;;_ > outline-snug-back ()
2032 (defun outline-snug-back ()
2033 "Position cursor at end of previous topic
2035 Presumes point is at the start of a topic prefix."
2036 (if (or (bobp) (eobp))
2039 (if (or (bobp) (not (memq (preceding-char) '(?
\n ?
\r))))
2042 (if (or (bobp) (not (memq (preceding-char) '(?
\n ?
\r))))
2045 ;;;_ > outline-beginning-of-level ()
2046 (defun outline-beginning-of-level ()
2047 "Go back to the first sibling at this level, visible or not."
2048 (outline-end-of-level 'backward
))
2049 ;;;_ > outline-end-of-level (&optional backward)
2050 (defun outline-end-of-level (&optional backward
)
2051 "Go to the last sibling at this level, visible or not."
2053 (let ((depth (outline-depth)))
2054 (while (outline-previous-sibling depth nil
))
2055 (prog1 (outline-recent-depth)
2056 (if (interactive-p) (outline-end-of-prefix)))))
2057 ;;;_ > outline-next-visible-heading (arg)
2058 (defun outline-next-visible-heading (arg)
2059 "Move to the next ARG'th visible heading line, backward if arg is negative.
2061 Move as far as possible in indicated direction \(beginning or end of
2062 buffer) if headings are exhausted."
2065 (let* ((backward (if (< arg
0) (setq arg
(* -
1 arg
))))
2066 (step (if backward -
1 1))
2067 (start-point (point))
2070 (while (> arg
0) ; limit condition
2071 (while (and (not (if backward
(bobp)(eobp))) ; boundary condition
2072 ;; Move, skipping over all those concealed lines:
2073 (< -
1 (forward-line step
))
2074 (not (setq got
(looking-at outline-regexp
)))))
2075 ;; Register this got, it may be the last:
2076 (if got
(setq prev got
))
2077 (setq arg
(1- arg
)))
2078 (cond (got ; Last move was to a prefix:
2079 (outline-prefix-data (match-beginning 0) (match-end 0))
2080 (outline-end-of-prefix))
2081 (prev ; Last move wasn't, but prev was:
2082 (outline-prefix-data (match-beginning 0) (match-end 0)))
2083 ((not backward
) (end-of-line) nil
))))
2084 ;;;_ > outline-previous-visible-heading (arg)
2085 (defun outline-previous-visible-heading (arg)
2086 "Move to the previous heading line.
2088 With argument, repeats or can move forward if negative.
2089 A heading line is one that starts with a `*' (or that outline-regexp
2092 (outline-next-visible-heading (- arg
)))
2093 ;;;_ > outline-forward-current-level (arg)
2094 (defun outline-forward-current-level (arg)
2095 "Position point at the next heading of the same level.
2097 Takes optional repeat-count, goes backward if count is negative.
2099 Returns resulting position, else nil if none found."
2101 (let ((start-depth (outline-current-depth))
2102 (start-point (point))
2104 (backward (> 0 arg
))
2108 (if (= 0 start-depth
)
2109 (error "No siblings, not in a topic..."))
2110 (if backward
(setq arg
(* -
1 arg
)))
2111 (while (not (or (zerop arg
)
2113 (while (and (not (if backward
(bobp) (eobp)))
2114 (if backward
(outline-previous-visible-heading 1)
2115 (outline-next-visible-heading 1))
2116 (> (setq last-depth
(outline-recent-depth)) start-depth
)))
2117 (if (and last-depth
(= last-depth start-depth
)
2118 (not (if backward
(bobp) (eobp))))
2119 (setq last-good
(point)
2121 (setq at-boundary t
)))
2122 (if (and (not (eobp))
2124 (and (> (or last-depth
(outline-depth)) 0)
2125 (= (outline-recent-depth) start-depth
)))
2126 outline-recent-prefix-beginning
2127 (goto-char last-good
)
2128 (if (not (interactive-p))
2130 (outline-end-of-prefix)
2131 (error "Hit %s level %d topic, traversed %d of %d requested"
2132 (if backward
"first" "last")
2133 (outline-recent-depth)
2134 (- (abs start-arg
) arg
)
2135 (abs start-arg
))))))
2136 ;;;_ > outline-backward-current-level (arg)
2137 (defun outline-backward-current-level (arg)
2138 "Inverse of `outline-forward-current-level'."
2141 (let ((current-prefix-arg (* -
1 arg
)))
2142 (call-interactively 'outline-forward-current-level
))
2143 (outline-forward-current-level (* -
1 arg
))))
2148 ;;;_ > outline-before-change-protect (beg end)
2149 (defun outline-before-change-protect (beg end
)
2150 "Outline before-change hook, regulates changes to concealed text.
2152 Reveal concealed text that would be changed by current command, and
2153 offer user choice to commit or forego the change. Unchanged text is
2154 reconcealed. User has option to have changed text reconcealed.
2156 Undo commands are specially treated - the user is not prompted for
2157 choice, the undoes are always committed (based on presumption that the
2158 things being undone were already subject to this regulation routine),
2159 and undoes always leave the changed stuff exposed.
2161 Changes to concealed regions are ignored while file is being written.
2162 \(This is for the sake of functions that do change the file during
2163 writes, like crypt and zip modes.)
2165 Locally bound in outline buffers to `before-change-functions', which
2166 in emacs 19 is run before any change to the buffer.
2168 Any functions which set [`this-command' to `undo', or which set]
2169 `outline-override-protect' non-nil (as does, eg, outline-flag-chars)
2170 are exempt from this restriction."
2171 (if (and (outline-mode-p)
2172 ; outline-override-protect
2173 ; set by functions that know what
2174 ; they're doing, eg outline internals:
2175 (not outline-override-protect
)
2176 (not outline-during-write-cue
)
2177 (save-match-data ; Preserve operation position state.
2178 ; Both beginning and end chars must
2180 (save-excursion (if (memq this-command
'(newline open-line
))
2181 ;; Compensate for stupid emacs {new,
2182 ;; open-}line display optimization:
2186 (or (outline-hidden-p)
2187 (and (not (= beg end
))
2189 (outline-hidden-p))))))
2191 (if (equal this-command
'undo
)
2192 ;; Allow undo without inhibition.
2193 ;; - Undoing new and open-line hits stupid emacs redisplay
2194 ;; optimization (em 19 cmds.c, ~ line 200).
2195 ;; - Presumably, undoing what was properly protected when
2197 ;; - Undo may be users' only recourse in protection faults.
2198 ;; So, expose what getting changed:
2199 (progn (message "Undo! - exposing concealed target...")
2200 (if (outline-hidden-p)
2201 (outline-show-children))
2204 (rehide-completely (save-excursion (outline-goto-prefix)
2205 (outline-hidden-p)))
2209 (if (condition-case err
2210 ;; Condition case to catch keyboard quits during reads.
2212 ; Give them a peek where
2214 (if (eolp) (setq rehide-place
2215 (outline-goto-prefix)))
2216 (outline-show-entry))
2217 ; Present the message, but...
2218 ; leave the cursor at the location
2219 ; until they respond:
2220 ; Then interpret the response:
2223 (message (concat "Change inside concealed"
2225 "(n or 'y'/'r'eclose)"))
2226 (setq response
(read-char))
2228 (cond ((memq response
'(?r ?R
))
2229 (setq response
'reclose
))
2230 ((memq response
'(?y ?Y ?
))
2232 ((memq response
'(?n ?N
127))
2237 "`r' means `yes, then reclose'")
2239 (t (message "Please answer y, n, or r")
2245 (if (eq response
'reclose
)
2247 (if rehide-place
(goto-char rehide-place
))
2248 (if rehide-completely
2249 (outline-hide-current-entry-completely)
2250 (outline-hide-current-entry)))
2251 (if (outline-ascend-to-depth (1- (outline-recent-depth)))
2252 (outline-show-children)
2253 (outline-show-to-offshoot)))
2255 (if rehide-completely
2257 (if rehide-place
(goto-char rehide-place
))
2258 (outline-hide-current-entry-completely))
2259 (outline-hide-current-entry))
2261 "Change within concealed region prevented.")))))))
2264 ;;;_ = outline-post-goto-bullet
2265 (defvar outline-post-goto-bullet nil
2266 "Outline internal var, for `outline-pre-command-business' hot-spot operation.
2268 When set, tells post-processing to reposition on topic bullet, and
2269 then unset it. Set by outline-pre-command-business when implementing
2270 hot-spot operation, where literal characters typed over a topic bullet
2271 are mapped to the command of the corresponding control-key on the
2273 (make-variable-buffer-local 'outline-post-goto-bullet
)
2274 ;;;_ > outline-post-command-business ()
2275 (defun outline-post-command-business ()
2276 "Outline post-command-hook function.
2278 - Null outline-override-protect, so it's not left open.
2280 - Implement (and clear) outline-post-goto-bullet, for hot-spot
2283 - Massages buffer-undo-list so successive, standard character self-inserts are
2284 aggregated. This kludge compensates for lack of undo bunching when
2285 before-change-functions is used."
2287 ; Apply any external change func:
2288 (if (not (outline-mode-p)) ; In outline-mode.
2290 (setq outline-override-protect nil
)
2291 (if outline-isearch-dynamic-expose
2292 (outline-isearch-rectification))
2293 (if outline-during-write-cue
2294 ;; Was used by outline-before-change-protect, done with it now:
2295 (setq outline-during-write-cue nil
))
2296 ;; Undo bunching business:
2297 (if (and (listp buffer-undo-list
) ; Undo history being kept.
2298 (equal this-command
'self-insert-command
)
2299 (equal last-command
'self-insert-command
))
2300 (let* ((prev-stuff (cdr buffer-undo-list
))
2301 (before-prev-stuff (cdr (cdr prev-stuff
)))
2302 cur-cell cur-from cur-to
2303 prev-cell prev-from prev-to
)
2304 (if (and before-prev-stuff
; Goes back far enough to bother,
2305 (not (car prev-stuff
)) ; and break before current,
2306 (not (car before-prev-stuff
)) ; !and break before prev!
2307 (setq prev-cell
(car (cdr prev-stuff
))) ; contents now,
2308 (setq cur-cell
(car buffer-undo-list
)) ; contents prev.
2310 ;; cur contents denote a single char insertion:
2311 (numberp (setq cur-from
(car cur-cell
)))
2312 (numberp (setq cur-to
(cdr cur-cell
)))
2313 (= 1 (- cur-to cur-from
))
2315 ;; prev contents denote fewer than aggregate-limit
2317 (numberp (setq prev-from
(car prev-cell
)))
2318 (numberp (setq prev-to
(cdr prev-cell
)))
2320 (> outline-undo-aggregation
(- prev-to prev-from
)))
2321 (setq buffer-undo-list
2322 (cons (cons prev-from cur-to
)
2323 (cdr (cdr (cdr buffer-undo-list
))))))))
2324 ;; Implement -post-goto-bullet, if set: (must be after undo business)
2325 (if (and outline-post-goto-bullet
2326 (outline-current-bullet-pos))
2327 (progn (goto-char (outline-current-bullet-pos))
2328 (setq outline-post-goto-bullet nil
)))
2330 ;;;_ > outline-pre-command-business ()
2331 (defun outline-pre-command-business ()
2332 "Outline pre-command-hook function for outline buffers.
2333 Implements special behavior when cursor is on bullet char.
2335 Self-insert characters are reinterpreted control-character references
2336 into the outline-mode-map. The outline-mode post-command hook will
2337 position a cursor that has moved as a result of such reinterpretation,
2338 on the destination topic's bullet, when the cursor wound up in the
2340 The upshot is that you can get easy, single (ie, unmodified) key
2341 outline maneuvering operations by positioning the cursor on the bullet
2342 char. You stay in this mode until you use some regular
2343 cursor-positioning command to relocate the cursor off of a bullet
2346 (if (not (outline-mode-p))
2347 ;; Shouldn't be invoked if not in allout outline-mode, but just in case:
2349 ;; Register isearch status:
2350 (if (and (boundp 'isearch-mode
) isearch-mode
)
2351 (setq outline-pre-was-isearching t
)
2352 (setq outline-pre-was-isearching nil
))
2353 ;; Hot-spot navigation provisions:
2354 (if (and (eq this-command
'self-insert-command
)
2355 (eq (point)(outline-current-bullet-pos)))
2356 (let* ((this-key-num (cond
2357 ((numberp last-command-char
)
2359 ;; XXX Only xemacs has characterp.
2360 ((and (fboundp 'characterp
)
2361 (characterp last-command-char
))
2362 (char-to-int last-command-char
))
2365 (if (zerop this-key-num
)
2367 ; Map upper-register literals
2368 ; to lower register:
2369 (if (<= 96 this-key-num
)
2370 (setq this-key-num
(- this-key-num
32)))
2371 ; Check if we have a literal:
2372 (if (and (<= 64 this-key-num
)
2373 (>= 96 this-key-num
))
2374 (setq mapped-binding
2375 (lookup-key 'outline-mode-map
2376 (concat outline-command-prefix
2377 (char-to-string (- this-key-num
2380 (setq outline-post-goto-bullet t
2381 this-command mapped-binding
)))))))
2382 ;;;_ > outline-find-file-hook ()
2383 (defun outline-find-file-hook ()
2384 "Activate outline-mode when `outline-auto-activation' & `outline-layout' are non-nil.
2386 See `outline-init' for setup instructions."
2387 (if (and outline-auto-activation
2388 (not (outline-mode-p))
2391 ;;;_ > outline-isearch-rectification
2392 (defun outline-isearch-rectification ()
2393 "Rectify outline exposure before, during, or after isearch.
2395 Called as part of outline-post-command-business."
2397 (let ((isearching (and (boundp 'isearch-mode
) isearch-mode
)))
2398 (cond ((and isearching
(not outline-pre-was-isearching
))
2399 (outline-isearch-expose 'start
))
2400 ((and isearching outline-pre-was-isearching
)
2401 (outline-isearch-expose 'continue
))
2402 ((and (not isearching
) outline-pre-was-isearching
)
2403 (outline-isearch-expose 'final
))
2404 ;; Not and wasn't isearching:
2405 (t (setq outline-isearch-prior-pos nil
)
2406 (setq outline-isearch-did-quit nil
)))))
2407 ;;;_ = outline-isearch-was-font-lock
2408 (defvar outline-isearch-was-font-lock
2409 (and (boundp 'font-lock-mode
) font-lock-mode
))
2411 ;;;_ > outline-flag-region (from to flag)
2412 (defmacro outline-flag-region
(from to flag
)
2413 "Hide or show lines from FROM to TO, via emacs selective-display FLAG char.
2414 Ie, text following flag C-m \(carriage-return) is hidden until the
2415 next C-j (newline) char.
2417 Returns the endpoint of the region."
2418 `(let ((buffer-read-only nil
)
2419 (outline-override-protect t
))
2420 (subst-char-in-region ,from
,to
2421 (if (= ,flag ?
\n) ?
\r ?
\n)
2424 ;;;_ > outline-isearch-expose (mode)
2425 (defun outline-isearch-expose (mode)
2426 "Mode is either 'clear, 'start, 'continue, or 'final."
2427 ;; outline-isearch-prior-pos encodes exposure status of prior pos:
2428 ;; (pos was-vis header-pos end-pos)
2429 ;; pos - point of concern
2430 ;; was-vis - t, else 'topic if entire topic was exposed, 'entry otherwise
2431 ;; Do reclosure or prior pos, as necessary:
2432 (if (eq mode
'start
)
2433 (setq outline-isearch-was-font-lock
(and (boundp 'font-lock-mode
)
2436 (if (eq mode
'final
)
2437 (setq font-lock-mode outline-isearch-was-font-lock
))
2438 (if (and outline-isearch-prior-pos
2439 (listp outline-isearch-prior-pos
))
2440 ;; Conceal prior peek:
2441 (outline-flag-region (car (cdr outline-isearch-prior-pos
))
2442 (car (cdr (cdr outline-isearch-prior-pos
)))
2444 (if (outline-visible-p)
2445 (setq outline-isearch-prior-pos nil
)
2446 (if (not (eq mode
'final
))
2447 (setq outline-isearch-prior-pos
(cons (point) (outline-show-entry)))
2448 (if outline-isearch-did-quit
2450 (setq outline-isearch-prior-pos nil
)
2451 (outline-show-children))))
2452 (setq outline-isearch-did-quit nil
))
2453 ;;;_ > outline-enwrap-isearch ()
2454 (defun outline-enwrap-isearch ()
2455 "Impose outline-mode isearch-abort wrapper for dynamic exposure in isearch.
2457 The function checks to ensure that the rebinding is done only once."
2459 (add-hook 'isearch-mode-end-hook
'outline-isearch-rectification
)
2460 (if (fboundp 'outline-real-isearch-abort
)
2463 ; Ensure load of isearch-mode:
2464 (if (or (and (fboundp 'isearch-mode
)
2465 (fboundp 'isearch-abort
))
2466 (condition-case error
2467 (load-library "isearch-mode")
2468 ('file-error
(message
2469 "Skipping isearch-mode provisions - %s '%s'"
2471 (car (cdr (cdr error
))))
2473 ;; Inhibit subsequent tries and return nil:
2474 (setq outline-isearch-dynamic-expose nil
))))
2475 ;; Isearch-mode loaded, encapsulate specific entry points for
2476 ;; outline dynamic-exposure business:
2478 ;; stash crucial isearch-mode funcs under known, private
2479 ;; names, then register wrapper functions under the old
2480 ;; names, in their stead:
2481 (fset 'outline-real-isearch-abort
(symbol-function 'isearch-abort
))
2482 (fset 'isearch-abort
'outline-isearch-abort
)))))
2483 ;;;_ > outline-isearch-abort ()
2484 (defun outline-isearch-abort ()
2485 "Wrapper for outline-real-isearch-abort \(which see), to register
2488 (setq outline-isearch-did-quit nil
)
2489 (condition-case what
2490 (outline-real-isearch-abort)
2491 ('quit
(setq outline-isearch-did-quit t
)
2492 (signal 'quit nil
))))
2494 ;;; Prevent unnecessary font-lock while isearching!
2495 (defvar isearch-was-font-locking nil
)
2496 (defun isearch-inhibit-font-lock ()
2497 "Inhibit font-lock while isearching - for use on isearch-mode-hook."
2498 (if (and (outline-mode-p) (boundp 'font-lock-mode
) font-lock-mode
)
2499 (setq isearch-was-font-locking t
2500 font-lock-mode nil
)))
2501 (add-hook 'isearch-mode-hook
'isearch-inhibit-font-lock
)
2502 (defun isearch-reenable-font-lock ()
2503 "Reenable font-lock after isearching - for use on isearch-mode-end-hook."
2504 (if (and (boundp 'font-lock-mode
) font-lock-mode
)
2505 (if (and (outline-mode-p) isearch-was-font-locking
)
2506 (setq isearch-was-font-locking nil
2507 font-lock-mode t
))))
2508 (add-hook 'isearch-mode-end-hook
'isearch-reenable-font-lock
)
2510 ;;;_ - Topic Format Assessment
2511 ;;;_ > outline-solicit-alternate-bullet (depth &optional current-bullet)
2512 (defun outline-solicit-alternate-bullet (depth &optional current-bullet
)
2514 "Prompt for and return a bullet char as an alternative to the current one.
2516 Offer one suitable for current depth DEPTH as default."
2518 (let* ((default-bullet (or (and (stringp current-bullet
) current-bullet
)
2519 (outline-bullet-for-depth depth
)))
2520 (sans-escapes (regexp-sans-escapes outline-bullets-string
))
2523 (goto-char (outline-current-bullet-pos))
2524 (setq choice
(solicit-char-in-string
2525 (format "Select bullet: %s ('%s' default): "
2531 (if (string= choice
"") default-bullet choice
))
2533 ;;;_ > outline-distinctive-bullet (bullet)
2534 (defun outline-distinctive-bullet (bullet)
2535 "True if bullet is one of those on outline-distinctive-bullets-string."
2536 (string-match (regexp-quote bullet
) outline-distinctive-bullets-string
))
2537 ;;;_ > outline-numbered-type-prefix (&optional prefix)
2538 (defun outline-numbered-type-prefix (&optional prefix
)
2539 "True if current header prefix bullet is numbered bullet."
2540 (and outline-numbered-bullet
2541 (string= outline-numbered-bullet
2543 (outline-get-prefix-bullet prefix
)
2544 (outline-get-bullet)))))
2545 ;;;_ > outline-bullet-for-depth (&optional depth)
2546 (defun outline-bullet-for-depth (&optional depth
)
2547 "Return outline topic bullet suited to optional DEPTH, or current depth."
2548 ;; Find bullet in plain-bullets-string modulo DEPTH.
2549 (if outline-stylish-prefixes
2550 (char-to-string (aref outline-plain-bullets-string
2551 (%
(max 0 (- depth
2))
2552 outline-plain-bullets-string-len
)))
2553 outline-primary-bullet
)
2556 ;;;_ - Topic Production
2557 ;;;_ > outline-make-topic-prefix (&optional prior-bullet
2558 (defun outline-make-topic-prefix (&optional prior-bullet
2564 ;; Depth null means use current depth, non-null means we're either
2565 ;; opening a new topic after current topic, lower or higher, or we're
2566 ;; changing level of current topic.
2567 ;; Solicit dominates specified bullet-char.
2569 "Generate a topic prefix suitable for optional arg DEPTH, or current depth.
2571 All the arguments are optional.
2573 PRIOR-BULLET indicates the bullet of the prefix being changed, or
2574 nil if none. This bullet may be preserved (other options
2575 notwithstanding) if it is on the outline-distinctive-bullets-string,
2578 Second arg NEW indicates that a new topic is being opened after the
2579 topic at point, if non-nil. Default bullet for new topics, eg, may
2580 be set (contingent to other args) to numbered bullets if previous
2581 sibling is one. The implication otherwise is that the current topic
2582 is being adjusted - shifted or rebulleted - and we don't consider
2583 bullet or previous sibling.
2585 Third arg DEPTH forces the topic prefix to that depth, regardless of
2586 the current topics' depth.
2588 If SOLICIT is non-nil, then the choice of bullet is solicited from
2589 user. If it's a character, then that character is offered as the
2590 default, otherwise the one suited to the context \(according to
2591 distinction or depth) is offered. \(This overrides other options,
2592 including, eg, a distinctive PRIOR-BULLET.) If non-nil, then the
2593 context-specific bullet is used.
2595 Fifth arg, NUMBER-CONTROL, matters only if `outline-numbered-bullet'
2596 is non-nil *and* soliciting was not explicitly invoked. Then
2597 NUMBER-CONTROL non-nil forces prefix to either numbered or
2598 denumbered format, depending on the value of the sixth arg, INDEX.
2600 \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...)
2602 If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then
2603 the prefix of the topic is forced to be numbered. Non-nil
2604 NUMBER-CONTROL and nil INDEX forces non-numbered format on the
2605 bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means
2606 that the index for the numbered prefix will be derived, by counting
2607 siblings back to start of level. If INDEX is a number, then that
2608 number is used as the index for the numbered prefix (allowing, eg,
2609 sequential renumbering to not require this function counting back the
2610 index for each successive sibling)."
2612 ;; The options are ordered in likely frequence of use, most common
2613 ;; highest, least lowest. Ie, more likely to be doing prefix
2614 ;; adjustments than soliciting, and yet more than numbering.
2615 ;; Current prefix is least dominant, but most likely to be commonly
2621 (depth (or depth
(outline-depth)))
2622 (header-lead outline-header-prefix
)
2625 ;; Getting value for bullet char is practically the whole job:
2628 ; Simplest situation - level 1:
2629 ((<= depth
1) (setq header-lead
"") outline-primary-bullet
)
2630 ; Simple, too: all asterisks:
2631 (outline-old-style-prefixes
2632 ;; Cheat - make body the whole thing, null out header-lead and
2634 (setq body
(make-string depth
2635 (string-to-char outline-primary-bullet
)))
2636 (setq header-lead
"")
2639 ;; (Neither level 1 nor old-style, so we're space padding.
2640 ;; Sneak it in the condition of the next case, whatever it is.)
2642 ;; Solicitation overrides numbering and other cases:
2643 ((progn (setq body
(make-string (- depth
2) ?\
))
2644 ;; The actual condition:
2646 (let* ((got (outline-solicit-alternate-bullet depth solicit
)))
2647 ;; Gotta check whether we're numbering and got a numbered bullet:
2648 (setq numbering
(and outline-numbered-bullet
2649 (not (and number-control
(not index
)))
2650 (string= got outline-numbered-bullet
)))
2651 ;; Now return what we got, regardless:
2654 ;; Numbering invoked through args:
2655 ((and outline-numbered-bullet number-control
)
2656 (if (setq numbering
(not (setq denumbering
(not index
))))
2657 outline-numbered-bullet
2658 (if (and prior-bullet
2659 (not (string= outline-numbered-bullet
2662 (outline-bullet-for-depth depth
))))
2664 ;;; Neither soliciting nor controlled numbering ;;;
2665 ;;; (may be controlled denumbering, tho) ;;;
2667 ;; Check wrt previous sibling:
2668 ((and new
; only check for new prefixes
2669 (<= depth
(outline-depth))
2670 outline-numbered-bullet
; ... & numbering enabled
2672 (let ((sibling-bullet
2674 ;; Locate correct sibling:
2675 (or (>= depth
(outline-depth))
2676 (outline-ascend-to-depth depth
))
2677 (outline-get-bullet))))
2678 (if (and sibling-bullet
2679 (string= outline-numbered-bullet sibling-bullet
))
2680 (setq numbering sibling-bullet
)))))
2682 ;; Distinctive prior bullet?
2684 (outline-distinctive-bullet prior-bullet
)
2685 ;; Either non-numbered:
2686 (or (not (and outline-numbered-bullet
2687 (string= prior-bullet outline-numbered-bullet
)))
2688 ;; or numbered, and not denumbering:
2689 (setq numbering
(not denumbering
)))
2693 ;; Else, standard bullet per depth:
2694 ((outline-bullet-for-depth depth
)))))
2700 (format "%d" (cond ((and index
(numberp index
)) index
)
2701 (new (1+ (outline-sibling-index depth
)))
2702 ((outline-sibling-index))))))
2705 ;;;_ > outline-open-topic (relative-depth &optional before use_sib_bullet)
2706 (defun outline-open-topic (relative-depth &optional before use_sib_bullet
)
2707 "Open a new topic at depth DEPTH.
2709 New topic is situated after current one, unless optional flag BEFORE
2710 is non-nil, or unless current line is complete empty (not even
2711 whitespace), in which case open is done on current line.
2713 If USE_SIB_BULLET is true, use the bullet of the prior sibling.
2717 - Creation of new topics is with respect to the visible topic
2718 containing the cursor, regardless of intervening concealed ones.
2720 - New headers are generally created after/before the body of a
2721 topic. However, they are created right at cursor location if the
2722 cursor is on a blank line, even if that breaks the current topic
2723 body. This is intentional, to provide a simple means for
2724 deliberately dividing topic bodies.
2726 - Double spacing of topic lists is preserved. Also, the first
2727 level two topic is created double-spaced (and so would be
2728 subsequent siblings, if that's left intact). Otherwise,
2729 single-spacing is used.
2731 - Creation of sibling or nested topics is with respect to the topic
2732 you're starting from, even when creating backwards. This way you
2733 can easily create a sibling in front of the current topic without
2734 having to go to its preceding sibling, and then open forward
2737 (let* ((depth (+ (outline-current-depth) relative-depth
))
2738 (opening-on-blank (if (looking-at "^\$")
2739 (not (setq before nil
))))
2740 opening-numbered
; Will get while computing ref-topic, below
2741 ref-depth
; Will get while computing ref-topic, below
2742 ref-bullet
; Will get while computing ref-topic, next
2743 (ref-topic (save-excursion
2744 (cond ((< relative-depth
0)
2745 (outline-ascend-to-depth depth
))
2746 ((>= relative-depth
1) nil
)
2747 (t (outline-back-to-current-heading)))
2748 (setq ref-depth
(outline-recent-depth))
2750 (if (> outline-recent-prefix-end
1)
2751 (outline-recent-bullet)
2753 (setq opening-numbered
2755 (and outline-numbered-bullet
2756 (or (<= relative-depth
0)
2757 (outline-descend-to-depth depth
))
2758 (if (outline-numbered-type-prefix)
2759 outline-numbered-bullet
))))
2764 (if (not opening-on-blank
)
2765 ; Positioning and vertical
2766 ; padding - only if not
2769 (goto-char ref-topic
)
2770 (setq dbl-space
; Determine double space action:
2771 (or (and (<= relative-depth
0) ; not descending;
2773 ;; at b-o-b or preceded by a blank line?
2774 (or (> 0 (forward-line -
1))
2775 (looking-at "^\\s-*$")
2778 ;; succeeded by a blank line?
2779 (outline-end-of-current-subtree)
2781 (and (= ref-depth
1)
2785 ;; Don't already have following
2786 ;; vertical padding:
2787 (not (outline-pre-next-preface)))))))
2789 ; Position to prior heading,
2790 ; if inserting backwards, and
2791 ; not going outwards:
2792 (if (and before
(>= relative-depth
0))
2793 (progn (outline-back-to-current-heading)
2794 (setq doing-beginning
(bobp))
2796 (outline-previous-heading)))
2797 (if (and before
(bobp))
2798 (outline-unprotected (open-line 1))))
2800 (if (<= relative-depth
0)
2801 ;; Not going inwards, don't snug up:
2803 (outline-unprotected (open-line (if dbl-space
2 1)))
2805 (progn (end-of-line)
2806 (outline-pre-next-preface)
2807 (while (= ?
\r (following-char))
2809 (if (not (looking-at "^$"))
2810 (outline-unprotected (open-line 1))))
2811 (outline-end-of-current-subtree)))
2812 ;; Going inwards - double-space if first offspring is,
2813 ;; otherwise snug up.
2814 (end-of-line) ; So we skip any concealed progeny.
2815 (outline-pre-next-preface)
2817 ;; Blank lines between current header body and next
2818 ;; header - get to last substantive (non-white-space)
2820 (re-search-backward "[^ \t\n]" nil t
))
2822 (outline-next-heading)
2823 (if (> (outline-recent-depth) ref-depth
)
2824 ;; This is an offspring.
2825 (progn (forward-line -
1)
2826 (looking-at "^\\s-*$"))))
2827 (progn (forward-line 1)
2828 (outline-unprotected (open-line 1))))
2830 ;;(if doing-beginning (goto-char doing-beginning))
2832 (progn (if (and (not (> depth ref-depth
))
2834 (outline-unprotected (open-line 1))
2835 (if (> depth ref-depth
)
2836 (outline-unprotected (newline 1))
2838 (outline-unprotected (open-line 1))
2840 (outline-unprotected (newline 1))))))
2842 (outline-unprotected (newline 1)))
2843 (if (and (not (eobp))
2847 (insert (concat (outline-make-topic-prefix opening-numbered
2852 ;;(if doing-beginning (save-excursion (newline (if dbl-space 2 1))))
2855 (outline-rebullet-heading (and use_sib_bullet ref-bullet
);;; solicit
2857 nil
;;; number-control
2862 ;;;_ . open-topic contingencies
2863 ;;;_ ; base topic - one from which open was issued
2864 ;;;_ , beginning char
2865 ;;;_ , amount of space before will be used, unless opening in place
2866 ;;;_ , end char will be used, unless opening before (and it still may)
2867 ;;;_ ; absolute depth of new topic
2868 ;;;_ ! insert in place - overrides most stuff
2869 ;;;_ ; relative depth of new re base
2870 ;;;_ ; before or after base topic
2871 ;;;_ ; spacing around topic, if any, prior to new topic and at same depth
2872 ;;;_ ; buffer boundaries - special provisions for beginning and end ob
2873 ;;;_ ; level 1 topics have special provisions also - double space.
2874 ;;;_ ; location of new topic
2875 ;;;_ > outline-open-subtopic (arg)
2876 (defun outline-open-subtopic (arg)
2877 "Open new topic header at deeper level than the current one.
2879 Negative universal arg means to open deeper, but place the new topic
2880 prior to the current one."
2882 (outline-open-topic 1 (> 0 arg
)))
2883 ;;;_ > outline-open-sibtopic (arg)
2884 (defun outline-open-sibtopic (arg)
2885 "Open new topic header at same level as the current one.
2887 Positive universal arg means to use the bullet of the prior sibling.
2889 Negative universal arg means to place the new topic prior to the current
2892 (outline-open-topic 0 (> 0 arg
) (< 1 arg
)))
2893 ;;;_ > outline-open-supertopic (arg)
2894 (defun outline-open-supertopic (arg)
2895 "Open new topic header at shallower level than the current one.
2897 Negative universal arg means to open shallower, but place the new
2898 topic prior to the current one."
2901 (outline-open-topic -
1 (> 0 arg
)))
2903 ;;;_ - Outline Alteration
2904 ;;;_ : Topic Modification
2905 ;;;_ = outline-former-auto-filler
2906 (defvar outline-former-auto-filler nil
2907 "Name of modal fill function being wrapped by outline-auto-fill.")
2908 ;;;_ > outline-auto-fill ()
2909 (defun outline-auto-fill ()
2910 "Outline-mode autofill function.
2912 Maintains outline hanging topic indentation if
2913 `outline-use-hanging-indents' is set."
2914 (let ((fill-prefix (if outline-use-hanging-indents
2915 ;; Check for topic header indentation:
2918 (if (looking-at outline-regexp
)
2919 ;; ... construct indentation to account for
2920 ;; length of topic prefix:
2921 (make-string (progn (outline-end-of-prefix)
2924 (if (or outline-former-auto-filler outline-use-hanging-indents
)
2926 ;;;_ > outline-reindent-body (old-depth new-depth &optional number)
2927 (defun outline-reindent-body (old-depth new-depth
&optional number
)
2928 "Reindent body lines which were indented at old-depth to new-depth.
2930 Optional arg NUMBER indicates numbering is being added, and it must
2933 Note that refill of indented paragraphs is not done."
2936 (outline-end-of-prefix)
2937 (let* ((new-margin (current-column))
2938 excess old-indent-begin old-indent-end
2940 ;; We want the column where the header-prefix text started
2941 ;; *before* the prefix was changed, so we infer it relative
2942 ;; to the new margin and the shift in depth:
2943 (old-margin (+ old-depth
(- new-margin new-depth
))))
2945 ;; Process lines up to (but excluding) next topic header:
2946 (outline-unprotected
2949 (and (re-search-forward "[\n\r]\\(\\s-*\\)"
2952 ;; Register the indent data, before we reset the
2953 ;; match data with a subsequent `looking-at':
2954 (setq old-indent-begin
(match-beginning 1)
2955 old-indent-end
(match-end 1))
2956 (not (looking-at outline-regexp
)))
2957 (if (> 0 (setq excess
(- (current-column)
2959 ;; Text starts left of old margin - don't adjust:
2961 ;; Text was hanging at or right of old left margin -
2962 ;; reindent it, preserving its existing indentation
2963 ;; beyond the old margin:
2964 (delete-region old-indent-begin old-indent-end
)
2965 (indent-to (+ new-margin excess
)))))))))
2966 ;;;_ > outline-rebullet-current-heading (arg)
2967 (defun outline-rebullet-current-heading (arg)
2968 "Solicit new bullet for current visible heading."
2970 (let ((initial-col (current-column))
2971 (on-bullet (eq (point)(outline-current-bullet-pos)))
2972 (backwards (if (< arg
0)
2973 (setq arg
(* arg -
1)))))
2975 (save-excursion (outline-back-to-current-heading)
2976 (outline-end-of-prefix)
2977 (outline-rebullet-heading t
;;; solicit
2979 nil
;;; number-control
2981 t
)) ;;; do-successors
2985 (setq initial-col nil
) ; Override positioning back to init col
2987 (outline-next-visible-heading 1)
2988 (outline-goto-prefix)
2989 (outline-next-visible-heading -
1))))
2991 (cond (on-bullet (goto-char (outline-current-bullet-pos)))
2992 (initial-col (move-to-column initial-col
)))))
2993 ;;;_ > outline-rebullet-heading (&optional solicit ...)
2994 (defun outline-rebullet-heading (&optional solicit
3000 "Adjust bullet of current topic prefix.
3002 All args are optional.
3004 If SOLICIT is non-nil, then the choice of bullet is solicited from
3005 user. If it's a character, then that character is offered as the
3006 default, otherwise the one suited to the context \(according to
3007 distinction or depth) is offered. If non-nil, then the
3008 context-specific bullet is just used.
3010 Second arg DEPTH forces the topic prefix to that depth, regardless
3011 of the topic's current depth.
3013 Third arg NUMBER-CONTROL can force the prefix to or away from
3014 numbered form. It has effect only if `outline-numbered-bullet' is
3015 non-nil and soliciting was not explicitly invoked (via first arg).
3016 Its effect, numbering or denumbering, then depends on the setting
3017 of the forth arg, INDEX.
3019 If NUMBER-CONTROL is non-nil and forth arg INDEX is nil, then the
3020 prefix of the topic is forced to be non-numbered. Null index and
3021 non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and
3022 non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil
3023 INDEX is a number, then that number is used for the numbered
3024 prefix. Non-nil and non-number means that the index for the
3025 numbered prefix will be derived by outline-make-topic-prefix.
3027 Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding
3030 Cf vars `outline-stylish-prefixes', `outline-old-style-prefixes',
3031 and `outline-numbered-bullet', which all affect the behavior of
3034 (let* ((current-depth (outline-depth))
3035 (new-depth (or new-depth current-depth
))
3036 (mb outline-recent-prefix-beginning
)
3037 (me outline-recent-prefix-end
)
3038 (current-bullet (buffer-substring (- me
1) me
))
3039 (new-prefix (outline-make-topic-prefix current-bullet
3046 ;; Is new one is identical to old?
3047 (if (and (= current-depth new-depth
)
3048 (string= current-bullet
3049 (substring new-prefix
(1- (length new-prefix
)))))
3053 ;; New prefix probably different from old:
3054 ; get rid of old one:
3055 (outline-unprotected (delete-region mb me
))
3057 ; Dispense with number if
3058 ; numbered-bullet prefix:
3059 (if (and outline-numbered-bullet
3060 (string= outline-numbered-bullet current-bullet
)
3061 (looking-at "[0-9]+"))
3062 (outline-unprotected
3063 (delete-region (match-beginning 0)(match-end 0))))
3065 ; Put in new prefix:
3066 (outline-unprotected (insert new-prefix
))
3068 ;; Reindent the body if elected and margin changed:
3069 (if (and outline-reindent-bodies
3070 (not (= new-depth current-depth
)))
3071 (outline-reindent-body current-depth new-depth
))
3073 ;; Recursively rectify successive siblings of orig topic if
3074 ;; caller elected for it:
3077 (while (outline-next-sibling new-depth nil
)
3079 (cond ((numberp index
) (1+ index
))
3080 ((not number-control
) (outline-sibling-index))))
3081 (if (outline-numbered-type-prefix)
3082 (outline-rebullet-heading nil
;;; solicit
3083 new-depth
;;; new-depth
3084 number-control
;;; number-control
3086 nil
))))) ;;;(dont!)do-successors
3087 ) ; (if (and (= current-depth new-depth)...))
3088 ) ; let* ((current-depth (outline-depth))...)
3090 ;;;_ > outline-rebullet-topic (arg)
3091 (defun outline-rebullet-topic (arg)
3092 "Like outline-rebullet-topic-grunt, but start from topic visible at point.
3094 Descends into invisible as well as visible topics, however.
3096 With repeat count, shift topic depth by that amount."
3098 (let ((start-col (current-column))
3102 (cond ((null arg
) (setq arg
0))
3103 ((listp arg
) (setq arg
(car arg
))))
3104 ;; Fill the user in, in case we're shifting a big topic:
3105 (if (not (zerop arg
)) (message "Shifting..."))
3106 (outline-back-to-current-heading)
3107 (if (<= (+ (outline-recent-depth) arg
) 0)
3108 (error "Attempt to shift topic below level 1"))
3109 (outline-rebullet-topic-grunt arg
)
3110 (if (not (zerop arg
)) (message "Shifting... done.")))
3111 (move-to-column (max 0 (+ start-col arg
)))))
3112 ;;;_ > outline-rebullet-topic-grunt (&optional relative-depth ...)
3113 (defun outline-rebullet-topic-grunt (&optional relative-depth
3119 "Rebullet the topic at point, visible or invisible, and all
3120 contained subtopics. See outline-rebullet-heading for rebulleting
3123 All arguments are optional.
3125 First arg RELATIVE-DEPTH means to shift the depth of the entire
3128 The rest of the args are for internal recursive use by the function
3129 itself. The are STARTING-DEPTH, STARTING-POINT, and INDEX."
3131 (let* ((relative-depth (or relative-depth
0))
3132 (new-depth (outline-depth))
3133 (starting-depth (or starting-depth new-depth
))
3134 (on-starting-call (null starting-point
))
3136 ;; Leave index null on starting call, so rebullet-heading
3137 ;; calculates it at what might be new depth:
3138 (and (or (zerop relative-depth
)
3139 (not on-starting-call
))
3140 (outline-sibling-index))))
3141 (moving-outwards (< 0 relative-depth
))
3142 (starting-point (or starting-point
(point))))
3144 ;; Sanity check for excessive promotion done only on starting call:
3145 (and on-starting-call
3147 (> 0 (+ starting-depth relative-depth
))
3148 (error "Attempt to shift topic out beyond level 1")) ;;; ====>
3150 (cond ((= starting-depth new-depth
)
3151 ;; We're at depth to work on this one:
3152 (outline-rebullet-heading nil
;;; solicit
3153 (+ starting-depth
;;; starting-depth
3157 ;; Every contained topic will get hit,
3158 ;; and we have to get to outside ones
3160 nil
) ;;; do-successors
3161 ;; ... and work on subsequent ones which are at greater depth:
3163 (outline-next-heading)
3164 (while (and (not (eobp))
3165 (< starting-depth
(outline-recent-depth)))
3166 (setq index
(1+ index
))
3167 (outline-rebullet-topic-grunt relative-depth
;;; relative-depth
3168 (1+ starting-depth
);;;starting-depth
3169 starting-point
;;; starting-point
3172 ((< starting-depth new-depth
)
3173 ;; Rare case - subtopic more than one level deeper than parent.
3174 ;; Treat this one at an even deeper level:
3175 (outline-rebullet-topic-grunt relative-depth
;;; relative-depth
3176 new-depth
;;; starting-depth
3177 starting-point
;;; starting-point
3180 (if on-starting-call
3182 ;; Rectify numbering of former siblings of the adjusted topic,
3183 ;; if topic has changed depth
3184 (if (or do-successors
3185 (and (not (zerop relative-depth
))
3186 (or (= (outline-recent-depth) starting-depth
)
3187 (= (outline-recent-depth) (+ starting-depth
3189 (outline-rebullet-heading nil nil nil nil t
))
3190 ;; Now rectify numbering of new siblings of the adjusted topic,
3191 ;; if depth has been changed:
3192 (progn (goto-char starting-point
)
3193 (if (not (zerop relative-depth
))
3194 (outline-rebullet-heading nil nil nil nil t
)))))
3197 ;;;_ > outline-renumber-to-depth (&optional depth)
3198 (defun outline-renumber-to-depth (&optional depth
)
3199 "Renumber siblings at current depth.
3201 Affects superior topics if optional arg DEPTH is less than current depth.
3203 Returns final depth."
3205 ;; Proceed by level, processing subsequent siblings on each,
3206 ;; ascending until we get shallower than the start depth:
3208 (let ((ascender (outline-depth))
3210 (while (and (not (eobp))
3212 (>= (outline-recent-depth) depth
)
3213 (>= ascender depth
))
3214 ; Skip over all topics at
3215 ; lesser depths, which can not
3216 ; have been disturbed:
3217 (while (and (not (setq was-eobp
(eobp)))
3218 (> (outline-recent-depth) ascender
))
3219 (outline-next-heading))
3220 ; Prime ascender for ascension:
3221 (setq ascender
(1- (outline-recent-depth)))
3222 (if (>= (outline-recent-depth) depth
)
3223 (outline-rebullet-heading nil
;;; solicit
3225 nil
;;; number-control
3227 t
)) ;;; do-successors
3228 (if was-eobp
(goto-char (point-max)))))
3229 (outline-recent-depth))
3230 ;;;_ > outline-number-siblings (&optional denumber)
3231 (defun outline-number-siblings (&optional denumber
)
3232 "Assign numbered topic prefix to this topic and its siblings.
3234 With universal argument, denumber - assign default bullet to this
3235 topic and its siblings.
3237 With repeated universal argument (`^U^U'), solicit bullet for each
3238 rebulleting each topic at this level."
3243 (outline-back-to-current-heading)
3244 (outline-beginning-of-level)
3245 (let ((depth (outline-recent-depth))
3246 (index (if (not denumber
) 1))
3247 (use-bullet (equal '(16) denumber
))
3250 (outline-rebullet-heading use-bullet
;;; solicit
3252 t
;;; number-control
3254 nil
) ;;; do-successors
3255 (if index
(setq index
(1+ index
)))
3256 (setq more
(outline-next-sibling depth nil
))))))
3257 ;;;_ > outline-shift-in (arg)
3258 (defun outline-shift-in (arg)
3259 "Increase depth of current heading and any topics collapsed within it."
3261 (outline-rebullet-topic arg
))
3262 ;;;_ > outline-shift-out (arg)
3263 (defun outline-shift-out (arg)
3264 "Decrease depth of current heading and any topics collapsed within it."
3266 (outline-rebullet-topic (* arg -
1)))
3267 ;;;_ : Surgery (kill-ring) functions with special provisions for outlines:
3268 ;;;_ > outline-kill-line (&optional arg)
3269 (defun outline-kill-line (&optional arg
)
3270 "Kill line, adjusting subsequent lines suitably for outline mode."
3273 (if (not (and (outline-mode-p) ; active outline mode,
3274 outline-numbered-bullet
; numbers may need adjustment,
3275 (bolp) ; may be clipping topic head,
3276 (looking-at outline-regexp
))) ; are clipping topic head.
3277 ;; Above conditions do not obtain - just do a regular kill:
3279 ;; Ah, have to watch out for adjustments:
3280 (let* ((depth (outline-depth)))
3283 ; Provide some feedback:
3286 ; Start with the topic
3287 ; following killed line:
3288 (if (not (looking-at outline-regexp
))
3289 (outline-next-heading))
3290 (outline-renumber-to-depth depth
)))))
3291 ;;;_ > outline-kill-topic ()
3292 (defun outline-kill-topic ()
3293 "Kill topic together with subtopics.
3295 Leaves primary topic's trailing vertical whitespace, if any."
3297 ;; Some finagling is done to make complex topic kills appear faster
3298 ;; than they actually are. A redisplay is performed immediately
3299 ;; after the region is disposed of, though the renumbering process
3300 ;; has yet to be performed. This means that there may appear to be
3301 ;; a lag *after* the kill has been performed.
3304 (let* ((beg (prog1 (outline-back-to-current-heading)(beginning-of-line)))
3305 (depth (outline-recent-depth)))
3306 (outline-end-of-current-subtree)
3308 (if (or (not (looking-at "^$"))
3309 ;; A blank line - cut it with this topic *unless* this
3310 ;; is the last topic at this level, in which case
3311 ;; we'll leave the blank line as part of the
3312 ;; containing topic:
3314 (and (outline-next-heading)
3315 (>= (outline-recent-depth) depth
))))
3318 (kill-region beg
(point))
3321 (outline-renumber-to-depth depth
))))
3322 ;;;_ > outline-yank-processing ()
3323 (defun outline-yank-processing (&optional arg
)
3325 "Incidental outline-specific business to be done just after text yanks.
3327 Does depth adjustment of yanked topics, when:
3329 1 the stuff being yanked starts with a valid outline header prefix, and
3330 2 it is being yanked at the end of a line which consists of only a valid
3333 Also, adjusts numbering of subsequent siblings when appropriate.
3335 Depth adjustment alters the depth of all the topics being yanked
3336 the amount it takes to make the first topic have the depth of the
3337 header into which it's being yanked.
3339 The point is left in front of yanked, adjusted topics, rather than
3340 at the end (and vice-versa with the mark). Non-adjusted yanks,
3341 however, are left exactly like normal, non-outline-specific yanks."
3344 ; Get to beginning, leaving
3345 ; region around subject:
3346 (if (< (my-mark-marker t
) (point))
3347 (exchange-point-and-mark))
3348 (let* ((subj-beg (point))
3349 (subj-end (my-mark-marker t
))
3350 ;; 'resituate' if yanking an entire topic into topic header:
3351 (resituate (and (outline-e-o-prefix-p)
3352 (looking-at (concat "\\(" outline-regexp
"\\)"))
3353 (outline-prefix-data (match-beginning 1)
3355 ;; `rectify-numbering' if resituating (where several topics may
3356 ;; be resituating) or yanking a topic into a topic slot (bol):
3357 (rectify-numbering (or resituate
3358 (and (bolp) (looking-at outline-regexp
)))))
3360 ; The yanked stuff is a topic:
3361 (let* ((prefix-len (- (match-end 1) subj-beg
))
3362 (subj-depth (outline-recent-depth))
3363 (prefix-bullet (outline-recent-bullet))
3365 ;; Nil if adjustment unnecessary, otherwise depth to which
3366 ;; adjustment should be made:
3368 (and (goto-char subj-end
)
3370 (goto-char subj-beg
)
3371 (and (looking-at outline-regexp
)
3374 (not (= (point) subj-beg
)))
3375 (looking-at outline-regexp
)
3376 (outline-prefix-data (match-beginning 0)
3378 (outline-recent-depth))))
3381 (setq rectify-numbering outline-numbered-bullet
)
3383 ; Do the adjustment:
3385 (message "... yanking") (sit-for 0)
3387 (narrow-to-region subj-beg subj-end
)
3388 ; Trim off excessive blank
3389 ; line at end, if any:
3390 (goto-char (point-max))
3391 (if (looking-at "^$")
3392 (outline-unprotected (delete-char -
1)))
3393 ; Work backwards, with each
3395 ; successively excluding the
3396 ; last processed topic from
3397 ; the narrow region:
3399 (outline-back-to-current-heading)
3400 ; go as high as we can in each bunch:
3401 (while (outline-ascend-to-depth (1- (outline-depth))))
3403 (outline-rebullet-topic-grunt (- adjust-to-depth
3406 (if (setq more
(not (bobp)))
3409 (narrow-to-region subj-beg
(point))))))
3411 ;; Preserve new bullet if it's a distinctive one, otherwise
3413 (if (string-match (regexp-quote prefix-bullet
)
3414 outline-distinctive-bullets-string
)
3415 ; Delete from bullet of old to
3416 ; before bullet of new:
3419 (delete-region (point) subj-beg
)
3420 (set-marker (my-mark-marker t
) subj-end
)
3421 (goto-char subj-beg
)
3422 (outline-end-of-prefix))
3423 ; Delete base subj prefix,
3425 (delete-region (point) (+ (point)
3427 (- adjust-to-depth subj-depth
)))
3428 ; and delete residual subj
3429 ; prefix digits and space:
3430 (while (looking-at "[0-9]") (delete-char 1))
3431 (if (looking-at " ") (delete-char 1))))
3432 (exchange-point-and-mark))))
3433 (if rectify-numbering
3436 ; Give some preliminary feedback:
3437 (message "... reconciling numbers") (sit-for 0)
3438 ; ... and renumber, in case necessary:
3439 (goto-char subj-beg
)
3440 (if (outline-goto-prefix)
3441 (outline-rebullet-heading nil
;;; solicit
3442 (outline-depth) ;;; depth
3443 nil
;;; number-control
3448 (exchange-point-and-mark))))
3449 ;;;_ > outline-yank (&optional arg)
3450 (defun outline-yank (&optional arg
)
3451 "Outline-mode yank, with depth and numbering adjustment of yanked topics.
3453 Non-topic yanks work no differently than normal yanks.
3455 If a topic is being yanked into a bare topic prefix, the depth of the
3456 yanked topic is adjusted to the depth of the topic prefix.
3458 1 we're yanking in an outline-mode buffer
3459 2 the stuff being yanked starts with a valid outline header prefix, and
3460 3 it is being yanked at the end of a line which consists of only a valid
3463 If these conditions hold then the depth of the yanked topics are all
3464 adjusted the amount it takes to make the first one at the depth of the
3465 header into which it's being yanked.
3467 The point is left in front of yanked, adjusted topics, rather than
3468 at the end (and vice-versa with the mark). Non-adjusted yanks,
3469 however, (ones that don't qualify for adjustment) are handled
3470 exactly like normal yanks.
3472 Numbering of yanked topics, and the successive siblings at the depth
3473 into which they're being yanked, is adjusted.
3475 Outline-yank-pop works with outline-yank just like normal yank-pop
3476 works with normal yank in non-outline buffers."
3479 (setq this-command
'yank
)
3481 (if (outline-mode-p)
3482 (outline-yank-processing)))
3483 ;;;_ > outline-yank-pop (&optional arg)
3484 (defun outline-yank-pop (&optional arg
)
3485 "Yank-pop like outline-yank when popping to bare outline prefixes.
3487 Adapts level of popped topics to level of fresh prefix.
3489 Note - prefix changes to distinctive bullets will stick, if followed
3490 by pops to non-distinctive yanks. Bug..."
3493 (setq this-command
'yank
)
3495 (if (outline-mode-p)
3496 (outline-yank-processing)))
3498 ;;;_ - Specialty bullet functions
3499 ;;;_ : File Cross references
3500 ;;;_ > outline-resolve-xref ()
3501 (defun outline-resolve-xref ()
3502 "Pop to file associated with current heading, if it has an xref bullet.
3504 \(Works according to setting of `outline-file-xref-bullet')."
3506 (if (not outline-file-xref-bullet
)
3508 "outline cross references disabled - no `outline-file-xref-bullet'")
3509 (if (not (string= (outline-current-bullet) outline-file-xref-bullet
))
3510 (error "current heading lacks cross-reference bullet `%s'"
3511 outline-file-xref-bullet
)
3514 (let* ((text-start outline-recent-prefix-end
)
3515 (heading-end (progn (end-of-line) (point))))
3516 (goto-char text-start
)
3518 (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t
)
3519 (buffer-substring (match-beginning 1) (match-end 1))))))
3521 (if (not (= (aref file-name
0) ?
:))
3522 (expand-file-name file-name
)
3523 ; A registry-files ref, strip the `:'
3524 ; and try to follow it:
3525 (let ((reg-ref (reference-registered-file
3526 (substring file-name
1) nil t
)))
3527 (if reg-ref
(car (cdr reg-ref
))))))
3528 (if (or (file-exists-p file-name
)
3529 (if (file-writable-p file-name
)
3530 (y-or-n-p (format "%s not there, create one? "
3532 (error "%s not found and can't be created" file-name
)))
3533 (condition-case failure
3534 (find-file-other-window file-name
)
3536 (error "%s not found" file-name
))
3542 ;;;_ #6 Exposure Control
3545 ;;;_ > outline-flag-current-subtree (flag)
3546 (defun outline-flag-current-subtree (flag)
3547 "Hide or show subtree of currently-visible topic.
3549 See `outline-flag-region' for more details."
3552 (outline-back-to-current-heading)
3553 (outline-flag-region (point)
3554 (progn (outline-end-of-current-subtree) (1- (point)))
3557 ;;;_ - Topic-specific
3558 ;;;_ > outline-show-entry ()
3559 (defun outline-show-entry ()
3560 "Like `outline-show-current-entry', reveals entries nested in hidden topics.
3562 This is a way to give restricted peek at a concealed locality without the
3563 expense of exposing its context, but can leave the outline with aberrant
3564 exposure. outline-hide-current-entry-completely or outline-show-offshoot
3565 should be used after the peek to rectify the exposure."
3571 (outline-goto-prefix)
3572 (setq beg
(if (= (preceding-char) ?
\r) (1- (point)) (point)))
3573 (re-search-forward "[\n\r]" nil t
)
3574 (setq end
(1- (if (< at
(point))
3575 ;; We're on topic head line - show only it:
3577 ;; or we're in body - include it:
3578 (max beg
(or (outline-pre-next-preface) (point))))))
3579 (outline-flag-region beg end ?
\n)
3581 ;;;_ > outline-show-children (&optional level strict)
3582 (defun outline-show-children (&optional level strict
)
3584 "If point is visible, show all direct subheadings of this heading.
3586 Otherwise, do outline-show-to-offshoot, and then show subheadings.
3588 Optional LEVEL specifies how many levels below the current level
3589 should be shown, or all levels if t. Default is 1.
3591 Optional STRICT means don't resort to -show-to-offshoot, no matter
3592 what. This is basically so -show-to-offshoot, which is called by
3593 this function, can employ the pure offspring-revealing capabilities of
3596 Returns point at end of subtree that was opened, if any. (May get a
3597 point of non-opened subtree?)"
3601 (if (and (not strict
)
3604 (progn (outline-show-to-offshoot) ; Point's concealed, open to
3606 ;; Then recurse, but with "strict" set so we don't
3607 ;; infinite regress:
3608 (setq max-pos
(outline-show-children level t
)))
3612 (let* ((start-pt (point))
3613 (chart (outline-chart-subtree (or level
1)))
3614 (to-reveal (outline-chart-to-reveal chart
(or level
1))))
3615 (goto-char start-pt
)
3616 (if (and strict
(= (preceding-char) ?
\r))
3617 ;; Concealed root would already have been taken care of,
3618 ;; unless strict was set.
3620 (outline-flag-region (point) (outline-snug-back) ?
\n)
3621 (if outline-show-bodies
3622 (progn (goto-char (car to-reveal
))
3623 (outline-show-current-entry)))))
3625 (goto-char (car to-reveal
))
3626 (outline-flag-region (point) (outline-snug-back) ?
\n)
3627 (if outline-show-bodies
3628 (progn (goto-char (car to-reveal
))
3629 (outline-show-current-entry)))
3630 (setq to-reveal
(cdr to-reveal
)))))))))
3631 ;;;_ > outline-hide-point-reconcile ()
3632 (defun outline-hide-reconcile ()
3633 "Like `outline-hide-current-entry'; hides completely if within hidden region.
3635 Specifically intended for aberrant exposure states, like entries that were
3636 exposed by outline-show-entry but are within otherwise concealed regions."
3639 (outline-goto-prefix)
3640 (outline-flag-region (if (not (bobp)) (1- (point)) (point))
3641 (progn (outline-pre-next-preface)
3642 (if (= ?
\r (following-char))
3646 ;;;_ > outline-show-to-offshoot ()
3647 (defun outline-show-to-offshoot ()
3648 "Like outline-show-entry, but reveals all concealed ancestors, as well.
3650 As with outline-hide-current-entry-completely, useful for rectifying
3651 aberrant exposure states produced by outline-show-entry."
3655 (let ((orig-pt (point))
3656 (orig-pref (outline-goto-prefix))
3659 (while (or bag-it
(= (preceding-char) ?
\r))
3661 (if (= last-at
(setq last-at
(point)))
3662 ;; Oops, we're not making any progress! Show the current
3663 ;; topic completely, and bag this try.
3664 (progn (beginning-of-line)
3665 (outline-show-current-subtree)
3670 "outline-show-to-offshoot: "
3671 "Aberrant nesting encountered.")))
3672 (outline-show-children)
3673 (goto-char orig-pref
))
3674 (goto-char orig-pt
)))
3675 (if (outline-hidden-p)
3676 (outline-show-entry)))
3677 ;;;_ > outline-hide-current-entry ()
3678 (defun outline-hide-current-entry ()
3679 "Hide the body directly following this heading."
3681 (outline-back-to-current-heading)
3683 (outline-flag-region (point)
3684 (progn (outline-end-of-current-entry) (point))
3686 ;;;_ > outline-show-current-entry (&optional arg)
3687 (defun outline-show-current-entry (&optional arg
)
3689 "Show body following current heading, or hide the entry if repeat count."
3693 (outline-hide-current-entry)
3695 (outline-flag-region (point)
3696 (progn (outline-end-of-current-entry) (point))
3698 ;;;_ > outline-hide-current-entry-completely ()
3699 ; ... outline-hide-current-entry-completely also for isearch dynamic exposure:
3700 (defun outline-hide-current-entry-completely ()
3701 "Like outline-hide-current-entry, but conceal topic completely.
3703 Specifically intended for aberrant exposure states, like entries that were
3704 exposed by outline-show-entry but are within otherwise concealed regions."
3707 (outline-goto-prefix)
3708 (outline-flag-region (if (not (bobp)) (1- (point)) (point))
3709 (progn (outline-pre-next-preface)
3710 (if (= ?
\r (following-char))
3714 ;;;_ > outline-show-current-subtree (&optional arg)
3715 (defun outline-show-current-subtree (&optional arg
)
3716 "Show everything within the current topic. With a repeat-count,
3717 expose this topic and its siblings."
3720 (if (<= (outline-current-depth) 0)
3721 ;; Outside any topics - try to get to the first:
3722 (if (not (outline-next-heading))
3724 ;; got to first, outermost topic - set to expose it and siblings:
3725 (message "Above outermost topic - exposing all.")
3726 (outline-flag-region (point-min)(point-max) ?
\n))
3728 (outline-flag-current-subtree ?
\n)
3729 (outline-beginning-of-level)
3730 (outline-expose-topic '(* :))))))
3731 ;;;_ > outline-hide-current-subtree (&optional just-close)
3732 (defun outline-hide-current-subtree (&optional just-close
)
3733 "Close the current topic, or containing topic if this one is already closed.
3735 If this topic is closed and it's a top level topic, close this topic
3738 If optional arg JUST-CLOSE is non-nil, do not treat the parent or
3739 siblings, even if the target topic is already closed."
3742 (let ((from (point))
3743 (orig-eol (progn (end-of-line)
3744 (if (not (outline-goto-prefix))
3745 (error "No topics found")
3746 (end-of-line)(point)))))
3747 (outline-flag-current-subtree ?
\r)
3749 (if (and (= orig-eol
(progn (goto-char orig-eol
)
3753 ;; Structure didn't change - try hiding current level:
3755 (if (outline-up-current-level 1 t
)
3759 "Top-level topic already closed - closing siblings..."))
3761 (outline-expose-topic '(0 :))
3762 (message (concat msg
" Done.")))
3764 (/= (outline-recent-depth) 0))
3765 (outline-hide-current-subtree))
3767 ;;;_ > outline-show-current-branches ()
3768 (defun outline-show-current-branches ()
3769 "Show all subheadings of this heading, but not their bodies."
3772 (outline-show-children t
))
3773 ;;;_ > outline-hide-current-leaves ()
3774 (defun outline-hide-current-leaves ()
3775 "Hide the bodies of the current topic and all its offspring."
3777 (outline-back-to-current-heading)
3778 (outline-hide-region-body (point) (progn (outline-end-of-current-subtree)
3781 ;;;_ - Region and beyond
3782 ;;;_ > outline-show-all ()
3783 (defun outline-show-all ()
3784 "Show all of the text in the buffer."
3786 (message "Exposing entire buffer...")
3787 (outline-flag-region (point-min) (point-max) ?
\n)
3788 (message "Exposing entire buffer... Done."))
3789 ;;;_ > outline-hide-bodies ()
3790 (defun outline-hide-bodies ()
3791 "Hide all of buffer except headings."
3793 (outline-hide-region-body (point-min) (point-max)))
3794 ;;;_ > outline-hide-region-body (start end)
3795 (defun outline-hide-region-body (start end
)
3796 "Hide all body lines in the region, but not headings."
3799 (narrow-to-region start end
)
3800 (goto-char (point-min))
3802 (outline-flag-region (point)
3803 (progn (outline-pre-next-preface) (point)) ?
\r)
3806 (if (looking-at "[\n\r][\n\r]")
3809 ;;;_ > outline-expose-topic (spec)
3810 (defun outline-expose-topic (spec)
3811 "Apply exposure specs to successive outline topic items.
3813 Use the more convenient frontend, `outline-new-exposure', if you don't
3814 need evaluation of the arguments, or even better, the `outline-layout'
3815 variable-keyed mode-activation/auto-exposure feature of allout outline
3816 mode. See the respective documentation strings for more details.
3818 Cursor is left at start position.
3820 SPEC is either a number or a list.
3822 Successive specs on a list are applied to successive sibling topics.
3824 A simple spec \(either a number, one of a few symbols, or the null
3825 list) dictates the exposure for the corresponding topic.
3827 Non-null lists recursively designate exposure specs for respective
3828 subtopics of the current topic.
3830 The `:' repeat spec is used to specify exposure for any number of
3831 successive siblings, up to the trailing ones for which there are
3832 explicit specs following the `:'.
3834 Simple (numeric and null-list) specs are interpreted as follows:
3836 Numbers indicate the relative depth to open the corresponding topic.
3837 - negative numbers force the topic to be closed before opening to the
3838 absolute value of the number, so all siblings are open only to
3840 - positive numbers open to the relative depth indicated by the
3841 number, but do not force already opened subtopics to be closed.
3842 - 0 means to close topic - hide all offspring.
3844 apply prior element to all siblings at current level, *up to*
3845 those siblings that would be covered by specs following the `:'
3846 on the list. Ie, apply to all topics at level but the last
3847 ones. \(Only first of multiple colons at same level is
3848 respected - subsequent ones are discarded.)
3849 * - completely opens the topic, including bodies.
3850 + - shows all the sub headers, but not the bodies
3851 - - exposes the body of the corresponding topic.
3854 \(outline-expose-topic '(-1 : 0))
3855 Close this and all following topics at current level, exposing
3856 only their immediate children, but close down the last topic
3857 at this current level completely.
3858 \(outline-expose-topic '(-1 () : 1 0))
3859 Close current topic so only the immediate subtopics are shown;
3860 show the children in the second to last topic, and completely
3862 \(outline-expose-topic '(-2 : -1 *))
3863 Expose children and grandchildren of all topics at current
3864 level except the last two; expose children of the second to
3865 last and completely open the last one."
3867 (interactive "xExposure spec: ")
3868 (if (not (listp spec
))
3870 (let ((depth (outline-depth))
3877 (setq prev-elem curr-elem
3878 curr-elem
(car spec
)
3880 (cond ; Do current element:
3881 ((null curr-elem
) nil
)
3882 ((symbolp curr-elem
)
3883 (cond ((eq curr-elem
'*) (outline-show-current-subtree)
3884 (if (> outline-recent-end-of-subtree max-pos
)
3885 (setq max-pos outline-recent-end-of-subtree
)))
3886 ((eq curr-elem
'+) (outline-show-current-branches)
3887 (if (> outline-recent-end-of-subtree max-pos
)
3888 (setq max-pos outline-recent-end-of-subtree
)))
3889 ((eq curr-elem
'-
) (outline-show-current-entry))
3892 ;; Expand the `repeat' spec to an explicit version,
3893 ;; w.r.t. remaining siblings:
3894 (let ((residue ; = # of sibs not covered by remaining spec
3895 ;; Dang - could be nice to make use of the chart, sigh:
3896 (- (length (outline-chart-siblings))
3899 ;; Some residue - cover it with prev-elem:
3900 (setq spec
(append (make-list residue prev-elem
)
3902 ((numberp curr-elem
)
3903 (if (and (>= 0 curr-elem
) (outline-visible-p))
3904 (save-excursion (outline-hide-current-subtree t
)
3907 (if (> outline-recent-end-of-subtree max-pos
)
3909 outline-recent-end-of-subtree
)))))
3910 (if (> (abs curr-elem
) 0)
3911 (progn (outline-show-children (abs curr-elem
))
3912 (if (> outline-recent-end-of-subtree max-pos
)
3913 (setq max-pos outline-recent-end-of-subtree
)))))
3915 (if (outline-descend-to-depth (1+ depth
))
3916 (let ((got (outline-expose-topic curr-elem
)))
3917 (if (and got
(> got max-pos
)) (setq max-pos got
))))))
3918 (cond (stay (setq stay nil
))
3919 ((listp (car spec
)) nil
)
3920 ((> max-pos
(point))
3921 ;; Capitalize on max-pos state to get us nearer next sibling:
3922 (progn (goto-char (min (point-max) max-pos
))
3923 (outline-next-heading)))
3924 ((outline-next-sibling depth
))))
3926 ;;;_ > outline-old-expose-topic (spec &rest followers)
3927 (defun outline-old-expose-topic (spec &rest followers
)
3929 "Deprecated. Use outline-expose-topic \(with different schema
3932 Dictate wholesale exposure scheme for current topic, according to SPEC.
3934 SPEC is either a number or a list. Optional successive args
3935 dictate exposure for subsequent siblings of current topic.
3937 A simple spec (either a number, a special symbol, or the null list)
3938 dictates the overall exposure for a topic. Non null lists are
3939 composite specs whose first element dictates the overall exposure for
3940 a topic, with the subsequent elements in the list interpreted as specs
3941 that dictate the exposure for the successive offspring of the topic.
3943 Simple (numeric and null-list) specs are interpreted as follows:
3945 - Numbers indicate the relative depth to open the corresponding topic:
3946 - negative numbers force the topic to be close before opening to the
3947 absolute value of the number.
3948 - positive numbers just open to the relative depth indicated by the number.
3950 - `*' completely opens the topic, including bodies.
3951 - `+' shows all the sub headers, but not the bodies
3952 - `-' exposes the body and immediate offspring of the corresponding topic.
3954 If the spec is a list, the first element must be a number, which
3955 dictates the exposure depth of the topic as a whole. Subsequent
3956 elements of the list are nested SPECs, dictating the specific exposure
3957 for the corresponding offspring of the topic.
3959 Optional FOLLOWER arguments dictate exposure for succeeding siblings."
3961 (interactive "xExposure spec: ")
3962 (let ((depth (outline-current-depth))
3965 (cond ((null spec
) nil
)
3967 (if (eq spec
'*) (outline-show-current-subtree))
3968 (if (eq spec
'+) (outline-show-current-branches))
3969 (if (eq spec
'-
) (outline-show-current-entry)))
3972 (save-excursion (outline-hide-current-subtree t
)
3974 (if (or (not max-pos
)
3975 (> (point) max-pos
))
3976 (setq max-pos
(point)))
3978 (setq spec
(* -
1 spec
)))))
3980 (outline-show-children spec
)))
3982 ;(let ((got (outline-old-expose-topic (car spec))))
3983 ; (if (and got (or (not max-pos) (> got max-pos)))
3984 ; (setq max-pos got)))
3985 (let ((new-depth (+ (outline-current-depth) 1))
3987 (setq max-pos
(outline-old-expose-topic (car spec
)))
3988 (setq spec
(cdr spec
))
3990 (outline-descend-to-depth new-depth
)
3991 (not (outline-hidden-p)))
3992 (progn (setq got
(apply 'outline-old-expose-topic spec
))
3993 (if (and got
(or (not max-pos
) (> got max-pos
)))
3994 (setq max-pos got
)))))))
3995 (while (and followers
3996 (progn (if (and max-pos
(< (point) max-pos
))
3997 (progn (goto-char max-pos
)
3998 (setq max-pos nil
)))
4000 (outline-next-sibling depth
)))
4001 (outline-old-expose-topic (car followers
))
4002 (setq followers
(cdr followers
)))
4004 ;;;_ > outline-new-exposure '()
4005 (defmacro outline-new-exposure
(&rest spec
)
4006 "Literal frontend for `outline-expose-topic', doesn't evaluate arguments.
4007 Some arguments that would need to be quoted in outline-expose-topic
4008 need not be quoted in outline-new-exposure.
4010 Cursor is left at start position.
4012 Use this instead of obsolete `outline-exposure'.
4015 \(outline-exposure (-1 () () () 1) 0)
4016 Close current topic at current level so only the immediate
4017 subtopics are shown, except also show the children of the
4018 third subtopic; and close the next topic at the current level.
4019 \(outline-exposure : -1 0)
4020 Close all topics at current level to expose only their
4021 immediate children, except for the last topic at the current
4022 level, in which even its immediate children are hidden.
4023 \(outline-exposure -2 : -1 *)
4024 Expose children and grandchildren of first topic at current
4025 level, and expose children of subsequent topics at current
4026 level *except* for the last, which should be opened completely."
4027 (list 'save-excursion
4028 '(if (not (or (outline-goto-prefix)
4029 (outline-next-heading)))
4030 (error "outline-new-exposure: Can't find any outline topics"))
4031 (list 'outline-expose-topic
(list 'quote spec
))))
4032 ;;;_ > outline-exposure '()
4033 (defmacro outline-exposure
(&rest spec
)
4034 "Being deprecated - use more recent `outline-new-exposure' instead.
4036 Literal frontend for `outline-old-expose-topic', doesn't evaluate arguments
4037 and retains start position."
4038 (list 'save-excursion
4039 '(if (not (or (outline-goto-prefix)
4040 (outline-next-heading)))
4041 (error "Can't find any outline topics"))
4042 (cons 'outline-old-expose-topic
4043 (mapcar (function (lambda (x) (list 'quote x
))) spec
))))
4045 ;;;_ #7 Systematic outline presentation - copying, printing, flattening
4047 ;;;_ - Mapping and processing of topics
4048 ;;;_ ( See also Subtree Charting, in Navigation code.)
4049 ;;;_ > outline-stringify-flat-index (flat-index)
4050 (defun outline-stringify-flat-index (flat-index &optional context
)
4051 "Convert list representing section/subsection/... to document string.
4053 Optional arg CONTEXT indicates interior levels to include."
4057 (context-depth (or (and context
2) 1)))
4058 ;; Take care of the explicit context:
4059 (while (> context-depth
0)
4060 (setq numstr
(int-to-string (car flat-index
))
4061 flat-index
(cdr flat-index
)
4062 result
(if flat-index
4063 (cons delim
(cons numstr result
))
4064 (cons numstr result
))
4065 context-depth
(if flat-index
(1- context-depth
) 0)))
4067 ;; Take care of the indentation:
4074 (1+ (truncate (if (zerop (car flat-index
))
4076 (log10 (car flat-index
)))))
4079 (setq flat-index
(cdr flat-index
)))
4080 ;; Dispose of single extra delim:
4081 (setq result
(cdr result
))))
4082 (apply 'concat result
)))
4083 ;;;_ > outline-stringify-flat-index-plain (flat-index)
4084 (defun outline-stringify-flat-index-plain (flat-index)
4085 "Convert list representing section/subsection/... to document string."
4089 (setq result
(cons (int-to-string (car flat-index
))
4091 (cons delim result
))))
4092 (setq flat-index
(cdr flat-index
)))
4093 (apply 'concat result
)))
4094 ;;;_ > outline-stringify-flat-index-indented (flat-index)
4095 (defun outline-stringify-flat-index-indented (flat-index)
4096 "Convert list representing section/subsection/... to document string."
4100 ;; Take care of the explicit context:
4101 (setq numstr
(int-to-string (car flat-index
))
4102 flat-index
(cdr flat-index
)
4103 result
(if flat-index
4104 (cons delim
(cons numstr result
))
4105 (cons numstr result
)))
4107 ;; Take care of the indentation:
4114 (1+ (truncate (if (zerop (car flat-index
))
4116 (log10 (car flat-index
)))))
4119 (setq flat-index
(cdr flat-index
)))
4120 ;; Dispose of single extra delim:
4121 (setq result
(cdr result
))))
4122 (apply 'concat result
)))
4123 ;;;_ > outline-listify-exposed (&optional start end format)
4124 (defun outline-listify-exposed (&optional start end format
)
4126 "Produce a list representing exposed topics in current region.
4128 This list can then be used by `outline-process-exposed' to manipulate
4131 Optional START and END indicate bounds of region.
4133 optional arg, FORMAT, designates an alternate presentation form for
4136 list - Present prefix as numeric section.subsection..., starting with
4137 section indicated by the list, innermost nesting first.
4138 `indent' \(symbol) - Convert header prefixes to all white space,
4139 except for distinctive bullets.
4141 The elements of the list produced are lists that represents a topic
4142 header and body. The elements of that list are:
4144 - a number representing the depth of the topic,
4145 - a string representing the header-prefix, including trailing whitespace and
4147 - a string representing the bullet character,
4148 - and a series of strings, each containing one line of the exposed
4149 portion of the topic entry."
4155 (strings prefix pad result depth new-depth out gone-out bullet beg
4160 ;; Goto initial topic, and register preceeding stuff, if any:
4161 (if (> (outline-goto-prefix) start
)
4162 ;; First topic follows beginning point - register preliminary stuff:
4163 (setq result
(list (list 0 "" nil
4164 (buffer-substring start
(1- (point)))))))
4165 (while (and (not done
)
4166 (not (eobp)) ; Loop until we've covered the region.
4167 (not (> (point) end
)))
4168 (setq depth
(outline-recent-depth) ; Current topics depth,
4169 bullet
(outline-recent-bullet) ; ... bullet,
4170 prefix
(outline-recent-prefix)
4171 beg
(progn (outline-end-of-prefix t
) (point))) ; and beginning.
4172 (setq done
; The boundary for the current topic:
4173 (not (outline-next-visible-heading 1)))
4174 (setq new-depth
(outline-recent-depth))
4176 out
(< new-depth depth
))
4181 (while (> next
(point)) ; Get all the exposed text in
4183 (cons (buffer-substring
4185 ;To hidden text or end of line:
4187 (search-forward "\r"
4188 (save-excursion (end-of-line)
4191 (if (= (preceding-char) ?
\r)
4195 (if (< (point) next
) ; Resume from after hid text, if any.
4198 ;; Accumulate list for this topic:
4199 (setq strings
(nreverse strings
))
4203 (let ((special (if (string-match
4204 (regexp-quote bullet
)
4205 outline-distinctive-bullets-string
)
4207 (cond ((listp format
)
4209 (if outline-abbreviate-flattened-numbering
4210 (outline-stringify-flat-index format
4212 (outline-stringify-flat-index-plain
4216 ((eq format
'indent
)
4219 (concat (make-string (1+ depth
) ?
)
4220 (substring prefix -
1))
4223 (make-string depth ?
)
4225 (t (error "outline-listify-exposed: %s %s"
4226 "invalid format" format
))))
4227 (list depth prefix strings
))
4229 ;; Reasses format, if any:
4230 (if (and format
(listp format
))
4231 (cond ((= new-depth depth
)
4232 (setq format
(cons (1+ (car format
))
4234 ((> new-depth depth
) ; descending - assume by 1:
4235 (setq format
(cons 1 format
)))
4238 (while (< new-depth depth
)
4239 (setq format
(cdr format
))
4240 (setq depth
(1- depth
)))
4241 ; And increment the current one:
4243 (cons (1+ (or (car format
)
4246 ;; Put the list with first at front, to last at back:
4247 (nreverse result
))))
4248 ;;;_ > outline-process-exposed (&optional func from to frombuf
4250 (defun outline-process-exposed (&optional func from to frombuf tobuf
4251 format
&optional start-num
)
4252 "Map function on exposed parts of current topic; results to another buffer.
4254 All args are options; default values itemized below.
4256 Apply FUNCTION to exposed portions FROM position TO position in buffer
4257 FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an
4258 alternate presentation form:
4260 `flat' - Present prefix as numeric section.subsection..., starting with
4261 section indicated by the start-num, innermost nesting first.
4262 X`flat-indented' - Prefix is like `flat' for first topic at each
4263 X level, but subsequent topics have only leaf topic
4264 X number, padded with blanks to line up with first.
4265 `indent' \(symbol) - Convert header prefixes to all white space,
4266 except for distinctive bullets.
4269 FUNCTION: `outline-insert-listified'
4270 FROM: region start, if region active, else start of buffer
4271 TO: region end, if region active, else end of buffer
4272 FROMBUF: current buffer
4273 TOBUF: buffer name derived: \"*current-buffer-name exposed*\"
4276 ; Resolve arguments,
4277 ; defaulting if necessary:
4278 (if (not func
) (setq func
'outline-insert-listified
))
4279 (if (not (and from to
))
4280 (if (my-region-active-p)
4281 (setq from
(region-beginning) to
(region-end))
4282 (setq from
(point-min) to
(point-max))))
4284 (if (not (bufferp frombuf
))
4285 ;; Specified but not a buffer - get it:
4286 (let ((got (get-buffer frombuf
)))
4288 (error (concat "outline-process-exposed: source buffer "
4291 (setq frombuf got
))))
4292 ;; not specified - default it:
4293 (setq frombuf
(current-buffer)))
4295 (if (not (bufferp tobuf
))
4296 (setq tobuf
(get-buffer-create tobuf
)))
4297 ;; not specified - default it:
4298 (setq tobuf
(concat "*" (buffer-name frombuf
) " exposed*")))
4303 (progn (set-buffer frombuf
)
4304 (outline-listify-exposed from to format
))))
4306 (mapcar func listified
)
4307 (pop-to-buffer tobuf
)))
4310 ;;;_ > outline-insert-listified (listified)
4311 (defun outline-insert-listified (listified)
4312 "Insert contents of listified outline portion in current buffer.
4314 Listified is a list representing each topic header and body:
4316 \`(depth prefix text)'
4318 or \`(depth prefix text bullet-plus)'
4320 If `bullet-plus' is specified, it is inserted just after the entire prefix."
4321 (setq listified
(cdr listified
))
4322 (let ((prefix (prog1
4324 (setq listified
(cdr listified
))))
4327 (setq listified
(cdr listified
))))
4328 (bullet-plus (car listified
)))
4330 (if bullet-plus
(insert (concat " " bullet-plus
)))
4333 (if (setq text
(cdr text
))
4336 ;;;_ > outline-copy-exposed-to-buffer (&optional arg tobuf format)
4337 (defun outline-copy-exposed-to-buffer (&optional arg tobuf format
)
4338 "Duplicate exposed portions of current outline to another buffer.
4340 Other buffer has current buffers name with \" exposed\" appended to it.
4342 With repeat count, copy the exposed parts of only the current topic.
4344 Optional second arg TOBUF is target buffer name.
4346 Optional third arg FORMAT, if non-nil, symbolically designates an
4347 alternate presentation format for the outline:
4349 `flat' - Convert topic header prefixes to numeric
4350 section.subsection... identifiers.
4351 `indent' - Convert header prefixes to all white space, except for
4352 distinctive bullets.
4353 `indent-flat' - The best of both - only the first of each level has
4354 the full path, the rest have only the section number
4355 of the leaf, preceded by the right amount of indentation."
4359 (setq tobuf
(get-buffer-create (concat "*" (buffer-name) " exposed*"))))
4360 (let* ((start-pt (point))
4361 (beg (if arg
(outline-back-to-current-heading) (point-min)))
4362 (end (if arg
(outline-end-of-current-subtree) (point-max)))
4363 (buf (current-buffer))
4365 (if (eq format
'flat
)
4366 (setq format
(if arg
(save-excursion
4368 (outline-topic-flat-index))
4370 (save-excursion (set-buffer tobuf
)(erase-buffer))
4371 (outline-process-exposed 'outline-insert-listified
4377 (goto-char (point-min))
4379 (goto-char start-pt
)))
4380 ;;;_ > outline-flatten-exposed-to-buffer (&optional arg tobuf)
4381 (defun outline-flatten-exposed-to-buffer (&optional arg tobuf
)
4382 "Present numeric outline of outline's exposed portions in another buffer.
4384 The resulting outline is not compatable with outline mode - use
4385 `outline-copy-exposed-to-buffer' if you want that.
4387 Use `outline-indented-exposed-to-buffer' for indented presentation.
4389 With repeat count, copy the exposed portions of only current topic.
4391 Other buffer has current buffers name with \" exposed\" appended to
4392 it, unless optional second arg TOBUF is specified, in which case it is
4395 (outline-copy-exposed-to-buffer arg tobuf
'flat
))
4396 ;;;_ > outline-indented-exposed-to-buffer (&optional arg tobuf)
4397 (defun outline-indented-exposed-to-buffer (&optional arg tobuf
)
4398 "Present indented outline of outline's exposed portions in another buffer.
4400 The resulting outline is not compatable with outline mode - use
4401 `outline-copy-exposed-to-buffer' if you want that.
4403 Use `outline-flatten-exposed-to-buffer' for numeric sectional presentation.
4405 With repeat count, copy the exposed portions of only current topic.
4407 Other buffer has current buffers name with \" exposed\" appended to
4408 it, unless optional second arg TOBUF is specified, in which case it is
4411 (outline-copy-exposed-to-buffer arg tobuf
'indent
))
4413 ;;;_ - LaTeX formatting
4414 ;;;_ > outline-latex-verb-quote (str &optional flow)
4415 (defun outline-latex-verb-quote (str &optional flow
)
4416 "Return copy of STRING for literal reproduction across latex processing.
4417 Expresses the original characters \(including carriage returns) of the
4418 string across latex processing."
4419 (mapconcat (function
4421 (cond ((memq char
'(?
\\ ?$ ?% ?
# ?
& ?
{ ?
} ?_ ?^ ?- ?
*))
4422 (concat "\\char" (number-to-string char
) "{}"))
4423 ((= char ?
\n) "\\\\")
4424 (t (char-to-string char
)))))
4427 ;;;_ > outline-latex-verbatim-quote-curr-line ()
4428 (defun outline-latex-verbatim-quote-curr-line ()
4429 "Express line for exact \(literal) representation across latex processing.
4431 Adjust line contents so it is unaltered \(from the original line)
4432 across latex processing, within the context of a `verbatim'
4433 environment. Leaves point at the end of the line."
4436 (end (progn (end-of-line)(point))))
4438 (while (re-search-forward "\\\\"
4439 ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#"
4440 end
; bounded by end-of-line
4441 1) ; no matches, move to end & return nil
4442 (goto-char (match-beginning 0))
4445 (goto-char (1+ (match-end 0))))))
4446 ;;;_ > outline-insert-latex-header (buf)
4447 (defun outline-insert-latex-header (buf)
4448 "Insert initial latex commands at point in BUFFER."
4449 ;; Much of this is being derived from the stuff in appendix of E in
4450 ;; the TeXBook, pg 421.
4452 (let ((doc-style (format "\n\\documentstyle{%s}\n"
4454 (page-numbering (if outline-number-pages
4455 "\\pagestyle{empty}\n"
4457 (linesdef (concat "\\def\\beginlines{"
4458 "\\par\\begingroup\\nobreak\\medskip"
4460 " \\kern1pt\\nobreak \\obeylines \\obeyspaces "
4461 "\\everypar{\\strut}}\n"
4463 "\\kern1pt\\endgroup\\medbreak\\noindent}\n"))
4464 (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n"
4465 outline-title-style
))
4466 (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n"
4467 outline-label-style
))
4468 (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n"
4469 outline-head-line-style
))
4470 (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n"
4471 outline-body-line-style
))
4472 (setlength (format "%s%s%s%s"
4473 "\\newlength{\\stepsize}\n"
4474 "\\setlength{\\stepsize}{"
4477 (oneheadline (format "%s%s%s%s%s%s%s"
4478 "\\newcommand{\\OneHeadLine}[3]{%\n"
4480 "\\hspace*{#2\\stepsize}%\n"
4481 "\\labelcmd{#1}\\hspace*{.2cm}"
4482 "\\headlinecmd{#3}\\\\["
4485 (onebodyline (format "%s%s%s%s%s%s"
4486 "\\newcommand{\\OneBodyLine}[2]{%\n"
4488 "\\hspace*{#1\\stepsize}%\n"
4489 "\\bodylinecmd{#2}\\\\["
4492 (begindoc "\\begin{document}\n\\begin{center}\n")
4493 (title (format "%s%s%s%s"
4495 (outline-latex-verb-quote (if outline-title
4497 (eval outline-title
)
4498 ('error
"<unnamed buffer>"))
4501 "\\end{center}\n\n"))
4502 (hsize "\\hsize = 7.5 true in\n")
4503 (hoffset "\\hoffset = -1.5 true in\n")
4504 (vspace "\\vspace{.1cm}\n\n"))
4505 (insert (concat doc-style
4520 ;;;_ > outline-insert-latex-trailer (buf)
4521 (defun outline-insert-latex-trailer (buf)
4522 "Insert concluding latex commands at point in BUFFER."
4524 (insert "\n\\end{document}\n"))
4525 ;;;_ > outline-latexify-one-item (depth prefix bullet text)
4526 (defun outline-latexify-one-item (depth prefix bullet text
)
4527 "Insert LaTeX commands for formatting one outline item.
4529 Args are the topics numeric DEPTH, the header PREFIX lead string, the
4530 BULLET string, and a list of TEXT strings for the body."
4531 (let* ((head-line (if text
(car text
)))
4532 (body-lines (cdr text
))
4536 (insert (concat "\\OneHeadLine{\\verb\1 "
4537 (outline-latex-verb-quote bullet
)
4542 (outline-latex-verb-quote head-line
)
4545 (if (not body-lines
)
4547 ;;(insert "\\beginlines\n")
4548 (insert "\\begin{verbatim}\n")
4550 (setq curr-line
(car body-lines
))
4551 (if (and (not body-content
)
4552 (not (string-match "^\\s-*$" curr-line
)))
4553 (setq body-content t
))
4554 ; Mangle any occurrences of
4555 ; "\end{verbatim}" in text,
4557 (if (and body-content
4558 (setq bop
(string-match "\\end{verbatim}" curr-line
)))
4559 (setq curr-line
(concat (substring curr-line
0 bop
)
4561 (substring curr-line bop
))))
4562 ;;(insert "|" (car body-lines) "|")
4564 (outline-latex-verbatim-quote-curr-line)
4566 (setq body-lines
(cdr body-lines
)))
4568 (setq body-content nil
)
4572 ;;(insert "\\endlines\n")
4573 (insert "\\end{verbatim}\n")
4575 ;;;_ > outline-latexify-exposed (arg &optional tobuf)
4576 (defun outline-latexify-exposed (arg &optional tobuf
)
4577 "Format current topics exposed portions to TOBUF for latex processing.
4578 TOBUF defaults to a buffer named the same as the current buffer, but
4579 with \"*\" prepended and \" latex-formed*\" appended.
4581 With repeat count, copy the exposed portions of entire buffer."
4586 (get-buffer-create (concat "*" (buffer-name) " latexified*"))))
4587 (let* ((start-pt (point))
4588 (beg (if arg
(point-min) (outline-back-to-current-heading)))
4589 (end (if arg
(point-max) (outline-end-of-current-subtree)))
4590 (buf (current-buffer)))
4593 (outline-insert-latex-header tobuf
)
4594 (goto-char (point-max))
4595 (outline-process-exposed 'outline-latexify-one-item
4600 (goto-char (point-max))
4601 (outline-insert-latex-trailer tobuf
)
4602 (goto-char (point-min))
4604 (goto-char start-pt
)))
4606 ;;;_ #8 miscellaneous
4607 ;;;_ > outline-mark-topic ()
4608 (defun outline-mark-topic ()
4609 "Put the region around topic currently containing point."
4612 (outline-goto-prefix)
4614 (outline-end-of-current-subtree)
4615 (exchange-point-and-mark))
4616 ;;;_ > outlineify-sticky ()
4617 ;; outlinify-sticky is correct spelling; provide this alias for sticklers:
4618 (defalias 'outlinify-sticky
'outlineify-sticky
)
4619 (defun outlineify-sticky (&optional arg
)
4620 "Activate outline mode and establish file var so it is started subsequently.
4622 See doc-string for `outline-layout' and `outline-init' for details on
4623 setup for auto-startup."
4630 (goto-char (point-min))
4631 (if (looking-at outline-regexp
)
4633 (outline-open-topic 2)
4634 (insert (concat "Dummy outline topic header - see"
4635 "`outline-mode' docstring: `^Hm'."))
4637 (goto-char (point-max))
4639 (outline-open-topic 0)
4640 (insert "Local emacs vars.\n")
4641 (outline-open-topic 1)
4642 (insert "(`outline-layout' is for allout.el outline-mode)\n")
4643 (outline-open-topic 0)
4644 (insert "Local variables:\n")
4645 (outline-open-topic 0)
4646 (insert (format "outline-layout: %s\n"
4649 (outline-open-topic 0)
4650 (insert "End:\n"))))
4651 ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting)
4652 (defun solicit-char-in-string (prompt string
&optional do-defaulting
)
4653 "Solicit (with first arg PROMPT) choice of a character from string STRING.
4655 Optional arg DO-DEFAULTING indicates to accept empty input (CR)."
4657 (let ((new-prompt prompt
)
4661 (message "%s" new-prompt
)
4663 ;; We do our own reading here, so we can circumvent, eg, special
4664 ;; treatment for `?' character. (Oughta use minibuffer keymap instead.)
4666 (char-to-string (let ((cursor-in-echo-area nil
)) (read-char))))
4669 (cond ((string-match (regexp-quote got
) string
) got
)
4670 ((and do-defaulting
(string= got
"\r"))
4671 ;; Return empty string to default:
4673 ((string= got
"\C-g") (signal 'quit nil
))
4675 (setq new-prompt
(concat prompt
4681 ;; got something out of loop - return it:
4684 ;;;_ > regexp-sans-escapes (string)
4685 (defun regexp-sans-escapes (regexp &optional successive-backslashes
)
4686 "Return a copy of REGEXP with all character escapes stripped out.
4688 Representations of actual backslashes - '\\\\\\\\' - are left as a
4691 Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion."
4693 (if (string= regexp
"")
4695 ;; Set successive-backslashes to number if current char is
4696 ;; backslash, or else to nil:
4697 (setq successive-backslashes
4698 (if (= (aref regexp
0) ?
\\)
4699 (if successive-backslashes
(1+ successive-backslashes
) 1)
4701 (if (or (not successive-backslashes
) (= 2 successive-backslashes
))
4702 ;; Include first char:
4703 (concat (substring regexp
0 1)
4704 (regexp-sans-escapes (substring regexp
1)))
4705 ;; Exclude first char, but maintain count:
4706 (regexp-sans-escapes (substring regexp
1) successive-backslashes
))))
4707 ;;;_ > my-region-active-p ()
4708 (defmacro my-region-active-p
()
4709 (if (fboundp 'region-active-p
)
4712 ;;;_ - add-hook definition for divergent emacsen
4713 ;;;_ > add-hook (hook function &optional append)
4714 (if (not (fboundp 'add-hook
))
4715 (defun add-hook (hook function
&optional append
)
4716 "Add to the value of HOOK the function FUNCTION unless already present.
4717 \(It becomes the first hook on the list unless optional APPEND is non-nil, in
4718 which case it becomes the last). HOOK should be a symbol, and FUNCTION may be
4719 any valid function. HOOK's value should be a list of functions, not a single
4720 function. If HOOK is void, it is first set to nil."
4721 (or (boundp hook
) (set hook nil
))
4722 (or (if (consp function
)
4723 ;; Clever way to tell whether a given lambda-expression
4724 ;; is equal to anything in the hook.
4725 (let ((tail (assoc (cdr function
) (symbol-value hook
))))
4726 (equal function tail
))
4727 (memq function
(symbol-value hook
)))
4730 (nconc (symbol-value hook
) (list function
))
4731 (cons function
(symbol-value hook
)))))))
4732 ;;;_ : my-mark-marker to accomodate divergent emacsen:
4733 (defun my-mark-marker (&optional force buffer
)
4734 "Accomodate the different signature for mark-marker across emacsen.
4736 GNU XEmacs takes two optional args, while mainline GNU Emacs does not,
4737 so pass them along when appropriate."
4738 (if (string-match " XEmacs " emacs-version
)
4739 (mark-marker force buffer
)
4742 ;;;_ #9 Under development
4743 ;;;_ > outline-bullet-isearch (&optional bullet)
4744 (defun outline-bullet-isearch (&optional bullet
)
4745 "Isearch \(regexp) for topic with bullet BULLET."
4748 (setq bullet
(solicit-char-in-string
4749 "ISearch for topic with bullet: "
4750 (regexp-sans-escapes outline-bullets-string
))))
4752 (let ((isearch-regexp t
)
4753 (isearch-string (concat "^"
4754 outline-header-prefix
4757 (isearch-repeat 'forward
)
4759 ;;;_ ? Re hooking up with isearch - use isearch-op-fun rather than
4760 ;;; wrapping the isearch functions.
4762 ;;;_* Local emacs vars.
4763 ;;; The following `outline-layout' local variable setting:
4764 ;;; - closes all topics from the first topic to just before the third-to-last,
4765 ;;; - shows the children of the third to last (config vars)
4766 ;;; - and the second to last (code section),
4767 ;;; - and closes the last topic (this local-variables section).
4769 ;;;outline-layout: (0 : -1 -1 0)
4772 ;;; allout.el ends here