emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Problems with capture and lisp code
@ 2016-01-21  9:55 Thomas Holst
  2016-01-21 13:19 ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Holst @ 2016-01-21  9:55 UTC (permalink / raw)
  To: org-mode mailing list

Hi,

for my work flow I would like to set up a capture template based on the
ideas described in:

http://www.jboecker.de/2010/04/14/general-reference-filing-with-org-mode.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 attach
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-hook"
  (add-hook 'org-capture-before-finalize-hook 'th:filing-attach-mv-hook)
  (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? For
the author of the article stated above this worked with remember - but
why does it not work with capture.

Any pointers welcome. Thanks for looking into this.

-- 
Mit freundlichen Grüßen / Best regards
  Thomas Holst 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problems with capture and lisp code
  2016-01-21  9:55 Problems with capture and lisp code Thomas Holst
@ 2016-01-21 13:19 ` Nicolas Goaziou
  2016-01-21 14:33   ` Thomas Holst
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2016-01-21 13:19 UTC (permalink / raw)
  To: Thomas Holst; +Cc: org-mode mailing list

Hello,

Thomas Holst <thomas.holst@de.bosch.com> writes:

> for my work flow I would like to set up a capture template based on the
> ideas described in:
>
> http://www.jboecker.de/2010/04/14/general-reference-filing-with-org-mode.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 attach
> 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-hook"
>   (add-hook 'org-capture-before-finalize-hook 'th:filing-attach-mv-hook)
>   (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? For
> 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 is
killed once the process is complete. Therefore, the uninstall hook
installed in `kill-hook-buffer' removes your function before it is
actually used.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problems with capture and lisp code
  2016-01-21 13:19 ` Nicolas Goaziou
@ 2016-01-21 14:33   ` Thomas Holst
  2016-01-25 23:28     ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Holst @ 2016-01-21 14:33 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: org-mode mailing list

Hi Nicolas,

· Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:

> Hello,
>
> Thomas Holst <thomas.holst@de.bosch.com> writes:
>
>> for my work flow I would like to set up a capture template based on the
>> ideas described in:
>>
>> http://www.jboecker.de/2010/04/14/general-reference-filing-with-org-mode.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 attach
>> 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-hook"
>>   (add-hook 'org-capture-before-finalize-hook 'th:filing-attach-mv-hook)
>>   (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? For
>> 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 is
> 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!

-- 
Mit freundlichen Grüßen / Best regards 
  Thomas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problems with capture and lisp code
  2016-01-21 14:33   ` Thomas Holst
@ 2016-01-25 23:28     ` Nicolas Goaziou
  2016-01-26  6:38       ` Holst Thomas (DGS-EC/ESE4)
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2016-01-25 23:28 UTC (permalink / raw)
  To: Thomas Holst; +Cc: org-mode mailing list

Hello,

Thomas Holst <thomas.holst@de.bosch.com> writes:

> Is there another way to execute lisp code when capture buffer is killed
> with C-c C-k?

I think `org-capture-after-finalize-hook' should be run nonetheless.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Problems with capture and lisp code
  2016-01-25 23:28     ` Nicolas Goaziou
@ 2016-01-26  6:38       ` Holst Thomas (DGS-EC/ESE4)
  0 siblings, 0 replies; 5+ messages in thread
From: Holst Thomas (DGS-EC/ESE4) @ 2016-01-26  6:38 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: org-mode mailing list

Hello Nicolas,

thank you for the pointer. I will try that and report.

Right now I remap C-c C-k in org-capture-mode. That works for the moment, but I'm not satisfied yet.

Regards
 Thomas Holst

Nicholas writes:

> Hello,
> 
> Thomas Holst <thomas.holst@de.bosch.com> writes:
> 
> > Is there another way to execute lisp code when capture buffer is killed
> > with C-c C-k?
> 
> I think `org-capture-after-finalize-hook' should be run nonetheless.
> 
> Regards,
> 
> --
> Nicolas Goaziou

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-01-26  6:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-21  9:55 Problems with capture and lisp code Thomas Holst
2016-01-21 13:19 ` Nicolas Goaziou
2016-01-21 14:33   ` Thomas Holst
2016-01-25 23:28     ` Nicolas Goaziou
2016-01-26  6:38       ` Holst Thomas (DGS-EC/ESE4)

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).