Re: [O] Refile: refile to any open file.
Kyle Meyer kyleam.com> writes: > > Nick Dokos gmail.com> wrote: > > jorge.alfaro-murillo yale.edu (Jorge A. Alfaro-Murillo) writes: > [...] > >> Perhaps you should return instead only the org mode files that are > >> opened, something like this: > >> > > > > Excellent idea: refiling to an arbitrary non-org-mode file will either > > skip the file (if you are lucky, in which case you just pay a > > performance penalty) or it will try to use it in which case you'll end > > up with an error. There is no point in including arbitrary files into > > the refile list. > [...] > > It might be better to check the major mode of the buffer, rather than > > its filename: it is not necessarily true that foo.org is an org-mode > > file, or foo.txt is not. > > There's a built-in Org function that does this. > > #+begin_src elisp > (org-buffer-list 'files) > #+end_src > > Thanks Kyle, Jorge, Nick and everybody! Below is the working piece, I take pieces here and there, grateful to everyone's help: (defun ixp/org-buffer-files () "Return list of opened orgmode buffer files" (mapcar (function buffer-file-name) (org-buffer-list 'files))) (setq org-refile-targets (quote ((nil :maxlevel . 3) (ixp/org-buffer-files :maxlevel . 1) (org-agenda-files :maxlevel . 3 It's posted on emacs wiki as well http://www.emacswiki.org/emacs/OrgMode#toc20
Re: [O] Refile: refile to any open file.
Nick Dokos wrote: > jorge.alfaro-muri...@yale.edu (Jorge A. Alfaro-Murillo) writes: [...] >> Perhaps you should return instead only the org mode files that are >> opened, something like this: >> > > Excellent idea: refiling to an arbitrary non-org-mode file will either > skip the file (if you are lucky, in which case you just pay a > performance penalty) or it will try to use it in which case you'll end > up with an error. There is no point in including arbitrary files into > the refile list. [...] > It might be better to check the major mode of the buffer, rather than > its filename: it is not necessarily true that foo.org is an org-mode > file, or foo.txt is not. There's a built-in Org function that does this. #+begin_src elisp (org-buffer-list 'files) #+end_src
Re: [O] Refile: refile to any open file.
jorge.alfaro-muri...@yale.edu (Jorge A. Alfaro-Murillo) writes: > Isaac writes: > >> Similar to this previous post, I am trying to file orgmode items >> to files/buffers currently opened. Being elisp rookie, I tried >> and came up with the following: >> >> (defun opened-buffer-files () >> "Return the list of files currently opened in emacs" (delq nil >> (mapcar (function buffer-file-name) (buffer-list))) ) > > Perhaps you should return instead only the org mode files that are > opened, something like this: > Excellent idea: refiling to an arbitrary non-org-mode file will either skip the file (if you are lucky, in which case you just pay a performance penalty) or it will try to use it in which case you'll end up with an error. There is no point in including arbitrary files into the refile list. > #+BEGIN_SRC emacs-lisp > (delq nil > (mapcar (lambda (x) > (if (and (buffer-file-name x) >(string-match "\\.org$" >(buffer-file-name x))) > (buffer-file-name x))) > (buffer-list))) > #+END_SRC > It might be better to check the major mode of the buffer, rather than its filename: it is not necessarily true that foo.org is an org-mode file, or foo.txt is not. But in general, I think it would be better to use a more targeted approach, rather than trying to use whatever happens to be open at the time. -- Nick
Re: [O] Refile: refile to any open file.
Isaac writes: Similar to this previous post, I am trying to file orgmode items to files/buffers currently opened. Being elisp rookie, I tried and came up with the following: (defun opened-buffer-files () "Return the list of files currently opened in emacs" (delq nil (mapcar (function buffer-file-name) (buffer-list))) ) Perhaps you should return instead only the org mode files that are opened, something like this: #+BEGIN_SRC emacs-lisp (delq nil (mapcar (lambda (x) (if (and (buffer-file-name x) (string-match "\\.org$" (buffer-file-name x))) (buffer-file-name x))) (buffer-list))) #+END_SRC Best, -- Jorge.
Re: [O] Refile: refile to any open file.
Isaac wrote: [...] > Similar to this previous post, I am trying to file orgmode items to > files/buffers currently opened. Some parts of my configuration [1,2] may be close to what you want (or at least give you something to start with). More recently, I've been using a slightly different approach [3] inspired by `dired-dwim-target'. [1] http://kyleam.com/posts/dynamic-org-refile-targets/ [2] https://github.com/kyleam/emacs.d/blob/8ccfbdac75d09cf068348c138fe82787e0e8b809/lisp/init-org.el#L280-313 [3] https://github.com/kyleam/emacs.d/blob/8ccfbdac75d09cf068348c138fe82787e0e8b809/lisp/init-org.el#L256-278
Re: [O] Refile: refile to any open file.
suvayu ali gmail.com> writes: > > On Sun, Feb 26, 2012 at 02:16, gmail.com> wrote: > > I have been using the function oog in org-occur-goto.el to search any > > open file, so somewhere in that file is a way to find open files. What > > remains is to use some condition from this file to declare > > org-refile-targets. I understand that a function can be used as a > > value of this variable. > > Look at the function oog-check-input. I believe it checks buffer-list > and the major-mode for each buffer to determine whether to include it > in the search. > > GL > Dear All, Similar to this previous post, I am trying to file orgmode items to files/buffers currently opened. Being elisp rookie, I tried and came up with the following: (defun opened-buffer-files () "Return the list of files currently opened in emacs" (delq nil (mapcar (function buffer-file-name) (buffer-list))) ) (setq org-refile-targets (quote ((opened-buffer-files :maxlevel . 5) (org-agenda-files :maxlevel . 5 Not suprisingly, it's not working ... I still can not get to the opened file/orgmode files, as target for filing. Can you help point out where I did it all wrong? Simiarly, I would like to add all opened buffers to agenda files list. I would really appreciate your inputs. Thanks, Isaac
Re: [O] Refile: refile to any open file.
On Sun, Feb 26, 2012 at 02:16, wrote: > I have been using the function oog in org-occur-goto.el to search any > open file, so somewhere in that file is a way to find open files. What > remains is to use some condition from this file to declare > org-refile-targets. I understand that a function can be used as a > value of this variable. Look at the function oog-check-input. I believe it checks buffer-list and the major-mode for each buffer to determine whether to include it in the search. GL -- Suvayu Open source is the future. It sets us free.
[O] Refile: refile to any open file.
It occurs from time to time that I wish to refile to an open file, that is not one of my org-refile-targets. It doesn't make sense to use org-agenda-files for refile targets since I might have other files open for various reasons. So I thought, why not either declare that any open file is a refile target, or else write a function that will execture org-refile with org-refile-targets set to include all open files. In truth, it would be even better to include org-agenda-files in the set of target files. I have been using the function oog in org-occur-goto.el to search any open file, so somewhere in that file is a way to find open files. What remains is to use some condition from this file to declare org-refile-targets. I understand that a function can be used as a value of this variable. I could spend all night working on this, or, ask on this list. Can anyone point to a good way to declare that BOTH all open buffers/files AND org-agenda-files as org-refile-targets? A hint would help. Alan Davis