From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: Letting hooks? Date: Fri, 08 Jun 2012 11:28:09 +0800 Message-ID: <87lijyv5x2.fsf@ericabrahamsen.net> References: <87mx4hxc3l.fsf@ericabrahamsen.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1339126123 28196 80.91.229.3 (8 Jun 2012 03:28:43 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 8 Jun 2012 03:28:43 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 08 05:28:42 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ScpsQ-0004hS-IY for geh-help-gnu-emacs@m.gmane.org; Fri, 08 Jun 2012 05:28:42 +0200 Original-Received: from localhost ([::1]:41167 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScpsQ-0003t5-Bx for geh-help-gnu-emacs@m.gmane.org; Thu, 07 Jun 2012 23:28:42 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:46273) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScpsK-0003t0-6p for help-gnu-emacs@gnu.org; Thu, 07 Jun 2012 23:28:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ScpsI-0000qd-L8 for help-gnu-emacs@gnu.org; Thu, 07 Jun 2012 23:28:35 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:43750) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScpsI-0000qY-Ea for help-gnu-emacs@gnu.org; Thu, 07 Jun 2012 23:28:34 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ScpsD-0004L6-Os for help-gnu-emacs@gnu.org; Fri, 08 Jun 2012 05:28:29 +0200 Original-Received: from 114.250.121.87 ([114.250.121.87]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 08 Jun 2012 05:28:29 +0200 Original-Received: from eric by 114.250.121.87 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 08 Jun 2012 05:28:29 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 51 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 114.250.121.87 X-Pgp-Key: http://pgp.mit.edu:11371/pks/lookup?op=vindex&search=0xC98BAE7B99D0D373 X-Pgp-Fingerprint: 8E19 28A9 2B51 0C67 565D DB34 C98B AE7B 99D0 D373 User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1.50 (gnu/linux) Cancel-Lock: sha1:rrfyFG6/enO9U8ybZ1NPYg+6N1k= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:85150 Archived-At: 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