aboutsummaryrefslogtreecommitdiffstats
path: root/oni-org
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-05-11 20:21:53 -0700
committerGravatar Tom Willemse2022-05-11 20:21:53 -0700
commit54e9c9c26f420fca9d088c9383f2f117a7a58bdd (patch)
tree01977b8e3b7b09b7cfdfb34cc3edd02a72d72d8b /oni-org
parentaaa5b89d0ad4bb8be0b42c873ede359e2ed651e8 (diff)
downloademacs-config-54e9c9c26f420fca9d088c9383f2f117a7a58bdd.tar.gz
emacs-config-54e9c9c26f420fca9d088c9383f2f117a7a58bdd.zip
[oni-org] Combine ‘oni-move-subtree-*’ into ‘oni-org-move-subtree’
These two functions do essentially the same thing, but in different directions. This can also be done with one single interactive function. This way there is only one thing to call.
Diffstat (limited to 'oni-org')
-rw-r--r--oni-org/oni-org.el38
1 files changed, 21 insertions, 17 deletions
diff --git a/oni-org/oni-org.el b/oni-org/oni-org.el
index 9a728be..6d69416 100644
--- a/oni-org/oni-org.el
+++ b/oni-org/oni-org.el
@@ -860,24 +860,28 @@ This is an around advice for ‘org-html--svg-image’ as FUN."
;;; Moving subtrees
-(defun oni-move-subtree-above ()
- (interactive)
- (let ((target (org-refile-get-location "Move subtree above")))
- (org-cut-subtree)
- (goto-char (nth 3 target))
- (org-paste-subtree)))
+(defun oni-org-move-subtree (target placement)
+ "Move the subtree at point to TARGET and place it at PLACEMENT.
-(defun oni-move-subtree-below ()
- (interactive)
- (let* ((components (org-heading-components))
- (target (org-refile-get-location "Move subtree below"))
- (marker (copy-marker (nth 3 target))))
- (org-cut-subtree)
- (goto-char marker)
- (org-forward-heading-same-level 1)
- (when (= (point) (marker-position marker))
- (goto-char (point-max)))
- (org-paste-subtree (car components))))
+TARGET should be a point or a marker in the current buffer.
+
+PLACEMENT should be a symbol. If PLACEMENT is above, it'll be
+placed above TARGET. Otherwise it will be placed below it."
+ (interactive
+ (list (let ((org-refile-targets '((nil :maxlevel . 1)))
+ (org-refile-use-outline-path nil))
+ (org-refile-get-location "Move subtree to:"))
+ (intern (completing-read "Above / Below: " '(above below) nil t))))
+ (save-excursion
+ (let ((heading-level (car (org-heading-components)))
+ (marker (copy-marker (nth 3 target))))
+ (org-cut-subtree)
+ (goto-char marker)
+ (unless (eq placement 'above)
+ (org-forward-heading-same-level 1)
+ (when (= (point) (marker-position marker))
+ (goto-char (point-max))))
+ (org-paste-subtree heading-level))))
(provide 'oni-org)
;;; oni-org.el ends here