org-mode 命令从子树创建新文件吗?

org-mode 命令从子树创建新文件吗?

在 Emacs org-mode 中,是否有类似的命令new-file-from-subtree

正如我所设想的,该命令将从当前文件中剪切子树,将子树粘贴到新缓冲区中,然后用子树的名称保存新缓冲区。

答案1

我不相信目前存在这样的命令。不过下面的命令可以解决问题:

(require 'org-element)

(defun zin/org-file-from-subtree (&optional name)
  "Cut the subtree currently being edited and create a new file
from it.

If called with the universal argument, prompt for new filename,
otherwise use the subtree title."
  (interactive "P")
  (org-back-to-heading)
  (let ((filename (cond
                   (current-prefix-arg
                    (expand-file-name
                     (read-file-name "New file name: ")))
                   (t
                    (concat
                     (expand-file-name
                      (org-element-property :title
                                            (org-element-at-point))
                      default-directory)
                     ".org")))))
    (org-cut-subtree)
    (find-file-noselect filename)
    (with-temp-file filename
      (org-mode)
      (yank))))

照原样,它不会将当前标题提升到 1 级,它将保留现有深度。(提升也应该可行,但需要更复杂的代码)。它还提供了使用 提示输入新文件名的选项C-u

相关内容