;;; allout.el --- extensive outline mode for use alone and with other modes ;; Copyright (C) 1992, 1993, 1994, 2001, 2002, 2003, 2004, ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. ;; Author: Ken Manheimer ;; Maintainer: Ken Manheimer ;; Created: Dec 1991 -- first release to usenet ;; Version: 2.2.1 ;; Keywords: outlines wp languages ;; Website: http://myriadicity.net/Sundry/EmacsAllout ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; Allout outline minor mode provides extensive outline formatting and ;; and manipulation beyond standard emacs outline mode. Some features: ;; ;; - Classic outline-mode topic-oriented navigation and exposure adjustment ;; - Topic-oriented editing including coherent topic and subtopic ;; creation, promotion, demotion, cut/paste across depths, etc. ;; - Incremental search with dynamic exposure and reconcealment of text ;; - Customizable bullet format -- enables programming-language specific ;; outlining, for code-folding editing. (Allout code itself is to try it; ;; formatted as an outline -- do ESC-x eval-buffer in allout.el; but ;; emacs local file variables need to be enabled when the ;; file was visited -- see `enable-local-variables'.) ;; - Configurable per-file initial exposure settings ;; - Symmetric-key and key-pair topic encryption, plus symmetric passphrase ;; mnemonic support, with verification against an established passphrase ;; (using a stashed encrypted dummy string) and user-supplied hint ;; maintenance. (See allout-toggle-current-subtree-encryption docstring. ;; Currently only GnuPG encryption is supported, and integration ;; with gpg-agent is not yet implemented.) ;; - Automatic topic-number maintenance ;; - "Hot-spot" operation, for single-keystroke maneuvering and ;; exposure control (see the allout-mode docstring) ;; - Easy rendering of exposed portions into numbered, latex, indented, etc ;; outline styles ;; - Careful attention to whitespace -- enabling blank lines between items ;; and maintenance of hanging indentation (in paragraph auto-fill and ;; across topic promotion and demotion) of topic bodies consistent with ;; indentation of their topic header. ;; ;; and more. ;; ;; See the `allout-mode' function's docstring for an introduction to the ;; mode. ;; ;; The latest development version and helpful notes are available at ;; http://myriadicity.net/Sundry/EmacsAllout . ;; ;; The outline menubar additions provide quick reference to many of ;; the features, and see the docstring of the variable `allout-init' ;; for instructions on priming your Emacs session for automatic ;; activation of allout-mode. ;; ;; See the docstring of the variables `allout-layout' and ;; `allout-auto-activation' for details on automatic activation of ;; `allout-mode' as a minor mode. (It has changed since allout ;; 3.x, for those of you that depend on the old method.) ;; ;; Note -- the lines beginning with `;;;_' are outline topic headers. ;; Just `ESC-x eval-buffer' to give it a whirl. ;; ken manheimer (ken dot manheimer at gmail dot com) ;;; Code: ;;;_* Dependency autoloads (require 'overlay) (eval-when-compile ;; Most of the requires here are for stuff covered by autoloads. ;; Since just byte-compiling doesn't trigger autoloads, so that ;; "function not found" warnings would occur without these requires. (progn (require 'pgg) (require 'pgg-gpg) (require 'overlay) ;; `cl' is required for `assert'. `assert' is not covered by a standard ;; autoload, but it is a macro, so that eval-when-compile is sufficient ;; to byte-compile it in, or to do the require when the buffer evalled. (require 'cl) )) ;;;_* USER CUSTOMIZATION VARIABLES: ;;;_ > defgroup allout (defgroup allout nil "Extensive outline mode for use alone and with other modes." :prefix "allout-" :group 'outlines) ;;;_ + Layout, Mode, and Topic Header Configuration ;;;_ = allout-auto-activation (defcustom allout-auto-activation nil "*Regulates auto-activation modality of allout outlines -- see `allout-init'. Setq-default by `allout-init' to regulate whether or not allout outline mode is automatically activated when the buffer-specific variable `allout-layout' is non-nil, and whether or not the layout dictated by `allout-layout' should be imposed on mode activation. With value t, auto-mode-activation and auto-layout are enabled. \(This also depends on `allout-find-file-hook' being installed in `find-file-hook', which is also done by `allout-init'.) With value `ask', auto-mode-activation is enabled, and endorsement for performing auto-layout is asked of the user each time. With value `activate', only auto-mode-activation is enabled, auto-layout is not. With value nil, neither auto-mode-activation nor auto-layout are enabled. See the docstring for `allout-init' for the proper interface to this variable." :type '(choice (const :tag "On" t) (const :tag "Ask about layout" "ask") (const :tag "Mode only" "activate") (const :tag "Off" nil)) :group 'allout) ;;;_ = allout-default-layout (defcustom allout-default-layout '(-2 : 0) "*Default allout outline layout specification. This setting specifies the outline exposure to use when `allout-layout' has the local value `t'. This docstring describes the layout specifications. A list value specifies a default layout for the current buffer, to be applied upon activation of `allout-mode'. Any non-nil value will automatically trigger `allout-mode', provided `allout-init' has been called to enable this behavior. The types of elements in the layout specification are: INTEGER -- dictate the relative depth to open the corresponding topic(s), where: -- negative numbers force the topic to be closed before opening to the absolute value of the number, so all siblings are open only to that level. -- positive numbers open to the relative depth indicated by the number, but do not force already opened subtopics to be closed. -- 0 means to close topic -- hide all subitems. : -- repeat spec -- apply the preceeding element to all siblings at current level, *up to* those siblings that would be covered by specs following the `:' on the list. Ie, apply to all topics at level but trailing ones accounted for by trailing specs. (Only the first of multiple colons at the same level is honored -- later ones are ignored.) * -- completely exposes the topic, including bodies + -- exposes all subtopics, but not the bodies - -- exposes the body of the corresponding topic, but not subtopics LIST -- a nested layout spec, to be applied intricately to its corresponding item(s) Examples: (-2 : 0) Collapse the top-level topics to show their children and grandchildren, but completely collapse the final top-level topic. (-1 () : 1 0) Close the first topic so only the immediate subtopics are shown, leave the subsequent topics exposed as they are until the second second to last topic, which is exposed at least one level, and completely close the last topic. (-2 : -1 *) Expose children and grandchildren of all topics at current level except the last two; expose children of the second to last and completely expose the last one, including its subtopics. See `allout-expose-topic' for more about the exposure process. Also, allout's mode-specific provisions will make topic prefixes default to the comment-start string, if any, of the language of the file. This is modulo the setting of `allout-use-mode-specific-leader', which see." :type 'allout-layout-type :group 'allout) ;;;_ : allout-layout-type (define-widget 'allout-layout-type 'lazy "Allout layout format customization basic building blocks." :type '(repeat (choice (integer :tag "integer (<= zero is strict)") (const :tag ": (repeat prior)" :) (const :tag "* (completely expose)" *) (const :tag "+ (expose all offspring, headlines only)" +) (const :tag "- (expose topic body but not offspring)" -) (allout-layout-type :tag "")))) ;;;_ = allout-show-bodies (defcustom allout-show-bodies nil "*If non-nil, show entire body when exposing a topic, rather than just the header." :type 'boolean :group 'allout) (make-variable-buffer-local 'allout-show-bodies) ;;;###autoload (put 'allout-show-bodies 'safe-local-variable (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil))))) ;;;_ = allout-beginning-of-line-cycles (defcustom allout-beginning-of-line-cycles t "*If non-nil, \\[allout-beginning-of-line] will cycle through smart-placement options. Cycling only happens on when the command is repeated, not when it follows a different command. Smart-placement means that repeated calls to this function will advance as follows: - if the cursor is on a non-headline body line and not on the first column: then it goes to the first column - if the cursor is on the first column of a non-headline body line: then it goes to the start of the headline within the item body - if the cursor is on the headline and not the start of the headline: then it goes to the start of the headline - if the cursor is on the start of the headline: then it goes to the bullet character (for hotspot navigation) - if the cursor is on the bullet character: then it goes to the first column of that line (the headline) - if the cursor is on the first column of the headline: then it goes to the start of the headline within the item body. In this fashion, you can use the beginning-of-line command to do its normal job and then, when repeated, advance through the entry, cycling back to start. If this configuration variable is nil, then the cursor is just advanced to the beginning of the line and remains there on repeated calls." :type 'boolean :group 'allout) ;;;_ = allout-end-of-line-cycles (defcustom allout-end-of-line-cycles t "*If non-nil, \\[allout-end-of-line] will cycle through smart-placement options. Cycling only happens on when the command is repeated, not when it follows a different command. Smart placement means that repeated calls to this function will advance as follows: - if the cursor is not on the end-of-line, then it goes to the end-of-line - if the cursor is on the end-of-line but not the end-of-entry, then it goes to the end-of-entry, exposing it if necessary - if the cursor is on the end-of-entry, then it goes to the end of the head line In this fashion, you can use the end-of-line command to do its normal job and then, when repeated, advance through the entry, cycling back to start. If this configuration variable is nil, then the cursor is just advanced to the end of the line and remains there on repeated calls." :type 'boolean :group 'allout) ;;;_ = allout-header-prefix (defcustom allout-header-prefix "." ;; this string is treated as literal match. it will be `regexp-quote'd, so ;; one cannot use regular expressions to match varying header prefixes. "*Leading string which helps distinguish topic headers. Outline topic header lines are identified by a leading topic header prefix, which mostly have the value of this var at their front. Level 1 topics are exceptions. They consist of only a single character, which is typically set to the `allout-primary-bullet'." :type 'string :group 'allout) (make-variable-buffer-local 'allout-header-prefix) ;;;###autoload (put 'allout-header-prefix 'safe-local-variable 'stringp) ;;;_ = allout-primary-bullet (defcustom allout-primary-bullet "*" "Bullet used for top-level outline topics. Outline topic header lines are identified by a leading topic header prefix, which is concluded by bullets that includes the value of this var and the respective allout-*-bullets-string vars. The value of an asterisk (`*') provides for backwards compatibility with the original Emacs outline mode. See `allout-plain-bullets-string' and `allout-distinctive-bullets-string' for the range of available bullets." :type 'string :group 'allout) (make-variable-buffer-local 'allout-primary-bullet) ;;;###autoload (put 'allout-primary-bullet 'safe-local-variable 'stringp) ;;;_ = allout-plain-bullets-string (defcustom allout-plain-bullets-string ".," "*The bullets normally used in outline topic prefixes. See `allout-distinctive-bullets-string' for the other kind of bullets. DO NOT include the close-square-bracket, `]', as a bullet. Outline mode has to be reactivated in order for changes to the value of this var to take effect." :type 'string :group 'allout) (make-variable-buffer-local 'allout-plain-bullets-string) ;;;###autoload (put 'allout-plain-bullets-string 'safe-local-variable 'stringp) ;;;_ = allout-distinctive-bullets-string (defcustom allout-distinctive-bullets-string "*+-=>()[{}&!?#%\"X@$~_\\:;^" "*Persistent outline header bullets used to distinguish special topics. These bullets are distinguish topics with particular character. They are not used by default in the topic creation routines, but are offered as options when you modify topic creation with a universal argument \(\\[universal-argument]), or during rebulleting \(\\[allout-rebullet-current-heading]). Distinctive bullets are not cycled when topics are shifted or otherwise automatically rebulleted, so their marking is persistent until deliberately changed. Their significance is purely by convention, however. Some conventions suggest themselves: `(' - open paren -- an aside or incidental point `?' - question mark -- uncertain or outright question `!' - exclamation point/bang -- emphatic `[' - open square bracket -- meta-note, about item instead of item's subject `\"' - double quote -- a quotation or other citation `=' - equal sign -- an assignement, equating a name with some connotation `^' - carat -- relates to something above Some are more elusive, but their rationale may be recognizable: `+' - plus -- pending consideration, completion `_' - underscore -- done, completed `&' - ampersand -- addendum, furthermore \(Some other non-plain bullets have special meaning to the software. By default: `~' marks encryptable topics -- see `allout-topic-encryption-bullet' `#' marks auto-numbered bullets -- see `allout-numbered-bullet'.) See `allout-plain-bullets-string' for the standard, alternating bullets. You must run `set-allout-regexp' in order for outline mode to adopt changes of this value. DO NOT include the close-square-bracket, `]', on either of the bullet strings." :type 'string :group 'allout) (make-variable-buffer-local 'allout-distinctive-bullets-string) ;;;###autoload (put 'allout-distinctive-bullets-string 'safe-local-variable 'stringp) ;;;_ = allout-use-mode-specific-leader (defcustom allout-use-mode-specific-leader t "*When non-nil, use mode-specific topic-header prefixes. Allout outline mode will use the mode-specific `allout-mode-leaders' or comment-start string, if any, to lead the topic prefix string, so topic headers look like comments in the programming language. It will also use the comment-start string, with an '_' appended, for `allout-primary-bullet'. String values are used as literals, not regular expressions, so do not escape any regulare-expression characters. Value t means to first check for assoc value in `allout-mode-leaders' alist, then use comment-start string, if any, then use default (`.'). \(See note about use of comment-start strings, below.) Set to the symbol for either of `allout-mode-leaders' or `comment-start' to use only one of them, respectively. Value nil means to always use the default (`.') and leave `allout-primary-bullet' unaltered. comment-start strings that do not end in spaces are tripled in the header-prefix, and an `_' underscore is tacked on the end, to distinguish them from regular comment strings. comment-start strings that do end in spaces are not tripled, but an underscore is substituted for the space. [This presumes that the space is for appearance, not comment syntax. You can use `allout-mode-leaders' to override this behavior, when undesired.]" :type '(choice (const t) (const nil) string (const allout-mode-leaders) (const comment-start)) :group 'allout) ;;;###autoload (put 'allout-use-mode-specific-leader 'safe-local-variable '(lambda (x) (or (memq x '(t nil allout-mode-leaders comment-start)) (stringp x)))) ;;;_ = allout-mode-leaders (defvar allout-mode-leaders '() "Specific allout-prefix leading strings per major modes. Use this if the mode's comment-start string isn't what you prefer, or if the mode lacks a comment-start string. See `allout-use-mode-specific-leader' for more details. If you're constructing a string that will comment-out outline structuring so it can be included in program code, append an extra character, like an \"_\" underscore, to distinguish the lead string from regular comments that start at the beginning-of-line.") ;;;_ = allout-old-style-prefixes (defcustom allout-old-style-prefixes nil "*When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes. Non-nil restricts the topic creation and modification functions to asterix-padded prefixes, so they look exactly like the original Emacs-outline style prefixes. Whatever the setting of this variable, both old and new style prefixes are always respected by the topic maneuvering functions." :type 'boolean :group 'allout) (make-variable-buffer-local 'allout-old-style-prefixes) ;;;###autoload (put 'allout-old-style-prefixes 'safe-local-variable (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil))))) ;;;_ = allout-stylish-prefixes -- alternating bullets (defcustom allout-stylish-prefixes t "*Do fancy stuff with topic prefix bullets according to level, etc. Non-nil enables topic creation, modification, and repositioning functions to vary the topic bullet char (the char that marks the topic depth) just preceding the start of the topic text) according to level. Otherwise, only asterisks (`*') and distinctive bullets are used. This is how an outline can look (but sans indentation) with stylish prefixes: * Top level .* A topic . + One level 3 subtopic . . One level 4 subtopic . . A second 4 subtopic . + Another level 3 subtopic . #1 A numbered level 4 subtopic . #2 Another . ! Another level 4 subtopic with a different distinctive bullet . #4 And another numbered level 4 subtopic This would be an outline with stylish prefixes inhibited (but the numbered and other distinctive bullets retained): * Top level .* A topic . * One level 3 subtopic . * One level 4 subtopic . * A second 4 subtopic . * Another level 3 subtopic . #1 A numbered level 4 subtopic . #2 Another . ! Another level 4 subtopic with a different distinctive bullet . #4 And another numbered level 4 subtopic Stylish and constant prefixes (as well as old-style prefixes) are always respected by the topic maneuvering functions, regardless of this variable setting. The setting of this var is not relevant when `allout-old-style-prefixes' is non-nil." :type 'boolean :group 'allout) (make-variable-buffer-local 'allout-stylish-prefixes) ;;;###autoload (put 'allout-stylish-prefixes 'safe-local-variable (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil))))) ;;;_ = allout-numbered-bullet (defcustom allout-numbered-bullet "#" "*String designating bullet of topics that have auto-numbering; nil for none. Topics having this bullet have automatic maintenance of a sibling sequence-number tacked on, just after the bullet. Conventionally set to \"#\", you can set it to a bullet of your choice. A nil value disables numbering maintenance." :type '(choice (const nil) string) :group 'allout) (make-variable-buffer-local 'allout-numbered-bullet) ;;;###autoload (put 'allout-numbered-bullet 'safe-local-variable (if (fboundp 'string-or-null-p) 'string-or-null-p '(lambda (x) (or (stringp x) (null x))))) ;;;_ = allout-file-xref-bullet (defcustom allout-file-xref-bullet "@" "*Bullet signifying file cross-references, for `allout-resolve-xref'. Set this var to the bullet you want to use for file cross-references." :type '(choice (const nil) string) :group 'allout) ;;;###autoload (put 'allout-file-xref-bullet 'safe-local-variable (if (fboundp 'string-or-null-p) 'string-or-null-p '(lambda (x) (or (stringp x) (null x))))) ;;;_ = allout-presentation-padding (defcustom allout-presentation-padding 2 "*Presentation-format white-space padding factor, for greater indent." :type 'integer :group 'allout) (make-variable-buffer-local 'allout-presentation-padding) ;;;###autoload (put 'allout-presentation-padding 'safe-local-variable 'integerp) ;;;_ = allout-abbreviate-flattened-numbering (defcustom allout-abbreviate-flattened-numbering nil "*If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic numbers to minimal amount with some context. Otherwise, entire numbers are always used." :type 'boolean :group 'allout) ;;;_ + LaTeX formatting ;;;_ - allout-number-pages (defcustom allout-number-pages nil "*Non-nil turns on page numbering for LaTeX formatting of an outline." :type 'boolean :group 'allout) ;;;_ - allout-label-style (defcustom allout-label-style "\\large\\bf" "*Font and size of labels for LaTeX formatting of an outline." :type 'string :group 'allout) ;;;_ - allout-head-line-style (defcustom allout-head-line-style "\\large\\sl " "*Font and size of entries for LaTeX formatting of an outline." :type 'string :group 'allout) ;;;_ - allout-body-line-style (defcustom allout-body-line-style " " "*Font and size of entries for LaTeX formatting of an outline." :type 'string :group 'allout) ;;;_ - allout-title-style (defcustom allout-title-style "\\Large\\bf" "*Font and size of titles for LaTeX formatting of an outline." :type 'string :group 'allout) ;;;_ - allout-title (defcustom allout-title '(or buffer-file-name (buffer-name)) "*Expression to be evaluated to determine the title for LaTeX formatted copy." :type 'sexp :group 'allout) ;;;_ - allout-line-skip (defcustom allout-line-skip ".05cm" "*Space between lines for LaTeX formatting of an outline." :type 'string :group 'allout) ;;;_ - allout-indent (defcustom allout-indent ".3cm" "*LaTeX formatted depth-indent spacing." :type 'string :group 'allout) ;;;_ + Topic encryption ;;;_ = allout-encryption group (defgroup allout-encryption nil "Settings for topic encryption features of allout outliner." :group 'allout) ;;;_ = allout-topic-encryption-bullet (defcustom allout-topic-encryption-bullet "~" "*Bullet signifying encryption of the entry's body." :type '(choice (const nil) string) :version "22.1" :group 'allout-encryption) ;;;_ = allout-passphrase-verifier-handling (defcustom allout-passphrase-verifier-handling t "*Enable use of symmetric encryption passphrase verifier if non-nil. See the docstring for the `allout-enable-file-variable-adjustment' variable for details about allout ajustment of file variables." :type 'boolean :version "22.1" :group 'allout-encryption) (make-variable-buffer-local 'allout-passphrase-verifier-handling) ;;;_ = allout-passphrase-hint-handling (defcustom allout-passphrase-hint-handling 'always "*Dictate outline encryption passphrase reminder handling: always -- always show reminder when prompting needed -- show reminder on passphrase entry failure disabled -- never present or adjust reminder See the docstring for the `allout-enable-file-variable-adjustment' variable for details about allout ajustment of file variables." :type '(choice (const always) (const needed) (const disabled)) :version "22.1" :group 'allout-encryption) (make-variable-buffer-local 'allout-passphrase-hint-handling) ;;;_ = allout-encrypt-unencrypted-on-saves (defcustom allout-encrypt-unencrypted-on-saves t "*When saving, should topics pending encryption be encrypted? The idea is to prevent file-system exposure of any un-encrypted stuff, and mostly covers both deliberate file writes and auto-saves. - Yes: encrypt all topics pending encryption, even if it's the one currently being edited. (In that case, the currently edited topic will be automatically decrypted before any user interaction, so they can continue editing but the copy on the file system will be encrypted.) Auto-saves will use the \"All except current topic\" mode if this one is selected, to avoid practical difficulties -- see below. - All except current topic: skip the topic currently being edited, even if it's pending encryption. This may expose the current topic on the file sytem, but avoids the nuisance of prompts for the encryption passphrase in the middle of editing for, eg, autosaves. This mode is used for auto-saves for both this option and \"Yes\". - No: leave it to the user to encrypt any unencrypted topics. For practical reasons, auto-saves always use the 'except-current policy when auto-encryption is enabled. (Otherwise, spurious passphrase prompts and unavoidable timing collisions are too disruptive.) If security for a file requires that even the current topic is never auto-saved in the clear, disable auto-saves for that file." :type '(choice (const :tag "Yes" t) (const :tag "All except current topic" except-current) (const :tag "No" nil)) :version "22.1" :group 'allout-encryption) (make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves) ;;;_ + Developer ;;;_ = allout-developer group (defgroup allout-developer nil "Settings for topic encryption features of allout outliner." :group 'allout) ;;;_ = allout-run-unit-tests-on-load (defcustom allout-run-unit-tests-on-load nil "*When non-nil, unit tests will be run at end of loading the allout module. Generally, allout code developers are the only ones who'll want to set this. \(If set, this makes it an even better practice to exercise changes by doing byte-compilation with a repeat count, so the file is loaded after compilation.) See `allout-run-unit-tests' to see what's run." :type 'boolean :group 'allout-developer) ;;;_ + Miscellaneous customization ;;;_ = allout-command-prefix (defcustom allout-command-prefix "\C-c " "*Key sequence to be used as prefix for outline mode command key bindings. Default is '\C-c'; just '\C-c' is more short-and-sweet, if you're willing to let allout use a bunch of \C-c keybindings." :type 'string :group 'allout) ;;;_ = allout-keybindings-list ;;; You have to reactivate allout-mode -- `(allout-mode t)' -- to ;;; institute changes to this var. (defvar allout-keybindings-list () "*List of `allout-mode' key / function bindings, for `allout-mode-map'. String or vector key will be prefaced with `allout-command-prefix', unless optional third, non-nil element is present.") (setq allout-keybindings-list '( ; Motion commands: ("\C-n" allout-next-visible-heading) ("\C-p" allout-previous-visible-heading) ("\C-u" allout-up-current-level) ("\C-f" allout-forward-current-level) ("\C-b" allout-backward-current-level) ("\C-a" allout-beginning-of-current-entry) ("\C-e" allout-end-of-entry) ; Exposure commands: ("\C-i" allout-show-children) ("\C-s" allout-show-current-subtree) ("\C-h" allout-hide-current-subtree) ("h" allout-hide-current-subtree) ("\C-o" allout-show-current-entry) ("!" allout-show-all) ("x" allout-toggle-current-subtree-encryption) ; Alteration commands: (" " allout-open-sibtopic) ("." allout-open-subtopic) ("," allout-open-supertopic) ("'" allout-shift-in) (">" allout-shift-in) ("<" allout-shift-out) ("\C-m" allout-rebullet-topic) ("*" allout-rebullet-current-heading) ("#" allout-number-siblings) ("\C-k" allout-kill-line t) ("\M-k" allout-copy-line-as-kill t) ("\C-y" allout-yank t) ("\M-y" allout-yank-pop t) ("\C-k" allout-kill-topic) ("\M-k" allout-copy-topic-as-kill) ; Miscellaneous commands: ;([?\C-\ ] allout-mark-topic) ("@" allout-resolve-xref) ("=c" allout-copy-exposed-to-buffer) ("=i" allout-indented-exposed-to-buffer) ("=t" allout-latexify-exposed) ("=p" allout-flatten-exposed-to-buffer))) ;;;_ = allout-inhibit-auto-fill (defcustom allout-inhibit-auto-fill nil "*If non-nil, auto-fill will be inhibited in the allout buffers. You can customize this setting to set it for all allout buffers, or set it in individual buffers if you want to inhibit auto-fill only in particular buffers. (You could use a function on `allout-mode-hook' to inhibit auto-fill according, eg, to the major mode.) If you don't set this and auto-fill-mode is enabled, allout will use the value that `normal-auto-fill-function', if any, when allout mode starts, or else allout's special hanging-indent maintaining auto-fill function, `allout-auto-fill'." :type 'boolean :group 'allout) (make-variable-buffer-local 'allout-inhibit-auto-fill) ;;;_ = allout-use-hanging-indents (defcustom allout-use-hanging-indents t "*If non-nil, topic body text auto-indent defaults to indent of the header. Ie, it is indented to be just past the header prefix. This is relevant mostly for use with `indented-text-mode', or other situations where auto-fill occurs." :type 'boolean :group 'allout) (make-variable-buffer-local 'allout-use-hanging-indents) ;;;###autoload (put 'allout-use-hanging-indents 'safe-local-variable (if (fboundp 'booleanp) 'booleanp '(lambda (x) (member x '(t nil))))) ;;;_ = allout-reindent-bodies (defcustom allout-reindent-bodies (if allout-use-hanging-indents 'text) "*Non-nil enables auto-adjust of topic body hanging indent with depth shifts. When active, topic body lines that are indented even with or beyond their topic header are reindented to correspond with depth shifts of the header. A value of t enables reindent in non-programming-code buffers, ie those that do not have the variable `comment-start' set. A value of `force' enables reindent whether or not `comment-start' is set." :type '(choice (const nil) (const t) (const text) (const force)) :group 'allout) (make-variable-buffer-local 'allout-reindent-bodies) ;;;###autoload (put 'allout-reindent-bodies 'safe-local-variable '(lambda (x) (memq x '(nil t text force)))) ;;;_ = allout-enable-file-variable-adjustment (defcustom allout-enable-file-variable-adjustment t "*If non-nil, some allout outline actions edit Emacs local file var text. This can range from changes to existing entries, addition of new ones, and creation of a new local variables section when necessary. Emacs file variables adjustments are also inhibited if `enable-local-variables' is nil. Operations potentially causing edits include allout encryption routines. For details, see `allout-toggle-current-subtree-encryption's docstring." :type 'boolean :group 'allout) (make-variable-buffer-local 'allout-enable-file-variable-adjustment) ;;;_* CODE -- no user customizations below. ;;;_ #1 Internal Outline Formatting and Configuration ;;;_ : Version ;;;_ = allout-version (defvar allout-version "2.2.1" "Version of currently loaded outline package. (allout.el)") ;;;_ > allout-version (defun allout-version (&optional here) "Return string describing the loaded outline version." (interactive "P") (let ((msg (concat "Allout Outline Mode v " allout-version))) (if here (insert msg)) (message "%s" msg) msg)) ;;;_ : Mode activation (defined here because it's referenced early) ;;;_ = allout-mode (defvar allout-mode nil "Allout outline mode minor-mode flag.") (make-variable-buffer-local 'allout-mode) ;;;_ = allout-layout nil (defvar allout-layout nil ; LEAVE GLOBAL VALUE NIL -- see docstring. "Buffer-specific setting for allout layout. In buffers where this is non-nil (and if `allout-init' has been run, to enable this behavior), `allout-mode' will be automatically activated. The layout dictated by the value will be used to set the initial exposure when `allout-mode' is activated. \*You should not setq-default this variable non-nil unless you want every visited file to be treated as an allout file.* The value would typically be set by a file local variable. For example, the following lines at the bottom of an Emacs Lisp file: ;;;Local variables: ;;;allout-layout: (0 : -1 -1 0) ;;;End: dictate activation of `allout-mode' mode when the file is visited \(presuming allout-init was already run), followed by the equivalent of `(allout-expose-topic 0 : -1 -1 0)'. (This is the layout used for the allout.el source file.) `allout-default-layout' describes the specification format. `allout-layout' can additionally have the value `t', in which case the value of `allout-default-layout' is used.") (make-variable-buffer-local 'allout-layout) ;;;###autoload (put 'allout-layout 'safe-local-variable '(lambda (x) (or (numberp x) (listp x) (memq x '(: * + -))))) ;;;_ : Topic header format ;;;_ = allout-regexp (defvar allout-regexp "" "*Regular expression to match the beginning of a heading line. Any line whose beginning matches this regexp is considered a heading. This var is set according to the user configuration vars by `set-allout-regexp'.") (make-variable-buffer-local 'allout-regexp) ;;;_ = allout-bullets-string (defvar allout-bullets-string "" "A string dictating the valid set of outline topic bullets. This var should *not* be set by the user -- it is set by `set-allout-regexp', and is produced from the elements of `allout-plain-bullets-string' and `allout-distinctive-bullets-string'.") (make-variable-buffer-local 'allout-bullets-string) ;;;_ = allout-bullets-string-len (defvar allout-bullets-string-len 0 "Length of current buffers' `allout-plain-bullets-string'.") (make-variable-buffer-local 'allout-bullets-string-len) ;;;_ = allout-depth-specific-regexp (defvar allout-depth-specific-regexp "" "*Regular expression to match a heading line prefix for a particular depth. This expression is used to search for depth-specific topic headers at depth 2 and greater. Use `allout-depth-one-regexp' for to seek topics at depth one. This var is set according to the user configuration vars by `set-allout-regexp'. It is prepared with format strings for two decimal numbers, which should each be one less than the depth of the topic prefix to be matched.") (make-variable-buffer-local 'allout-depth-specific-regexp) ;;;_ = allout-depth-one-regexp (defvar allout-depth-one-regexp "" "*Regular expression to match a heading line prefix for depth one. This var is set according to the user configuration vars by `set-allout-regexp'. It is prepared with format strings for two decimal numbers, which should each be one less than the depth of the topic prefix to be matched.") (make-variable-buffer-local 'allout-depth-one-regexp) ;;;_ = allout-line-boundary-regexp (defvar allout-line-boundary-regexp () "`allout-regexp' with outline style beginning-of-line anchor. This is properly set by `set-allout-regexp'.") (make-variable-buffer-local 'allout-line-boundary-regexp) ;;;_ = allout-bob-regexp (defvar allout-bob-regexp () "Like `allout-line-boundary-regexp', for headers at beginning of buffer.") (make-variable-buffer-local 'allout-bob-regexp) ;;;_ = allout-header-subtraction (defvar allout-header-subtraction (1- (length allout-header-prefix)) "Allout-header prefix length to subtract when computing topic depth.") (make-variable-buffer-local 'allout-header-subtraction) ;;;_ = allout-plain-bullets-string-len (defvar allout-plain-bullets-string-len (length allout-plain-bullets-string) "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.") (make-variable-buffer-local 'allout-plain-bullets-string-len) ;;;_ = allout-doublecheck-at-and-shallower (defconst allout-doublecheck-at-and-shallower 2 "Validate apparent topics of this depth and shallower as being non-aberrant. Verified with `allout-aberrant-container-p'. This check's usefulness is limited to shallow depths, because the determination of aberrance is according to the mistaken item being followed by a legitimate item of excessively greater depth.") ;;;_ X allout-reset-header-lead (header-lead) (defun allout-reset-header-lead (header-lead) "*Reset the leading string used to identify topic headers." (interactive "sNew lead string: ") (setq allout-header-prefix header-lead) (setq allout-header-subtraction (1- (length allout-header-prefix))) (set-allout-regexp)) ;;;_ X allout-lead-with-comment-string (header-lead) (defun allout-lead-with-comment-string (&optional header-lead) "*Set the topic-header leading string to specified string. Useful when for encapsulating outline structure in programming language comments. Returns the leading string." (interactive "P") (if (not (stringp header-lead)) (setq header-lead (read-string "String prefix for topic headers: "))) (setq allout-reindent-bodies nil) (allout-reset-header-lead header-lead) header-lead) ;;;_ > allout-infer-header-lead-and-primary-bullet () (defun allout-infer-header-lead-and-primary-bullet () "Determine appropriate `allout-header-prefix' and `allout-primary-bullet'. Works according to settings of: `comment-start' `allout-header-prefix' (default) `allout-use-mode-specific-leader' and `allout-mode-leaders'. Apply this via (re)activation of `allout-mode', rather than invoking it directly." (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader) (if (or (stringp allout-use-mode-specific-leader) (memq allout-use-mode-specific-leader '(allout-mode-leaders comment-start t))) allout-use-mode-specific-leader ;; Oops -- garbled value, equate with effect of t: t))) (leader (cond ((not use-leader) nil) ;; Use the explicitly designated leader: ((stringp use-leader) use-leader) (t (or (and (memq use-leader '(t allout-mode-leaders)) ;; Get it from outline mode leaders? (cdr (assq major-mode allout-mode-leaders))) ;; ... didn't get from allout-mode-leaders... (and (memq use-leader '(t comment-start)) comment-start ;; Use comment-start, maybe tripled, and with ;; underscore: (concat (if (string= " " (substring comment-start (1- (length comment-start)))) ;; Use comment-start, sans trailing space: (substring comment-start 0 -1) (concat comment-start comment-start comment-start)) ;; ... and append underscore, whichever: "_"))))))) (if (not leader) nil (setq allout-header-prefix leader) (if (not allout-old-style-prefixes) ;; setting allout-primary-bullet makes the top level topics use -- ;; actually, be -- the special prefix: (setq allout-primary-bullet leader)) allout-header-prefix))) (defalias 'allout-infer-header-lead 'allout-infer-header-lead-and-primary-bullet) ;;;_ > allout-infer-body-reindent () (defun allout-infer-body-reindent () "Determine proper setting for `allout-reindent-bodies'. Depends on default setting of `allout-reindent-bodies' (which see) and presence of setting for `comment-start', to tell whether the file is programming code." (if (and allout-reindent-bodies comment-start (not (eq 'force allout-reindent-bodies))) (setq allout-reindent-bodies nil))) ;;;_ > set-allout-regexp () (defun set-allout-regexp () "Generate proper topic-header regexp form for outline functions. Works with respect to `allout-plain-bullets-string' and `allout-distinctive-bullets-string'. Also refresh various data structures that hinge on the regexp." (interactive) ;; Derive allout-bullets-string from user configured components: (setq allout-bullets-string "") (let ((strings (list 'allout-plain-bullets-string 'allout-distinctive-bullets-string 'allout-primary-bullet)) cur-string cur-len cur-char index) (while strings (setq index 0) (setq cur-len (length (setq cur-string (symbol-value (car strings))))) (while (< index cur-len) (setq cur-char (aref cur-string index)) (setq allout-bullets-string (concat allout-bullets-string (cond ; Single dash would denote a ; sequence, repeated denotes ; a dash: ((eq cur-char ?-) "--") ; literal close-square-bracket ; doesn't work right in the ; expr, exclude it: ((eq cur-char ?\]) "") (t (regexp-quote (char-to-string cur-char)))))) (setq index (1+ index))) (setq strings (cdr strings))) ) ;; Derive next for repeated use in allout-pending-bullet: (setq allout-plain-bullets-string-len (length allout-plain-bullets-string)) (setq allout-header-subtraction (1- (length allout-header-prefix))) (let (new-part old-part) (setq new-part (concat "\\(" (regexp-quote allout-header-prefix) "[ \t]*" ;; already regexp-quoted in a custom way: "[" allout-bullets-string "]" "\\)") old-part (concat "\\(" (regexp-quote allout-primary-bullet) "\\|" (regexp-quote allout-header-prefix) "\\)" "+" " ?[^" allout-primary-bullet "]") allout-regexp (concat new-part "\\|" old-part "\\|\^l") allout-line-boundary-regexp (concat "\n" new-part "\\|" "\n" old-part) allout-bob-regexp (concat "\\`" new-part "\\|" "\\`" old-part)) (setq allout-depth-specific-regexp (concat "\\(^\\|\\`\\)" "\\(" ;; new-style spacers-then-bullet string: "\\(" (allout-format-quote (regexp-quote allout-header-prefix)) " \\{%s\\}" "[" (allout-format-quote allout-bullets-string) "]" "\\)" ;; old-style all-bullets string, if primary not multi-char: (if (< 0 allout-header-subtraction) "" (concat "\\|\\(" (allout-format-quote (regexp-quote allout-primary-bullet)) (allout-format-quote (regexp-quote allout-primary-bullet)) (allout-format-quote (regexp-quote allout-primary-bullet)) "\\{%s\\}" ;; disqualify greater depths: "[^" (allout-format-quote allout-primary-bullet) "]\\)" )) "\\)" )) (setq allout-depth-one-regexp (concat "\\(^\\|\\`\\)" "\\(" "\\(" (regexp-quote allout-header-prefix) ;; disqualify any bullet char following any amount of ;; intervening whitespace: " *" (concat "[^ " allout-bullets-string "]") "\\)" (if (< 0 allout-header-subtraction) ;; Need not support anything like the old ;; bullet style if the prefix is multi-char. "" (concat "\\|" (regexp-quote allout-primary-bullet) ;; disqualify deeper primary-bullet sequences: "[^" allout-primary-bullet "]")) "\\)" )))) ;;;_ : Key bindings ;;;_ = allout-mode-map (defvar allout-mode-map nil "Keybindings for (allout) outline minor mode.") ;;;_ > produce-allout-mode-map (keymap-alist &optional base-map) (defun produce-allout-mode-map (keymap-list &optional base-map) "Produce keymap for use as `allout-mode-map', from KEYMAP-LIST. Built on top of optional BASE-MAP, or empty sparse map if none specified. See doc string for `allout-keybindings-list' for format of binding list." (let ((map (or base-map (make-sparse-keymap))) (pref (list allout-command-prefix))) (mapcar (function (lambda (cell) (let ((add-pref (null (cdr (cdr cell)))) (key-suff (list (car cell)))) (apply 'define-key (list map (apply 'concat (if add-pref (append pref key-suff) key-suff)) (car (cdr cell))))))) keymap-list) map)) ;;;_ : Menu bar (defvar allout-mode-exposure-menu) (defvar allout-mode-editing-menu) (defvar allout-mode-navigation-menu) (defvar allout-mode-misc-menu) (defun produce-allout-mode-menubar-entries () (require 'easymenu) (easy-menu-define allout-mode-exposure-menu allout-mode-map "Allout outline exposure menu." '("Exposure" ["Show Entry" allout-show-current-entry t] ["Show Children" allout-show-children t] ["Show Subtree" allout-show-current-subtree t] ["Hide Subtree" allout-hide-current-subtree t] ["Hide Leaves" allout-hide-current-leaves t] "----" ["Show All" allout-show-all t])) (easy-menu-define allout-mode-editing-menu allout-mode-map "Allout outline editing menu." '("Headings" ["Open Sibling" allout-open-sibtopic t] ["Open Subtopic" allout-open-subtopic t] ["Open Supertopic" allout-open-supertopic t] "----" ["Shift Topic In" allout-shift-in t] ["Shift Topic Out" allout-shift-out t] ["Rebullet Topic" allout-rebullet-topic t] ["Rebullet Heading" allout-rebullet-current-heading t] ["Number Siblings" allout-number-siblings t] "----" ["Toggle Topic Encryption" allout-toggle-current-subtree-encryption (> (allout-current-depth) 1)])) (easy-menu-define allout-mode-navigation-menu allout-mode-map "Allout outline navigation menu." '("Navigation" ["Next Visible Heading" allout-next-visible-heading t] ["Previous Visible Heading" allout-previous-visible-heading t] "----" ["Up Level" allout-up-current-level t] ["Forward Current Level" allout-forward-current-level t] ["Backward Current Level" allout-backward-current-level t] "----" ["Beginning of Entry" allout-beginning-of-current-entry t] ["End of Entry" allout-end-of-entry t] ["End of Subtree" allout-end-of-current-subtree t])) (easy-menu-define allout-mode-misc-menu allout-mode-map "Allout outlines miscellaneous bindings." '("Misc" ["Version" allout-version t] "----" ["Duplicate Exposed" allout-copy-exposed-to-buffer t] ["Duplicate Exposed, numbered" allout-flatten-exposed-to-buffer t] ["Duplicate Exposed, indented" allout-indented-exposed-to-buffer t] "----" ["Set Header Lead" allout-reset-header-lead t] ["Set New Exposure" allout-expose-topic t]))) ;;;_ : Allout Modal-Variables Utilities ;;;_ = allout-mode-prior-settings (defvar allout-mode-prior-settings nil "Internal `allout-mode' use; settings to be resumed on mode deactivation. See `allout-add-resumptions' and `allout-do-resumptions'.") (make-variable-buffer-local 'allout-mode-prior-settings) ;;;_ > allout-add-resumptions (&rest pairs) (defun allout-add-resumptions (&rest pairs) "Set name/value PAIRS. Old settings are preserved for later resumption using `allout-do-resumptions'. The new values are set as a buffer local. On resumption, the prior buffer scope of the variable is restored along with its value. If it was a void buffer-local value, then it is left as nil on resumption. The pairs are lists whose car is the name of the variable and car of the cdr is the new value: '(some-var some-value)'. The pairs can actually be triples, where the third element qualifies the disposition of the setting, as described further below. If the optional third element is the symbol 'extend, then the new value created by `cons'ing the second element of the pair onto the front of the existing value. If the optional third element is the symbol 'append, then the new value is extended from the existing one by `append'ing a list containing the second element of the pair onto the end of the existing value. Extension, and resumptions in general, should not be used for hook functions -- use the 'local mode of `add-hook' for that, instead. The settings are stored on `allout-mode-prior-settings'." (while pairs (let* ((pair (pop pairs)) (name (car pair)) (value (cadr pair)) (qualifier (if (> (length pair) 2) (caddr pair))) prior-value) (if (not (symbolp name)) (error "Pair's name, %S, must be a symbol, not %s" name (type-of name))) (setq prior-value (condition-case nil (symbol-value name) (void-variable nil))) (when (not (assoc name allout-mode-prior-settings)) ;; Not already added as a resumption, create the prior setting entry. (if (local-variable-p name) ;; is already local variable -- preserve the prior value: (push (list name prior-value) allout-mode-prior-settings) ;; wasn't local variable, indicate so for resumption by killing ;; local value, and make it local: (push (list name) allout-mode-prior-settings) (make-local-variable name))) (if qualifier (cond ((eq qualifier 'extend) (if (not (listp prior-value)) (error "extension of non-list prior value attempted") (set name (cons value prior-value)))) ((eq qualifier 'append) (if (not (listp prior-value)) (error "appending of non-list prior value attempted") (set name (append prior-value (list value))))) (t (error "unrecognized setting qualifier `%s' encountered" qualifier))) (set name value))))) ;;;_ > allout-do-resumptions () (defun allout-do-resumptions () "Resume all name/value settings registered by `allout-add-resumptions'. This is used when concluding allout-mode, to resume selected variables to their settings before allout-mode was started." (while allout-mode-prior-settings (let* ((pair (pop allout-mode-prior-settings)) (name (car pair)) (value-cell (cdr pair))) (if (not value-cell) ;; Prior value was global: (kill-local-variable name) ;; Prior value was explicit: (set name (car value-cell)))))) ;;;_ : Mode-specific incidentals ;;;_ > allout-unprotected (expr) (defmacro allout-unprotected (expr) "Enable internal outline operations to alter invisible text." `(let ((inhibit-read-only (if (not buffer-read-only) t)) (inhibit-field-text-motion t)) ,expr)) ;;;_ = allout-mode-hook (defvar allout-mode-hook nil "*Hook that's run when allout mode starts.") ;;;_ = allout-mode-deactivate-hook (defvar allout-mode-deactivate-hook nil "*Hook that's run when allout mode ends.") ;;;_ = allout-exposure-category (defvar allout-exposure-category nil "Symbol for use as allout invisible-text overlay category.") ;;;_ x allout-view-change-hook (defvar allout-view-change-hook nil "*(Deprecated) A hook run after allout outline exposure changes. Switch to using `allout-exposure-change-hook' instead. Both hooks are currently respected, but the other conveys the details of the exposure change via explicit parameters, and this one will eventually be disabled in a subsequent allout version.") ;;;_ = allout-exposure-change-hook (defvar allout-exposure-change-hook nil "*Hook that's run after allout outline subtree exposure changes. It is run at the conclusion of `allout-flag-region'. Functions on the hook must take three arguments: - FROM -- integer indicating the point at the start of the change. - TO -- integer indicating the point of the end of the change. - FLAG -- change mode: nil for exposure, otherwise concealment. This hook might be invoked multiple times by a single command. This hook is replacing `allout-view-change-hook', which is being deprecated and eventually will not be invoked.") ;;;_ = allout-structure-added-hook (defvar allout-structure-added-hook nil "*Hook that's run after addition of items to the outline. Functions on the hook should take two arguments: - NEW-START -- integer indicating position of start of the first new item. - NEW-END -- integer indicating position of end of the last new item. Some edits that introduce new items may missed by this hook: specifically edits that native allout routines do not control. This hook might be invoked multiple times by a single command.") ;;;_ = allout-structure-deleted-hook (defvar allout-structure-deleted-hook nil "*Hook that's run after disciplined deletion of subtrees from the outline. Functions on the hook must take two arguments: - DEPTH -- integer indicating the depth of the subtree that was deleted. - REMOVED-FROM -- integer indicating the point where the subtree was removed. Some edits that remove or invalidate items may missed by this hook: specifically edits that native allout routines do not control. This hook might be invoked multiple times by a single command.") ;;;_ = allout-structure-shifted-hook (defvar allout-structure-shifted-hook nil "*Hook that's run after shifting of items in the outline. Functions on the hook should take two arguments: - DEPTH-CHANGE -- integer indicating depth increase, negative for decrease - START -- integer indicating the start point of the shifted parent item. Some edits that shift items can be missed by this hook: specifically edits that native allout routines do not control. This hook might be invoked multiple times by a single command.") ;;;_ = allout-outside-normal-auto-fill-function (defvar allout-outside-normal-auto-fill-function nil "Value of normal-auto-fill-function outside of allout mode. Used by allout-auto-fill to do the mandated normal-auto-fill-function wrapped within allout's automatic fill-prefix setting.") (make-variable-buffer-local 'allout-outside-normal-auto-fill-function) ;;;_ = file-var-bug hack (defvar allout-v18/19-file-var-hack nil "Horrible hack used to prevent invalid multiple triggering of outline mode from prop-line file-var activation. Used by `allout-mode' function to track repeats.") ;;;_ = allout-passphrase-verifier-string (defvar allout-passphrase-verifier-string nil "Setting used to test solicited encryption passphrases against the one already associated with a file. It consists of an encrypted random string useful only to verify that a passphrase entered by the user is effective for decryption. The passphrase itself is \*not* recorded in the file anywhere, and the encrypted contents are random binary characters to avoid exposing greater susceptibility to search attacks. The verifier string is retained as an Emacs file variable, as well as in the Emacs buffer state, if file variable adjustments are enabled. See `allout-enable-file-variable-adjustment' for details about that.") (make-variable-buffer-local 'allout-passphrase-verifier-string) ;;;###autoload (put 'allout-passphrase-verifier-string 'safe-local-variable 'stringp) ;;;_ = allout-passphrase-hint-string (defvar allout-passphrase-hint-string "" "Variable used to retain reminder string for file's encryption passphrase. See the description of `allout-passphrase-hint-handling' for details about how the reminder is deployed. The hint is retained as an Emacs file variable, as well as in the Emacs buffer state, if file variable adjustments are enabled. See `allout-enable-file-variable-adjustment' for details about that.") (make-variable-buffer-local 'allout-passphrase-hint-string) (setq-default allout-passphrase-hint-string "") ;;;###autoload (put 'allout-passphrase-hint-string 'safe-local-variable 'stringp) ;;;_ = allout-after-save-decrypt (defvar allout-after-save-decrypt nil "Internal variable, is nil or has the value of two points: - the location of a topic to be decrypted after saving is done - where to situate the cursor after the decryption is performed This is used to decrypt the topic that was currently being edited, if it was encrypted automatically as part of a file write or autosave.") (make-variable-buffer-local 'allout-after-save-decrypt) ;;;_ = allout-encryption-plaintext-sanitization-regexps (defvar allout-encryption-plaintext-sanitization-regexps nil "List of regexps whose matches are removed from plaintext before encryption. This is for the sake of removing artifacts, like escapes, that are added on and not actually part of the original plaintext. The removal is done just prior to encryption. Entries must be symbols that are bound to the desired values. Each value can be a regexp or a list with a regexp followed by a substitution string. If it's just a regexp, all its matches are removed before the text is encrypted. If it's a regexp and a substitution, the substition is used against the regexp matches, a la `replace-match'.") (make-variable-buffer-local 'allout-encryption-text-removal-regexps) ;;;_ = allout-encryption-ciphertext-rejection-regexps (defvar allout-encryption-ciphertext-rejection-regexps nil "Variable for regexps matching plaintext to remove before encryption. This is for the sake of redoing encryption in cases where the ciphertext incidentally contains strings that would disrupt mode operation -- for example, a line that happens to look like an allout-mode topic prefix. Entries must be symbols that are bound to the desired regexp values. The encryption will be retried up to `allout-encryption-ciphertext-rejection-limit' times, after which an error is raised.") (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps) ;;;_ = allout-encryption-ciphertext-rejection-ceiling (defvar allout-encryption-ciphertext-rejection-ceiling 5 "Limit on number of times encryption ciphertext is rejected. See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.") (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling) ;;;_ > allout-mode-p () ;; Must define this macro above any uses, or byte compilation will lack ;; proper def, if file isn't loaded -- eg, during emacs build! (defmacro allout-mode-p () "Return t if `allout-mode' is active in current buffer." 'allout-mode) ;;;_ > allout-write-file-hook-handler () (defun allout-write-file-hook-handler () "Implement `allout-encrypt-unencrypted-on-saves' policy for file writes." (if (or (not (allout-mode-p)) (not (boundp 'allout-encrypt-unencrypted-on-saves)) (not allout-encrypt-unencrypted-on-saves)) nil (let ((except-mark (and (equal allout-encrypt-unencrypted-on-saves 'except-current) (point-marker)))) (if (save-excursion (goto-char (point-min)) (allout-next-topic-pending-encryption except-mark)) (progn (message "auto-encrypting pending topics") (sit-for 0) (condition-case failure (setq allout-after-save-decrypt (allout-encrypt-decrypted except-mark)) (error (progn (message "allout-write-file-hook-handler suppressing error %s" failure) (sit-for 2)))))) )) nil) ;;;_ > allout-auto-save-hook-handler () (defun allout-auto-save-hook-handler () "Implement `allout-encrypt-unencrypted-on-saves' policy for auto save." (if (and (allout-mode-p) allout-encrypt-unencrypted-on-saves) ;; Always implement 'except-current policy when enabled. (let ((allout-encrypt-unencrypted-on-saves 'except-current)) (allout-write-file-hook-handler)))) ;;;_ > allout-after-saves-handler () (defun allout-after-saves-handler () "Decrypt topic encrypted for save, if it's currently being edited. Ie, if it was pending encryption and contained the point in its body before the save. We use values stored in `allout-after-save-decrypt' to locate the topic and the place for the cursor after the decryption is done." (if (not (and (allout-mode-p) (boundp 'allout-after-save-decrypt) allout-after-save-decrypt)) t (goto-char (car allout-after-save-decrypt)) (let ((was-modified (buffer-modified-p))) (allout-toggle-subtree-encryption) (if (not was-modified) (set-buffer-modified-p nil))) (goto-char (cadr allout-after-save-decrypt)) (setq allout-after-save-decrypt nil)) ) ;;;_ = allout-inhibit-aberrance-doublecheck nil ;; In some exceptional moments, disparate topic depths need to be allowed ;; momentarily, eg when one topic is being yanked into another and they're ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck ;; prevents the aberrance doublecheck to allow, eg, the reconciliation ;; processing to happen in the presence of such discrepancies. It should ;; almost never be needed, however. (defvar allout-inhibit-aberrance-doublecheck nil "Internal state, for momentarily inhibits aberrance doublecheck. This should only be momentarily let-bound non-nil, not set non-nil in a lasting way.") ;;;_ #2 Mode activation ;;;_ = allout-explicitly-deactivated (defvar allout-explicitly-deactivated nil "If t, `allout-mode's last deactivation was deliberate. So `allout-post-command-business' should not reactivate it...") (make-variable-buffer-local 'allout-explicitly-deactivated) ;;;_ > allout-init (&optional mode) (defun allout-init (&optional mode) "Prime `allout-mode' to enable/disable auto-activation, wrt `allout-layout'. MODE is one of the following symbols: - nil (or no argument) deactivate auto-activation/layout; - `activate', enable auto-activation only; - `ask', enable auto-activation, and enable auto-layout but with confirmation for layout operation solicited from user each time; - `report', just report and return the current auto-activation state; - anything else (eg, t) for auto-activation and auto-layout, without any confirmation check. Use this function to setup your Emacs session for automatic activation of allout outline mode, contingent to the buffer-specific setting of the `allout-layout' variable. (See `allout-layout' and `allout-expose-topic' docstrings for more details on auto layout). `allout-init' works by setting up (or removing) the `allout-mode' find-file-hook, and giving `allout-auto-activation' a suitable setting. To prime your Emacs session for full auto-outline operation, include the following two lines in your Emacs init file: \(require 'allout) \(allout-init t)" (interactive) (if (interactive-p) (progn (setq mode (completing-read (concat "Select outline auto setup mode " "(empty for report, ? for options) ") '(("nil")("full")("activate")("deactivate") ("ask") ("report") ("")) nil t)) (if (string= mode "") (setq mode 'report) (setq mode (intern-soft mode))))) (let ;; convenience aliases, for consistent ref to respective vars: ((hook 'allout-find-file-hook) (find-file-hook-var-name (if (boundp 'find-file-hook) 'find-file-hook 'find-file-hooks)) (curr-mode 'allout-auto-activation)) (cond ((not mode) (set find-file-hook-var-name (delq hook (symbol-value find-file-hook-var-name))) (if (interactive-p) (message "Allout outline mode auto-activation inhibited."))) ((eq mode 'report) (if (not (memq hook (symbol-value find-file-hook-var-name))) (allout-init nil) ;; Just punt and use the reports from each of the modes: (allout-init (symbol-value curr-mode)))) (t (add-hook find-file-hook-var-name hook) (set curr-mode ; `set', not `setq'! (cond ((eq mode 'activate) (message "Outline mode auto-activation enabled.") 'activate) ((eq mode 'report) ;; Return the current mode setting: (allout-init mode)) ((eq mode 'ask) (message (concat "Outline mode auto-activation and " "-layout (upon confirmation) enabled.")) 'ask) ((message "Outline mode auto-activation and -layout enabled.") 'full))))))) ;;;_ > allout-setup-menubar () (defun allout-setup-menubar () "Populate the current buffer's menubar with `allout-mode' stuff." (let ((menus (list allout-mode-exposure-menu allout-mode-editing-menu allout-mode-navigation-menu allout-mode-misc-menu)) cur) (while menus (setq cur (car menus) menus (cdr menus)) (easy-menu-add cur)))) ;;;_ > allout-overlay-preparations (defun allout-overlay-preparations () "Set the properties of the allout invisible-text overlay and others." (setplist 'allout-exposure-category nil) (put 'allout-exposure-category 'invisible 'allout) (put 'allout-exposure-category 'evaporate t) ;; XXX We use isearch-open-invisible *and* isearch-mode-end-hook. The ;; latter would be sufficient, but it seems that a separate behavior -- ;; the _transient_ opening of invisible text during isearch -- is keyed to ;; presence of the isearch-open-invisible property -- even though this ;; property controls the isearch _arrival_ behavior. This is the case at ;; least in emacs 21, 22.1, and xemacs 21.4. (put 'allout-exposure-category 'isearch-open-invisible 'allout-isearch-end-handler) (if (featurep 'xemacs) (put 'allout-exposure-category 'start-open t) (put 'allout-exposure-category 'insert-in-front-hooks '(allout-overlay-insert-in-front-handler))) (put 'allout-exposure-category 'modification-hooks '(allout-overlay-interior-modification-handler))) ;;;_ > allout-mode (&optional toggle) ;;;_ : Defun: ;;;###autoload (defun allout-mode (&optional toggle) ;;;_ . Doc string: "Toggle minor mode for controlling exposure and editing of text outlines. \\ Optional prefix argument TOGGLE forces the mode to re-initialize if it is positive, otherwise it turns the mode off. Allout outline mode always runs as a minor mode. Allout outline mode provides extensive outline oriented formatting and manipulation. It enables structural editing of outlines, as well as navigation and exposure. It also is specifically aimed at accommodating syntax-sensitive text like programming languages. (For an example, see the allout code itself, which is organized as an allout outline.) In addition to typical outline navigation and exposure, allout includes: - topic-oriented authoring, including keystroke-based topic creation, repositioning, promotion/demotion, cut, and paste - incremental search with dynamic exposure and reconcealment of hidden text - adjustable format, so programming code can be developed in outline-structure - easy topic encryption and decryption - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control - integral outline layout, for automatic initial exposure when visiting a file - independent extensibility, using comprehensive exposure and authoring hooks and many other features. Below is a description of the key bindings, and then explanation of special `allout-mode' features and terminology. See also the outline menubar additions for quick reference to many of the features, and see the docstring of the function `allout-init' for instructions on priming your emacs session for automatic activation of `allout-mode'. The bindings are dictated by the customizable `allout-keybindings-list' variable. We recommend customizing `allout-command-prefix' to use just `\\C-c' as the command prefix, if the allout bindings don't conflict with any personal bindings you have on \\C-c. In any case, outline structure navigation and authoring is simplified by positioning the cursor on an item's bullet character, the \"hot-spot\" -- then you can invoke allout commands with just the un-prefixed, un-control-shifted command letters. This is described further in the HOT-SPOT Operation section. Exposure Control: ---------------- \\[allout-hide-current-subtree] `allout-hide-current-subtree' \\[allout-show-children] `allout-show-children' \\[allout-show-current-subtree] `allout-show-current-subtree' \\[allout-show-current-entry] `allout-show-current-entry' \\[allout-show-all] `allout-show-all' Navigation: ---------- \\[allout-next-visible-heading] `allout-next-visible-heading' \\[allout-previous-visible-heading] `allout-previous-visible-heading' \\[allout-up-current-level] `allout-up-current-level' \\[allout-forward-current-level] `allout-forward-current-level' \\[allout-backward-current-level] `allout-backward-current-level' \\[allout-end-of-entry] `allout-end-of-entry' \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot) \\[allout-beginning-of-line] `allout-beginning-of-line' -- like regular beginning-of-line, but if immediately repeated cycles to the beginning of the current item and then to the hot-spot (if `allout-beginning-of-line-cycles' is set). Topic Header Production: ----------------------- \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic. \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic. \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent. Topic Level and Prefix Adjustment: --------------------------------- \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper \\[allout-shift-out] `allout-shift-out' ... less deep \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for current topic \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and its' offspring -- distinctive bullets are not changed, others are alternated according to nesting depth. \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings -- the offspring are not affected. With repeat count, revoke numbering. Topic-oriented Killing and Yanking: ---------------------------------- \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring. \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring. \\[allout-kill-line] `allout-kill-line' kill-line, attending to outline structure. \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it. \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to depth of heading if yanking into bare topic heading (ie, prefix sans text). \\[allout-yank-pop] `allout-yank-pop' Is to allout-yank as yank-pop is to yank Topic-oriented Encryption: ------------------------- \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption' Encrypt/Decrypt topic content Misc commands: ------------- M-x outlineify-sticky Activate outline mode for current buffer, and establish a default file-var setting for `allout-layout'. \\[allout-mark-topic] `allout-mark-topic' \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer' Duplicate outline, sans concealed text, to buffer with name derived from derived from that of current buffer -- \"*BUFFERNAME exposed*\". \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer' Like above 'copy-exposed', but convert topic prefixes to section.subsection... numeric format. \\[eval-expression] (allout-init t) Setup Emacs session for outline mode auto-activation. Topic Encryption Outline mode supports gpg encryption of topics, with support for symmetric and key-pair modes, passphrase timeout, passphrase consistency checking, user-provided hinting for symmetric key mode, and auto-encryption of topics pending encryption on save. Topics pending encryption are, by default, automatically encrypted during file saves. If the contents of the topic containing the cursor was encrypted for a save, it is automatically decrypted for continued editing. The aim of these measures is reliable topic privacy while preventing accidents like neglected encryption before saves, forgetting which passphrase was used, and other practical pitfalls. See `allout-toggle-current-subtree-encryption' function docstring and `allout-encrypt-unencrypted-on-saves' customization variable for details. HOT-SPOT Operation Hot-spot operation provides a means for easy, single-keystroke outline navigation and exposure control. When the text cursor is positioned directly on the bullet character of a topic, regular characters (a to z) invoke the commands of the corresponding allout-mode keymap control chars. For example, \"f\" would invoke the command typically bound to \"C-cC-f\" \(\\[allout-forward-current-level] `allout-forward-current-level'). Thus, by positioning the cursor on a topic bullet, you can execute the outline navigation and manipulation commands with a single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get this special translation, so you can use them to get out of the hot-spot and back to normal editing operation. In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]]) is replaced with one that makes it easy to get to the hot-spot. If you repeat it immediately it cycles (if `allout-beginning-of-line-cycles' is set) to the beginning of the item and then, if you hit it again immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry' \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located at the beginning of the current entry. Extending Allout Allout exposure and authoring activites all have associated hooks, by which independent code can cooperate with allout without changes to the allout core. Here are key ones: `allout-mode-hook' `allout-mode-deactivate-hook' `allout-exposure-change-hook' `allout-structure-added-hook' `allout-structure-deleted-hook' `allout-structure-shifted-hook' Terminology Topic hierarchy constituents -- TOPICS and SUBTOPICS: ITEM: A unitary outline element, including the HEADER and ENTRY text. TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH and with no intervening items of lower DEPTH than the container. CURRENT ITEM: The visible ITEM most immediately containing the cursor. DEPTH: The degree of nesting of an ITEM; it increases with containment. The DEPTH is determined by the HEADER PREFIX. The DEPTH is also called the: LEVEL: The same as DEPTH. ANCESTORS: Those ITEMs whose TOPICs contain an ITEM. PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that of the ITEM. OFFSPRING: The ITEMs contained within an ITEM's TOPIC. SUBTOPIC: An OFFSPRING of its ANCESTOR TOPICs. CHILD: An immediate SUBTOPIC of its PARENT. SIBLINGS: TOPICs having the same PARENT and DEPTH. Topic text constituents: HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER text. ENTRY: The text content of an ITEM, before any OFFSPRING, but including the HEADER text and distinct from the ITEM PREFIX. BODY: Same as ENTRY. PREFIX: The leading text of an ITEM which distinguishes it from normal ENTRY text. Allout recognizes the outline structure according to the strict PREFIX format. It consists of a PREFIX-LEAD string, PREFIX-PADDING, and a BULLET. The BULLET might be followed by a number, indicating the ordinal number of the topic among its siblings, or an asterisk indicating encryption, plus an optional space. After that is the ITEM HEADER text, which is not part of the PREFIX. The relative length of the PREFIX determines the nesting DEPTH of the ITEM. PREFIX-LEAD: The string at the beginning of a HEADER PREFIX, by default a `.'. It can be customized by changing the setting of `allout-header-prefix' and then reinitializing `allout-mode'. When the PREFIX-LEAD is set to the comment-string of a programming language, outline structuring can be embedded in program code without interfering with processing of the text (by emacs or the language processor) as program code. This setting happens automatically when allout mode is used in programming-mode buffers. See `allout-use-mode-specific-leader' docstring for more detail. PREFIX-PADDING: Spaces or asterisks which separate the PREFIX-LEAD and the bullet, determining the ITEM's DEPTH. BULLET: A character at the end of the ITEM PREFIX, it must be one of the characters listed on `allout-plain-bullets-string' or `allout-distinctive-bullets-string'. When creating a TOPIC, plain BULLETs are by default used, according to the DEPTH of the TOPIC. Choice among the distinctive BULLETs is offered when you provide a universal argugment \(\\[universal-argument]) to the TOPIC creation command, or when explictly rebulleting a TOPIC. The significance of the various distinctive bullets is purely by convention. See the documentation for the above bullet strings for more details. EXPOSURE: The state of a TOPIC which determines the on-screen visibility of its OFFSPRING and contained ENTRY text. CONCEALED: TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed text is represented by \"...\" ellipses. CONCEALED TOPICs are effectively collapsed within an ANCESTOR. CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED. OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be." ;;;_ . Code (interactive "P") (let* ((active (and (not (equal major-mode 'outline)) (allout-mode-p))) ; Massage universal-arg `toggle' val: (toggle (and toggle (or (and (listp toggle)(car toggle)) toggle))) ; Activation specifically demanded? (explicit-activation (and toggle (or (symbolp toggle) (and (wholenump toggle) (not (zerop toggle)))))) ;; allout-mode already called once during this complex command? (same-complex-command (eq allout-v18/19-file-var-hack (car command-history))) (write-file-hook-var-name (cond ((boundp 'write-file-functions) 'write-file-functions) ((boundp 'write-file-hooks) 'write-file-hooks) (t 'local-write-file-hooks))) do-layout ) ; See comments below re v19.18,.19 bug. (setq allout-v18/19-file-var-hack (car command-history)) (cond ;; Provision for v19.18, 19.19 bug -- ;; Emacs v 19.18, 19.19 file-var code invokes prop-line-designated ;; modes twice when file is visited. We have to avoid toggling mode ;; off on second invocation, so we detect it as best we can, and ;; skip everything. ((and same-complex-command ; Still in same complex command ; as last time `allout-mode' invoked. active ; Already activated. (not explicit-activation) ; Prop-line file-vars don't have args. (string-match "^19.1[89]" ; Bug only known to be in v19.18 and emacs-version)); 19.19. t) ;; Deactivation: ((and (not explicit-activation) (or active toggle)) ; Activation not explicitly ; requested, and either in ; active state or *de*activation ; specifically requested: (setq allout-explicitly-deactivated t) (allout-do-resumptions) (remove-from-invisibility-spec '(allout . t)) (remove-hook 'pre-command-hook 'allout-pre-command-business t) (remove-hook 'post-command-hook 'allout-post-command-business t) (remove-hook 'before-change-functions 'allout-before-change-handler t) (remove-hook 'isearch-mode-end-hook 'allout-isearch-end-handler t) (remove-hook write-file-hook-var-name 'allout-write-file-hook-handler t) (remove-hook 'auto-save-hook 'allout-auto-save-hook-handler t) (remove-overlays (point-min) (point-max) 'category 'allout-exposure-category) (setq allout-mode nil) (run-hooks 'allout-mode-deactivate-hook)) ;; Activation: ((not active) (setq allout-explicitly-deactivated nil) (if allout-old-style-prefixes ;; Inhibit all the fancy formatting: (allout-add-resumptions '(allout-primary-bullet "*"))) (allout-overlay-preparations) ; Doesn't hurt to redo this. (allout-infer-header-lead-and-primary-bullet) (allout-infer-body-reindent) (set-allout-regexp) (allout-add-resumptions '(allout-encryption-ciphertext-rejection-regexps allout-line-boundary-regexp extend) '(allout-encryption-ciphertext-rejection-regexps allout-bob-regexp extend)) ;; Produce map from current version of allout-keybindings-list: (allout-setup-mode-map) (produce-allout-mode-menubar-entries) ;; Include on minor-mode-map-alist, if not already there: (if (not (member '(allout-mode . allout-mode-map) minor-mode-map-alist)) (setq minor-mode-map-alist (cons '(allout-mode . allout-mode-map) minor-mode-map-alist))) (add-to-invisibility-spec '(allout . t)) (allout-add-resumptions '(line-move-ignore-invisible t)) (add-hook 'pre-command-hook 'allout-pre-command-business nil t) (add-hook 'post-command-hook 'allout-post-command-business nil t) (add-hook 'before-change-functions 'allout-before-change-handler nil t) (add-hook 'isearch-mode-end-hook 'allout-isearch-end-handler nil t) (add-hook write-file-hook-var-name 'allout-write-file-hook-handler nil t) (add-hook 'auto-save-hook 'allout-auto-save-hook-handler nil t) ;; Stash auto-fill settings and adjust so custom allout auto-fill ;; func will be used if auto-fill is active or activated. (The ;; custom func respects topic headline, maintains hanging-indents, ;; etc.) (if (and auto-fill-function (not allout-inhibit-auto-fill)) ;; allout-auto-fill will use the stashed values and so forth. (allout-add-resumptions '(auto-fill-function allout-auto-fill))) (allout-add-resumptions (list 'allout-former-auto-filler auto-fill-function) ;; Register allout-auto-fill to be used if ;; filling is active: (list 'allout-outside-normal-auto-fill-function normal-auto-fill-function) '(normal-auto-fill-function allout-auto-fill) ;; Paragraphs are broken by topic headlines. (list 'paragraph-start (concat paragraph-start "\\|^\\(" allout-regexp "\\)")) (list 'paragraph-separate (concat paragraph-separate "\\|^\\(" allout-regexp "\\)"))) (or (assq 'allout-mode minor-mode-alist) (setq minor-mode-alist (cons '(allout-mode " Allout") minor-mode-alist))) (allout-setup-menubar) (if allout-layout (setq do-layout t)) (setq allout-mode t) (run-hooks 'allout-mode-hook)) ;; Reactivation: ((setq do-layout t) (allout-infer-body-reindent)) ) ;; end of activation-mode cases. ;; Do auto layout if warranted: (let ((use-layout (if (listp allout-layout) allout-layout allout-default-layout))) (if (and do-layout allout-auto-activation use-layout (and (not (eq allout-auto-activation 'activate)) (if (eq allout-auto-activation 'ask) (if (y-or-n-p (format "Expose %s with layout '%s'? " (buffer-name) use-layout)) t (message "Skipped %s layout." (buffer-name)) nil) t))) (save-excursion (message "Adjusting '%s' exposure..." (buffer-name)) (goto-char 0) (allout-this-or-next-heading) (condition-case err (progn (apply 'allout-expose-topic (list use-layout)) (message "Adjusting '%s' exposure... done." (buffer-name))) ;; Problem applying exposure -- notify user, but don't ;; interrupt, eg, file visit: (error (message "%s" (car (cdr err))) (sit-for 1)))))) allout-mode ) ; let* ) ; defun (defun allout-setup-mode-map () "Establish allout-mode bindings." (setq-default allout-mode-map (produce-allout-mode-map allout-keybindings-list)) (setq allout-mode-map (produce-allout-mode-map allout-keybindings-list)) (substitute-key-definition 'beginning-of-line 'allout-beginning-of-line allout-mode-map global-map) (substitute-key-definition 'move-beginning-of-line 'allout-beginning-of-line allout-mode-map global-map) (substitute-key-definition 'end-of-line 'allout-end-of-line allout-mode-map global-map) (substitute-key-definition 'move-end-of-line 'allout-end-of-line allout-mode-map global-map) (fset 'allout-mode-map allout-mode-map)) ;; ensure that allout-mode-map has some setting even if allout-mode hasn't ;; been invoked: (allout-setup-mode-map) ;;;_ > allout-minor-mode (defalias 'allout-minor-mode 'allout-mode) ;;;_ > allout-unload-function (defun allout-unload-function () "Unload the allout outline library." (save-current-buffer (dolist (buffer (buffer-list)) (set-buffer buffer) (when allout-mode (allout-mode -1)))) ;; continue standard unloading nil) ;;;_ - Position Assessment ;;;_ > allout-hidden-p (&optional pos) (defsubst allout-hidden-p (&optional pos) "Non-nil if the character after point is invisible." (eq (get-char-property (or pos (point)) 'invisible) 'allout)) ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end ;;; &optional prelen) (defun allout-overlay-insert-in-front-handler (ol after beg end &optional prelen) "Shift the overlay so stuff inserted in front of it are excluded." (if after (move-overlay ol (1+ beg) (overlay-end ol)))) ;;;_ > allout-overlay-interior-modification-handler (ol after beg end ;;; &optional prelen) (defun allout-overlay-interior-modification-handler (ol after beg end &optional prelen) "Get confirmation before making arbitrary changes to invisible text. We expose the invisible text and ask for confirmation. Refusal or `keyboard-quit' abandons the changes, with keyboard-quit additionally reclosing the opened text. No confirmation is necessary when `inhibit-read-only' is set -- eg, allout internal functions use this feature cohesively bunch changes." (when (and (not inhibit-read-only) (not after)) (let ((start (point)) (ol-start (overlay-start ol)) (ol-end (overlay-end ol)) first) (goto-char beg) (while (< (point) end) (when (allout-hidden-p) (allout-show-to-offshoot) (if (allout-hidden-p) (save-excursion (forward-char 1) (allout-show-to-offshoot))) (when (not first) (setq first (point)))) (goto-char (if (featurep 'xemacs) (next-property-change (1+ (point)) nil end) (next-char-property-change (1+ (point)) end)))) (when first (goto-char first) (condition-case nil (if (not (yes-or-no-p (substitute-command-keys (concat "Modify concealed text? (\"no\" just aborts," " \\[keyboard-quit] also reconceals) ")))) (progn (goto-char start) (error "Concealed-text change refused."))) (quit (allout-flag-region ol-start ol-end nil) (allout-flag-region ol-start ol-end t) (error "Concealed-text change abandoned, text reconcealed.")))) (goto-char start)))) ;;;_ > allout-before-change-handler (beg end) (defun allout-before-change-handler (beg end) "Protect against changes to invisible text. See `allout-overlay-interior-modification-handler' for details." (if (and (allout-mode-p) undo-in-progress (allout-hidden-p)) (allout-show-to-offshoot)) ;; allout-overlay-interior-modification-handler on an overlay handles ;; this in other emacs, via `allout-exposure-category's 'modification-hooks. (when (and (featurep 'xemacs) (allout-mode-p)) ;; process all of the pending overlays: (save-excursion (goto-char beg) (let ((overlay (allout-get-invisibility-overlay))) (allout-overlay-interior-modification-handler overlay nil beg end nil))))) ;;;_ > allout-isearch-end-handler (&optional overlay) (defun allout-isearch-end-handler (&optional overlay) "Reconcile allout outline exposure on arriving in hidden text after isearch. Optional OVERLAY parameter is for when this function is used by `isearch-open-invisible' overlay property. It is otherwise unused, so this function can also be used as an `isearch-mode-end-hook'." (if (and (allout-mode-p) (allout-hidden-p)) (allout-show-to-offshoot))) ;;;_ #3 Internal Position State-Tracking -- "allout-recent-*" funcs ;;; All the basic outline functions that directly do string matches to ;;; evaluate heading prefix location set the variables ;;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end' ;;; when successful. Functions starting with `allout-recent-' all ;;; use this state, providing the means to avoid redundant searches ;;; for just-established data. This optimization can provide ;;; significant speed improvement, but it must be employed carefully. ;;;_ = allout-recent-prefix-beginning (defvar allout-recent-prefix-beginning 0 "Buffer point of the start of the last topic prefix encountered.") (make-variable-buffer-local 'allout-recent-prefix-beginning) ;;;_ = allout-recent-prefix-end (defvar allout-recent-prefix-end 0 "Buffer point of the end of the last topic prefix encountered.") (make-variable-buffer-local 'allout-recent-prefix-end) ;;;_ = allout-recent-depth (defvar allout-recent-depth 0 "Depth of the last topic prefix encountered.") (make-variable-buffer-local 'allout-recent-depth) ;;;_ = allout-recent-end-of-subtree (defvar allout-recent-end-of-subtree 0 "Buffer point last returned by `allout-end-of-current-subtree'.") (make-variable-buffer-local 'allout-recent-end-of-subtree) ;;;_ > allout-prefix-data () (defsubst allout-prefix-data () "Register allout-prefix state data. For reference by `allout-recent' funcs. Return the new value of `allout-recent-prefix-beginning'." (setq allout-recent-prefix-end (or (match-end 1) (match-end 2)) allout-recent-prefix-beginning (or (match-beginning 1) (match-beginning 2)) allout-recent-depth (max 1 (- allout-recent-prefix-end allout-recent-prefix-beginning allout-header-subtraction))) allout-recent-prefix-beginning) ;;;_ > nullify-allout-prefix-data () (defsubst nullify-allout-prefix-data () "Mark allout prefix data as being uninformative." (setq allout-recent-prefix-end (point) allout-recent-prefix-beginning (point) allout-recent-depth 0) allout-recent-prefix-beginning) ;;;_ > allout-recent-depth () (defsubst allout-recent-depth () "Return depth of last heading encountered by an outline maneuvering function. All outline functions which directly do string matches to assess headings set the variables `allout-recent-prefix-beginning' and `allout-recent-prefix-end' if successful. This function uses those settings to return the current depth." allout-recent-depth) ;;;_ > allout-recent-prefix () (defsubst allout-recent-prefix () "Like `allout-recent-depth', but returns text of last encountered prefix. All outline functions which directly do string matches to assess headings set the variables `allout-recent-prefix-beginning' and `allout-recent-prefix-end' if successful. This function uses those settings to return the current prefix." (buffer-substring-no-properties allout-recent-prefix-beginning allout-recent-prefix-end)) ;;;_ > allout-recent-bullet () (defmacro allout-recent-bullet () "Like allout-recent-prefix, but returns bullet of last encountered prefix. All outline functions which directly do string matches to assess headings set the variables `allout-recent-prefix-beginning' and `allout-recent-prefix-end' if successful. This function uses those settings to return the current depth of the most recently matched topic." '(buffer-substring-no-properties (1- allout-recent-prefix-end) allout-recent-prefix-end)) ;;;_ #4 Navigation ;;;_ - Position Assessment ;;;_ : Location Predicates ;;;_ > allout-do-doublecheck () (defsubst allout-do-doublecheck () "True if current item conditions qualify for checking on topic aberrance." (and ;; presume integrity of outline and yanked content during yank -- necessary ;; to allow for level disparity of yank location and yanked text: (not allout-inhibit-aberrance-doublecheck) ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck: (<= allout-recent-depth allout-doublecheck-at-and-shallower))) ;;;_ > allout-aberrant-container-p () (defun allout-aberrant-container-p () "True if topic, or next sibling with children, contains them discontinuously. Discontinuous means an immediate offspring that is nested more than one level deeper than the topic. If topic has no offspring, then the next sibling with offspring will determine whether or not this one is determined to be aberrant. If true, then the allout-recent-* settings are calibrated on the offspring that qaulifies it as aberrant, ie with depth that exceeds the topic by more than one." ;; This is most clearly understood when considering standard-prefix-leader ;; low-level topics, which can all too easily match text not intended as ;; headers. For example, any line with a leading '.' or '*' and lacking a ;; following bullet qualifies without this protection. (A sequence of ;; them can occur naturally, eg a typical textual bullet list.) We ;; disqualify such low-level sequences when they are followed by a ;; discontinuously contained child, inferring that the sequences are not ;; actually connected with their prospective context. (let ((depth (allout-depth)) (start-point (point)) done aberrant) (save-excursion (while (and (not done) (re-search-forward allout-line-boundary-regexp nil 0)) (allout-prefix-data) (goto-char allout-recent-prefix-beginning) (cond ;; sibling -- continue: ((eq allout-recent-depth depth)) ;; first offspring is excessive -- aberrant: ((> allout-recent-depth (1+ depth)) (setq done t aberrant t)) ;; next non-sibling is lower-depth -- not aberrant: (t (setq done t))))) (if aberrant aberrant (goto-char start-point) ;; recalibrate allout-recent-* (allout-depth) nil))) ;;;_ > allout-on-current-heading-p () (defun allout-on-current-heading-p () "Return non-nil if point is on current visible topics' header line. Actually, returns prefix beginning point." (save-excursion (allout-beginning-of-current-line) (and (looking-at allout-regexp) (allout-prefix-data) (or (not (allout-do-doublecheck)) (not (allout-aberrant-container-p)))))) ;;;_ > allout-on-heading-p () (defalias 'allout-on-heading-p 'allout-on-current-heading-p) ;;;_ > allout-e-o-prefix-p () (defun allout-e-o-prefix-p () "True if point is located where current topic prefix ends, heading begins." (and (save-excursion (let ((inhibit-field-text-motion t)) (beginning-of-line)) (looking-at allout-regexp)) (= (point)(save-excursion (allout-end-of-prefix)(point))))) ;;;_ : Location attributes ;;;_ > allout-depth () (defun allout-depth () "Return depth of topic most immediately containing point. Return zero if point is not within any topic. Like `allout-current-depth', but respects hidden as well as visible topics." (save-excursion (let ((start-point (point))) (if (and (allout-goto-prefix) (not (< start-point (point)))) allout-recent-depth (progn ;; Oops, no prefix, nullify it: (nullify-allout-prefix-data) ;; ... and return 0: 0))))) ;;;_ > allout-current-depth () (defun allout-current-depth () "Return depth of visible topic most immediately containing point. Return zero if point is not within any topic." (save-excursion (if (allout-back-to-current-heading) (max 1 (- allout-recent-prefix-end allout-recent-prefix-beginning allout-header-subtraction)) 0))) ;;;_ > allout-get-current-prefix () (defun allout-get-current-prefix () "Topic prefix of the current topic." (save-excursion (if (allout-goto-prefix) (allout-recent-prefix)))) ;;;_ > allout-get-bullet () (defun allout-get-bullet () "Return bullet of containing topic (visible or not)." (save-excursion (and (allout-goto-prefix) (allout-recent-bullet)))) ;;;_ > allout-current-bullet () (defun allout-current-bullet () "Return bullet of current (visible) topic heading, or none if none found." (condition-case nil (save-excursion (allout-back-to-current-heading) (buffer-substring-no-properties (- allout-recent-prefix-end 1) allout-recent-prefix-end)) ;; Quick and dirty provision, ostensibly for missing bullet: (args-out-of-range nil)) ) ;;;_ > allout-get-prefix-bullet (prefix) (defun allout-get-prefix-bullet (prefix) "Return the bullet of the header prefix string PREFIX." ;; Doesn't make sense if we're old-style prefixes, but this just ;; oughtn't be called then, so forget about it... (if (string-match allout-regexp prefix) (substring prefix (1- (match-end 2)) (match-end 2)))) ;;;_ > allout-sibling-index (&optional depth) (defun allout-sibling-index (&optional depth) "Item number of this prospective topic among its siblings. If optional arg DEPTH is greater than current depth, then we're opening a new level, and return 0. If less than this depth, ascend to that depth and count..." (save-excursion (cond ((and depth (<= depth 0) 0)) ((or (null depth) (= depth (allout-depth))) (let ((index 1)) (while (allout-previous-sibling allout-recent-depth nil) (setq index (1+ index))) index)) ((< depth allout-recent-depth) (allout-ascend-to-depth depth) (allout-sibling-index)) (0)))) ;;;_ > allout-topic-flat-index () (defun allout-topic-flat-index () "Return a list indicating point's numeric section.subsect.subsubsect... Outermost is first." (let* ((depth (allout-depth)) (next-index (allout-sibling-index depth)) (rev-sibls nil)) (while (> next-index 0) (setq rev-sibls (cons next-index rev-sibls)) (setq depth (1- depth)) (setq next-index (allout-sibling-index depth))) rev-sibls) ) ;;;_ - Navigation routines ;;;_ > allout-beginning-of-current-line () (defun allout-beginning-of-current-line () "Like beginning of line, but to visible text." ;; This combination of move-beginning-of-line and beginning-of-line is ;; deliberate, but the (beginning-of-line) may now be superfluous. (let ((inhibit-field-text-motion t)) (move-beginning-of-line 1) (beginning-of-line) (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p))) (beginning-of-line) (if (or (allout-hidden-p) (not (bolp))) (forward-char -1))))) ;;;_ > allout-end-of-current-line () (defun allout-end-of-current-line () "Move to the end of line, past concealed text if any." ;; XXX This is for symmetry with `allout-beginning-of-current-line' -- ;; `move-end-of-line' doesn't suffer the same problem as ;; `move-beginning-of-line'. (let ((inhibit-field-text-motion t)) (end-of-line) (while (allout-hidden-p) (end-of-line) (if (allout-hidden-p) (forward-char 1))))) ;;;_ > allout-beginning-of-line () (defun allout-beginning-of-line () "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set." (interactive) (if (or (not allout-beginning-of-line-cycles) (not (equal last-command this-command))) (move-beginning-of-line 1) (allout-depth) (let ((beginning-of-body (save-excursion (while (and (allout-do-doublecheck) (allout-aberrant-container-p) (allout-previous-visible-heading 1))) (allout-beginning-of-current-entry) (point)))) (cond ((= (current-column) 0) (goto-char beginning-of-body)) ((< (point) beginning-of-body) (allout-beginning-of-current-line)) ((= (point) beginning-of-body) (goto-char (allout-current-bullet-pos))) (t (allout-beginning-of-current-line) (if (< (point) beginning-of-body) ;; we were on the headline after its start: (goto-char beginning-of-body))))))) ;;;_ > allout-end-of-line () (defun allout-end-of-line () "End-of-line with `allout-end-of-line-cycles' behavior, if set." (interactive) (if (or (not allout-end-of-line-cycles) (not (equal last-command this-command))) (allout-end-of-current-line) (let ((end-of-entry (save-excursion (allout-end-of-entry) (point)))) (cond ((not (eolp)) (allout-end-of-current-line)) ((or (allout-hidden-p) (save-excursion (forward-char -1) (allout-hidden-p))) (allout-back-to-current-heading) (allout-show-current-entry) (allout-show-children) (allout-end-of-entry)) ((>= (point) end-of-entry) (allout-back-to-current-heading) (allout-end-of-current-line)) (t (allout-end-of-entry)))))) ;;;_ > allout-next-heading () (defsubst allout-next-heading () "Move to the heading for the topic (possibly invisible) after this one. Returns the location of the heading, or nil if none found. We skip anomalous low-level topics, a la `allout-aberrant-container-p'." (if (looking-at allout-regexp) (forward-char 1)) (when (re-search-forward allout-line-boundary-regexp nil 0) (allout-prefix-data) (and (allout-do-doublecheck) ;; this will set allout-recent-* on the first non-aberrant topic, ;; whether it's the current one or one that disqualifies it: (allout-aberrant-container-p)) (goto-char allout-recent-prefix-beginning))) ;;;_ > allout-this-or-next-heading (defun allout-this-or-next-heading () "Position cursor on current or next heading." ;; A throwaway non-macro that is defined after allout-next-heading ;; and usable by allout-mode. (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading))) ;;;_ > allout-previous-heading () (defun allout-previous-heading () "Move to the prior (possibly invisible) heading line. Return the location of the beginning of the heading, or nil if not found. We skip anomalous low-level topics, a la `allout-aberrant-container-p'." (if (bobp) nil (let ((start-point (point))) ;; allout-goto-prefix-doublechecked calls us, so we can't use it here. (allout-goto-prefix) (when (or (re-search-backward allout-line-boundary-regexp nil 0) (looking-at allout-bob-regexp)) (goto-char (allout-prefix-data)) (if (and (allout-do-doublecheck) (allout-aberrant-container-p)) (or (allout-previous-heading) (and (goto-char start-point) ;; recalibrate allout-recent-*: (allout-depth) nil)) (point)))))) ;;;_ > allout-get-invisibility-overlay () (defun allout-get-invisibility-overlay () "Return the overlay at point that dictates allout invisibility." (let ((overlays (overlays-at (point))) got) (while (and overlays (not got)) (if (equal (overlay-get (car overlays) 'invisible) 'allout) (setq got (car overlays)) (pop overlays))) got)) ;;;_ > allout-back-to-visible-text () (defun allout-back-to-visible-text () "Move to most recent prior character that is visible, and return point." (if (allout-hidden-p) (goto-char (overlay-start (allout-get-invisibility-overlay)))) (point)) ;;;_ - Subtree Charting ;;;_ " These routines either produce or assess charts, which are ;;; nested lists of the locations of topics within a subtree. ;;; ;;; Charts enable efficient subtree navigation by providing a reusable basis ;;; for elaborate, compound assessment and adjustment of a subtree. ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth) (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth) "Produce a location \"chart\" of subtopics of the containing topic. Optional argument LEVELS specifies a depth limit (relative to start depth) for the chart. Null LEVELS means no limit. When optional argument VISIBLE is non-nil, the chart includes only the visible subelements of the charted subjects. The remaining optional args are for internal use by the function. Point is left at the end of the subtree. Charts are used to capture outline structure, so that outline-altering routines need assess the structure only once, and then use the chart for their elaborate manipulations. The chart entries for the topics are in reverse order, so the last topic is listed first. The entry for each topic consists of an integer indicating the point at the beginning of the topic prefix. Charts for offspring consists of a list containing, recursively, the charts for the respective subtopics. The chart for a topics' offspring precedes the entry for the topic itself. The other function parameters are for internal recursion, and should not be specified by external callers. ORIG-DEPTH is depth of topic at starting point, and PREV-DEPTH is depth of prior topic." (let ((original (not orig-depth)) ; `orig-depth' set only in recursion. chart curr-depth) (if original ; Just starting? ; Register initial settings and ; position to first offspring: (progn (setq orig-depth (allout-depth)) (or prev-depth (setq prev-depth (1+ orig-depth))) (if visible (allout-next-visible-heading 1) (allout-next-heading)))) ;; Loop over the current levels' siblings. Besides being more ;; efficient than tail-recursing over a level, it avoids exceeding ;; the typically quite constrained Emacs max-lisp-eval-depth. ;; ;; Probably would speed things up to implement loop-based stack ;; operation rather than recursing for lower levels. Bah. (while (and (not (eobp)) ; Still within original topic? (< orig-depth (setq curr-depth allout-recent-depth)) (cond ((= prev-depth curr-depth) ;; Register this one and move on: (setq chart (cons allout-recent-prefix-beginning chart)) (if (and levels (<= levels 1)) ;; At depth limit -- skip sublevels: (or (allout-next-sibling curr-depth) ;; or no more siblings -- proceed to ;; next heading at lesser depth: (while (and (<= curr-depth allout-recent-depth) (if visible (allout-next-visible-heading 1) (allout-next-heading))))) (if visible (allout-next-visible-heading 1) (allout-next-heading)))) ((and (< prev-depth curr-depth) (or (not levels) (> levels 0))) ;; Recurse on deeper level of curr topic: (setq chart (cons (allout-chart-subtree (and levels (1- levels)) visible orig-depth curr-depth) chart)) ;; ... then continue with this one. ) ;; ... else nil if we've ascended back to prev-depth. ))) (if original ; We're at the last sibling on ; the original level. Position ; to the end of it: (progn (and (not (eobp)) (forward-char -1)) (and (= (preceding-char) ?\n) (= (aref (buffer-substring (max 1 (- (point) 3)) (point)) 1) ?\n) (forward-char -1)) (setq allout-recent-end-of-subtree (point)))) chart ; (nreverse chart) not necessary, ; and maybe not preferable. )) ;;;_ > allout-chart-siblings (&optional start end) (defun allout-chart-siblings (&optional start end) "Produce a list of locations of this and succeeding sibling topics. Effectively a top-level chart of siblings. See `allout-chart-subtree' for an explanation of charts." (save-excursion (when (allout-goto-prefix-doublechecked) (let ((chart (list (point)))) (while (allout-next-sibling) (setq chart (cons (point) chart))) (if chart (setq chart (nreverse chart))))))) ;;;_ > allout-chart-to-reveal (chart depth) (defun allout-chart-to-reveal (chart depth) "Return a flat list of hidden points in subtree CHART, up to DEPTH. If DEPTH is nil, include hidden points at any depth. Note that point can be left at any of the points on chart, or at the start point." (let (result here) (while (and (or (null depth) (> depth 0)) chart) (setq here (car chart)) (if (listp here) (let ((further (allout-chart-to-reveal here (if (null depth) depth (1- depth))))) ;; We're on the start of a subtree -- recurse with it, if there's ;; more depth to go: (if further (setq result (append further result))) (setq chart (cdr chart))) (goto-char here) (if (allout-hidden-p) (setq result (cons here result))) (setq chart (cdr chart)))) result)) ;;;_ X allout-chart-spec (chart spec &optional exposing) ;; (defun allout-chart-spec (chart spec &optional exposing) ;; "Not yet (if ever) implemented. ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC. ;; Exposure spec indicates the locations to be exposed and the prescribed ;; exposure status. Optional arg EXPOSING is an integer, with 0 ;; indicating pending concealment, anything higher indicating depth to ;; which subtopic headers should be exposed, and negative numbers ;; indicating (negative of) the depth to which subtopic headers and ;; bodies should be exposed. ;; The produced list can have two types of entries. Bare numbers ;; indicate points in the buffer where topic headers that should be ;; exposed reside. ;; - bare negative numbers indicates that the topic starting at the ;; point which is the negative of the number should be opened, ;; including their entries. ;; - bare positive values indicate that this topic header should be ;; opened. ;; - Lists signify the beginning and end points of regions that should ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and ;; exposure:" ;; (while spec ;; (cond ((listp spec) ;; ) ;; ) ;; (setq spec (cdr spec))) ;; ) ;;;_ - Within Topic ;;;_ > allout-goto-prefix () (defun allout-goto-prefix () "Put point at beginning of immediately containing outline topic. Goes to most immediate subsequent topic if none immediately containing. Not sensitive to topic visibility. Returns the point at the beginning of the prefix, or nil if none." (let (done) (while (and (not done) (search-backward "\n" nil 1)) (forward-char 1) (if (looking-at allout-regexp) (setq done (allout-prefix-data)) (forward-char -1))) (if (bobp) (cond ((looking-at allout-regexp) (allout-prefix-data)) ((allout-next-heading)) (done)) done))) ;;;_ > allout-goto-prefix-doublechecked () (defun allout-goto-prefix-doublechecked () "Put point at beginning of immediately containing outline topic. Like `allout-goto-prefix', but shallow topics (according to `allout-doublecheck-at-and-shallower') are checked and disqualified for child containment discontinuity, according to `allout-aberrant-container-p'." (if (allout-goto-prefix) (if (and (allout-do-doublecheck) (allout-aberrant-container-p)) (allout-previous-heading) (point)))) ;;;_ > allout-end-of-prefix () (defun allout-end-of-prefix (&optional ignore-decorations) "Position cursor at beginning of header text. If optional IGNORE-DECORATIONS is non-nil, put just after bullet, otherwise skip white space between bullet and ensuing text." (if (not (allout-goto-prefix-doublechecked)) nil (goto-char allout-recent-prefix-end) (if ignore-decorations t (while (looking-at "[0-9]") (forward-char 1)) (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1))) ;; Reestablish where we are: (allout-current-depth))) ;;;_ > allout-current-bullet-pos () (defun allout-current-bullet-pos () "Return position of current (visible) topic's bullet." (if (not (allout-current-depth)) nil (1- allout-recent-prefix-end))) ;;;_ > allout-back-to-current-heading () (defun allout-back-to-current-heading () "Move to heading line of current topic, or beginning if not in a topic. If interactive, we position at the end of the prefix. Return value of resulting point, unless we started outside of (before any) topics, in which case we return nil." (allout-beginning-of-current-line) (let ((bol-point (point))) (if (allout-goto-prefix-doublechecked) (if (<= (point) bol-point) (if (interactive-p) (allout-end-of-prefix) (point)) (goto-char (point-min)) nil)))) ;;;_ > allout-back-to-heading () (defalias 'allout-back-to-heading 'allout-back-to-current-heading) ;;;_ > allout-pre-next-prefix () (defun allout-pre-next-prefix () "Skip forward to just before the next heading line. Returns that character position." (if (allout-next-heading) (goto-char (1- allout-recent-prefix-beginning)))) ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank) (defun allout-end-of-subtree (&optional current include-trailing-blank) "Put point at the end of the last leaf in the containing topic. Optional CURRENT means put point at the end of the containing visible topic. Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if any, as part of the subtree. Otherwise, that trailing blank will be excluded as delimiting whitespace between topics. Returns the value of point." (interactive "P") (if current (allout-back-to-current-heading) (allout-goto-prefix-doublechecked)) (let ((level allout-recent-depth)) (allout-next-heading) (while (and (not (eobp)) (> allout-recent-depth level)) (allout-next-heading)) (if (eobp) (allout-end-of-entry) (forward-char -1)) (if (and (not include-trailing-blank) (= ?\n (preceding-char))) (forward-char -1)) (setq allout-recent-end-of-subtree (point)))) ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank) (defun allout-end-of-current-subtree (&optional include-trailing-blank) "Put point at end of last leaf in currently visible containing topic. Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if any, as part of the subtree. Otherwise, that trailing blank will be excluded as delimiting whitespace between topics. Returns the value of point." (interactive) (allout-end-of-subtree t include-trailing-blank)) ;;;_ > allout-beginning-of-current-entry () (defun allout-beginning-of-current-entry () "When not already there, position point at beginning of current topic header. If already there, move cursor to bullet for hot-spot operation. \(See `allout-mode' doc string for details of hot-spot operation.)" (interactive) (let ((start-point (point))) (move-beginning-of-line 1) (if (< 0 (allout-current-depth)) (goto-char allout-recent-prefix-end) (goto-char (point-min))) (allout-end-of-prefix) (if (and (interactive-p) (= (point) start-point)) (goto-char (allout-current-bullet-pos))))) ;;;_ > allout-end-of-entry (&optional inclusive) (defun allout-end-of-entry (&optional inclusive) "Position the point at the end of the current topics' entry. Optional INCLUSIVE means also include trailing empty line, if any. When unset, whitespace between items separates them even when the items are collapsed." (interactive) (allout-pre-next-prefix) (if (and (not inclusive) (not (bobp)) (= ?\n (preceding-char))) (forward-char -1)) (point)) ;;;_ > allout-end-of-current-heading () (defun allout-end-of-current-heading () (interactive) (allout-beginning-of-current-entry) (search-forward "\n" nil t) (forward-char -1)) (defalias 'allout-end-of-heading 'allout-end-of-current-heading) ;;;_ > allout-get-body-text () (defun allout-get-body-text () "Return the unmangled body text of the topic immediately containing point." (save-excursion (allout-end-of-prefix) (if (not (search-forward "\n" nil t)) nil (backward-char 1) (let ((pre-body (point))) (if (not pre-body) nil (allout-end-of-entry t) (if (not (= pre-body (point))) (buffer-substring-no-properties (1+ pre-body) (point)))) ) ) ) ) ;;;_ - Depth-wise ;;;_ > allout-ascend-to-depth (depth) (defun allout-ascend-to-depth (depth) "Ascend to depth DEPTH, returning depth if successful, nil if not." (if (and (> depth 0)(<= depth (allout-depth))) (let (last-ascended) (while (and (< depth allout-recent-depth) (setq last-ascended (allout-ascend)))) (goto-char allout-recent-prefix-beginning) (if (interactive-p) (allout-end-of-prefix)) (and last-ascended allout-recent-depth)))) ;;;_ > allout-ascend () (defun allout-ascend (&optional dont-move-if-unsuccessful) "Ascend one level, returning resulting depth if successful, nil if not. Point is left at the beginning of the level whether or not successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in which case point is returned to its original starting location." (if dont-move-if-unsuccessful (setq dont-move-if-unsuccessful (point))) (prog1 (if (allout-beginning-of-level) (let ((bolevel (point)) (bolevel-depth allout-recent-depth)) (allout-previous-heading) (cond ((< allout-recent-depth bolevel-depth) allout-recent-depth) ((= allout-recent-depth bolevel-depth) (if dont-move-if-unsuccessful (goto-char dont-move-if-unsuccessful)) (allout-depth) nil) (t ;; some topic after very first is lower depth than first: (goto-char bolevel) (allout-depth) nil)))) (if (interactive-p) (allout-end-of-prefix)))) ;;;_ > allout-descend-to-depth (depth) (defun allout-descend-to-depth (depth) "Descend to depth DEPTH within current topic. Returning depth if successful, nil if not." (let ((start-point (point)) (start-depth (allout-depth))) (while (and (> (allout-depth) 0) (not (= depth allout-recent-depth)) ; ... not there yet (allout-next-heading) ; ... go further (< start-depth allout-recent-depth))) ; ... still in topic (if (and (> (allout-depth) 0) (= allout-recent-depth depth)) depth (goto-char start-point) nil)) ) ;;;_ > allout-up-current-level (arg) (defun allout-up-current-level (arg) "Move out ARG levels from current visible topic." (interactive "p") (let ((start-point (point))) (allout-back-to-current-heading) (if (not (allout-ascend)) (progn (goto-char start-point) (error "Can't ascend past outermost level")) (if (interactive-p) (allout-end-of-prefix)) allout-recent-prefix-beginning))) ;;;_ - Linear ;;;_ > allout-next-sibling (&optional depth backward) (defun allout-next-sibling (&optional depth backward) "Like `allout-forward-current-level', but respects invisible topics. Traverse at optional DEPTH, or current depth if none specified. Go backward if optional arg BACKWARD is non-nil. Return the start point of the new topic if successful, nil otherwise." (if (if backward (bobp) (eobp)) nil (let ((target-depth (or depth (allout-depth))) (start-point (point)) (start-prefix-beginning allout-recent-prefix-beginning) (count 0) leaping last-depth) (while (and ;; done too few single steps to resort to the leap routine: (not leaping) ;; not at limit: (not (if backward (bobp) (eobp))) ;; still traversable: (if backward (allout-previous-heading) (allout-next-heading)) ;; we're below the target depth (> (setq last-depth allout-recent-depth) target-depth)) (setq count (1+ count)) (if (> count 7) ; lists are commonly 7 +- 2, right?-) (setq leaping t))) (cond (leaping (or (allout-next-sibling-leap target-depth backward) (progn (goto-char start-point) (if depth (allout-depth) target-depth) nil))) ((and (not (eobp)) (and (> (or last-depth (allout-depth)) 0) (= allout-recent-depth target-depth)) (not (= start-prefix-beginning allout-recent-prefix-beginning))) allout-recent-prefix-beginning) (t (goto-char start-point) (if depth (allout-depth) target-depth) nil))))) ;;;_ > allout-next-sibling-leap (&optional depth backward) (defun allout-next-sibling-leap (&optional depth backward) "Like `allout-next-sibling', but by direct search for topic at depth. Traverse at optional DEPTH, or current depth if none specified. Go backward if optional arg BACKWARD is non-nil. Return the start point of the new topic if successful, nil otherwise. Costs more than regular `allout-next-sibling' for short traversals: - we have to check the prior (next, if travelling backwards) item to confirm connectivity with the prior topic, and - if confirmed, we have to reestablish the allout-recent-* settings with some extra navigation - if confirmation fails, we have to do more work to recover It is an increasingly big win when there are many intervening offspring before the next sibling, however, so `allout-next-sibling' resorts to this if it finds itself in that situation." (if (if backward (bobp) (eobp)) nil (let* ((start-point (point)) (target-depth (or depth (allout-depth))) (search-whitespace-regexp nil) (depth-biased (- target-depth 2)) (expression (if (<= target-depth 1) allout-depth-one-regexp (format allout-depth-specific-regexp depth-biased depth-biased))) found done) (while (not done) (setq found (if backward (re-search-backward expression nil 'to-limit) (forward-char 1) (re-search-forward expression nil 'to-limit))) (if (and found (allout-aberrant-container-p)) (setq found nil)) (setq done (or found (if backward (bobp) (eobp))))) (if (not found) (progn (goto-char start-point) nil) ;; rationale: if any intervening items were at a lower depth, we ;; would now be on the first offspring at the target depth -- ie, ;; the preceeding item (per the search direction) must be at a ;; lesser depth. that's all we need to check. (if backward (allout-next-heading) (allout-previous-heading)) (if (< allout-recent-depth target-depth) ;; return to start and reestablish allout-recent-*: (progn (goto-char start-point) (allout-depth) nil) (goto-char found) ;; locate cursor and set allout-recent-*: (allout-goto-prefix)))))) ;;;_ > allout-previous-sibling (&optional depth backward) (defun allout-previous-sibling (&optional depth backward) "Like `allout-forward-current-level' backwards, respecting invisible topics. Optional DEPTH specifies depth to traverse, default current depth. Optional BACKWARD reverses direction. Return depth if successful, nil otherwise." (allout-next-sibling depth (not backward)) ) ;;;_ > allout-snug-back () (defun allout-snug-back () "Position cursor at end of previous topic. Presumes point is at the start of a top