2015-11-13 17:47:06 -05:00
|
|
|
;;; org-archive.el --- Archiving for Org -*- lexical-binding: t; -*-
|
2008-04-09 09:42:36 -04:00
|
|
|
|
2018-01-07 00:27:54 -05:00
|
|
|
;; Copyright (C) 2004-2018 Free Software Foundation, Inc.
|
2008-04-09 09:42:36 -04:00
|
|
|
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
2018-01-16 11:22:00 -05:00
|
|
|
;; Homepage: https://orgmode.org
|
2008-04-09 09:42:36 -04:00
|
|
|
;;
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
2008-05-06 08:45:52 -04:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2008-04-09 09:42:36 -04:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:45:52 -04:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2008-04-09 09:42:36 -04:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 18:52:52 -04:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2008-04-09 09:42:36 -04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
|
2008-12-16 09:26:18 -05:00
|
|
|
;; This file contains the face definitions for Org.
|
2008-04-09 09:42:36 -04:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'org)
|
|
|
|
|
2015-11-13 17:59:33 -05:00
|
|
|
(declare-function org-element-type "org-element" (element))
|
2012-08-05 14:02:36 -04:00
|
|
|
(declare-function org-datetree-find-date-create "org-datetree" (date &optional keep-restriction))
|
2015-11-13 17:59:33 -05:00
|
|
|
(declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ())
|
2009-07-20 03:16:28 -04:00
|
|
|
|
2009-09-17 16:54:54 -04:00
|
|
|
(defcustom org-archive-default-command 'org-archive-subtree
|
2009-10-30 10:53:00 -04:00
|
|
|
"The default archiving command."
|
2009-09-17 16:54:54 -04:00
|
|
|
:group 'org-archive
|
|
|
|
:type '(choice
|
|
|
|
(const org-archive-subtree)
|
|
|
|
(const org-archive-to-archive-sibling)
|
2010-04-01 07:11:54 -04:00
|
|
|
(const org-archive-set-tag)))
|
2009-09-17 16:54:54 -04:00
|
|
|
|
2010-03-11 01:23:03 -05:00
|
|
|
(defcustom org-archive-reversed-order nil
|
|
|
|
"Non-nil means make the tree first child under the archive heading, not last."
|
|
|
|
:group 'org-archive
|
2012-03-19 16:38:12 -04:00
|
|
|
:version "24.1"
|
2010-03-11 01:23:03 -05:00
|
|
|
:type 'boolean)
|
|
|
|
|
2008-04-10 02:45:30 -04:00
|
|
|
(defcustom org-archive-sibling-heading "Archive"
|
|
|
|
"Name of the local archive sibling that is used to archive entries locally.
|
2008-04-09 09:42:36 -04:00
|
|
|
Locally means: in the tree, under a sibling.
|
2008-04-10 02:45:30 -04:00
|
|
|
See `org-archive-to-archive-sibling' for more information."
|
2008-04-09 09:42:36 -04:00
|
|
|
:group 'org-archive
|
|
|
|
:type 'string)
|
|
|
|
|
2009-10-02 00:47:30 -04:00
|
|
|
(defcustom org-archive-mark-done nil
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means mark entries as DONE when they are moved to the archive file.
|
2016-08-23 16:13:56 -04:00
|
|
|
This can be a string to set the keyword to use. When non-nil, Org will
|
2008-04-09 09:42:36 -04:00
|
|
|
use the first keyword in its list that means done."
|
|
|
|
:group 'org-archive
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "No" nil)
|
|
|
|
(const :tag "Yes" t)
|
|
|
|
(string :tag "Use this keyword")))
|
|
|
|
|
|
|
|
(defcustom org-archive-stamp-time t
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means add a time stamp to entries moved to an archive file.
|
2008-05-09 00:08:45 -04:00
|
|
|
This variable is obsolete and has no effect anymore, instead add or remove
|
|
|
|
`time' from the variable `org-archive-save-context-info'."
|
2008-04-09 09:42:36 -04:00
|
|
|
:group 'org-archive
|
|
|
|
:type 'boolean)
|
|
|
|
|
2013-01-30 05:50:14 -05:00
|
|
|
(defcustom org-archive-file-header-format "\nArchived entries from file %s\n\n"
|
|
|
|
"The header format string for newly created archive files.
|
|
|
|
When nil, no header will be inserted.
|
|
|
|
When a string, a %s formatter will be replaced by the file name."
|
|
|
|
:group 'org-archive
|
Add :version and :package-version
* ox.el (org-export-snippet-translation-alist)
(org-export-coding-system, org-export-in-background)
(org-export-async-init-file, org-export-invisible-backends)
(org-export-dispatch-use-expert-ui):
* ox-texinfo.el (org-texinfo-filename, org-texinfo-classes)
(org-texinfo-format-headline-function)
(org-texinfo-node-description-column)
(org-texinfo-active-timestamp-format)
(org-texinfo-link-with-unknown-path-format)
(org-texinfo-tables-verbatim)
(org-texinfo-table-scientific-notation)
(org-texinfo-text-markup-alist)
(org-texinfo-format-drawer-function)
(org-texinfo-format-inlinetask-function)
(org-texinfo-info-process):
* ox-man.el (org-man-tables-centered)
(org-man-table-scientific-notation)
(org-man-source-highlight, org-man-source-highlight-langs)
(org-man-pdf-process, org-man-logfiles-extensions):
* ox-html.el (org-html-allow-name-attribute-in-anchors)
(org-html-coding-system, org-html-divs):
* ox-ascii.el (org-ascii-text-width)
(org-ascii-headline-spacing, org-ascii-indented-line-width)
(org-ascii-paragraph-spacing, org-ascii-charset)
(org-ascii-underline, org-ascii-bullets)
(org-ascii-links-to-notes)
(org-ascii-table-keep-all-vertical-lines)
(org-ascii-table-widen-columns)
(org-ascii-table-use-ascii-art)
(org-ascii-format-drawer-function)
(org-ascii-format-inlinetask-function):
* org.el (org-modules, org-export-backends)
(org-highlight-latex-and-related, orgstruct-setup-hook):
* org-attach.el (org-attach-git-annex-cutoff):
* org-archive.el (org-archive-file-header-format):
* org-agenda.el (org-agenda-todo-ignore-time-comparison-use-seconds):
* ob-python.el (org-babel-python-hline-to)
(org-babel-python-None-to):
* ob-ditaa.el (org-ditaa-eps-jar-path):
* ob-core.el (org-babel-results-keyword): Add :version and
:package-version.
* ox-ascii.el: Use utf-8-emacs as the file coding system.
2013-03-05 10:34:16 -05:00
|
|
|
:version "24.4"
|
|
|
|
:package-version '(Org . "8.0")
|
2013-01-30 05:50:14 -05:00
|
|
|
:type 'string)
|
|
|
|
|
2011-02-01 10:09:04 -05:00
|
|
|
(defcustom org-archive-subtree-add-inherited-tags 'infile
|
|
|
|
"Non-nil means append inherited tags when archiving a subtree."
|
|
|
|
:group 'org-archive
|
2012-03-19 16:38:12 -04:00
|
|
|
:version "24.1"
|
2011-02-01 10:09:04 -05:00
|
|
|
:type '(choice
|
|
|
|
(const :tag "Never" nil)
|
|
|
|
(const :tag "When archiving a subtree to the same file" infile)
|
|
|
|
(const :tag "Always" t)))
|
|
|
|
|
2008-04-09 09:42:36 -04:00
|
|
|
(defcustom org-archive-save-context-info '(time file olpath category todo itags)
|
|
|
|
"Parts of context info that should be stored as properties when archiving.
|
2008-05-09 00:08:45 -04:00
|
|
|
When a subtree is moved to an archive file, it loses information given by
|
2008-04-09 09:42:36 -04:00
|
|
|
context, like inherited tags, the category, and possibly also the TODO
|
|
|
|
state (depending on the variable `org-archive-mark-done').
|
|
|
|
This variable can be a list of any of the following symbols:
|
|
|
|
|
|
|
|
time The time of archiving.
|
|
|
|
file The file where the entry originates.
|
2008-05-27 02:19:33 -04:00
|
|
|
ltags The local tags, in the headline of the subtree.
|
|
|
|
itags The tags the subtree inherits from further up the hierarchy.
|
2008-04-09 09:42:36 -04:00
|
|
|
todo The pre-archive TODO state.
|
|
|
|
category The category, taken from file name or #+CATEGORY lines.
|
|
|
|
olpath The outline path to the item. These are all headlines above
|
|
|
|
the current item, separated by /, like a file path.
|
|
|
|
|
|
|
|
For each symbol present in the list, a property will be created in
|
2011-02-01 09:29:46 -05:00
|
|
|
the archived entry, with a prefix \"ARCHIVE_\", to remember this
|
2008-04-09 09:42:36 -04:00
|
|
|
information."
|
|
|
|
:group 'org-archive
|
|
|
|
:type '(set :greedy t
|
2012-08-11 13:10:44 -04:00
|
|
|
(const :tag "Time" time)
|
|
|
|
(const :tag "File" file)
|
|
|
|
(const :tag "Category" category)
|
|
|
|
(const :tag "TODO state" todo)
|
|
|
|
(const :tag "Priority" priority)
|
|
|
|
(const :tag "Inherited tags" itags)
|
|
|
|
(const :tag "Outline path" olpath)
|
|
|
|
(const :tag "Local tags" ltags)))
|
2008-04-09 09:42:36 -04:00
|
|
|
|
2014-10-13 21:38:41 -04:00
|
|
|
(defvar org-archive-hook nil
|
|
|
|
"Hook run after successfully archiving a subtree.
|
|
|
|
Hook functions are called with point on the subtree in the
|
|
|
|
original file. At this stage, the subtree has been added to the
|
|
|
|
archive location, but not yet deleted from the original file.")
|
|
|
|
|
2008-04-18 03:50:50 -04:00
|
|
|
(defun org-get-local-archive-location ()
|
|
|
|
"Get the archive location applicable at point."
|
2014-03-12 14:54:05 -04:00
|
|
|
(let ((re "^[ \t]*#\\+ARCHIVE:[ \t]+\\(\\S-.*\\S-\\)[ \t]*$")
|
2008-04-18 03:50:50 -04:00
|
|
|
prop)
|
|
|
|
(save-excursion
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(setq prop (org-entry-get nil "ARCHIVE" 'inherit))
|
|
|
|
(cond
|
|
|
|
((and prop (string-match "\\S-" prop))
|
|
|
|
prop)
|
|
|
|
((or (re-search-backward re nil t)
|
|
|
|
(re-search-forward re nil t))
|
|
|
|
(match-string 1))
|
2010-09-11 01:38:27 -04:00
|
|
|
(t org-archive-location))))))
|
2008-04-18 03:50:50 -04:00
|
|
|
|
2013-11-15 00:53:59 -05:00
|
|
|
;;;###autoload
|
2008-04-18 03:50:50 -04:00
|
|
|
(defun org-add-archive-files (files)
|
2009-01-10 15:51:08 -05:00
|
|
|
"Splice the archive files into the list of files.
|
2008-04-18 03:50:50 -04:00
|
|
|
This implies visiting all these files and finding out what the
|
|
|
|
archive file is."
|
2009-01-10 15:51:08 -05:00
|
|
|
(org-uniquify
|
|
|
|
(apply
|
|
|
|
'append
|
|
|
|
(mapcar
|
|
|
|
(lambda (f)
|
|
|
|
(if (not (file-exists-p f))
|
|
|
|
nil
|
|
|
|
(with-current-buffer (org-get-agenda-file-buffer f)
|
|
|
|
(cons f (org-all-archive-files)))))
|
|
|
|
files))))
|
2008-04-18 03:50:50 -04:00
|
|
|
|
|
|
|
(defun org-all-archive-files ()
|
|
|
|
"Get a list of all archive files used in the current buffer."
|
2015-11-13 17:47:06 -05:00
|
|
|
(let ((case-fold-search t)
|
|
|
|
files)
|
|
|
|
(org-with-wide-buffer
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (re-search-forward
|
|
|
|
"^[ \t]*\\(#\\+\\|:\\)ARCHIVE:[ \t]+\\(.*\\)"
|
|
|
|
nil t)
|
|
|
|
(when (save-match-data
|
|
|
|
(if (eq (match-string 1) ":") (org-at-property-p)
|
|
|
|
(eq (org-element-type (org-element-at-point)) 'keyword)))
|
|
|
|
(let ((file (org-extract-archive-file
|
Remove final parts of XEmacs compatibility code
* lisp/org-compat.el: Declare `org-add-hook', `org-decompose-region',
`org-detach-overlay', `org-file-equal-p', `org-float-time',
`org-indent-line-to', `org-indent-to-column', `org-looking-at-p',
`org-looking-back', `org-propertize', `org-re' and
`org-select-frame-set-input-focus' as obsolete.
(org-overlay-display, org-overlay-before-string, org-find-overlays):
Move to "org.el"
(org-xemacs-key-equivalents, org-xemacs-p): Remove variables.
(org-region-active-p): Drop XEmacs support.
(org-xemacs-without-invisibility): Remove macro.
(org-get-x-clipboard-compat): Remove function.
* lisp/org-macs.el (org-match-string-no-properties): Remove function.
* lisp/ob-core.el:
* lisp/org-agenda.el:
* lisp/org-archive.el:
* lisp/org-clock.el:
* lisp/org-colview.el:
* lisp/org-crypt.el:
* lisp/org-element.el:
* lisp/org-faces.el:
* lisp/org-feed.el:
* lisp/org-footnote.el:
* lisp/org-habit.el:
* lisp/org-id.el:
* lisp/org-indent.el:
* lisp/org-inlinetask.el:
* lisp/org-lint.el:
* lisp/org-list.el:
* lisp/org-mouse.el:
* lisp/org-pcomplete.el:
* lisp/org-src.el:
* lisp/org-table.el:
* lisp/org-timer.el:
* lisp/org.el:
* lisp/ox-ascii.el:
* lisp/ox-odt.el:
* lisp/ox.el:
* contrib/lisp/org-notify.el:
* contrib/lisp/ox-taskjuggler.el:
* contrib/lisp/org-wikinodes.el:
* testing/lisp/test-org-src.el:
* testing/lisp/test-org.el: Silence byte-compiler.
2016-05-26 06:18:00 -04:00
|
|
|
(match-string-no-properties 2))))
|
2015-11-13 17:47:06 -05:00
|
|
|
(when (and (org-string-nw-p file) (file-exists-p file))
|
|
|
|
(push file files))))))
|
2008-04-18 03:50:50 -04:00
|
|
|
(setq files (nreverse files))
|
2015-11-13 17:47:06 -05:00
|
|
|
(let ((file (org-extract-archive-file)))
|
|
|
|
(when (and (org-string-nw-p file) (file-exists-p file))
|
|
|
|
(push file files)))
|
2008-04-18 03:50:50 -04:00
|
|
|
files))
|
|
|
|
|
|
|
|
(defun org-extract-archive-file (&optional location)
|
2008-05-08 03:19:05 -04:00
|
|
|
"Extract and expand the file name from archive LOCATION.
|
|
|
|
if LOCATION is not given, the value of `org-archive-location' is used."
|
2008-04-18 03:50:50 -04:00
|
|
|
(setq location (or location org-archive-location))
|
|
|
|
(if (string-match "\\(.*\\)::\\(.*\\)" location)
|
2008-04-25 09:44:07 -04:00
|
|
|
(if (= (match-beginning 1) (match-end 1))
|
2011-07-20 18:23:23 -04:00
|
|
|
(buffer-file-name (buffer-base-buffer))
|
2008-04-25 09:44:07 -04:00
|
|
|
(expand-file-name
|
2008-05-08 03:19:05 -04:00
|
|
|
(format (match-string 1 location)
|
2011-07-20 18:23:23 -04:00
|
|
|
(file-name-nondirectory
|
|
|
|
(buffer-file-name (buffer-base-buffer))))))))
|
2008-04-18 03:50:50 -04:00
|
|
|
|
|
|
|
(defun org-extract-archive-heading (&optional location)
|
2008-05-08 03:19:05 -04:00
|
|
|
"Extract the heading from archive LOCATION.
|
|
|
|
if LOCATION is not given, the value of `org-archive-location' is used."
|
2008-04-18 03:50:50 -04:00
|
|
|
(setq location (or location org-archive-location))
|
|
|
|
(if (string-match "\\(.*\\)::\\(.*\\)" location)
|
2009-01-11 15:23:10 -05:00
|
|
|
(format (match-string 2 location)
|
2011-07-20 18:23:23 -04:00
|
|
|
(file-name-nondirectory
|
|
|
|
(buffer-file-name (buffer-base-buffer))))))
|
2008-04-18 03:50:50 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-04-09 09:42:36 -04:00
|
|
|
(defun org-archive-subtree (&optional find-done)
|
|
|
|
"Move the current subtree to the archive.
|
Fix breakage due to outline-invisible-p defn change in emacs 26+
* lisp/org.el (org-invisible-p): New function. Restore the behavior
of outline-invisible-p prior to the following commint on emacs master
<http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=9cc59ffbbb2f20fbbf1c72d2e0c9dc47c7906a99>.
* lisp/org.el (org-cycle-internal-local)
(org-clean-visibility-after-subtree-move, org-goto)
(org-get-location, org-move-subtree-down, org-copy-subtree)
(org-paste-subtree, org-next-link, org-mark-ring-goto)
(org-todo, org-deadline, org-schedule, org-set-tags)
(org-truely-invisible-p, org-invisible-p2)
(org-forward-heading-same-level, org-forward-paragraph)
(org-backward-paragraph, org-down-element)
(org-bookmark-jump-unhide, org-mark-jump-unhide):
* lisp/org-list.el (org-insert-item):
* lisp/org-crypt.el (org-encrypt-entry, org-decrypt-entry):
* lisp/org-clock.el (org-clock-load):
* lisp/org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag)
(org-archive-set-tag):
* contrib/lisp/org-drill.el (org-drill-hide-subheadings-if): Use
org-invisible-p instead of outline-invisible-p.
Reference:
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-06/msg00230.html>
2017-06-14 11:20:05 -04:00
|
|
|
The archive can be a certain top-level heading in the current
|
|
|
|
file, or in a different file. The tree will be moved to that
|
|
|
|
location, the subtree heading be marked DONE, and the current
|
|
|
|
time will be added.
|
|
|
|
|
|
|
|
When called with a single prefix argument FIND-DONE, find whole
|
|
|
|
trees without any open TODO items and archive them (after getting
|
|
|
|
confirmation from the user). When called with a double prefix
|
|
|
|
argument, find whole trees with timestamps before today and
|
|
|
|
archive them (after getting confirmation from the user). If the
|
|
|
|
cursor is not at a headline when these commands are called, try
|
|
|
|
all level 1 trees. If the cursor is on a headline, only try the
|
|
|
|
direct children of this heading."
|
2008-04-09 09:42:36 -04:00
|
|
|
(interactive "P")
|
2011-12-30 02:52:05 -05:00
|
|
|
(if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
|
2011-12-30 05:13:45 -05:00
|
|
|
(let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
|
2011-12-31 06:06:43 -05:00
|
|
|
'region-start-level 'region))
|
2011-12-30 05:13:45 -05:00
|
|
|
org-loop-over-headlines-in-active-region)
|
2011-12-30 02:52:05 -05:00
|
|
|
(org-map-entries
|
|
|
|
`(progn (setq org-map-continue-from (progn (org-back-to-heading) (point)))
|
|
|
|
(org-archive-subtree ,find-done))
|
|
|
|
org-loop-over-headlines-in-active-region
|
Fix breakage due to outline-invisible-p defn change in emacs 26+
* lisp/org.el (org-invisible-p): New function. Restore the behavior
of outline-invisible-p prior to the following commint on emacs master
<http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=9cc59ffbbb2f20fbbf1c72d2e0c9dc47c7906a99>.
* lisp/org.el (org-cycle-internal-local)
(org-clean-visibility-after-subtree-move, org-goto)
(org-get-location, org-move-subtree-down, org-copy-subtree)
(org-paste-subtree, org-next-link, org-mark-ring-goto)
(org-todo, org-deadline, org-schedule, org-set-tags)
(org-truely-invisible-p, org-invisible-p2)
(org-forward-heading-same-level, org-forward-paragraph)
(org-backward-paragraph, org-down-element)
(org-bookmark-jump-unhide, org-mark-jump-unhide):
* lisp/org-list.el (org-insert-item):
* lisp/org-crypt.el (org-encrypt-entry, org-decrypt-entry):
* lisp/org-clock.el (org-clock-load):
* lisp/org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag)
(org-archive-set-tag):
* contrib/lisp/org-drill.el (org-drill-hide-subheadings-if): Use
org-invisible-p instead of outline-invisible-p.
Reference:
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-06/msg00230.html>
2017-06-14 11:20:05 -04:00
|
|
|
cl (if (org-invisible-p) (org-end-of-subtree nil t))))
|
2014-01-17 10:14:13 -05:00
|
|
|
(cond
|
|
|
|
((equal find-done '(4)) (org-archive-all-done))
|
|
|
|
((equal find-done '(16)) (org-archive-all-old))
|
|
|
|
(t
|
2011-12-30 02:52:05 -05:00
|
|
|
;; Save all relevant TODO keyword-relatex variables
|
2015-11-17 18:17:35 -05:00
|
|
|
(let* ((tr-org-todo-keywords-1 org-todo-keywords-1)
|
|
|
|
(tr-org-todo-kwd-alist org-todo-kwd-alist)
|
|
|
|
(tr-org-done-keywords org-done-keywords)
|
|
|
|
(tr-org-todo-regexp org-todo-regexp)
|
|
|
|
(tr-org-todo-line-regexp org-todo-line-regexp)
|
|
|
|
(tr-org-odd-levels-only org-odd-levels-only)
|
|
|
|
(this-buffer (current-buffer))
|
|
|
|
(time (format-time-string
|
|
|
|
(substring (cdr org-time-stamp-formats) 1 -1)))
|
|
|
|
(file (abbreviate-file-name
|
|
|
|
(or (buffer-file-name (buffer-base-buffer))
|
|
|
|
(error "No file associated to buffer"))))
|
|
|
|
(location (org-get-local-archive-location))
|
|
|
|
(afile (or (org-extract-archive-file location)
|
|
|
|
(error "Invalid `org-archive-location'")))
|
|
|
|
(heading (org-extract-archive-heading location))
|
|
|
|
(infile-p (equal file (abbreviate-file-name (or afile ""))))
|
|
|
|
(newfile-p (and (org-string-nw-p afile)
|
|
|
|
(not (file-exists-p afile))))
|
|
|
|
(buffer (cond ((not (org-string-nw-p afile)) this-buffer)
|
|
|
|
((find-buffer-visiting afile))
|
|
|
|
((find-file-noselect afile))
|
|
|
|
(t (error "Cannot access file \"%s\"" afile))))
|
|
|
|
level datetree-date datetree-subheading-p)
|
2012-04-21 11:27:43 -04:00
|
|
|
(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))))
|
2011-12-30 02:52:05 -05:00
|
|
|
(if (and (> (length heading) 0)
|
|
|
|
(string-match "^\\*+" heading))
|
|
|
|
(setq level (match-end 0))
|
|
|
|
(setq heading nil level 0))
|
|
|
|
(save-excursion
|
|
|
|
(org-back-to-heading t)
|
2015-11-17 18:17:35 -05:00
|
|
|
;; Get context information that will be lost by moving the
|
|
|
|
;; tree. See `org-archive-save-context-info'.
|
2018-04-18 11:28:52 -04:00
|
|
|
(let* ((all-tags (org-get-tags))
|
|
|
|
(local-tags
|
|
|
|
(cl-remove-if (lambda (tag)
|
|
|
|
(get-text-property 0 'inherited tag))
|
|
|
|
all-tags))
|
|
|
|
(inherited-tags
|
|
|
|
(cl-remove-if-not (lambda (tag)
|
|
|
|
(get-text-property 0 'inherited tag))
|
|
|
|
all-tags))
|
2015-11-17 18:17:35 -05:00
|
|
|
(context
|
|
|
|
`((category . ,(org-get-category nil 'force-refresh))
|
|
|
|
(file . ,file)
|
|
|
|
(itags . ,(mapconcat #'identity inherited-tags " "))
|
|
|
|
(ltags . ,(mapconcat #'identity local-tags " "))
|
|
|
|
(olpath . ,(mapconcat #'identity
|
|
|
|
(org-get-outline-path)
|
|
|
|
"/"))
|
|
|
|
(time . ,time)
|
|
|
|
(todo . ,(org-entry-get (point) "TODO")))))
|
|
|
|
;; We first only copy, in case something goes wrong
|
|
|
|
;; we need to protect `this-command', to avoid kill-region sets it,
|
|
|
|
;; which would lead to duplication of subtrees
|
|
|
|
(let (this-command) (org-copy-subtree 1 nil t))
|
|
|
|
(set-buffer buffer)
|
2016-08-23 16:13:56 -04:00
|
|
|
;; Enforce Org mode for the archive buffer
|
2015-11-17 18:17:35 -05:00
|
|
|
(if (not (derived-mode-p 'org-mode))
|
|
|
|
;; Force the mode for future visits.
|
|
|
|
(let ((org-insert-mode-line-in-empty-file t)
|
|
|
|
(org-inhibit-startup t))
|
|
|
|
(call-interactively 'org-mode)))
|
|
|
|
(when (and newfile-p org-archive-file-header-format)
|
|
|
|
(goto-char (point-max))
|
|
|
|
(insert (format org-archive-file-header-format
|
|
|
|
(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
|
|
|
|
(let ((org-todo-line-regexp tr-org-todo-line-regexp)
|
|
|
|
(org-todo-keywords-1 tr-org-todo-keywords-1)
|
|
|
|
(org-todo-kwd-alist tr-org-todo-kwd-alist)
|
|
|
|
(org-done-keywords tr-org-done-keywords)
|
|
|
|
(org-todo-regexp tr-org-todo-regexp)
|
|
|
|
(org-todo-line-regexp tr-org-todo-line-regexp)
|
|
|
|
(org-odd-levels-only
|
|
|
|
(if (local-variable-p 'org-odd-levels-only (current-buffer))
|
|
|
|
org-odd-levels-only
|
|
|
|
tr-org-odd-levels-only)))
|
|
|
|
(goto-char (point-min))
|
2017-12-06 10:03:23 -05:00
|
|
|
(org-show-all '(headings blocks))
|
2015-11-17 18:17:35 -05:00
|
|
|
(if (and heading (not (and datetree-date (not datetree-subheading-p))))
|
|
|
|
(progn
|
|
|
|
(if (re-search-forward
|
2018-04-19 08:27:12 -04:00
|
|
|
(concat "^" (regexp-quote heading) org-tag-group-re)
|
2015-11-17 18:17:35 -05:00
|
|
|
nil t)
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
;; Heading not found, just insert it at the end
|
|
|
|
(goto-char (point-max))
|
|
|
|
(or (bolp) (insert "\n"))
|
|
|
|
;; datetrees don't need too much spacing
|
|
|
|
(insert (if datetree-date "" "\n") heading "\n")
|
|
|
|
(end-of-line 0))
|
|
|
|
;; Make the subtree visible
|
|
|
|
(outline-show-subtree)
|
|
|
|
(if org-archive-reversed-order
|
|
|
|
(progn
|
|
|
|
(org-back-to-heading t)
|
|
|
|
(outline-next-heading))
|
|
|
|
(org-end-of-subtree t))
|
|
|
|
(skip-chars-backward " \t\r\n")
|
|
|
|
(and (looking-at "[ \t\r\n]*")
|
|
|
|
;; datetree archives don't need so much spacing.
|
|
|
|
(replace-match (if datetree-date "\n" "\n\n"))))
|
2017-05-05 05:59:10 -04:00
|
|
|
;; No specific heading, just go to end of file, or to the
|
|
|
|
;; beginning, depending on `org-archive-reversed-order'.
|
|
|
|
(if org-archive-reversed-order
|
|
|
|
(progn
|
|
|
|
(goto-char (point-min))
|
|
|
|
(unless (org-at-heading-p) (outline-next-heading))
|
|
|
|
(insert "\n") (backward-char 1))
|
|
|
|
(goto-char (point-max))
|
|
|
|
;; Subtree narrowing can let the buffer end on
|
|
|
|
;; a headline. `org-paste-subtree' then deletes it.
|
|
|
|
;; To prevent this, make sure visible part of buffer
|
|
|
|
;; always terminates on a new line, while limiting
|
|
|
|
;; number of blank lines in a date tree.
|
|
|
|
(unless (and datetree-date (bolp)) (insert "\n"))))
|
2015-11-17 18:17:35 -05:00
|
|
|
;; Paste
|
|
|
|
(org-paste-subtree (org-get-valid-level level (and heading 1)))
|
|
|
|
;; Shall we append inherited tags?
|
|
|
|
(and inherited-tags
|
|
|
|
(or (and (eq org-archive-subtree-add-inherited-tags 'infile)
|
|
|
|
infile-p)
|
|
|
|
(eq org-archive-subtree-add-inherited-tags t))
|
2018-04-20 04:45:19 -04:00
|
|
|
(org-set-tags all-tags))
|
2015-11-17 18:17:35 -05:00
|
|
|
;; Mark the entry as done
|
|
|
|
(when (and org-archive-mark-done
|
2016-11-13 04:58:23 -05:00
|
|
|
(let ((case-fold-search nil))
|
|
|
|
(looking-at org-todo-line-regexp))
|
2015-11-17 18:17:35 -05:00
|
|
|
(or (not (match-end 2))
|
|
|
|
(not (member (match-string 2) org-done-keywords))))
|
|
|
|
(let (org-log-done org-todo-log-states)
|
|
|
|
(org-todo
|
|
|
|
(car (or (member org-archive-mark-done org-done-keywords)
|
|
|
|
org-done-keywords)))))
|
2011-12-30 02:52:05 -05:00
|
|
|
|
2015-11-17 18:17:35 -05:00
|
|
|
;; Add the context info.
|
|
|
|
(dolist (item org-archive-save-context-info)
|
|
|
|
(let ((value (cdr (assq item context))))
|
|
|
|
(when (org-string-nw-p value)
|
|
|
|
(org-entry-put
|
|
|
|
(point)
|
|
|
|
(concat "ARCHIVE_" (upcase (symbol-name item)))
|
|
|
|
value))))
|
2017-11-25 10:26:15 -05:00
|
|
|
(widen))))
|
2014-10-13 21:38:41 -04:00
|
|
|
;; Here we are back in the original buffer. Everything seems
|
|
|
|
;; to have worked. So now run hooks, cut the tree and finish
|
|
|
|
;; up.
|
|
|
|
(run-hooks 'org-archive-hook)
|
2011-12-30 02:52:05 -05:00
|
|
|
(let (this-command) (org-cut-subtree))
|
|
|
|
(when (featurep 'org-inlinetask)
|
|
|
|
(org-inlinetask-remove-END-maybe))
|
|
|
|
(setq org-markers-to-move nil)
|
2017-09-06 08:31:01 -04:00
|
|
|
(when org-provide-todo-statistics
|
|
|
|
(save-excursion
|
|
|
|
;; Go to parent, even if no children exist.
|
|
|
|
(org-up-heading-safe)
|
|
|
|
;; Update cookie of parent.
|
|
|
|
(org-update-statistics-cookies nil)))
|
2011-12-30 02:52:05 -05:00
|
|
|
(message "Subtree archived %s"
|
|
|
|
(if (eq this-buffer buffer)
|
|
|
|
(concat "under heading: " heading)
|
2014-01-17 10:14:13 -05:00
|
|
|
(concat "in file: " (abbreviate-file-name afile)))))))
|
2011-12-30 02:52:05 -05:00
|
|
|
(org-reveal)
|
|
|
|
(if (looking-at "^[ \t]*$")
|
|
|
|
(outline-next-visible-heading 1))))
|
2008-04-09 09:42:36 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-04-10 02:45:30 -04:00
|
|
|
(defun org-archive-to-archive-sibling ()
|
|
|
|
"Archive the current heading by moving it under the archive sibling.
|
2016-11-06 19:14:04 -05:00
|
|
|
|
2008-04-10 02:45:30 -04:00
|
|
|
The archive sibling is a sibling of the heading with the heading name
|
|
|
|
`org-archive-sibling-heading' and an `org-archive-tag' tag. If this
|
2016-11-06 19:14:04 -05:00
|
|
|
sibling does not exist, it will be created at the end of the subtree.
|
|
|
|
|
|
|
|
Archiving time is retained in the ARCHIVE_TIME node property."
|
2008-04-09 09:42:36 -04:00
|
|
|
(interactive)
|
2011-12-30 02:52:05 -05:00
|
|
|
(if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
|
2011-12-30 05:13:45 -05:00
|
|
|
(let ((cl (when (eq org-loop-over-headlines-in-active-region 'start-level)
|
2011-12-31 06:06:43 -05:00
|
|
|
'region-start-level 'region))
|
2011-12-30 05:13:45 -05:00
|
|
|
org-loop-over-headlines-in-active-region)
|
2011-12-30 02:52:05 -05:00
|
|
|
(org-map-entries
|
|
|
|
'(progn (setq org-map-continue-from
|
|
|
|
(progn (org-back-to-heading)
|
|
|
|
(if (looking-at (concat "^.*:" org-archive-tag ":.*$"))
|
2017-09-06 08:31:01 -04:00
|
|
|
(org-end-of-subtree t)
|
2011-12-30 02:52:05 -05:00
|
|
|
(point))))
|
|
|
|
(when (org-at-heading-p)
|
|
|
|
(org-archive-to-archive-sibling)))
|
|
|
|
org-loop-over-headlines-in-active-region
|
Fix breakage due to outline-invisible-p defn change in emacs 26+
* lisp/org.el (org-invisible-p): New function. Restore the behavior
of outline-invisible-p prior to the following commint on emacs master
<http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=9cc59ffbbb2f20fbbf1c72d2e0c9dc47c7906a99>.
* lisp/org.el (org-cycle-internal-local)
(org-clean-visibility-after-subtree-move, org-goto)
(org-get-location, org-move-subtree-down, org-copy-subtree)
(org-paste-subtree, org-next-link, org-mark-ring-goto)
(org-todo, org-deadline, org-schedule, org-set-tags)
(org-truely-invisible-p, org-invisible-p2)
(org-forward-heading-same-level, org-forward-paragraph)
(org-backward-paragraph, org-down-element)
(org-bookmark-jump-unhide, org-mark-jump-unhide):
* lisp/org-list.el (org-insert-item):
* lisp/org-crypt.el (org-encrypt-entry, org-decrypt-entry):
* lisp/org-clock.el (org-clock-load):
* lisp/org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag)
(org-archive-set-tag):
* contrib/lisp/org-drill.el (org-drill-hide-subheadings-if): Use
org-invisible-p instead of outline-invisible-p.
Reference:
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-06/msg00230.html>
2017-06-14 11:20:05 -04:00
|
|
|
cl (if (org-invisible-p) (org-end-of-subtree nil t))))
|
2011-12-30 02:52:05 -05:00
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(let (b e pos leader level)
|
|
|
|
(org-back-to-heading t)
|
|
|
|
(looking-at org-outline-regexp)
|
|
|
|
(setq leader (match-string 0)
|
|
|
|
level (funcall outline-level))
|
2017-12-11 17:19:40 -05:00
|
|
|
(setq pos (point-marker))
|
2011-07-27 10:32:41 -04:00
|
|
|
(condition-case nil
|
2011-12-30 02:52:05 -05:00
|
|
|
(outline-up-heading 1 t)
|
|
|
|
(error (setq e (point-max)) (goto-char (point-min))))
|
|
|
|
(setq b (point))
|
|
|
|
(unless e
|
|
|
|
(condition-case nil
|
|
|
|
(org-end-of-subtree t t)
|
|
|
|
(error (goto-char (point-max))))
|
|
|
|
(setq e (point)))
|
|
|
|
(goto-char b)
|
|
|
|
(unless (re-search-forward
|
|
|
|
(concat "^" (regexp-quote leader)
|
|
|
|
"[ \t]*"
|
|
|
|
org-archive-sibling-heading
|
|
|
|
"[ \t]*:"
|
|
|
|
org-archive-tag ":") e t)
|
|
|
|
(goto-char e)
|
|
|
|
(or (bolp) (newline))
|
|
|
|
(insert leader org-archive-sibling-heading "\n")
|
|
|
|
(beginning-of-line 0)
|
|
|
|
(org-toggle-tag org-archive-tag 'on))
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(if org-archive-reversed-order
|
|
|
|
(outline-next-heading)
|
|
|
|
(org-end-of-subtree t t))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char pos)
|
|
|
|
(let ((this-command this-command)) (org-cut-subtree)))
|
|
|
|
(org-paste-subtree (org-get-valid-level level 1))
|
|
|
|
(org-set-property
|
|
|
|
"ARCHIVE_TIME"
|
|
|
|
(format-time-string
|
2014-10-28 21:42:51 -04:00
|
|
|
(substring (cdr org-time-stamp-formats) 1 -1)))
|
2011-12-30 02:52:05 -05:00
|
|
|
(outline-up-heading 1 t)
|
2015-09-27 11:45:07 -04:00
|
|
|
(outline-hide-subtree)
|
2011-12-30 02:52:05 -05:00
|
|
|
(org-cycle-show-empty-lines 'folded)
|
2017-09-06 08:31:01 -04:00
|
|
|
(when org-provide-todo-statistics
|
|
|
|
;; Update TODO statistics of parent.
|
|
|
|
(org-update-parent-todo-statistics))
|
2011-12-30 02:52:05 -05:00
|
|
|
(goto-char pos)))
|
|
|
|
(org-reveal)
|
|
|
|
(if (looking-at "^[ \t]*$")
|
|
|
|
(outline-next-visible-heading 1))))
|
2008-04-09 09:42:36 -04:00
|
|
|
|
|
|
|
(defun org-archive-all-done (&optional tag)
|
|
|
|
"Archive sublevels of the current tree without open TODO items.
|
|
|
|
If the cursor is not on a headline, try all level 1 trees. If
|
|
|
|
it is on a headline, try all direct children.
|
|
|
|
When TAG is non-nil, don't move trees, but mark them with the ARCHIVE tag."
|
2014-01-17 10:14:13 -05:00
|
|
|
(org-archive-all-matches
|
2015-11-13 17:47:06 -05:00
|
|
|
(lambda (_beg end)
|
2016-11-13 04:58:23 -05:00
|
|
|
(let ((case-fold-search nil))
|
|
|
|
(unless (re-search-forward org-not-done-heading-regexp end t)
|
|
|
|
"no open TODO items")))
|
2014-01-17 10:14:13 -05:00
|
|
|
tag))
|
|
|
|
|
|
|
|
(defun org-archive-all-old (&optional tag)
|
|
|
|
"Archive sublevels of the current tree with timestamps prior to today.
|
|
|
|
If the cursor is not on a headline, try all level 1 trees. If
|
|
|
|
it is on a headline, try all direct children.
|
|
|
|
When TAG is non-nil, don't move trees, but mark them with the ARCHIVE tag."
|
|
|
|
(org-archive-all-matches
|
2015-11-13 17:47:06 -05:00
|
|
|
(lambda (_beg end)
|
2014-01-17 10:14:13 -05:00
|
|
|
(let (ts)
|
|
|
|
(and (re-search-forward org-ts-regexp end t)
|
|
|
|
(setq ts (match-string 0))
|
|
|
|
(< (org-time-stamp-to-now ts) 0)
|
|
|
|
(if (not (looking-at
|
|
|
|
(concat "--\\(" org-ts-regexp "\\)")))
|
|
|
|
(concat "old timestamp " ts)
|
|
|
|
(setq ts (concat "old timestamp " ts (match-string 0)))
|
|
|
|
(and (< (org-time-stamp-to-now (match-string 1)) 0)
|
|
|
|
ts)))))
|
|
|
|
tag))
|
|
|
|
|
|
|
|
(defun org-archive-all-matches (predicate &optional tag)
|
|
|
|
"Archive sublevels of the current tree that match PREDICATE.
|
|
|
|
|
|
|
|
PREDICATE is a function of two arguments, BEG and END, which
|
|
|
|
specify the beginning and end of the headline being considered.
|
|
|
|
It is called with point positioned at BEG. The headline will be
|
|
|
|
archived if PREDICATE returns non-nil. If the return value of
|
|
|
|
PREDICATE is a string, it should describe the reason for
|
|
|
|
archiving the heading.
|
|
|
|
|
|
|
|
If the cursor is not on a headline, try all level 1 trees. If it
|
|
|
|
is on a headline, try all direct children. When TAG is non-nil,
|
|
|
|
don't move trees, but mark them with the ARCHIVE tag."
|
|
|
|
(let ((rea (concat ".*:" org-archive-tag ":")) re1
|
2008-04-09 09:42:36 -04:00
|
|
|
(begm (make-marker))
|
|
|
|
(endm (make-marker))
|
2014-01-17 10:14:13 -05:00
|
|
|
(question (if tag "Set ARCHIVE tag? "
|
|
|
|
"Move subtree to archive? "))
|
|
|
|
reason beg end (cntarch 0))
|
2012-01-02 13:52:35 -05:00
|
|
|
(if (org-at-heading-p)
|
2008-04-09 09:42:36 -04:00
|
|
|
(progn
|
|
|
|
(setq re1 (concat "^" (regexp-quote
|
|
|
|
(make-string
|
2009-12-10 03:23:58 -05:00
|
|
|
(+ (- (match-end 0) (match-beginning 0) 1)
|
|
|
|
(if org-odd-levels-only 2 1))
|
2008-04-09 09:42:36 -04:00
|
|
|
?*))
|
|
|
|
" "))
|
|
|
|
(move-marker begm (point))
|
|
|
|
(move-marker endm (org-end-of-subtree t)))
|
|
|
|
(setq re1 "^* ")
|
|
|
|
(move-marker begm (point-min))
|
|
|
|
(move-marker endm (point-max)))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char begm)
|
|
|
|
(while (re-search-forward re1 endm t)
|
|
|
|
(setq beg (match-beginning 0)
|
|
|
|
end (save-excursion (org-end-of-subtree t) (point)))
|
|
|
|
(goto-char beg)
|
2014-01-17 10:14:13 -05:00
|
|
|
(if (not (setq reason (funcall predicate beg end)))
|
2008-04-09 09:42:36 -04:00
|
|
|
(goto-char end)
|
|
|
|
(goto-char beg)
|
|
|
|
(if (and (or (not tag) (not (looking-at rea)))
|
2014-01-17 10:14:13 -05:00
|
|
|
(y-or-n-p
|
|
|
|
(if (stringp reason)
|
|
|
|
(concat question "(" reason ")")
|
|
|
|
question)))
|
2008-04-09 09:42:36 -04:00
|
|
|
(progn
|
|
|
|
(if tag
|
|
|
|
(org-toggle-tag org-archive-tag 'on)
|
|
|
|
(org-archive-subtree))
|
|
|
|
(setq cntarch (1+ cntarch)))
|
|
|
|
(goto-char end)))))
|
|
|
|
(message "%d trees archived" cntarch)))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-04-09 09:42:36 -04:00
|
|
|
(defun org-toggle-archive-tag (&optional find-done)
|
|
|
|
"Toggle the archive tag for the current headline.
|
|
|
|
With prefix ARG, check all children of current headline and offer tagging
|
|
|
|
the children that do not contain any open TODO items."
|
|
|
|
(interactive "P")
|
2011-12-30 02:52:05 -05:00
|
|
|
(if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
|
2011-12-30 05:13:45 -05:00
|
|
|
(let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
|
2011-12-31 06:06:43 -05:00
|
|
|
'region-start-level 'region))
|
2011-12-30 05:13:45 -05:00
|
|
|
org-loop-over-headlines-in-active-region)
|
2011-12-30 02:52:05 -05:00
|
|
|
(org-map-entries
|
|
|
|
`(org-toggle-archive-tag ,find-done)
|
|
|
|
org-loop-over-headlines-in-active-region
|
Fix breakage due to outline-invisible-p defn change in emacs 26+
* lisp/org.el (org-invisible-p): New function. Restore the behavior
of outline-invisible-p prior to the following commint on emacs master
<http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=9cc59ffbbb2f20fbbf1c72d2e0c9dc47c7906a99>.
* lisp/org.el (org-cycle-internal-local)
(org-clean-visibility-after-subtree-move, org-goto)
(org-get-location, org-move-subtree-down, org-copy-subtree)
(org-paste-subtree, org-next-link, org-mark-ring-goto)
(org-todo, org-deadline, org-schedule, org-set-tags)
(org-truely-invisible-p, org-invisible-p2)
(org-forward-heading-same-level, org-forward-paragraph)
(org-backward-paragraph, org-down-element)
(org-bookmark-jump-unhide, org-mark-jump-unhide):
* lisp/org-list.el (org-insert-item):
* lisp/org-crypt.el (org-encrypt-entry, org-decrypt-entry):
* lisp/org-clock.el (org-clock-load):
* lisp/org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag)
(org-archive-set-tag):
* contrib/lisp/org-drill.el (org-drill-hide-subheadings-if): Use
org-invisible-p instead of outline-invisible-p.
Reference:
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-06/msg00230.html>
2017-06-14 11:20:05 -04:00
|
|
|
cl (if (org-invisible-p) (org-end-of-subtree nil t))))
|
2011-12-30 02:52:05 -05:00
|
|
|
(if find-done
|
|
|
|
(org-archive-all-done 'tag)
|
|
|
|
(let (set)
|
|
|
|
(save-excursion
|
|
|
|
(org-back-to-heading t)
|
|
|
|
(setq set (org-toggle-tag org-archive-tag))
|
2016-02-10 18:47:55 -05:00
|
|
|
(when set (org-flag-subtree t)))
|
2011-12-30 02:52:05 -05:00
|
|
|
(and set (beginning-of-line 1))
|
|
|
|
(message "Subtree %s" (if set "archived" "unarchived"))))))
|
2008-04-09 09:42:36 -04:00
|
|
|
|
2009-09-17 16:54:54 -04:00
|
|
|
(defun org-archive-set-tag ()
|
|
|
|
"Set the ARCHIVE tag."
|
|
|
|
(interactive)
|
2011-12-30 02:52:05 -05:00
|
|
|
(if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
|
2011-12-30 05:13:45 -05:00
|
|
|
(let ((cl (if (eq org-loop-over-headlines-in-active-region 'start-level)
|
2011-12-31 06:06:43 -05:00
|
|
|
'region-start-level 'region))
|
2011-12-30 05:13:45 -05:00
|
|
|
org-loop-over-headlines-in-active-region)
|
2011-12-30 02:52:05 -05:00
|
|
|
(org-map-entries
|
|
|
|
'org-archive-set-tag
|
|
|
|
org-loop-over-headlines-in-active-region
|
Fix breakage due to outline-invisible-p defn change in emacs 26+
* lisp/org.el (org-invisible-p): New function. Restore the behavior
of outline-invisible-p prior to the following commint on emacs master
<http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=9cc59ffbbb2f20fbbf1c72d2e0c9dc47c7906a99>.
* lisp/org.el (org-cycle-internal-local)
(org-clean-visibility-after-subtree-move, org-goto)
(org-get-location, org-move-subtree-down, org-copy-subtree)
(org-paste-subtree, org-next-link, org-mark-ring-goto)
(org-todo, org-deadline, org-schedule, org-set-tags)
(org-truely-invisible-p, org-invisible-p2)
(org-forward-heading-same-level, org-forward-paragraph)
(org-backward-paragraph, org-down-element)
(org-bookmark-jump-unhide, org-mark-jump-unhide):
* lisp/org-list.el (org-insert-item):
* lisp/org-crypt.el (org-encrypt-entry, org-decrypt-entry):
* lisp/org-clock.el (org-clock-load):
* lisp/org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag)
(org-archive-set-tag):
* contrib/lisp/org-drill.el (org-drill-hide-subheadings-if): Use
org-invisible-p instead of outline-invisible-p.
Reference:
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-06/msg00230.html>
2017-06-14 11:20:05 -04:00
|
|
|
cl (if (org-invisible-p) (org-end-of-subtree nil t))))
|
2011-12-30 02:52:05 -05:00
|
|
|
(org-toggle-tag org-archive-tag 'on)))
|
2009-09-17 16:54:54 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun org-archive-subtree-default ()
|
|
|
|
"Archive the current subtree with the default command.
|
|
|
|
This command is set with the variable `org-archive-default-command'."
|
|
|
|
(interactive)
|
2009-10-05 11:13:56 -04:00
|
|
|
(call-interactively org-archive-default-command))
|
2009-09-17 16:54:54 -04:00
|
|
|
|
2009-11-18 12:32:51 -05:00
|
|
|
;;;###autoload
|
2009-10-30 10:53:00 -04:00
|
|
|
(defun org-archive-subtree-default-with-confirmation ()
|
|
|
|
"Archive the current subtree with the default command.
|
|
|
|
This command is set with the variable `org-archive-default-command'."
|
|
|
|
(interactive)
|
|
|
|
(if (y-or-n-p "Archive this subtree or entry? ")
|
|
|
|
(call-interactively org-archive-default-command)
|
|
|
|
(error "Abort")))
|
|
|
|
|
2008-04-09 09:42:36 -04:00
|
|
|
(provide 'org-archive)
|
|
|
|
|
2012-10-02 02:50:46 -04:00
|
|
|
;; Local variables:
|
|
|
|
;; generated-autoload-file: "org-loaddefs.el"
|
|
|
|
;; End:
|
|
|
|
|
2008-04-09 09:42:36 -04:00
|
|
|
;;; org-archive.el ends here
|