From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wes Hardaker Subject: Re: org-contacts from bbdb: a starting solution Date: Wed, 09 Mar 2011 07:18:20 -0800 Message-ID: References: <87pqq0ms7p.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=58980 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PxL9d-0002bd-Do for emacs-orgmode@gnu.org; Wed, 09 Mar 2011 10:18:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PxL9c-0000b9-06 for emacs-orgmode@gnu.org; Wed, 09 Mar 2011 10:18:25 -0500 Received: from mail.hardakers.net ([168.150.236.43]:50487) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PxL9b-0000as-PK for emacs-orgmode@gnu.org; Wed, 09 Mar 2011 10:18:23 -0500 In-Reply-To: <87pqq0ms7p.fsf@ucl.ac.uk> (Eric S. Fraga's message of "Wed, 09 Mar 2011 11:46:50 +0000") 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: Eric S Fraga Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain >>>>> On Wed, 09 Mar 2011 11:46:50 +0000, Eric S Fraga said: ESF> Are you intending to extend your code for not-so-appropriate fields? If ESF> so, I definitely would like to see the addresses converted and it would ESF> be quite useful to have the notes converted entry text for the org entry ESF> (i.e. not a property). I thought about trying to create a generic 'list' of matching 'this' to 'that' but hadn't gotten to it yet. I'd be happy to change the notes so it went under the properties, if that's what you want? I think you want what is attached. -- Wes Hardaker My Pictures: http://capturedonearth.com/ My Thoughts: http://pontifications.hardakers.net/ --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=bbdb-to-org-contacts.el (require 'bbdb) (require 'bbdb-com) (defvar bbdb-to-org-contacts-record-prefix "***") (defvar bbdb-to-org-contacts-record-blanks " ") (defun bbdb-to-org-contacts (to-file) "outputs a org-contacts file" (interactive (list (read-file-name "Save in file: "))) (let* ((filename (expand-file-name to-file)) (records (bbdb-records))) (find-file filename) (while records (bbdb-record-to-org-record (car records)) (setq records (cdr records))) )) (defun bbdb-record-to-org-record (record) "converts a single record" (let* ( (name (bbdb-record-name record)) (company (bbdb-record-company record)) (net (bbdb-record-net record)) (aka (bbdb-record-aka record)) (phone (bbdb-record-phones record)) (address (bbdb-record-addresses record)) (notes (bbdb-record-notes record)) ) (insert (format "%s %s\n" bbdb-to-org-contacts-record-prefix name)) (insert (format "%s :PROPERTIES:\n" bbdb-to-org-contacts-record-blanks)) (when aka (insert (format "%s :AKA:\t%s\n" bbdb-to-org-contacts-record-blanks (mapconcat (function (lambda(str) str)) aka ", ")))) (when net (insert (format "%s :EMAIL:\t%s\n" bbdb-to-org-contacts-record-blanks (mapconcat (function (lambda(str) str)) net " ")))) (when company (insert (format "%s :COMPANY:\t%s\n" bbdb-to-org-contacts-record-blanks company))) (when phone (insert (mapconcat (function (lambda(rec) (if (stringp (elt rec 1)) (format "%s :PHONE_%s:\t%s" bbdb-to-org-contacts-record-blanks (upcase (elt rec 0)) (elt rec 1)) (let ((len (length rec)) (count 2) (output (format "%d" (elt rec 1)))) (while (< count (1- len)) (setq output (concat output (format "-%d" (elt rec count)))) (setq count (1+ count))) (format "%s :PHONE_%s:\t%s" bbdb-to-org-contacts-record-blanks (upcase (elt rec 0)) output))))) phone "\n")) (insert "\n")) (insert (format "%s :END:\n" bbdb-to-org-contacts-record-blanks)) (when notes (insert (format "%s - %s\n" bbdb-to-org-contacts-record-blanks notes))) )) (provide 'bbdb-to-org-contacts) --=-=-=--