aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Berman2013-02-03 00:06:23 +0100
committerStephen Berman2013-02-03 00:06:23 +0100
commitab951d1bf3a175877bc68822de479ba4f4ac0cba (patch)
treec4272f30a543cc95a190b1f97e9f20901ebe7c92
parent0d6eb16262072a01b3ee7d4bbe7916ca4b52da6d (diff)
downloademacs-ab951d1bf3a175877bc68822de479ba4f4ac0cba.tar.gz
emacs-ab951d1bf3a175877bc68822de479ba4f4ac0cba.zip
* calendar/todos.el: Several small fixes and improvements.
(todos-done-separator-string): Change default value. (todos-update-categories-sexp): Remove unnecessary and misquided setq of todos-default-todos-file. Use delete-region instead of kill-region to avoid polluting kill-ring. (todos-unload-hook): Remove (was not used). (todos-edit-multiline): Don't generate new edit buffer name on each invocation---that can cause confusion due to indirect buffer. (todos-edit-quit): Ensure lines in edit buffer that follow hard newlines are indented in the file to conform to diary format. (todos-set-item-priority): If done items in category are visible, keep them visible.
-rw-r--r--lisp/ChangeLog15
-rw-r--r--lisp/calendar/todos.el80
2 files changed, 59 insertions, 36 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index f2d5d2e22c4..900b38b9d6b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,18 @@
12013-02-02 Stephen Berman <stephen.berman@gmx.net>
2
3 * calendar/todos.el: Several small fixes and improvements.
4 (todos-done-separator-string): Change default value.
5 (todos-update-categories-sexp): Remove unnecessary and misquided
6 setq of todos-default-todos-file. Use delete-region instead of
7 kill-region to avoid polluting kill-ring.
8 (todos-unload-hook): Remove (was not used).
9 (todos-edit-multiline): Don't generate new edit buffer name on
10 each invocation---that can cause confusion due to indirect buffer.
11 (todos-edit-quit): Ensure lines in edit buffer that follow hard
12 newlines are indented in the file to conform to diary format.
13 (todos-set-item-priority): If done items in category are visible,
14 keep them visible.
15
12013-01-30 Stephen Berman <stephen.berman@gmx.net> 162013-01-30 Stephen Berman <stephen.berman@gmx.net>
2 17
3 * calendar/todos.el: Fix done separator overlay bug. Remove most 18 * calendar/todos.el: Fix done separator overlay bug. Remove most
diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el
index 7511c7cc2b6..1e8f10b0552 100644
--- a/lisp/calendar/todos.el
+++ b/lisp/calendar/todos.el
@@ -243,7 +243,7 @@ only when no items are marked."
243 (custom-set-default symbol (propertize value 'face 'todos-mark))) 243 (custom-set-default symbol (propertize value 'face 'todos-mark)))
244 :group 'todos-mode-display) 244 :group 'todos-mode-display)
245 245
246(defcustom todos-done-separator-string "_" 246(defcustom todos-done-separator-string "="
247 "String for generating `todos-done-separator'. 247 "String for generating `todos-done-separator'.
248 248
249If the string consists of a single character, 249If the string consists of a single character,
@@ -1249,11 +1249,16 @@ Todos files named in `todos-category-completions-files'."
1249 ;; already is one. 1249 ;; already is one.
1250 (let* ((done-sep todos-done-separator) 1250 (let* ((done-sep todos-done-separator)
1251 (ovs (overlays-at done-sep-start)) 1251 (ovs (overlays-at done-sep-start))
1252 ;; ov-sep0 ov-sep1)
1252 ov-sep) 1253 ov-sep)
1253 ;; There should never be more than one overlay here, so car suffices. 1254 ;; There should never be more than one overlay here, so car suffices.
1254 (unless (and ovs (string= (overlay-get (car ovs) 'display) done-sep)) 1255 (unless (and ovs (string= (overlay-get (car ovs) 'display) done-sep))
1255 (setq ov-sep (make-overlay done-sep-start done-end)) 1256 (setq ov-sep (make-overlay done-sep-start done-end))
1256 (overlay-put ov-sep 'display done-sep)))) 1257 (overlay-put ov-sep 'display done-sep))))
1258 ;; (setq ov-sep0 (make-overlay done-sep-start done-end))
1259 ;; (setq ov-sep1 (make-overlay done-end done-end))
1260 ;; (overlay-put ov-sep0 'invisible t)
1261 ;; (overlay-put ov-sep1 'after-string done-sep)))
1257 (narrow-to-region (point-min) done-start) 1262 (narrow-to-region (point-min) done-start)
1258 ;; Loading this from todos-mode, or adding it to the mode hook, causes 1263 ;; Loading this from todos-mode, or adding it to the mode hook, causes
1259 ;; Emacs to hang in todos-item-start, at (looking-at todos-item-start). 1264 ;; Emacs to hang in todos-item-start, at (looking-at todos-item-start).
@@ -1308,15 +1313,8 @@ With nil or omitted CATEGORY, default to the current category."
1308 (goto-char (point-min)) 1313 (goto-char (point-min))
1309 (if (looking-at (concat "^" (regexp-quote todos-category-beg))) 1314 (if (looking-at (concat "^" (regexp-quote todos-category-beg)))
1310 (progn (newline) (goto-char (point-min)) ; Make space for sexp. 1315 (progn (newline) (goto-char (point-min)) ; Make space for sexp.
1311 ;; No categories sexp means the first item was just added
1312 ;; to this file, so have to initialize Todos file and
1313 ;; categories variables in order e.g. to enable categories
1314 ;; display.
1315 (setq todos-default-todos-file (buffer-file-name))
1316 (setq todos-categories (todos-make-categories-list t))) 1316 (setq todos-categories (todos-make-categories-list t)))
1317 ;; With empty buffer (e.g. with new archive in 1317 (delete-region (line-beginning-position) (line-end-position)))
1318 ;; `todos-move-category') `kill-line' signals end of buffer.
1319 (kill-region (line-beginning-position) (line-end-position)))
1320 (prin1 todos-categories (current-buffer)))))) 1318 (prin1 todos-categories (current-buffer))))))
1321 1319
1322(defun todos-make-categories-list (&optional force) 1320(defun todos-make-categories-list (&optional force)
@@ -2930,16 +2928,6 @@ which is the value of the user option
2930 'todos-reset-and-enable-done-separator nil t) 2928 'todos-reset-and-enable-done-separator nil t)
2931 (add-hook 'kill-buffer-hook 'todos-reset-global-current-todos-file nil t)) 2929 (add-hook 'kill-buffer-hook 'todos-reset-global-current-todos-file nil t))
2932 2930
2933(defun todos-unload-hook ()
2934 ""
2935 (remove-hook 'pre-command-hook 'todos-show-current-file t)
2936 (remove-hook 'post-command-hook 'todos-update-buffer-list t)
2937 (remove-hook 'find-file-hook 'todos-display-as-todos-file t)
2938 (remove-hook 'find-file-hook 'todos-add-to-buffer-list t)
2939 (remove-hook 'window-configuration-change-hook
2940 'todos-reset-and-enable-done-separator t)
2941 (remove-hook 'kill-buffer-hook 'todos-reset-global-current-todos-file t))
2942
2943(put 'todos-archive-mode 'mode-class 'special) 2931(put 'todos-archive-mode 'mode-class 'special)
2944 2932
2945;; If todos-mode is parent, all todos-mode key bindings appear to be 2933;; If todos-mode is parent, all todos-mode key bindings appear to be
@@ -4522,6 +4510,8 @@ the priority is not given by HERE but by prompting."
4522 (unless (and todos-use-only-highlighted-region (use-region-p)) 4510 (unless (and todos-use-only-highlighted-region (use-region-p))
4523 (error "There is no active region")))) 4511 (error "There is no active region"))))
4524 (let* ((buf (current-buffer)) 4512 (let* ((buf (current-buffer))
4513 ;; (ocat (todos-current-category))
4514 ;; (todos-mm (eq major-mode 'todos-mode))
4525 (cat+file (cond ((equal arg '(4)) 4515 (cat+file (cond ((equal arg '(4))
4526 (todos-read-category "Insert in category: ")) 4516 (todos-read-category "Insert in category: "))
4527 ((equal arg '(16)) 4517 ((equal arg '(16))
@@ -4592,15 +4582,18 @@ the priority is not given by HERE but by prompting."
4592 new-item nil nil 1)) 4582 new-item nil nil 1))
4593 (if here 4583 (if here
4594 (cond ((not (eq major-mode 'todos-mode)) 4584 (cond ((not (eq major-mode 'todos-mode))
4595 (error "Cannot insert a todo item here outside of Todos mode")) 4585 (error "Cannot insert a todo item here outside of Todos mode"))
4596 ((not (eq buf (current-buffer))) 4586 ((not (eq buf (current-buffer)))
4597 (error "Cannot insert an item here after changing buffer")) 4587 (error "Cannot insert an item here after changing buffer"))
4598 ((or (todos-done-item-p) 4588 ((or (todos-done-item-p)
4599 ;; Point on last blank line. 4589 ;; Point on last blank line.
4600 (save-excursion (forward-line -1) (todos-done-item-p))) 4590 (save-excursion (forward-line -1) (todos-done-item-p)))
4601 (error "Cannot insert a new item in the done item section")) 4591 (error "Cannot insert a new item in the done item section"))
4602 (t 4592 (t
4603 (todos-insert-with-overlays new-item))) 4593 (todos-insert-with-overlays new-item)))
4594 ;; (if (and todos-mm (equal cat ocat))
4595 ;; (todos-insert-with-overlays new-item)
4596 ;; )
4604 ;; (todos-set-item-priority new-item (todos-current-category) t)) 4597 ;; (todos-set-item-priority new-item (todos-current-category) t))
4605 (todos-set-item-priority new-item cat t) 4598 (todos-set-item-priority new-item cat t)
4606 ;; If item is inserted at end of category, make sure the 4599 ;; If item is inserted at end of category, make sure the
@@ -4735,7 +4728,7 @@ minibuffer; otherwise, edit it in Todos Edit mode."
4735 todos-date-pattern) new)) 4728 todos-date-pattern) new))
4736 (setq new (read-from-minibuffer 4729 (setq new (read-from-minibuffer
4737 "Item must start with a date: " new)))) 4730 "Item must start with a date: " new))))
4738 ;; Indent newlines inserted by C-q C-j if nonspace char follows. 4731 ;; Ensure lines following hard newlines are indented.
4739 (setq new (replace-regexp-in-string 4732 (setq new (replace-regexp-in-string
4740 "\\(\n\\)[^[:blank:]]" 4733 "\\(\n\\)[^[:blank:]]"
4741 (concat "\n" (make-string todos-indent-to-here 32)) new 4734 (concat "\n" (make-string todos-indent-to-here 32)) new
@@ -4756,9 +4749,7 @@ the format of Diary entries."
4756(defun todos-edit-multiline (&optional item) 4749(defun todos-edit-multiline (&optional item)
4757 "" 4750 ""
4758 (interactive) 4751 (interactive)
4759 ;; FIXME: should there be only one live Todos Edit buffer? 4752 (let ((buffer-name todos-edit-buffer))
4760 ;; (let ((buffer-name todos-edit-buffer))
4761 (let ((buffer-name (generate-new-buffer-name todos-edit-buffer)))
4762 (set-window-buffer 4753 (set-window-buffer
4763 (selected-window) 4754 (selected-window)
4764 (set-buffer (make-indirect-buffer 4755 (set-buffer (make-indirect-buffer
@@ -4774,14 +4765,25 @@ the format of Diary entries."
4774 4765
4775(defun todos-edit-quit () 4766(defun todos-edit-quit ()
4776 "Return from Todos Edit mode to Todos mode. 4767 "Return from Todos Edit mode to Todos mode.
4768If the item contains hard line breaks, make sure the following
4769lines are indented by `todos-indent-to-here' to conform to diary
4770format.
4777 4771
4778If the whole file was in Todos Edit mode, check before returning 4772If the whole file was in Todos Edit mode, check before returning
4779whether the file is still a valid Todos file and if so, also 4773whether the file is still a valid Todos file and if so, also
4780recalculate the Todos categories sexp, in case changes were made 4774recalculate the Todos categories sexp, in case changes were made
4781in the number or names of categories." 4775in the number or names of categories."
4782 (interactive) 4776 (interactive)
4783 (when (eq (buffer-size) (- (point-max) (point-min))) 4777 (if (eq (buffer-size) (- (point-max) (point-min)))
4784 (when (todos-check-format) (todos-repair-categories-sexp))) 4778 (when (todos-check-format)
4779 (todos-repair-categories-sexp))
4780 ;; Ensure lines following hard newlines are indented.
4781 (let ((item (replace-regexp-in-string
4782 "\\(\n\\)[^[:blank:]]"
4783 (concat "\n" (make-string todos-indent-to-here 32))
4784 (buffer-string) nil nil 1)))
4785 (delete-region (point-min) (point-max))
4786 (insert item)))
4785 (kill-buffer) 4787 (kill-buffer)
4786 ;; In case next buffer is not the one holding todos-current-todos-file. 4788 ;; In case next buffer is not the one holding todos-current-todos-file.
4787 (todos-show)) 4789 (todos-show))
@@ -5148,7 +5150,7 @@ items in this category."
5148 (todos-forward-item))))))) 5150 (todos-forward-item)))))))
5149 5151
5150(defun todos-set-item-priority (&optional item cat new arg) 5152(defun todos-set-item-priority (&optional item cat new arg)
5151 "Set todo ITEM's priority in CATegory and move item accordingly. 5153 "Prompt for and set ITEM's priority in CATegory.
5152 5154
5153Interactively, ITEM defaults to the item at point, CAT to the 5155Interactively, ITEM defaults to the item at point, CAT to the
5154current category in Todos mode, and the priority is a number 5156current category in Todos mode, and the priority is a number
@@ -5206,7 +5208,13 @@ meaning to raise or lower the item's priority by one."
5206 ;; prompting for its priority. 5208 ;; prompting for its priority.
5207 (unless (or arg (called-interactively-p t)) 5209 (unless (or arg (called-interactively-p t))
5208 (todos-category-number cat) 5210 (todos-category-number cat)
5209 (todos-category-select)) 5211 ;; If done items in category are visible, keep them visible.
5212 (let (done)
5213 (save-excursion
5214 (goto-char (point-min))
5215 (setq done (re-search-forward todos-done-string-start nil t)))
5216 (let ((todos-show-with-done done))
5217 (todos-category-select))))
5210 ;; Prompt for priority only when the category has at least one todo item. 5218 ;; Prompt for priority only when the category has at least one todo item.
5211 (when (> maxnum 1) 5219 (when (> maxnum 1)
5212 (while (not priority) 5220 (while (not priority)