Browse Source

Make bbdb-abbiversary entries links to the BBDB database entry.

The links can be accessed with C-c C-o.  If there are several links,
a prefix arg can be used to select one.
Carsten Dominik 17 years ago
parent
commit
b7502705a3
3 changed files with 50 additions and 9 deletions
  1. 10 0
      lisp/ChangeLog
  2. 13 7
      lisp/org-agenda.el
  3. 27 2
      lisp/org-bbdb.el

+ 10 - 0
lisp/ChangeLog

@@ -1,5 +1,15 @@
 2008-06-12  Carsten Dominik  <dominik@science.uva.nl>
 2008-06-12  Carsten Dominik  <dominik@science.uva.nl>
 
 
+	* org-bbdb.el (org-bbdb-follow-anniversary-link): New function.
+
+	* org-agenda.el (org-agenda-open-link): If there is an
+	org-bbdb-name property in the current line, jump to that bbdb
+	entry.
+
+	* org-bbdb.el (org-bbdb-anniversaries): Add the bbdb-name as a
+	text property, so that the agenda knows where this entry comes
+	from.
+
 	* org-agenda.el (org-agenda-clock-in): Fixed bug in the
 	* org-agenda.el (org-agenda-clock-in): Fixed bug in the
 	interaction between clocking-in from the agenda, and  automatic
 	interaction between clocking-in from the agenda, and  automatic
 	task state switching.
 	task state switching.

+ 13 - 7
lisp/org-agenda.el

@@ -4502,14 +4502,20 @@ If this information is not given, the function uses the tree at point."
 	      (delete-region (point-at-bol) (1+ (point-at-eol)))))
 	      (delete-region (point-at-bol) (1+ (point-at-eol)))))
 	  (beginning-of-line 0))))))
 	  (beginning-of-line 0))))))
 
 
-(defun org-agenda-open-link ()
+(declare-function org-bbdb-follow-anniversary-link "org-bbdb" (&optional arg))
+
+(defun org-agenda-open-link (&optional arg)
   "Follow the link in the current line, if any."
   "Follow the link in the current line, if any."
-  (interactive)
-  (org-agenda-copy-local-variable 'org-link-abbrev-alist-local)
-  (save-excursion
-    (save-restriction
-      (narrow-to-region (point-at-bol) (point-at-eol))
-      (org-open-at-point))))
+  (interactive "P")
+  (if (and (fboundp 'org-bbdb-follow-anniversary-link)
+	   (org-bbdb-follow-anniversary-link arg))
+      nil ; ok, there was a link, we followed it
+    ;; There was no link
+    (org-agenda-copy-local-variable 'org-link-abbrev-alist-local)
+    (save-excursion
+      (save-restriction
+	(narrow-to-region (point-at-bol) (point-at-eol))
+	(org-open-at-point)))))
 
 
 (defun org-agenda-copy-local-variable (var)
 (defun org-agenda-copy-local-variable (var)
   "Get a variable from a referenced buffer and install it here."
   "Get a variable from a referenced buffer and install it here."

+ 27 - 2
lisp/org-bbdb.el

@@ -30,7 +30,6 @@
 ;; Org-mode loads this module by default - if this is not what you want,
 ;; Org-mode loads this module by default - if this is not what you want,
 ;; configure the variable `org-modules'.
 ;; configure the variable `org-modules'.
 
 
-
 ;; It also implements an interface (based on Ivar Rummelhoff's
 ;; It also implements an interface (based on Ivar Rummelhoff's
 ;; bbdb-anniv.el) for those org-mode users, who do not use the diary
 ;; 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
 ;; but who do want to include the anniversaries stored in the BBDB
@@ -77,7 +76,10 @@
 ;;       1973-06-22
 ;;       1973-06-22
 ;;       20??-??-?? wedding
 ;;       20??-??-?? wedding
 ;;       1998-03-12 %s created bbdb-anniv.el %d years ago
 ;;       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:
 ;;; Code:
 
 
 (require 'org)
 (require 'org)
@@ -302,6 +304,7 @@ This is used by Org to re-create the anniversary hash table."
                         (funcall form name years suffix))
                         (funcall form name years suffix))
                        ((listp form) (eval form))
                        ((listp form) (eval form))
                        (t (format form name years suffix)))))
                        (t (format form name years suffix)))))
+	    (org-add-props tmp nil 'org-bbdb-name name)
             (if text
             (if text
                 (setq text (append text (list tmp)))
                 (setq text (append text (list tmp)))
               (setq text (list tmp)))))
               (setq text (list tmp)))))
@@ -309,6 +312,28 @@ This is used by Org to re-create the anniversary hash table."
     (when text
     (when text
       (mapconcat 'identity text "; "))))
       (mapconcat 'identity text "; "))))
 
 
+(defun org-bbdb-follow-anniversary-link (arg)
+  "Check if there is a BBDB anniversary link in current line and follow it."
+  (let ((n (prefix-numeric-value arg))
+	end name names last)
+    (setq name (get-text-property (point) 'org-bbdb-name))
+    (save-excursion
+      (beginning-of-line 1)
+      (setq end (1- (point-at-eol)))
+      (setq last (1- (point)))
+      (while (and (setq next (next-single-property-change
+			      (point) 'org-bbdb-name nil end))
+		  (> next last))
+	(goto-char next)
+	(setq last next)
+	(setq names (cons (get-text-property (point) 'org-bbdb-name) names))))
+    (setq names (nreverse (delq nil names)))
+    (if (setq name (or (and arg (nth (1- n) names))
+		       name
+		       (car names)))
+	(progn (bbdb-name name nil) t)
+      nil)))
+
 (provide 'org-bbdb)
 (provide 'org-bbdb)
 
 
 ;; arch-tag: 9e4f275d-d080-48c1-b040-62247f66b5c2
 ;; arch-tag: 9e4f275d-d080-48c1-b040-62247f66b5c2