6

In this post it talks about opening org files via find-file.

I'm trying to do this non-interactivley. I try calling:

(find-file "~/git/LeoUfimtsev.github.io/org/" "*.org") 

But instead of opening all org files, it pops up with a list of possible choices.

Can I force it to load all files instead of showing a menu?

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

2 Answers2

4

(find-file "*.org" t).

And do that in directory "~/git/LeoUfimtsev.github.io/org/", if you want the Org files from that directory only.

E.g.:

 (let ((default-directory  "~/git/LeoUfimtsev.github.io/org/"))
   (find-file "*.org" t))

The result of this is the same as if you had used C-x C-f *.org in that directory: All of the Org files in the default directory will be opened (visited in a buffer).


I think maybe you were misreading the doc of find-file, in this sense: I think you were misreading the description of parameter WILDCARDS to be a string of wildcards. Instead, it is a Boolean value that says whether to interpret parameter FILENAME as a glob pattern (i.e., as containing wildcards). Here is that part of the doc string:

Interactively, or if WILDCARDS is non-nil in a call from Lisp, expand wildcards (if any) and visit multiple files. You can suppress wildcard expansion by setting `find-file-wildcards' to nil.

WILDCARDS is only tested to see whether it is non-nil. Expansion of wildcards occurs for FILENAME. So if you pass a FILENAME of *.org and you pass a non-nil value as the second argument (WILDCARDS) then the glob pattern *.org is expanded.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • Instead of setting `default-directory`, it might be easier to just use: `(find-file "~/git/LeoUfimtsev.github.io/org/*.org" t)`. +1, though. I missed how `WILDCARDS` was to be used too! – Some Guy Dec 06 '17 at 16:27
0

Try this:

(mapc #'find-file-noselect
   (directory-files "~/git/LeoUfimtsev.github.io/org/" nil "\\.org$"))

Note that that third argument is not a glob, but an Emacs regex.

Relevant documentation


find-file-noselect is a compiled Lisp function.

(find-file-noselect FILENAME &optional NOWARN RAWFILE WILDCARDS)

Read file FILENAME into a buffer and return the buffer. If a buffer exists visiting FILENAME, return that one, butverify that the file has not changed since visited or saved. The buffer is not selected, just returned to the caller. Optional second arg NOWARN non-nil means suppress any warning messages. Optional third arg RAWFILE non-nil means the file is read literally. Optional fourth arg WILDCARDS non-nil means do wildcard processing and visit all the matching files. When wildcards are actually used and expanded, return a list of buffers that are visiting the various files.


directory-files is a built-in function in `C source code'.

(directory-files DIRECTORY &optional FULL MATCH NOSORT)

Return a list of names of files in DIRECTORY. There are three optional arguments: If FULL is non-nil, return absolute file names. Otherwise return names that are relative to the specified directory. If MATCH is non-nil, mention only file names that match the regexp MATCH. If NOSORT is non-nil, the list is not sorted--its order is unpredictable. Otherwise, the list returned is sorted with `string-lessp'. NOSORT is useful if you plan to sort the result yourself.

PythonNut
  • 10,243
  • 2
  • 29
  • 75