我通常使用org-mode来跟踪TODO.我有这样的文件:
* Misc.
** TODO Task 1
** TODO Task 2
* Project 1
** TODO Task 1
** TODO Task 2
Run Code Online (Sandbox Code Playgroud)
虽然归档整个子树一样Project 1的工作如预期,我不能够移动Task 1以Misc.使得归档文件看起来像这样(忽略在这个例子中PROPERTIES):
* Misc
** DONE Task 1
Run Code Online (Sandbox Code Playgroud)
换句话说,我想保留一个任务所属的所有部分.有快速的方法吗?
Jon*_*pin 20
您可能希望:ARCHIVE:在父标题上设置该属性.
它允许您进行标题特定org-archive-location设置.(参见手册)
例如,如果您的存档文件设置为%s_archive您希望原始文件看起来像这样
* Misc.
:PROPERTIES:
:ARCHIVE: %s_archive::* Misc
:END:
** TODO Task 1
** TODO Task 2
* Project 1
:PROPERTIES:
:ARCHIVE: %s_archive::* Project 1
:END:
** TODO Task 1
** TODO Task 2
Run Code Online (Sandbox Code Playgroud)
这会将任何子树发送* Misc到* Misc存档文件的标题中,并且会对子树中的子树执行相同的操作Project 1(除非您一次性归档整个树).在子树出现后存档父树将其添加为目标下的附加子标题.它不支持多个级别,因此您必须提前设置存档文件标题,以确保在需要复杂的类型设置时以您希望的方式输出.
您还可以使用此属性将特定树归档为单独的文件(用于导出/发布/共享).
小智 6
;; org-archive-subtree-hierarchical.el
;; modified from https://lists.gnu.org/archive/html/emacs-orgmode/2014-08/msg00109.html
;; In orgmode
;; * A
;; ** AA
;; *** AAA
;; ** AB
;; *** ABA
;; Archiving AA will remove the subtree from the original file and create
;; it like that in archive target:
;; * AA
;; ** AAA
;; And this give you
;; * A
;; ** AA
;; *** AAA
(require 'org-archive)
(defun org-archive-subtree-hierarchical--line-content-as-string ()
"Returns the content of the current line as a string"
(save-excursion
(beginning-of-line)
(buffer-substring-no-properties
(line-beginning-position) (line-end-position))))
(defun org-archive-subtree-hierarchical--org-child-list ()
"This function returns all children of a heading as a list. "
(interactive)
(save-excursion
;; this only works with org-version > 8.0, since in previous
;; org-mode versions the function (org-outline-level) returns
;; gargabe when the point is not on a heading.
(if (= (org-outline-level) 0)
(outline-next-visible-heading 1)
(org-goto-first-child))
(let ((child-list (list (org-archive-subtree-hierarchical--line-content-as-string))))
(while (org-goto-sibling)
(setq child-list (cons (org-archive-subtree-hierarchical--line-content-as-string) child-list)))
child-list)))
(defun org-archive-subtree-hierarchical--org-struct-subtree ()
"This function returns the tree structure in which a subtree
belongs as a list."
(interactive)
(let ((archive-tree nil))
(save-excursion
(while (org-up-heading-safe)
(let ((heading
(buffer-substring-no-properties
(line-beginning-position) (line-end-position))))
(if (eq archive-tree nil)
(setq archive-tree (list heading))
(setq archive-tree (cons heading archive-tree))))))
archive-tree))
(defun org-archive-subtree-hierarchical ()
"This function archives a subtree hierarchical"
(interactive)
(let ((org-tree (org-archive-subtree-hierarchical--org-struct-subtree))
(this-buffer (current-buffer))
(file (abbreviate-file-name
(or (buffer-file-name (buffer-base-buffer))
(error "No file associated to buffer")))))
(save-excursion
(setq location (org-get-local-archive-location)
afile (org-extract-archive-file location)
heading (org-extract-archive-heading location)
infile-p (equal file (abbreviate-file-name (or afile ""))))
(unless afile
(error "Invalid `org-archive-location'"))
(if (> (length afile) 0)
(setq newfile-p (not (file-exists-p afile))
visiting (find-buffer-visiting afile)
buffer (or visiting (find-file-noselect afile)))
(setq buffer (current-buffer)))
(unless buffer
(error "Cannot access file \"%s\"" afile))
(org-cut-subtree)
(set-buffer buffer)
(org-mode)
(goto-char (point-min))
(while (not (equal org-tree nil))
(let ((child-list (org-archive-subtree-hierarchical--org-child-list)))
(if (member (car org-tree) child-list)
(progn
(search-forward (car org-tree) nil t)
(setq org-tree (cdr org-tree)))
(progn
(goto-char (point-max))
(newline)
(org-insert-struct org-tree)
(setq org-tree nil)))))
(newline)
(org-yank)
(when (not (eq this-buffer buffer))
(save-buffer))
(message "Subtree archived %s"
(concat "in file: " (abbreviate-file-name afile))))))
(defun org-insert-struct (struct)
"TODO"
(interactive)
(when struct
(insert (car struct))
(newline)
(org-insert-struct (cdr struct))))
(defun org-archive-subtree ()
(org-archive-subtree-hierarchical)
)
Run Code Online (Sandbox Code Playgroud)
这种黑客行为就像重新归档到具有完全相同的父结构的归档文件一样,:PROPERTIES:此处没有归档。
也是这里的要点:https : //gist.github.com/CodeFalling/87b116291aa87fde72cb
我认为不org-mode支持直接镜像存档文件中的当前上下文。
有一个相关变量,org-archive-location可用于指定单个标题来放置已存档的项目,但不支持树中的多个级别。在此页面上,有两个建议org-archive-subtree可能就足够了。我在这里复制第一个,以防站点消失:
(defadvice org-archive-subtree (around my-org-archive-subtree activate)
(let ((org-archive-location
(if (save-excursion (org-back-to-heading)
(> (org-outline-level) 1))
(concat (car (split-string org-archive-location "::"))
"::* "
(car (org-get-outline-path)))
org-archive-location)))
ad-do-it))
Run Code Online (Sandbox Code Playgroud)
第二个也是更复杂的一个也保留在顶级标题上找到的标签。
最后一件有用的事情是自定义变量org-archive-save-context-info。如果此列表包含符号'olpath,则归档条目将包含:ARCHIVE_OLPATH:属性,该属性设置为归档条目的轮廓路径(例如Projects/Misc。也许您可以对进行一些后处理,org-archive-subtree然后使用将该属性重新定位到其归档轮廓路径。