简体   繁体   English

Emacs - 用于确定远程服务器名称/地址的dired-mode测试

[英]Emacs — dired-mode test to determine remote server name / address

Is there a test to obtain the remote server name (eg, localhost ) or address (eg, 12.34.56.789 ) in the current-buffer with dired-mode active? 是否有一个测试来获取current-buffer的远程服务器名称(例如localhost )或地址(例如, 12.34.56.789 )以及dired-mode active?

I suppose I could use string-match or split-string and then equal , but I thought there might be a handy function like get server name. 我想我可以使用string-matchsplit-string然后equal ,但我认为可能有一个方便的函数,如获取服务器名称。

iphone -- dired-directory iphone - dired-directory

/ssh:root@localhost#2222:/var/mobile/Applications/F30B1574-5979-4764-8742-7F9DB2863094/Documents/.0.data:

shared server -- dired-directory 共享服务器 - dired-directory

/ssh:lawlist@12.34.56.789:/home/lawlist/public_html:

If it's tramp paths you're interested in, then you probably want to look at tramp-dissect-file-name or with-parsed-tramp-file-name . 如果它是您感兴趣的tramp路径,那么您可能希望查看tramp-dissect-file-namewith-parsed-tramp-file-name eg: 例如:

(tramp-file-name-host (tramp-dissect-file-name path))

If you want to exclude the port, use tramp-file-name-real-host . 如果要排除端口,请使用tramp-file-name-real-host

You might need to check file-remote-p first, if that's not already certain; 你可能需要先检查file-remote-p ,如果还不确定的话。 and that also leads us to a nice shortcut I'd never noticed before: 这也引导我们找到一条我从未注意过的好捷径:

(file-remote-p path 'host)

(no port-less option here, if would seem) (这里没有无端口选项,如果有的话)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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