From c81dc33a4886766729bf1738078de34449e3b8ba Mon Sep 17 00:00:00 2001 From: Roland Winkler Date: Sun, 18 Dec 2011 13:30:40 -0600 Subject: [PATCH] new format `%t' for bbdb-anniv-alist --- ChangeLog | 6 ++++++ TODO | 2 ++ lisp/bbdb-anniv.el | 37 +++++++++++++++++++++++-------------- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 05d4051..15b2fcf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-12-18 Roland Winkler + * lisp/bbdb-anniv.el (bbdb-anniv-alist): New format specification + `%t'. + (bbdb-anniv-diary-entries): Use it. Handle diary's backup forms + in better a way. + 2011-12-11 Roland Winkler * INSTALL, Makefile.in, aclocal.m4, configure.ac, install-sh: * lisp/Makefile.in, doc/Makefil.in, doc/bbdb.texi: diff --git a/TODO b/TODO index 49c487f..0d494f6 100644 --- a/TODO +++ b/TODO @@ -44,6 +44,8 @@ See the end of the file for license conditions. ** Allow splitting of bbdb-file into multiple files +** bbdb-narrow-display: Inverse of bbdb-append-display + * Internals ** Remove bbdb-auto-notes-rules-expanded? diff --git a/lisp/bbdb-anniv.el b/lisp/bbdb-anniv.el index 5e83cc2..372aaf0 100644 --- a/lisp/bbdb-anniv.el +++ b/lisp/bbdb-anniv.el @@ -26,7 +26,6 @@ ;; In particular, `calendar-date-style' is obeyed via `diary-date-forms'. ;; If `bbdb-anniv-alist' has a non-nil FORM for this type of anniversary, ;; FORM is used to display the anniversary entry in the diary buffer. -;; In this case TEXT is ignored. ;; If FORM is nil, TEXT is used instead to display the anniversary entry ;; in the diary buffer. ;; @@ -50,6 +49,7 @@ FORM is a format string with the following substitutions: %n name of the record %d number of years %s ordinal suffix (st, nd, rd, th) for the year. + %t the optional text following the date string in an anniversary field. If FORM is nil, the format string is taken from the anniversary field of each record." :type '(repeat (cons :tag "Rule" @@ -126,23 +126,32 @@ To enable this feature, put the following into your .emacs: (dolist (rule bbdb-anniv-alist) (dolist (anniv (bbdb-record-note-split record (car rule))) (let ((date-forms date-forms) - (anniv-string (concat anniv " XX")) ; for backup forms + (anniv-string (concat anniv " X")) ; for backup forms (case-fold-search t) form yy text) (while (setq form (pop date-forms)) - (if (string-match (car form) anniv-string) - (setq date-forms nil - yy (match-string 1 anniv-string) - yy (if (and yy (string-match-p "[0-9]+" yy)) - (- current-year (string-to-number yy)) - 100) ; as in `diary-anniversary' - text (or (cdr rule) - (substring anniv-string - (if (cdr form) (1- (match-end 0)) - (match-end 0)) - -3))))) + (when (string-match (car form) anniv-string) + (setq date-forms nil + yy (match-string 1 anniv-string) + yy (if (and yy (string-match-p "[0-9]+" yy)) + (- current-year (string-to-number yy)) + 100) ; as in `diary-anniversary' + ;; For backup forms we should search backward in + ;; anniv-string from (match-end 0) for "\\<". + ;; That gets too complicated here! + ;; Yet for the default value of `diary-date-forms' + ;; this would matter only if anniv-string started + ;; with a time. That is rather rare for anniversaries. + ;; Then we may simply step backward by one character. + text (substring anniv-string (if (cdr form) ; backup + (1- (match-end 0)) + (match-end 0)) -1)) + (if (cdr rule) + (setq text (replace-regexp-in-string "%t" text (cdr rule)))) + (setq text (replace-regexp-in-string "\\`[ \t]+" "" text) + text (replace-regexp-in-string "[ \t]+\\'" "" text)))) ;; Add the anniversaries to `diary-entries-list'. - (if (and yy (> yy 0)) + (if (and yy (> yy 0) (< 0 (length text))) (diary-add-to-list date (format