5

I've got a couple dozen org files that I'd like to have loaded at once. They're in a directory structure something like this:

org/dev
org/dev/python.org
org/dev/emacs.org
...
org/dev/ios
org/dev/ios/swift.org
...
org/dev/android
org/dev/android/android.org
org/ergo
org/ergo/programming_by_voice.org
...

What's the best way to load all these files at once so that I can have the buffers in memory when I'm working on my notes? It's nice to be able to type C-x b and have my buffers listed for autocomplete with ido, rather than navigating the directory tree.

h4labs
  • 269
  • 1
  • 9
  • 1
    Would you be interested in using the `org-agenda-files` or do you have files that are not a part of that list, or do you have only some of those files and wish to exclude others in the list? Essentially, I'm asking whether it is necessary to select the region of text in your buffer to extract a list of files, or whether that list already exists somewhere else -- e.g., `org-agenda-files`. – lawlist Dec 30 '14 at 07:00
  • 1
    Something like this will open all of the `org-agenda-files` (*if* you want everything that is a part of that list, the elements of which are determined based upon your user configuration): `(defun open-all-org-agenda-files () (interactive) (let ((files (org-agenda-files))) (mapcar (lambda (x) (find-file x)) files)))` – lawlist Dec 30 '14 at 07:19
  • It's achievable with https://github.com/abo-abo/helm-org-wiki if you're willing to invest some effort to set it up. – abo-abo Dec 30 '14 at 12:51
  • I'm a little unsure what exactly you want. Do you want to be able to open multiple files at one time, and your question is unrelated to org? Do you want to define a project as a collection of specific files and open them all at once? Do you want to define a project and let `find-file' included all files in the project? – grettke Dec 31 '14 at 01:55
  • @grettke I have a set of org files that I want to work on at the same time. So, I'd like to have these easily accessible so I don't have to navigate up/down directories to find them. Seems reasonable, right? I publish by simply using 'org-publish-project'. I defined the project so I'd like to take advantage of that. I guarantee that I'm not the first person want to do this. – h4labs Jan 01 '15 at 16:27
  • @h4labs Definitely not the first. My preference is Projectile combined with DesktopSaveMode. I open up everything that I need an leave the buffers open for a while. Some people like traditional projects like you would find in Eclipse for example. There are a bunch of options listed here http://www.emacswiki.org/emacs/CategoryProject. I would be interested to know what you like here, or not. – grettke Jan 02 '15 at 22:25
  • @grettke Funny that when I read your hidden comment (SE does not show all comments by default), you had already suggested the exact same thing I suggested in my solution below :) – Kaushal Modi Jan 18 '15 at 16:50

3 Answers3

7

You can use wildcards with find-file:

C-x C-f ~/path/to/*.org RET

This will open all org files in /path/to/. You could also use find-file-other-frame to instantly display all the buffers that were created. Otherwise the buffers are created but only one is displayed initially.

This does not open org files in subdirectories. To do that additionally use

C-x C-f ~/path/to/*/*.org RET

Use additional instances of */ to open files nested even deeper. I don't think there's a magical wildcard that stands for "this directory and all its subdirectories".

tarsius
  • 25,298
  • 4
  • 69
  • 109
  • How do I use this programmatically? I tried (find-file "~/org" "*.org") but instead of loading the files, it shows all the files that are matching and I can select which to load. – Leo Ufimtsev Feb 20 '15 at 20:17
5

@Lawlist gave a nice snippet of code in his comment. You can assign a function to load all org files via:

(defun my/open-all-org-agenda-files () 
  (interactive) 
  (let ((files (org-agenda-files))) (mapcar (lambda (x) (find-file x)) files))) 

(this is his code, if you like this, please up-vote his comment)

Now you can add files to your agenda file list very quickly via: C - c [ . You can view/edit your current file list via var: org-agenda-files. C - c h then type: org-agenda-files to view/customize it.

You can add a line of code to the end of your .emacs to load these file on start-up:

(my/open-all-org-agenda-files)

Hope it helps.

[edit] in hind sight, the above doesn't work that well as all those files are added to agenda clock reports, making reports very long with many files showing 0 time.

[edit2]
In hind-hind sight, this does actually work. I simply add the :fileskip0 parameter and it skips files where time is zero.

Leo Ufimtsev
  • 4,488
  • 3
  • 22
  • 45
4

As @grettke mentioned in the comments, this question is not specific to org mode. From what I understand you need a solution to quickly open any file from a "project".

If that's the case, you can try using the projectile package, also available through Melpa.

For projectile to work on your set of files, you need to define that set as being a part of a "project". The easiest way to do so is by doing git init in the base directory of your "project" i.e. org directory. You can do this even if you don't plan to later git manage your files.

Once you have projectile set up as per its documentation, here are some usage scenarios:

  • Let's say you have one of your org files open and you want to open some other file from the same "project". You can do that by doing C-c p f or M-x projectile-find-file.
  • Let's say you are working on a file NOT in that "project" and you want to quickly go to one of your org files. You can do C-c p p or M-x projectile-switch-project, select the project you want to switch to ( org ) and then pick one of the files from that project.

This setup compliments very well with the emacs built-in desktop package.

The simplest way to get the desktop save and restore working is by adding these to your emacs init.

(require 'desktop)
(desktop-save-mode 1) 
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179