aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Berman2013-02-19 23:29:28 +0100
committerStephen Berman2013-02-19 23:29:28 +0100
commit8b38fab92bcdb8703447ada31a1972c9be6ed17c (patch)
treec79da4fa05abbd991b4af542fc82f733b5cd89f8
parent21d0ff7bc8ec16e2808924b317d189dad90391c3 (diff)
downloademacs-8b38fab92bcdb8703447ada31a1972c9be6ed17c.tar.gz
emacs-8b38fab92bcdb8703447ada31a1972c9be6ed17c.zip
* calendar/todos.el: Item insertion and done/undo fixes.
(todos-insert-item): Maybe set the insertion file to todos-global-current-todos-file. When inserting into a file that was not being visited on invoking this command, ensure chosen category is properly selected. Make item inserted "here" the first todo item if the command was invoked with point in done items section or outside of the current category. (todos-item-done): When done items are shown, put cursor on first just done item. (todos-item-undo): Put cursor on undone item.
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/calendar/todos.el152
2 files changed, 71 insertions, 94 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2e4aac74190..00ea7098ae5 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,16 @@
12013-02-19 Stephen Berman <stephen.berman@gmx.net>
2
3 * calendar/todos.el: Item insertion and done/undo fixes.
4 (todos-insert-item): Maybe set the insertion file to
5 todos-global-current-todos-file. When inserting into a file that
6 was not being visited on invoking this command, ensure chosen
7 category is properly selected. Make item inserted "here" the
8 first todo item if the command was invoked with point in done
9 items section or outside of the current category.
10 (todos-item-done): When done items are shown, put cursor on first
11 just done item.
12 (todos-item-undo): Put cursor on undone item.
13
12013-02-16 Stephen Berman <stephen.berman@gmx.net> 142013-02-16 Stephen Berman <stephen.berman@gmx.net>
2 15
3 * calendar/todos.el: Improve handling of overlays. 16 * calendar/todos.el: Improve handling of overlays.
diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el
index 13249f95c10..46d419d642c 100644
--- a/lisp/calendar/todos.el
+++ b/lisp/calendar/todos.el
@@ -1150,11 +1150,14 @@ 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 ;; If separator's length is window-width, an 1153 ;; If separator's length is window-width, then
1154 ;; indented empty line appears between the 1154 ;; with non-nil todos-wrap-lines and
1155 ;; separator and the first done item. 1155 ;; todos-wrap-and-indent as value of
1156 ;; FIXME: should this be customizable? 1156 ;; todos-line-wrapping-function, an indented empty
1157 ;; line appears between the separator and the
1158 ;; first done item.
1157 (make-string (1- (window-width)) (string-to-char sep)) 1159 (make-string (1- (window-width)) (string-to-char sep))
1160 ;; (make-string (window-width) (string-to-char sep))
1158 todos-done-separator-string) 1161 todos-done-separator-string)
1159 'face 'todos-done-sep))) 1162 'face 'todos-done-sep)))
1160 1163
@@ -4522,7 +4525,9 @@ the new item:
4522 category, insert it directly above the todo item at 4525 category, insert it directly above the todo item at
4523 point (hence lowering the priority of the remaining items), or 4526 point (hence lowering the priority of the remaining items), or
4524 if point is on the empty line below the last todo item, insert 4527 if point is on the empty line below the last todo item, insert
4525 the new item there. If the command with `here' is invoked 4528 the new item there. If point is in the done items section of
4529 the category, insert the new item as the first todo item in the
4530 category. Likewise, if the command with `here' is invoked
4526 outside of the current category, jump to the chosen category 4531 outside of the current category, jump to the chosen category
4527 and insert the new item as the first item in the category. 4532 and insert the new item as the first item in the category.
4528- If REGION-OR-HERE is the symbol `region', use the region of the 4533- If REGION-OR-HERE is the symbol `region', use the region of the
@@ -4575,6 +4580,8 @@ the priority is not given by HERE but by prompting."
4575 (t 4580 (t
4576 (cons (todos-current-category) 4581 (cons (todos-current-category)
4577 (or todos-current-todos-file 4582 (or todos-current-todos-file
4583 (and todos-show-current-file
4584 todos-global-current-todos-file)
4578 (todos-absolute-file-name 4585 (todos-absolute-file-name
4579 todos-default-todos-file)))))) 4586 todos-default-todos-file))))))
4580 (cat (car cat+file)) 4587 (cat (car cat+file))
@@ -4613,10 +4620,11 @@ the priority is not given by HERE but by prompting."
4613 (setq todos-current-todos-file file) 4620 (setq todos-current-todos-file file)
4614 (unless todos-global-current-todos-file 4621 (unless todos-global-current-todos-file
4615 (setq todos-global-current-todos-file todos-current-todos-file)) 4622 (setq todos-global-current-todos-file todos-current-todos-file))
4616 ;; These are not needed here, since they are called in 4623 ;; When inserting into a file that was not being visited on
4617 ;; todos-set-item-priority. 4624 ;; invoking this command, point is at bof.
4618 ;; (todos-category-number cat) 4625 (when (= (point) 1)
4619 ;; (todos-category-select) 4626 (todos-category-number cat)
4627 (todos-category-select))
4620 (let ((buffer-read-only nil) 4628 (let ((buffer-read-only nil)
4621 done-only item-added) 4629 done-only item-added)
4622 (setq new-item 4630 (setq new-item
@@ -4636,37 +4644,36 @@ the priority is not given by HERE but by prompting."
4636 "\\(\n\\)[^[:blank:]]" 4644 "\\(\n\\)[^[:blank:]]"
4637 (concat "\n" (make-string todos-indent-to-here 32)) 4645 (concat "\n" (make-string todos-indent-to-here 32))
4638 new-item nil nil 1)) 4646 new-item nil nil 1))
4639 (if here 4647 (unwind-protect
4640 (if (or (todos-done-item-p) (todos-done-item-section-p)) 4648 (progn
4641 (error "Cannot insert item in done items section") 4649 ;; If only done items are displayed in category,
4642 (unless (and todos-mm (equal cat ocat)) 4650 ;; toggle to todo items.
4643 (todos-category-number cat) 4651 (when (save-excursion
4644 (todos-category-select) 4652 (goto-char (point-min))
4645 (goto-char (point-min))) 4653 (looking-at todos-done-string-start))
4646 (todos-insert-with-overlays new-item)) 4654 (setq done-only t)
4647 (unwind-protect 4655 (todos-show-done-only))
4648 (progn 4656 (if here
4649 ;; If only done items are displayed in category, 4657 (progn
4650 ;; toggle to todo items. 4658 (unless (and todos-mm (equal cat ocat)
4651 (when (and (goto-char (point-min)) 4659 (not (todos-done-item-section-p)))
4652 (looking-at todos-done-string-start)) 4660 (goto-char (point-min)))
4653 (setq done-only t) 4661 (todos-insert-with-overlays new-item))
4654 (todos-show-done-only)) 4662 (todos-set-item-priority new-item cat t))
4655 (todos-set-item-priority new-item cat t) 4663 (setq item-added t))
4656 (setq item-added t)) 4664 ;; If user cancels before setting priority, restore
4657 ;; If user cancels before setting priority, restore 4665 ;; display.
4658 ;; display. 4666 (unless item-added
4659 (unless item-added 4667 (and done-only (todos-show-done-only)))
4660 (and done-only (todos-show-done-only))) 4668 ;; If todos section is not visible when insertion
4661 ;; If todos section is not visible when insertion 4669 ;; command is called (either because only done items
4662 ;; command is called (either because only done items 4670 ;; were shown or because category was not in current
4663 ;; were shown or because category was not in current 4671 ;; buffer), then if item is inserted at end of category,
4664 ;; buffer), then if item is inserted at end of category, 4672 ;; point is at eob and eob at window-start, so that that
4665 ;; point is at eob and eob at window-start, so that that 4673 ;; higher priority todo items are out of view. So we
4666 ;; higher priority todo items are out of view. So we 4674 ;; recenter to make sure the todo items are displayed in
4667 ;; recenter to make sure the todo items are displayed in 4675 ;; the window.
4668 ;; the window. 4676 (when item-added (recenter)))
4669 (when item-added (recenter))))
4670 (todos-update-count 'todo 1) 4677 (todos-update-count 'todo 1)
4671 (if (or diary todos-include-in-diary) (todos-update-count 'diary 1)) 4678 (if (or diary todos-include-in-diary) (todos-update-count 'diary 1))
4672 (todos-update-categories-sexp)))))) 4679 (todos-update-categories-sexp))))))
@@ -4807,55 +4814,6 @@ minibuffer; otherwise, edit it in Todos Edit mode."
4807 (todos-insert-with-overlays new) 4814 (todos-insert-with-overlays new)
4808 (move-to-column item-beg)))))) 4815 (move-to-column item-beg))))))
4809 4816
4810;; (defun todos-edit-multiline-item ()
4811;; "Edit current Todo item in Todos Edit mode.
4812;; Use of newlines invokes `todos-indent' to insure compliance with
4813;; the format of Diary entries."
4814;; (interactive)
4815;; (todos-edit-multiline t))
4816
4817;; (defun todos-edit-multiline (&optional item) ;FIXME: not item editing command
4818;; "" ;FIXME
4819;; (interactive)
4820;; (let ((buffer-name todos-edit-buffer))
4821;; (set-window-buffer
4822;; (selected-window)
4823;; (set-buffer (make-indirect-buffer
4824;; (file-name-nondirectory todos-current-todos-file)
4825;; buffer-name)))
4826;; (if item
4827;; (narrow-to-region (todos-item-start) (todos-item-end))
4828;; (widen))
4829;; (todos-edit-mode)
4830;; (message "%s" (substitute-command-keys
4831;; (concat "Type \\[todos-edit-quit] to check file format "
4832;; "validity and return to Todos mode.\n")))))
4833
4834;; (defun todos-edit-quit ()
4835;; "Return from Todos Edit mode to Todos mode.
4836;; If the item contains hard line breaks, make sure the following
4837;; lines are indented by `todos-indent-to-here' to conform to diary
4838;; format.
4839
4840;; If the whole file was in Todos Edit mode, check before returning
4841;; whether the file is still a valid Todos file and if so, also
4842;; recalculate the Todos categories sexp, in case changes were made
4843;; in the number or names of categories."
4844;; (interactive)
4845;; (if (eq (buffer-size) (- (point-max) (point-min)))
4846;; (when (todos-check-format)
4847;; (todos-repair-categories-sexp))
4848;; ;; Ensure lines following hard newlines are indented.
4849;; (let ((item (replace-regexp-in-string
4850;; "\\(\n\\)[^[:blank:]]"
4851;; (concat "\n" (make-string todos-indent-to-here 32))
4852;; (buffer-string) nil nil 1)))
4853;; (delete-region (point-min) (point-max))
4854;; (insert item)))
4855;; (kill-buffer)
4856;; ;; In case next buffer is not the one holding todos-current-todos-file.
4857;; (todos-show))
4858
4859(defun todos-edit-multiline-item () 4817(defun todos-edit-multiline-item ()
4860 "Edit current Todo item in Todos Edit mode. 4818 "Edit current Todo item in Todos Edit mode.
4861Use of newlines invokes `todos-indent' to insure compliance with 4819Use of newlines invokes `todos-indent' to insure compliance with
@@ -5602,8 +5560,8 @@ visible."
5602 (show-done (save-excursion 5560 (show-done (save-excursion
5603 (goto-char (point-min)) 5561 (goto-char (point-min))
5604 (re-search-forward todos-done-string-start nil t))) 5562 (re-search-forward todos-done-string-start nil t)))
5605 item done-item 5563 (buffer-read-only nil)
5606 (buffer-read-only)) 5564 item done-item opoint)
5607 (and marked (goto-char (point-min))) 5565 (and marked (goto-char (point-min)))
5608 (catch 'done 5566 (catch 'done
5609 ;; Stop looping when we hit the empty line below the last 5567 ;; Stop looping when we hit the empty line below the last
@@ -5636,13 +5594,16 @@ visible."
5636 (re-search-forward 5594 (re-search-forward
5637 (concat "^" (regexp-quote todos-category-done)) nil t) 5595 (concat "^" (regexp-quote todos-category-done)) nil t)
5638 (forward-char) 5596 (forward-char)
5597 (when show-done (setq opoint (point)))
5639 (insert done-item "\n")) 5598 (insert done-item "\n"))
5640 (todos-update-count 'todo (- item-count)) 5599 (todos-update-count 'todo (- item-count))
5641 (todos-update-count 'done item-count) 5600 (todos-update-count 'done item-count)
5642 (todos-update-count 'diary (- diary-count)) 5601 (todos-update-count 'diary (- diary-count))
5643 (todos-update-categories-sexp) 5602 (todos-update-categories-sexp)
5644 (let ((todos-show-with-done show-done)) 5603 (let ((todos-show-with-done show-done))
5645 (todos-category-select)))))) 5604 (todos-category-select)
5605 ;; When done items are shown, put cursor on first just done item.
5606 (when opoint (goto-char opoint)))))))
5646 5607
5647(defun todos-done-item-add-edit-or-delete-comment (&optional arg) 5608(defun todos-done-item-add-edit-or-delete-comment (&optional arg)
5648 "Add a comment to this done item or edit an existing comment. 5609 "Add a comment to this done item or edit an existing comment.
@@ -5745,13 +5706,16 @@ the restored item."
5745 (unwind-protect 5706 (unwind-protect
5746 (progn 5707 (progn
5747 (todos-set-item-priority item (todos-current-category) t) 5708 (todos-set-item-priority item (todos-current-category) t)
5748 (setq undone t) 5709 (setq undone t
5710 opoint (point))
5749 (todos-update-count 'todo 1) 5711 (todos-update-count 'todo 1)
5750 (todos-update-count 'done -1) 5712 (todos-update-count 'done -1)
5751 (and (todos-diary-item-p) (todos-update-count 'diary 1)) 5713 (and (todos-diary-item-p) (todos-update-count 'diary 1))
5752 (todos-update-categories-sexp) 5714 (todos-update-categories-sexp)
5753 (let ((todos-show-with-done (> (todos-get-count 'done) 0))) 5715 (let ((todos-show-with-done (> (todos-get-count 'done) 0)))
5754 (todos-category-select))) 5716 (todos-category-select)
5717 ;; Put the cursor on the undone item.
5718 (goto-char opoint)))
5755 (unless undone 5719 (unless undone
5756 (let ((todos-show-with-done t)) 5720 (let ((todos-show-with-done t))
5757 (widen) 5721 (widen)