From 9b06d2b0c5edc3feffc13da89a28b7b48ac55d3c Mon Sep 17 00:00:00 2001
From: Kyle Meyer <kyle@kyleam.com>
Date: Sat, 21 Feb 2015 22:02:27 -0500
Subject: Rewrite org-refile-dwim-target-file

---
 lisp/init-org.el | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

(limited to 'lisp')

diff --git a/lisp/init-org.el b/lisp/init-org.el
index 8bc7d55..6aa5944 100644
--- a/lisp/init-org.el
+++ b/lisp/init-org.el
@@ -464,6 +464,8 @@ displayed in the agenda."
   "Exclude DONE state from refile targets."
   (not (member (nth 2 (org-heading-components)) org-done-keywords)))
 
+(defvar km/org-refile-dwim-maxlevel 2)
+
 (defun km/org-refile-dwim ()
   "Rebind `org-refile-targets' if next window is an Org buffer.
 A target is determined by `km/org-refile-dwim-target-file'."
@@ -479,15 +481,14 @@ A target is determined by `km/org-refile-dwim-target-file'."
 
 (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)
+  (let* ((from-buffer (current-buffer))
+         (other-win (get-window-with-predicate
+                     (lambda (w)
+                       (with-current-buffer (window-buffer w)
+                         (and (derived-mode-p 'org-mode)
+                              (not (eq from-buffer (current-buffer)))))))))
+    (and other-win
+         (buffer-file-name (window-buffer other-win)))))
 
 (defun km/org-refile-to-other-file (file &optional maxlevel)
   "Refile with `org-refile-targets' set to FILE.
-- 
cgit v1.2.3