emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Help debugging a problem when saving org-agenda files with C-x s
@ 2009-05-13  6:12 Tassilo Horn
  2009-05-13  8:55 ` Tassilo Horn
  2009-05-14 14:17 ` Carsten Dominik
  0 siblings, 2 replies; 7+ messages in thread
From: Tassilo Horn @ 2009-05-13  6:12 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,

I use an own function to save the current agenta to a text file, which I
display in a tooltip on my desktop:

--8<---------------cut here---------------start------------->8---
(defun th-org-mode-init ()
  (add-hook 'after-save-hook 'th-org-update-agenda-file t t))

(add-hook 'org-mode-hook 'th-org-mode-init)

;; TODO: This errors when calling C-x s after modifying things in the agenda.
(defun th-org-update-agenda-file (&optional force)
  (interactive)
  (when (and (eq major-mode 'org-mode)
             (member buffer-file-name org-agenda-files))
    (save-excursion
      (save-window-excursion
        (let ((file "/tmp/org-agenda.txt"))
          (org-agenda-list)
          (org-write-agenda file))))))
--8<---------------cut here---------------end--------------->8---

This works fine when I save an agenda file while in its buffer, but when
I edit the file via agenda commands and hit `C-x s', I'm asked if I want
to save "/home/horn/repos/org/uni.org" and say yes, I get this error:

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (error "Agenda file /home/horn/repos/org/uni.org is not in `org-mode'")
  signal(error ("Agenda file /home/horn/repos/org/uni.org is not in `org-mode'"))
  error("Agenda file %s is not in `org-mode'" "/home/horn/repos/org/uni.org")
  org-agenda-get-day-entries("/home/horn/repos/org/uni.org" (5 11 2009) :deadline :scheduled :sexp :timestamp)
  byte-code("...")
  org-agenda-list()
  (let ((file "/tmp/org-agenda.txt")) (org-agenda-list) (org-write-agenda file))
  (save-window-excursion (let (...) (org-agenda-list) (org-write-agenda file)))
  (save-excursion (save-window-excursion (let ... ... ...)))
  (progn (save-excursion (save-window-excursion ...)))
  (if (and (eq major-mode ...) (member buffer-file-name org-agenda-files)) (progn (save-excursion ...)))
  (when (and (eq major-mode ...) (member buffer-file-name org-agenda-files)) (save-excursion (save-window-excursion ...)))
  th-org-update-agenda-file()
  run-hooks(after-save-hook)
  basic-save-buffer()
  save-buffer()
  #[(buffer) "rq. )" [buffer save-buffer] 1](#<buffer uni.org>)
  map-y-or-n-p(#[(buffer) ".!V.!..."])
  byte-code("...")
  save-some-buffers(nil)
  call-interactively(save-some-buffers nil nil)
--8<---------------cut here---------------end--------------->8---

I'm not sure what's the problem here.  /home/horn/repos/org/uni.org is
surely in org-mode!

Any help on that?

Bye,
Tassilo

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

* Re: Help debugging a problem when saving org-agenda files with C-x s
  2009-05-13  6:12 Help debugging a problem when saving org-agenda files with C-x s Tassilo Horn
@ 2009-05-13  8:55 ` Tassilo Horn
  2009-05-14 14:17 ` Carsten Dominik
  1 sibling, 0 replies; 7+ messages in thread
From: Tassilo Horn @ 2009-05-13  8:55 UTC (permalink / raw)
  To: emacs-orgmode

Tassilo Horn <tassilo@member.fsf.org> writes:

> I use an own function to save the current agenta to a text file, which
> I display in a tooltip on my desktop:
>
> (defun th-org-mode-init ()
>   (add-hook 'after-save-hook 'th-org-update-agenda-file t t))
>
> (add-hook 'org-mode-hook 'th-org-mode-init)
>
> ;; TODO: This errors when calling C-x s after modifying things in the agenda.
> (defun th-org-update-agenda-file (&optional force)
>   (interactive)
>   (when (and (eq major-mode 'org-mode)
>              (member buffer-file-name org-agenda-files))
>     (save-excursion
>       (save-window-excursion
>         (let ((file "/tmp/org-agenda.txt"))
>           (org-agenda-list)
>           (org-write-agenda file))))))
>
> This works fine when I save an agenda file while in its buffer, but
> when I edit the file via agenda commands and hit `C-x s', I'm asked if
> I want to save "/home/horn/repos/org/uni.org" and say yes, I get this
> error:

Just a short addition: If I answer yes and get this error, the buffer
contents (and file contents) of uni.org are "Week-agenda (W20):\n".
Thanks I have all my agenda files in git and commit regularly!

Bye,
Tassilo

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

* Re: Help debugging a problem when saving org-agenda files with C-x s
  2009-05-13  6:12 Help debugging a problem when saving org-agenda files with C-x s Tassilo Horn
  2009-05-13  8:55 ` Tassilo Horn
@ 2009-05-14 14:17 ` Carsten Dominik
  2009-05-14 16:43   ` Tassilo Horn
  1 sibling, 1 reply; 7+ messages in thread
From: Carsten Dominik @ 2009-05-14 14:17 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-orgmode


On May 13, 2009, at 8:12 AM, Tassilo Horn wrote:

> Hi all,
>
> I use an own function to save the current agenta to a text file,  
> which I
> display in a tooltip on my desktop:
>
> --8<---------------cut here---------------start------------->8---
> (defun th-org-mode-init ()
>  (add-hook 'after-save-hook 'th-org-update-agenda-file t t))
>
> (add-hook 'org-mode-hook 'th-org-mode-init)
>
> ;; TODO: This errors when calling C-x s after modifying things in  
> the agenda.
> (defun th-org-update-agenda-file (&optional force)
>  (interactive)
>  (when (and (eq major-mode 'org-mode)
>             (member buffer-file-name org-agenda-files))
>    (save-excursion
>      (save-window-excursion
>        (let ((file "/tmp/org-agenda.txt"))
>          (org-agenda-list)
>          (org-write-agenda file))))))
> --8<---------------cut here---------------end--------------->8---
>
> This works fine when I save an agenda file while in its buffer, but  
> when
> I edit the file via agenda commands and hit `C-x s', I'm asked if I  
> want
> to save "/home/horn/repos/org/uni.org" and say yes, I get this error:
>

This probably happens because you are relying on org-agenda-list which  
is supposed to display the agenda window and in this way set the  
selected window and buffer.  In non-interactive use, the buffer is  
created, but display is delayed until after the next idle moment.

Not tested, but this may help:

Replace (org-agenda-write) with this:

(with-current-buffer org-agenda-buffer-name (org-write-agenda file))

HTH

- Carsten

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

* Re: Help debugging a problem when saving org-agenda files with C-x s
  2009-05-14 14:17 ` Carsten Dominik
@ 2009-05-14 16:43   ` Tassilo Horn
  2009-05-14 17:28     ` Carsten Dominik
  0 siblings, 1 reply; 7+ messages in thread
From: Tassilo Horn @ 2009-05-14 16:43 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

Hi Carsten,

>> --8<---------------cut here---------------start------------->8---
>> (defun th-org-mode-init ()
>>  (add-hook 'after-save-hook 'th-org-update-agenda-file t t))
>>
>> (add-hook 'org-mode-hook 'th-org-mode-init)
>>
>> ;; TODO: This errors when calling C-x s after modifying things in the agenda.
>> (defun th-org-update-agenda-file (&optional force)
>>  (interactive)
>>  (when (and (eq major-mode 'org-mode)
>>             (member buffer-file-name org-agenda-files))
>>    (save-excursion
>>      (save-window-excursion
>>        (let ((file "/tmp/org-agenda.txt"))
>>          (org-agenda-list)
>>          (org-write-agenda file))))))
>> --8<---------------cut here---------------end--------------->8---
>>
>> This works fine when I save an agenda file while in its buffer, but
>> when I edit the file via agenda commands and hit `C-x s', I'm asked
>> if I want to save "/home/horn/repos/org/uni.org" and say yes, I get
>> this error:
>
> This probably happens because you are relying on org-agenda-list which
> is supposed to display the agenda window and in this way set the
> selected window and buffer.  In non-interactive use, the buffer is
> created, but display is delayed until after the next idle moment.
>
> Not tested, but this may help:
>
> Replace (org-agenda-write) with this:
>
> (with-current-buffer org-agenda-buffer-name (org-write-agenda file))

No, I'm sorry.  I still get the error, and it's already triggered in the
call to `org-agenda-list' before `org-write-agenda' is called.  The
error is thrown in `org-agenda-get-day-entries'.

Bye,
Tassilo

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

* Re: Help debugging a problem when saving org-agenda files with C-x s
  2009-05-14 16:43   ` Tassilo Horn
@ 2009-05-14 17:28     ` Carsten Dominik
  2009-05-14 18:41       ` Tassilo Horn
  0 siblings, 1 reply; 7+ messages in thread
From: Carsten Dominik @ 2009-05-14 17:28 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-orgmode

Did you restart Emacs?  My idea was that the first time you call this,  
you change the file name of a buffer, and the second time the problem  
happens.

- Carsten

On May 14, 2009, at 6:43 PM, Tassilo Horn wrote:

> Carsten Dominik <carsten.dominik@gmail.com> writes:
>
> Hi Carsten,
>
>>> --8<---------------cut here---------------start------------->8---
>>> (defun th-org-mode-init ()
>>> (add-hook 'after-save-hook 'th-org-update-agenda-file t t))
>>>
>>> (add-hook 'org-mode-hook 'th-org-mode-init)
>>>
>>> ;; TODO: This errors when calling C-x s after modifying things in  
>>> the agenda.
>>> (defun th-org-update-agenda-file (&optional force)
>>> (interactive)
>>> (when (and (eq major-mode 'org-mode)
>>>            (member buffer-file-name org-agenda-files))
>>>   (save-excursion
>>>     (save-window-excursion
>>>       (let ((file "/tmp/org-agenda.txt"))
>>>         (org-agenda-list)
>>>         (org-write-agenda file))))))
>>> --8<---------------cut here---------------end--------------->8---
>>>
>>> This works fine when I save an agenda file while in its buffer, but
>>> when I edit the file via agenda commands and hit `C-x s', I'm asked
>>> if I want to save "/home/horn/repos/org/uni.org" and say yes, I get
>>> this error:
>>
>> This probably happens because you are relying on org-agenda-list  
>> which
>> is supposed to display the agenda window and in this way set the
>> selected window and buffer.  In non-interactive use, the buffer is
>> created, but display is delayed until after the next idle moment.
>>
>> Not tested, but this may help:
>>
>> Replace (org-agenda-write) with this:
>>
>> (with-current-buffer org-agenda-buffer-name (org-write-agenda file))
>
> No, I'm sorry.  I still get the error, and it's already triggered in  
> the
> call to `org-agenda-list' before `org-write-agenda' is called.  The
> error is thrown in `org-agenda-get-day-entries'.
>
> Bye,
> Tassilo

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

* Re: Help debugging a problem when saving org-agenda files with C-x s
  2009-05-14 17:28     ` Carsten Dominik
@ 2009-05-14 18:41       ` Tassilo Horn
  2009-05-16 15:14         ` Carsten Dominik
  0 siblings, 1 reply; 7+ messages in thread
From: Tassilo Horn @ 2009-05-14 18:41 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> Did you restart Emacs?  My idea was that the first time you call this,
> you change the file name of a buffer, and the second time the problem
> happens.

First, I only evaled my function anew, but now I tried with a new emacs
instance and the error is still the same.

But now I can see what happens (but I don't have a solution right now):

  - `C-x s' saves the modified org buffer (I checked that the changes
    are saved to disk)

  - my function is triggered cause it's in `after-save-hook' buffer
    locally

  - somehow the buffer associated with the saved org file uni.org is
    erased and org tries to insert an agendo into this buffer (only one
    propertized line)

           Week-agenda (W20):

    and the major mode is now `org-agenda-mode', which results in the
    error I posted when org tries to create the agenda page.

Bye,
Tassilo
-- 
[Emacs] is written in Lisp, which is the only computer language that is
beautiful.  -- Neal Stephenson, _In the Beginning was the Command Line_

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

* Re: Help debugging a problem when saving org-agenda files with C-x s
  2009-05-14 18:41       ` Tassilo Horn
@ 2009-05-16 15:14         ` Carsten Dominik
  0 siblings, 0 replies; 7+ messages in thread
From: Carsten Dominik @ 2009-05-16 15:14 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-orgmode


On May 14, 2009, at 8:41 PM, Tassilo Horn wrote:

> Carsten Dominik <carsten.dominik@gmail.com> writes:
>
>> Did you restart Emacs?  My idea was that the first time you call  
>> this,
>> you change the file name of a buffer, and the second time the problem
>> happens.
>
> First, I only evaled my function anew, but now I tried with a new  
> emacs
> instance and the error is still the same.
>
> But now I can see what happens (but I don't have a solution right  
> now):
>
> - `C-x s' saves the modified org buffer (I checked that the changes
>   are saved to disk)
>
> - my function is triggered cause it's in `after-save-hook' buffer
>   locally

Calling such functions recursively is never a good idea, even if
it is accidental recursion in this case.

You could and should turn off your hook function in after-safe-hook
for the duration of your command.  On common way to do this is to
make it dependent on a variable and bind this variable dynamically
while you run the hook function


Like

(defvar do-my-hook t)

...

(defun th-org-update-agenda-file (&optional force)
(interactive)
(when (and do-my-hook
            (eq major-mode 'org-mode)
            (member buffer-file-name org-agenda-files))
   (save-excursion
     (save-window-excursion
       (let ((do-my-hook nil)
	     (file "/tmp/org-agenda.txt"))
         (org-agenda-list)
         (org-write-agenda file))))))


HTH

- Carsten



>
> - somehow the buffer associated with the saved org file uni.org is
>   erased and org tries to insert an agendo into this buffer (only one
>   propertized line)
>
>          Week-agenda (W20):
>
>   and the major mode is now `org-agenda-mode', which results in the
>   error I posted when org tries to create the agenda page.
>
> Bye,
> Tassilo
> -- 
> [Emacs] is written in Lisp, which is the only computer language that  
> is
> beautiful.  -- Neal Stephenson, _In the Beginning was the Command  
> Line_

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

end of thread, other threads:[~2009-05-16 17:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-13  6:12 Help debugging a problem when saving org-agenda files with C-x s Tassilo Horn
2009-05-13  8:55 ` Tassilo Horn
2009-05-14 14:17 ` Carsten Dominik
2009-05-14 16:43   ` Tassilo Horn
2009-05-14 17:28     ` Carsten Dominik
2009-05-14 18:41       ` Tassilo Horn
2009-05-16 15:14         ` Carsten Dominik

Code repositories for project(s) associated with this 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).