Function: todo-item-done
todo-item-done is an interactive and byte-compiled function defined in
todo-mode.el.gz.
Signature
(todo-item-done &optional ARG)
Documentation
Tag a todo item in this category as done and relocate it.
With prefix argument ARG prompt for a comment and append it to
the done item; this is only possible if there are no marked
items. If there are marked items, tag all of these with
todo-done-string plus the current date and, if
todo-always-add-time-string is non-nil, the current time;
otherwise, just tag the item at point. Items tagged as done are
relocated to the category's (by default hidden) done section. If
done items are visible on invoking this command, they remain
visible.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-item-done (&optional arg)
"Tag a todo item in this category as done and relocate it.
With prefix argument ARG prompt for a comment and append it to
the done item; this is only possible if there are no marked
items. If there are marked items, tag all of these with
`todo-done-string' plus the current date and, if
`todo-always-add-time-string' is non-nil, the current time;
otherwise, just tag the item at point. Items tagged as done are
relocated to the category's (by default hidden) done section. If
done items are visible on invoking this command, they remain
visible."
(interactive "P")
(let* ((cat (todo-current-category))
(marked (assoc cat todo-categories-with-marks)))
(when marked (todo--user-error-if-marked-done-item))
(unless
;; Noop if point is not on a todo (i.e. not done) item and
;; there are no marked items.
(and (or (todo-done-item-p) (looking-at "^$")
;; On done items separator.
(save-excursion (beginning-of-line)
(looking-at todo-category-done)))
(not marked))
(let* ((date-string (calendar-date-string (calendar-current-date) t t))
(time-string (if todo-always-add-time-string
(format-time-string " %H:%M")
""))
(done-prefix (concat "[" todo-done-string date-string time-string
"] "))
(comment (and arg (read-string "Enter a comment: ")))
(item-count 0)
(diary-count 0)
(show-done (save-excursion
(goto-char (point-min))
(re-search-forward todo-done-string-start nil t)))
(inhibit-read-only t)
header item done-items
(opoint (point)))
;; Don't add empty comment to done item.
(setq comment (unless (zerop (length comment))
(concat " [" todo-comment-string ": " comment "]")))
(and marked (goto-char (point-min)))
(setq header (todo-get-overlay 'header))
(catch 'done
;; Stop looping when we hit the empty line below the last
;; todo item (this is eobp if only done items are hidden).
(while (not (looking-at "^$"))
(if (or (not marked) (and marked (todo-marked-item-p)))
(progn
(setq item (todo-item-string))
(push (concat done-prefix item comment) done-items)
(setq item-count (1+ item-count))
(when (todo-diary-item-p)
(setq diary-count (1+ diary-count)))
(todo-remove-item)
(unless marked (throw 'done nil)))
(todo-forward-item))))
(setq done-items (nreverse done-items))
(when marked
(setq todo-categories-with-marks
(assq-delete-all cat todo-categories-with-marks)))
(save-excursion
(widen)
(re-search-forward
(concat "^" (regexp-quote todo-category-done)) nil t)
(forward-char)
(when show-done (setq opoint (point)))
(while done-items
(insert (pop done-items) "\n")
(when header (let ((copy (copy-overlay header)))
(re-search-backward
(concat todo-item-start
"\\( " diary-time-regexp "\\)?"
(regexp-quote todo-nondiary-end) "? ")
nil t)
(move-overlay copy (match-beginning 0) (match-end 0)))
(todo-item-end)
(forward-char))))
(todo-update-count 'todo (- item-count))
(todo-update-count 'done item-count)
(todo-update-count 'diary (- diary-count))
(todo-update-categories-sexp)
(let ((todo-show-with-done show-done))
(todo-category-select)
;; When done items are visible, put point at the top of the
;; done items section. When done items are hidden, restore
;; point to its location prior to invoking this command.
(when opoint (goto-char opoint)))))))