From c25165c25dc9fdb5b57b3c66b2e0ec0efdbeb7ad Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Wed, 17 Aug 2011 11:20:42 +0200 Subject: [PATCH] org-refile: New option `org-refile-active-region-within-subtree'. * org.el (org-refile-active-region-within-subtree): New option to allow refiling a region that is part of a subtree without containing a subtree itself. This default to `nil'. (org-refile): Use the new option. Put point at the beginning of the region/subtree to be refiled, so that users understand what will be refiled. Also improve the prompt to tell whether the user is refiling a region or a headline. Thanks to Jeff Horn for raising the issue of refiling a list item, and to Nicolas Goaziou, Nick Dokos and Suvayu Ali for discussing them patiently. The discussion led to these changes. --- lisp/org.el | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index d9572c2b3..737bcc163 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -1970,6 +1970,16 @@ heading." (const :tag "Always" t) (const :tag "Prompt for confirmation" confirm))) +(defcustom org-refile-active-region-within-subtree nil + "Non-nil means also refile active region within a subtree. + +By default `org-refile' doesn't allow refiling regions if they +don't contain a set of subtrees, but it might be convenient to +do so sometimes: in that case, the first line of the region is +converted to a headline before refiling." + :group 'org-refile + :type 'boolean) + (defgroup org-todo nil "Options concerning TODO items in Org-mode." :tag "Org TODO" @@ -10435,8 +10445,10 @@ prefix argument (`C-u C-u C-u C-c C-w')." (goto-char region-start) (or (bolp) (goto-char (point-at-bol))) (setq region-start (point)) - (unless (org-kill-is-subtree-p - (buffer-substring region-start region-end)) + (unless (or (org-kill-is-subtree-p + (buffer-substring region-start region-end)) + (prog1 org-refile-active-region-within-subtree + (org-toggle-heading))) (error "The region is not a (sequence of) subtree(s)"))) (if (equal goto '(16)) (org-refile-goto-last-stored) @@ -10452,8 +10464,11 @@ prefix argument (`C-u C-u C-u C-c C-w')." (setq goto nil))) (setq it (or rfloc (save-excursion + (org-back-to-heading t) (org-refile-get-location - (if goto "Goto" "Refile to") default-buffer + (cond (goto "Goto") + (regionp "Refile region to") + (t "Refile subtree to")) default-buffer org-refile-allow-creating-parent-nodes))))) (setq file (nth 1 it) re (nth 2 it)