el/dot-emacs.el: Fix `bbdb-canonicalize-address'.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 13 Apr 2016 16:22:08 +0000 (17:22 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 13 Apr 2016 16:22:08 +0000 (17:22 +0100)
The built-in definition uses `run-hook-with-args', and expects to get a
sensible return value out the far end.  This is badly broken for two
reasons.

  * The first one is that `run-hook-with-args' has an explicitly
    unspecified return value, so relying on it to be anything useful is
    obviously silly.

  * The second is that, if the hook list isn't just a singleton, it's
    not at all clear how we should choose which function's return value
    to actually use.

The new code explicitly threads the address through all of the hook
functions in turn, and continues until we've had a pass where all of
them declined to change it.

el/dot-emacs.el

index d254154..fae5e01 100644 (file)
@@ -238,6 +238,32 @@ frame is actually mapped on the screen."
   "Save match data around the `markdown-mode' `after-change-functions' hook."
   (save-match-data ad-do-it))
 
+;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args'
+;; always returns nil, with the result that all email addresses are lost.
+;; Replace the function entirely.
+(defadvice bbdb-canonicalize-address
+    (around mdw-bug-fix activate compile)
+  "Don't use `run-hook-with-args', because that doesn't work."
+  (let ((net (ad-get-arg 0)))
+
+    ;; Make sure this is a proper hook list.
+    (if (functionp bbdb-canonicalize-net-hook)
+       (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook)))
+
+    ;; Iterate over the hooks until things converge.
+    (let ((donep nil))
+      (while (not donep)
+       (let (next (changep nil)
+             hook (hooks bbdb-canonicalize-net-hook))
+         (while hooks
+           (setq hook (pop hooks))
+           (setq next (funcall hook net))
+           (if (not (equal next net))
+               (setq changep t
+                     net next)))
+         (setq donep (not changep)))))
+    (setq ad-return-value net)))
+
 ;; Transient mark mode hacks.
 
 (defadvice exchange-point-and-mark