;;; outline.el --- outline mode commands for Emacs;; Copyright (C) 1986, 1993, 1994 Free Software Foundation, Inc.;; Maintainer: XEmacs Development Team;; Keywords: outlines;; This file is part of XEmacs.;; XEmacs 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 2, or (at your option);; any later version.;; XEmacs 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 XEmacs; see the file COPYING. If not, write to the Free;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA;; 02111-1307, USA.;;; Synched up with: FSF 19.34.;;; Commentary:;; This package is a major mode for editing outline-format documents.;; An outline can be `abstracted' to show headers at any given level,;; with all stuff below hidden. See the Emacs manual for details.;;; Code:;; Jan '86, Some new features added by Peter Desnoyers and rewritten by RMS.(defvaroutline-regexpnil"*Regular expression to match the beginning of a heading.Any line whose beginning matches this regexp is considered to start a heading.The recommended way to set this is with a Local Variables: listin the file it applies to. See also outline-heading-end-regexp.");; Can't initialize this in the defvar above -- some major modes have;; already assigned a local value to it.(or(default-value'outline-regexp)(setq-defaultoutline-regexp"[*\^L]+"));; XEmacs change(defvaroutline-heading-end-regexp(purecopy"[\n\^M]")"*Regular expression to match the end of a heading line.You can assume that point is at the beginning of a heading when thisregexp is searched for. The heading ends at the end of the match.The recommended way to set this is with a \"Local Variables:\" listin the file it applies to.");; XEmacs: There is no point in doing this differently now. -sb(defvaroutline-mode-prefix-mapnil)(ifoutline-mode-prefix-mapnil(setqoutline-mode-prefix-map(make-sparse-keymap))(define-keyoutline-mode-prefix-map"\C-n"'outline-next-visible-heading)(define-keyoutline-mode-prefix-map"\C-p"'outline-previous-visible-heading)(define-keyoutline-mode-prefix-map"\C-i"'show-children)(define-keyoutline-mode-prefix-map"\C-s"'show-subtree)(define-keyoutline-mode-prefix-map"\C-d"'hide-subtree)(define-keyoutline-mode-prefix-map"\C-u"'outline-up-heading)(define-keyoutline-mode-prefix-map"\C-f"'outline-forward-same-level)(define-keyoutline-mode-prefix-map"\C-b"'outline-backward-same-level)(define-keyoutline-mode-prefix-map"\C-t"'hide-body)(define-keyoutline-mode-prefix-map"\C-a"'show-all)(define-keyoutline-mode-prefix-map"\C-c"'hide-entry)(define-keyoutline-mode-prefix-map"\C-e"'show-entry)(define-keyoutline-mode-prefix-map"\C-l"'hide-leaves)(define-keyoutline-mode-prefix-map"\C-k"'show-branches)(define-keyoutline-mode-prefix-map"\C-q"'hide-sublevels)(define-keyoutline-mode-prefix-map"\C-o"'hide-other))(defvaroutline-mode-menu-bar-mapnil)(ifoutline-mode-menu-bar-mapnil(setqoutline-mode-menu-bar-map(make-sparse-keymap))(define-keyoutline-mode-menu-bar-map[hide](cons"Hide"(make-sparse-keymap"Hide")))(define-keyoutline-mode-menu-bar-map[hidehide-other]'("Hide Other".hide-other))(define-keyoutline-mode-menu-bar-map[hidehide-sublevels]'("Hide Sublevels".hide-sublevels))(define-keyoutline-mode-menu-bar-map[hidehide-subtree]'("Hide Subtree".hide-subtree))(define-keyoutline-mode-menu-bar-map[hidehide-entry]'("Hide Entry".hide-entry))(define-keyoutline-mode-menu-bar-map[hidehide-body]'("Hide Body".hide-body))(define-keyoutline-mode-menu-bar-map[hidehide-leaves]'("Hide Leaves".hide-leaves))(define-keyoutline-mode-menu-bar-map[show](cons"Show"(make-sparse-keymap"Show")))(define-keyoutline-mode-menu-bar-map[showshow-subtree]'("Show Subtree".show-subtree))(define-keyoutline-mode-menu-bar-map[showshow-children]'("Show Children".show-children))(define-keyoutline-mode-menu-bar-map[showshow-branches]'("Show Branches".show-branches))(define-keyoutline-mode-menu-bar-map[showshow-entry]'("Show Entry".show-entry))(define-keyoutline-mode-menu-bar-map[showshow-all]'("Show All".show-all))(define-keyoutline-mode-menu-bar-map[headings](cons"Headings"(make-sparse-keymap"Headings")))(define-keyoutline-mode-menu-bar-map[headingsoutline-backward-same-level]'("Previous Same Level".outline-backward-same-level))(define-keyoutline-mode-menu-bar-map[headingsoutline-forward-same-level]'("Next Same Level".outline-forward-same-level))(define-keyoutline-mode-menu-bar-map[headingsoutline-previous-visible-heading]'("Previous".outline-previous-visible-heading))(define-keyoutline-mode-menu-bar-map[headingsoutline-next-visible-heading]'("Next".outline-next-visible-heading))(define-keyoutline-mode-menu-bar-map[headingsoutline-up-heading]'("Up".outline-up-heading)))(defvaroutline-mode-mapnil"")(ifoutline-mode-mapnil;; XEmacs change;(setq outline-mode-map (nconc (make-sparse-keymap) text-mode-map))(setqoutline-mode-map(make-sparse-keymap'text-mode-map))(define-keyoutline-mode-map"\C-c"outline-mode-prefix-map)(define-keyoutline-mode-map[menu-bar]outline-mode-menu-bar-map));;; #+XEmacs(defvaroutline-mode-menu;; This is the RB menu which also makes 3 menus in the menubar (like;; FSF rather than because it's good)'("Outline"("Headings"["Up"outline-up-headingt]["Next"outline-next-visible-headingt]["Previous"outline-previous-visible-headingt]["Next Same Level"outline-forward-same-levelt]["Previous Same Level"outline-backward-same-levelt])("Show"["Show All"show-allt]["Show Entry"show-entryt]["Show Branches"show-branchest]["Show Children"show-childrent]["Show Subtree"show-subtreet])("Hide"["Hide Leaves"hide-leavest]["Hide Body"hide-bodyt]["Hide Entry"hide-entryt]["Hide Subtree"hide-subtreet]["Hide Other"hide-othert]["Hide Sublevels"hide-sublevelst])));;; #+XEmacs(defunoutline-mode-menu()(interactive)(popup-menuoutline-mode-menu));;; #+XEmacs;;; ?? Is this OK & if so should it be in minor mode too?(define-keyoutline-mode-map[button3]'outline-mode-menu);;; #+XEmacs(defunoutline-install-menubar(&optionalremove);; install or remove the outline menus;; This is a nop if menubars aren't available(when(and(featurep'menubar); XEmacscurrent-menubar)(let((menus(cdroutline-mode-menu))path)(and(notremove)(set-buffer-menubar(copy-sequencecurrent-menubar)))(whilemenus(setqpath(list(car(carmenus))))(if(andremove(find-menu-itemcurrent-menubarpath))(delete-menu-itempath)(or(car(find-menu-itemcurrent-menubarpath))(add-menunil(car(carmenus))(cdr(carmenus))nil)))(setqmenus(cdrmenus))))));;;###autoload(defvaroutline-minor-modenil"Non-nil if using Outline mode as a minor mode of some other mode.");;;###autoload(make-variable-buffer-local'outline-minor-mode);;;###autoload(put'outline-minor-mode'permanent-localt);(or (assq 'outline-minor-mode minor-mode-alist); (setq minor-mode-alist (append minor-mode-alist; (list '(outline-minor-mode " Outl")))));; XEmacs: do it right.;;;###autoload(add-minor-mode'outline-minor-mode" Outl")(defvaroutline-font-lock-keywords'(;; Highlight headings according to the level.("^\\(\\*+\\)[ \t]*\\(.+\\)?[ \t]*$"(1font-lock-string-face)(2(let((len(-(match-end1)(match-beginning1))))(or(cdr(assqlen'((1.font-lock-function-name-face)(2.font-lock-keyword-face)(3.font-lock-comment-face))))font-lock-variable-name-face))nilt));; Highlight citations of the form [1] and [Mar94].("\\[\\([A-Z][A-Za-z]+\\)*[0-9]+\\]".font-lock-type-face))"Additional expressions to highlight in Outline mode.");;; #+XEmacs(defvaroutline-mode-hooknil"Hook to run when entering outline-mode.");;;###autoload(defunoutline-mode()"Set major mode for editing outlines with selective display.Headings are lines which start with asterisks: one for major headings,two for subheadings, etc. Lines not starting with asterisks are body lines. Body text or subheadings under a heading can be made temporarilyinvisible, or visible again. Invisible lines are attached to the end of the heading, so they move with it, if the line is killed and yankedback. A heading with text hidden under it is marked with an ellipsis (...).Commands:\\<outline-mode-map>\\[outline-next-visible-heading] outline-next-visible-heading move by visible headings\\[outline-previous-visible-heading] outline-previous-visible-heading\\[outline-forward-same-level] outline-forward-same-level similar but skip subheadings\\[outline-backward-same-level] outline-backward-same-level\\[outline-up-heading] outline-up-heading move from subheading to heading\\[hide-body] make all text invisible (not headings).\\[show-all] make everything in buffer visible.The remaining commands are used when point is on a heading line.They apply to some of the body or subheadings of that heading.\\[hide-subtree] hide-subtree make body and subheadings invisible.\\[show-subtree] show-subtree make body and subheadings visible.\\[show-children] show-children make direct subheadings visible. No effect on body, or subheadings 2 or more levels down. With arg N, affects subheadings N levels down.\\[hide-entry] make immediately following body invisible.\\[show-entry] make it visible.\\[hide-leaves] make body under heading and under its subheadings invisible. The subheadings remain visible.\\[show-branches] make all subheadings at all levels visible.The variable `outline-regexp' can be changed to control what is a heading.A line is a heading if `outline-regexp' matches something at thebeginning of the line. The longer the match, the deeper the level.Turning on outline mode calls the value of `text-mode-hook' and then of`outline-mode-hook', if they are non-nil."(interactive)(kill-all-local-variables)(setqselective-displayt)(use-local-mapoutline-mode-map)(setqmode-name"Outline")(setqmajor-mode'outline-mode)(define-abbrev-table'text-mode-abbrev-table())(setqlocal-abbrev-tabletext-mode-abbrev-table)(set-syntax-tabletext-mode-syntax-table)(make-local-variable'paragraph-start)(setqparagraph-start(concatparagraph-start"\\|\\("outline-regexp"\\)"));; Inhibit auto-filling of header lines.(make-local-variable'auto-fill-inhibit-regexp)(setqauto-fill-inhibit-regexpoutline-regexp)(make-local-variable'paragraph-separate)(setqparagraph-separate(concatparagraph-separate"\\|\\("outline-regexp"\\)"));; #+XEmacs(outline-install-menubar)(make-local-variable'font-lock-defaults)(setqfont-lock-defaults'(outline-font-lock-keywordst))(make-local-variable'change-major-mode-hook)(add-hook'change-major-mode-hook'show-all)(run-hooks'text-mode-hook'outline-mode-hook))(defvaroutline-minor-mode-prefix"\C-c@""*Prefix key to use for Outline commands in Outline minor mode.The value of this variable is checked as part of loading Outline mode.After that, changing the prefix key requires manipulating keymaps.")(defvaroutline-minor-mode-mapnil)(ifoutline-minor-mode-mapnil(setqoutline-minor-mode-map(make-sparse-keymap))(define-keyoutline-minor-mode-map[menu-bar]outline-mode-menu-bar-map)(define-keyoutline-minor-mode-mapoutline-minor-mode-prefixoutline-mode-prefix-map))(or(assq'outline-minor-modeminor-mode-map-alist)(setqminor-mode-map-alist(cons(cons'outline-minor-modeoutline-minor-mode-map)minor-mode-map-alist)));;;###autoload(defunoutline-minor-mode(&optionalarg)"Toggle Outline minor mode.With arg, turn Outline minor mode on if arg is positive, off otherwise.See the command `outline-mode' for more information on this mode."(interactive"P")(setqoutline-minor-mode(if(nullarg)(notoutline-minor-mode)(>(prefix-numeric-valuearg)0)))(ifoutline-minor-mode(progn(setqselective-displayt);; #+XEmacs(outline-install-menubar)(run-hooks'outline-minor-mode-hook))(setqselective-displaynil));; When turning off outline mode, get rid of any ^M's.(unlessoutline-minor-mode(outline-flag-region(point-min)(point-max)?\n);; XEmacs change(set-buffer-modified-p(buffer-modified-p));; #+XEmacs(outline-install-menubar'remove));; XEmacs change(redraw-modeline))(defvaroutline-level'outline-level"Function of no args to compute a header's nesting level in an outline.It can assume point is at the beginning of a header line.");; This used to count columns rather than characters, but that made ^L;; appear to be at level 2 instead of 1. Columns would be better for;; tab handling, but the default regexp doesn't use tabs, and anyone;; who changes the regexp can also redefine the outline-level variable;; as appropriate.(defunoutline-level()"Return the depth to which a statement is nested in the outline.Point must be at the beginning of a header line. This is actuallythe number of characters that `outline-regexp' matches."(save-excursion(looking-atoutline-regexp)(-(match-end0)(match-beginning0))))(defunoutline-next-preface()"Skip forward to just before the next heading line.If there's no following heading line, stop before the newlineat the end of the buffer."(if(re-search-forward(concat"[\n\^M]\\("outline-regexp"\\)")nil'move)(goto-char(match-beginning0)))(if(memq(preceding-char)'(?\n?\^M))(forward-char-1)))(defunoutline-next-heading()"Move to the next (possibly invisible) heading line."(interactive)(if(re-search-forward(concat"[\n\^M]\\("outline-regexp"\\)")nil'move)(goto-char(1+(match-beginning0)))))(defunoutline-back-to-heading()"Move to previous heading line, or beg of this line if it's a heading.Only visible heading lines are considered."(beginning-of-line)(or(outline-on-heading-p)(re-search-backward(concat"^\\("outline-regexp"\\)")nilt)(error"before first heading")))(defunoutline-on-heading-p()"Return t if point is on a (visible) heading line."(save-excursion(beginning-of-line)(and(bolp)(looking-atoutline-regexp))))(defunoutline-end-of-heading()(if(re-search-forwardoutline-heading-end-regexpnil'move)(forward-char-1)))(defunoutline-next-visible-heading(arg)"Move to the next visible heading line.With argument, repeats or can move backward if negative.A heading line is one that starts with a `*' (or that`outline-regexp' matches)."(interactive"p")(if(<arg0)(beginning-of-line)(end-of-line))(or(re-search-forward(concat"^\\("outline-regexp"\\)")niltarg)(error""))(beginning-of-line))(defunoutline-previous-visible-heading(arg)"Move to the previous heading line.With argument, repeats or can move forward if negative.A heading line is one that starts with a `*' (or that`outline-regexp' matches)."(interactive"p")(outline-next-visible-heading(-arg)))(defunoutline-flag-region(fromtoflag)"Hides or shows lines from FROM to TO, according to FLAG.If FLAG is `\\n' (newline character) then text is shown,while if FLAG is `\\^M' (control-M) the text is hidden."(let(buffer-read-only)(subst-char-in-regionfromto(if(=flag?\n)?\^M?\n)flagt)))(defunhide-entry()"Hide the body directly following this heading."(interactive)(outline-back-to-heading)(outline-end-of-heading)(save-excursion(outline-flag-region(point)(progn(outline-next-preface)(point))?\^M)))(defunshow-entry()"Show the body directly following this heading."(interactive)(save-excursion(outline-flag-region(point)(progn(outline-next-preface)(point))?\n)))(defunhide-body()"Hide all of buffer except headings."(interactive)(hide-region-body(point-min)(point-max)))(defunhide-region-body(startend)"Hide all body lines in the region, but not headings."(save-excursion(save-restriction(narrow-to-regionstartend)(goto-char(point-min))(if(outline-on-heading-p)(outline-end-of-heading))(while(not(eobp))(outline-flag-region(point)(progn(outline-next-preface)(point))?\^M)(if(not(eobp))(progn(forward-char(if(looking-at"[\n\^M][\n\^M]")21))(outline-end-of-heading)))))))(defunshow-all()"Show all of the text in the buffer."(interactive)(outline-flag-region(point-min)(point-max)?\n))(defunhide-subtree()"Hide everything after this heading at deeper levels."(interactive)(outline-flag-subtree?\^M))(defunhide-leaves()"Hide all body after this heading at deeper levels."(interactive)(outline-back-to-heading)(outline-end-of-heading)(hide-region-body(point)(progn(outline-end-of-subtree)(point))))(defunshow-subtree()"Show everything after this heading at deeper levels."(interactive)(outline-flag-subtree?\n))(defunhide-sublevels(levels)"Hide everything but the top LEVELS levels of headers, in whole buffer."(interactive"p")(if(<levels1)(error"Must keep at least one level of headers"))(setqlevels(1-levels))(save-excursion(goto-char(point-min));; Keep advancing to the next top-level heading.(while(or(and(bobp)(outline-on-heading-p))(outline-next-heading))(let((end(save-excursion(outline-end-of-subtree)(point))));; Hide everything under that.(outline-flag-region(point)end?\^M);; Show the first LEVELS levels under that.(if(>levels0)(show-childrenlevels));; Move to the next, since we already found it.(goto-charend)))))(defunhide-other()"Hide everything except for the current body and the parent headings."(interactive)(hide-sublevels1)(let((last(point))(pos(point)))(while(save-excursion(and(re-search-backward"[\n\r]"nilt)(eq(following-char)?\r)))(save-excursion(beginning-of-line)(if(eqlast(point))(progn(outline-next-heading)(outline-flag-regionlast(point)?\n))(show-children)(setqlast(point)))))))(defunoutline-flag-subtree(flag)(save-excursion(outline-back-to-heading)(outline-end-of-heading)(outline-flag-region(point)(progn(outline-end-of-subtree)(point))flag)))(defunoutline-end-of-subtree()(outline-back-to-heading)(let((opoint(point))(firstt)(level(funcalloutline-level)))(while(and(not(eobp))(orfirst(>(funcalloutline-level)level)))(setqfirstnil)(outline-next-heading))(if(memq(preceding-char)'(?\n?\^M))(progn;; Go to end of line before heading(forward-char-1)(if(memq(preceding-char)'(?\n?\^M));; leave blank line before heading(forward-char-1))))))(defunshow-branches()"Show all subheadings of this heading, but not their bodies."(interactive)(show-children1000))(defunshow-children(&optionallevel)"Show all direct subheadings of this heading.Prefix arg LEVEL is how many levels below the current level should be shown.Default is enough to cause the following heading to appear."(interactive"P")(setqlevel(iflevel(prefix-numeric-valuelevel)(save-excursion(outline-back-to-heading)(let((start-level(funcalloutline-level)))(outline-next-heading)(if(eobp)1(max1(-(funcalloutline-level)start-level)))))))(save-excursion(save-restriction(outline-back-to-heading)(setqlevel(+level(funcalloutline-level)))(narrow-to-region(point)(progn(outline-end-of-subtree)(if(eobp)(point-max)(1+(point)))))(goto-char(point-min))(while(and(not(eobp))(progn(outline-next-heading)(not(eobp))))(if(<=(funcalloutline-level)level)(save-excursion(outline-flag-region(save-excursion(forward-char-1)(if(memq(preceding-char)'(?\n?\^M))(forward-char-1))(point))(progn(outline-end-of-heading)(point))?\n)))))))(defunoutline-up-heading(arg)"Move to the heading line of which the present line is a subheading.With argument, move up ARG levels."(interactive"p")(outline-back-to-heading)(if(eq(funcalloutline-level)1)(error""))(while(and(>(funcalloutline-level)1)(>arg0)(not(bobp)))(let((present-level(funcalloutline-level)))(while(not(<(funcalloutline-level)present-level))(outline-previous-visible-heading1))(setqarg(-arg1)))))(defunoutline-forward-same-level(arg)"Move forward to the ARG'th subheading at same level as this one.Stop at the first and last subheadings of a superior heading."(interactive"p")(outline-back-to-heading)(while(>arg0)(let((point-to-move-to(save-excursion(outline-get-next-sibling))))(ifpoint-to-move-to(progn(goto-charpoint-to-move-to)(setqarg(1-arg)))(progn(setqarg0)(error""))))))(defunoutline-get-next-sibling()"Move to next heading of the same level, and return point or nil if none."(let((level(funcalloutline-level)))(outline-next-visible-heading1)(while(and(>(funcalloutline-level)level)(not(eobp)))(outline-next-visible-heading1))(if(<(funcalloutline-level)level)nil(point))))(defunoutline-backward-same-level(arg)"Move backward to the ARG'th subheading at same level as this one.Stop at the first and last subheadings of a superior heading."(interactive"p")(outline-back-to-heading)(while(>arg0)(let((point-to-move-to(save-excursion(outline-get-last-sibling))))(ifpoint-to-move-to(progn(goto-charpoint-to-move-to)(setqarg(1-arg)))(progn(setqarg0)(error""))))))(defunoutline-get-last-sibling()"Move to next heading of the same level, and return point or nil if none."(let((level(funcalloutline-level)))(outline-previous-visible-heading1)(while(and(>(funcalloutline-level)level)(not(bobp)))(outline-previous-visible-heading1))(if(<(funcalloutline-level)level)nil(point))))(provide'outline);;; outline.el ends here