When I open multiple files at once with emacs, like emacs file1 file2, it opens the two files side-by-side (in different windows in the same frame). But when I do the same with emacsclient, it only shows the first one. The others are also opened but not visible. How do I get the emacs behavior with emacsclient?


1 Answer 1


If you want this behavior to be systematic, here's a way to modify the behavior of server-visit-files to take over the window configuration and split the window evenly into the files that are being visited.

(defvar server-visit-files-custom-find:buffer-count)
(defadvice server-visit-files
  (around server-visit-files-custom-find
      activate compile)
  "Maintain a counter of visited files from a single client call."
  (let ((server-visit-files-custom-find:buffer-count 0))
(defun server-visit-hook-custom-find ()
  "Arrange to visit the files from a client call in separate windows."
  (if (zerop server-visit-files-custom-find:buffer-count)
    (switch-to-buffer (current-buffer)))
    (let ((buffer (current-buffer))
      (window (split-window-sensibly)))
      (switch-to-buffer buffer)
  (setq server-visit-files-custom-find:buffer-count
    (1+ server-visit-files-custom-find:buffer-count)))
(add-hook 'server-visit-hook 'server-visit-hook-custom-find)

An improvement would be to make C-x # kill the window. I think this would require patching both server-edit to set a flag and server-switch-buffer to kill the window if this flag is raised.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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