Function: todo-unarchive-items
todo-unarchive-items is an interactive and byte-compiled function
defined in todo-mode.el.gz.
Signature
(todo-unarchive-items)
Documentation
Unarchive at least one item in this archive category.
If there are marked items, unarchive all of these; otherwise, unarchive the item at point.
Unarchived items are restored as done items to the corresponding category in the todo file, inserted at the top of done items section. If all items in the archive category have been restored, the category is deleted from the archive. If this was the only category in the archive, the archive file is deleted.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-unarchive-items ()
"Unarchive at least one item in this archive category.
If there are marked items, unarchive all of these; otherwise,
unarchive the item at point.
Unarchived items are restored as done items to the corresponding
category in the todo file, inserted at the top of done items
section. If all items in the archive category have been
restored, the category is deleted from the archive. If this was
the only category in the archive, the archive file is deleted."
(interactive)
(when (eq major-mode 'todo-archive-mode)
(let* ((cat (todo-current-category))
(tbuf (find-file-noselect
(concat (file-name-sans-extension todo-current-todo-file)
".todo")
t))
(marked (assoc cat todo-categories-with-marks))
(item (concat (todo-item-string) "\n"))
(marked-count 0)
marked-items
(inhibit-read-only t))
(when marked
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(when (todo-marked-item-p)
(setq marked-items (concat marked-items (todo-item-string) "\n"))
(setq marked-count (1+ marked-count)))
(todo-forward-item))))
;; Restore items to top of category's done section and update counts.
(with-current-buffer tbuf
(let ((headers-hidden todo--item-headers-hidden)
(inhibit-read-only t) newcat)
(if headers-hidden (todo-toggle-item-header))
(widen)
(goto-char (point-min))
;; Find the corresponding todo category, or if there isn't
;; one, add it.
(unless (re-search-forward
(concat "^" (regexp-quote (concat todo-category-beg cat))
"$")
nil t)
(todo-add-category nil cat)
(setq newcat t))
;; Go to top of category's done section.
(re-search-forward
(concat "^" (regexp-quote todo-category-done)) nil t)
(forward-line)
(cond (marked
(insert marked-items)
(todo-update-count 'done marked-count cat)
(unless newcat ; Newly added category has no archive.
(todo-update-count 'archived (- marked-count) cat)))
(t
(insert item)
(todo-update-count 'done 1 cat)
(unless newcat ; Newly added category has no archive.
(todo-update-count 'archived -1 cat))))
(if headers-hidden (todo-toggle-item-header))
(todo-update-categories-sexp)))
;; Delete restored items from archive.
(when marked
(setq item nil)
(goto-char (point-min)))
(catch 'done
(while (not (eobp))
(if (or (todo-marked-item-p) item)
(progn
(todo-remove-item)
(when item
(throw 'done (setq item nil))))
(todo-forward-item))))
(todo-update-count 'done (if marked (- marked-count) -1) cat)
;; If we unarchived the last item in category, then if that was
;; the only category, delete the whole file, otherwise, just
;; delete the category.
(when (= 0 (todo-get-count 'done))
(if (= 1 (length todo-categories))
(progn
(delete-file todo-current-todo-file)
;; Kill the archive buffer silently.
(set-buffer-modified-p nil)
(kill-buffer))
(widen)
(let ((beg (re-search-backward
(concat "^" (regexp-quote todo-category-beg) cat "$")
nil t))
(end (if (re-search-forward
(concat "^" (regexp-quote todo-category-beg))
nil t 2)
(match-beginning 0)
(point-max))))
(remove-overlays beg end)
(delete-region beg end)
(setq todo-categories (delete (assoc cat todo-categories)
todo-categories)))))
(todo-update-categories-sexp)
;; Visit category in todo file and show restored done items.
(let ((tfile (buffer-file-name tbuf))
(todo-show-with-done t))
(set-window-buffer (selected-window)
(set-buffer (find-file-noselect tfile)))
(todo-category-number cat)
(todo-category-select)
;; Selecting the category leaves point at the end of the done
;; items separator string, so move it to the (first) restored
;; done item.
(forward-line)
(message "Items unarchived.")))))