From: Mark Wooding Date: Wed, 13 Apr 2016 16:22:08 +0000 (+0100) Subject: el/dot-emacs.el: Fix `bbdb-canonicalize-address'. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/d54a4cf35d90fe372d5b192ccd93bbd65ff4f25f?hp=--cc el/dot-emacs.el: Fix `bbdb-canonicalize-address'. 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. --- d54a4cf35d90fe372d5b192ccd93bbd65ff4f25f diff --git a/el/dot-emacs.el b/el/dot-emacs.el index d254154..fae5e01 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -238,6 +238,32 @@ (defadvice markdown-check-change-for-wiki-link "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