diff options
| author | Paul Rankin | 2014-11-29 14:56:59 +0100 |
|---|---|---|
| committer | Stephen Berman | 2014-11-29 14:56:59 +0100 |
| commit | 287740d6ed8135702d34133dbf01c4387bc145dc (patch) | |
| tree | 396b4128b78e8c409cf8bb8c7bc3c4358eb748cb | |
| parent | dbff8fd118824163f4d2780fa8566cf92e1d8e86 (diff) | |
| download | emacs-287740d6ed8135702d34133dbf01c4387bc145dc.tar.gz emacs-287740d6ed8135702d34133dbf01c4387bc145dc.zip | |
* outline.el (outline-move-subtree-down): Refactor and improve code.
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/outline.el | 41 |
2 files changed, 24 insertions, 21 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2a450a7acff..fbd7e2f8eeb 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2014-11-29 Paul Rankin <paul@tilk.co> (tiny change) | ||
| 2 | |||
| 3 | * outline.el (outline-move-subtree-down): Refactor and improve code. | ||
| 4 | |||
| 1 | 2014-11-29 Stephen Berman <stephen.berman@gmx.net> | 5 | 2014-11-29 Stephen Berman <stephen.berman@gmx.net> |
| 2 | Stefan Monnier <monnier@iro.umontreal.ca> | 6 | Stefan Monnier <monnier@iro.umontreal.ca> |
| 3 | 7 | ||
diff --git a/lisp/outline.el b/lisp/outline.el index 61ee7ff0f9f..bb563410dba 100644 --- a/lisp/outline.el +++ b/lisp/outline.el | |||
| @@ -645,25 +645,25 @@ the match data is set appropriately." | |||
| 645 | (defun outline-move-subtree-down (&optional arg) | 645 | (defun outline-move-subtree-down (&optional arg) |
| 646 | "Move the current subtree down past ARG headlines of the same level." | 646 | "Move the current subtree down past ARG headlines of the same level." |
| 647 | (interactive "p") | 647 | (interactive "p") |
| 648 | (let ((movfunc (if (> arg 0) 'outline-get-next-sibling | 648 | (outline-back-to-heading) |
| 649 | 'outline-get-last-sibling)) | 649 | (let* ((movfunc (if (> arg 0) 'outline-get-next-sibling |
| 650 | (ins-point (make-marker)) | 650 | 'outline-get-last-sibling)) |
| 651 | (cnt (abs arg)) | 651 | ;; Find the end of the subtree to be moved as well as the point to |
| 652 | ;; Make sure we can move forward to find the end of the | 652 | ;; move it to, adding a newline if necessary, to ensure these points |
| 653 | ;; subtree and the insertion point. | 653 | ;; are at bol on the line below the subtree. |
| 654 | (maybe-forward-char (lambda () | 654 | (end-point-func (lambda () |
| 655 | (if (eq (char-after) ?\n) (forward-char 1) | 655 | (outline-end-of-subtree) |
| 656 | (if (and (eobp) (not (bolp))) (insert "\n"))))) | 656 | (if (eq (char-after) ?\n) (forward-char 1) |
| 657 | beg end folded) | 657 | (if (and (eobp) (not (bolp))) (insert "\n"))) |
| 658 | ;; Select the tree. | 658 | (point))) |
| 659 | (outline-back-to-heading) | 659 | (beg (point)) |
| 660 | (setq beg (point)) | 660 | (folded (save-match-data |
| 661 | (save-match-data | 661 | (outline-end-of-heading) |
| 662 | (save-excursion (outline-end-of-heading) | 662 | (outline-invisible-p))) |
| 663 | (setq folded (outline-invisible-p))) | 663 | (end (save-match-data |
| 664 | (outline-end-of-subtree)) | 664 | (funcall end-point-func))) |
| 665 | (funcall maybe-forward-char) | 665 | (ins-point (make-marker)) |
| 666 | (setq end (point)) | 666 | (cnt (abs arg))) |
| 667 | ;; Find insertion point, with error handling. | 667 | ;; Find insertion point, with error handling. |
| 668 | (goto-char beg) | 668 | (goto-char beg) |
| 669 | (while (> cnt 0) | 669 | (while (> cnt 0) |
| @@ -673,8 +673,7 @@ the match data is set appropriately." | |||
| 673 | (setq cnt (1- cnt))) | 673 | (setq cnt (1- cnt))) |
| 674 | (if (> arg 0) | 674 | (if (> arg 0) |
| 675 | ;; Moving forward - still need to move over subtree. | 675 | ;; Moving forward - still need to move over subtree. |
| 676 | (progn (outline-end-of-subtree) | 676 | (funcall end-point-func)) |
| 677 | (funcall maybe-forward-char))) | ||
| 678 | (move-marker ins-point (point)) | 677 | (move-marker ins-point (point)) |
| 679 | (insert (delete-and-extract-region beg end)) | 678 | (insert (delete-and-extract-region beg end)) |
| 680 | (goto-char ins-point) | 679 | (goto-char ins-point) |