diff options
| author | Stephen Berman | 2013-06-19 22:11:03 +0200 |
|---|---|---|
| committer | Stephen Berman | 2013-06-19 22:11:03 +0200 |
| commit | e2ff2f69b9db9bd96bc16dc02ed08cd053ef778c (patch) | |
| tree | 1e2302bb3f4490e8e31855fa76b51a107a15e8d8 /lisp | |
| parent | ddce2e3ed10ae39db765dbc66322cde94e0d6973 (diff) | |
| download | emacs-e2ff2f69b9db9bd96bc16dc02ed08cd053ef778c.tar.gz emacs-e2ff2f69b9db9bd96bc16dc02ed08cd053ef778c.zip | |
* todo-mode.el (todo-convert-legacy-files): Eliminate last change,
since it couldn't avoid namespace clashes, and instead let local
variables hold the legacy values used for conversion. This also
does not interfere with live todo buffers.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/calendar/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/calendar/todo-mode.el | 327 |
2 files changed, 168 insertions, 166 deletions
diff --git a/lisp/calendar/ChangeLog b/lisp/calendar/ChangeLog index 4792cbb336f..ec2b95f25f9 100644 --- a/lisp/calendar/ChangeLog +++ b/lisp/calendar/ChangeLog | |||
| @@ -1,5 +1,12 @@ | |||
| 1 | 2013-06-19 Stephen Berman <stephen.berman@gmx.net> | 1 | 2013-06-19 Stephen Berman <stephen.berman@gmx.net> |
| 2 | 2 | ||
| 3 | * todo-mode.el (todo-convert-legacy-files): Eliminate last change, | ||
| 4 | since it couldn't avoid namespace clashes, and instead let local | ||
| 5 | variables hold the legacy values used for conversion. This also | ||
| 6 | does not interfere with live todo buffers. | ||
| 7 | |||
| 8 | 2013-06-19 Stephen Berman <stephen.berman@gmx.net> | ||
| 9 | |||
| 3 | * todo-mode.el: Rename from todos.el, change all occurrences of | 10 | * todo-mode.el: Rename from todos.el, change all occurrences of |
| 4 | "todos-" prefix to "todo-" and references to "Todos" to "Todo" or | 11 | "todos-" prefix to "todo-" and references to "Todos" to "Todo" or |
| 5 | "Todo mode". | 12 | "Todo mode". |
diff --git a/lisp/calendar/todo-mode.el b/lisp/calendar/todo-mode.el index 12c9fc6973b..8d4b8a9fab8 100644 --- a/lisp/calendar/todo-mode.el +++ b/lisp/calendar/todo-mode.el | |||
| @@ -4485,175 +4485,170 @@ format and saved (the latter as a Todo Archive file) with a new | |||
| 4485 | name in `todo-directory'. See also the documentation string of | 4485 | name in `todo-directory'. See also the documentation string of |
| 4486 | `todo-legacy-date-time-regexp' for further details." | 4486 | `todo-legacy-date-time-regexp' for further details." |
| 4487 | (interactive) | 4487 | (interactive) |
| 4488 | (if todo-file-buffers | 4488 | ;; If there are user customizations of legacy options, use them, |
| 4489 | (message "Before converting you must kill all todo file buffers") | 4489 | ;; otherwise use the legacy default values. |
| 4490 | ;; Before loading legacy code we have to void symbols whose names | 4490 | (let ((todo-file-do-tem (if (boundp 'todo-file-do) |
| 4491 | ;; are the same in the old and new versions, so use placeholders | 4491 | todo-file-do |
| 4492 | ;; during conversion and restore them afterwards. | 4492 | (locate-user-emacs-file "todo-do" ".todo-do"))) |
| 4493 | (let ((todo-categories-tem todo-categories) | 4493 | (todo-file-done-tem (if (boundp 'todo-file-done) |
| 4494 | (todo-prefix-tem todo-prefix) | 4494 | todo-file-done |
| 4495 | (todo-category-beg-tem todo-category-beg)) | 4495 | (locate-user-emacs-file "todo-done" ".todo-done"))) |
| 4496 | ;; (fset 'todo-mode-tem 'todo-mode) | 4496 | (todo-initials-tem (and (boundp 'todo-initials) todo-initials)) |
| 4497 | (makunbound 'todo-categories) | 4497 | (todo-entry-prefix-function-tem (and (boundp 'todo-entry-prefix-function) |
| 4498 | (makunbound 'todo-prefix) | 4498 | todo-entry-prefix-function)) |
| 4499 | (makunbound 'todo-category-beg) | 4499 | todo-categories-tem todo-prefix-tem) |
| 4500 | (fmakunbound 'todo-mode) | 4500 | ;; Convert `todo-file-do'. |
| 4501 | (when (eq this-command 'todo-convert-legacy-files) | 4501 | (if (not (file-exists-p todo-file-do-tem)) |
| 4502 | ;; We can't use require because the feature provided by the | 4502 | (message "No legacy Todo file exists") |
| 4503 | ;; old version is the same as the new version's. | 4503 | (let ((default "todo-do-conv") |
| 4504 | (load "todo-mode")) | 4504 | file archive-sexp) |
| 4505 | ;; Convert `todo-file-do'. | 4505 | (with-temp-buffer |
| 4506 | (if (file-exists-p todo-file-do) | 4506 | (insert-file-contents todo-file-do-tem) |
| 4507 | (let ((default "todo-do-conv") | 4507 | ;; Eliminate old-style local variables list in first line. |
| 4508 | file archive-sexp) | 4508 | (delete-region (line-beginning-position) (1+ (line-end-position))) |
| 4509 | (with-temp-buffer | 4509 | (search-forward " --- " nil t) ; Legacy todo-category-beg. |
| 4510 | (insert-file-contents todo-file-do) | 4510 | (setq todo-prefix-tem (buffer-substring-no-properties |
| 4511 | (let ((end (search-forward ")" (line-end-position) t)) | 4511 | (line-beginning-position) (match-beginning 0))) |
| 4512 | (beg (search-backward "(" (line-beginning-position) t))) | 4512 | (goto-char (point-min)) |
| 4513 | (setq todo-categories | 4513 | (while (not (eobp)) |
| 4514 | (read (buffer-substring-no-properties beg end)))) | 4514 | (cond |
| 4515 | (todo-mode) | 4515 | ;; Old-style category start delimiter. |
| 4516 | (delete-region (line-beginning-position) (1+ (line-end-position))) | 4516 | ((looking-at (regexp-quote (concat todo-prefix-tem " --- "))) |
| 4517 | (replace-match todo-category-beg)) | ||
| 4518 | ;; Old-style category end delimiter. | ||
| 4519 | ((looking-at (regexp-quote "--- End")) | ||
| 4520 | (replace-match "")) | ||
| 4521 | ;; Old-style category separator. | ||
| 4522 | ((looking-at (regexp-quote | ||
| 4523 | (concat todo-prefix-tem " " | ||
| 4524 | (make-string 75 ?-)))) | ||
| 4525 | (replace-match todo-category-done)) | ||
| 4526 | ;; Old-style item header (date/time/initials). | ||
| 4527 | ((looking-at (concat (regexp-quote todo-prefix-tem) " " | ||
| 4528 | (if todo-entry-prefix-function-tem | ||
| 4529 | (funcall todo-entry-prefix-function-tem) | ||
| 4530 | (concat todo-legacy-date-time-regexp " " | ||
| 4531 | (if todo-initials-tem | ||
| 4532 | (regexp-quote todo-initials-tem) | ||
| 4533 | "[^:]*") | ||
| 4534 | ":")))) | ||
| 4535 | (todo-convert-legacy-date-time))) | ||
| 4536 | (forward-line)) | ||
| 4537 | (setq file (concat todo-directory | ||
| 4538 | (read-string | ||
| 4539 | (format "Save file as (default \"%s\"): " default) | ||
| 4540 | nil nil default) | ||
| 4541 | ".todo")) | ||
| 4542 | (write-region (point-min) (point-max) file nil 'nomessage nil t)) | ||
| 4543 | (with-temp-buffer | ||
| 4544 | (insert-file-contents file) | ||
| 4545 | (let ((todo-categories (todo-make-categories-list t))) | ||
| 4546 | (todo-update-categories-sexp)) | ||
| 4547 | (write-region (point-min) (point-max) file nil 'nomessage)) | ||
| 4548 | (setq todo-files (funcall todo-files-function)) | ||
| 4549 | ;; Convert `todo-file-done'. | ||
| 4550 | (when (file-exists-p todo-file-done-tem) | ||
| 4551 | (with-temp-buffer | ||
| 4552 | (insert-file-contents todo-file-done-tem) | ||
| 4553 | (let ((beg (make-marker)) | ||
| 4554 | (end (make-marker)) | ||
| 4555 | cat cats comment item) | ||
| 4517 | (while (not (eobp)) | 4556 | (while (not (eobp)) |
| 4518 | (cond | 4557 | (when (looking-at todo-legacy-date-time-regexp) |
| 4519 | ((looking-at (regexp-quote (concat todo-prefix todo-category-beg))) | 4558 | (set-marker beg (point)) |
| 4520 | (replace-match todo-category-beg-tem)) | 4559 | (todo-convert-legacy-date-time) |
| 4521 | ((looking-at (regexp-quote todo-category-end)) | 4560 | (set-marker end (point)) |
| 4561 | (goto-char beg) | ||
| 4562 | (insert "[" todo-done-string) | ||
| 4563 | (goto-char end) | ||
| 4564 | (insert "]") | ||
| 4565 | (forward-char) | ||
| 4566 | (when (looking-at todo-legacy-date-time-regexp) | ||
| 4567 | (todo-convert-legacy-date-time)) | ||
| 4568 | (when (looking-at (concat " " (if todo-initials-tem | ||
| 4569 | (regexp-quote | ||
| 4570 | todo-initials-tem) | ||
| 4571 | "[^:]*") | ||
| 4572 | ":")) | ||
| 4573 | (replace-match ""))) | ||
| 4574 | (if (re-search-forward | ||
| 4575 | (concat "^" todo-legacy-date-time-regexp) nil t) | ||
| 4576 | (goto-char (match-beginning 0)) | ||
| 4577 | (goto-char (point-max))) | ||
| 4578 | (backward-char) | ||
| 4579 | (when (looking-back "\\[\\([^][]+\\)\\]") | ||
| 4580 | (setq cat (match-string 1)) | ||
| 4581 | (goto-char (match-beginning 0)) | ||
| 4522 | (replace-match "")) | 4582 | (replace-match "")) |
| 4523 | ((looking-at (regexp-quote (concat todo-prefix " " | 4583 | ;; If the item ends with a non-comment parenthesis not |
| 4524 | todo-category-sep))) | 4584 | ;; followed by a period, we lose (but we inherit that |
| 4525 | (replace-match todo-category-done)) | 4585 | ;; problem from the legacy code). |
| 4526 | ((looking-at (concat (regexp-quote todo-prefix) " " | 4586 | (when (looking-back "(\\(.*\\)) ") |
| 4527 | todo-legacy-date-time-regexp " " | 4587 | (setq comment (match-string 1)) |
| 4528 | (regexp-quote todo-initials) ":")) | 4588 | (replace-match "") |
| 4529 | ;; FIXME: Should todo-initials be converted? That | 4589 | (insert "[" todo-comment-string ": " comment "]")) |
| 4530 | ;; would require changes to item insertion and editing. | 4590 | (set-marker end (point)) |
| 4531 | (todo-convert-legacy-date-time))) | 4591 | (if (member cat cats) |
| 4532 | (forward-line)) | 4592 | ;; If item is already in its category, leave it there. |
| 4533 | (setq file (concat todo-directory | 4593 | (unless (save-excursion |
| 4534 | (read-string | 4594 | (re-search-backward |
| 4535 | (format "Save file as (default \"%s\"): " default) | 4595 | (concat "^" (regexp-quote todo-category-beg) |
| 4536 | nil nil default) | ||
| 4537 | ".todo")) | ||
| 4538 | (write-region (point-min) (point-max) file nil 'nomessage nil t)) | ||
| 4539 | (with-temp-buffer | ||
| 4540 | (insert-file-contents file) | ||
| 4541 | (let* ((todo-category-beg todo-category-beg-tem) ; Used by t-m-c-l. | ||
| 4542 | (todo-categories (todo-make-categories-list t))) | ||
| 4543 | (todo-update-categories-sexp)) | ||
| 4544 | (write-region (point-min) (point-max) file nil 'nomessage)) | ||
| 4545 | ;; Convert `todo-file-done'. | ||
| 4546 | (when (file-exists-p todo-file-done) | ||
| 4547 | (with-temp-buffer | ||
| 4548 | (insert-file-contents todo-file-done) | ||
| 4549 | (let ((beg (make-marker)) | ||
| 4550 | (end (make-marker)) | ||
| 4551 | cat cats comment item) | ||
| 4552 | (while (not (eobp)) | ||
| 4553 | (when (looking-at todo-legacy-date-time-regexp) | ||
| 4554 | (set-marker beg (point)) | ||
| 4555 | (todo-convert-legacy-date-time) | ||
| 4556 | (set-marker end (point)) | ||
| 4557 | (goto-char beg) | ||
| 4558 | (insert "[" todo-done-string) | ||
| 4559 | (goto-char end) | ||
| 4560 | (insert "]") | ||
| 4561 | (forward-char) | ||
| 4562 | (when (looking-at todo-legacy-date-time-regexp) | ||
| 4563 | (todo-convert-legacy-date-time)) | ||
| 4564 | (when (looking-at (concat " " | ||
| 4565 | (regexp-quote todo-initials) ":")) | ||
| 4566 | ;; FIXME: Should todo-initials be converted? | ||
| 4567 | (replace-match ""))) | ||
| 4568 | (if (re-search-forward | ||
| 4569 | (concat "^" todo-legacy-date-time-regexp) nil t) | ||
| 4570 | (goto-char (match-beginning 0)) | ||
| 4571 | (goto-char (point-max))) | ||
| 4572 | (backward-char) | ||
| 4573 | (when (looking-back "\\[\\([^][]+\\)\\]") | ||
| 4574 | (setq cat (match-string 1)) | ||
| 4575 | (goto-char (match-beginning 0)) | ||
| 4576 | (replace-match "")) | ||
| 4577 | ;; If the item ends with a non-comment parenthesis not | ||
| 4578 | ;; followed by a period, we lose (but we inherit that problem | ||
| 4579 | ;; from todo-mode.el). | ||
| 4580 | (when (looking-back "(\\(.*\\)) ") | ||
| 4581 | (setq comment (match-string 1)) | ||
| 4582 | (replace-match "") | ||
| 4583 | (insert "[" todo-comment-string ": " comment "]")) | ||
| 4584 | (set-marker end (point)) | ||
| 4585 | (if (member cat cats) | ||
| 4586 | ;; If item is already in its category, leave it there. | ||
| 4587 | (unless (save-excursion | ||
| 4588 | (re-search-backward | ||
| 4589 | (concat "^" (regexp-quote todo-category-beg-tem) | ||
| 4590 | "\\(.*\\)$") nil t) | ||
| 4591 | (string= (match-string 1) cat)) | ||
| 4592 | ;; Else move it to its category. | ||
| 4593 | (setq item (buffer-substring-no-properties beg end)) | ||
| 4594 | (delete-region beg (1+ end)) | ||
| 4595 | (set-marker beg (point)) | ||
| 4596 | (re-search-backward | ||
| 4597 | (concat "^" | ||
| 4598 | (regexp-quote (concat todo-category-beg-tem cat)) | ||
| 4599 | "$") | ||
| 4600 | nil t) | ||
| 4601 | (forward-line) | ||
| 4602 | (if (re-search-forward | ||
| 4603 | (concat "^" (regexp-quote todo-category-beg-tem) | ||
| 4604 | "\\(.*\\)$") nil t) | 4596 | "\\(.*\\)$") nil t) |
| 4605 | (progn (goto-char (match-beginning 0)) | 4597 | (string= (match-string 1) cat)) |
| 4606 | (newline) | 4598 | ;; Else move it to its category. |
| 4607 | (forward-line -1)) | 4599 | (setq item (buffer-substring-no-properties beg end)) |
| 4608 | (goto-char (point-max))) | 4600 | (delete-region beg (1+ end)) |
| 4609 | (insert item "\n") | 4601 | (set-marker beg (point)) |
| 4610 | (goto-char beg)) | 4602 | (re-search-backward |
| 4611 | (push cat cats) | 4603 | (concat "^" |
| 4612 | (goto-char beg) | 4604 | (regexp-quote (concat todo-category-beg cat)) |
| 4613 | (insert todo-category-beg-tem cat "\n\n" | 4605 | "$") |
| 4614 | todo-category-done "\n")) | 4606 | nil t) |
| 4615 | (forward-line)) | 4607 | (forward-line) |
| 4616 | (set-marker beg nil) | 4608 | (if (re-search-forward |
| 4617 | (set-marker end nil)) | 4609 | (concat "^" (regexp-quote todo-category-beg) |
| 4618 | (setq file (concat (file-name-sans-extension file) ".toda")) | 4610 | "\\(.*\\)$") nil t) |
| 4619 | (write-region (point-min) (point-max) file nil 'nomessage nil t)) | 4611 | (progn (goto-char (match-beginning 0)) |
| 4620 | (with-temp-buffer | 4612 | (newline) |
| 4621 | (insert-file-contents file) | 4613 | (forward-line -1)) |
| 4622 | (let* ((todo-category-beg todo-category-beg-tem) ; Used by t-m-c-l. | 4614 | (goto-char (point-max))) |
| 4623 | (todo-categories (todo-make-categories-list t))) | 4615 | (insert item "\n") |
| 4624 | (todo-update-categories-sexp)) | 4616 | (goto-char beg)) |
| 4625 | (write-region (point-min) (point-max) file nil 'nomessage) | 4617 | (push cat cats) |
| 4626 | (setq archive-sexp (read (buffer-substring-no-properties | 4618 | (goto-char beg) |
| 4627 | (line-beginning-position) | 4619 | (insert todo-category-beg cat "\n\n" |
| 4628 | (line-end-position))))) | 4620 | todo-category-done "\n")) |
| 4629 | (setq file (concat (file-name-sans-extension file) ".todo")) | 4621 | (forward-line)) |
| 4630 | ;; Update categories sexp of converted Todo file again, adding | 4622 | (set-marker beg nil) |
| 4631 | ;; counts of archived items. | 4623 | (set-marker end nil)) |
| 4632 | (with-temp-buffer | 4624 | (setq file (concat (file-name-sans-extension file) ".toda")) |
| 4633 | (insert-file-contents file) | 4625 | (write-region (point-min) (point-max) file nil 'nomessage nil t)) |
| 4634 | (let ((sexp (read (buffer-substring-no-properties | 4626 | (with-temp-buffer |
| 4635 | (line-beginning-position) | 4627 | (insert-file-contents file) |
| 4636 | (line-end-position))))) | 4628 | (let* ((todo-categories (todo-make-categories-list t))) |
| 4637 | (dolist (cat sexp) | 4629 | (todo-update-categories-sexp)) |
| 4638 | (let ((archive-cat (assoc (car cat) archive-sexp))) | 4630 | (write-region (point-min) (point-max) file nil 'nomessage) |
| 4639 | (if archive-cat | 4631 | (setq archive-sexp (read (buffer-substring-no-properties |
| 4640 | (aset (cdr cat) 3 (aref (cdr archive-cat) 2))))) | 4632 | (line-beginning-position) |
| 4641 | (delete-region (line-beginning-position) (line-end-position)) | 4633 | (line-end-position))))) |
| 4642 | (prin1 sexp (current-buffer))) | 4634 | (setq file (concat (file-name-sans-extension file) ".todo")) |
| 4643 | (write-region (point-min) (point-max) file nil 'nomessage))) | 4635 | ;; Update categories sexp of converted Todo file again, adding |
| 4644 | (todo-reevaluate-filelist-defcustoms) | 4636 | ;; counts of archived items. |
| 4645 | (message "Format conversion done.")) | 4637 | (with-temp-buffer |
| 4646 | (message "No legacy Todo file exists")) | 4638 | (insert-file-contents file) |
| 4647 | ;; (setq todo-categories todo-categories-tem | 4639 | (let ((sexp (read (buffer-substring-no-properties |
| 4648 | ;; todo-prefix todo-prefix-tem | 4640 | (line-beginning-position) |
| 4649 | ;; todo-category-beg todo-category-beg-tem) | 4641 | (line-end-position))))) |
| 4650 | ;; (fset 'todo-mode 'todo-mode-tem) | 4642 | (dolist (cat sexp) |
| 4651 | ;; (makunbound 'todo-categories-tem) | 4643 | (let ((archive-cat (assoc (car cat) archive-sexp))) |
| 4652 | ;; (makunbound 'todo-prefix-tem) | 4644 | (if archive-cat |
| 4653 | ;; (makunbound 'todo-category-beg-tem) | 4645 | (aset (cdr cat) 3 (aref (cdr archive-cat) 2))))) |
| 4654 | ;; (fmakunbound 'todo-mode-tem) | 4646 | (delete-region (line-beginning-position) (line-end-position)) |
| 4655 | (unload-feature 'todo) | 4647 | (prin1 sexp (current-buffer))) |
| 4656 | (require 'todo)))) | 4648 | (write-region (point-min) (point-max) file nil 'nomessage)) |
| 4649 | (setq todo-archives (funcall todo-files-function t))) | ||
| 4650 | (todo-reevaluate-filelist-defcustoms) | ||
| 4651 | (message "Format conversion done."))))) | ||
| 4657 | 4652 | ||
| 4658 | ;; ----------------------------------------------------------------------------- | 4653 | ;; ----------------------------------------------------------------------------- |
| 4659 | ;;; Utility functions for Todo files, categories and items | 4654 | ;;; Utility functions for Todo files, categories and items |