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