From d7a49dae500b62803d35dfc47d99f462479fb66d Mon Sep 17 00:00:00 2001 From: Stephen Berman Date: Sun, 9 Jun 2013 21:16:39 +0200 Subject: [PATCH] * todos.el: Fix and improve item date string editing. (todos-date-pattern): Make dayname an explicitly numbered group. (todos-basic-edit-item-header): Set match for dayname and use it to ensure attempting to edit day, month or year of a date header containing a day name is a noop, simplifying and fixing buggy code. --- lisp/calendar/ChangeLog | 8 ++++++++ lisp/calendar/todos.el | 19 +++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lisp/calendar/ChangeLog b/lisp/calendar/ChangeLog index b09cf30f1c7..0d8fda0d147 100644 --- a/lisp/calendar/ChangeLog +++ b/lisp/calendar/ChangeLog @@ -1,3 +1,11 @@ +2013-06-09 Stephen Berman + + * todos.el: Fix and improve item date string editing. + (todos-date-pattern): Make dayname an explicitly numbered group. + (todos-basic-edit-item-header): Set match for dayname and use it + to ensure attempting to edit day, month or year of a date header + containing a day name is a noop, simplifying and fixing buggy code. + 2013-06-08 Stephen Berman * todos.el: Improve commentary. diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el index 6d79fadd106..4f83ead0d48 100644 --- a/lisp/calendar/todos.el +++ b/lisp/calendar/todos.el @@ -211,7 +211,7 @@ The final element is \"*\", indicating an unspecified month.") (defconst todos-date-pattern (let ((dayname (diary-name-pattern calendar-day-name-array nil t))) - (concat "\\(?5:" dayname "\\|" + (concat "\\(?4:\\(?5:" dayname "\\)\\|" (let ((dayname) (monthname (format "\\(?6:%s\\)" (diary-name-pattern todos-month-name-array @@ -2099,6 +2099,7 @@ otherwise, edit just the item at point." (line-end-position) t) (let* ((odate (match-string-no-properties 1)) (otime (match-string-no-properties 2)) + (odayname (match-string-no-properties 5)) (omonthname (match-string-no-properties 6)) (omonth (match-string-no-properties 7)) (oday (match-string-no-properties 8)) @@ -2133,9 +2134,8 @@ otherwise, edit just the item at point." (when (> (length ntime) 0) (setq ntime (concat " " ntime)))) ;; When date string consists only of a day name, - ;; passing other date components is a NOP. - ((and (memq what '(year month day)) - (not (or oyear omonth oday)))) + ;; passing other date components is a noop. + ((and odayname (memq what '(year month day)))) ((eq what 'year) (setq day oday monthname omonthname @@ -2220,12 +2220,11 @@ otherwise, edit just the item at point." (setq monthname (aref tma-array (1- adjmm)))) ;; Return changed numerical day as a string. (number-to-string (nth 1 date))))))))) - ;; If new year, month or day date string components were - ;; calculated, rebuild the whole date string from them. - (when (memq what '(year month day)) - (if (or oyear omonth omonthname oday) - (setq ndate (mapconcat 'eval calendar-date-display-form "")) - (message "Cannot edit date component of empty date string"))) + (unless odayname + ;; If year, month or day date string components were + ;; changed, rebuild the date string. + (when (memq what '(year month day)) + (setq ndate (mapconcat 'eval calendar-date-display-form "")))) (when ndate (replace-match ndate nil nil nil 1)) ;; Add new time string to the header, if it was supplied. (when ntime -- 2.39.2