]> code.delx.au - gnu-emacs/commitdiff
outline.el: Fix subtree movement.
authorStephen Berman <stephen.berman@gmx.net>
Thu, 27 Nov 2014 10:03:58 +0000 (11:03 +0100)
committerStephen Berman <stephen.berman@gmx.net>
Thu, 27 Nov 2014 10:03:58 +0000 (11:03 +0100)
Fixes: debbugs:19102
Co-authored-by: Stefan Monnier <monnier@iro.umontreal.ca>
* outline.el (outline-move-subtree-down): Make sure we can move
forward to find the end of the subtree and the insertion point.

lisp/ChangeLog
lisp/outline.el

index d88ecfeb8a8a8886f1f45c22b251464349637afc..8c480190c179463b7b2380697a811c84875afedf 100644 (file)
@@ -1,3 +1,10 @@
+2014-11-27  Stephen Berman  <stephen.berman@gmx.net>
+           Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * outline.el (outline-move-subtree-down): Make sure we can move
+       forward to find the end of the subtree and the insertion point
+       (bug#19102).
+
 2014-11-27  Leonard Randall  <leonard.a.randall@gmail.com>
 
        * textmodes/reftex-parse.el (reftex-using-biblatex-p): Make search
index c7cad31f572fb157acc519e8a353637a5d855bea..61ee7ff0f9f2300346b646040251ea6e506c41b3 100644 (file)
@@ -649,27 +649,32 @@ the match data is set appropriately."
                   'outline-get-last-sibling))
        (ins-point (make-marker))
        (cnt (abs arg))
+       ;; Make sure we can move forward to find the end of the
+       ;; subtree and the insertion point.
+       (maybe-forward-char (lambda ()
+                             (if (eq (char-after) ?\n) (forward-char 1)
+                               (if (and (eobp) (not (bolp))) (insert "\n")))))
        beg end folded)
-    ;; Select the tree
+    ;; 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))
+    (funcall maybe-forward-char)
     (setq end (point))
-    ;; Find insertion point, with error handling
+    ;; 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
+       ;; Moving forward - still need to move over subtree.
        (progn (outline-end-of-subtree)
-              (if (= (char-after) ?\n) (forward-char 1))))
+              (funcall maybe-forward-char)))
     (move-marker ins-point (point))
     (insert (delete-and-extract-region beg end))
     (goto-char ins-point)