简体   繁体   中英

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

您可以使用urxvt(一个优秀的终端模拟器)并编写perl扩展来执行此操作,即使远程计算机上未安装emacsclient也是如此。

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.

Cx Cf /ssh:remotehost:/ Tab Tab

This works best when you've got SSH keys or similar passwordless access set up, but it sounds like you have that already.

我在这里做的是从远程到本地的反向ssh连接,并在本地运行emacsclient:

me@remote-machine$ ssh -f me@local-machine emacsclient /ssh:remote-machine/$(realpath my-file-name)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM