Ronan Waide <[EMAIL PROTECTED]> writes:

> Ideally the address editing function should return a true or false
> value (for "valid/invalid" data) and the calling code should handle
> that appropriately - by which I mean if you're editing an address, it
> remains unchanged, and if you're adding an address, it discards
> whatever you were trying to add. This would then allow you to write a
> smart editing function for your own locale that, for example, doesn't
> allow you to enter addresses with invalid zip/postal codes or
> whatever. Likewise it could be applied to phones, or whatever else I
> guess.

After an attempt at implementing this, I present a patch for review.
It is a bit problematic and requires more thorough testing.

Editing fields happens with bbdb-edit-current-field.  There,
bbdb-record-edit-field-internal is called and the return value is used
to determine wether the BBDB buffer needs to be sorted or not.  The
return value of bbdb-record-edit-field-internal when editing an
address is the return value of bbdb-record-edit-address.  That again
is the value of funcalling the bbdb-address-editing-function.

Therefore, if I changed the meaning of the bbdb-address-edit-default
return value (currently nil means not to resort the DB when an address
is edited), then a lot of changes need to be done: All the editing
functions need to change the meaning of their return values.

If anybody wrote his custom bbdb-address-edit-function, it needs to be
changed as well.

Furthermore, looking at bbdb-record-edit-name, it used to compute
wether the record needs resorting or not.  I changed this such that
any editing of name or company will result in a need to resort.
(Competing semantics for a return value?)

Anyway...  I'll write ChangeLog entries etc. as soon as it is decided
that this is the right way to go.  What do you think?

Alex.
-- 
http://www.geocities.com/kensanata/emacs.html
http://www.emacswiki.org/


/home/alex/elisp/bbdb/lisp $ cvs diff
cvs server: Diffing .
Index: bbdb-com.el
===================================================================
RCS file: /cvsroot/bbdb/bbdb/lisp/bbdb-com.el,v
retrieving revision 1.111
diff -r1.111 bbdb-com.el
427,430c427,431
<                      (bbdb-record-edit-address addr str)
<                      (if L
<                          (progn (setcdr L-tail (cons addr nil))
<                                 (setq L-tail (cdr L-tail)))
---
>                    ;; dont't add addr to L if user didn't enter any data
>                      (when (bbdb-record-edit-address addr str)
>                      (if L
>                          (progn (setcdr L-tail (cons addr nil))
>                                 (setq L-tail (cdr L-tail)))
432c433
<                                L-tail L)))
---
>                                L-tail L))))
623a625,626
> (defun bbdb-record-edit-affects-sort (field)
>   (eq field 'name))
755,756c758,759
<   (if (null contents)
<       (setq contents (bbdb-prompt-for-new-field-value name)))
---
>   (when (null contents)
>     (error "No data!"))
853,854c856,858
<            (bbdb-record-edit-address a)
<            a))
---
>            (if (bbdb-record-edit-address a)
>              a
>            nil)))
887,892c891,897
<     (setq need-to-sort
<           (bbdb-record-edit-field-internal record (car field) (nth 1 field)))
<     (bbdb-change-record record need-to-sort)
<     (bbdb-redisplay-one-record record)
<     ;; (bbdb-offer-save)
<     ))
---
>     (setq need-to-sort (bbdb-record-edit-affects-sort (car field))
>           changed-p (bbdb-record-edit-field-internal record (car field) (nth 1 
>field)))
>     (when changed-p
>       (bbdb-change-record record need-to-sort)
>       (bbdb-redisplay-one-record record)
>       ;; (bbdb-offer-save)
>       )))
895c900
<   (let (fn ln co need-to-sort new-name old-name)
---
>   (let (fn ln co new-name old-name)
908,911d912
<        (setq need-to-sort (or (not (string= fn
<                                             (or (bbdb-record-firstname bbdb-record) 
"")))
<                               (not (string= ln
<                                             (or (bbdb-record-lastname bbdb-record) 
"")))))
927,931d927
<     (setq need-to-sort
<           (or need-to-sort
<               (not (equal (if co (downcase co) "")
<                           (downcase (or (bbdb-record-company bbdb-record)
<                                         ""))))))
948c944,945
<     need-to-sort))
---
>     ;; return non-nil if there is data
>     (or fn ln co)))
977,980c974,975
<     (bbdb-address-set-streets addr str)
<     (bbdb-address-set-city addr cty)
<     (bbdb-address-set-state addr ste)
<     (bbdb-address-set-zip addr zip)
---
>     ;; Return nil if no data was entered.  If data was entered, update
>     ;; the record.
982,987c977,983
<         ;; user didn't enter anything. this causes a display bug. this
<         ;; is a temporary fix. Ideally, we'd simply discard the entire
<         ;; address entry, but that's going to require bigger hacking.
<         (bbdb-address-set-country addr "Emacs")
<       (bbdb-address-set-country addr country))
<     nil))
---
>       nil
>       (bbdb-address-set-streets addr str)
>       (bbdb-address-set-city addr cty)
>       (bbdb-address-set-state addr ste)
>       (bbdb-address-set-zip addr zip)
>       (bbdb-address-set-country addr country)
>       t)))
993c989,990
< The default value is the symbol `bbdb-address-edit-default'."
---
> The default value is the symbol `bbdb-address-edit-default'.
> When this function returns nil, the address will be discarded."
1025c1022
<     (if (= (length phone-number) 2)
---
>     (if (= (length phone-number) 2);; magic number: don't assume north american 
>format
1027,1030c1024,1027
<         (bbdb-phone-set-exchange phone-number (nth 1 newp))
<         (bbdb-phone-set-suffix phone-number (nth 2 newp))
<         (bbdb-phone-set-extension phone-number (or (nth 3 newp) 0))))
<   nil)
---
>       (bbdb-phone-set-exchange phone-number (nth 1 newp))
>       (bbdb-phone-set-suffix phone-number (nth 2 newp))
>       (bbdb-phone-set-extension phone-number (or (nth 3 newp) 0)))
>     (not (equal '("") newp))))
1057,1058c1054,1055
<       (bbdb-record-set-net bbdb-record newnets)))
<   nil)
---
>       (bbdb-record-set-net bbdb-record newnets)
>       (not (string= str "")))))
1085,1086c1082,1083
<       (bbdb-record-set-aka bbdb-record newaka)))
<   nil)
---
>       (bbdb-record-set-aka bbdb-record newaka)
>       (not (string= str "")))))
1097c1094
<   nil)
---
>   t)
1117c1114
<   nil)
---
>   t)

_______________________________________________
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/

Reply via email to