Re: [O] Problems with capture and lisp code

2016-01-25 Thread Holst Thomas (DGS-EC/ESE4)
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  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



Re: [O] Problems with capture and lisp code

2016-01-25 Thread Nicolas Goaziou
Hello,

Thomas Holst  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



Re: [O] Problems with capture and lisp code

2016-01-21 Thread Nicolas Goaziou
Hello,

Thomas Holst  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



[O] Problems with capture and lisp code

2016-01-21 Thread Thomas Holst
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 



Re: [O] Problems with capture and lisp code

2016-01-21 Thread Thomas Holst
Hi Nicolas,

· Nicolas Goaziou  wrote:

> Hello,
>
> Thomas Holst  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



Re: [O] Problems with capture

2015-12-08 Thread Thomas Holst
Hi Nicolas,
· Nicolas Goaziou  wrote:
> Thomas Holst  writes:

> [...snip...]

after a git-pull the first error (about cache) is gone. The second error
still is there:


>>   condition-case: Capture template `hr': Invalid table line specification 
>> "III-1"

The table which was inserted looks like this:

#+begin_src org
  ** OPEN [2015-12-08 Di] Rechnungen
  #+NAME: akt-vers-rechnungen
  
|---+---+--+-++---+-++-|
  | ! | Datum | Arzt | für wen | Betrag | wann bez. | wann bearb. | wann erh. 
Vers | wann erh. Beih. |
  
|---+---+--+-++---+-++-|
  
|---+---+--+-++---+-++-|
  | # |   |  | |   0.00 |   | |   
0.00 |0.00 |
  
|---+---+--+-++---+-++-|
  #+TBLFM: $8=$5*0.2;%.2f::$9=$5*0.8;%.2f::@2$5=vsum(@-II..@-I);%.2f
#+end_src

After creation point is at beginning of headline (left of the two *).
>From my point of view table line specification "III-1" is ok.

Thanks for looking into this.

-- 
Mit freundlichen Grüßen / Best regards 

Thomas Holst 
DGS-EC/ESE4

Tel.   +49 (711) 811-40681
PC-Fax +49 (711) 811-5182208



Re: [O] Problems with capture

2015-12-08 Thread Thomas Holst
Hi Nicolas,

replying to myself :-),

I dug a little deeper into this.

· Thomas Holst  wrote:
> Hi Nicolas,
> · Nicolas Goaziou  wrote:
>> Thomas Holst  writes:
>
>> [...snip...]
>
> after a git-pull the first error (about cache) is gone. The second error
> still is there:
>
>>>   condition-case: Capture template `hr': Invalid table line specification 
>>> "III-1"
>
> The table which was inserted looks like this:
> #+begin_src org
>   ** OPEN [2015-12-08 Di] Rechnungen
>   #+NAME: akt-vers-rechnungen
>   
> |---+---+--+-++---+-++-|
>   | ! | Datum | Arzt | f+r wen | Betrag | wann bez. | wann bearb. | wann erh. 
> Vers | wann erh. Beih. |
>   
> |---+---+--+-++---+-++-|
>   
> |---+---+--+-++---+-++-|
>   | # |   |  | |   0.00 |   | |   
> 0.00 |0.00 |
>   
> |---+---+--+-++---+-++-|
>   #+TBLFM: $8=$5*0.2;%.2f::$9=$5*0.8;%.2f::@2$5=vsum(@-II..@-I);%.2f
> #+end_src
> After creation point is at beginning of headline (left of the two *).
> From my point of view table line specification "III-1" is ok.
>
> Thanks for looking into this.

The culprit is `org-capture-place-table-line'. It narrows the buffer to
relevant table but leaves point at the beginning of an empty line.
`org-table-analyze' does not any table and exits with nil.

For me the following patch fixes the problem:

#+begin_src diff
1 file changed, 1 insertion(+)
lisp/org-capture.el | 1 +

modified   lisp/org-capture.el
@@ -1156,6 +1156,7 @@ may have been stored before."
   (goto-char end)
   (insert "\n|   |\n||\n||\n")
   (narrow-to-region (1+ end) (point)))
+(goto-char (point-min))
 ;; We are narrowed to the table, or to an empty line if there was no table
 
 ;; Check if the template is good
#+end_src

Maybe there is a better way to fix this.

Thanks again for lookint into this.

-- 
Mit freundlichen Grüßen / Best regards 

Thomas Holst 



[O] Problems with capture

2015-12-07 Thread Thomas Holst
Hello org-moders,

I have a little trouble with capture. First here is the setup for one of
my capture templates:

#+begin_src emacs-lisp
(setq org-capture-templates
  '(
;; ...
("hr" "Rechnung erfassen" table-line (file+function 
"~/git/org-priv/Univ_Beih.org" th:capure-find-open-vers-regn)
 "| # | %^u | %^{Arzt/Apotheke} | %^{für wen|Lida|Oleg|Victor|Simon} | 
%^{Betrag} | %^u | | | |"
 :table-line-pos "III-1" :immediate-finish t)
;; ...
))
#+end_src

What this template shall achive:

- look if there is an entry (headline) with todo state OPEN
- if entry exists append a table line
- if entry does not exist, create a new headline, insert table structure
  and append line to newly created table.

The function `th:capture-find-open-vers-regn' does this. Creating works
fine, but a get an error:

  Error running timer `org-element--cache-sync': (error "Invalid search bound 
(wrong side of point)")

and:

  condition-case: Capture template `hr': Invalid table line specification "III-1

I use something like:

#+begin_src emacs-lisp
(org-element-map (org-element-parse-buffer) 'headline
   (lambda (hl)
 (and
  (string= "Rechnungen" (car (org-element-property :title hl)))
  (= 1 (org-element-property :level hl))
  (org-element-property :begin hl)))
   nil t)
#+end_src

To find the Position in the file and regular

: (insert "a huge string")

To insert new heading and table structure. The new structure is created,
but something breaks caching. How can I insert the new structure without
breaking caching?

Thanks for any pointers.

P.S.
Org-mode version 8.3.2 
(release_8.3.2-359-g6b2c38 @ /home/thommy/git-emacs/org-mode/lisp/)

GNU Emacs 24.5.1 (i686-pc-linux-gnu, GTK+ Version 2.24.23) 
of 2015-07-03 on thommy-desktop

-- 
Bis neulich ...
  Thomas



Re: [O] Problems with capture

2015-12-07 Thread Nicolas Goaziou
Hello,

Thomas Holst  writes:

> I have a little trouble with capture. First here is the setup for one of
> my capture templates:
>
> #+begin_src emacs-lisp
> (setq org-capture-templates
>   '(
> ;; ...
> ("hr" "Rechnung erfassen" table-line (file+function 
> "~/git/org-priv/Univ_Beih.org" th:capure-find-open-vers-regn)
>  "| # | %^u | %^{Arzt/Apotheke} | %^{fr wen|Lida|Oleg|Victor|Simon} | 
> %^{Betrag} | %^u | | | |"
>  :table-line-pos "III-1" :immediate-finish t)
> ;; ...
> ))
> #+end_src
>
> What this template shall achive:
>
> - look if there is an entry (headline) with todo state OPEN
> - if entry exists append a table line
> - if entry does not exist, create a new headline, insert table structure
>   and append line to newly created table.
>
> The function `th:capture-find-open-vers-regn' does this. Creating works
> fine, but a get an error:
>
>   Error running timer `org-element--cache-sync': (error "Invalid search bound 
> (wrong side of point)")
>
> and:
>
>   condition-case: Capture template `hr': Invalid table line specification 
> "III-1
>
> I use something like:
>
> #+begin_src emacs-lisp
> (org-element-map (org-element-parse-buffer) 'headline
>(lambda (hl)
>  (and
>   (string= "Rechnungen" (car (org-element-property :title hl)))
>   (= 1 (org-element-property :level hl))
>   (org-element-property :begin hl)))
>nil t)
> #+end_src
>
> To find the Position in the file and regular
>
> : (insert "a huge string")
>
> To insert new heading and table structure. The new structure is created,
> but something breaks caching. How can I insert the new structure without
> breaking caching?

I think I fixed something related recently. Could you update Org and try
again?


Regards,

-- 
Nicolas Goaziou



Re: [O] Problems with capture in tables

