;;; outline.el --- outline mode commands for Emacs
-;; Copyright (C) 1986, 93, 94, 95, 97, 2000, 2001
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1986, 1993, 1994, 1995, 1997, 2000, 2001, 2002,
+;; 2003, 2004, 2005 Free Software Foundation, Inc.
;; Maintainer: FSF
;; Keywords: outlines
;; 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., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;; Code:
(defgroup outlines nil
- "Support for hierarchical outlining"
+ "Support for hierarchical outlining."
:prefix "outline-"
:group 'editing)
0 '(outline-font-lock-face) nil t)))
"Additional expressions to highlight in Outline mode.")
-(defface outline-1 '((t :inherit font-lock-function-name-face)) "Level 1.")
-(defface outline-2 '((t :inherit font-lock-variable-name-face)) "Level 2.")
-(defface outline-3 '((t :inherit font-lock-keyword-face)) "Level 3.")
-(defface outline-4 '((t :inherit font-lock-builtin-face)) "Level 4.")
-(defface outline-5 '((t :inherit font-lock-comment-face)) "Level 5.")
-(defface outline-6 '((t :inherit font-lock-constant-face)) "Level 6.")
-(defface outline-7 '((t :inherit font-lock-type-face)) "Level 7.")
-(defface outline-8 '((t :inherit font-lock-string-face)) "Level 8.")
+(defface outline-1
+ '((t :inherit font-lock-function-name-face))
+ "Level 1."
+ :group 'outlines)
+
+(defface outline-2
+ '((t :inherit font-lock-variable-name-face))
+ "Level 2."
+ :group 'outlines)
+
+(defface outline-3
+ '((t :inherit font-lock-keyword-face))
+ "Level 3."
+ :group 'outlines)
+
+(defface outline-4
+ '((t :inherit font-lock-builtin-face))
+ "Level 4."
+ :group 'outlines)
+
+(defface outline-5
+ '((t :inherit font-lock-comment-face))
+ "Level 5."
+ :group 'outlines)
+
+(defface outline-6
+ '((t :inherit font-lock-constant-face))
+ "Level 6."
+ :group 'outlines)
+
+(defface outline-7
+ '((t :inherit font-lock-type-face))
+ "Level 7."
+ :group 'outlines)
+
+(defface outline-8
+ '((t :inherit font-lock-string-face))
+ "Level 8."
+ :group 'outlines)
(defvar outline-font-lock-faces
[outline-1 outline-2 outline-3 outline-4
(defvar outline-mode-hook nil
"*This hook is run when outline mode starts.")
+(defvar outline-blank-line nil
+ "*Non-nil means to leave unhidden blank line before heading.")
+
;;;###autoload
(define-derived-mode outline-mode text-mode "Outline"
"Set major mode for editing outlines with selective display.
'(outline-font-lock-keywords t nil nil backward-paragraph))
(setq imenu-generic-expression
(list (list nil (concat "^\\(?:" outline-regexp "\\).*$") 0)))
- (add-hook 'change-major-mode-hook 'show-all nil t)
- (run-hooks 'outline-mode-hook))
+ (add-hook 'change-major-mode-hook 'show-all nil t))
(defcustom outline-minor-mode-prefix "\C-c@"
"*Prefix key to use for Outline commands in Outline minor mode.
(if (re-search-forward (concat "\n\\(?:" outline-regexp "\\)")
nil 'move)
(goto-char (match-beginning 0)))
- (if (and (bolp) (not (bobp)))
+ (if (and (bolp) (or outline-blank-line (eobp)) (not (bobp)))
(forward-char -1)))
(defun outline-next-heading ()
(or (caar outline-heading-alist) "")
(match-string 0)))))
(unless (or (string-match "[ \t]\\'" head)
- (not (string-match outline-regexp (concat head " "))))
+ (not (string-match (concat "\\`\\(?:" outline-regexp "\\)")
+ (concat head " "))))
(setq head (concat head " ")))
(unless (bolp) (end-of-line) (newline))
(insert head)
(save-excursion (newline-and-indent)))
(run-hooks 'outline-insert-heading-hook)))
+(defun outline-invent-heading (head up)
+ (save-match-data
+ ;; Let's try to invent one by repeating or deleting the last char.
+ (let ((new-head (if up (substring head 0 -1)
+ (concat head (substring head -1)))))
+ (if (string-match (concat "\\`\\(?:" outline-regexp "\\)")
+ new-head)
+ ;; Why bother checking that it is indeed higher/lower level ?
+ new-head
+ ;; Didn't work, so ask what to do.
+ (read-string (format "%s heading for `%s': "
+ (if up "Parent" "Demoted") head)
+ head nil nil t)))))
+
(defun outline-promote (&optional children)
"Promote headings higher up the tree.
If prefix argument CHILDREN is given, promote also all the children.
(save-excursion (outline-get-next-sibling) (point))))
(t
(outline-back-to-heading t)
- (let* ((head (match-string 0))
+ (let* ((head (match-string-no-properties 0))
(level (save-match-data (funcall outline-level)))
(up-head (or (outline-head-from-level (1- level) head)
+ ;; Use the parent heading, if it is really
+ ;; one level less.
(save-excursion
(save-match-data
(outline-up-heading 1 t)
- (match-string 0))))))
+ (and (= (1- level) (funcall outline-level))
+ (match-string-no-properties 0))))
+ ;; Bummer!! There is no lower level heading.
+ (outline-invent-heading head 'up))))
(unless (rassoc level outline-heading-alist)
(push (cons head level) outline-heading-alist))
(point)
(save-excursion (outline-get-next-sibling) (point))))
(t
- (let* ((head (match-string 0))
+ (let* ((head (match-string-no-properties 0))
(level (save-match-data (funcall outline-level)))
(down-head
(or (outline-head-from-level (1+ level) head)
(<= (funcall outline-level) level))))
(unless (eobp)
(looking-at outline-regexp)
- (match-string 0))))
- (save-match-data
- ;; Bummer!! There is no lower heading in the buffer.
- ;; Let's try to invent one by repeating the first char.
- (let ((new-head (concat (substring head 0 1) head)))
- (if (string-match (concat "\\`" outline-regexp) new-head)
- ;; Why bother checking that it is indeed lower level ?
- new-head
- ;; Didn't work: keep it as is so it's still a heading.
- head))))))
-
- (unless (rassoc level outline-heading-alist)
- (push (cons head level) outline-heading-alist))
- (replace-match down-head nil t)))))
+ (match-string-no-properties 0))))
+ ;; Bummer!! There is no higher-level heading in the buffer.
+ (outline-invent-heading head nil))))
+
+ (unless (rassoc level outline-heading-alist)
+ (push (cons head level) outline-heading-alist))
+ (replace-match down-head nil t)))))
(defun outline-head-from-level (level head &optional alist)
"Get new heading with level LEVEL from ALIST.
(defun outline-move-subtree-down (&optional arg)
"Move the currrent subtree down past ARG headlines of the same level."
(interactive "p")
- (let ((re (concat "^" outline-regexp))
- (movfunc (if (> arg 0) 'outline-get-next-sibling
+ (let ((movfunc (if (> arg 0) 'outline-get-next-sibling
'outline-get-last-sibling))
(ins-point (make-marker))
(cnt (abs arg))
- beg end txt folded)
+ beg end folded)
;; Select the tree
(outline-back-to-heading)
(setq beg (point))
"Hide the body directly following this heading."
(interactive)
(outline-back-to-heading)
- (outline-end-of-heading)
(save-excursion
+ (outline-end-of-heading)
(outline-flag-region (point) (progn (outline-next-preface) (point)) t)))
(defun show-entry ()
(progn (outline-next-preface) (point)) nil)))
(defun hide-body ()
- "Hide all of buffer except headings."
+ "Hide all body lines in buffer, leaving all headings visible."
(interactive)
(hide-region-body (point-min) (point-max)))
(narrow-to-region start end)
(goto-char (point-min))
(if (outline-on-heading-p)
- (outline-end-of-heading))
+ (outline-end-of-heading)
+ (outline-next-preface))
(while (not (eobp))
(outline-flag-region (point)
(progn (outline-next-preface) (point)) t)
(defun outline-show-heading ()
"Show the current heading and move to its end."
(outline-flag-region (- (point)
- (if (bobp) 0
- (if (eq (char-before (1- (point))) ?\n)
- 2 1)))
+ (if (bobp) 0
+ (if (and outline-blank-line
+ (eq (char-before (1- (point))) ?\n))
+ 2 1)))
(progn (outline-end-of-heading) (point))
nil))
(save-excursion
(outline-back-to-heading t)
(show-entry)
- (while (condition-case nil (progn (outline-up-heading 1) (not (bobp)))
+ (while (condition-case nil (progn (outline-up-heading 1 t) (not (bobp)))
(error nil))
(outline-flag-region (1- (point))
(save-excursion (forward-line 1) (point))
(defun outline-end-of-subtree ()
(outline-back-to-heading)
- (let ((opoint (point))
- (first t)
+ (let ((first t)
(level (funcall outline-level)))
(while (and (not (eobp))
(or first (> (funcall outline-level) level)))
(progn
;; Go to end of line before heading
(forward-char -1)
- (if (bolp)
- ;; leave blank line before heading
- (forward-char -1))))))
+ (if (and outline-blank-line (bolp))
+ ;; leave blank line before heading
+ (forward-char -1))))))
\f
(defun show-branches ()
"Show all subheadings of this heading, but not their bodies."
With argument, move up ARG levels.
If INVISIBLE-OK is non-nil, also consider invisible lines."
(interactive "p")
+ (and (eq this-command 'outline-up-heading)
+ (or (eq last-command 'outline-up-heading) (push-mark)))
(outline-back-to-heading invisible-ok)
(let ((start-level (funcall outline-level)))
(if (eq start-level 1)
(provide 'outline)
(provide 'noutline)
+;; arch-tag: 1724410e-7d4d-4f46-b801-49e18171e874
;;; outline.el ends here