Allow archiving to a datetree.
* org-archive.el (org-archive-subtree): Allow archiving to a datetree. * org.el (org-archive-location): Ditto. * org.texi (Moving subtrees): Document the ability to archive to a datetree. TINYCHANGE
This commit is contained in:
parent
b112ac9c2f
commit
44e7ed1a59
22
doc/org.texi
22
doc/org.texi
|
@ -6976,16 +6976,20 @@ is invoked, the level 1 trees will be checked.
|
||||||
@cindex archive locations
|
@cindex archive locations
|
||||||
The default archive location is a file in the same directory as the
|
The default archive location is a file in the same directory as the
|
||||||
current file, with the name derived by appending @file{_archive} to the
|
current file, with the name derived by appending @file{_archive} to the
|
||||||
current file name. For information and examples on how to change this,
|
current file name. You can also choose what heading to file archived
|
||||||
|
items under, with the possibility to add them to a datetree in a file.
|
||||||
|
For information and examples on how to specify the file and the heading,
|
||||||
see the documentation string of the variable
|
see the documentation string of the variable
|
||||||
@code{org-archive-location}. There is also an in-buffer option for
|
@code{org-archive-location}.
|
||||||
setting this variable, for example@footnote{For backward compatibility,
|
|
||||||
the following also works: If there are several such lines in a file,
|
There is also an in-buffer option for setting this variable, for
|
||||||
each specifies the archive location for the text below it. The first
|
example@footnote{For backward compatibility, the following also works:
|
||||||
such line also applies to any text before its definition. However,
|
If there are several such lines in a file, each specifies the archive
|
||||||
using this method is @emph{strongly} deprecated as it is incompatible
|
location for the text below it. The first such line also applies to any
|
||||||
with the outline structure of the document. The correct method for
|
text before its definition. However, using this method is
|
||||||
setting multiple archive locations in a buffer is using properties.}:
|
@emph{strongly} deprecated as it is incompatible with the outline
|
||||||
|
structure of the document. The correct method for setting multiple
|
||||||
|
archive locations in a buffer is using properties.}:
|
||||||
|
|
||||||
@cindex #+ARCHIVE
|
@cindex #+ARCHIVE
|
||||||
@example
|
@example
|
||||||
|
|
|
@ -223,13 +223,14 @@ this heading."
|
||||||
(current-time)))
|
(current-time)))
|
||||||
category todo priority ltags itags atags
|
category todo priority ltags itags atags
|
||||||
;; end of variables that will be used for saving context
|
;; end of variables that will be used for saving context
|
||||||
location afile heading buffer level newfile-p infile-p visiting)
|
location afile heading buffer level newfile-p infile-p visiting
|
||||||
|
datetree-date datetree-subheading-p)
|
||||||
|
|
||||||
;; Find the local archive location
|
;; Find the local archive location
|
||||||
(setq location (org-get-local-archive-location)
|
(setq location (org-get-local-archive-location)
|
||||||
afile (org-extract-archive-file location)
|
afile (org-extract-archive-file location)
|
||||||
heading (org-extract-archive-heading location)
|
heading (org-extract-archive-heading location)
|
||||||
infile-p (equal file (abbreviate-file-name afile)))
|
infile-p (equal file (abbreviate-file-name (or afile ""))))
|
||||||
(unless afile
|
(unless afile
|
||||||
(error "Invalid `org-archive-location'"))
|
(error "Invalid `org-archive-location'"))
|
||||||
|
|
||||||
|
@ -240,6 +241,13 @@ this heading."
|
||||||
(setq buffer (current-buffer)))
|
(setq buffer (current-buffer)))
|
||||||
(unless buffer
|
(unless buffer
|
||||||
(error "Cannot access file \"%s\"" afile))
|
(error "Cannot access file \"%s\"" afile))
|
||||||
|
(when (string-match "\\`datetree/" heading)
|
||||||
|
;; Replace with ***, to represent the 3 levels of headings the
|
||||||
|
;; datetree has.
|
||||||
|
(setq heading (replace-regexp-in-string "\\`datetree/" "***" heading))
|
||||||
|
(setq datetree-subheading-p (> (length heading) 3))
|
||||||
|
(setq datetree-date (org-date-to-gregorian
|
||||||
|
(or (org-entry-get nil "CLOSED" t) time))))
|
||||||
(if (and (> (length heading) 0)
|
(if (and (> (length heading) 0)
|
||||||
(string-match "^\\*+" heading))
|
(string-match "^\\*+" heading))
|
||||||
(setq level (match-end 0))
|
(setq level (match-end 0))
|
||||||
|
@ -272,6 +280,10 @@ this heading."
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(insert (format "\nArchived entries from file %s\n\n"
|
(insert (format "\nArchived entries from file %s\n\n"
|
||||||
(buffer-file-name this-buffer))))
|
(buffer-file-name this-buffer))))
|
||||||
|
(when datetree-date
|
||||||
|
(require 'org-datetree)
|
||||||
|
(org-datetree-find-date-create datetree-date)
|
||||||
|
(org-narrow-to-subtree))
|
||||||
;; Force the TODO keywords of the original buffer
|
;; Force the TODO keywords of the original buffer
|
||||||
(let ((org-todo-line-regexp tr-org-todo-line-regexp)
|
(let ((org-todo-line-regexp tr-org-todo-line-regexp)
|
||||||
(org-todo-keywords-1 tr-org-todo-keywords-1)
|
(org-todo-keywords-1 tr-org-todo-keywords-1)
|
||||||
|
@ -285,7 +297,7 @@ this heading."
|
||||||
tr-org-odd-levels-only)))
|
tr-org-odd-levels-only)))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(show-all)
|
(show-all)
|
||||||
(if heading
|
(if (and heading (not (and datetree-date (not datetree-subheading-p))))
|
||||||
(progn
|
(progn
|
||||||
(if (re-search-forward
|
(if (re-search-forward
|
||||||
(concat "^" (regexp-quote heading)
|
(concat "^" (regexp-quote heading)
|
||||||
|
@ -295,7 +307,8 @@ this heading."
|
||||||
;; Heading not found, just insert it at the end
|
;; Heading not found, just insert it at the end
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(or (bolp) (insert "\n"))
|
(or (bolp) (insert "\n"))
|
||||||
(insert "\n" heading "\n")
|
;; datetrees don't need too much spacing
|
||||||
|
(insert (if datetree-date "" "\n") heading "\n")
|
||||||
(end-of-line 0))
|
(end-of-line 0))
|
||||||
;; Make the subtree visible
|
;; Make the subtree visible
|
||||||
(show-subtree)
|
(show-subtree)
|
||||||
|
@ -306,9 +319,10 @@ this heading."
|
||||||
(org-end-of-subtree t))
|
(org-end-of-subtree t))
|
||||||
(skip-chars-backward " \t\r\n")
|
(skip-chars-backward " \t\r\n")
|
||||||
(and (looking-at "[ \t\r\n]*")
|
(and (looking-at "[ \t\r\n]*")
|
||||||
(replace-match "\n\n")))
|
;; datetree archives don't need so much spacing.
|
||||||
|
(replace-match (if datetree-date "\n" "\n\n"))))
|
||||||
;; No specific heading, just go to end of file.
|
;; No specific heading, just go to end of file.
|
||||||
(goto-char (point-max)) (insert "\n"))
|
(goto-char (point-max)) (unless datetree-date (insert "\n")))
|
||||||
;; Paste
|
;; Paste
|
||||||
(org-paste-subtree (org-get-valid-level level (and heading 1)))
|
(org-paste-subtree (org-get-valid-level level (and heading 1)))
|
||||||
;; Shall we append inherited tags?
|
;; Shall we append inherited tags?
|
||||||
|
@ -336,6 +350,7 @@ this heading."
|
||||||
(setq n (concat "ARCHIVE_" (upcase (symbol-name e))))
|
(setq n (concat "ARCHIVE_" (upcase (symbol-name e))))
|
||||||
(org-entry-put (point) n v)))))
|
(org-entry-put (point) n v)))))
|
||||||
|
|
||||||
|
(widen)
|
||||||
;; Save and kill the buffer, if it is not the same buffer.
|
;; Save and kill the buffer, if it is not the same buffer.
|
||||||
(when (not (eq this-buffer buffer))
|
(when (not (eq this-buffer buffer))
|
||||||
(save-buffer))))
|
(save-buffer))))
|
||||||
|
|
|
@ -4176,6 +4176,15 @@ Here are a few examples:
|
||||||
Archive in file ~/org/archive.org (absolute path), under headlines
|
Archive in file ~/org/archive.org (absolute path), under headlines
|
||||||
\"From FILENAME\" where file name is the current file name.
|
\"From FILENAME\" where file name is the current file name.
|
||||||
|
|
||||||
|
\"~/org/datetree.org::datetree/* Finished Tasks\"
|
||||||
|
The \"datetree/\" string is special, signifying to archive
|
||||||
|
items to the datetree. Items are placed in either the CLOSED
|
||||||
|
date of the item, or the current date if there is no CLOSED date.
|
||||||
|
The heading will be a subentry to the current date. There doesn't
|
||||||
|
need to be a heading, but there always needs to be a slash after
|
||||||
|
datetree. For example, to store archived items directly in the
|
||||||
|
datetree, use \"~/org/datetree.org::datetree/\".
|
||||||
|
|
||||||
\"basement::** Finished Tasks\"
|
\"basement::** Finished Tasks\"
|
||||||
Archive in file ./basement (relative path), as level 3 trees
|
Archive in file ./basement (relative path), as level 3 trees
|
||||||
below the level 2 heading \"** Finished Tasks\".
|
below the level 2 heading \"** Finished Tasks\".
|
||||||
|
|
Loading…
Reference in New Issue