forked from mirrors/org-mode
Allow to loop over active region for more archive commands.
* org-archive.el (org-archive-subtree) (org-archive-to-archive-sibling, org-archive-set-tag) (org-toggle-archive-tag): Allow to loop over the active region by using `org-loop-over-headlines-in-active-region'.
This commit is contained in:
parent
371b0cf9aa
commit
361261b048
|
@ -190,10 +190,17 @@ If the cursor is not at a headline when this command is called, try all level
|
|||
1 trees. If the cursor is on a headline, only try the direct children of
|
||||
this heading."
|
||||
(interactive "P")
|
||||
(if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
|
||||
(let (org-loop-over-headlines-in-active-region)
|
||||
(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
|
||||
'region
|
||||
(if (outline-invisible-p) (org-end-of-subtree nil t))))
|
||||
(if find-done
|
||||
(org-archive-all-done)
|
||||
;; Save all relevant TODO keyword-relatex variables
|
||||
|
||||
(let ((tr-org-todo-line-regexp org-todo-line-regexp) ; keep despite compiler
|
||||
(tr-org-todo-keywords-1 org-todo-keywords-1)
|
||||
(tr-org-todo-kwd-alist org-todo-kwd-alist)
|
||||
|
@ -341,7 +348,7 @@ this heading."
|
|||
(concat "in file: " (abbreviate-file-name afile))))))
|
||||
(org-reveal)
|
||||
(if (looking-at "^[ \t]*$")
|
||||
(outline-next-visible-heading 1)))
|
||||
(outline-next-visible-heading 1))))
|
||||
|
||||
(defun org-archive-to-archive-sibling ()
|
||||
"Archive the current heading by moving it under the archive sibling.
|
||||
|
@ -349,6 +356,19 @@ 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
|
||||
sibling does not exist, it will be created at the end of the subtree."
|
||||
(interactive)
|
||||
(if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
|
||||
(let (org-loop-over-headlines-in-active-region)
|
||||
(org-map-entries
|
||||
'(progn (setq org-map-continue-from
|
||||
(progn (org-back-to-heading)
|
||||
(if (looking-at (concat "^.*:" org-archive-tag ":.*$"))
|
||||
(org-end-of-subtree t)
|
||||
(point))))
|
||||
(when (org-at-heading-p)
|
||||
(org-archive-to-archive-sibling)))
|
||||
org-loop-over-headlines-in-active-region
|
||||
'region
|
||||
(if (outline-invisible-p) (org-end-of-subtree nil t))))
|
||||
(save-restriction
|
||||
(widen)
|
||||
(let (b e pos leader level)
|
||||
|
@ -397,7 +417,7 @@ sibling does not exist, it will be created at the end of the subtree."
|
|||
(goto-char pos)))
|
||||
(org-reveal)
|
||||
(if (looking-at "^[ \t]*$")
|
||||
(outline-next-visible-heading 1)))
|
||||
(outline-next-visible-heading 1))))
|
||||
|
||||
(defun org-archive-all-done (&optional tag)
|
||||
"Archive sublevels of the current tree without open TODO items.
|
||||
|
@ -448,6 +468,13 @@ When TAG is non-nil, don't move trees, but mark them with the ARCHIVE tag."
|
|||
With prefix ARG, check all children of current headline and offer tagging
|
||||
the children that do not contain any open TODO items."
|
||||
(interactive "P")
|
||||
(if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
|
||||
(let (org-loop-over-headlines-in-active-region)
|
||||
(org-map-entries
|
||||
`(org-toggle-archive-tag ,find-done)
|
||||
org-loop-over-headlines-in-active-region
|
||||
'region
|
||||
(if (outline-invisible-p) (org-end-of-subtree nil t))))
|
||||
(if find-done
|
||||
(org-archive-all-done 'tag)
|
||||
(let (set)
|
||||
|
@ -456,12 +483,19 @@ the children that do not contain any open TODO items."
|
|||
(setq set (org-toggle-tag org-archive-tag))
|
||||
(when set (hide-subtree)))
|
||||
(and set (beginning-of-line 1))
|
||||
(message "Subtree %s" (if set "archived" "unarchived")))))
|
||||
(message "Subtree %s" (if set "archived" "unarchived"))))))
|
||||
|
||||
(defun org-archive-set-tag ()
|
||||
"Set the ARCHIVE tag."
|
||||
(interactive)
|
||||
(org-toggle-tag org-archive-tag 'on))
|
||||
(if (and (org-region-active-p) org-loop-over-headlines-in-active-region)
|
||||
(let (org-loop-over-headlines-in-active-region)
|
||||
(org-map-entries
|
||||
'org-archive-set-tag
|
||||
org-loop-over-headlines-in-active-region
|
||||
'region
|
||||
(if (outline-invisible-p) (org-end-of-subtree nil t))))
|
||||
(org-toggle-tag org-archive-tag 'on)))
|
||||
|
||||
;;;###autoload
|
||||
(defun org-archive-subtree-default ()
|
||||
|
|
Loading…
Reference in New Issue