]> code.delx.au - gnu-emacs/blobdiff - lisp/outline.el
Update copyright year to 2015
[gnu-emacs] / lisp / outline.el
index da5519f95eb4debdc6a9e9294862d44282bf969f..11d71fb1226339bc21b25707b85d56dc5474022d 100644 (file)
@@ -1,9 +1,9 @@
 ;;; outline.el --- outline mode commands for Emacs
 
-;; Copyright (C) 1986, 1993-1995, 1997, 2000-2012
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1986, 1993-1995, 1997, 2000-2015 Free Software
+;; Foundation, Inc.
 
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
 ;; Keywords: outlines
 
 ;; This file is part of GNU Emacs.
   :prefix "outline-"
   :group 'wp)
 
-(defcustom outline-regexp "[*\^L]+"
+(defvar outline-regexp "[*\^L]+"
   "Regular expression to match the beginning of a heading.
 Any line whose beginning matches this regexp is considered to start a heading.
 Note that Outline mode only checks this regexp at the start of a line,
 so the regexp need not (and usually does not) start with `^'.
 The recommended way to set this is with a Local Variables: list
-in the file it applies to.  See also `outline-heading-end-regexp'."
-  :type 'regexp
-  :group 'outlines)
+in the file it applies to.  See also `outline-heading-end-regexp'.")
 ;;;###autoload(put 'outline-regexp 'safe-local-variable 'stringp)
 
-(defcustom outline-heading-end-regexp "\n"
+(defvar outline-heading-end-regexp "\n"
   "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
-in the file it applies to."
-  :type 'regexp
-  :group 'outlines)
+in the file it applies to.")
 ;;;###autoload(put 'outline-heading-end-regexp 'safe-local-variable 'stringp)
 
 (defvar outline-mode-prefix-map
@@ -284,10 +280,10 @@ in the file it applies to."
   "Normal hook to be run after outline visibility changes.")
 
 (defvar outline-mode-hook nil
-  "*This hook is run when outline mode starts.")
+  "This hook is run when outline mode starts.")
 
 (defvar outline-blank-line nil
-  "*Non-nil means to leave unhidden blank line before heading.")
+  "Non-nil means to leave unhidden blank line before heading.")
 
 ;;;###autoload
 (define-derived-mode outline-mode text-mode "Outline"
@@ -380,7 +376,7 @@ See the command `outline-mode' for more information on this mode."
     (show-all)))
 \f
 (defvar outline-level 'outline-level
-  "*Function of no args to compute a header's nesting level in an outline.
+  "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 and that the match
 data reflects the `outline-regexp'.")
 ;;;###autoload(put 'outline-level 'risky-local-variable t)
@@ -649,31 +645,35 @@ the match data is set appropriately."
 (defun outline-move-subtree-down (&optional arg)
   "Move the current subtree down past ARG headlines of the same level."
   (interactive "p")
-  (let ((movfunc (if (> arg 0) 'outline-get-next-sibling
-                  'outline-get-last-sibling))
-       (ins-point (make-marker))
-       (cnt (abs arg))
-       beg end folded)
-    ;; Select the tree
-    (outline-back-to-heading)
-    (setq beg (point))
-    (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))
-    (setq end (point))
-    ;; Find insertion point, with error handling
+  (outline-back-to-heading)
+  (let* ((movfunc (if (> arg 0) 'outline-get-next-sibling
+                   'outline-get-last-sibling))
+        ;; Find the end of the subtree to be moved as well as the point to
+        ;; move it to, adding a newline if necessary, to ensure these points
+        ;; are at bol on the line below the subtree.
+         (end-point-func (lambda ()
+                          (outline-end-of-subtree)
+                          (if (eq (char-after) ?\n) (forward-char 1)
+                               (if (and (eobp) (not (bolp))) (insert "\n")))
+                          (point)))
+         (beg (point))
+         (folded (save-match-data
+                  (outline-end-of-heading)
+                  (outline-invisible-p)))
+         (end (save-match-data
+               (funcall end-point-func)))
+         (ins-point (make-marker))
+         (cnt (abs arg)))
+    ;; Find insertion point, with error handling.
     (goto-char beg)
     (while (> cnt 0)
       (or (funcall movfunc)
          (progn (goto-char beg)
-                (error "Cannot move past superior level")))
+                (user-error "Cannot move past superior level")))
       (setq cnt (1- cnt)))
     (if (> arg 0)
-       ;; Moving forward - still need to move over subtree
-       (progn (outline-end-of-subtree)
-              (if (= (char-after) ?\n) (forward-char 1))))
+       ;; Moving forward - still need to move over subtree.
+       (funcall end-point-func))
     (move-marker ins-point (point))
     (insert (delete-and-extract-region beg end))
     (goto-char ins-point)