diff options
| -rw-r--r-- | lisp/ChangeLog | 23 | ||||
| -rw-r--r-- | lisp/calendar/todos.el | 300 |
2 files changed, 203 insertions, 120 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 900b38b9d6b..95e932acded 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,26 @@ | |||
| 1 | 2013-02-04 Stephen Berman <stephen.berman@gmx.net> | ||
| 2 | |||
| 3 | * calendar/todos.el: Bug fixes involving or displaying done items. | ||
| 4 | (todos-done-separator): Make length of long separator one less | ||
| 5 | than window-width, in order to avoid following empty line. | ||
| 6 | (todos-forward-item, todos-backward-item): Make empty line below | ||
| 7 | last todo item accessible only by invoking without a numerical | ||
| 8 | prefix argument and make the latter invocations move only to items. | ||
| 9 | (todos-insert-item): Set todos-current-todos-file after selecting | ||
| 10 | buffer, in order not to set global value. If only done items are | ||
| 11 | shown when this command is invoked, toggle to show todo items to | ||
| 12 | avoid insertion into done items section. When done items are | ||
| 13 | shown, protect from cancelling before setting item priority: this | ||
| 14 | also needs recentering to display all items. | ||
| 15 | (todos-set-item-priority): Only call on (not done) todo items. | ||
| 16 | Check that done items are visible not because file is widened. | ||
| 17 | Use only `any' argument of called-interactively-p. Make sure that | ||
| 18 | giving an undone item lowest priority restores it to the todo | ||
| 19 | section. | ||
| 20 | (todos-item-done): If done items are visible on invoking this | ||
| 21 | command, keep them visible afterwards. Stop looking for marked | ||
| 22 | items on reaching the empty line below the last todo item. | ||
| 23 | |||
| 1 | 2013-02-02 Stephen Berman <stephen.berman@gmx.net> | 24 | 2013-02-02 Stephen Berman <stephen.berman@gmx.net> |
| 2 | 25 | ||
| 3 | * calendar/todos.el: Several small fixes and improvements. | 26 | * calendar/todos.el: Several small fixes and improvements. |
diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el index 1e8f10b0552..ce7fa961b48 100644 --- a/lisp/calendar/todos.el +++ b/lisp/calendar/todos.el | |||
| @@ -1150,7 +1150,11 @@ number as its value." | |||
| 1150 | "Return string used as value of variable `todos-done-separator'." | 1150 | "Return string used as value of variable `todos-done-separator'." |
| 1151 | (let ((sep todos-done-separator-string)) | 1151 | (let ((sep todos-done-separator-string)) |
| 1152 | (propertize (if (= 1 (length sep)) | 1152 | (propertize (if (= 1 (length sep)) |
| 1153 | (make-string (window-width) (string-to-char sep)) | 1153 | ;; If separator's length is window-width, an |
| 1154 | ;; indented empty line appears between the | ||
| 1155 | ;; separator and the first done item. | ||
| 1156 | ;; FIXME: should this be customizable? | ||
| 1157 | (make-string (1- (window-width)) (string-to-char sep)) | ||
| 1154 | todos-done-separator-string) | 1158 | todos-done-separator-string) |
| 1155 | 'face 'todos-done-sep))) | 1159 | 'face 'todos-done-sep))) |
| 1156 | 1160 | ||
| @@ -1522,6 +1526,14 @@ The final element is \"*\", indicating an unspecified month.") | |||
| 1522 | (todos-item-start) | 1526 | (todos-item-start) |
| 1523 | (looking-at todos-done-string-start))) | 1527 | (looking-at todos-done-string-start))) |
| 1524 | 1528 | ||
| 1529 | ;; (defun todos-done-item-section-p () | ||
| 1530 | ;; "Return non-nil if point is in category's done items section." | ||
| 1531 | ;; (save-excursion | ||
| 1532 | ;; (or (re-search-backward (concat "^" (regexp-quote todos-category-done)) | ||
| 1533 | ;; nil t) | ||
| 1534 | ;; (progn (goto-char (point-min)) | ||
| 1535 | ;; (looking-at todos-done-string-start))))) | ||
| 1536 | |||
| 1525 | (defun todos-prefix-overlay () | 1537 | (defun todos-prefix-overlay () |
| 1526 | "Return this item's prefix overlay." | 1538 | "Return this item's prefix overlay." |
| 1527 | (let* ((lbp (line-beginning-position)) | 1539 | (let* ((lbp (line-beginning-position)) |
| @@ -3522,7 +3534,17 @@ CAT; this is used in Todos Categories mode." | |||
| 3522 | (defun todos-forward-item (&optional count) | 3534 | (defun todos-forward-item (&optional count) |
| 3523 | "Move point down to start of item with next lower priority. | 3535 | "Move point down to start of item with next lower priority. |
| 3524 | With positive numerical prefix COUNT, move point COUNT items | 3536 | With positive numerical prefix COUNT, move point COUNT items |
| 3525 | downward." | 3537 | downward. |
| 3538 | |||
| 3539 | If the category's done items are hidden, this command also moves | ||
| 3540 | point to the empty line below the last todo item from any higher | ||
| 3541 | item in the category, i.e., when invoked with or without a prefix | ||
| 3542 | argument. If the category's done items are visible, this command | ||
| 3543 | called with a prefix argument only moves point to a lower item, | ||
| 3544 | e.g., with point on the last todo item and called with prefix 1, | ||
| 3545 | it moves point to the first done item; but if called with point | ||
| 3546 | on the last todo item without a prefix argument, it moves point | ||
| 3547 | the the empty line above the done items separator." | ||
| 3526 | (interactive "P") | 3548 | (interactive "P") |
| 3527 | ;; It's not worth the trouble to allow prefix arg value < 1, since we have | 3549 | ;; It's not worth the trouble to allow prefix arg value < 1, since we have |
| 3528 | ;; the corresponding command. | 3550 | ;; the corresponding command. |
| @@ -3538,9 +3560,9 @@ downward." | |||
| 3538 | ;; space above todos-done-separator, since that is a legitimate place to | 3560 | ;; space above todos-done-separator, since that is a legitimate place to |
| 3539 | ;; insert an item. But skip this space if count > 1, since that should | 3561 | ;; insert an item. But skip this space if count > 1, since that should |
| 3540 | ;; only stop on an item. | 3562 | ;; only stop on an item. |
| 3541 | (when (and not-done (todos-done-item-p)) | 3563 | (when (and not-done (todos-done-item-p) (not count)) |
| 3542 | (if (or (not count) (= count 1)) | 3564 | ;; (if (or (not count) (= count 1)) |
| 3543 | (re-search-backward "^$" start t)))))) | 3565 | (re-search-backward "^$" start t)))));) |
| 3544 | ;; FIXME: The preceding sexp is insufficient when buffer is not narrowed, | 3566 | ;; FIXME: The preceding sexp is insufficient when buffer is not narrowed, |
| 3545 | ;; since there could be no done items in this category, so the search puts | 3567 | ;; since there could be no done items in this category, so the search puts |
| 3546 | ;; us on first todo item of next category. Does this ever happen? If so: | 3568 | ;; us on first todo item of next category. Does this ever happen? If so: |
| @@ -3557,7 +3579,14 @@ downward." | |||
| 3557 | (defun todos-backward-item (&optional count) | 3579 | (defun todos-backward-item (&optional count) |
| 3558 | "Move point up to start of item with next higher priority. | 3580 | "Move point up to start of item with next higher priority. |
| 3559 | With positive numerical prefix COUNT, move point COUNT items | 3581 | With positive numerical prefix COUNT, move point COUNT items |
| 3560 | upward." | 3582 | upward. |
| 3583 | |||
| 3584 | If the category's done items are visible, this command called | ||
| 3585 | with a prefix argument only moves point to a higher item, e.g., | ||
| 3586 | with point on the first done item and called with prefix 1, it | ||
| 3587 | moves to the last todo item; but if called with point on the | ||
| 3588 | first done item without a prefix argument, it moves point the the | ||
| 3589 | empty line above the done items separator." | ||
| 3561 | (interactive "P") | 3590 | (interactive "P") |
| 3562 | ;; Avoid moving to bob if on the first item but not at bob. | 3591 | ;; Avoid moving to bob if on the first item but not at bob. |
| 3563 | (when (> (line-number-at-pos) 1) | 3592 | (when (> (line-number-at-pos) 1) |
| @@ -3575,7 +3604,8 @@ upward." | |||
| 3575 | ;; todos-done-separator, since that is a legitimate place to insert an | 3604 | ;; todos-done-separator, since that is a legitimate place to insert an |
| 3576 | ;; item. But skip this space if count > 1, since that should only | 3605 | ;; item. But skip this space if count > 1, since that should only |
| 3577 | ;; stop on an item. | 3606 | ;; stop on an item. |
| 3578 | (when (and done (not (todos-done-item-p)) (or (not count) (= count 1)) | 3607 | (when (and done (not (todos-done-item-p)) (not count) |
| 3608 | ;(or (not count) (= count 1)) | ||
| 3579 | (not (equal (buffer-name) todos-regexp-items-buffer))) | 3609 | (not (equal (buffer-name) todos-regexp-items-buffer))) |
| 3580 | (re-search-forward (concat "^" (regexp-quote todos-category-done)) | 3610 | (re-search-forward (concat "^" (regexp-quote todos-category-done)) |
| 3581 | nil t) | 3611 | nil t) |
| @@ -4550,12 +4580,17 @@ the priority is not given by HERE but by prompting." | |||
| 4550 | (substring (current-time-string) 11 16))))) | 4580 | (substring (current-time-string) 11 16))))) |
| 4551 | (setq todos-date-from-calendar nil) | 4581 | (setq todos-date-from-calendar nil) |
| 4552 | (find-file-noselect file 'nowarn) | 4582 | (find-file-noselect file 'nowarn) |
| 4553 | (setq todos-current-todos-file file) | ||
| 4554 | (set-window-buffer (selected-window) | 4583 | (set-window-buffer (selected-window) |
| 4555 | ;; If current category was nil till now, on | 4584 | ;; If current category was nil till now, on |
| 4556 | ;; entering Todos mode here it will be set to | 4585 | ;; entering Todos mode here it will be set to |
| 4557 | ;; file's first category. | 4586 | ;; file's first category. |
| 4558 | (set-buffer (find-buffer-visiting file))) | 4587 | (set-buffer (find-buffer-visiting file))) |
| 4588 | (setq todos-current-todos-file file) | ||
| 4589 | ;; If only done items are displayed in category, toggle to | ||
| 4590 | ;; todo items. | ||
| 4591 | (when (and (goto-char (point-min)) | ||
| 4592 | (looking-at todos-done-string-start)) | ||
| 4593 | (todos-show-done-only)) | ||
| 4559 | (unless todos-global-current-todos-file | 4594 | (unless todos-global-current-todos-file |
| 4560 | (setq todos-global-current-todos-file todos-current-todos-file)) | 4595 | (setq todos-global-current-todos-file todos-current-todos-file)) |
| 4561 | ;; These are not needed here, since they are called in | 4596 | ;; These are not needed here, since they are called in |
| @@ -4595,10 +4630,17 @@ the priority is not given by HERE but by prompting." | |||
| 4595 | ;; (todos-insert-with-overlays new-item) | 4630 | ;; (todos-insert-with-overlays new-item) |
| 4596 | ;; ) | 4631 | ;; ) |
| 4597 | ;; (todos-set-item-priority new-item (todos-current-category) t)) | 4632 | ;; (todos-set-item-priority new-item (todos-current-category) t)) |
| 4598 | (todos-set-item-priority new-item cat t) | 4633 | (unwind-protect |
| 4599 | ;; If item is inserted at end of category, make sure the | 4634 | (todos-set-item-priority new-item cat t) |
| 4600 | ;; items above it are displayed in the window. | 4635 | ;; In (at least) two circumstances, point may be at eob |
| 4601 | (recenter)) | 4636 | ;; and eob at window-start, so that that the todo items |
| 4637 | ;; are out of view: (i) if item is inserted at end of | ||
| 4638 | ;; category, (ii) if only done items are shown, this is | ||
| 4639 | ;; (above) programmatically toggled to show todo items, | ||
| 4640 | ;; and user cancels before setting new item's | ||
| 4641 | ;; priority. To make sure the todo items are displayed | ||
| 4642 | ;; in the window, force recentering. | ||
| 4643 | (recenter))) | ||
| 4602 | (todos-update-count 'todo 1) | 4644 | (todos-update-count 'todo 1) |
| 4603 | (if (or diary todos-include-in-diary) (todos-update-count 'diary 1)) | 4645 | (if (or diary todos-include-in-diary) (todos-update-count 'diary 1)) |
| 4604 | (todos-update-categories-sexp)))))) | 4646 | (todos-update-categories-sexp)))))) |
| @@ -5152,115 +5194,125 @@ items in this category." | |||
| 5152 | (defun todos-set-item-priority (&optional item cat new arg) | 5194 | (defun todos-set-item-priority (&optional item cat new arg) |
| 5153 | "Prompt for and set ITEM's priority in CATegory. | 5195 | "Prompt for and set ITEM's priority in CATegory. |
| 5154 | 5196 | ||
| 5155 | Interactively, ITEM defaults to the item at point, CAT to the | 5197 | Interactively, ITEM is the todo item at point, CAT is the current |
| 5156 | current category in Todos mode, and the priority is a number | 5198 | category, and the priority is a number between 1 and the number |
| 5157 | between 1 and the number of items in the category. | 5199 | of items in the category. Non-interactively, non-nil NEW means |
| 5158 | Non-interactively, non-nil NEW means ITEM is a new item and the | 5200 | ITEM is a new item and the lowest priority is one more than the |
| 5159 | lowest priority is one more than the number of items in CAT. | 5201 | number of items in CAT. |
| 5160 | 5202 | ||
| 5161 | The new priority is set either interactively by prompt or by a | 5203 | The new priority is set either interactively by prompt or by a |
| 5162 | numerical prefix argument, or noninteractively by argument ARG, | 5204 | numerical prefix argument, or noninteractively by argument ARG, |
| 5163 | whose value can be either of the symbols `raise' or `lower', | 5205 | whose value can be either of the symbols `raise' or `lower', |
| 5164 | meaning to raise or lower the item's priority by one." | 5206 | meaning to raise or lower the item's priority by one." |
| 5165 | (interactive) ; Prefix arg? | 5207 | (interactive) ;FIXME: Prefix arg? |
| 5166 | (let* ((item (or item (todos-item-string))) | 5208 | (unless (and (called-interactively-p 'any) |
| 5167 | (marked (todos-marked-item-p)) | 5209 | (or (todos-done-item-p) (looking-at "^$"))) |
| 5168 | (cat (or cat (cond ((eq major-mode 'todos-mode) | 5210 | (let* ((item (or item (todos-item-string))) |
| 5169 | (todos-current-category)) | 5211 | (marked (todos-marked-item-p)) |
| 5170 | ((eq major-mode 'todos-filtered-items-mode) | 5212 | (cat (or cat (cond ((eq major-mode 'todos-mode) |
| 5171 | (let* ((regexp1 | 5213 | (todos-current-category)) |
| 5172 | (concat todos-date-string-start | 5214 | ((eq major-mode 'todos-filtered-items-mode) |
| 5173 | todos-date-pattern | 5215 | (let* ((regexp1 |
| 5174 | "\\( " diary-time-regexp "\\)?" | 5216 | (concat todos-date-string-start |
| 5175 | (regexp-quote todos-nondiary-end) | 5217 | todos-date-pattern |
| 5176 | "?\\(?1: \\[\\(.+:\\)?.+\\]\\)"))) | 5218 | "\\( " diary-time-regexp "\\)?" |
| 5177 | (save-excursion | 5219 | (regexp-quote todos-nondiary-end) |
| 5178 | (re-search-forward regexp1 nil t) | 5220 | "?\\(?1: \\[\\(.+:\\)?.+\\]\\)"))) |
| 5179 | (match-string-no-properties 1))))))) | 5221 | (save-excursion |
| 5180 | curnum | 5222 | (re-search-forward regexp1 nil t) |
| 5181 | (todo (cond ((or (eq arg 'raise) (eq arg 'lower) | 5223 | (match-string-no-properties 1))))))) |
| 5182 | (eq major-mode 'todos-filtered-items-mode)) | 5224 | curnum |
| 5183 | (save-excursion | 5225 | (todo (cond ((or (eq arg 'raise) (eq arg 'lower) |
| 5184 | (let ((curstart (todos-item-start)) | 5226 | (eq major-mode 'todos-filtered-items-mode)) |
| 5185 | (count 0)) | 5227 | (save-excursion |
| 5186 | (goto-char (point-min)) | 5228 | (let ((curstart (todos-item-start)) |
| 5187 | (while (looking-at todos-item-start) | 5229 | (count 0)) |
| 5188 | (setq count (1+ count)) | 5230 | (goto-char (point-min)) |
| 5189 | (when (= (point) curstart) (setq curnum count)) | 5231 | (while (looking-at todos-item-start) |
| 5190 | (todos-forward-item)) | 5232 | (setq count (1+ count)) |
| 5191 | count))) | 5233 | (when (= (point) curstart) (setq curnum count)) |
| 5192 | ((eq major-mode 'todos-mode) | 5234 | (todos-forward-item)) |
| 5193 | (todos-get-count 'todo cat)))) | 5235 | count))) |
| 5194 | (maxnum (if new (1+ todo) todo)) | 5236 | ((eq major-mode 'todos-mode) |
| 5195 | (prompt (format "Set item priority (1-%d): " maxnum)) | 5237 | (todos-get-count 'todo cat)))) |
| 5196 | (priority (cond ((numberp current-prefix-arg) | 5238 | (maxnum (if new (1+ todo) todo)) |
| 5197 | current-prefix-arg) | 5239 | (prompt (format "Set item priority (1-%d): " maxnum)) |
| 5198 | ((and (eq arg 'raise) (>= curnum 1)) | 5240 | (priority (cond ((numberp current-prefix-arg) |
| 5199 | (1- curnum)) | 5241 | current-prefix-arg) |
| 5200 | ((and (eq arg 'lower) (<= curnum maxnum)) | 5242 | ((and (eq arg 'raise) (>= curnum 1)) |
| 5201 | (1+ curnum)))) | 5243 | (1- curnum)) |
| 5202 | candidate | 5244 | ((and (eq arg 'lower) (<= curnum maxnum)) |
| 5203 | buffer-read-only) | 5245 | (1+ curnum)))) |
| 5204 | (unless (and priority | 5246 | candidate |
| 5205 | (or (and (eq arg 'raise) (zerop priority)) | 5247 | buffer-read-only) |
| 5206 | (and (eq arg 'lower) (> priority maxnum)))) | 5248 | (unless (and priority |
| 5207 | ;; When moving item to another category, show the category before | 5249 | (or (and (eq arg 'raise) (zerop priority)) |
| 5208 | ;; prompting for its priority. | 5250 | (and (eq arg 'lower) (> priority maxnum)))) |
| 5209 | (unless (or arg (called-interactively-p t)) | 5251 | ;; When moving item to another category, show the category before |
| 5210 | (todos-category-number cat) | 5252 | ;; prompting for its priority. |
| 5211 | ;; If done items in category are visible, keep them visible. | 5253 | (unless (or arg (called-interactively-p 'any)) |
| 5212 | (let (done) | 5254 | (todos-category-number cat) |
| 5213 | (save-excursion | 5255 | ;; If done items in category are visible, keep them visible. |
| 5214 | (goto-char (point-min)) | 5256 | (let ((done todos-show-with-done)) |
| 5215 | (setq done (re-search-forward todos-done-string-start nil t))) | 5257 | (when (> (buffer-size) (- (point-max) (point-min))) |
| 5216 | (let ((todos-show-with-done done)) | 5258 | (save-excursion |
| 5217 | (todos-category-select)))) | 5259 | (goto-char (point-min)) |
| 5218 | ;; Prompt for priority only when the category has at least one todo item. | 5260 | (setq done (re-search-forward todos-done-string-start nil t)))) |
| 5219 | (when (> maxnum 1) | 5261 | (let ((todos-show-with-done done)) |
| 5220 | (while (not priority) | 5262 | (todos-category-select))))) |
| 5221 | (setq candidate (read-number prompt)) | 5263 | ;; Prompt for priority only when the category has at least one todo item. |
| 5222 | (setq prompt (when (or (< candidate 1) (> candidate maxnum)) | 5264 | (when (> maxnum 1) |
| 5223 | (format "Priority must be an integer between 1 and %d.\n" | 5265 | (while (not priority) |
| 5224 | maxnum))) | 5266 | (setq candidate (read-number prompt)) |
| 5225 | (unless prompt (setq priority candidate)))) | 5267 | (setq prompt (when (or (< candidate 1) (> candidate maxnum)) |
| 5226 | ;; In Top Priorities buffer, an item's priority can be changed | 5268 | (format "Priority must be an integer between 1 and %d.\n" |
| 5227 | ;; wrt items in another category, but not wrt items in the same | 5269 | maxnum))) |
| 5228 | ;; category. | 5270 | (unless prompt (setq priority candidate)))) |
| 5229 | (when (eq major-mode 'todos-filtered-items-mode) | 5271 | ;; In Top Priorities buffer, an item's priority can be changed |
| 5230 | (let* ((regexp2 (concat todos-date-string-start todos-date-pattern | 5272 | ;; wrt items in another category, but not wrt items in the same |
| 5231 | "\\( " diary-time-regexp "\\)?" | 5273 | ;; category. |
| 5232 | (regexp-quote todos-nondiary-end) | 5274 | (when (eq major-mode 'todos-filtered-items-mode) |
| 5233 | "?\\(?1:" (regexp-quote cat) "\\)")) | 5275 | (let* ((regexp2 (concat todos-date-string-start todos-date-pattern |
| 5234 | (end (cond ((< curnum priority) | 5276 | "\\( " diary-time-regexp "\\)?" |
| 5235 | (save-excursion (todos-item-end))) | 5277 | (regexp-quote todos-nondiary-end) |
| 5236 | ((> curnum priority) | 5278 | "?\\(?1:" (regexp-quote cat) "\\)")) |
| 5237 | (save-excursion (todos-item-start))))) | 5279 | (end (cond ((< curnum priority) |
| 5238 | (match (save-excursion | 5280 | (save-excursion (todos-item-end))) |
| 5239 | (cond ((< curnum priority) | 5281 | ((> curnum priority) |
| 5240 | (todos-forward-item (1+ (- priority curnum))) | 5282 | (save-excursion (todos-item-start))))) |
| 5241 | (when (re-search-backward regexp2 end t) | 5283 | (match (save-excursion |
| 5242 | (match-string-no-properties 1))) | 5284 | (cond ((< curnum priority) |
| 5243 | ((> curnum priority) | 5285 | (todos-forward-item (1+ (- priority curnum))) |
| 5244 | (todos-backward-item (- curnum priority)) | 5286 | (when (re-search-backward regexp2 end t) |
| 5245 | (when (re-search-forward regexp2 end t) | 5287 | (match-string-no-properties 1))) |
| 5246 | (match-string-no-properties 1))))))) | 5288 | ((> curnum priority) |
| 5247 | (when match | 5289 | (todos-backward-item (- curnum priority)) |
| 5248 | (error (concat "Cannot reprioritize items from the same " | 5290 | (when (re-search-forward regexp2 end t) |
| 5249 | "category in this mode, only in Todos mode"))))) | 5291 | (match-string-no-properties 1))))))) |
| 5250 | ;; Interactively or with non-nil ARG, relocate the item within its | 5292 | (when match |
| 5251 | ;; category. | 5293 | (error (concat "Cannot reprioritize items from the same " |
| 5252 | (when (or arg (called-interactively-p)) | 5294 | "category in this mode, only in Todos mode"))))) |
| 5253 | (todos-remove-item)) | 5295 | ;; Interactively or with non-nil ARG, relocate the item within its |
| 5254 | (goto-char (point-min)) | 5296 | ;; category. |
| 5255 | (when priority | 5297 | (when (or arg (called-interactively-p 'any)) |
| 5256 | (unless (= priority 1) | 5298 | (todos-remove-item)) |
| 5257 | (todos-forward-item (1- priority)))) | 5299 | (goto-char (point-min)) |
| 5258 | (todos-insert-with-overlays item) | 5300 | (when priority |
| 5259 | ;; If item was marked, restore the mark. | 5301 | (unless (= priority 1) |
| 5260 | (and marked | 5302 | (todos-forward-item (1- priority)) |
| 5261 | (let* ((ov (todos-prefix-overlay)) | 5303 | ;; When called from todos-item-undo and the highest priority |
| 5262 | (pref (overlay-get ov 'before-string))) | 5304 | ;; is chosen, this advances point to the first done item, so |
| 5263 | (overlay-put ov 'before-string (concat todos-item-mark pref))))))) | 5305 | ;; move it up to the empty line above the done items |
| 5306 | ;; separator. | ||
| 5307 | (when (looking-back (concat "^" | ||
| 5308 | (regexp-quote todos-category-done) "\n")) | ||
| 5309 | (todos-backward-item)))) | ||
| 5310 | (todos-insert-with-overlays item) | ||
| 5311 | ;; If item was marked, restore the mark. | ||
| 5312 | (and marked | ||
| 5313 | (let* ((ov (todos-prefix-overlay)) | ||
| 5314 | (pref (overlay-get ov 'before-string))) | ||
| 5315 | (overlay-put ov 'before-string (concat todos-item-mark pref)))))))) | ||
| 5264 | 5316 | ||
| 5265 | (defun todos-raise-item-priority () | 5317 | (defun todos-raise-item-priority () |
| 5266 | "Raise priority of current item by moving it up by one item." | 5318 | "Raise priority of current item by moving it up by one item." |
| @@ -5427,7 +5479,7 @@ section in the category moved to." | |||
| 5427 | (goto-char omark)))))))) | 5479 | (goto-char omark)))))))) |
| 5428 | 5480 | ||
| 5429 | (defun todos-item-done (&optional arg) | 5481 | (defun todos-item-done (&optional arg) |
| 5430 | "Tag at least one item in this category as done and hide it. | 5482 | "Tag a todo item in this category as done and relocate it. |
| 5431 | 5483 | ||
| 5432 | With prefix argument ARG prompt for a comment and append it to | 5484 | With prefix argument ARG prompt for a comment and append it to |
| 5433 | the done item; this is only possible if there are no marked | 5485 | the done item; this is only possible if there are no marked |
| @@ -5435,7 +5487,9 @@ items. If there are marked items, tag all of these with | |||
| 5435 | `todos-done-string' plus the current date and, if | 5487 | `todos-done-string' plus the current date and, if |
| 5436 | `todos-always-add-time-string' is non-nil, the current time; | 5488 | `todos-always-add-time-string' is non-nil, the current time; |
| 5437 | otherwise, just tag the item at point. Items tagged as done are | 5489 | otherwise, just tag the item at point. Items tagged as done are |
| 5438 | relocated to the category's (by default hidden) done section." | 5490 | relocated to the category's (by default hidden) done section. If |
| 5491 | done items are visible on invoking this command, they remain | ||
| 5492 | visible." | ||
| 5439 | (interactive "P") | 5493 | (interactive "P") |
| 5440 | (let* ((cat (todos-current-category)) | 5494 | (let* ((cat (todos-current-category)) |
| 5441 | (marked (assoc cat todos-categories-with-marks))) | 5495 | (marked (assoc cat todos-categories-with-marks))) |
| @@ -5451,11 +5505,16 @@ relocated to the category's (by default hidden) done section." | |||
| 5451 | (comment (and arg (not marked) (read-string "Enter a comment: "))) | 5505 | (comment (and arg (not marked) (read-string "Enter a comment: "))) |
| 5452 | (item-count 0) | 5506 | (item-count 0) |
| 5453 | (diary-count 0) | 5507 | (diary-count 0) |
| 5508 | (show-done (save-excursion | ||
| 5509 | (goto-char (point-min)) | ||
| 5510 | (re-search-forward todos-done-string-start nil t))) | ||
| 5454 | item done-item | 5511 | item done-item |
| 5455 | (buffer-read-only)) | 5512 | (buffer-read-only)) |
| 5456 | (and marked (goto-char (point-min))) | 5513 | (and marked (goto-char (point-min))) |
| 5457 | (catch 'done | 5514 | (catch 'done |
| 5458 | (while (not (eobp)) | 5515 | ;; Stop looping when we hit the empty line below the last |
| 5516 | ;; todo item (this is eobp if only done items are hidden). | ||
| 5517 | (while (not (looking-at "^$")) ;(not (eobp)) | ||
| 5459 | (if (or (not marked) (and marked (todos-marked-item-p))) | 5518 | (if (or (not marked) (and marked (todos-marked-item-p))) |
| 5460 | (progn | 5519 | (progn |
| 5461 | (setq item (todos-item-string)) | 5520 | (setq item (todos-item-string)) |
| @@ -5488,7 +5547,8 @@ relocated to the category's (by default hidden) done section." | |||
| 5488 | (todos-update-count 'done item-count) | 5547 | (todos-update-count 'done item-count) |
| 5489 | (todos-update-count 'diary (- diary-count)) | 5548 | (todos-update-count 'diary (- diary-count)) |
| 5490 | (todos-update-categories-sexp) | 5549 | (todos-update-categories-sexp) |
| 5491 | (save-excursion (todos-category-select)))))) | 5550 | (let ((todos-show-with-done show-done)) |
| 5551 | (todos-category-select)))))) | ||
| 5492 | 5552 | ||
| 5493 | (defun todos-done-item-add-edit-or-delete-comment (&optional arg) | 5553 | (defun todos-done-item-add-edit-or-delete-comment (&optional arg) |
| 5494 | "Add a comment to this done item or edit an existing comment. | 5554 | "Add a comment to this done item or edit an existing comment. |