diff options
author | Kyle Meyer <kyle@kyleam.com> | 2014-08-02 22:37:27 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2014-08-02 22:37:27 -0400 |
commit | f4d71b2f2af4a80731274492d31d29ac0b2fcace (patch) | |
tree | fddae9403d051e3a385591c1ddec9a9e7cf76609 /lisp | |
parent | 1b35ba1f218c4436fa8415e557b8303efc73f639 (diff) | |
download | emacs.d-f4d71b2f2af4a80731274492d31d29ac0b2fcace.tar.gz |
Advise org-refile with dwim target
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/init-org.el | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lisp/init-org.el b/lisp/init-org.el index e2d77a3..8b2fc76 100644 --- a/lisp/init-org.el +++ b/lisp/init-org.el @@ -253,6 +253,28 @@ be restored properly." (setq org-refile-target-verify-function 'km/verify-refile-target) +(defadvice org-refile (around km/org-refile-dwim activate) + "Rebind `org-refile-targets' if next window is an Org buffer. +A target is determined by `km/org-refile-dwim-target-file'." + (let* ((dwim-target (km/org-refile-dwim-target-file)) + (org-refile-targets (if dwim-target + `((dwim-target + :maxlevel . ,km/org-refile-dwim-maxlevel)) + org-refile-targets))) + ad-do-it)) + +(defun km/org-refile-dwim-target-file () + "Return next window that is an Org buffer." + (let ((from-buffer (current-buffer))) + (--when-let (get-window-with-predicate + (lambda (w) + (with-current-buffer (window-buffer w) + (and (eq major-mode 'org-mode) + (not (eq from-buffer (current-buffer))))))) + (buffer-file-name (window-buffer it))))) + +(defvar km/org-refile-dwim-maxlevel 2) + (defun km/org-refile-to-other-file (file &optional maxlevel) "Refile with `org-refile-targets' set to FILE. A numeric prefix can be given to set MAXLEVEL (defaults to 2)." |