mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-11 09:20:51 +00:00
8d64207425
* org.el (org-set-tags-to): New command. * org-latex.el (org-export-latex-set-initial-vars): Also check in the plist. * org.el (org-additional-option-like-keywords): Add LATEX_CLASS keyword. * org-exp.el (org-infile-export-plist): Add LATEX_CLASS keyword. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-inlinetask.el (org-inlinetask-export): Option removed. (org-inlinetask-export-handler): Better export. * org-xoxo.el (org-export-xoxo-final-hook): New hook. (org-export-as-xoxo): Run the new hook. * org-html.el (org-export-html-final-hook): New hook. (org-export-as-html): Run the new hook. * org-docbook.el (org-export-docbook-final-hook): New hook. (org-export-as-docbook): Run the new hook. * org-ascii.el (org-export-ascii-final-hook): New hook. (org-export-as-ascii): Run the new hook. * org-latex.el (org-export-latex-treat-sub-super-char): Allow a space character as the character before the ^/_. (org-export-latex-final-hook): New hook. (org-export-as-latex): Run `org-export-latex-final-hook'. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-macs.el (org-if-unprotected-at): Fix docstring. * org-agenda.el (org-agenda-change-all-lines): Handle invisible text in the prefix (if category is a link). * org-latex.el (org-export-latex-preprocess): Deal properly with empty lines in verse environments. * org.el (org-format-latex-header): Inline fullpage.sty. * org-footnote.el (org-footnote-create-definition): Reveal context to add a new footnote definition. * org.el (org-ctrl-c-ctrl-c): Pass prefix arg to org-table-recalculate when cursor is in TBLFM line. * org-list.el (org-renumber-ordered-list): Fix cursor position when bullet length has changed. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-format-latex): Mention `org-format-latex-options' in the docstring. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-agenda-get): New function. * org-agenda.el (org-agenda-post-command-hook): No longer move point away from end of line. (org-agenda-add-entry-text, org-agenda-collect-markers) (org-finalize-agenda, org-agenda-mark-clocking-task) (org-agenda-dim-blocked-tasks, org-agenda-entry-text-show-here) (org-agenda-entry-text-show, org-agenda-highlight-todo) (org-agenda-compare-effort, org-agenda-filter-apply) (org-agenda-later, org-agenda-change-time-span) (org-agenda-post-command-hook, org-agenda-show-priority) (org-agenda-show-tags, org-agenda-goto, org-agenda-kill) (org-agenda-archive, org-agenda-archive-to-archive-sibling) (org-remove-subtree-entries-from-agenda, org-agenda-refile) (org-agenda-open-link, org-agenda-copy-local-variable) (org-agenda-switch-to, org-agenda-check-no-diary) (org-agenda-tree-to-indirect-buffer, org-agenda-todo) (org-agenda-add-note, org-agenda-change-all-lines) (org-agenda-priority, org-agenda-set-tags) (org-agenda-set-property, org-agenda-set-effort) (org-agenda-toggle-archive-tag, org-agenda-date-later) (org-agenda-show-new-time, org-agenda-date-prompt) (org-agenda-schedule, org-agenda-deadline, org-agenda-action) (org-agenda-clock-in, org-agenda-bulk-mark) (org-agenda-bulk-unmark, org-agenda-show-the-flagging-note): Use `org-get-at-bol'. * org-colview.el (org-columns-display-here) (org-columns-edit-allowed, org-agenda-columns): Use `org-get-at-bol'. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-special-ctrl-a/e): Improve documentation and customize type. (org-end-of-line): Don't jump to after the ellipsis. (org-mode-map): Bind <home> and <end> as well. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-fontify-meta-lines-and-blocks): Treat lines with a space after #+ as comments. (org-open-at-point): Run `org-follow-link-hook' always. * org-latex.el (org-export-latex-emph-format): Use better commands to insert special characters in verbatim snippets. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-faces.el (org-copy-face): New function. Use it to create various faces formerly created by using `copy-face'. * org-agenda.el (org-prepare-agenda): Don't officially mark this window dedicated. (org-agenda-quit): Kill the frame containing the agenda window if that frame was created for the agenda. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-date-prompt): Mark the changed time stamp in the agenda. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-prepare-agenda): Reset `org-drawers-for-agenda'. (org-prepare-agenda): Uniquify list of drawers. * org.el (org-complex-heading-regexp-format): New variable. (org-set-regexps-and-options): Define `org-complex-heading-regexp-format'. (org-drawers-for-agenda): New variable. (org-map-entries): Bind `org-drawers-for-agenda'. (org-prepare-agenda-buffers): Add to `org-drawers-for-agenda'. * org-remember.el (org-go-to-remember-target) (org-remember-handler): Use `org-complex-heading-regexp-format'. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-highlight-todo): Fix text property problem. * org.el (org-on-heading-p, org-at-heading-p): Make sure these are always with `invisible-ok'. (org-store-link): No error when there is nothing to link to in the agenda. * org-list.el (org-update-checkbox-count): Insert changed cookie before the old, to avoid problems with invisibility at the end of the line. (org-update-checkbox-count): Insert changed cookie before the old, to avoid problems with invisibility at the end of the line. * org.el (org-sort-entries-or-items): Include the final newline. (org-fontify-meta-lines-and-blocks): Add indented dynamic block lines for fontification. (org-dblock-start-re, org-dblock-end-re): Allow indentation. (org-prepare-dblock): Store the current indentation of the BEGIN line. (org-update-dblock): Apply the indentation of the begin line to the rest of the block. (org-ctrl-c-ctrl-c): Also find indented dblock lines. (org-startup-folded): New allowed value `showeverything'. (org-startup-options): Add STARTUP keyword `showeverything'. (org-set-startup-visibility): Respect value `showeverything' in org-startup-folded. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-closest-date): Fix issue with past preference. * org-archive.el (org-archive-set-tag) (org-archive-subtree-default): New commands. * org-clock.el (org-clock-clocktable-default-properties): New option. (org-clock-report): Use `org-clock-clocktable-default-properties'. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-iswitchb-completing-read): Fix typo. * org-crypt.el: New file. * org.el: Add an entry for org-crypt. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-menu): Reorganize the menu for more consistency. (org-batch-store-agenda-views): New function. (org-agenda-title-append): Define variable. (org-write-agenda): New export to Org files. (org-agenda-get-some-entry-text): New arguments INDENT and KEEP. (org-agenda): Allow to keep the restricted file list if a special variable is bound to t. (org-agenda): Define a special agenda view for working on flagged entries. (org-agenda-get-restriction-and-command): List the new agenda view. (org-agenda-show-the-flagging-note): New command. (org-agenda-mode-map): New key `?' for looking at the flagging note. * org.el (org-autoload): Autoload org-mobile.el. (org-org-menu): Add menu commands for MobileOrg in the Org menu. * org-mobile.el: New file. * org-id.el (org-id-get): Fix bug with forcing ID on an item. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-table.el (orgtbl-line-start-regexp): Match also TBLNAME statements. (org-table-get-remote-range): Match indented #+TBLNAME statements. * org.el (org-convert-to-odd-levels) (org-convert-to-oddeven-levels): Work also correctly if the file is in outline-mode. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org.el (org-store-link): When in agenda buffer, link to referenced entry. (org-add-planning-info): Remove spaces at eol. * org-macs.el (org-with-point-at): Add a `lisp-indent-function' property. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-first-lines): Fix problem with LaTeX export of first line and selected subtree. * org.el (org-shifttab): Interpret arg differently when using only odd levels. 2009-10-01 Bastien Guerry <bzg@altern.org> * org.el (org-check-agenda-file): Use a more explicit message 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-exp.el (org-export-remove-special-table-lines): Don't remove normal lines. 2009-10-01 Bastien Guerry <bzg@altern.org> * org.el (org-offer-links-in-entry): Don't use "Select link" as a prompt in the temporary window. * org-agenda.el (org-agenda-bulk-mark): Use a slightly soberer prefix for marked entries in the agenda view. 2009-10-01 Andreas Burtzlaff <andy13@gmx.net> (tiny change) * org.el (outline-end-of-subtree): Bugfix: advise this function in a way that prevents any trailing character from being displayed. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-menu): Fix bugs in the bulk action menu. * org-exp.el (org-export-remove-special-table-lines): Remove bad slow regexp match. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-latex.el (org-export-latex-preprocess): Do not protect in the LaTeX header. * org-src.el (org-edit-src-save): Save window setup while saving. (org-edit-src-code): Use new buffer name construction scheme. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-entry-text-exclude-regexps): New variable. (org-agenda-entry-text-cleanup-hook): New hook. (org-agenda-get-some-entry-text): Remove matches of `org-agenda-entry-text-exclude-regexps' and run the hook `org-agenda-entry-text-cleanup-hook'. * org.el (org-offer-links-in-entry): New argument ZERO to implement a link with index zero. (org-cycle-show-empty-lines): Not keep empty line under header hidden. (org-iswitchb-completing-read): Bind `switchb-use-virtual-buffers' to nil for special completion. (org-store-link): Don't error before the first heading. * org-agenda.el (org-agenda-open-link): Pass the prefix to `org-offer-links-in-entry'. 2009-10-01 Carsten Dominik <carsten.dominik@gmail.com> * org-agenda.el (org-agenda-quit): Provide the window argument for `window-dedicated-p', Emacs 22 needs it. (org-format-agenda-item): If the category is a link, arrange for invisible text to replaced with spaces. (org-compile-prefix-format): Add the extra space. (org-prefix-category-length): New variable. * org-exp.el (org-export-cleanup-toc-line): Remove footnote references from TOC lines. * org.el (org-selected-window): New variable. * org-table.el (org-table-edit-formulas): Remember the selected window. (org-table-fedit-finish, org-table-fedit-abort): Select the window that was originally selected. * org-exp.el (org-export-preprocess-apply-macros): Scan the expansion of a macro for more macro definitions. * org-agenda.el (org-agenda-dim-blocked-tasks): Make sure the invisibility overlay starts on the newline.
388 lines
14 KiB
EmacsLisp
388 lines
14 KiB
EmacsLisp
;;; org-bbdb.el --- Support for links to BBDB entries from within Org-mode
|
|
|
|
;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
|
|
;; Free Software Foundation, Inc.
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>,
|
|
;; Thomas Baumann <thomas dot baumann at ch dot tum dot de>
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
;; Homepage: http://orgmode.org
|
|
;; Version: 6.31a
|
|
;;
|
|
;; This file is part of GNU Emacs.
|
|
;;
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;
|
|
;;; Commentary:
|
|
|
|
;; This file implements links to BBDB database entries from within Org-mode.
|
|
;; Org-mode loads this module by default - if this is not what you want,
|
|
;; configure the variable `org-modules'.
|
|
|
|
;; It also implements an interface (based on Ivar Rummelhoff's
|
|
;; bbdb-anniv.el) for those org-mode users, who do not use the diary
|
|
;; but who do want to include the anniversaries stored in the BBDB
|
|
;; into the org-agenda. If you already include the `diary' into the
|
|
;; agenda, you might want to prefer to include the anniversaries in
|
|
;; the diary using bbdb-anniv.el.
|
|
;;
|
|
;; Put the following in /somewhere/at/home/diary.org and make sure
|
|
;; that this file is in `org-agenda-files`
|
|
;;
|
|
;; %%(org-bbdb-anniversaries)
|
|
;;
|
|
;; For example my diary.org looks like:
|
|
;; * Anniversaries
|
|
;; #+CATEGORY: Anniv
|
|
;; %%(org-bbdb-anniversaries)
|
|
;;
|
|
;;
|
|
;; To add an anniversary to a BBDB record, press `C-o' in the record.
|
|
;; You will be prompted for the field name, in this case it must be
|
|
;; "anniversary". If this is the first time you are using this field,
|
|
;; you need to confirm that it should be created.
|
|
;;
|
|
;; The format of an anniversary field stored in BBDB is the following
|
|
;; (items in {} are optional):
|
|
;;
|
|
;; YYYY-MM-DD{ CLASS-OR-FORMAT-STRING}
|
|
;; {\nYYYY-MM-DD CLASS-OR-FORMAT-STRING}...
|
|
;;
|
|
;; CLASS-OR-FORMAT-STRING is one of two things:
|
|
;;
|
|
;; - an identifier for a class of anniversaries (eg. birthday or
|
|
;; wedding) from `org-bbdb-anniversary-format-alist' which then
|
|
;; defines the format tring for this class
|
|
;; - the (format) string displayed in the diary.
|
|
;;
|
|
;; You can enter multiple anniversaries for a single BBDB record by
|
|
;; separating them with a newline character. At the BBDB prompt for
|
|
;; the field value, type `C-q C-j' to enter a newline between two
|
|
;; anniversaries.
|
|
;;
|
|
;; If you omit the CLASS-OR-FORMAT-STRING entirely, it defaults to the
|
|
;; value of `org-bbdb-default-anniversary-format' ("birthday" by
|
|
;; default).
|
|
;;
|
|
;; The substitutions in the format string are (in order):
|
|
;; - the name of the record containing this anniversary
|
|
;; - the number of years
|
|
;; - an ordinal suffix (st, nd, rd, th) for the year
|
|
;;
|
|
;; See the documentation of `org-bbdb-anniversary-format-alist' for
|
|
;; further options.
|
|
;;
|
|
;; Example
|
|
;;
|
|
;; 1973-06-22
|
|
;; 20??-??-?? wedding
|
|
;; 1998-03-12 %s created bbdb-anniv.el %d years ago
|
|
;;
|
|
;; From Org's agenda, you can use `C-c C-o' to jump to the BBDB
|
|
;; link from which the entry at point originates.
|
|
;;
|
|
;;; Code:
|
|
|
|
(require 'org)
|
|
(eval-when-compile
|
|
(require 'cl))
|
|
|
|
;; Declare external functions and variables
|
|
|
|
(declare-function bbdb "ext:bbdb-com" (string elidep))
|
|
(declare-function bbdb-company "ext:bbdb-com" (string elidep))
|
|
(declare-function bbdb-current-record "ext:bbdb-com"
|
|
(&optional planning-on-modifying))
|
|
(declare-function bbdb-name "ext:bbdb-com" (string elidep))
|
|
(declare-function bbdb-completing-read-record "ext:bbdb-com"
|
|
(prompt &optional omit-records))
|
|
(declare-function bbdb-record-getprop "ext:bbdb" (record property))
|
|
(declare-function bbdb-record-name "ext:bbdb" (record))
|
|
(declare-function bbdb-records "ext:bbdb"
|
|
(&optional dont-check-disk already-in-db-buffer))
|
|
(declare-function bbdb-split "ext:bbdb" (string separators))
|
|
(declare-function bbdb-string-trim "ext:bbdb" (string))
|
|
|
|
(declare-function calendar-leap-year-p "calendar" (year))
|
|
(declare-function diary-ordinal-suffix "diary-lib" (n))
|
|
|
|
(defvar date) ;; dynamically scoped from Org
|
|
|
|
;; Customization
|
|
|
|
(defgroup org-bbdb-anniversaries nil
|
|
"Customizations for including anniversaries from BBDB into Agenda."
|
|
:group 'org-bbdb)
|
|
|
|
(defcustom org-bbdb-default-anniversary-format "birthday"
|
|
"Default anniversary class."
|
|
:type 'string
|
|
:group 'org-bbdb-anniversaries
|
|
:require 'bbdb)
|
|
|
|
(defcustom org-bbdb-anniversary-format-alist
|
|
'(("birthday" lambda
|
|
(name years suffix)
|
|
(concat "Birthday: [[bbdb:" name "][" name " ("
|
|
(number-to-string years)
|
|
suffix ")]]"))
|
|
("wedding" lambda
|
|
(name years suffix)
|
|
(concat "[[bbdb:" name "][" name "'s "
|
|
(number-to-string years)
|
|
suffix " wedding anniversary]]")))
|
|
"How different types of anniversaries should be formatted.
|
|
An alist of elements (STRING . FORMAT) where STRING is the name of an
|
|
anniversary class and format is either:
|
|
1) A format string with the following substitutions (in order):
|
|
* the name of the record containing this anniversary
|
|
* the number of years
|
|
* an ordinal suffix (st, nd, rd, th) for the year
|
|
|
|
2) A function to be called with three arguments: NAME YEARS SUFFIX
|
|
(string int string) returning a string for the diary or nil.
|
|
|
|
3) An Emacs Lisp form that should evaluate to a string (or nil) in the
|
|
scope of variables NAME, YEARS and SUFFIX (among others)."
|
|
:type 'sexp
|
|
:group 'org-bbdb-anniversaries
|
|
:require 'bbdb)
|
|
|
|
(defcustom org-bbdb-anniversary-field 'anniversary
|
|
"The BBDB field which contains anniversaries.
|
|
The anniversaries are stored in the following format
|
|
|
|
YYYY-MM-DD Class-or-Format-String
|
|
|
|
where class is one of the customized classes for anniversaries;
|
|
birthday and wedding are predefined. Format-String can take three
|
|
substitutions 1) the name of the record containing this
|
|
anniversary, 2) the number of years, and 3) an ordinal suffix for
|
|
the year.
|
|
|
|
Multiple anniversaries can be separated by \\n."
|
|
:type 'symbol
|
|
:group 'org-bbdb-anniversaries
|
|
:require 'bbdb)
|
|
|
|
(defcustom org-bbdb-extract-date-fun 'org-bbdb-anniv-extract-date
|
|
"How to retrieve `month date year' from the anniversary field.
|
|
|
|
Customize if you have already filled your BBDB with dates
|
|
different from YYYY-MM-DD. The function must return a list (month
|
|
date year)."
|
|
:type 'function
|
|
:group 'org-bbdb-anniversaries
|
|
:require 'bbdb)
|
|
|
|
|
|
;; Install the link type
|
|
(org-add-link-type "bbdb" 'org-bbdb-open 'org-bbdb-export)
|
|
(add-hook 'org-store-link-functions 'org-bbdb-store-link)
|
|
|
|
;; Implementation
|
|
(defun org-bbdb-store-link ()
|
|
"Store a link to a BBDB database entry."
|
|
(when (eq major-mode 'bbdb-mode)
|
|
;; This is BBDB, we make this link!
|
|
(let* ((name (bbdb-record-name (bbdb-current-record)))
|
|
(company (bbdb-record-getprop (bbdb-current-record) 'company))
|
|
(link (org-make-link "bbdb:" name)))
|
|
(org-store-link-props :type "bbdb" :name name :company company
|
|
:link link :description name)
|
|
link)))
|
|
|
|
(defun org-bbdb-export (path desc format)
|
|
"Create the export version of a BBDB link specified by PATH or DESC.
|
|
If exporting to either HTML or LaTeX FORMAT the link will be
|
|
italicised, in all other cases it is left unchanged."
|
|
(cond
|
|
((eq format 'html) (format "<i>%s</i>" (or desc path)))
|
|
((eq format 'latex) (format "\\textit{%s}" (or desc path)))
|
|
(t (or desc path))))
|
|
|
|
(defun org-bbdb-open (name)
|
|
"Follow a BBDB link to NAME."
|
|
(require 'bbdb)
|
|
(let ((inhibit-redisplay (not debug-on-error))
|
|
(bbdb-electric-p nil))
|
|
(catch 'exit
|
|
;; Exact match on name
|
|
(bbdb-name (concat "\\`" name "\\'") nil)
|
|
(if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
|
|
;; Exact match on name
|
|
(bbdb-company (concat "\\`" name "\\'") nil)
|
|
(if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
|
|
;; Partial match on name
|
|
(bbdb-name name nil)
|
|
(if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
|
|
;; Partial match on company
|
|
(bbdb-company name nil)
|
|
(if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
|
|
;; General match including network address and notes
|
|
(bbdb name nil)
|
|
(when (= 0 (buffer-size (get-buffer "*BBDB*")))
|
|
(delete-window (get-buffer-window "*BBDB*"))
|
|
(error "No matching BBDB record")))))
|
|
|
|
(defun org-bbdb-anniv-extract-date (time-str)
|
|
"Convert YYYY-MM-DD to (month date year).
|
|
Argument TIME-STR is the value retrieved from BBDB."
|
|
(multiple-value-bind (y m d) (values-list (bbdb-split time-str "-"))
|
|
(list (string-to-number m)
|
|
(string-to-number d)
|
|
(string-to-number y))))
|
|
|
|
(defun org-bbdb-anniv-split (str)
|
|
"Split multiple entries in the BBDB anniversary field.
|
|
Argument STR is the anniversary field in BBDB."
|
|
(let ((pos (string-match "[ \t]" str)))
|
|
(if pos (list (substring str 0 pos)
|
|
(bbdb-string-trim (substring str pos)))
|
|
(list str nil))))
|
|
|
|
(defvar org-bbdb-anniv-hash nil
|
|
"A hash holding anniversaries extracted from BBDB.
|
|
The hash table is created on first use.")
|
|
|
|
(defvar org-bbdb-updated-p t
|
|
"This is non-nil if BBDB has been updated since we last built the hash.")
|
|
|
|
(defun org-bbdb-make-anniv-hash ()
|
|
"Create a hash with anniversaries extracted from BBDB, for fast access.
|
|
The anniversaries are assumed to be stored `org-bbdb-anniversary-field'."
|
|
|
|
(let (split tmp annivs)
|
|
(clrhash org-bbdb-anniv-hash)
|
|
(dolist (rec (bbdb-records))
|
|
(when (setq annivs (bbdb-record-getprop
|
|
rec org-bbdb-anniversary-field))
|
|
(setq annivs (bbdb-split annivs "\n"))
|
|
(while annivs
|
|
(setq split (org-bbdb-anniv-split (pop annivs)))
|
|
(multiple-value-bind (m d y)
|
|
(values-list (funcall org-bbdb-extract-date-fun (car split)))
|
|
(setq tmp (gethash (list m d) org-bbdb-anniv-hash))
|
|
(puthash (list m d) (cons (list y
|
|
(bbdb-record-name rec)
|
|
(cadr split))
|
|
tmp)
|
|
org-bbdb-anniv-hash))))))
|
|
(setq org-bbdb-updated-p nil))
|
|
|
|
(defun org-bbdb-updated (rec)
|
|
"Record the fact that BBDB has been updated.
|
|
This is used by Org to re-create the anniversary hash table."
|
|
(setq org-bbdb-updated-p t))
|
|
|
|
(add-hook 'bbdb-after-change-hook 'org-bbdb-updated)
|
|
|
|
;;;###autoload
|
|
(defun org-bbdb-anniversaries()
|
|
"Extract anniversaries from BBDB for display in the agenda."
|
|
(require 'bbdb)
|
|
(require 'diary-lib)
|
|
(unless (hash-table-p org-bbdb-anniv-hash)
|
|
(setq org-bbdb-anniv-hash
|
|
(make-hash-table :test 'equal :size 366)))
|
|
|
|
(when (or org-bbdb-updated-p
|
|
(= 0 (hash-table-count org-bbdb-anniv-hash)))
|
|
(org-bbdb-make-anniv-hash))
|
|
|
|
(let* ((m (car date)) ; month
|
|
(d (nth 1 date)) ; day
|
|
(y (nth 2 date)) ; year
|
|
(annivs (gethash (list m d) org-bbdb-anniv-hash))
|
|
(text ())
|
|
rec recs)
|
|
|
|
;; we don't want to miss people born on Feb. 29th
|
|
(when (and (= m 3) (= d 1)
|
|
(not (null (gethash (list 2 29) org-bbdb-anniv-hash)))
|
|
(not (calendar-leap-year-p y)))
|
|
(setq recs (gethash (list 2 29) org-bbdb-anniv-hash))
|
|
(while (setq rec (pop recs))
|
|
(push rec annivs)))
|
|
|
|
(when annivs
|
|
(while (setq rec (pop annivs))
|
|
(when rec
|
|
(let* ((class (or (nth 2 rec)
|
|
org-bbdb-default-anniversary-format))
|
|
(form (or (cdr (assoc class
|
|
org-bbdb-anniversary-format-alist))
|
|
class)) ; (as format string)
|
|
(name (nth 1 rec))
|
|
(years (- y (car rec)))
|
|
(suffix (diary-ordinal-suffix years))
|
|
(tmp (cond
|
|
((functionp form)
|
|
(funcall form name years suffix))
|
|
((listp form) (eval form))
|
|
(t (format form name years suffix)))))
|
|
(org-add-props tmp nil 'org-bbdb-name name)
|
|
(if text
|
|
(setq text (append text (list tmp)))
|
|
(setq text (list tmp)))))
|
|
))
|
|
(when text
|
|
(mapconcat 'identity text "; "))))
|
|
|
|
(defun org-bbdb-complete-link ()
|
|
"Read a bbdb link with name completion."
|
|
(require 'bbdb-com)
|
|
(concat "bbdb:"
|
|
(bbdb-record-name (car (bbdb-completing-read-record "Name: ")))))
|
|
|
|
(defun org-bbdb-anniv-export-ical ()
|
|
"Extract anniversaries from BBDB and convert them to icalendar format."
|
|
(require 'bbdb)
|
|
(require 'diary-lib)
|
|
(unless (hash-table-p org-bbdb-anniv-hash)
|
|
(setq org-bbdb-anniv-hash
|
|
(make-hash-table :test 'equal :size 366)))
|
|
(when (or org-bbdb-updated-p
|
|
(= 0 (hash-table-count org-bbdb-anniv-hash)))
|
|
(org-bbdb-make-anniv-hash))
|
|
(maphash 'org-bbdb-format-vevent org-bbdb-anniv-hash))
|
|
|
|
(defun org-bbdb-format-vevent (key recs)
|
|
(let (rec categ)
|
|
(while (setq rec (pop recs))
|
|
(setq categ (or (nth 2 rec) org-bbdb-default-anniversary-format))
|
|
(princ (format "BEGIN:VEVENT
|
|
UID: ANNIV-%4i%02i%02i-%s
|
|
DTSTART:%4i%02i%02i
|
|
SUMMARY:%s
|
|
DESCRIPTION:%s
|
|
CATEGORIES:%s
|
|
RRULE:FREQ=YEARLY
|
|
END:VEVENT\n"
|
|
(nth 0 rec) (nth 0 key) (nth 1 key)
|
|
(mapconcat 'identity
|
|
(org-split-string (nth 1 rec) "[^a-zA-Z0-90]+")
|
|
"-")
|
|
(nth 0 rec) (nth 0 key) (nth 1 key)
|
|
(nth 1 rec)
|
|
(concat (capitalize categ) " " (nth 1 rec))
|
|
categ)))))
|
|
|
|
(provide 'org-bbdb)
|
|
|
|
;; arch-tag: 9e4f275d-d080-48c1-b040-62247f66b5c2
|
|
|
|
;;; org-bbdb.el ends here
|