使用来自 ssh 会话的 emacs tramp 对远程文件进行原始编辑 [英] Originate edit of remote file using emacs tramp from ssh session

查看:14
本文介绍了使用来自 ssh 会话的 emacs tramp 对远程文件进行原始编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个有点古怪的问题.我使用 tramp 来编辑远程文件,但我也打开了几个终端 ssh-ing 到该远程机器以及其他工作(我在 emacs 中运行 ssh shell 时遇到问题).

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).

在终端工作期间,我经常想编辑一些文件,我目前的程序是复制文件名,然后使用 emacs tramp 打开该文件(在搞乱了在 Tramp 中获取文件路径之后格式).这对于快速编辑来说工作量太大,并且在路径处理部分很容易出错.

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.

问题是:我是否可以在远程 ssh 会话中执行一些使用文件名的命令,将其转换为 Tramp 格式(这是最简单的部分),然后运行一个 local 命令(例如 emacsclient blahblahblah) 以便我可以在本地 emacs 中使用 tramp 编辑远程文件?

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?

我不确定我是否足够清楚.我不想在远程机器上运行 emacs(在终端上或通过 x 会话),但我确实想从远程提示发送文件到我的本地 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

推荐答案

您可以设置您的 emacs-server 使用 tcp 连接(不仅仅是本地套接字),然后在远程端,告诉 emacsclient 连接到那个tcp连接:

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:

在您的 .emacs 中

In your .emacs

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

然后在远程端:

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

上面对 emacsclient 的调用会在本地"机器上运行的 Emacs 中打开远程"机器本地的文件.显然,您可以将对 emacsclient 的调用包装在您想要使其更容易的任何类型的脚本中.

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.

如果你的主目录在远程机器上不可见,你需要像这样自定义 server-auth-dir 变量:

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")

有关更多文档,请参阅 Emacsclient选项.

For more documentation, see Emacsclient options.

这篇关于使用来自 ssh 会话的 emacs tramp 对远程文件进行原始编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