Originate edit of remote file using emacs tramp from ssh session
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
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.
Theres also http://www.emacswiki.org/emacs/AnsiTermHints#toc4
Incorporates remote directory tracking which lets tramp open remote files as if it was local
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.
Maybe you already know about this and it doesn't work well for you, but when I've needed to do that sort of thing the filename completion in TRAMP has been helpful enough that I've never thought of looking for alternatives.
C-xC-f/ssh:remotehost:/
TabTab
This works best when you've got SSH keys or similar passwordless access set up, but it sounds like you have that already.
What I am doing here is a reverse ssh connection from remote to local and running emacsclient locally:
me@remote-machine$ ssh -f me@local-machine emacsclient /ssh:remote-machine/$(realpath my-file-name)
精彩评论