How to make emacsclient open each file in a separate "window" in the same "frame"
I am trying to open two files, for example "hello.txt" and "world.txt" in emacsclient from the terminal, and I want them to open in two different windows (as in the emacs sense of the word), but in the same frame.
I am calling emacsclient like this:
emacsclient -nw hello.txt world.txt
What happens is that in one frame of emacsclient, one window is displayed, which displays hello.txt. Another file opens in a buffer that is not displayed.
If I use emacs instead of emacsclient instead, I get the intended output (i.e. two files open in the same frame but in two windows). How do I make emacsclient behave like emacs?
I am not asking for ways to create an emacsclient to create multiple frames, instead I was asking for some way to make emacsclient open multiple files in split windows within the same frame.
It doesn't look like you can do it directly using emacsclient and a list of files
You can achieve the same effect, with a bit of kludge, by passing lisp to emacsclient to do what you want, although it gets a little verbose
emacsclient -t -e '(progn (find-file "file1")(find-file-other-window "file2"))'
Maybe you can wrap this up with a small shell script ec2files.sh
that takes two parameters and interpolates them into this lisp form.
Or write defun, which you load into emacs init, which takes 2 file arguments and opens them.
(defun example-split-window-2-files (f1 f2)
(find-file f1)
(find-file-other-window f2))
and then call this from emacsclient -e
emacsclient -t -e '(example-split-window-2-files "file1" "file2")'
The variable server-window
is what you want to look at. You can set this variable to a function that chooses which window to open.
My emacs config has the following:
(setq server-window 'pop-to-buffer)
This ensures that when (one) file is opened, it uses another window (creating one if necessary) to display the file. You will need to either find or write a function to navigate to the server window, which will keep creating new windows to display files.
Section 37.1, "Calling emacsclient" of the emacs 24.3.1 manual says:
You can also force the
emacsclient' to open a new frame on a graphical display, or on a text terminal, using the
-c 'and `-t' options.