From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Holst Subject: Re: Problems with capture and lisp code Date: Thu, 21 Jan 2016 15:33:25 +0100 Message-ID: References: <87k2n3t6i6.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39809) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMGIp-000302-VO for emacs-orgmode@gnu.org; Thu, 21 Jan 2016 09:33:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMGIk-0005Ec-00 for emacs-orgmode@gnu.org; Thu, 21 Jan 2016 09:33:35 -0500 Received: from smtp6-v.fe.bosch.de ([2a03:cc00:ff0:100::2]:13872) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMGIj-0005Dx-Fx for emacs-orgmode@gnu.org; Thu, 21 Jan 2016 09:33:29 -0500 In-Reply-To: <87k2n3t6i6.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Thu, 21 Jan 2016 14:19:13 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nicolas Goaziou Cc: org-mode mailing list Hi Nicolas, =B7 Nicolas Goaziou wrote: > Hello, > > Thomas Holst writes: > >> for my work flow I would like to set up a capture template based on th= e >> ideas described in: >> >> http://www.jboecker.de/2010/04/14/general-reference-filing-with-org-mo= de.html#sec-5 >> >> The original is based on remember but I want to use capture. The >> principle is as follows: >> >> In the capture template run some lisp code which appends a function to >> `org-capture-before-finalize-hook' which calls `org-attach-mv' to atta= ch >> a file. >> >> The function run from capture template looks like this: >> >> #+begin_src emacs-lisp >> (defun th:filing-install-attach-mv-hook () >> "call this from a capture template to install th:filing-attach-mv-ho= ok" >> (add-hook 'org-capture-before-finalize-hook 'th:filing-attach-mv-hoo= k) >> (make-local-variable 'kill-buffer-hook) >> (add-hook 'kill-buffer-hook 'th:filing-uninstall-attach-mv-hook) >> (add-hook 'org-capture-mode-hook 'th:filing-uninstall-attach-mv-hook= ) >> (message "finalize-hook: %s" org-capture-before-finalize-hook)) >> #+end_src >> >> In the messages buffer I can see that at run time of the function >> `th:filing-attach-mv-hook' is in `org-capture-before-finalize-hook'. >> >> Now when I look at `org-capture-before-finalize-hook' in the final >> capture buffer `th:filing-attach-mv-hook' is not there. >> >> The same happens with `kill-buffer-hook'. I also tried >> `org-capture-prepare-finalize-hook'. Same result. >> >> So I am puzzled here :-(. Is there some caching mechanism involved? Fo= r >> the author of the article stated above this worked with remember - but >> why does it not work with capture. > > Wild guess: capture template is expanded in a temporary buffer, which i= s > killed once the process is complete. Therefore, the uninstall hook > installed in `kill-hook-buffer' removes your function before it is > actually used. that's it! your guess is right! Seems that is what is going on! The function in `kill-buffer-hook' was to remove `th:filing-attach-mv-hook' when capture buffer was killed with C-c C-k. Is there another way to execute lisp code when capture buffer is killed with C-c C-k? I could alter `kill-buffer-hook' globally, but then if another buffer is killed while capture buffer still is there the function is also removed. Hmm ... - I have to think it over maybe I find a solution for that. Anyway thanks a lot for the pointer! --=20 Mit freundlichen Gr=FC=DFen / Best regards=20 Thomas