Better support for organisation-only records. Also fix a bug when firstname or lastname are nil. Comments welcome ;)
>From 2fcdf3844f7c0c999988377f738184be5ec60e55 Mon Sep 17 00:00:00 2001 Date: Tue, 20 Sep 2011 22:16:56 +0800 --- lisp/bbdb-com.el | 14 ++++++++++---- lisp/bbdb.el | 45 ++++++++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/lisp/bbdb-com.el b/lisp/bbdb-com.el index f8de3313..89cedb18 100644 --- a/lisp/bbdb-com.el +++ b/lisp/bbdb-com.el @@ -1346,13 +1346,17 @@ (defun bbdb-delete-field-or-record (records field &optional noprompt) (let ((type (car field)) (record (car records))) ;; Multiple elements in RECORDS are only meaningful if we delete these ;; records completely (so that the cdr of FIELD is irrelevant). - (if (eq type 'name) + (if (eq type (if (bbdb-record-is-organization record) + 'organization + 'name)) (bbdb-delete-records records noprompt) (if (cdr records) (error "Cannot delete same field from multiple records")) (when (or noprompt (y-or-n-p (format "delete this %s field (of %s)? " - type (bbdb-record-name record)))) + type (if (bbdb-record-is-organization record) + (bbdb-record-organization record) + (bbdb-record-name record))))) (cond ((memq type '(phone address)) (bbdb-record-set-field record type @@ -1385,8 +1389,10 @@ (defun bbdb-delete-records (records &optional noprompt) (dolist (record (bbdb-record-list records)) (when (or noprompt (y-or-n-p (format "Delete the BBDB record of %s? " - (or (bbdb-record-name record) - (car (bbdb-record-mail record)))))) + (if (bbdb-record-is-organization record) + (bbdb-record-organization record) + (or (bbdb-record-name record) + (car (bbdb-record-mail record))))))) (bbdb-debug (if (bbdb-record-deleted-p record) (error "Deleting deleted record"))) (bbdb-redisplay-record record t) diff --git a/lisp/bbdb.el b/lisp/bbdb.el index 612af8db..294ba1d6 100644 --- a/lisp/bbdb.el +++ b/lisp/bbdb.el @@ -1782,13 +1782,15 @@ (defun bbdb-record-set-name (record &optional first last) (let ((fl (bbdb-concat " " first last)) (lf (bbdb-concat " " last first)) (cache (bbdb-record-cache record))) + (if (string= fl "") (setq fl nil)) + (if (string= lf "") (setq lf nil)) ;; Set cache (bbdb-cache-set-fl-name cache fl) (bbdb-cache-set-lf-name cache lf) ;; Set hash. For convenience, the hash contains the full name as ;; first-last and last-fist. - (bbdb-puthash fl record) - (bbdb-puthash lf record) + (and (stringp fl) (bbdb-puthash fl record)) + (and (stringp lf) (bbdb-puthash lf record)) fl)) (defun bbdb-record-unset-name (record) @@ -2142,22 +2144,29 @@ (defun bbdb-display-list (list field &optional terminator face indent) (terminator (bbdb-display-text terminator (list field) face)))))) +(defun bbdb-record-is-organization (record) + "Return non-nil if RECORD is an organization." + (let ((name (bbdb-record-name record)) + (affix (bbdb-record-affix record)) + (organization (bbdb-record-organization record))) + (and (not name) (not affix) organization))) + (defun bbdb-display-name-organization (record) "Insert name, affix, and organization of RECORD." - ;; Name - (let ((name (or (bbdb-record-name record) "???"))) - (bbdb-display-text name (list 'name name) 'bbdb-name)) - ;; Affix - (let ((affix (bbdb-record-affix record))) - (when affix - (insert ", ") - (bbdb-display-list affix 'affix))) - ;; Organization - (let ((organization (bbdb-record-organization record))) - (when organization - (insert " - ") - (bbdb-display-list organization 'organization nil - 'bbdb-organization)))) + (let ((name (bbdb-record-name record)) + (affix (bbdb-record-affix record)) + (organization (bbdb-record-organization record))) + (if (bbdb-record-is-organization record) + (bbdb-display-list organization 'organization nil + 'bbdb-organization) + (bbdb-display-text (or name "???") (list 'name name) 'bbdb-name) + (when affix + (insert ", ") + (bbdb-display-list affix 'affix)) + (when organization + (insert " - ") + (bbdb-display-list organization 'organization nil + 'bbdb-organization))))) (defun bbdb-display-record-one-line (record layout field-list) "Record formatting function for the one-line layout. @@ -3197,7 +3206,9 @@ (defun bbdb-field-menu (record field) (concat "\"" (aref (nth 1 field) 0) "\" " (capitalize (symbol-name type)) " field:")))) ["Edit Field" bbdb-edit-field t]) - (unless (eq type 'name) + (unless (eq type (if (bbdb-record-is-organization record) + 'organization + 'name)) (list ["Delete Field" bbdb-delete-field-or-record t])) (cond ((eq type 'phone) (list (vector (concat "Dial " (bbdb-phone-string (nth 1 field))) -- 1.7.6 ------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 _______________________________________________ bbdb-info@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/