On Tue, 3 Aug 2004, Ronan Waide said:
> On June 26, [EMAIL PROTECTED] said:
>> This is, IMHO, a bug in BBDB: if a record has a dozen addresses on it and
>> all dozen match some email you just read, the bbdb-notice-hook should
>> still only be called once for that message.
> 
> It's not a bug, it's a feature! The documentation states that it's
> called each time a BBDB record is noticed, and in the instance you
> cite, each record needs to have the notice-hook called in order to
> honour that statement.

Ah. We really need another hook, perhaps.

I guess the hideous hack in bbdb-expire 1.7+ works, but, well, ick. It
just seems like a rather inefficient way to go about things. :)

(The hack:

(defadvice bbdb-update-records (around bbdb-expire-bbdb-notice-changes-only-once-bind 
activate)
  "Bind a variable that is used to remember how many times the notice hook has been 
run."
  (let ((bbdb-expire-bbdb-notice-hook-update-count (make-hash-table)))
    ad-do-it))

(defadvice bbdb-annotate-message-sender (after bbdb-expire-count-notice-calls activate)
  "Update the variable that counts how many times the notice hook has been run.
 It's done for each record in this call to `bbdb-update-records' (which can
update a single record multiple times and merge the results)."
  (when (and (boundp 'bbdb-expire-bbdb-notice-hook-update-count)
             ad-return-value)
    (let ((count (gethash ad-return-value bbdb-expire-bbdb-notice-hook-update-count)))
      (if count
          (puthash ad-return-value (1+ count) 
bbdb-expire-bbdb-notice-hook-update-count)
        (puthash ad-return-value 1 bbdb-expire-bbdb-notice-hook-update-count)))))

(defmacro bbdb-expire-call-only-once (record &rest body)
  "Call the BODY at most once per record display.

Only has an effect when called inside the `bbdb-notice-hook'."
  `(if (or (not (boundp 'bbdb-expire-bbdb-notice-hook-update-count))
           (null (gethash record bbdb-expire-bbdb-notice-hook-update-count))
           (< 2 (gethash record bbdb-expire-bbdb-notice-hook-update-count)))
       ,@body))

and then wrap things in `bbdb-expire-call-only-once' forms. It might be
more efficient to use an alist or an obarray, not a hash table...)

>                        While I appreciate what you're saying, I'm not
> exactly inclined to break existing behaviour that may well be of use
> to people (like me, for example).

I think you're right: I misread the docs (I was thinking of BBDB as
collating all messages and then noticing each record exactly once,
not as noticing the same record over and over again if several
addresses matched the same record). Both behaviours are useful,
and may well be useful to different functions running simultaneously.

>                                   Note that if you set
> bbdb-get-only-first-address-p it'll do pretty much exactly this
> anyway, because bbdb's being told not to look at anything beyond the
> first address. You could make that a prerequisite of your code, maybe.

Nope: that changes the behaviour of the BBDB from the user's point of
view (and makes it arguably less useful), something I am sworn not to do
:)

But for now, the hack works. A bit icky, but, well, that's Emacs for
you. :)

-- 
`The copyright file is for everyone.  That we make it available in
 plain-text, uncompressed form rather than in spinning, throbbing
 OpenGL-rendered 3D text over a thumping dance music soundtrack is a
 feature, not a bug.' --- Branden Robinson



-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/

Reply via email to