From 7680f777c00609d72e33d03ddbe6797bdf110797 Mon Sep 17 00:00:00 2001 From: Stephen Berman Date: Thu, 25 Apr 2013 00:30:43 +0200 Subject: [PATCH] * calendar/todos.el (todos-check-format): Add check of well-formedness of categories sexp. If it is well-formed but differs from todos-categories, do not signal an error but display a message. --- lisp/calendar/ChangeLog | 6 +++++ lisp/calendar/todos.el | 56 +++++++++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/lisp/calendar/ChangeLog b/lisp/calendar/ChangeLog index 5168fe33671..e3d3b45f5a9 100644 --- a/lisp/calendar/ChangeLog +++ b/lisp/calendar/ChangeLog @@ -1,3 +1,9 @@ +2013-04-24 Stephen Berman + + * todos.el (todos-check-format): Add check of well-formedness of + categories sexp. If it is well-formed but differs from + todos-categories, do not signal an error but display a message. + 2013-04-21 Stephen Berman * todos.el: Fixes and improvements related to item relocation. diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el index 30c64efb0f0..9e1e4904d9c 100644 --- a/lisp/calendar/todos.el +++ b/lisp/calendar/todos.el @@ -1066,31 +1066,45 @@ short Todos Archive or Top Priorities file name, respectively." (defun todos-check-format () "Signal an error if the current Todos file is ill-formatted. -Otherwise return t. The error message gives the line number -where the invalid formatting was found." +Otherwise return t. Display a message if the file is well-formed +but the categories sexp differs from the current value of +`todos-categories'." (save-excursion (save-restriction (widen) (goto-char (point-min)) - (let ((cats (prin1-to-string todos-categories)) - (sexp (buffer-substring-no-properties (line-beginning-position) - (line-end-position)))) - ;; Check for `todos-categories' sexp as the first line - (unless (string= sexp cats) - (error "Invalid or missing todos-categories sexp"))) - (forward-line) - (let ((legit (concat "\\(^" (regexp-quote todos-category-beg) "\\)" - "\\|\\(" todos-date-string-start todos-date-pattern "\\)" - "\\|\\(^[ \t]+[^ \t]*\\)" - "\\|^$" - "\\|\\(^" (regexp-quote todos-category-done) "\\)" - "\\|\\(" todos-done-string-start "\\)"))) - (while (not (eobp)) - (unless (looking-at legit) - (error "Illegitimate Todos file format at line %d" - (line-number-at-pos (point)))) - (forward-line))))) - ;; (message "This Todos file is well-formatted.") + (let* ((cats (prin1-to-string todos-categories)) + (ssexp (buffer-substring-no-properties (line-beginning-position) + (line-end-position))) + (sexp (read ssexp))) + ;; Check the first line for `todos-categories' sexp. + (dolist (c sexp) + (let ((v (cdr c))) + (unless (and (stringp (car c)) + (vectorp v) + (= 4 (length v))) + (error "Invalid or missing todos-categories sexp")))) + (forward-line) + ;; Check well-formedness of categories. + (let ((legit (concat "\\(^" (regexp-quote todos-category-beg) "\\)" + "\\|\\(" todos-date-string-start todos-date-pattern "\\)" + "\\|\\(^[ \t]+[^ \t]*\\)" + "\\|^$" + "\\|\\(^" (regexp-quote todos-category-done) "\\)" + "\\|\\(" todos-done-string-start "\\)"))) + (while (not (eobp)) + (unless (looking-at legit) + (error "Illegitimate Todos file format at line %d" + (line-number-at-pos (point)))) + (forward-line))) + ;; Warn user if categories sexp has changed. + (unless (string= ssexp cats) + (message (concat "The sexp at the beginning of the file differs " + "from the value of `todos-categories.\n" + "If the sexp is wrong, you can fix it with " + "M-x todos-repair-categories-sexp,\n" + "but note this reverts any changes you have " + "made in the order of the categories.")))))) t) ;; --------------------------------------------------------------------------- -- 2.39.5