Christian Neverdal
Christian Neverdal

Reputation: 5375

emacs: Automatically open corresponding file in another instance

I want something similar to Emacs C++, opening corresponding header file except that I want to

1) Always automatically open the corresponding header; and

2) Do that in another emacs instance (if someone came up with a solution that made all other emacs instances do this, it would be fine also.)

Note that I use emacs in the terminal mode so I can't do https://superuser.com/questions/102163/how-to-split-emacs-over-a-dual-monitor (or at least I do not know how).

Upvotes: 3

Views: 254

Answers (1)

joachifm
joachifm

Reputation: 99

A simple solution to 2) is to run an emacs instance with server-mode enabled in the second terminal and command it from the main emacs instance by using server-eval-at.

To launch the slave, run:

$ emacs --eval '(progn (setq server-name "ff-slave") (server-mode 1))'

Then use the following code to command it:

(require 'server)
(require 'find-file)

(defun command-ff-slave ()
  (interactive)
  (save-excursion
    (let ((b (ff-other-file-name)))
      (if (null b)
          (message "Found no other file")
          (server-eval-at "ff-slave"
                          `(find-file ,b))))))

Calling command-ff-slave from the main emacs instance should open any related file in a new buffer on the slave server.

Upvotes: 2

Related Questions