Joe Casadonte <[EMAIL PROTECTED]> writes:

> Changing the following line in bbdb-search-simple seemed to fix this,
> but I'm not sure if I've changed things semantically or not.
> Actually, I'm pretty sure I did, but I think it was for the better:
> 
>   OLD:            (setq answer (append recs n-rec)))
>   NEW:            (setq answer (append answer (list n-rec))))
> 
> Not quite sure what the first was trying to accomplish w/r/t appending
> recs rather then answer.  The basic issue was that recs had two
> records in it as potential matches; when it has one, it works fine.  I
> added a third record, and the patched version works still, so I think
> I may be on to something (or just *on* something, you can decide).
> 

I just encountered this bug today.  I had a hard time understanding the
logic of the code, too.  Even with your patch, I think there is still some
flawed logic.  For example:

  (let (...
        ret)
    (if (not (and name-recs net-recs))
        (or (and name-recs (car name-recs))
        ...
      )       
      ret)))

Will this return the value of the or branch as the value of
bbdb-search-simple? 

I decided to rewrite the function totally:

  (defsubst bbdb-search-simple (name net)
    "name is a string; net is a string or list of strings."
    (when (equal name "") (setq name nil))
    (when (equal name "") (setq net nil))
    (bbdb-records t)                    ; make sure db is parsed; don't check disk 
(faster)
    (let ((name-recs (when name;; filter out companies from hash
                         (loop
                           for rec in (bbdb-gethash (downcase name))
                           for name-in-rec = (bbdb-record-name rec)
                           if (and name-in-rec
                                   (string= (downcase name)
                                            (downcase name-in-rec)))
                           collect rec)))
          (net-recs  (cond 
                      ((stringp net) (bbdb-gethash (downcase net)))
                      ((null net) nil)
                      (t (mapcan (lambda (n) (bbdb-gethash (downcase n))) net))))
          ret)
      (cond 
       ((and name-recs (null net-recs))
        (setq ret (car name-recs)))
       ((and net-recs (null name-recs))
        (setq ret (car net-recs)))
       (t
        (setq ret 
              (loop 
                for rec in name-recs
                if (member rec net-recs) return rec))))
      ret))

--- Alastair


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

Reply via email to