GNU bug report logs - #19102
24.4; outline-move-subtree-up/down error at last and second-last subtree

Previous Next

Package: emacs;

Reported by: Paul Rankin <paul <at> tilk.co>

Date: Wed, 19 Nov 2014 08:34:01 UTC

Severity: normal

Found in version 24.4

Done: Stephen Berman <stephen.berman <at> gmx.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stephen Berman <stephen.berman <at> gmx.net>
To: Paul Rankin <paul <at> tilk.co>
Cc: 19102 <at> debbugs.gnu.org
Subject: bug#19102: 24.4; outline-move-subtree-up/down error at last and second-last subtree
Date: Wed, 19 Nov 2014 14:17:25 +0100
[Message part 1 (text/plain, inline)]
On Wed, 19 Nov 2014 18:29:01 +1000 Paul Rankin <paul <at> tilk.co> wrote:

> 1. emacs -Q
> 2. M-x switch-to-buffer RET test
> 3. M-x outline-mode
> 4. insert:
>    * one
>    * two
>    * three
> 5. position point at "* three"
> 6. M-x outline-move-subtree-up
>    => Wrong type argument: number-or-marker-p, nil
> 7. position point at "* two"
> 8. M-x outline-move-subtree-down
>    => Wrong type argument: number-or-marker-p, nil
>
> Expected behaviour:
>
> - at 6. subtree "* three" should move above "* two"
> - or at 8. subtree "* two" should move below "* three"

The following patch (against master) seems to fix this, though it could
probably be done more elegantly.

Steve Berman

[Message part 2 (text/x-patch, inline)]
diff --git a/lisp/outline.el b/lisp/outline.el
index c7cad31..bfed982 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -649,17 +649,27 @@ the match data is set appropriately."
 		   'outline-get-last-sibling))
 	(ins-point (make-marker))
 	(cnt (abs arg))
+	;; Make sure we can move forward when needed (bug#19102).
+	(maybe-forward-char (lambda ()
+			      (when (and (eobp) (not (bolp)))
+				(newline))
+			      (unless (bolp)
+				(if (= (char-after) ?\n)
+				    (forward-char 1)))))
+	(empty-last-line (save-excursion
+			   (goto-char (point-max))
+			   (and (bolp) (eolp))))
 	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)
@@ -667,14 +677,19 @@ the match data is set appropriately."
 		 (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)
     (if folded (hide-subtree))
-    (move-marker ins-point nil)))
+    (move-marker ins-point nil)
+    ;; Clean up if necessary.
+    (save-excursion
+      (goto-char (point-max))
+      (when (and (bolp) (eolp) (not empty-last-line))
+	(delete-char -1)))))
 
 (defun outline-end-of-heading ()
   (if (re-search-forward outline-heading-end-regexp nil 'move)

This bug report was last modified 10 years and 237 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.