From: Stephen Berman Date: Mon, 13 May 2013 09:42:25 +0000 (+0200) Subject: * todos.el: Fixes for item marking and marked items. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~2058 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=74e14031486a5b116bcf2cd821e842b54f0f959d;p=emacs.git * todos.el: Fixes for item marking and marked items. (todos-toggle-mark-item): Make no-op if point is not on an item. Toggle mark even if point is not at start of item. (todos-item-done): Signal an error if a done item is marked. Process marked todo items even if point is in done items section. --- diff --git a/lisp/calendar/ChangeLog b/lisp/calendar/ChangeLog index fcdcf20151d..19f515781b7 100644 --- a/lisp/calendar/ChangeLog +++ b/lisp/calendar/ChangeLog @@ -1,3 +1,11 @@ +2013-05-13 Stephen Berman + + * todos.el: Fixes for item marking and marked items. + (todos-toggle-mark-item): Make no-op if point is not on an item. + Toggle mark even if point is not at start of item. + (todos-item-done): Signal an error if a done item is marked. + Process marked todo items even if point is in done items section. + 2013-05-11 Stephen Berman * todos.el (todos-item-undone): Remove item highlighting when user diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el index aff12e62158..f951123bc2b 100644 --- a/lisp/calendar/todos.el +++ b/lisp/calendar/todos.el @@ -3906,24 +3906,28 @@ face." With a positive numerical prefix argument N, change the marking of the next N items." (interactive "p") - (unless (> n 1) (setq n 1)) - (dotimes (i n) - (let* ((cat (todos-current-category)) - (marks (assoc cat todos-categories-with-marks)) - (ov (todos-get-overlay 'prefix)) - (pref (overlay-get ov 'before-string))) - (if (todos-marked-item-p) - (progn - (overlay-put ov 'before-string (substring pref 1)) - (if (= (cdr marks) 1) ; Deleted last mark in this category. - (setq todos-categories-with-marks - (assq-delete-all cat todos-categories-with-marks)) - (setcdr marks (1- (cdr marks))))) - (overlay-put ov 'before-string (concat todos-item-mark pref)) - (if marks - (setcdr marks (1+ (cdr marks))) - (push (cons cat 1) todos-categories-with-marks)))) - (todos-forward-item))) + (when (todos-item-string) + (unless (> n 1) (setq n 1)) + (dotimes (i n) + (let* ((cat (todos-current-category)) + (marks (assoc cat todos-categories-with-marks)) + (ov (progn + (unless (looking-at todos-item-start) + (todos-item-start)) + (todos-get-overlay 'prefix))) + (pref (overlay-get ov 'before-string))) + (if (todos-marked-item-p) + (progn + (overlay-put ov 'before-string (substring pref 1)) + (if (= (cdr marks) 1) ; Deleted last mark in this category. + (setq todos-categories-with-marks + (assq-delete-all cat todos-categories-with-marks)) + (setcdr marks (1- (cdr marks))))) + (overlay-put ov 'before-string (concat todos-item-mark pref)) + (if marks + (setcdr marks (1+ (cdr marks))) + (push (cons cat 1) todos-categories-with-marks)))) + (todos-forward-item)))) (defun todos-mark-category () "Mark all visiblw items in this category with `todos-item-mark'." @@ -5661,9 +5665,25 @@ visible." (interactive "P") (let* ((cat (todos-current-category)) (marked (assoc cat todos-categories-with-marks))) - (unless (or (todos-done-item-p) - ;; Point is between todo and done items. - (and (looking-at "^$") (not marked))) + (when marked + (save-excursion + (save-restriction + (goto-char (point-max)) + (todos-backward-item) + (unless (todos-done-item-p) + (widen) + (unless (re-search-forward + (concat "^" (regexp-quote todos-category-beg)) nil t) + (goto-char (point-max))) + (forward-line -1)) + (while (todos-done-item-p) + (when (todos-marked-item-p) + (user-error "This command does not apply to done items")) + (todos-backward-item))))) + (unless (and (not marked) + (or (todos-done-item-p) + ;; Point is between todo and done items. + (looking-at "^$"))) (let* ((date-string (calendar-date-string (calendar-current-date) t t)) (time-string (if todos-always-add-time-string (concat " " (substring (current-time-string) 11 16)) @@ -5685,7 +5705,7 @@ visible." (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 "^$")) ;(not (eobp)) + (while (not (looking-at "^$")) (if (or (not marked) (and marked (todos-marked-item-p))) (progn (setq item (todos-item-string))