tags:

views:

353

answers:

2

This is probably a somewhat out-of-wack question. I use tramp to edit remote files, but I also open several terminals ssh-ing to that remote machine as well for other works (I had problems running ssh shell inside emacs).

Often times during the terminal work I would like to edit some file, and my current procedure is to copy the file name, and then use emacs tramp to open that file (after messing all around with getting the file path in the tramp format). This is way too much work for a quick edit and quite error prone in the path handling part.

The question is: Can I execute some command in the remote ssh session that takes the filename, transform that to tramp format (that's the easy part), and run a local command (like emacsclient blahblahblah) so that I can edit the remote file using tramp in my local emacs?

I'm not sure if I'm clear enough. I don't want to run emacs on the remote machine (either on the terminal or through an x session), but I do want to send file to my local emacs from a remote prompt, like this:

user@remote-machien ~/ $ run_local_emacs somefile
# then the file "/ssh:user@remote-machine/:/home/user/somefile" shows up 
# in my local emacs
+1  A: 

You can set up your emacs-server to use a tcp connection (not just a local socket), and then on the remote side, tell emacsclient to connect to that tcp connection:

In your .emacs

(setq server-use-tcp t)
(setq server-host "name_of_local_machine")
(server-start)

And then on the remote side:

emacsclient -f ~/.emacs.d/server/server /`hostname`:/path/to/local/file

The above call to emacsclient brings up a file local to the "remote" machine in your Emacs running in the "local" machine. Obviously you can wrap the call to emacsclient in whatever kind of script you want to make it easier.

If your home directory is not visible on the remote machine, you will need to customize the server-auth-dir variable like so:

(setq server-auth-dir "/some/path/visible/on/both/machines")

For more documentation, see Emacsclient options.

Trey Jackson
So I should start a server on the remote machine as well? I got error when running emacsclient on the remote machine (on ssh): "emacsclient: error accessing server file "~/.emacs.d/server/server"
polyglot
@polyglot No, you don't start a server on the remote machine (that's what you're trying to avoid). The path to the server file must be visible to both machines for this to work. If that's not possible... you might be able to get away with copying the server file over - that's not quite as transparent.
Trey Jackson
Ah it works now. I did copy the server file over but there was some permission error; now it works!
polyglot
A: 

You can use urxvt (an excellent terminal emulator) and write a perl extension to do this even if emacsclient isn't installed on the remote machine.

Ivan Andrus