2011-05-05 Thread Aankhen
Hi,

On Wed, May 4, 2011 at 12:55, Thomas Holst thomas.ho...@de.bosch.com wrote:
 I am trying to put a line into a table via org capture.

 My org file looks like this:
 [snip]

 My capture template looks like this:
 #+begin_src emacs-lisp
 (setq org-capture-templates
      '((x Testing table-line
       (file+headline c:/temp/TestCaptTbl.org Heading 1)
           | # | %t | %^{weight} | | :table-line-pos II-1)))
 #+end_src

 When I invoke capture I get the following error (backtrace):

 [snip]

 Now if I leave `:table-line-pos II-1' out of the template it works fine
 but the line is appended at the end. That's obviously not what I want.

 [snip]

As far as I can tell, the value of ‘:table-line-pos’ is supposed to be
a string.  This seems to work for me:

,
| (setq org-capture-templates
|   '((x Testing table-line
|  (file+headline Z:/temp/TestCaptTbl.org Heading 1)
|  | # | %t | %^{weight} | | :table-line-pos II-1)))
`

Hope this helps.
Aankhen



Re: [O] Problems with capture in tables

2011-05-05 Thread Thomas Holst
Hi Aankhen,

thanks for your answer.
· Aankhen aank...@gmail.com wrote:

 Hi,

 On Wed, May 4, 2011 at 12:55, Thomas Holst thomas.ho...@de.bosch.com wrote:
 I am trying to put a line into a table via org capture.

 My org file looks like this:
 [snip]

 My capture template looks like this:
 #+begin_src emacs-lisp
 (setq org-capture-templates
      '((x Testing table-line
       (file+headline c:/temp/TestCaptTbl.org Heading 1)
           | # | %t | %^{weight} | | :table-line-pos II-1)))
 #+end_src

 When I invoke capture I get the following error (backtrace):

 [snip]

 Now if I leave `:table-line-pos II-1' out of the template it works fine
 but the line is appended at the end. That's obviously not what I want.

 [snip]

 As far as I can tell, the value of ‘:table-line-pos’ is supposed to be
 a string.  This seems to work for me:

 ,
 | (setq org-capture-templates
 |   '((x Testing table-line
 |  (file+headline Z:/temp/TestCaptTbl.org Heading 1)
 |  | # | %t | %^{weight} | | :table-line-pos II-1)))
 `

 Hope this helps.
 Aankhen

That did the trick - works like a charm! I was shure I tried the string,
but I assume there was a typing error.

Thanks again.

-- 
Mit freundlichen Grüßen / Best regards 

Thomas Holst 



[O] Problems with capture in tables

2011-05-04 Thread Thomas Holst
Hello,

I am trying to put a line into a table via org capture.

My org file looks like this:
#+begin_src org

* Heading 1

  #+TBLNAME: Testing

  |   | date| weight |  BMI |
  |---+-++--|
  | # | 2011-05-02 Mo | 85 | 24.8 |
  | # | 2011-05-03 Di | 82 | 24.0 |
  |---+-++--|
  | # | |3.0 |  0.9 |
  #+TBLFM: $4=$3/(1.85)^2;%.1f::@4$3=(@I - @II-1);%.1f

#+end_src

My capture template looks like this:
#+begin_src emacs-lisp
(setq org-capture-templates
  '((x Testing table-line
   (file+headline c:/temp/TestCaptTbl.org Heading 1)
   | # | %t | %^{weight} | | :table-line-pos II-1)))
#+end_src

When I invoke capture I get the following error (backtrace):

: Debugger entered--Lisp error: (error Capture template `x': stringp)
:   signal(error (Capture template `x': stringp))
:   error(Capture template `%s': %s x stringp)
:   byte-code(\301p!\203

Now if I leave `:table-line-pos II-1' out of the template it works fine
but the line is appended at the end. That's obviously not what I want.

Tested this with =emacs -Q=
GNU Emacs 23.2.1 (i386-mingw-nt5.1.2600) of 2010-05-08 on G41R2F1
Org-mode version 7.5 (release_7.5.246.gace72) (local modification to
makefile and org-git-link)
WinXP

-- 
Mit freundlichen Grüßen / Best regards 

Thomas Holst