Permalink
Browse files

new format `%t' for bbdb-anniv-alist

  • Loading branch information...
1 parent 2e1ef24 commit c81dc33a4886766729bf1738078de34449e3b8ba Roland Winkler committed Dec 18, 2011
Showing with 31 additions and 14 deletions.
  1. +6 −0 ChangeLog
  2. +2 −0 TODO
  3. +23 −14 lisp/bbdb-anniv.el
View
@@ -1,3 +1,9 @@
+2011-12-18 Roland Winkler <winkler@gnu.org>
+ * 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 <winkler@gnu.org>
* INSTALL, Makefile.in, aclocal.m4, configure.ac, install-sh:
* lisp/Makefile.in, doc/Makefil.in, doc/bbdb.texi:
View
@@ -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?
View
@@ -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

0 comments on commit c81dc33

Please sign in to comment.