如果您使用的是 emacs 24.1 或更高版本,您可以尝试
(setq org-refile-active-region-within-subtree t)
这几乎可以满足您的要求,但是将突出显示文本的行(emacs术语是“活动区域”)变成标题。
如果要将突出显示的文本移动到另一个标题,则必须扩展 org-mode。幸运的是,org 提供了您需要的工具。这是一个例子:
(defvar org-refile-region-format "\n%s\n")
(defvar org-refile-region-position 'top
"Where to refile a region. Use 'bottom to refile at the
end of the subtree. ")
(defun org-refile-region (beg end copy)
"Refile the active region.
If no region is active, refile the current paragraph.
With prefix arg C-u, copy region instad of killing it."
(interactive "r\nP")
;; mark paragraph if no region is set
(unless (use-region-p)
(setq beg (save-excursion
(backward-paragraph)
(skip-chars-forward "\n\t ")
(point))
end (save-excursion
(forward-paragraph)
(skip-chars-backward "\n\t ")
(point))))
(let* ((target (save-excursion (org-refile-get-location)))
(file (nth 1 target))
(pos (nth 3 target))
(text (buffer-substring-no-properties beg end)))
(unless copy (kill-region beg end))
(deactivate-mark)
(with-current-buffer (find-file-noselect file)
(save-excursion
(goto-char pos)
(if (eql org-refile-region-position 'bottom)
(org-end-of-subtree)
(org-end-of-meta-data-and-drawers))
(insert (format org-refile-region-format text))))))
我们使用org-refile-get-location
org refiling 机制并提取文件和位置。然后我们去那个位置并插入复制的文本。为方便起见,添加了两个变量。
org-refile-targets
让您控制要考虑的文件,例如:
nil ;; only the current file
'((org-agenda-files :maxlevel . 2)) ;; all agenda files, 1st/2nd level
'((org-files-list :maxlevel . 4)) ;; all agenda and all open files
'((my-org-files-list :maxlevel . 4)) ;; all files returned by `my-org-files-list'
要将重新归档限制为当前打开的组织缓冲区,请定义一个函数
(defun my-org-files-list ()
(mapcar (lambda (buffer)
(buffer-file-name buffer))
(org-buffer-list 'files t)))
然后要么
(setq org-refile-targets '((my-org-files-list :maxlevel . 4)))
或使用
M-x customize-option <ret> org-refile-targets
从“值菜单”中选择“功能”,然后键入my-org-files-list