emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 287740d: * outline.el (outline-move-subtree-down):


From: Stephen Berman
Subject: [Emacs-diffs] master 287740d: * outline.el (outline-move-subtree-down): Refactor and improve code.
Date: Sat, 29 Nov 2014 13:57:36 +0000

branch: master
commit 287740d6ed8135702d34133dbf01c4387bc145dc
Author: Paul Rankin <address@hidden>
Date:   Sat Nov 29 14:56:59 2014 +0100

    * outline.el (outline-move-subtree-down): Refactor and improve code.
---
 lisp/ChangeLog  |    4 ++++
 lisp/outline.el |   41 ++++++++++++++++++++---------------------
 2 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2a450a7..fbd7e2f 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
+2014-11-29  Paul Rankin  <address@hidden>  (tiny change)
+
+       * outline.el (outline-move-subtree-down): Refactor and improve code.
+
 2014-11-29  Stephen Berman  <address@hidden>
            Stefan Monnier  <address@hidden>
 
diff --git a/lisp/outline.el b/lisp/outline.el
index 61ee7ff..bb56341 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -645,25 +645,25 @@ 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))
-       ;; 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.
-    (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))
-    (funcall maybe-forward-char)
-    (setq end (point))
+  (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)
@@ -673,8 +673,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)
-              (funcall maybe-forward-char)))
+       (funcall end-point-func))
     (move-marker ins-point (point))
     (insert (delete-and-extract-region beg end))
     (goto-char ins-point)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]