使用来自ssh会话的emacs流氓来源编辑远程文件 [英] Originate edit of remote file using emacs tramp from ssh session

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

问题描述

这可能是一个有点陌生的问题。我使用流浪汉编辑远程文件,但我也打开几个终端ssh-ing到该远程机器以及其他工作(我有问题在emacs中运行ssh shell)。



通常在终端工作期间,我想编辑一些文件,而我当前的过程是复制文件名,然后使用emacs tramp打开该文件在弄乱了所有的文件路径以流氓格式)。这对于快速编辑来说太多了,在路径处理部分中容易出错。



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



我不知道我是否够清楚我不想在远程机器上运行emacs(在终端上或通过x会话),但是我想要将文件从远程提示符发送到我的本地emacs,如下所示:

  user @ remote-machien〜/ $ run_local_emacs somefile 
#然后文件/ ssh:user @ remote-machine /:/ home / user / somefile在我的本地emacs中显示


解决方案

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



在.emacs中

 (setq server-use-tcp t)
(setq server-主机name_of_local_machine)
(服务器启动)

然后在远程端:

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

上述调用 emacsclient 文件本地到您的Emacs中运行的本地机器中的远程机器。显然,您可以将任何类型的脚本中的 emacsclient 包裹起来。



如果您的主目录在远程机器上不可见,您将需要
来自定义 server-auth-dir 变量,如下所示:

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

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


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.

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

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