Here is a fast-and-filthy elisp function that could be modified as you may wish.
(defun subtree-to-new-file ()
(interactive)
"sloppily assists in moving an org subtree to a new file"
(org-copy-subtree nil t)
;;; This long setq statement gets the title of the first heading, to use as a default filename for the new .org file.
(setq first-heading
(with-temp-buffer
(yank)
(beginning-of-buffer)
(search-forward " " nil nil 1)
(setq title-start (point))
(end-of-visual-line)
(setq title-end (point))
(setq first-heading (buffer-substring title-start title-end))
))
(setq def-filename (concat first-heading ".org"))
(let ((insert-default-directory t))
(find-file-other-window
(read-file-name "Move subtree to file:" def-filename)
))
(org-paste-subtree)
;;; this final command adds the new .org file to the agenda
(org-agenda-file-to-front)
)
You can give this code a quick try by pasting into your *scratch*
buffer and hitting Ctrl+j. Then go to a subtree in an org-mode file and hit Alt+x to M-x subtree-to-new-file
.
If you want it to be in place every time you use emacs and are completely unfamliar with elisp, the easiest thing might be to also paste this code somewhere into your .emacs
configuration file and save it. You can also add a line before or after the function to give it a keybinding. The easiest way to do that (but maybe not the best) would be something like: (global-set-key "\C-xw" 'subtree-to-new-file)
.
org-agenda-files