* Letting hooks? @ 2012-06-06 5:07 Eric Abrahamsen 2012-06-06 6:36 ` Tassilo Horn [not found] ` <mailman.2336.1338964587.855.help-gnu-emacs@gnu.org> 0 siblings, 2 replies; 4+ messages in thread From: Eric Abrahamsen @ 2012-06-06 5:07 UTC (permalink / raw) To: help-gnu-emacs I'm trying to temporarily add a function to a hook within the space of one function. I've tried a bunch of stuff and nothing's worked properly, and I suspect I'm just doing the Wrong Thing. Everything I've tried has been along the lines of: --8<---------------cut here---------------start------------->8--- (defun my-function () (let ((grommet-created-hook (push my-hook-function grommet-created-hook))) (create-grommet))) --8<---------------cut here---------------end--------------->8--- I've tried it with append and copy-sequence, everything blows up in different ways. Is this simply the wrong approach, or have I just not tried the right commands? All advice appreciated! Eric -- GNU Emacs 24.1.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.10) of 2012-06-06 on pellet ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Letting hooks? 2012-06-06 5:07 Letting hooks? Eric Abrahamsen @ 2012-06-06 6:36 ` Tassilo Horn [not found] ` <mailman.2336.1338964587.855.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 4+ messages in thread From: Tassilo Horn @ 2012-06-06 6:36 UTC (permalink / raw) To: help-gnu-emacs Eric Abrahamsen <eric@ericabrahamsen.net> writes: Hi Eric, > (defun my-function () > (let ((grommet-created-hook > (push my-hook-function > grommet-created-hook))) > (create-grommet))) I think `push' is definitively a bad idea, cause it changes `grommet-created-hook' global value, too. And `my-hook-function' has to be quoted. (let ((grommet-created-hook (cons 'my-hook-function grommet-created-hook))) (create-grommet)) should do the trick. Bye, Tassilo ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <mailman.2336.1338964587.855.help-gnu-emacs@gnu.org>]
* Re: Letting hooks? [not found] ` <mailman.2336.1338964587.855.help-gnu-emacs@gnu.org> @ 2012-06-08 0:57 ` Stefan Monnier 2012-06-08 3:28 ` Eric Abrahamsen 0 siblings, 1 reply; 4+ messages in thread From: Stefan Monnier @ 2012-06-08 0:57 UTC (permalink / raw) To: help-gnu-emacs > (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)) -- Stefan ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Letting hooks? 2012-06-08 0:57 ` Stefan Monnier @ 2012-06-08 3:28 ` Eric Abrahamsen 0 siblings, 0 replies; 4+ messages in thread From: Eric Abrahamsen @ 2012-06-08 3:28 UTC (permalink / raw) To: help-gnu-emacs 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-06-08 3:28 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-06-06 5:07 Letting hooks? Eric Abrahamsen 2012-06-06 6:36 ` Tassilo Horn [not found] ` <mailman.2336.1338964587.855.help-gnu-emacs@gnu.org> 2012-06-08 0:57 ` Stefan Monnier 2012-06-08 3:28 ` Eric Abrahamsen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).