6

I am trying to open two files, say 'hello.txt' and 'world.txt' in emacsclient from a terminal and I want them to be opened in two different windows(as in the emacs sense of the word) but in the same frame.

I invoke emacsclient like this:

emacsclient -nw hello.txt world.txt

What presently happens is that a single emacsclient frame shows a single window where hello.txt is displayed. The other file, is opened into a buffer which is not visible.

If I instead use emacs instead of emacsclient I get the intended result(i.e two files get opened within the same frame but in two windows). How can I make emacsclient behave the same way as emacs?

I am not asking for ways to make emacsclient spawn multiple frames, rather I was asking for some way to make emacsclient to open multiple files in split-windows inside the same frame.

Ajoy
  • 525
  • 1
  • 9
  • 20

3 Answers3

4

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.

I have the following in my emacs config:

(setq server-window 'pop-to-buffer)

That ensures that when you open a (single) file it uses another window (creating it if necessary) to display the file. You will need to either find or write a function to pass to server-window that will keep creating new windows for you to display files in.

WillW
  • 871
  • 6
  • 18
3

It doesn't seem like you can do this directly using emacsclient and a file list

You can achieve the same effect, with a bit of a kludge, by passing lisp to emacsclient to do what you want, although it gets a bit verbose

emacsclient -t -e '(progn (find-file "file1")(find-file-other-window "file2"))' 

You perhaps could wrap this is a little shell script ec2files.sh, that takes two parameters and interpolates them into that lisp form.

Or write a defun that you load in emacs init that 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 invoke that from emacsclient -e

emacsclient -t -e '(example-split-window-2-files "file1" "file2")'
cms
  • 5,864
  • 2
  • 28
  • 31
0

Section 37.1, "Invoking `emacsclient'", of the emacs 24.3.1 manual says:

You can also force emacsclient' to open a new frame on a graphical display, or on a text terminal, using the-c' and `-t' options.

Ian Miller
  • 593
  • 3
  • 10
  • This is not what I was asking, I do not want to open new frames, but only a separate window for each of the files. – Ajoy Aug 02 '14 at 08:05