>>>>> Thomas E Deweese writes:
> (defvar bbdb-default-country "USA"
>       "Default country to be used when formatting addresses 
> that lack a country field")

> ---

>   (let ((country (downcase (or (bbdb-address-country addr)
>                                bbdb-default-country))))
>     (if (or (string-equal country "us")
>             (string-equal country "usa"))
>         (format "%5d" (bbdb-address-zip addr))
>      (format "%d" (bbdb-address-zip addr))))

> ---
> Hope this helps anyway...

It did.  It took some time (which I didn't have much of) looking at
the sources and fiddling with my own limited lisp skills but I've come
up with the following, which is not a patch, but rather a
customization (hmm, maybe I shouldn't use that word since it's not
through the customize i/f).

I noticed that there is an opportunity to override the default
formatting function by customizing bbdb-address-formatting-alist.  I
copied bbdb-format-address-default and made a couple mods to it (all
in the let statement, which is now a let*) and renamed the function.
My first thought was to use advice, but I couldn't come up that one.
I'm sure this isn't the best way to do it, but it does seem to be
working OK for me for the last week or so.

(defvar bbdb-default-country "USA"
        "Default country to be used when formatting addresses 
that lack a country field")

(setq bbdb-address-formatting-alist (list
                                     (cons 'bbdb-address-is-continental
                                           'bbdb-format-address-continental)
                                     (cons nil
                                           'dsg-bbdb-format-address)))

(defun dsg-bbdb-format-address  (addr)
  "Insert formated address ADDR in current buffer.
This is the default format; it is used in the US, for example.

This function is a possible formatting function for
`bbdb-address-formatting-alist'.

The result looks like this:
       location: street
                 street
                 ...
                 city, state  zip
                 country"
  (insert (format " %14s: " (bbdb-address-location addr)))
  (bbdb-format-streets addr)
  (let* ((country (downcase (or (bbdb-address-country addr)
                                bbdb-default-country)))
         (c (bbdb-address-city addr))
         (s (bbdb-address-state addr))
         (zz (bbdb-address-zip addr))
         (z (if (and (integerp zz)
                     (or (string-equal country "us")
                         (string-equal country "usa")))
                (format "%05d" zz)
              (bbdb-address-zip-string addr))))
    (if (or (> (length c) 0)
            (> (length z) 0)
            (> (length s) 0))
        (progn
          (indent-to 17)
          (insert c (if (and (> (length c) 0)
                             (> (length s) 0)) ", " "")
                  s (if (and (or (> (length c) 0)
                                 (> (length s) 0))
                             (> (length z) 0)) "  " "")
                  z "\n"))))
  (let ((str (bbdb-address-country addr)))
    (if (= 0 (length str)) nil
      (indent-to 17) (insert str "\n"))))

-- 
Dave Goldberg
[EMAIL PROTECTED]
_______________________________________________
bbdb-info mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/mailman/listinfo/bbdb-info

Reply via email to