I have a largish tex project that is separated into several tex files. Everytime I want to work on it I open emacs and manually C-x C-f all the files that I want to work on.

I was wondering if there is a way to open files (from command line) from a file containing a list of filenames, something like


file1.tex file2.tex file3.tex

then do

cat files | emacs -nw

except that emacs doesn't support the command used as it doesn't like that stdin is reassigned.

any ideas?

  • 1
    Check out emacs client so you don't start a new emacs every time, but simply open the files in an already running emacs. – Tom Mar 25 '12 at 6:14

Pass it through xargs instead:

cat files | xargs emacs

xargs takes text from stdin and passes it as arguments to the program specified. Piping the files file into is causes it to call emacs something like:

emacs file1.tex file2.tex file3.tex

An alternative to Collin Hockey's suggestion is to use command substitution in your shell. The following syntax works in Bourne like shells (sh, bash, zsh &c.).

emacs $( cat files )

or equivalently (but less readably and more ambiguously)

emacs ` cat files `

Still not an elegant solution, though. I'm not generally an emacs user, but I guess some of the answers here might be what you really want. Have a look!

Neither mine nor Collin's solution will work properly if the list of filenames is longer than getconf ARG_MAX bytes. On my system that is approximately 2 MiB.


This really wont solve your issue but will be a potential alternative. Check out desktop-save-mode If you have certain buffers open when you close emacs, on reopening emacs it will reopen all of the buffers you had.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.