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