- (setq todos-categories-with-marks
- (assq-delete-all cat todos-categories-with-marks))
- ;; Insert undone items that were marked at end of todo item list.
- (goto-char (point-min))
- (re-search-forward (concat "^" (regexp-quote todos-category-done))
- nil t)
- (forward-line -1)
- (insert item)
- (todos-update-count 'todo item-count)
- (todos-update-count 'done (- item-count))
- (when diary-count (todos-update-count 'diary diary-count))
- (todos-update-categories-sexp)
- (let ((todos-show-with-done (> (todos-get-count 'done) 0)))
- (todos-category-select)))
- ;; With an unmarked undone item, prompt for its priority. If user
- ;; cancels before setting new priority, then leave the done item
- ;; unchanged.
- (unwind-protect
- (progn
- (todos-set-item-priority item (todos-current-category) t)
- (setq undone t
- opoint (point))
- (todos-update-count 'todo 1)
- (todos-update-count 'done -1)
- (and (todos-diary-item-p) (todos-update-count 'diary 1))
- (todos-update-categories-sexp)
- (let ((todos-show-with-done (> (todos-get-count 'done) 0)))
- (todos-category-select)
- ;; Put the cursor on the undone item.
- (goto-char opoint)))
- (unless undone
- (let ((todos-show-with-done t))
- (widen)
- (goto-char orig-mrk)
- (todos-insert-with-overlays orig-item)
- (set-buffer-modified-p bufmod)
- (todos-category-select))
- (goto-char opoint))))
- (set-marker orig-mrk nil)))))
+ ;; Chop off last newline of multiple items string, since
+ ;; it will be reinserted on setting priority.
+ (and marked (setq item (substring item 0 -1)))
+ (todos-set-item-priority item cat t)
+ (setq npoint (point))
+ (setq undone t))
+ (if ov (delete-overlay ov))
+ (if (not undone)
+ (goto-char opoint)
+ (if marked
+ (progn
+ (setq item nil)
+ (re-search-forward
+ (concat "^" (regexp-quote todos-category-done)) nil t)
+ (while (not (eobp))
+ (if (todos-marked-item-p)
+ (todos-remove-item)
+ (todos-forward-item)))
+ (setq todos-categories-with-marks
+ (assq-delete-all cat todos-categories-with-marks)))
+ (goto-char omark)
+ (todos-remove-item))
+ (todos-update-count 'todo item-count)
+ (todos-update-count 'done (- item-count))
+ (when diary-count (todos-update-count 'diary diary-count))
+ (todos-update-categories-sexp)
+ (let ((todos-show-with-done (> (todos-get-count 'done) 0)))
+ (todos-category-select))
+ ;; Put cursor on undone item.
+ (goto-char npoint)))
+ (set-marker omark nil)))))