From 1d04af59b66b8efb9dda28d06bce9e54dc1cef4f Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Tue, 15 Aug 2023 13:54:00 +0300 Subject: [PATCH] org-refile-get-targets: Barf when target is not an Org buffer * lisp/org-refile.el (org-refile-get-targets): Display error when target buffer is not in Org mode. If we do not manually throw an error, local variables like `org-complex-heading-regexp' will not be defined, and the user would see a lot more cryptic error. --- lisp/org-refile.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lisp/org-refile.el b/lisp/org-refile.el index 1902da2c7..f96182c00 100644 --- a/lisp/org-refile.el +++ b/lisp/org-refile.el @@ -307,6 +307,8 @@ converted to a headline before refiling." (t (error "Bad refiling target description %s" desc))) (dolist (f files) (with-current-buffer (if (bufferp f) f (org-get-agenda-file-buffer f)) + (unless (derived-mode-p 'org-mode) + (error "Major mode in refile target buffer \"%s\" must be `org-mode'" f)) (or (setq tgs (org-refile-cache-get (buffer-file-name) descre)) (progn