Re: [O] automagically add/remove org mode buffers to agenda files list (was: Re: collect info from org files in agenda when open?)
Hi Drew, org-mode-community, * Drew Adams drew.ad...@oracle.com [14. Jul. 2013]: (add-hook 'kill-buffer-hook 'org-remove-file) But the last hook does not work as espected. Instead it says Current buffer does not visit a file. But according to the documentation kill-buffer-hook is run before the buffer is actually killed and the buffer is current when calling the hook. Any ideas what I'm doing wrong? I have no idea what `org-remove-file' does, but if it expects the current buffer to be visiting a file then that explains your problem. `kill-buffer-hook' is run whenever ANY buffer is killed, not just a buffer visiting a file. And Emacs uses lots of buffers that are not visiting files. What you can do is use a different function, `foo', that first tests whether the current buffer is the kind of buffer you want to apply `org-remove-file' to, and if so invoke that, and if not do nothing. Thanks, this helped. For the record: I wrote function which tests if the current buffer is associated with a file and if it is in org-mode. Iff so I remove it from the list of agenda files. Ciao, Gregor -- -... --- .-. . -.. ..--.. ...-.-
[O] automagically add/remove org mode buffers to agenda files list (was: Re: collect info from org files in agenda when open?)
Hi Eric, org-mod users and developers, * Eric Abrahamsen e...@ericabrahamsen.net [13. Jul. 2013]: Gregor Zattler telegr...@gmx.net writes: But I wished there was also the ability to define a list of files which do only contribute to the agenda if already open (preferably with some pattern matching, so one could customize org to add any open org file to the agenda). You could certainly do this with a function attached to `find-file-hook'. In the function, check if (buffer-file-name) ends in .org: if it does, then `org-agenda-file-to-front' and you're good to go. Your answer motivated me to play with org-mode-hook. Now I have the following as part of my init.el: ; start with diary in agenda (setq org-agenda-files '(~/org/diary.org)) ; automatically add org files to agenda (add-hook 'org-mode-hook 'org-agenda-file-to-front) ; automagically remove killed org buffers from agenda files list (add-hook 'kill-buffer-hook 'org-remove-file) But the last hook does not work as espected. Instead it says Current buffer does not visit a file. But according to the documentation kill-buffer-hook is run before the buffer is actually killed and the buffer is current when calling the hook. Any ideas what I'm doing wrong? Ciao, Gregor -- -... --- .-. . -.. ..--.. ...-.-
Re: [O] automagically add/remove org mode buffers to agenda files list (was: Re: collect info from org files in agenda when open?)
(add-hook 'kill-buffer-hook 'org-remove-file) But the last hook does not work as espected. Instead it says Current buffer does not visit a file. But according to the documentation kill-buffer-hook is run before the buffer is actually killed and the buffer is current when calling the hook. Any ideas what I'm doing wrong? I have no idea what `org-remove-file' does, but if it expects the current buffer to be visiting a file then that explains your problem. `kill-buffer-hook' is run whenever ANY buffer is killed, not just a buffer visiting a file. And Emacs uses lots of buffers that are not visiting files. What you can do is use a different function, `foo', that first tests whether the current buffer is the kind of buffer you want to apply `org-remove-file' to, and if so invoke that, and if not do nothing.