help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Letting hooks?


From: Eric Abrahamsen
Subject: Re: Letting hooks?
Date: Fri, 08 Jun 2012 11:28:09 +0800
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1.50 (gnu/linux)

On Fri, Jun 08 2012, Stefan Monnier wrote:

>>   (let ((grommet-created-hook
>>          (cons 'my-hook-function grommet-created-hook)))
>>     (create-grommet))
>
> This will often work, indeed, and is fairly elegant.
> For some hooks where the buffer-localness is used/modified within
> create-grommet, you may prefer:
>
>   (unwind-protect
>       (progn
>         (add-hook 'grommet-created-hook 'my-hook-function)
>         (create-grommet))
>     (remove-hook 'grommet-created-hook 'my-hook-function))

Thanks, I'll give this a shot as well. I was seeing very weird behavior
with Tassilo's solution – so strange that I'm assuming I've done
something elsewhere to cause it, but I haven't yet figured out what.

These are org-mode capture hooks I'm working with, and I was finding
that on a fresh start of emacs, before org was loaded (which *ought* to
mean before my own code was loaded at all), the `grommet-created-hook'
(actually `org-capture-before-finalize-hook') was already initialized to
`my-hook-function'.

Specifically: I could start emacs fresh, run describe-variable on
`org-capture-before-finalize-hook', and it would tell me the value was
(my-hook-function), but otherwise treated it as an unknown variable (ie
the docstring didn't show up, all that).

After loading org (which also loads my code, as I'm modifying a local
branch of the org codebase), describe-variable describes the hook
properly, and reports it as empty, but actually running my code (using
the cons method above) doesn't add my function to the hook.

All that seems like crazy talk me. I haven't had time to do the whole
"emacs -Q" song and dance, but I don't see anything that could be
initializing `org-capture-before-finalize-hook' before the org code is
loaded, and `my-hook-function' only exists in one place, in the one file
that's part of my local org branch.

Anyway, I'm going to dunk my head in a bucket and come back to this
later.

Thanks!
Eric

-- 
GNU Emacs 24.1.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.10)
 of 2012-06-06 on pellet




reply via email to

[Prev in Thread] Current Thread [Next in Thread]