]> code.delx.au - gnu-emacs/blobdiff - lisp/outline.el
(compilation-goto-locus): Use `next-error' face instead of `region'.
[gnu-emacs] / lisp / outline.el
index 48c0a2576fd5a112f08b7ca0008eda478b2945d7..0f7d3b627b05be5e4ec015e6f3f6d52222b93ee9 100644 (file)
@@ -1,6 +1,6 @@
 ;;; outline.el --- outline mode commands for Emacs
 
-;; Copyright (C) 1986, 93, 94, 95, 97, 2000, 2001
+;; Copyright (C) 1986, 93, 94, 95, 97, 2000, 01, 2004
 ;;   Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
@@ -152,7 +152,7 @@ in the file it applies to."
                                         (cons '(--- "---") (cdr x))))
                                   outline-mode-menu-bar-map))))))
     map))
-             
+
 
 (defvar outline-mode-map
   (let ((map (make-sparse-keymap)))
@@ -213,6 +213,12 @@ in the file it applies to."
 (defvar outline-view-change-hook nil
   "Normal hook to be run after outline visibility changes.")
 
+(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.
@@ -346,7 +352,7 @@ at the end of the buffer."
   (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 ()
@@ -407,7 +413,8 @@ If INVISIBLE-OK is non-nil, an invisible heading line is ok too."
                    (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)
@@ -440,10 +447,10 @@ in the region."
                          (save-match-data
                            (outline-up-heading 1 t)
                            (match-string 0))))))
-      
+
       (unless (rassoc level outline-heading-alist)
        (push (cons head level) outline-heading-alist))
-      
+
       (replace-match up-head nil t)))))
 
 (defun outline-demote (&optional children)
@@ -483,7 +490,8 @@ in the region."
                  ;; 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)
+                   (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.
@@ -554,8 +562,8 @@ the match data is set appropriately."
 (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 ((re (concat "^\\(?:" outline-regexp "\\)"))
+       (movfunc (if (> arg 0) 'outline-get-next-sibling
                   'outline-get-last-sibling))
        (ins-point (make-marker))
        (cnt (abs arg))
@@ -563,8 +571,8 @@ the match data is set appropriately."
     ;; Select the tree
     (outline-back-to-heading)
     (setq beg (point))
-    (save-match-data 
-      (save-excursion (outline-end-of-heading) 
+    (save-match-data
+      (save-excursion (outline-end-of-heading)
                      (setq folded (outline-invisible-p)))
       (outline-end-of-subtree))
     (if (= (char-after) ?\n) (forward-char 1))
@@ -578,7 +586,7 @@ the match data is set appropriately."
       (setq cnt (1- cnt)))
     (if (> arg 0)
        ;; Moving forward - still need to move over subtree
-       (progn (outline-end-of-subtree) 
+       (progn (outline-end-of-subtree)
               (if (= (char-after) ?\n) (forward-char 1))))
     (move-marker ins-point (point))
     (insert (delete-and-extract-region beg end))
@@ -657,7 +665,7 @@ If FLAG is nil then text is shown, while if FLAG is t the text is hidden."
        ;; reveal do the rest, by simply doing:
        ;; (remove-overlays (overlay-start o) (overlay-end o)
        ;;                  'invisible 'outline)
-       ;; 
+       ;;
        ;; That works fine as long as everything is in sync, but if the
        ;; structure of the document is changed while revealing parts of it,
        ;; the resulting behavior can be ugly.  I.e. we need to make
@@ -701,8 +709,8 @@ If FLAG is nil then text is shown, while if FLAG is t the text is hidden."
   "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 ()
@@ -765,9 +773,10 @@ Show the heading too, if it is currently invisible."
 (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))
 
@@ -836,9 +845,9 @@ Show the heading too, if it is currently invisible."
        (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."
@@ -879,6 +888,8 @@ Default is enough to cause the following heading to appear."
 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)
@@ -984,4 +995,5 @@ convenient way to make a table of contents of the buffer."
 (provide 'outline)
 (provide 'noutline)
 
+;;; arch-tag: 1724410e-7d4d-4f46-b801-49e18171e874
 ;;; outline.el ends here