Function: todo-item-undone

todo-item-undone is an interactive and byte-compiled function defined in todo-mode.el.gz.

Signature

(todo-item-undone)

Documentation

Restore at least one done item to this category's todo section.

Prompt for the new priority. If there are marked items, undo all of these, giving the first undone item the new priority and the rest following directly in sequence; otherwise, undo just the item at point.

If the done item has a comment, ask whether to omit the comment from the restored item. With multiple marked done items with comments, only ask once, and if affirmed, omit subsequent comments without asking.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-item-undone ()
  "Restore at least one done item to this category's todo section.
Prompt for the new priority.  If there are marked items, undo all
of these, giving the first undone item the new priority and the
rest following directly in sequence; otherwise, undo just the
item at point.

If the done item has a comment, ask whether to omit the comment
from the restored item.  With multiple marked done items with
comments, only ask once, and if affirmed, omit subsequent
comments without asking."
  (interactive)
  (let* ((cat (todo-current-category))
	 (marked (assoc cat todo-categories-with-marks))
	 (num (if (not marked) 1 (cdr marked))))
    (when (or marked (todo-done-item-p))
      (let ((opoint (point))
	    (omark (point-marker))
	    (first 'first)
	    (item-count 0)
	    (diary-count 0)
            (omit-prompt (ngettext "Omit comment from restored item? "
                                   "Omit comments from restored items? "
                           num))
	    start end item ov npoint undone)
	(and marked (goto-char (point-min)))
	(catch 'done
	  (while (not (eobp))
	    (when (or (not marked) (and marked (todo-marked-item-p)))
	      (if (not (todo-done-item-p))
		  (progn
		    (goto-char opoint)
		    (user-error "Only done items can be undone"))
		(todo-item-start)
		(unless marked
		  (setq ov (make-overlay (save-excursion (todo-item-start))
					 (save-excursion (todo-item-end))))
		  (overlay-put ov 'face 'todo-search))
		;; Find the end of the date string added upon tagging item as
		;; done.
		(setq start (search-forward "] "))
		(setq item-count (1+ item-count))
		(unless (looking-at (regexp-quote todo-nondiary-start))
		  (setq diary-count (1+ diary-count)))
		(setq end (save-excursion (todo-item-end)))
		;; Ask (once) whether to omit done item's comment.  If
		;; affirmed, omit subsequent comments without asking.
		(when (re-search-forward
		       (concat " \\[" (regexp-quote todo-comment-string)
			       ": [^]]+\\]")
                       end t)
		  (unwind-protect
		      (if (eq first 'first)
			  (setq first
				(if (eq todo-undo-item-omit-comment 'ask)
				    (when (todo-y-or-n-p omit-prompt)
				      'omit)
				  (when todo-undo-item-omit-comment 'omit)))
			t)
		    (when (and (eq first 'first) ov) (delete-overlay ov)))
		  (when (eq first 'omit)
		    (setq end (match-beginning 0))))
		(setq item (concat item
				   (buffer-substring-no-properties start end)
				   (when marked "\n")))
		(unless marked (throw 'done nil))))
	    (todo-forward-item)))
	(unwind-protect
	    (progn
	      ;; Chop off last newline of multiple items string, since
	      ;; it will be reinserted on setting priority.
	      (and marked (setq item (substring item 0 -1)))
	      (todo-set-item-priority item cat t)
	      (setq npoint (point))
	      (setq undone t))
	  (when ov (delete-overlay ov))
	  (if (not undone)
	      (goto-char opoint)
	    (let ((inhibit-read-only t))
	      (if marked
		  (progn
		    (setq item nil)
		    (re-search-forward
		     (concat "^" (regexp-quote todo-category-done)) nil t)
		    (while (not (eobp))
		      (if (todo-marked-item-p)
			  (todo-remove-item)
			(todo-forward-item)))
		    (setq todo-categories-with-marks
			  (assq-delete-all cat todo-categories-with-marks)))
		(goto-char omark)
		(todo-remove-item)))
	    (todo-update-count 'todo item-count)
	    (todo-update-count 'done (- item-count))
	    (when diary-count (todo-update-count 'diary diary-count))
	    (todo-update-categories-sexp)
	    (let ((todo-show-with-done (> (todo-get-count 'done) 0)))
	      (todo-category-select))
	    ;; Put cursor on undone item.
	    (goto-char npoint)))
	(set-marker omark nil)))))