I would like to launch Emacs by typing a command line in the terminal in Ubuntu linux. I want Emacs to open file a.txt in one frame and another file b.txt in another frame. I tried the command *emacs a.txt -f make-frame-command b.txt* Unfortunately this command does not work. It launches one frame with a split buffer containing a.txt and b.txt and another frame with just a.txt

  • you can execute some elisp code to do that : emacs --eval "(progn (find-file \"a.txt\")(find-file-other-frame \"b.txt\") ".
    – gigiair
    Feb 15 '20 at 16:34
  • Unfortunately that proposed code does not work at all. It simply opens a single un-named buffer in emacs
    – Vikram
    Feb 15 '20 at 18:25
  • I just missed the last parenthesis. Try : emacs --eval "(progn(find-file \"a.txt\")(find-file-other-frame \"b.txt\"))". Shame on me...
    – gigiair
    Feb 15 '20 at 19:51
  • thank you - it now works perfectly! Is there a way of passing a variable for the file name to the command? I'd like to put this command in my .bashrc file and open a.txt and b.pdf where a and b are variable names specified by me.
    – Vikram
    Feb 15 '20 at 20:20
  • fA="a.txt";fB="b.txt";emacs --eval "(progn(find-file \"$fA\")(find-file-other-frame \"$fB\"))"
    – gigiair
    Feb 15 '20 at 22:08

Any valid elisp code can be executed when starting Emacs with the --eval option. For instance

 emacs --eval "(progn(find-file \"a.txt\")(find-file-other-frame \"b.txt\"))"


emacs --eval "(find-file \"a.txt\")" --eval "(find-file-other-frame \"b.txt\")"

do the trick.

The first --eval command is unnecessary, you can just type

emacs a.txt --eval "(find-file-other-frame \"b.txt\")"

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.