org-agenda: Small refactoring
[org-mode/org-tableheadings.git] / lisp / org-archive.el
blobc76abdb765a770aeb19ccd776a2ac8d6bed58a73
1 ;;; org-archive.el --- Archiving for Org -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2004-2017 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;;
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;; Commentary:
27 ;; This file contains the face definitions for Org.
29 ;;; Code:
31 (require 'org)
33 (declare-function org-element-type "org-element" (element))
34 (declare-function org-datetree-find-date-create "org-datetree" (date &optional keep-restriction))
35 (declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ())
37 (defcustom org-archive-default-command 'org-archive-subtree
38 "The default archiving command."
39 :group 'org-archive
40 :type '(choice
41 (const org-archive-subtree)
42 (const org-archive-to-archive-sibling)
43 (const org-archive-set-tag)))
45 (defcustom org-archive-reversed-order nil
46 "Non-nil means make the tree first child under the archive heading, not last."
47 :group 'org-archive
48 :version "24.1"
49 :type 'boolean)
51 (defcustom org-archive-sibling-heading "Archive"
52 "Name of the local archive sibling that is used to archive entries locally.
53 Locally means: in the tree, under a sibling.
54 See `org-archive-to-archive-sibling' for more information."
55 :group 'org-archive
56 :type 'string)
58 (defcustom org-archive-mark-done nil
59 "Non-nil means mark entries as DONE when they are moved to the archive file.
60 This can be a string to set the keyword to use. When non-nil, Org will
61 use the first keyword in its list that means done."
62 :group 'org-archive
63 :type '(choice
64 (const :tag "No" nil)
65 (const :tag "Yes" t)
66 (string :tag "Use this keyword")))
68 (defcustom org-archive-stamp-time t
69 "Non-nil means add a time stamp to entries moved to an archive file.
70 This variable is obsolete and has no effect anymore, instead add or remove
71 `time' from the variable `org-archive-save-context-info'."
72 :group 'org-archive
73 :type 'boolean)
75 (defcustom org-archive-file-header-format "\nArchived entries from file %s\n\n"
76 "The header format string for newly created archive files.
77 When nil, no header will be inserted.
78 When a string, a %s formatter will be replaced by the file name."
79 :group 'org-archive
80 :version "24.4"
81 :package-version '(Org . "8.0")
82 :type 'string)
84 (defcustom org-archive-subtree-add-inherited-tags 'infile
85 "Non-nil means append inherited tags when archiving a subtree."
86 :group 'org-archive
87 :version "24.1"
88 :type '(choice
89 (const :tag "Never" nil)
90 (const :tag "When archiving a subtree to the same file" infile)
91 (const :tag "Always" t)))
93 (defcustom org-archive-save-context-info '(time file olpath category todo itags)
94 "Parts of context info that should be stored as properties when archiving.
95 When a subtree is moved to an archive file, it loses information given by
96 context, like inherited tags, the category, and possibly also the TODO
97 state (depending on the variable `org-archive-mark-done').
98 This variable can be a list of any of the following symbols:
100 time The time of archiving.
101 file The file where the entry originates.
102 ltags The local tags, in the headline of the subtree.
103 itags The tags the subtree inherits from further up the hierarchy.
104 todo The pre-archive TODO state.
105 category The category, taken from file name or #+CATEGORY lines.
106 olpath The outline path to the item. These are all headlines above
107 the current item, separated by /, like a file path.
109 For each symbol present in the list, a property will be created in
110 the archived entry, with a prefix \"ARCHIVE_\", to remember this
111 information."
112 :group 'org-archive
113 :type '(set :greedy t
114 (const :tag "Time" time)
115 (const :tag "File" file)
116 (const :tag "Category" category)
117 (const :tag "TODO state" todo)
118 (const :tag "Priority" priority)
119 (const :tag "Inherited tags" itags)
120 (const :tag "Outline path" olpath)
121 (const :tag "Local tags" ltags)))
123 (defvar org-archive-hook nil
124 "Hook run after successfully archiving a subtree.
125 Hook functions are called with point on the subtree in the
126 original file. At this stage, the subtree has been added to the
127 archive location, but not yet deleted from the original file.")
129 (defun org-get-local-archive-location ()
130 "Get the archive location applicable at point."
131 (let ((re "^[ \t]*#\\+ARCHIVE:[ \t]+\\(\\S-.*\\S-\\)[ \t]*$")
132 prop)
133 (save-excursion
134 (save-restriction
135 (widen)
136 (setq prop (org-entry-get nil "ARCHIVE" 'inherit))
137 (cond
138 ((and prop (string-match "\\S-" prop))
139 prop)
140 ((or (re-search-backward re nil t)
141 (re-search-forward re nil t))
142 (match-string 1))
143 (t org-archive-location))))))
145 ;;;###autoload
146 (defun org-add-archive-files (files)
147 "Splice the archive files into the list of files.
148 This implies visiting all these files and finding out what the
149 archive file is."
150 (org-uniquify
151 (apply
152 'append
153 (mapcar
154 (lambda (f)
155 (if (not (file-exists-p f))
157 (with-current-buffer (org-get-agenda-file-buffer f)
158 (cons f (org-all-archive-files)))))
159 files))))
161 (defun org-all-archive-files ()
162 "Get a list of all archive files used in the current buffer."
163 (let ((case-fold-search t)
164 files)
165 (org-with-wide-buffer
166 (goto-char (point-min))
167 (while (re-search-forward
168 "^[ \t]*\\(#\\+\\|:\\)ARCHIVE:[ \t]+\\(.*\\)"
169 nil t)
170 (when (save-match-data
171 (if (eq (match-string 1) ":") (org-at-property-p)
172 (eq (org-element-type (org-element-at-point)) 'keyword)))
173 (let ((file (org-extract-archive-file
174 (match-string-no-properties 2))))
175 (when (and (org-string-nw-p file) (file-exists-p file))
176 (push file files))))))
177 (setq files (nreverse files))
178 (let ((file (org-extract-archive-file)))
179 (when (and (org-string-nw-p file) (file-exists-p file))
180 (push file files)))
181 files))
183 (defun org-extract-archive-file (&optional location)
184 "Extract and expand the file name from archive LOCATION.
185 if LOCATION is not given, the value of `org-archive-location' is used."
186 (setq location (or location org-archive-location))
187 (if (string-match "\\(.*\\)::\\(.*\\)" location)
188 (if (= (match-beginning 1) (match-end 1))
189 (buffer-file-name (buffer-base-buffer))
190 (expand-file-name
191 (format (match-string 1 location)
192 (file-name-nondirectory
193 (buffer-file-name (buffer-base-buffer))))))))
195 (defun org-extract-archive-heading (&optional location)
196 "Extract the heading from archive LOCATION.
197 if LOCATION is not given, the value of `org-archive-location' is used."
198 (setq location (or location org-archive-location))
199 (if (string-match "\\(.*\\)::\\(.*\\)" location)
200 (format (match-string 2 location)
201 (file-name-nondirectory
202 (buffer-file-name (buffer-base-buffer))))))
204 ;;;###autoload
205 (defun org-archive-subtree (&optional find-done)
206 "Move the current subtree to the archive.
207 The archive can be a certain top-level heading in the current file, or in
208 a different file. The tree will be moved to that location, the subtree
209 heading be marked DONE, and the current time will be added.
211 When called with a single prefix argument FIND-DONE, find whole trees without any
212 open TODO items and archive them (after getting confirmation from the user).
213 When called with a double prefix argument, find whole trees with timestamps before
214 today and archive them (after getting confirmation from the user).
215 If the cursor is not at a headline when these commands are called, try all level
216 1 trees. If the cursor is on a headline, only try the direct children of
217 this heading."
218 (interactive "P")
219 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
220 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
221 'region-start-level 'region))
222 org-loop-over-headlines-in-active-region)
223 (org-map-entries
224 `(progn (setq org-map-continue-from (progn (org-back-to-heading) (point)))
225 (org-archive-subtree ,find-done))
226 org-loop-over-headlines-in-active-region
227 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
228 (cond
229 ((equal find-done '(4)) (org-archive-all-done))
230 ((equal find-done '(16)) (org-archive-all-old))
232 ;; Save all relevant TODO keyword-relatex variables
233 (let* ((tr-org-todo-keywords-1 org-todo-keywords-1)
234 (tr-org-todo-kwd-alist org-todo-kwd-alist)
235 (tr-org-done-keywords org-done-keywords)
236 (tr-org-todo-regexp org-todo-regexp)
237 (tr-org-todo-line-regexp org-todo-line-regexp)
238 (tr-org-odd-levels-only org-odd-levels-only)
239 (this-buffer (current-buffer))
240 (time (format-time-string
241 (substring (cdr org-time-stamp-formats) 1 -1)))
242 (file (abbreviate-file-name
243 (or (buffer-file-name (buffer-base-buffer))
244 (error "No file associated to buffer"))))
245 (location (org-get-local-archive-location))
246 (afile (or (org-extract-archive-file location)
247 (error "Invalid `org-archive-location'")))
248 (heading (org-extract-archive-heading location))
249 (infile-p (equal file (abbreviate-file-name (or afile ""))))
250 (newfile-p (and (org-string-nw-p afile)
251 (not (file-exists-p afile))))
252 (buffer (cond ((not (org-string-nw-p afile)) this-buffer)
253 ((find-buffer-visiting afile))
254 ((find-file-noselect afile))
255 (t (error "Cannot access file \"%s\"" afile))))
256 level datetree-date datetree-subheading-p)
257 (when (string-match "\\`datetree/" heading)
258 ;; Replace with ***, to represent the 3 levels of headings the
259 ;; datetree has.
260 (setq heading (replace-regexp-in-string "\\`datetree/" "***" heading))
261 (setq datetree-subheading-p (> (length heading) 3))
262 (setq datetree-date (org-date-to-gregorian
263 (or (org-entry-get nil "CLOSED" t) time))))
264 (if (and (> (length heading) 0)
265 (string-match "^\\*+" heading))
266 (setq level (match-end 0))
267 (setq heading nil level 0))
268 (save-excursion
269 (org-back-to-heading t)
270 ;; Get context information that will be lost by moving the
271 ;; tree. See `org-archive-save-context-info'.
272 (let* ((all-tags (org-get-tags-at))
273 (local-tags (org-get-tags))
274 (inherited-tags (org-delete-all local-tags all-tags))
275 (context
276 `((category . ,(org-get-category nil 'force-refresh))
277 (file . ,file)
278 (itags . ,(mapconcat #'identity inherited-tags " "))
279 (ltags . ,(mapconcat #'identity local-tags " "))
280 (olpath . ,(mapconcat #'identity
281 (org-get-outline-path)
282 "/"))
283 (time . ,time)
284 (todo . ,(org-entry-get (point) "TODO")))))
285 ;; We first only copy, in case something goes wrong
286 ;; we need to protect `this-command', to avoid kill-region sets it,
287 ;; which would lead to duplication of subtrees
288 (let (this-command) (org-copy-subtree 1 nil t))
289 (set-buffer buffer)
290 ;; Enforce Org mode for the archive buffer
291 (if (not (derived-mode-p 'org-mode))
292 ;; Force the mode for future visits.
293 (let ((org-insert-mode-line-in-empty-file t)
294 (org-inhibit-startup t))
295 (call-interactively 'org-mode)))
296 (when (and newfile-p org-archive-file-header-format)
297 (goto-char (point-max))
298 (insert (format org-archive-file-header-format
299 (buffer-file-name this-buffer))))
300 (when datetree-date
301 (require 'org-datetree)
302 (org-datetree-find-date-create datetree-date)
303 (org-narrow-to-subtree))
304 ;; Force the TODO keywords of the original buffer
305 (let ((org-todo-line-regexp tr-org-todo-line-regexp)
306 (org-todo-keywords-1 tr-org-todo-keywords-1)
307 (org-todo-kwd-alist tr-org-todo-kwd-alist)
308 (org-done-keywords tr-org-done-keywords)
309 (org-todo-regexp tr-org-todo-regexp)
310 (org-todo-line-regexp tr-org-todo-line-regexp)
311 (org-odd-levels-only
312 (if (local-variable-p 'org-odd-levels-only (current-buffer))
313 org-odd-levels-only
314 tr-org-odd-levels-only)))
315 (goto-char (point-min))
316 (outline-show-all)
317 (if (and heading (not (and datetree-date (not datetree-subheading-p))))
318 (progn
319 (if (re-search-forward
320 (concat "^" (regexp-quote heading)
321 "[ \t]*\\(:[[:alnum:]_@#%:]+:\\)?[ \t]*\\($\\|\r\\)")
322 nil t)
323 (goto-char (match-end 0))
324 ;; Heading not found, just insert it at the end
325 (goto-char (point-max))
326 (or (bolp) (insert "\n"))
327 ;; datetrees don't need too much spacing
328 (insert (if datetree-date "" "\n") heading "\n")
329 (end-of-line 0))
330 ;; Make the subtree visible
331 (outline-show-subtree)
332 (if org-archive-reversed-order
333 (progn
334 (org-back-to-heading t)
335 (outline-next-heading))
336 (org-end-of-subtree t))
337 (skip-chars-backward " \t\r\n")
338 (and (looking-at "[ \t\r\n]*")
339 ;; datetree archives don't need so much spacing.
340 (replace-match (if datetree-date "\n" "\n\n"))))
341 ;; No specific heading, just go to end of file, or to the
342 ;; beginning, depending on `org-archive-reversed-order'.
343 (if org-archive-reversed-order
344 (progn
345 (goto-char (point-min))
346 (unless (org-at-heading-p) (outline-next-heading))
347 (insert "\n") (backward-char 1))
348 (goto-char (point-max))
349 ;; Subtree narrowing can let the buffer end on
350 ;; a headline. `org-paste-subtree' then deletes it.
351 ;; To prevent this, make sure visible part of buffer
352 ;; always terminates on a new line, while limiting
353 ;; number of blank lines in a date tree.
354 (unless (and datetree-date (bolp)) (insert "\n"))))
355 ;; Paste
356 (org-paste-subtree (org-get-valid-level level (and heading 1)))
357 ;; Shall we append inherited tags?
358 (and inherited-tags
359 (or (and (eq org-archive-subtree-add-inherited-tags 'infile)
360 infile-p)
361 (eq org-archive-subtree-add-inherited-tags t))
362 (org-set-tags-to all-tags))
363 ;; Mark the entry as done
364 (when (and org-archive-mark-done
365 (let ((case-fold-search nil))
366 (looking-at org-todo-line-regexp))
367 (or (not (match-end 2))
368 (not (member (match-string 2) org-done-keywords))))
369 (let (org-log-done org-todo-log-states)
370 (org-todo
371 (car (or (member org-archive-mark-done org-done-keywords)
372 org-done-keywords)))))
374 ;; Add the context info.
375 (dolist (item org-archive-save-context-info)
376 (let ((value (cdr (assq item context))))
377 (when (org-string-nw-p value)
378 (org-entry-put
379 (point)
380 (concat "ARCHIVE_" (upcase (symbol-name item)))
381 value))))
382 (widen)
383 ;; Save and kill the buffer, if it is not the same
384 ;; buffer.
385 (unless (eq this-buffer buffer) (save-buffer)))))
386 ;; Here we are back in the original buffer. Everything seems
387 ;; to have worked. So now run hooks, cut the tree and finish
388 ;; up.
389 (run-hooks 'org-archive-hook)
390 (let (this-command) (org-cut-subtree))
391 (when (featurep 'org-inlinetask)
392 (org-inlinetask-remove-END-maybe))
393 (setq org-markers-to-move nil)
394 (message "Subtree archived %s"
395 (if (eq this-buffer buffer)
396 (concat "under heading: " heading)
397 (concat "in file: " (abbreviate-file-name afile)))))))
398 (org-reveal)
399 (if (looking-at "^[ \t]*$")
400 (outline-next-visible-heading 1))))
402 ;;;###autoload
403 (defun org-archive-to-archive-sibling ()
404 "Archive the current heading by moving it under the archive sibling.
406 The archive sibling is a sibling of the heading with the heading name
407 `org-archive-sibling-heading' and an `org-archive-tag' tag. If this
408 sibling does not exist, it will be created at the end of the subtree.
410 Archiving time is retained in the ARCHIVE_TIME node property."
411 (interactive)
412 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
413 (let ((cl (when (eq org-loop-over-headlines-in-active-region 'start-level)
414 'region-start-level 'region))
415 org-loop-over-headlines-in-active-region)
416 (org-map-entries
417 '(progn (setq org-map-continue-from
418 (progn (org-back-to-heading)
419 (if (looking-at (concat "^.*:" org-archive-tag ":.*$"))
420 (org-end-of-subtree t)
421 (point))))
422 (when (org-at-heading-p)
423 (org-archive-to-archive-sibling)))
424 org-loop-over-headlines-in-active-region
425 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
426 (save-restriction
427 (widen)
428 (let (b e pos leader level)
429 (org-back-to-heading t)
430 (looking-at org-outline-regexp)
431 (setq leader (match-string 0)
432 level (funcall outline-level))
433 (setq pos (point))
434 (condition-case nil
435 (outline-up-heading 1 t)
436 (error (setq e (point-max)) (goto-char (point-min))))
437 (setq b (point))
438 (unless e
439 (condition-case nil
440 (org-end-of-subtree t t)
441 (error (goto-char (point-max))))
442 (setq e (point)))
443 (goto-char b)
444 (unless (re-search-forward
445 (concat "^" (regexp-quote leader)
446 "[ \t]*"
447 org-archive-sibling-heading
448 "[ \t]*:"
449 org-archive-tag ":") e t)
450 (goto-char e)
451 (or (bolp) (newline))
452 (insert leader org-archive-sibling-heading "\n")
453 (beginning-of-line 0)
454 (org-toggle-tag org-archive-tag 'on))
455 (beginning-of-line 1)
456 (if org-archive-reversed-order
457 (outline-next-heading)
458 (org-end-of-subtree t t))
459 (save-excursion
460 (goto-char pos)
461 (let ((this-command this-command)) (org-cut-subtree)))
462 (org-paste-subtree (org-get-valid-level level 1))
463 (org-set-property
464 "ARCHIVE_TIME"
465 (format-time-string
466 (substring (cdr org-time-stamp-formats) 1 -1)))
467 (outline-up-heading 1 t)
468 (outline-hide-subtree)
469 (org-cycle-show-empty-lines 'folded)
470 (goto-char pos)))
471 (org-reveal)
472 (if (looking-at "^[ \t]*$")
473 (outline-next-visible-heading 1))))
475 (defun org-archive-all-done (&optional tag)
476 "Archive sublevels of the current tree without open TODO items.
477 If the cursor is not on a headline, try all level 1 trees. If
478 it is on a headline, try all direct children.
479 When TAG is non-nil, don't move trees, but mark them with the ARCHIVE tag."
480 (org-archive-all-matches
481 (lambda (_beg end)
482 (let ((case-fold-search nil))
483 (unless (re-search-forward org-not-done-heading-regexp end t)
484 "no open TODO items")))
485 tag))
487 (defun org-archive-all-old (&optional tag)
488 "Archive sublevels of the current tree with timestamps prior to today.
489 If the cursor is not on a headline, try all level 1 trees. If
490 it is on a headline, try all direct children.
491 When TAG is non-nil, don't move trees, but mark them with the ARCHIVE tag."
492 (org-archive-all-matches
493 (lambda (_beg end)
494 (let (ts)
495 (and (re-search-forward org-ts-regexp end t)
496 (setq ts (match-string 0))
497 (< (org-time-stamp-to-now ts) 0)
498 (if (not (looking-at
499 (concat "--\\(" org-ts-regexp "\\)")))
500 (concat "old timestamp " ts)
501 (setq ts (concat "old timestamp " ts (match-string 0)))
502 (and (< (org-time-stamp-to-now (match-string 1)) 0)
503 ts)))))
504 tag))
506 (defun org-archive-all-matches (predicate &optional tag)
507 "Archive sublevels of the current tree that match PREDICATE.
509 PREDICATE is a function of two arguments, BEG and END, which
510 specify the beginning and end of the headline being considered.
511 It is called with point positioned at BEG. The headline will be
512 archived if PREDICATE returns non-nil. If the return value of
513 PREDICATE is a string, it should describe the reason for
514 archiving the heading.
516 If the cursor is not on a headline, try all level 1 trees. If it
517 is on a headline, try all direct children. When TAG is non-nil,
518 don't move trees, but mark them with the ARCHIVE tag."
519 (let ((rea (concat ".*:" org-archive-tag ":")) re1
520 (begm (make-marker))
521 (endm (make-marker))
522 (question (if tag "Set ARCHIVE tag? "
523 "Move subtree to archive? "))
524 reason beg end (cntarch 0))
525 (if (org-at-heading-p)
526 (progn
527 (setq re1 (concat "^" (regexp-quote
528 (make-string
529 (+ (- (match-end 0) (match-beginning 0) 1)
530 (if org-odd-levels-only 2 1))
531 ?*))
532 " "))
533 (move-marker begm (point))
534 (move-marker endm (org-end-of-subtree t)))
535 (setq re1 "^* ")
536 (move-marker begm (point-min))
537 (move-marker endm (point-max)))
538 (save-excursion
539 (goto-char begm)
540 (while (re-search-forward re1 endm t)
541 (setq beg (match-beginning 0)
542 end (save-excursion (org-end-of-subtree t) (point)))
543 (goto-char beg)
544 (if (not (setq reason (funcall predicate beg end)))
545 (goto-char end)
546 (goto-char beg)
547 (if (and (or (not tag) (not (looking-at rea)))
548 (y-or-n-p
549 (if (stringp reason)
550 (concat question "(" reason ")")
551 question)))
552 (progn
553 (if tag
554 (org-toggle-tag org-archive-tag 'on)
555 (org-archive-subtree))
556 (setq cntarch (1+ cntarch)))
557 (goto-char end)))))
558 (message "%d trees archived" cntarch)))
560 ;;;###autoload
561 (defun org-toggle-archive-tag (&optional find-done)
562 "Toggle the archive tag for the current headline.
563 With prefix ARG, check all children of current headline and offer tagging
564 the children that do not contain any open TODO items."
565 (interactive "P")
566 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
567 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
568 'region-start-level 'region))
569 org-loop-over-headlines-in-active-region)
570 (org-map-entries
571 `(org-toggle-archive-tag ,find-done)
572 org-loop-over-headlines-in-active-region
573 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
574 (if find-done
575 (org-archive-all-done 'tag)
576 (let (set)
577 (save-excursion
578 (org-back-to-heading t)
579 (setq set (org-toggle-tag org-archive-tag))
580 (when set (org-flag-subtree t)))
581 (and set (beginning-of-line 1))
582 (message "Subtree %s" (if set "archived" "unarchived"))))))
584 (defun org-archive-set-tag ()
585 "Set the ARCHIVE tag."
586 (interactive)
587 (if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
588 (let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
589 'region-start-level 'region))
590 org-loop-over-headlines-in-active-region)
591 (org-map-entries
592 'org-archive-set-tag
593 org-loop-over-headlines-in-active-region
594 cl (if (outline-invisible-p) (org-end-of-subtree nil t))))
595 (org-toggle-tag org-archive-tag 'on)))
597 ;;;###autoload
598 (defun org-archive-subtree-default ()
599 "Archive the current subtree with the default command.
600 This command is set with the variable `org-archive-default-command'."
601 (interactive)
602 (call-interactively org-archive-default-command))
604 ;;;###autoload
605 (defun org-archive-subtree-default-with-confirmation ()
606 "Archive the current subtree with the default command.
607 This command is set with the variable `org-archive-default-command'."
608 (interactive)
609 (if (y-or-n-p "Archive this subtree or entry? ")
610 (call-interactively org-archive-default-command)
611 (error "Abort")))
613 (provide 'org-archive)
615 ;; Local variables:
616 ;; generated-autoload-file: "org-loaddefs.el"
617 ;; End:
619 ;;; org-archive.el ends here