diff options
| author | Stephen Berman | 2012-10-08 01:45:40 +0200 |
|---|---|---|
| committer | Stephen Berman | 2012-10-08 01:45:40 +0200 |
| commit | 57da062dfef7a780b82742e26cb797f8841b6745 (patch) | |
| tree | 928eac3558463b488dea974b5d2978f4c2b5280a | |
| parent | fd6c6328aefd206a2d81fd5a98fb6a8b90a4eeec (diff) | |
| download | emacs-57da062dfef7a780b82742e26cb797f8841b6745.tar.gz emacs-57da062dfef7a780b82742e26cb797f8841b6745.zip | |
* calendar/todos.el: Fixes to todos-move-item and some of its
subroutines.
(todos-move-item): When there are marked items, point need not be
on an item; remove obsolete use of todos-add-category, since this
is now already done in todos-read-category; fix typo.
(todos-diary-item-p): Exclude empty lines.
(todos-read-category): Restore point and narrowing after adding
new category, to avoid moving to beginning of file when moving
marked items to a new category.
(todos-set-item-priority): Prompt for priority only when the
category has at least one todo item; only use non-nil priority to
calculate insertion location.
(todos-read-category): Don't reset todos-categories when a new
category is added due to todos-move-item or todos-jump-to-item.
| -rw-r--r-- | lisp/ChangeLog | 17 | ||||
| -rw-r--r-- | lisp/calendar/todos.el | 227 |
2 files changed, 137 insertions, 107 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0c58a997c81..377b1883be6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,20 @@ | |||
| 1 | 2012-10-08 Stephen Berman <stephen.berman@gmx.net> | ||
| 2 | |||
| 3 | * calendar/todos.el: Fixes to todos-move-item and some of its | ||
| 4 | subroutines. | ||
| 5 | (todos-move-item): When there are marked items, point need not be | ||
| 6 | on an item; remove obsolete use of todos-add-category, since this | ||
| 7 | is now already done in todos-read-category; fix typo. | ||
| 8 | (todos-diary-item-p): Exclude empty lines. | ||
| 9 | (todos-read-category): Restore point and narrowing after adding | ||
| 10 | new category, to avoid moving to beginning of file when moving | ||
| 11 | marked items to a new category. | ||
| 12 | (todos-set-item-priority): Prompt for priority only when the | ||
| 13 | category has at least one todo item; only use non-nil priority to | ||
| 14 | calculate insertion location. | ||
| 15 | (todos-read-category): Don't reset todos-categories when a new | ||
| 16 | category is added due to todos-move-item or todos-jump-to-item. | ||
| 17 | |||
| 1 | 2012-09-24 Stephen Berman <stephen.berman@gmx.net> | 18 | 2012-09-24 Stephen Berman <stephen.berman@gmx.net> |
| 2 | 19 | ||
| 3 | * calendar/todos.el (todos-copy-item): New command. | 20 | * calendar/todos.el (todos-copy-item): New command. |
diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el index 5c07f620770..b6dff87348a 100644 --- a/lisp/calendar/todos.el +++ b/lisp/calendar/todos.el | |||
| @@ -1442,8 +1442,9 @@ it.") | |||
| 1442 | (defun todos-diary-item-p () | 1442 | (defun todos-diary-item-p () |
| 1443 | "Return non-nil if item at point has diary entry format." | 1443 | "Return non-nil if item at point has diary entry format." |
| 1444 | (save-excursion | 1444 | (save-excursion |
| 1445 | (todos-item-start) | 1445 | (when (todos-item-string) ; Exclude empty lines. |
| 1446 | (not (looking-at (regexp-quote todos-nondiary-start))))) | 1446 | (todos-item-start) |
| 1447 | (not (looking-at (regexp-quote todos-nondiary-start)))))) | ||
| 1447 | 1448 | ||
| 1448 | (defun todos-done-item-p () | 1449 | (defun todos-done-item-p () |
| 1449 | "Return non-nil if item at point is a done item." | 1450 | "Return non-nil if item at point is a done item." |
| @@ -1573,7 +1574,15 @@ ask whether to add the category." | |||
| 1573 | (unless added | 1574 | (unless added |
| 1574 | (if (y-or-n-p (format (concat "There is no category \"%s\" in " | 1575 | (if (y-or-n-p (format (concat "There is no category \"%s\" in " |
| 1575 | "this file; add it? ") cat)) | 1576 | "this file; add it? ") cat)) |
| 1576 | (todos-add-category cat) | 1577 | ;; Restore point and narrowing after adding new |
| 1578 | ;; category, to avoid moving to beginning of file when | ||
| 1579 | ;; moving marked items to a new category (todos-move-item). | ||
| 1580 | (save-excursion | ||
| 1581 | (save-restriction | ||
| 1582 | (todos-add-category cat) | ||
| 1583 | ;; We've changed todos-categories, so we must not | ||
| 1584 | ;; reset it below. | ||
| 1585 | (setq added t))) | ||
| 1577 | (keyboard-quit)))) | 1586 | (keyboard-quit)))) |
| 1578 | ;; Restore the original value of todos-categories unless a new category | 1587 | ;; Restore the original value of todos-categories unless a new category |
| 1579 | ;; was added (since todos-add-category changes todos-categories). | 1588 | ;; was added (since todos-add-category changes todos-categories). |
| @@ -4669,12 +4678,14 @@ meaning to raise or lower the item's priority by one." | |||
| 4669 | (unless (or arg (called-interactively-p t)) | 4678 | (unless (or arg (called-interactively-p t)) |
| 4670 | (todos-category-number cat) | 4679 | (todos-category-number cat) |
| 4671 | (todos-category-select)) | 4680 | (todos-category-select)) |
| 4672 | (while (not priority) | 4681 | ;; Prompt for priority only when the category has at least one todo item. |
| 4673 | (setq candidate (read-number prompt)) | 4682 | (when (> maxnum 1) |
| 4674 | (setq prompt (when (or (< candidate 1) (> candidate maxnum)) | 4683 | (while (not priority) |
| 4675 | (format "Priority must be an integer between 1 and %d.\n" | 4684 | (setq candidate (read-number prompt)) |
| 4676 | maxnum))) | 4685 | (setq prompt (when (or (< candidate 1) (> candidate maxnum)) |
| 4677 | (unless prompt (setq priority candidate))) | 4686 | (format "Priority must be an integer between 1 and %d.\n" |
| 4687 | maxnum))) | ||
| 4688 | (unless prompt (setq priority candidate)))) | ||
| 4678 | ;; In Top Priorities buffer, an item's priority can be changed | 4689 | ;; In Top Priorities buffer, an item's priority can be changed |
| 4679 | ;; wrt items in another category, but not wrt items in the same | 4690 | ;; wrt items in another category, but not wrt items in the same |
| 4680 | ;; category. | 4691 | ;; category. |
| @@ -4704,7 +4715,9 @@ meaning to raise or lower the item's priority by one." | |||
| 4704 | (when (or arg (called-interactively-p)) | 4715 | (when (or arg (called-interactively-p)) |
| 4705 | (todos-remove-item)) | 4716 | (todos-remove-item)) |
| 4706 | (goto-char (point-min)) | 4717 | (goto-char (point-min)) |
| 4707 | (unless (= priority 1) (todos-forward-item (1- priority))) | 4718 | (when priority |
| 4719 | (unless (= priority 1) | ||
| 4720 | (todos-forward-item (1- priority)))) | ||
| 4708 | (todos-insert-with-overlays item) | 4721 | (todos-insert-with-overlays item) |
| 4709 | ;; If item was marked, restore the mark. | 4722 | ;; If item was marked, restore the mark. |
| 4710 | (and marked (overlay-put (make-overlay (point) (point)) | 4723 | (and marked (overlay-put (make-overlay (point) (point)) |
| @@ -4733,103 +4746,102 @@ If the chosen category is not one of the existing categories, | |||
| 4733 | then it is created and the item(s) become(s) the first | 4746 | then it is created and the item(s) become(s) the first |
| 4734 | entry/entries in that category." | 4747 | entry/entries in that category." |
| 4735 | (interactive) | 4748 | (interactive) |
| 4736 | (unless (or (todos-done-item-p) | 4749 | (let* ((cat1 (todos-current-category)) |
| 4737 | ;; Point is between todo and done items. | 4750 | (marked (assoc cat1 todos-categories-with-marks))) |
| 4738 | (looking-at "^$")) | 4751 | (unless (or (todos-done-item-p) |
| 4739 | (let* ((buffer-read-only) | 4752 | ;; Point is between todo and done items. |
| 4740 | (file1 todos-current-todos-file) | 4753 | (and (looking-at "^$") (not marked))) |
| 4741 | (cat1 (todos-current-category)) | 4754 | (let* ((buffer-read-only) |
| 4742 | (marked (assoc cat1 todos-categories-with-marks)) | 4755 | (file1 todos-current-todos-file) |
| 4743 | (num todos-category-number) | 4756 | (num todos-category-number) |
| 4744 | (item (todos-item-string)) | 4757 | (item (todos-item-string)) |
| 4745 | (diary-item (todos-diary-item-p)) | 4758 | (diary-item (todos-diary-item-p)) |
| 4746 | (omark (save-excursion (todos-item-start) (point-marker))) | 4759 | (omark (save-excursion (todos-item-start) (point-marker))) |
| 4747 | (file2 (if file | 4760 | (file2 (if file |
| 4748 | (todos-read-file-name "Choose a Todos file: " nil t) | 4761 | (todos-read-file-name "Choose a Todos file: " nil t) |
| 4749 | file1)) | 4762 | file1)) |
| 4750 | (count 0) | 4763 | (count 0) |
| 4751 | (count-diary 0) | 4764 | (count-diary 0) |
| 4752 | ov cat2 nmark) | 4765 | ov cat2 nmark) |
| 4753 | (set-buffer (find-file-noselect file2)) | 4766 | (set-buffer (find-file-noselect file2)) |
| 4754 | (unwind-protect | 4767 | (unwind-protect |
| 4755 | (progn | 4768 | (progn |
| 4756 | (unless marked | 4769 | (unless marked |
| 4757 | (setq ov (make-overlay (save-excursion (todos-item-start)) | 4770 | (setq ov (make-overlay (save-excursion (todos-item-start)) |
| 4758 | (save-excursion (todos-item-end)))) | 4771 | (save-excursion (todos-item-end)))) |
| 4759 | (overlay-put ov 'face 'todos-search)) | 4772 | (overlay-put ov 'face 'todos-search)) |
| 4760 | (setq cat2 (let* ((pl (if (and marked (> (cdr marked) 1)) "s" "")) | 4773 | (setq cat2 (let* ((pl (if (and marked (> (cdr marked) 1)) "s" "")) |
| 4761 | (name (todos-read-category | 4774 | (name (todos-read-category |
| 4762 | (concat "Move item" pl " to category: "))) | 4775 | (concat "Move item" pl " to category: "))) |
| 4763 | (prompt (concat "Choose a different category than " | 4776 | (prompt (concat "Choose a different category than " |
| 4764 | "the current one\n(type `" | 4777 | "the current one\n(type `" |
| 4765 | (key-description | 4778 | (key-description |
| 4766 | (car (where-is-internal | 4779 | (car (where-is-internal |
| 4767 | 'todos-set-item-priority))) | 4780 | 'todos-set-item-priority))) |
| 4768 | "' to reprioritize item " | 4781 | "' to reprioritize item " |
| 4769 | "within the same category): "))) | 4782 | "within the same category): "))) |
| 4770 | (while (equal name cat1) | 4783 | (while (equal name cat1) |
| 4771 | (setq name (todos-read-category prompt))) | 4784 | (setq name (todos-read-category prompt))) |
| 4772 | name))) | 4785 | name))) |
| 4773 | (if ov (delete-overlay ov))) | 4786 | (if ov (delete-overlay ov))) |
| 4774 | (set-buffer (find-buffer-visiting file1)) | 4787 | (set-buffer (find-buffer-visiting file1)) |
| 4775 | (if marked | 4788 | (if marked |
| 4776 | (progn | 4789 | (progn |
| 4777 | (setq item nil) | 4790 | (setq item nil) |
| 4778 | (goto-char (point-min)) | 4791 | (goto-char (point-min)) |
| 4779 | (while (not (eobp)) | 4792 | (while (not (eobp)) |
| 4780 | (when (todos-marked-item-p) | 4793 | (when (todos-marked-item-p) |
| 4781 | (setq item (concat item (todos-item-string) "\n")) | 4794 | (setq item (concat item (todos-item-string) "\n")) |
| 4782 | (setq count (1+ count)) | 4795 | (setq count (1+ count)) |
| 4783 | (when (todos-diary-item-p) | 4796 | (when (todos-diary-item-p) |
| 4784 | (setq count-diary (1+ count-diary)))) | 4797 | (setq count-diary (1+ count-diary)))) |
| 4785 | (todos-forward-item)) | 4798 | (todos-forward-item)) |
| 4786 | ;; Chop off last newline. | 4799 | ;; Chop off last newline. |
| 4787 | (setq item (substring item 0 -1))) | 4800 | (setq item (substring item 0 -1))) |
| 4788 | (setq count 1) | 4801 | (setq count 1) |
| 4789 | (when (todos-diary-item-p) (setq count-diary 1))) | 4802 | (when (todos-diary-item-p) (setq count-diary 1))) |
| 4790 | (set-window-buffer (selected-window) | 4803 | (set-window-buffer (selected-window) |
| 4791 | (set-buffer (find-file-noselect file2))) | 4804 | (set-buffer (find-file-noselect file2))) |
| 4792 | (unless (assoc cat2 todos-categories) (todos-add-category cat2)) | 4805 | (todos-set-item-priority item cat2 t) |
| 4793 | (todos-set-item-priority item cat2 t) | 4806 | (setq nmark (point-marker)) |
| 4794 | (setq nmark (point-marker)) | 4807 | (todos-update-count 'todo count) |
| 4795 | (todos-update-count 'todo count) | 4808 | (todos-update-count 'diary count-diary) |
| 4796 | (todos-update-count 'diary count-diary) | 4809 | (todos-update-categories-sexp) |
| 4797 | (todos-update-categories-sexp) | 4810 | (with-current-buffer (find-buffer-visiting file1) |
| 4798 | (with-current-buffer (find-buffer-visiting file1) | 4811 | (save-excursion |
| 4799 | (save-excursion | 4812 | (save-restriction |
| 4800 | (save-restriction | 4813 | (widen) |
| 4801 | (widen) | 4814 | (goto-char omark) |
| 4802 | (goto-char omark) | 4815 | (if marked |
| 4803 | (if marked | 4816 | (let (beg end) |
| 4804 | (let (beg end) | 4817 | (setq item nil) |
| 4805 | (setq item nil) | 4818 | (re-search-backward |
| 4806 | (re-search-backward | 4819 | (concat "^" (regexp-quote todos-category-beg)) nil t) |
| 4807 | (concat "^" (regexp-quote todos-category-beg)) nil t) | 4820 | (forward-line) |
| 4808 | (forward-line) | 4821 | (setq beg (point)) |
| 4809 | (setq beg (point)) | 4822 | (re-search-forward |
| 4810 | (re-search-forward | 4823 | (concat "^" (regexp-quote todos-category-done)) nil t) |
| 4811 | (concat "^" (regexp-quote todos-category-done)) nil t) | 4824 | (setq end (match-beginning 0)) |
| 4812 | (setq end (match-beginning 0)) | 4825 | (goto-char beg) |
| 4813 | (goto-char beg) | 4826 | (while (< (point) end) |
| 4814 | (while (< (point) end) | 4827 | (if (todos-marked-item-p) |
| 4815 | (if (todos-marked-item-p) | 4828 | (todos-remove-item) |
| 4816 | (todos-remove-item) | 4829 | (todos-forward-item))) |
| 4817 | (todos-forward-item))) | 4830 | ;; FIXME: does this work? |
| 4818 | ;; FIXME: does this work? | 4831 | (remove-overlays (point-min) (point-max) |
| 4819 | (remove-overlays (point-min) (point-max) | 4832 | 'before-string todos-item-mark) |
| 4820 | 'before-string todos-item-mark) | 4833 | (setq todos-categories-with-marks |
| 4821 | (setq todos-categories-with-marks | 4834 | (assq-delete-all cat1 todos-categories-with-marks))) |
| 4822 | (assq-delete-all cat todos-categories-with-marks))) | 4835 | (if ov (delete-overlay ov)) |
| 4823 | (if ov (delete-overlay ov)) | 4836 | (todos-remove-item)))) |
| 4824 | (todos-remove-item)))) | 4837 | (todos-update-count 'todo (- count) cat1) |
| 4825 | (todos-update-count 'todo (- count) cat1) | 4838 | (todos-update-count 'diary (- count-diary) cat1) |
| 4826 | (todos-update-count 'diary (- count-diary) cat1) | 4839 | (todos-update-categories-sexp)) |
| 4827 | (todos-update-categories-sexp)) | 4840 | (set-window-buffer (selected-window) |
| 4828 | (set-window-buffer (selected-window) | 4841 | (set-buffer (find-file-noselect file2))) |
| 4829 | (set-buffer (find-file-noselect file2))) | 4842 | (setq todos-category-number (todos-category-number cat2)) |
| 4830 | (setq todos-category-number (todos-category-number cat2)) | 4843 | (todos-category-select) |
| 4831 | (todos-category-select) | 4844 | (goto-char nmark))))) |
| 4832 | (goto-char nmark)))) | ||
| 4833 | 4845 | ||
| 4834 | (defun todos-move-item-to-file () | 4846 | (defun todos-move-item-to-file () |
| 4835 | "Move the current todo item to a category in another Todos file." | 4847 | "Move the current todo item to a category in another Todos file." |
| @@ -4861,6 +4873,7 @@ relocated to the category's (by default hidden) done section." | |||
| 4861 | (let* ((cat (todos-current-category)) | 4873 | (let* ((cat (todos-current-category)) |
| 4862 | (marked (assoc cat todos-categories-with-marks))) | 4874 | (marked (assoc cat todos-categories-with-marks))) |
| 4863 | (unless (or (todos-done-item-p) | 4875 | (unless (or (todos-done-item-p) |
| 4876 | ;; Point is between todo and done items. | ||
| 4864 | (and (looking-at "^$") (not marked))) | 4877 | (and (looking-at "^$") (not marked))) |
| 4865 | (let* ((date-string (calendar-date-string (calendar-current-date) t t)) | 4878 | (let* ((date-string (calendar-date-string (calendar-current-date) t t)) |
| 4866 | (time-string (if todos-always-add-time-string | 4879 | (time-string (if todos-always-add-time-string |