ol-bbdb.el 20 KB

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