2001-07-15 16:15:35 +00:00
|
|
|
|
;;; ooutline.el --- outline mode commands for Emacs
|
1996-01-14 07:34:30 +00:00
|
|
|
|
|
2006-12-09 04:06:06 +00:00
|
|
|
|
;; Copyright (C) 1986, 1993, 1994, 1997, 2001, 2002, 2003, 2004,
|
2008-01-07 02:00:47 +00:00
|
|
|
|
;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
1992-07-22 04:22:30 +00:00
|
|
|
|
;; Maintainer: FSF
|
1995-04-14 23:24:11 +00:00
|
|
|
|
;; Keywords: outlines
|
1992-07-22 04:22:30 +00:00
|
|
|
|
|
1991-04-10 16:07:18 +00:00
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
2008-05-06 04:29:13 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1991-04-10 16:07:18 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 04:29:13 +00:00
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
|
|
|
|
;; 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
|
2008-05-06 04:29:13 +00:00
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
1993-03-22 05:42:35 +00:00
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2008-04-11 07:44:49 +00:00
|
|
|
|
;; This file has been obsolete since Emacs 21.1.
|
|
|
|
|
|
1993-03-22 05:42:35 +00:00
|
|
|
|
;; 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.
|
|
|
|
|
|
1992-07-16 21:47:34 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
1991-04-10 16:07:18 +00:00
|
|
|
|
;; Jan '86, Some new features added by Peter Desnoyers and rewritten by RMS.
|
1997-04-12 03:18:33 +00:00
|
|
|
|
|
|
|
|
|
(defgroup outlines nil
|
2005-07-04 02:56:16 +00:00
|
|
|
|
"Support for hierarchical outlining."
|
1997-04-12 03:18:33 +00:00
|
|
|
|
:prefix "outline-"
|
|
|
|
|
:group 'editing)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defcustom outline-regexp nil
|
1991-04-10 16:07:18 +00:00
|
|
|
|
"*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: list
|
1997-04-12 03:18:33 +00:00
|
|
|
|
in the file it applies to. See also outline-heading-end-regexp."
|
|
|
|
|
:type '(choice regexp (const nil))
|
|
|
|
|
:group 'outlines)
|
1994-03-09 06:52:12 +00:00
|
|
|
|
|
|
|
|
|
;; 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-default outline-regexp "[*\^L]+"))
|
2003-02-04 13:24:35 +00:00
|
|
|
|
|
1997-04-12 03:18:33 +00:00
|
|
|
|
(defcustom outline-heading-end-regexp "[\n\^M]"
|
1991-04-10 16:07:18 +00:00
|
|
|
|
"*Regular expression to match the end of a heading line.
|
|
|
|
|
You can assume that point is at the beginning of a heading when this
|
|
|
|
|
regexp is searched for. The heading ends at the end of the match.
|
|
|
|
|
The recommended way to set this is with a \"Local Variables:\" list
|
1997-04-12 03:18:33 +00:00
|
|
|
|
in the file it applies to."
|
|
|
|
|
:type 'regexp
|
|
|
|
|
:group 'outlines)
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(defvar outline-mode-prefix-map nil)
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(if outline-mode-prefix-map
|
1991-04-10 16:07:18 +00:00
|
|
|
|
nil
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(setq outline-mode-prefix-map (make-sparse-keymap))
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-n" 'outline-next-visible-heading)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-p" 'outline-previous-visible-heading)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-i" 'show-children)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-s" 'show-subtree)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-d" 'hide-subtree)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-u" 'outline-up-heading)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-f" 'outline-forward-same-level)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-b" 'outline-backward-same-level)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-t" 'hide-body)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-a" 'show-all)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-c" 'hide-entry)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-e" 'show-entry)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-l" 'hide-leaves)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-k" 'show-branches)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-q" 'hide-sublevels)
|
|
|
|
|
(define-key outline-mode-prefix-map "\C-o" 'hide-other))
|
|
|
|
|
|
|
|
|
|
(defvar outline-mode-menu-bar-map nil)
|
|
|
|
|
(if outline-mode-menu-bar-map
|
|
|
|
|
nil
|
|
|
|
|
(setq outline-mode-menu-bar-map (make-sparse-keymap))
|
|
|
|
|
|
|
|
|
|
(define-key outline-mode-menu-bar-map [hide]
|
1993-07-04 21:44:25 +00:00
|
|
|
|
(cons "Hide" (make-sparse-keymap "Hide")))
|
|
|
|
|
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [hide hide-other]
|
1994-03-13 00:38:48 +00:00
|
|
|
|
'("Hide Other" . hide-other))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [hide hide-sublevels]
|
1994-03-13 00:38:48 +00:00
|
|
|
|
'("Hide Sublevels" . hide-sublevels))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [hide hide-subtree]
|
1993-07-20 17:57:35 +00:00
|
|
|
|
'("Hide Subtree" . hide-subtree))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [hide hide-entry]
|
1993-07-20 17:57:35 +00:00
|
|
|
|
'("Hide Entry" . hide-entry))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [hide hide-body]
|
1993-07-20 17:57:35 +00:00
|
|
|
|
'("Hide Body" . hide-body))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [hide hide-leaves]
|
1993-07-20 17:57:35 +00:00
|
|
|
|
'("Hide Leaves" . hide-leaves))
|
1993-07-04 21:44:25 +00:00
|
|
|
|
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [show]
|
1993-07-04 21:44:25 +00:00
|
|
|
|
(cons "Show" (make-sparse-keymap "Show")))
|
|
|
|
|
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [show show-subtree]
|
1993-07-20 17:57:35 +00:00
|
|
|
|
'("Show Subtree" . show-subtree))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [show show-children]
|
1993-07-20 17:57:35 +00:00
|
|
|
|
'("Show Children" . show-children))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [show show-branches]
|
1993-07-20 17:57:35 +00:00
|
|
|
|
'("Show Branches" . show-branches))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [show show-entry]
|
1993-07-20 17:57:35 +00:00
|
|
|
|
'("Show Entry" . show-entry))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [show show-all]
|
1993-07-20 17:57:35 +00:00
|
|
|
|
'("Show All" . show-all))
|
1993-07-04 21:44:25 +00:00
|
|
|
|
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [headings]
|
1993-07-04 21:44:25 +00:00
|
|
|
|
(cons "Headings" (make-sparse-keymap "Headings")))
|
|
|
|
|
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [headings outline-backward-same-level]
|
1993-07-04 21:44:25 +00:00
|
|
|
|
'("Previous Same Level" . outline-backward-same-level))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [headings outline-forward-same-level]
|
1993-07-04 21:44:25 +00:00
|
|
|
|
'("Next Same Level" . outline-forward-same-level))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [headings outline-previous-visible-heading]
|
1993-07-04 21:44:25 +00:00
|
|
|
|
'("Previous" . outline-previous-visible-heading))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [headings outline-next-visible-heading]
|
1993-07-04 21:44:25 +00:00
|
|
|
|
'("Next" . outline-next-visible-heading))
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(define-key outline-mode-menu-bar-map [headings outline-up-heading]
|
1993-07-04 21:44:25 +00:00
|
|
|
|
'("Up" . outline-up-heading)))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
1994-08-27 21:02:12 +00:00
|
|
|
|
(defvar outline-mode-map nil "")
|
|
|
|
|
|
|
|
|
|
(if outline-mode-map
|
|
|
|
|
nil
|
|
|
|
|
(setq outline-mode-map (nconc (make-sparse-keymap) text-mode-map))
|
|
|
|
|
(define-key outline-mode-map "\C-c" outline-mode-prefix-map)
|
|
|
|
|
(define-key outline-mode-map [menu-bar] outline-mode-menu-bar-map))
|
|
|
|
|
|
1997-04-12 03:18:33 +00:00
|
|
|
|
(defcustom outline-minor-mode nil
|
|
|
|
|
"Non-nil if using Outline mode as a minor mode of some other mode."
|
|
|
|
|
:type 'boolean
|
|
|
|
|
:group 'outlines)
|
1993-05-21 17:25:50 +00:00
|
|
|
|
(make-variable-buffer-local 'outline-minor-mode)
|
|
|
|
|
(put 'outline-minor-mode 'permanent-local t)
|
1994-01-29 23:58:07 +00:00
|
|
|
|
(or (assq 'outline-minor-mode minor-mode-alist)
|
|
|
|
|
(setq minor-mode-alist (append minor-mode-alist
|
|
|
|
|
(list '(outline-minor-mode " Outl")))))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
1994-10-07 09:54:58 +00:00
|
|
|
|
(defvar outline-font-lock-keywords
|
|
|
|
|
'(;; Highlight headings according to the level.
|
1996-09-10 03:18:36 +00:00
|
|
|
|
("^\\([*]+\\)[ \t]*\\([^\n\r]+\\)?[ \t]*[\n\r]"
|
1994-10-07 09:54:58 +00:00
|
|
|
|
(1 font-lock-string-face)
|
|
|
|
|
(2 (let ((len (- (match-end 1) (match-beginning 1))))
|
|
|
|
|
(or (cdr (assq len '((1 . font-lock-function-name-face)
|
|
|
|
|
(2 . font-lock-keyword-face)
|
|
|
|
|
(3 . font-lock-comment-face))))
|
|
|
|
|
font-lock-variable-name-face))
|
|
|
|
|
nil t))
|
1996-01-05 22:21:28 +00:00
|
|
|
|
;; Highlight citations of the form [1] and [Mar94].
|
2000-03-31 11:07:14 +00:00
|
|
|
|
("\\[\\([[:upper:]][[:alpha:]]+\\)*[0-9]+\\]" . font-lock-type-face))
|
1994-10-07 09:54:58 +00:00
|
|
|
|
"Additional expressions to highlight in Outline mode.")
|
|
|
|
|
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(defun outline-mode ()
|
|
|
|
|
"Set major mode for editing outlines with selective display.
|
|
|
|
|
Headings are lines which start with asterisks: one for major headings,
|
2003-02-04 13:24:35 +00:00
|
|
|
|
two for subheadings, etc. Lines not starting with asterisks are body lines.
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
|
|
|
|
Body text or subheadings under a heading can be made temporarily
|
2003-02-04 13:24:35 +00:00
|
|
|
|
invisible, or visible again. Invisible lines are attached to the end
|
1991-04-10 16:07:18 +00:00
|
|
|
|
of the heading, so they move with it, if the line is killed and yanked
|
|
|
|
|
back. 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
|
|
|
|
|
|
1994-03-10 23:49:00 +00:00
|
|
|
|
\\[hide-body] make all text invisible (not headings).
|
|
|
|
|
\\[show-all] make everything in buffer visible.
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
|
|
|
|
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.
|
1994-03-10 23:49:00 +00:00
|
|
|
|
\\[hide-entry] make immediately following body invisible.
|
|
|
|
|
\\[show-entry] make it visible.
|
|
|
|
|
\\[hide-leaves] make body under heading and under its subheadings invisible.
|
1991-04-10 16:07:18 +00:00
|
|
|
|
The subheadings remain visible.
|
1994-03-10 23:49:00 +00:00
|
|
|
|
\\[show-branches] make all subheadings at all levels visible.
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
|
|
|
|
The variable `outline-regexp' can be changed to control what is a heading.
|
|
|
|
|
A line is a heading if `outline-regexp' matches something at the
|
|
|
|
|
beginning 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)
|
|
|
|
|
(setq selective-display t)
|
|
|
|
|
(use-local-map outline-mode-map)
|
|
|
|
|
(setq mode-name "Outline")
|
|
|
|
|
(setq major-mode 'outline-mode)
|
|
|
|
|
(define-abbrev-table 'text-mode-abbrev-table ())
|
|
|
|
|
(setq local-abbrev-table text-mode-abbrev-table)
|
|
|
|
|
(set-syntax-table text-mode-syntax-table)
|
|
|
|
|
(make-local-variable 'paragraph-start)
|
1995-03-02 15:36:11 +00:00
|
|
|
|
(setq paragraph-start (concat paragraph-start "\\|\\("
|
1991-04-10 16:07:18 +00:00
|
|
|
|
outline-regexp "\\)"))
|
|
|
|
|
;; Inhibit auto-filling of header lines.
|
|
|
|
|
(make-local-variable 'auto-fill-inhibit-regexp)
|
|
|
|
|
(setq auto-fill-inhibit-regexp outline-regexp)
|
|
|
|
|
(make-local-variable 'paragraph-separate)
|
1995-03-02 15:36:11 +00:00
|
|
|
|
(setq paragraph-separate (concat paragraph-separate "\\|\\("
|
1991-04-10 16:07:18 +00:00
|
|
|
|
outline-regexp "\\)"))
|
1994-10-12 09:00:56 +00:00
|
|
|
|
(make-local-variable 'font-lock-defaults)
|
|
|
|
|
(setq font-lock-defaults '(outline-font-lock-keywords t))
|
1994-06-15 23:03:28 +00:00
|
|
|
|
(make-local-variable 'change-major-mode-hook)
|
1994-02-10 00:48:59 +00:00
|
|
|
|
(add-hook 'change-major-mode-hook 'show-all)
|
2005-05-26 15:24:51 +00:00
|
|
|
|
(run-mode-hooks 'text-mode-hook 'outline-mode-hook))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
1997-04-12 03:18:33 +00:00
|
|
|
|
(defcustom outline-minor-mode-prefix "\C-c@"
|
1994-09-03 00:07:49 +00:00
|
|
|
|
"*Prefix key to use for Outline commands in Outline minor mode.
|
|
|
|
|
The value of this variable is checked as part of loading Outline mode.
|
1997-04-12 03:18:33 +00:00
|
|
|
|
After that, changing the prefix key requires manipulating keymaps."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'outlines)
|
1993-08-14 09:08:50 +00:00
|
|
|
|
|
1993-05-19 16:19:00 +00:00
|
|
|
|
(defvar outline-minor-mode-map nil)
|
|
|
|
|
(if outline-minor-mode-map
|
|
|
|
|
nil
|
|
|
|
|
(setq outline-minor-mode-map (make-sparse-keymap))
|
1993-07-04 21:44:25 +00:00
|
|
|
|
(define-key outline-minor-mode-map [menu-bar]
|
1994-08-27 21:02:12 +00:00
|
|
|
|
outline-mode-menu-bar-map)
|
1993-08-14 09:08:50 +00:00
|
|
|
|
(define-key outline-minor-mode-map outline-minor-mode-prefix
|
1994-08-27 21:02:12 +00:00
|
|
|
|
outline-mode-prefix-map))
|
1993-05-19 16:19:00 +00:00
|
|
|
|
|
|
|
|
|
(or (assq 'outline-minor-mode minor-mode-map-alist)
|
|
|
|
|
(setq minor-mode-map-alist
|
|
|
|
|
(cons (cons 'outline-minor-mode outline-minor-mode-map)
|
|
|
|
|
minor-mode-map-alist)))
|
|
|
|
|
|
|
|
|
|
(defun outline-minor-mode (&optional arg)
|
1993-05-21 17:25:50 +00:00
|
|
|
|
"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."
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(interactive "P")
|
|
|
|
|
(setq outline-minor-mode
|
|
|
|
|
(if (null arg) (not outline-minor-mode)
|
|
|
|
|
(> (prefix-numeric-value arg) 0)))
|
|
|
|
|
(if outline-minor-mode
|
|
|
|
|
(progn
|
|
|
|
|
(setq selective-display t)
|
|
|
|
|
(run-hooks 'outline-minor-mode-hook))
|
1993-09-21 07:32:51 +00:00
|
|
|
|
(setq selective-display nil))
|
1993-12-23 04:47:13 +00:00
|
|
|
|
;; When turning off outline mode, get rid of any ^M's.
|
|
|
|
|
(or outline-minor-mode
|
|
|
|
|
(outline-flag-region (point-min) (point-max) ?\n))
|
1995-04-25 22:27:27 +00:00
|
|
|
|
(force-mode-line-update))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
1993-08-14 09:13:23 +00:00
|
|
|
|
(defvar outline-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.")
|
|
|
|
|
|
1994-03-10 23:57:21 +00:00
|
|
|
|
;; 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.
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(defun outline-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 actually
|
1994-03-10 23:49:00 +00:00
|
|
|
|
the number of characters that `outline-regexp' matches."
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(looking-at outline-regexp)
|
1994-03-10 23:49:00 +00:00
|
|
|
|
(- (match-end 0) (match-beginning 0))))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
|
|
|
|
(defun outline-next-preface ()
|
1994-07-06 20:12:42 +00:00
|
|
|
|
"Skip forward to just before the next heading line.
|
|
|
|
|
If there's no following heading line, stop before the newline
|
|
|
|
|
at the end of the buffer."
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(if (re-search-forward (concat "[\n\^M]\\(" outline-regexp "\\)")
|
|
|
|
|
nil 'move)
|
1994-07-06 20:12:42 +00:00
|
|
|
|
(goto-char (match-beginning 0)))
|
|
|
|
|
(if (memq (preceding-char) '(?\n ?\^M))
|
|
|
|
|
(forward-char -1)))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
|
|
|
|
(defun outline-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-beginning 0)))))
|
|
|
|
|
|
|
|
|
|
(defun outline-back-to-heading ()
|
1994-03-03 19:17:47 +00:00
|
|
|
|
"Move to previous heading line, or beg of this line if it's a heading.
|
|
|
|
|
Only visible heading lines are considered."
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(or (outline-on-heading-p)
|
1994-03-10 23:49:00 +00:00
|
|
|
|
(re-search-backward (concat "^\\(" outline-regexp "\\)") nil t)
|
|
|
|
|
(error "before first heading")))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
|
|
|
|
(defun outline-on-heading-p ()
|
1994-05-02 07:45:48 +00:00
|
|
|
|
"Return t if point is on a (visible) heading line."
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
1994-03-10 23:49:00 +00:00
|
|
|
|
(and (bolp)
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(looking-at outline-regexp))))
|
|
|
|
|
|
|
|
|
|
(defun outline-end-of-heading ()
|
|
|
|
|
(if (re-search-forward outline-heading-end-regexp nil 'move)
|
|
|
|
|
(forward-char -1)))
|
|
|
|
|
|
|
|
|
|
(defun outline-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 (< arg 0)
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(end-of-line))
|
1994-03-10 23:49:00 +00:00
|
|
|
|
(or (re-search-forward (concat "^\\(" outline-regexp "\\)") nil t arg)
|
|
|
|
|
(error ""))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(beginning-of-line))
|
|
|
|
|
|
|
|
|
|
(defun outline-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)))
|
|
|
|
|
|
|
|
|
|
(defun outline-flag-region (from to flag)
|
|
|
|
|
"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."
|
1993-06-01 03:24:24 +00:00
|
|
|
|
(let (buffer-read-only)
|
|
|
|
|
(subst-char-in-region from to
|
|
|
|
|
(if (= flag ?\n) ?\^M ?\n)
|
|
|
|
|
flag t)))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
|
|
|
|
(defun hide-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)))
|
|
|
|
|
|
|
|
|
|
(defun show-entry ()
|
|
|
|
|
"Show the body directly following this heading."
|
|
|
|
|
(interactive)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(outline-flag-region (point) (progn (outline-next-preface) (point)) ?\n)))
|
|
|
|
|
|
|
|
|
|
(defun hide-body ()
|
|
|
|
|
"Hide all of buffer except headings."
|
|
|
|
|
(interactive)
|
|
|
|
|
(hide-region-body (point-min) (point-max)))
|
|
|
|
|
|
|
|
|
|
(defun hide-region-body (start end)
|
|
|
|
|
"Hide all body lines in the region, but not headings."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(narrow-to-region start end)
|
|
|
|
|
(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]")
|
|
|
|
|
2 1))
|
|
|
|
|
(outline-end-of-heading)))))))
|
|
|
|
|
|
|
|
|
|
(defun show-all ()
|
|
|
|
|
"Show all of the text in the buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(outline-flag-region (point-min) (point-max) ?\n))
|
|
|
|
|
|
|
|
|
|
(defun hide-subtree ()
|
|
|
|
|
"Hide everything after this heading at deeper levels."
|
|
|
|
|
(interactive)
|
|
|
|
|
(outline-flag-subtree ?\^M))
|
|
|
|
|
|
|
|
|
|
(defun hide-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))))
|
|
|
|
|
|
|
|
|
|
(defun show-subtree ()
|
|
|
|
|
"Show everything after this heading at deeper levels."
|
|
|
|
|
(interactive)
|
|
|
|
|
(outline-flag-subtree ?\n))
|
|
|
|
|
|
1994-03-13 00:38:48 +00:00
|
|
|
|
(defun hide-sublevels (levels)
|
1994-05-02 07:45:48 +00:00
|
|
|
|
"Hide everything but the top LEVELS levels of headers, in whole buffer."
|
1994-02-24 22:37:49 +00:00
|
|
|
|
(interactive "p")
|
1994-02-24 23:43:30 +00:00
|
|
|
|
(if (< levels 1)
|
1994-02-24 22:37:49 +00:00
|
|
|
|
(error "Must keep at least one level of headers"))
|
1994-02-24 23:43:30 +00:00
|
|
|
|
(setq levels (1- levels))
|
1994-02-24 22:37:49 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
1994-05-04 05:48:53 +00:00
|
|
|
|
;; 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.
|
1994-05-04 19:55:33 +00:00
|
|
|
|
(if (> levels 0)
|
1994-05-04 05:48:53 +00:00
|
|
|
|
(show-children levels))
|
|
|
|
|
;; Move to the next, since we already found it.
|
|
|
|
|
(goto-char end)))))
|
1994-02-24 22:37:49 +00:00
|
|
|
|
|
1994-03-13 00:38:48 +00:00
|
|
|
|
(defun hide-other ()
|
1994-02-24 22:37:49 +00:00
|
|
|
|
"Hide everything except for the current body and the parent headings."
|
|
|
|
|
(interactive)
|
1994-03-13 00:38:48 +00:00
|
|
|
|
(hide-sublevels 1)
|
1994-02-24 22:37:49 +00:00
|
|
|
|
(let ((last (point))
|
|
|
|
|
(pos (point)))
|
|
|
|
|
(while (save-excursion
|
|
|
|
|
(and (re-search-backward "[\n\r]" nil t)
|
|
|
|
|
(eq (following-char) ?\r)))
|
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(if (eq last (point))
|
|
|
|
|
(progn
|
|
|
|
|
(outline-next-heading)
|
|
|
|
|
(outline-flag-region last (point) ?\n))
|
|
|
|
|
(show-children)
|
|
|
|
|
(setq last (point)))))))
|
|
|
|
|
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(defun outline-flag-subtree (flag)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(outline-back-to-heading)
|
|
|
|
|
(outline-end-of-heading)
|
|
|
|
|
(outline-flag-region (point)
|
|
|
|
|
(progn (outline-end-of-subtree) (point))
|
|
|
|
|
flag)))
|
|
|
|
|
|
|
|
|
|
(defun outline-end-of-subtree ()
|
|
|
|
|
(outline-back-to-heading)
|
|
|
|
|
(let ((opoint (point))
|
|
|
|
|
(first t)
|
1993-08-14 09:13:23 +00:00
|
|
|
|
(level (funcall outline-level)))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(while (and (not (eobp))
|
1993-08-14 09:13:23 +00:00
|
|
|
|
(or first (> (funcall outline-level) level)))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(setq first nil)
|
|
|
|
|
(outline-next-heading))
|
1994-04-18 23:53:51 +00:00
|
|
|
|
(if (memq (preceding-char) '(?\n ?\^M))
|
|
|
|
|
(progn
|
1994-04-19 07:44:27 +00:00
|
|
|
|
;; Go to end of line before heading
|
1994-04-18 23:53:51 +00:00
|
|
|
|
(forward-char -1)
|
|
|
|
|
(if (memq (preceding-char) '(?\n ?\^M))
|
|
|
|
|
;; leave blank line before heading
|
|
|
|
|
(forward-char -1))))))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
|
|
|
|
(defun show-branches ()
|
|
|
|
|
"Show all subheadings of this heading, but not their bodies."
|
|
|
|
|
(interactive)
|
|
|
|
|
(show-children 1000))
|
|
|
|
|
|
|
|
|
|
(defun show-children (&optional level)
|
|
|
|
|
"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")
|
|
|
|
|
(setq level
|
|
|
|
|
(if level (prefix-numeric-value level)
|
|
|
|
|
(save-excursion
|
1994-03-03 19:17:47 +00:00
|
|
|
|
(outline-back-to-heading)
|
1993-08-14 09:13:23 +00:00
|
|
|
|
(let ((start-level (funcall outline-level)))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(outline-next-heading)
|
1994-01-31 16:41:12 +00:00
|
|
|
|
(if (eobp)
|
|
|
|
|
1
|
|
|
|
|
(max 1 (- (funcall outline-level) start-level)))))))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(save-excursion
|
1994-03-03 19:17:47 +00:00
|
|
|
|
(save-restriction
|
|
|
|
|
(outline-back-to-heading)
|
|
|
|
|
(setq level (+ level (funcall outline-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 (<= (funcall outline-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)))))))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
|
|
|
|
(defun outline-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)
|
1993-08-14 09:13:23 +00:00
|
|
|
|
(if (eq (funcall outline-level) 1)
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(error ""))
|
1994-03-10 23:49:00 +00:00
|
|
|
|
(while (and (> (funcall outline-level) 1)
|
|
|
|
|
(> arg 0)
|
|
|
|
|
(not (bobp)))
|
|
|
|
|
(let ((present-level (funcall outline-level)))
|
|
|
|
|
(while (not (< (funcall outline-level) present-level))
|
|
|
|
|
(outline-previous-visible-heading 1))
|
|
|
|
|
(setq arg (- arg 1)))))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
|
|
|
|
|
(defun outline-forward-same-level (arg)
|
1994-05-02 07:45:48 +00:00
|
|
|
|
"Move forward to the ARG'th subheading at same level as this one.
|
|
|
|
|
Stop at the first and last subheadings of a superior heading."
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(interactive "p")
|
|
|
|
|
(outline-back-to-heading)
|
|
|
|
|
(while (> arg 0)
|
|
|
|
|
(let ((point-to-move-to (save-excursion
|
2003-02-04 13:24:35 +00:00
|
|
|
|
(outline-get-next-sibling))))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(if point-to-move-to
|
|
|
|
|
(progn
|
|
|
|
|
(goto-char point-to-move-to)
|
|
|
|
|
(setq arg (1- arg)))
|
|
|
|
|
(progn
|
|
|
|
|
(setq arg 0)
|
|
|
|
|
(error ""))))))
|
|
|
|
|
|
|
|
|
|
(defun outline-get-next-sibling ()
|
1994-05-02 07:45:48 +00:00
|
|
|
|
"Move to next heading of the same level, and return point or nil if none."
|
1993-08-14 09:13:23 +00:00
|
|
|
|
(let ((level (funcall outline-level)))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(outline-next-visible-heading 1)
|
1993-08-14 09:13:23 +00:00
|
|
|
|
(while (and (> (funcall outline-level) level)
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(not (eobp)))
|
|
|
|
|
(outline-next-visible-heading 1))
|
1993-08-14 09:13:23 +00:00
|
|
|
|
(if (< (funcall outline-level) level)
|
1991-04-10 16:07:18 +00:00
|
|
|
|
nil
|
|
|
|
|
(point))))
|
2003-02-04 13:24:35 +00:00
|
|
|
|
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(defun outline-backward-same-level (arg)
|
1994-05-02 07:45:48 +00:00
|
|
|
|
"Move backward to the ARG'th subheading at same level as this one.
|
|
|
|
|
Stop at the first and last subheadings of a superior heading."
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(interactive "p")
|
|
|
|
|
(outline-back-to-heading)
|
|
|
|
|
(while (> arg 0)
|
|
|
|
|
(let ((point-to-move-to (save-excursion
|
|
|
|
|
(outline-get-last-sibling))))
|
|
|
|
|
(if point-to-move-to
|
|
|
|
|
(progn
|
|
|
|
|
(goto-char point-to-move-to)
|
|
|
|
|
(setq arg (1- arg)))
|
|
|
|
|
(progn
|
|
|
|
|
(setq arg 0)
|
|
|
|
|
(error ""))))))
|
|
|
|
|
|
|
|
|
|
(defun outline-get-last-sibling ()
|
1994-05-02 07:45:48 +00:00
|
|
|
|
"Move to next heading of the same level, and return point or nil if none."
|
1993-08-14 09:13:23 +00:00
|
|
|
|
(let ((level (funcall outline-level)))
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(outline-previous-visible-heading 1)
|
1993-08-14 09:13:23 +00:00
|
|
|
|
(while (and (> (funcall outline-level) level)
|
1991-04-10 16:07:18 +00:00
|
|
|
|
(not (bobp)))
|
|
|
|
|
(outline-previous-visible-heading 1))
|
1993-08-14 09:13:23 +00:00
|
|
|
|
(if (< (funcall outline-level) level)
|
1991-04-10 16:07:18 +00:00
|
|
|
|
nil
|
|
|
|
|
(point))))
|
|
|
|
|
|
1993-05-19 16:19:00 +00:00
|
|
|
|
(provide 'outline)
|
|
|
|
|
|
2008-04-10 14:10:46 +00:00
|
|
|
|
;; arch-tag: 14ed00e1-bd40-4db8-86e5-3b82ce326e45
|
2001-07-15 16:15:35 +00:00
|
|
|
|
;;; ooutline.el ends here
|