aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Berman2013-04-25 00:30:43 +0200
committerStephen Berman2013-04-25 00:30:43 +0200
commit7680f777c00609d72e33d03ddbe6797bdf110797 (patch)
treef1dc85e3a4eed7b211fe33e678a1f337e0194516
parent308f5beb340bfa840f427eae1bbd3d4193930d7f (diff)
downloademacs-7680f777c00609d72e33d03ddbe6797bdf110797.tar.gz
emacs-7680f777c00609d72e33d03ddbe6797bdf110797.zip
* 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.
-rw-r--r--lisp/calendar/ChangeLog6
-rw-r--r--lisp/calendar/todos.el56
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 @@
12013-04-24 Stephen Berman <stephen.berman@gmx.net>
2
3 * todos.el (todos-check-format): Add check of well-formedness of
4 categories sexp. If it is well-formed but differs from
5 todos-categories, do not signal an error but display a message.
6
12013-04-21 Stephen Berman <stephen.berman@gmx.net> 72013-04-21 Stephen Berman <stephen.berman@gmx.net>
2 8
3 * todos.el: Fixes and improvements related to item relocation. 9 * 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."
1066 1066
1067(defun todos-check-format () 1067(defun todos-check-format ()
1068 "Signal an error if the current Todos file is ill-formatted. 1068 "Signal an error if the current Todos file is ill-formatted.
1069Otherwise return t. The error message gives the line number 1069Otherwise return t. Display a message if the file is well-formed
1070where the invalid formatting was found." 1070but the categories sexp differs from the current value of
1071`todos-categories'."
1071 (save-excursion 1072 (save-excursion
1072 (save-restriction 1073 (save-restriction
1073 (widen) 1074 (widen)
1074 (goto-char (point-min)) 1075 (goto-char (point-min))
1075 (let ((cats (prin1-to-string todos-categories)) 1076 (let* ((cats (prin1-to-string todos-categories))
1076 (sexp (buffer-substring-no-properties (line-beginning-position) 1077 (ssexp (buffer-substring-no-properties (line-beginning-position)
1077 (line-end-position)))) 1078 (line-end-position)))
1078 ;; Check for `todos-categories' sexp as the first line 1079 (sexp (read ssexp)))
1079 (unless (string= sexp cats) 1080 ;; Check the first line for `todos-categories' sexp.
1080 (error "Invalid or missing todos-categories sexp"))) 1081 (dolist (c sexp)
1081 (forward-line) 1082 (let ((v (cdr c)))
1082 (let ((legit (concat "\\(^" (regexp-quote todos-category-beg) "\\)" 1083 (unless (and (stringp (car c))
1083 "\\|\\(" todos-date-string-start todos-date-pattern "\\)" 1084 (vectorp v)
1084 "\\|\\(^[ \t]+[^ \t]*\\)" 1085 (= 4 (length v)))
1085 "\\|^$" 1086 (error "Invalid or missing todos-categories sexp"))))
1086 "\\|\\(^" (regexp-quote todos-category-done) "\\)" 1087 (forward-line)
1087 "\\|\\(" todos-done-string-start "\\)"))) 1088 ;; Check well-formedness of categories.
1088 (while (not (eobp)) 1089 (let ((legit (concat "\\(^" (regexp-quote todos-category-beg) "\\)"
1089 (unless (looking-at legit) 1090 "\\|\\(" todos-date-string-start todos-date-pattern "\\)"
1090 (error "Illegitimate Todos file format at line %d" 1091 "\\|\\(^[ \t]+[^ \t]*\\)"
1091 (line-number-at-pos (point)))) 1092 "\\|^$"
1092 (forward-line))))) 1093 "\\|\\(^" (regexp-quote todos-category-done) "\\)"
1093 ;; (message "This Todos file is well-formatted.") 1094 "\\|\\(" todos-done-string-start "\\)")))
1095 (while (not (eobp))
1096 (unless (looking-at legit)
1097 (error "Illegitimate Todos file format at line %d"
1098 (line-number-at-pos (point))))
1099 (forward-line)))
1100 ;; Warn user if categories sexp has changed.
1101 (unless (string= ssexp cats)
1102 (message (concat "The sexp at the beginning of the file differs "
1103 "from the value of `todos-categories.\n"
1104 "If the sexp is wrong, you can fix it with "
1105 "M-x todos-repair-categories-sexp,\n"
1106 "but note this reverts any changes you have "
1107 "made in the order of the categories."))))))
1094 t) 1108 t)
1095 1109
1096;; --------------------------------------------------------------------------- 1110;; ---------------------------------------------------------------------------