ol-bbdb.el 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. ;;; ol-bbdb.el --- Links to BBDB entries -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. ;; Authors: Carsten Dominik <carsten.dominik@gmail.com>
  4. ;; Thomas Baumann <thomas dot baumann at ch dot tum dot de>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; URL: https://orgmode.org
  7. ;;
  8. ;; This file is part of GNU Emacs.
  9. ;;
  10. ;; GNU Emacs is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21. ;;
  22. ;;; Commentary:
  23. ;; This file implements links to BBDB database entries from within Org.
  24. ;; Org mode loads this module by default - if this is not what you want,
  25. ;; configure the variable `org-modules'.
  26. ;; It also implements an interface (based on Ivar Rummelhoff's
  27. ;; bbdb-anniv.el) for those Org users, who do not use the diary
  28. ;; but who do want to include the anniversaries stored in the BBDB
  29. ;; into the org-agenda. If you already include the `diary' into the
  30. ;; agenda, you might want to prefer to include the anniversaries in
  31. ;; the diary using bbdb-anniv.el.
  32. ;;
  33. ;; Put the following in /somewhere/at/home/diary.org and make sure
  34. ;; that this file is in `org-agenda-files'.
  35. ;;
  36. ;; %%(org-bbdb-anniversaries)
  37. ;;
  38. ;; For example my diary.org looks like:
  39. ;; * Anniversaries
  40. ;; #+CATEGORY: Anniv
  41. ;; %%(org-bbdb-anniversaries)
  42. ;;
  43. ;;
  44. ;; To add an anniversary to a BBDB record, press `C-o' in the record.
  45. ;; You will be prompted for the field name, in this case it must be
  46. ;; "anniversary". If this is the first time you are using this field,
  47. ;; you need to confirm that it should be created.
  48. ;;
  49. ;; The format of an anniversary field stored in BBDB is the following
  50. ;; (items in {} are optional):
  51. ;;
  52. ;; YYYY-MM-DD{ CLASS-OR-FORMAT-STRING}
  53. ;; {\nYYYY-MM-DD CLASS-OR-FORMAT-STRING}...
  54. ;;
  55. ;; CLASS-OR-FORMAT-STRING is one of two things:
  56. ;;
  57. ;; - an identifier for a class of anniversaries (e.g. birthday or
  58. ;; wedding) from `org-bbdb-anniversary-format-alist' which then
  59. ;; defines the format string for this class
  60. ;; - the (format) string displayed in the diary.
  61. ;;
  62. ;; You can enter multiple anniversaries for a single BBDB record by
  63. ;; separating them with a newline character. At the BBDB prompt for
  64. ;; the field value, type `C-q C-j' to enter a newline between two
  65. ;; anniversaries.
  66. ;;
  67. ;; If you omit the CLASS-OR-FORMAT-STRING entirely, it defaults to the
  68. ;; value of `org-bbdb-default-anniversary-format' ("birthday" by
  69. ;; default).
  70. ;;
  71. ;; The substitutions in the format string are (in order):
  72. ;; - the name of the record containing this anniversary
  73. ;; - the number of years
  74. ;; - an ordinal suffix (st, nd, rd, th) for the year
  75. ;;
  76. ;; See the documentation of `org-bbdb-anniversary-format-alist' for
  77. ;; further options.
  78. ;;
  79. ;; Example
  80. ;;
  81. ;; 1973-06-22
  82. ;; 20??-??-?? wedding
  83. ;; 1998-03-12 %s created bbdb-anniv.el %d years ago
  84. ;;
  85. ;; From Org's agenda, you can use `C-c C-o' to jump to the BBDB
  86. ;; link from which the entry at point originates.
  87. ;;
  88. ;;; Code:
  89. (require 'org-macs)
  90. (org-assert-version)
  91. (require 'cl-lib)
  92. (require 'org-compat)
  93. (require 'org-macs)
  94. (require 'ol)
  95. ;;; Declare functions and variables
  96. (declare-function bbdb "ext:bbdb-com" (string elidep))
  97. (declare-function bbdb-company "ext:bbdb-com" (string elidep))
  98. (declare-function bbdb-current-record "ext:bbdb-com" (&optional planning-on-modifying))
  99. (declare-function bbdb-name "ext:bbdb-com" (string elidep))
  100. (declare-function bbdb-completing-read-record "ext:bbdb-com" (prompt &optional omit-records))
  101. (declare-function bbdb-record-field "ext:bbdb" (record field))
  102. (declare-function bbdb-record-getprop "ext:bbdb" (record property))
  103. (declare-function bbdb-record-name "ext:bbdb" (record))
  104. (declare-function bbdb-records "ext:bbdb" (&optional dont-check-disk already-in-db-buffer))
  105. (declare-function bbdb-split "ext:bbdb" (string separators))
  106. (declare-function bbdb-string-trim "ext:bbdb" (string))
  107. (declare-function bbdb-record-get-field "ext:bbdb" (record field))
  108. (declare-function bbdb-search-name "ext:bbdb-com" (regexp &optional layout))
  109. (declare-function bbdb-search-organization "ext:bbdb-com" (regexp &optional layout))
  110. ;; `bbdb-record-note' was part of BBDB v3.x
  111. (declare-function bbdb-record-note "ext:bbdb" (record label))
  112. ;; `bbdb-record-xfield' replaces it in recent BBDB v3.x+
  113. (declare-function bbdb-record-xfield "ext:bbdb" (record label))
  114. (declare-function calendar-absolute-from-gregorian "calendar" (date))
  115. (declare-function calendar-gregorian-from-absolute "calendar" (date))
  116. (declare-function calendar-leap-year-p "calendar" (year))
  117. (declare-function diary-ordinal-suffix "diary-lib" (n))
  118. (with-no-warnings (defvar date)) ; unprefixed, from calendar.el
  119. ;;; Customization
  120. (defgroup org-bbdb-anniversaries nil
  121. "Customizations for including anniversaries from BBDB into Agenda."
  122. :group 'org-bbdb)
  123. (defcustom org-bbdb-default-anniversary-format "birthday"
  124. "Default anniversary class."
  125. :type 'string
  126. :group 'org-bbdb-anniversaries
  127. :require 'bbdb)
  128. (defcustom org-bbdb-general-anniversary-description-after 7
  129. "When to switch anniversary descriptions to a more general format.
  130. Anniversary descriptions include the point in time, when the
  131. anniversary appears. This is, in its most general form, just the
  132. date of the anniversary. Or more specific terms, like \"today\",
  133. \"tomorrow\" or \"in n days\" are used to describe the time span.
  134. If the anniversary happens in less than that number of days, the
  135. specific description is used. Otherwise, the general one is
  136. used."
  137. :group 'org-bbdb-anniversaries
  138. :version "26.1"
  139. :package-version '(Org . "9.1")
  140. :type 'integer
  141. :require 'bbdb
  142. :safe #'integerp)
  143. (defcustom org-bbdb-anniversary-format-alist
  144. '(("birthday" .
  145. (lambda (name years suffix)
  146. (concat "Birthday: [[bbdb:" name "][" name " ("
  147. (format "%s" years) ; handles numbers as well as strings
  148. suffix ")]]")))
  149. ("wedding" .
  150. (lambda (name years suffix)
  151. (concat "[[bbdb:" name "][" name "'s "
  152. (format "%s" years)
  153. suffix " wedding anniversary]]"))))
  154. "How different types of anniversaries should be formatted.
  155. An alist of elements (STRING . FORMAT) where STRING is the name of an
  156. anniversary class and format is either:
  157. 1) A format string with the following substitutions (in order):
  158. - the name of the record containing this anniversary
  159. - the number of years
  160. - an ordinal suffix (st, nd, rd, th) for the year
  161. 2) A function to be called with three arguments: NAME YEARS SUFFIX
  162. (string int string) returning a string for the diary or nil.
  163. 3) An Emacs Lisp form that should evaluate to a string (or nil) in the
  164. scope of variables NAME, YEARS and SUFFIX (among others)."
  165. :type '(alist :key-type (string :tag "Class")
  166. :value-type (function :tag "Function"))
  167. :group 'org-bbdb-anniversaries
  168. :require 'bbdb)
  169. (defcustom org-bbdb-anniversary-field 'anniversary
  170. "The BBDB field which contains anniversaries.
  171. The anniversaries are stored in the following format
  172. YYYY-MM-DD Class-or-Format-String
  173. where class is one of the customized classes for anniversaries;
  174. birthday and wedding are predefined. Format-String can take three
  175. substitutions 1) the name of the record containing this
  176. anniversary, 2) the number of years, and 3) an ordinal suffix for
  177. the year.
  178. Multiple anniversaries can be separated by \\n."
  179. :type 'symbol
  180. :group 'org-bbdb-anniversaries
  181. :require 'bbdb)
  182. (defcustom org-bbdb-extract-date-fun 'org-bbdb-anniv-extract-date
  183. "How to retrieve `month date year' from the anniversary field.
  184. Customize if you have already filled your BBDB with dates
  185. different from YYYY-MM-DD. The function must return a list (month
  186. date year)."
  187. :type 'function
  188. :group 'org-bbdb-anniversaries
  189. :require 'bbdb)
  190. ;; Install the link type
  191. (org-link-set-parameters "bbdb"
  192. :follow #'org-bbdb-open
  193. :export #'org-bbdb-export
  194. :complete #'org-bbdb-complete-link
  195. :store #'org-bbdb-store-link)
  196. ;;; Implementation
  197. (defun org-bbdb-store-link ()
  198. "Store a link to a BBDB database entry."
  199. (when (eq major-mode 'bbdb-mode)
  200. ;; This is BBDB, we make this link!
  201. (let* ((rec (bbdb-current-record))
  202. (name (bbdb-record-name rec))
  203. (company (if (fboundp 'bbdb-record-getprop)
  204. (bbdb-record-getprop rec 'company)
  205. (car (bbdb-record-field rec 'organization))))
  206. (link (concat "bbdb:" name)))
  207. (org-link-store-props :type "bbdb" :name name :company company
  208. :link link :description name)
  209. link)))
  210. (defun org-bbdb-export (path desc format _)
  211. "Create the export version of a BBDB link specified by PATH or DESC.
  212. If exporting to either HTML or LaTeX FORMAT the link will be
  213. italicized, in all other cases it is left unchanged."
  214. (when (string= desc (format "bbdb:%s" path))
  215. (setq desc path))
  216. (cond
  217. ((eq format 'html) (format "<i>%s</i>" desc))
  218. ((eq format 'latex) (format "\\textit{%s}" desc))
  219. ((eq format 'odt)
  220. (format "<text:span text:style-name=\"Emphasis\">%s</text:span>" desc))
  221. (t desc)))
  222. (defun org-bbdb-open (name _)
  223. "Follow a BBDB link to NAME."
  224. (require 'bbdb-com)
  225. (let ((inhibit-redisplay (not debug-on-error)))
  226. (if (fboundp 'bbdb-name)
  227. (org-bbdb-open-old name)
  228. (org-bbdb-open-new name))))
  229. (defun org-bbdb-open-old (name)
  230. (catch 'exit
  231. ;; Exact match on name
  232. (bbdb-name (concat "\\`" name "\\'") nil)
  233. (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
  234. ;; Exact match on name
  235. (bbdb-company (concat "\\`" name "\\'") nil)
  236. (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
  237. ;; Partial match on name
  238. (bbdb-name name nil)
  239. (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
  240. ;; Partial match on company
  241. (bbdb-company name nil)
  242. (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
  243. ;; General match including network address and notes
  244. (bbdb name nil)
  245. (when (= 0 (buffer-size (get-buffer "*BBDB*")))
  246. (delete-window (get-buffer-window "*BBDB*"))
  247. (error "No matching BBDB record"))))
  248. (defun org-bbdb-open-new (name)
  249. (catch 'exit
  250. ;; Exact match on name
  251. (bbdb-search-name (concat "\\`" name "\\'") nil)
  252. (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
  253. ;; Exact match on name
  254. (bbdb-search-organization (concat "\\`" name "\\'") nil)
  255. (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
  256. ;; Partial match on name
  257. (bbdb-search-name name nil)
  258. (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
  259. ;; Partial match on company
  260. (bbdb-search-organization name nil)
  261. (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
  262. ;; General match including network address and notes
  263. (bbdb name nil)
  264. (when (= 0 (buffer-size (get-buffer "*BBDB*")))
  265. (delete-window (get-buffer-window "*BBDB*"))
  266. (error "No matching BBDB record"))))
  267. (defun org-bbdb-anniv-extract-date (time-str)
  268. "Convert YYYY-MM-DD to (month date year).
  269. Argument TIME-STR is the value retrieved from BBDB. If YYYY- is omitted
  270. it will be considered unknown."
  271. (pcase (org-split-string time-str "-")
  272. (`(,a ,b) (list (string-to-number a) (string-to-number b) nil))
  273. (`(,a ,b ,c) (list (string-to-number b)
  274. (string-to-number c)
  275. (string-to-number a)))))
  276. (defun org-bbdb-anniv-split (str)
  277. "Split multiple entries in the BBDB anniversary field.
  278. Argument STR is the anniversary field in BBDB."
  279. (let ((pos (string-match "[ \t]" str)))
  280. (if pos (list (substring str 0 pos)
  281. (bbdb-string-trim (substring str pos)))
  282. (list str nil))))
  283. (defvar org-bbdb-anniv-hash nil
  284. "A hash holding anniversaries extracted from BBDB.
  285. The hash table is created on first use.")
  286. (defvar org-bbdb-updated-p t
  287. "This is non-nil if BBDB has been updated since we last built the hash.")
  288. (defun org-bbdb-make-anniv-hash ()
  289. "Create a hash with anniversaries extracted from BBDB, for fast access.
  290. The anniversaries are assumed to be stored `org-bbdb-anniversary-field'."
  291. (let ((old-bbdb (fboundp 'bbdb-record-getprop))
  292. (record-func (if (fboundp 'bbdb-record-xfield)
  293. 'bbdb-record-xfield
  294. 'bbdb-record-note))
  295. split tmp annivs)
  296. (clrhash org-bbdb-anniv-hash)
  297. (dolist (rec (bbdb-records))
  298. (when (setq annivs (if old-bbdb
  299. (bbdb-record-getprop
  300. rec org-bbdb-anniversary-field)
  301. (funcall record-func
  302. rec org-bbdb-anniversary-field)))
  303. (setq annivs (if old-bbdb
  304. (bbdb-split annivs "\n")
  305. ;; parameter order is reversed in new bbdb
  306. (bbdb-split "\n" annivs)))
  307. (while annivs
  308. (setq split (org-bbdb-anniv-split (pop annivs)))
  309. (pcase-let ((`(,m ,d ,y) (funcall org-bbdb-extract-date-fun
  310. (car split))))
  311. (setq tmp (gethash (list m d) org-bbdb-anniv-hash))
  312. (puthash (list m d) (cons (list y
  313. (bbdb-record-name rec)
  314. (cadr split))
  315. tmp)
  316. org-bbdb-anniv-hash))))))
  317. (setq org-bbdb-updated-p nil))
  318. (defun org-bbdb-updated (_rec)
  319. "Record the fact that BBDB has been updated.
  320. This is used by Org to re-create the anniversary hash table."
  321. (setq org-bbdb-updated-p t))
  322. (add-hook 'bbdb-after-change-hook 'org-bbdb-updated)
  323. ;;;###autoload
  324. (defun org-bbdb-anniversaries ()
  325. "Extract anniversaries from BBDB for display in the agenda.
  326. When called programmatically, this function expects the `date'
  327. variable to be globally bound."
  328. (require 'bbdb)
  329. (require 'diary-lib)
  330. (unless (hash-table-p org-bbdb-anniv-hash)
  331. (setq org-bbdb-anniv-hash
  332. (make-hash-table :test 'equal :size 366)))
  333. (when (or org-bbdb-updated-p
  334. (= 0 (hash-table-count org-bbdb-anniv-hash)))
  335. (org-bbdb-make-anniv-hash))
  336. (let* ((m (car date)) ; month
  337. (d (nth 1 date)) ; day
  338. (y (nth 2 date)) ; year
  339. (annivs (gethash (list m d) org-bbdb-anniv-hash))
  340. (text ())
  341. rec recs)
  342. ;; We don't want to miss people born on Feb. 29th
  343. (when (and (= m 3) (= d 1)
  344. (not (null (gethash (list 2 29) org-bbdb-anniv-hash)))
  345. (not (calendar-leap-year-p y)))
  346. (setq recs (gethash (list 2 29) org-bbdb-anniv-hash))
  347. (while (setq rec (pop recs))
  348. (push rec annivs)))
  349. (when annivs
  350. (while (setq rec (pop annivs))
  351. (when rec
  352. (let* ((class (or (nth 2 rec)
  353. org-bbdb-default-anniversary-format))
  354. (form (or (cdr (assoc-string
  355. class org-bbdb-anniversary-format-alist t))
  356. class)) ; (as format string)
  357. (name (nth 1 rec))
  358. (years (if (eq (car rec) nil)
  359. "unknown"
  360. (- y (car rec))))
  361. (suffix (if (eq (car rec) nil)
  362. ""
  363. (diary-ordinal-suffix years)))
  364. (tmp (cond
  365. ((functionp form)
  366. (funcall form name years suffix))
  367. ((listp form) (eval form))
  368. (t (format form name years suffix)))))
  369. (org-add-props tmp nil 'org-bbdb-name name)
  370. (if text
  371. (setq text (append text (list tmp)))
  372. (setq text (list tmp)))))
  373. ))
  374. text))
  375. ;;; Return the list of anniversaries for today and the next n-1
  376. ;;; (default: n=7) days. This is meant to be used in an org file
  377. ;;; instead of org-bbdb-anniversaries:
  378. ;;;
  379. ;;; %%(org-bbdb-anniversaries-future)
  380. ;;;
  381. ;;; or
  382. ;;;
  383. ;;; %%(org-bbdb-anniversaries-future 3)
  384. ;;;
  385. ;;; to override the 7-day default.
  386. (defun org-bbdb-date-list (d n)
  387. "Return list of dates in (m d y) format from the given date D to n-1 days hence."
  388. (let ((abs (calendar-absolute-from-gregorian d)))
  389. (mapcar (lambda (i) (calendar-gregorian-from-absolute (+ abs i)))
  390. (number-sequence 0 (1- n)))))
  391. (defun org-bbdb-anniversary-description (agenda-date anniv-date)
  392. "Return a string used to incorporate into an agenda anniversary entry.
  393. The calculation of the anniversary description string is based on
  394. the difference between the anniversary date, given as ANNIV-DATE,
  395. and the date on which the entry appears in the agenda, given as
  396. AGENDA-DATE. This makes it possible to have different entries
  397. for the same event depending on if it occurs in the next few days
  398. or far away in the future."
  399. (let ((delta (- (calendar-absolute-from-gregorian anniv-date)
  400. (calendar-absolute-from-gregorian agenda-date))))
  401. (cond
  402. ((= delta 0) " -- today\\&")
  403. ((= delta 1) " -- tomorrow\\&")
  404. ((< delta org-bbdb-general-anniversary-description-after)
  405. (format " -- in %d days\\&" delta))
  406. ((pcase-let ((`(,month ,day ,year) anniv-date))
  407. (format " -- %d-%02d-%02d\\&" year month day))))))
  408. (defun org-bbdb-anniversaries-future (&optional n)
  409. "Return list of anniversaries for today and the next n-1 days (default n=7)."
  410. (let ((n (or n 7)))
  411. (when (<= n 0)
  412. (error "The (optional) argument of `org-bbdb-anniversaries-future' \
  413. must be positive"))
  414. (let (
  415. ;; List of relevant dates.
  416. (dates (org-bbdb-date-list date n))
  417. ;; Function to annotate text of each element of l with the
  418. ;; anniversary date d.
  419. (annotate-descriptions
  420. (lambda (agenda-date d l)
  421. (mapcar (lambda (x)
  422. ;; The assumption here is that x is a bbdb link
  423. ;; of the form [[bbdb:name][description]].
  424. ;; This function rather arbitrarily modifies
  425. ;; the description by adding the date to it in
  426. ;; a fixed format.
  427. (let ((desc (org-bbdb-anniversary-description
  428. agenda-date d)))
  429. (string-match "]]" x)
  430. (replace-match desc nil nil x)))
  431. l))))
  432. ;; Map a function that generates anniversaries for each date
  433. ;; over the dates and nconc the results into a single list. When
  434. ;; it is no longer necessary to support older versions of Emacs,
  435. ;; this can be done with a cl-mapcan; for now, we use the (apply
  436. ;; #'nconc ...) method for compatibility.
  437. (apply #'nconc
  438. (mapcar
  439. (lambda (d)
  440. (let ((agenda-date date)
  441. (date d))
  442. ;; Rebind 'date' so that org-bbdb-anniversaries will
  443. ;; be fooled into giving us the list for the given
  444. ;; date and then annotate the descriptions for that
  445. ;; date.
  446. (funcall annotate-descriptions agenda-date d (org-bbdb-anniversaries))))
  447. dates)))))
  448. (defun org-bbdb-complete-link ()
  449. "Read a bbdb link with name completion."
  450. (require 'bbdb-com)
  451. (let ((rec (bbdb-completing-read-record "Name: ")))
  452. (concat "bbdb:"
  453. (bbdb-record-name (if (listp rec)
  454. (car rec)
  455. rec)))))
  456. (defun org-bbdb-anniv-export-ical ()
  457. "Extract anniversaries from BBDB and convert them to icalendar format."
  458. (require 'bbdb)
  459. (require 'diary-lib)
  460. (unless (hash-table-p org-bbdb-anniv-hash)
  461. (setq org-bbdb-anniv-hash
  462. (make-hash-table :test 'equal :size 366)))
  463. (when (or org-bbdb-updated-p
  464. (= 0 (hash-table-count org-bbdb-anniv-hash)))
  465. (org-bbdb-make-anniv-hash))
  466. (maphash 'org-bbdb-format-vevent org-bbdb-anniv-hash))
  467. (defun org-bbdb-format-vevent (key recs)
  468. (let (rec categ)
  469. (while (setq rec (pop recs))
  470. (setq categ (or (nth 2 rec) org-bbdb-default-anniversary-format))
  471. (princ (format "BEGIN:VEVENT
  472. UID: ANNIV-%4i%02i%02i-%s
  473. DTSTART:%4i%02i%02i
  474. SUMMARY:%s
  475. DESCRIPTION:%s
  476. CATEGORIES:%s
  477. RRULE:FREQ=YEARLY
  478. END:VEVENT\n"
  479. (nth 0 rec) (nth 0 key) (nth 1 key)
  480. (mapconcat 'identity
  481. (org-split-string (nth 1 rec) "[^a-zA-Z0-90]+")
  482. "-")
  483. (nth 0 rec) (nth 0 key) (nth 1 key)
  484. (nth 1 rec)
  485. (concat (capitalize categ) " " (nth 1 rec))
  486. categ)))))
  487. (provide 'ol-bbdb)
  488. ;; Local variables:
  489. ;; generated-autoload-file: "org-loaddefs.el"
  490. ;; End:
  491. ;;; ol-bbdb.el ends here