diff options
| -rw-r--r-- | lisp/ChangeLog | 14 | ||||
| -rw-r--r-- | lisp/calendar/todos.el | 212 |
2 files changed, 116 insertions, 110 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index fe66ff93267..bf1658d6f7c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,19 @@ | |||
| 1 | 2013-03-15 Stephen Berman <stephen.berman@gmx.net> | 1 | 2013-03-15 Stephen Berman <stephen.berman@gmx.net> |
| 2 | 2 | ||
| 3 | * calendar/todos.el: Item unarchiving fixes and improvements. | ||
| 4 | (todos-archive-mode-map): Add bindings for item and category | ||
| 5 | marking/unmarking; make todos-display-categories binding same as | ||
| 6 | in Todos mode; remove todos-unarchive-category binding. | ||
| 7 | (todos-unarchive-category): Remove. | ||
| 8 | (todos-unarchive-items): Fix handling of marked items. Remove | ||
| 9 | code for unarchiving whole category, since that is covered by | ||
| 10 | unarchiving marked items. Handle unarchiving items to a category | ||
| 11 | that had been deleted from the todo file by re-adding the | ||
| 12 | category. Use todos-category-select to display restored items, | ||
| 13 | not todos-show. Remove obsolete or superfluous code. | ||
| 14 | |||
| 15 | 2013-03-15 Stephen Berman <stephen.berman@gmx.net> | ||
| 16 | |||
| 3 | * calendar/todos.el (todos-reset-prefix): Don't remove overlays, | 17 | * calendar/todos.el (todos-reset-prefix): Don't remove overlays, |
| 4 | since it's superfluous and also wrongly removes items marks. | 18 | since it's superfluous and also wrongly removes items marks. |
| 5 | (todos-category-completions): Select current category on visiting | 19 | (todos-category-completions): Select current category on visiting |
diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el index b3e867d4b63..0527579a051 100644 --- a/lisp/calendar/todos.el +++ b/lisp/calendar/todos.el | |||
| @@ -2849,9 +2849,12 @@ which is the value of the user option | |||
| 2849 | (define-key map "n" 'todos-forward-item) | 2849 | (define-key map "n" 'todos-forward-item) |
| 2850 | (define-key map "p" 'todos-backward-item) | 2850 | (define-key map "p" 'todos-backward-item) |
| 2851 | ;; display commands | 2851 | ;; display commands |
| 2852 | (define-key map "C" 'todos-display-categories) | 2852 | (define-key map "Cd" 'todos-display-categories) |
| 2853 | (define-key map "H" 'todos-highlight-item) | 2853 | (define-key map "H" 'todos-highlight-item) |
| 2854 | (define-key map "N" 'todos-hide-show-item-numbering) | 2854 | (define-key map "N" 'todos-hide-show-item-numbering) |
| 2855 | (define-key map "*" 'todos-mark-unmark-item) | ||
| 2856 | (define-key map "C*" 'todos-mark-category) | ||
| 2857 | (define-key map "Cu" 'todos-unmark-category) | ||
| 2855 | ;; (define-key map "" 'todos-hide-show-date-time) | 2858 | ;; (define-key map "" 'todos-hide-show-date-time) |
| 2856 | (define-key map "P" 'todos-print) | 2859 | (define-key map "P" 'todos-print) |
| 2857 | (define-key map "q" 'todos-quit) | 2860 | (define-key map "q" 'todos-quit) |
| @@ -2859,7 +2862,6 @@ which is the value of the user option | |||
| 2859 | (define-key map "S" 'todos-search) | 2862 | (define-key map "S" 'todos-search) |
| 2860 | (define-key map "t" 'todos-show) | 2863 | (define-key map "t" 'todos-show) |
| 2861 | (define-key map "u" 'todos-unarchive-items) | 2864 | (define-key map "u" 'todos-unarchive-items) |
| 2862 | (define-key map "U" 'todos-unarchive-category) | ||
| 2863 | map) | 2865 | map) |
| 2864 | "Todos Archive mode keymap.") | 2866 | "Todos Archive mode keymap.") |
| 2865 | 2867 | ||
| @@ -5885,120 +5887,110 @@ this category does not exist in the archive, it is created." | |||
| 5885 | (interactive) | 5887 | (interactive) |
| 5886 | (todos-archive-done-item t)) | 5888 | (todos-archive-done-item t)) |
| 5887 | 5889 | ||
| 5888 | (defun todos-unarchive-items (&optional all) | 5890 | (defun todos-unarchive-items () |
| 5889 | "Unarchive at least one item in this archive category. | 5891 | "Unarchive at least one item in this archive category. |
| 5890 | |||
| 5891 | If there are marked items, unarchive all of these; otherwise, | 5892 | If there are marked items, unarchive all of these; otherwise, |
| 5892 | with non-nil argument ALL, unarchive all items in this category; | 5893 | unarchive the item at point. |
| 5893 | otherwise, unarchive the item at point. | ||
| 5894 | 5894 | ||
| 5895 | Unarchived items are restored as done items to the corresponding | 5895 | Unarchived items are restored as done items to the corresponding |
| 5896 | category in the Todos file, inserted at the end of done section. | 5896 | category in the Todos file, inserted at the end of done items |
| 5897 | If all items in the archive category were restored, the category | 5897 | section. If all items in the archive category have been |
| 5898 | is deleted from the archive. If this was the only category in the | 5898 | restored, the category is deleted from the archive. If this was |
| 5899 | archive, the archive file is deleted." | 5899 | the only category in the archive, the archive file is deleted." |
| 5900 | (interactive) | 5900 | (interactive) |
| 5901 | (when (eq major-mode 'todos-archive-mode) | 5901 | (when (eq major-mode 'todos-archive-mode) |
| 5902 | (catch 'end | 5902 | (let* ((cat (todos-current-category)) |
| 5903 | (let* ((cat (todos-current-category)) | 5903 | (tbuf (find-file-noselect |
| 5904 | (tbuf (find-file-noselect | 5904 | (concat (file-name-sans-extension todos-current-todos-file) |
| 5905 | (concat (file-name-sans-extension todos-current-todos-file) | 5905 | ".todo") t)) |
| 5906 | ".todo") t)) | 5906 | (marked (assoc cat todos-categories-with-marks)) |
| 5907 | (marked (assoc cat todos-categories-with-marks)) | 5907 | (item (concat (todos-item-string) "\n")) |
| 5908 | (item (concat (todos-item-string) "\n")) | 5908 | (marked-count 0) |
| 5909 | (all-items (when all (buffer-substring-no-properties | 5909 | marked-items |
| 5910 | (point-min) (point-max)))) | 5910 | buffer-read-only) |
| 5911 | (all-count (when all (todos-get-count 'done))) | 5911 | (when marked |
| 5912 | marked-items marked-count | 5912 | (save-excursion |
| 5913 | buffer-read-only) | 5913 | (goto-char (point-min)) |
| 5914 | (when marked | 5914 | (while (not (eobp)) |
| 5915 | (save-excursion | 5915 | (when (todos-marked-item-p) |
| 5916 | (goto-char (point-min)) | 5916 | (setq marked-items (concat marked-items (todos-item-string) "\n")) |
| 5917 | (while (not (eobp)) | 5917 | (setq marked-count (1+ marked-count))) |
| 5918 | (when (todos-marked-item-p) | 5918 | (todos-forward-item)))) |
| 5919 | (concat marked-items (todos-item-string) "\n") | 5919 | ;; Restore items to end of category's done section and update counts. |
| 5920 | (setq marked-count (1+ marked-count))) | 5920 | (with-current-buffer tbuf |
| 5921 | (todos-forward-item)))) | 5921 | (let (buffer-read-only newcat) |
| 5922 | ;; Restore items to end of category's done section and update counts. | 5922 | (widen) |
| 5923 | (with-current-buffer tbuf | 5923 | (goto-char (point-min)) |
| 5924 | (let (buffer-read-only) | 5924 | ;; Find the corresponding todo category, or if there isn't |
| 5925 | (widen) | 5925 | ;; one, add it. |
| 5926 | (goto-char (point-min)) | 5926 | (unless (re-search-forward |
| 5927 | (re-search-forward (concat "^" (regexp-quote | 5927 | (concat "^" (regexp-quote (concat todos-category-beg cat)) |
| 5928 | (concat todos-category-beg cat)) "$") | 5928 | "$") nil t) |
| 5929 | nil t) | 5929 | (todos-add-category nil cat) |
| 5930 | ;; Go to end of category's done section. | 5930 | (setq newcat t) |
| 5931 | (if (re-search-forward (concat "^" (regexp-quote todos-category-beg)) | 5931 | ;; Put point below newly added category beginning, |
| 5932 | nil t) | 5932 | ;; otherwise the following search wrongly succeeds. |
| 5933 | (goto-char (match-beginning 0)) | 5933 | (forward-line)) |
| 5934 | (goto-char (point-max))) | 5934 | ;; Go to end of category's done section. |
| 5935 | (cond (marked | 5935 | (if (re-search-forward (concat "^" (regexp-quote todos-category-beg)) |
| 5936 | (insert marked-items) | 5936 | nil t) |
| 5937 | (todos-update-count 'done marked-count cat) | 5937 | (goto-char (match-beginning 0)) |
| 5938 | (todos-update-count 'archived (- marked-count) cat)) | 5938 | (goto-char (point-max))) |
| 5939 | (all | 5939 | (cond (marked |
| 5940 | (insert all-items) | 5940 | (insert marked-items) |
| 5941 | (todos-update-count 'done all-count cat) | 5941 | (todos-update-count 'done marked-count cat) |
| 5942 | (todos-update-count 'archived (- all-count) cat)) | 5942 | (unless newcat ; Newly added category has no archive. |
| 5943 | (t | 5943 | (todos-update-count 'archived (- marked-count) cat))) |
| 5944 | (insert item) | 5944 | (t |
| 5945 | (todos-update-count 'done 1 cat) | 5945 | (insert item) |
| 5946 | (todos-update-count 'archived -1 cat))) | 5946 | (todos-update-count 'done 1 cat) |
| 5947 | (todos-update-categories-sexp))) | 5947 | (unless newcat ; Newly added category has no archive. |
| 5948 | ;; Delete restored items from archive. | 5948 | (todos-update-count 'archived -1 cat)))) |
| 5949 | (cond ((or marked item) | 5949 | (todos-update-categories-sexp))) |
| 5950 | (and marked (goto-char (point-min))) | 5950 | ;; Delete restored items from archive. |
| 5951 | (catch 'done | 5951 | (when marked |
| 5952 | (while (not (eobp)) | 5952 | (setq item nil) |
| 5953 | (if (or (and marked (todos-marked-item-p)) item) | 5953 | (goto-char (point-min))) |
| 5954 | (progn | 5954 | (catch 'done |
| 5955 | (todos-remove-item) | 5955 | (while (not (eobp)) |
| 5956 | ;; Don't leave point below last item. | 5956 | (if (or (todos-marked-item-p) item) |
| 5957 | (and item (bolp) (eolp) (< (point-min) (point-max)) | 5957 | (progn |
| 5958 | (todos-backward-item)) | 5958 | (todos-remove-item) |
| 5959 | (when item | 5959 | (when item |
| 5960 | (throw 'done (setq item nil)))) | 5960 | (throw 'done (setq item nil)))) |
| 5961 | (todos-forward-item)))) | 5961 | (todos-forward-item)))) |
| 5962 | (todos-update-count 'done (if marked (- marked-count) -1) cat)) | 5962 | (todos-update-count 'done (if marked (- marked-count) -1) cat) |
| 5963 | (all | 5963 | ;; If that was the last category in the archive, delete the whole file. |
| 5964 | (remove-overlays (point-min) (point-max)) | 5964 | (if (= (length todos-categories) 1) |
| 5965 | (delete-region (point-min) (point-max)))) | 5965 | (progn |
| 5966 | ;; If that was the last category in the archive, delete the whole file. | 5966 | (delete-file todos-current-todos-file) |
| 5967 | (if (= (length todos-categories) 1) | 5967 | ;; Kill the archive buffer silently. |
| 5968 | (progn | 5968 | (set-buffer-modified-p nil) |
| 5969 | (delete-file todos-current-todos-file) | 5969 | (kill-buffer)) |
| 5970 | ;; Don't bother confirming killing the archive buffer. | 5970 | ;; Otherwise, if the archive category is now empty, delete it. |
| 5971 | (set-buffer-modified-p nil) | 5971 | (when (eq (point-min) (point-max)) |
| 5972 | (kill-buffer)) | 5972 | (widen) |
| 5973 | ;; Otherwise, if the archive category is now empty, delete it. | 5973 | (let ((beg (re-search-backward |
| 5974 | (when (eq (point-min) (point-max)) | 5974 | (concat "^" (regexp-quote todos-category-beg) cat "$") |
| 5975 | (widen) | 5975 | nil t)) |
| 5976 | (let ((beg (re-search-backward | 5976 | (end (if (re-search-forward |
| 5977 | (concat "^" (regexp-quote todos-category-beg) cat "$") | 5977 | (concat "^" (regexp-quote todos-category-beg)) |
| 5978 | nil t)) | 5978 | nil t 2) |
| 5979 | (end (if (re-search-forward | 5979 | (match-beginning 0) |
| 5980 | (concat "^" (regexp-quote todos-category-beg)) | 5980 | (point-max)))) |
| 5981 | nil t 2) | 5981 | (remove-overlays beg end) |
| 5982 | (match-beginning 0) | 5982 | (delete-region beg end) |
| 5983 | (point-max)))) | 5983 | (setq todos-categories (delete (assoc cat todos-categories) |
| 5984 | (remove-overlays beg end) | 5984 | todos-categories)) |
| 5985 | (delete-region beg end) | 5985 | (todos-update-categories-sexp)))) |
| 5986 | (setq todos-categories (delete (assoc cat todos-categories) | 5986 | ;; Visit category in Todos file and show restored done items. |
| 5987 | todos-categories)) | 5987 | (let ((tfile (buffer-file-name tbuf)) |
| 5988 | (todos-update-categories-sexp)))) | 5988 | (todos-show-with-done t)) |
| 5989 | ;; Visit category in Todos file and show restored done items. | 5989 | (set-window-buffer (selected-window) |
| 5990 | (let ((tfile (buffer-file-name tbuf)) | 5990 | (set-buffer (find-file-noselect tfile))) |
| 5991 | (todos-show-with-done t)) | 5991 | (todos-category-number cat) |
| 5992 | (set-window-buffer (selected-window) | 5992 | (todos-category-select) |
| 5993 | (set-buffer (find-file-noselect tfile))) | 5993 | (message "Items unarchived."))))) |
| 5994 | (todos-category-number cat) | ||
| 5995 | (todos-show) | ||
| 5996 | (message "Items unarchived.")))))) | ||
| 5997 | |||
| 5998 | (defun todos-unarchive-category () | ||
| 5999 | "Unarchive all items in this category. See `todos-unarchive-items'." | ||
| 6000 | (interactive) | ||
| 6001 | (todos-unarchive-items t)) | ||
| 6002 | 5994 | ||
| 6003 | (provide 'todos) | 5995 | (provide 'todos) |
| 6004 | 5996 | ||