From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastian Rose Subject: Re: Re: contact management in org-mode? Date: Wed, 11 Nov 2009 14:19:58 +0100 Message-ID: <87pr7pgpvl.fsf@gmx.de> References: <878wfoc5ao.fsf@cuma.i-did-not-set--mail-host-address--so-tickle-me> <87iqerzvm2.fsf@gollum.intra.norang.ca> <20091025023410.GK2357@thinkpad.adamsinfoserv.com> <87pr86tywd.wl%ucecesf@ucl.ac.uk> <87zl7arynb.fsf@dynapse.com> <20091029173640.GM28398@thinkpad.adamsinfoserv.com> <7bef1f890910291300o2e063d58h9d620278a6472032@mail.gmail.com> <20091031031059.GF23167@thinkpad.adamsinfoserv.com> <87skcp4kw7.fsf@benfinney.id.au> <87skcoejxt.fsf@gmx.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N8D7S-0003Vh-IZ for emacs-orgmode@gnu.org; Wed, 11 Nov 2009 08:20:18 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N8D7N-0003Kq-GF for emacs-orgmode@gnu.org; Wed, 11 Nov 2009 08:20:17 -0500 Received: from [199.232.76.173] (port=52761 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N8D7N-0003KX-4c for emacs-orgmode@gnu.org; Wed, 11 Nov 2009 08:20:13 -0500 Received: from mail.gmx.net ([213.165.64.20]:54001) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1N8D7M-0008DY-C0 for emacs-orgmode@gnu.org; Wed, 11 Nov 2009 08:20:12 -0500 In-Reply-To: <87skcoejxt.fsf@gmx.de> (Sebastian Rose's message of "Sun, 08 Nov 2009 23:22:06 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Matt Lundin Cc: Ben Finney , emacs-orgmode@gnu.org --=-=-= How about ... Here is a first simple example file. It's not very elaborate and can be done better. I just used the first functions I found in bbdb code, that do what I need. In some cases it might be better to use `bbdb-search' directly. But it let's us insert bbdb: and mailto: links easily. Basically, it works like this: 1. C-c b s (org-bbdb/select-record) selects a record for use. You have to call this function to select a new record. If no record is selcted, the functions in (2.) call this automatically. 2. Use the insertion functions: - C-c b n (org-bbdb/insert-name) inserts the name of the currently selected record at point. With prefix arg, inserts a bbdb: org-link. - C-c b m (org-bbdb/insert-mail) inserts the email address of the current record at point. With prefix arg, inserts a mailto: org-link. - C-c b m (org-bbdb/insert-phone) inserts the phone number of the current record at point. With prefix arg, inserts a dial: org-link - a link type, that is not yet defined. It's supposed to call `bbdb-dial-number' on activation. Just an idea... - C-c b a (org-bbdb/insert-address) inserts the postal address of the selected record at point. As the other functions, this is far from perfect... C-c b TAB (org-bbdb/complete-name) tries to complete a name at point and inserts an Org-link. The link is either a bbdb: link, or a mailto: link. Depends on your setting of `org-bbdb-default-link-type'. This function does not yet select a new record. Nice to have: We could add a function, that `narrows' to a set of bbdb records based on a certain field, e.g. city or note or custom field (e.g. `tag'). We could then format that list and insert that into a buffer. Or write a mail to all those in the list by Bcc-ing them all. Best wishes Sebastian --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=org-bbdb.el Content-Transfer-Encoding: quoted-printable Content-Description: org-bbdb.el ; ; org-bbdb.el ; ; Author: Sebastian Rose, Hannover, Germany ; ; Released under the GNU General Public License version 3 ; see: http://www.gnu.org/licenses/gpl-3.0.html ; (require 'org) (require 'bbdb) (require 'bbdb-com) (defcustom org-bbdb-default-link-type "bbdb" "The default link-type for name completion. set to 'bbdb', 'mailto' or some custom linktype.") (defvar org-bbdb-record nil "The active bbdb record.") (define-prefix-command 'org-bbdb-map nil "Org-BBDB") ;; TODO: define these keys in org-mode-map? (global-set-key [(control ?c) (?b)] org-bbdb-map) (define-key global-map [(control ?c) (?b) (?s)] 'org-bbdb/select-record) (define-key global-map [(control ?c) (?b) (tab)] 'org-bbdb/complete-name) (define-key global-map [(control ?c) (?b) (?n)] 'org-bbdb/insert-name) (define-key global-map [(control ?c) (?b) (?m)] 'org-bbdb/insert-mail) (define-key global-map [(control ?c) (?b) (?a)] 'org-bbdb/insert-address) (define-key global-map [(control ?c) (?b) (?p)] 'org-bbdb/insert-phone) ;; Basic functions (defun org-bbdb/select-record (&optional cached) "Select a new BBDB record to choose entries from. If CACHED is not nil, use the cached `org-bbdb-record' or select one. Returns the selected record or nil." (interactive) (when (or (not cached) (not org-bbdb-record)) (let ((bbdb-completion-type nil) (bbdb-complete-name-allow-cycling t) (record (bbdb-completing-read-one-record "Choose record: "))) (setq org-bbdb-record record))) (unless org-bbdb-record (message "%s" "No record selected. Try again.")) org-bbdb-record) ;; This is the only completion function: (defun org-bbdb/complete-name () "Complete name at point and insert a link. NOTE: only the last word preceding point is taken into account for the search (and thus replaced by the result)! The type of link depends on the setting of `org-bbdb-default-link-type'. TODO: select the record." (interactive "*") (let* ((s (current-word)) (id (bbdb-read-addresses-with-completion "Choose address: " s)) ;; Not sure if bbdb trims the end of an email. ;; Just assume it anyway: (has-net (string-match "^\\(.*\\) <\\(.+@.+\\..\\{2,6\\}\\)>$" id)) (name (if has-net (match-string 1 id) id)) (mail (if has-net (match-string 2 id) name)) (lt (if has-net org-bbdb-default-link-type "bbdb")) (ins (concat "[[" lt ":" mail "][" name "]]"))) (backward-word) (kill-word 1) (insert ins) ;; (forward-char (length ins)) )) ;; ;; Insertion functions ;; We have a get- and a insert- function for all important fields. ;; ;; -- name (defun org-bbdb/get-name (&optional record) "Return the name of a record." (let ((rec (or record (org-bbdb/select-record t)))) (if rec (bbdb-record-name rec) nil))) (defun org-bbdb/insert-name (&optional as-link) "Insert the name of the currently active record. With prefix argument, insert a bbdb: Org-link." (interactive "*P") (let ((n (org-bbdb/get-name))) (if n (if as-link (insert "[[bbdb:" n "][" n "]]") (insert n))))) ;; -- email (defun org-bbdb/get-mail (&optional record) "Return the email of a record." (let ((rec (or record (org-bbdb/select-record t)))) (if rec (car (bbdb-record-net rec)) nil))) (defun org-bbdb/insert-mail (&optional as-link) "Insert the email of the currently active record. With prefix argument, insert a mailto: Org-link." (interactive "*P") (message "%s" as-link) (let ((n (org-bbdb/get-mail))) (if n (if as-link (insert "[[mailto:" n "][" n "]]") (insert n))))) ;; -- phone (defun org-bbdb/get-phone (&optional record) "Return the phone number of a record." (let ((rec (or record (org-bbdb/select-record t)))) (if rec (car (bbdb-record-phones rec)) ;; support just one phone number... nil))) (defun org-bbdb/insert-phone (&optional as-link) "Insert the phone number of the currently active record. With prefix argument, insert a dial: Org-link which is to be defined." (interactive "*P") (message "%s" as-link) (let ((n (elt (org-bbdb/get-phone) 1))) (if n (if as-link (insert "[[dial:" n "][" n "]]") (insert n))))) ;; -- postal address (defun org-bbdb/get-address (&optional record) "Return the postal address of a record." (let ((rec (or record (org-bbdb/select-record t)))) (if rec (car (bbdb-record-addresses rec)) ;; we support only one address fo= r now. nil))) (defun org-bbdb/insert-address () "Insert the postal address of the currently active record." (interactive "*") (let ((addr (org-bbdb/get-address))) (if addr ;; TODO: add a fomat variable. We will insert the parts of the addr= esses ;; separated by commas in most cases. (bbdb-format-address addr nil 0)))) --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--