繁体   English   中英

如何从命令行启动emacs,但如果服务器已在运行,则使用emacsclient?

[英]How do I start emacs from the command line but use emacsclient if a server is already running?

我在Ubuntu下使用emacs

如果我想编辑a.txt,那么我点击emacs图标或使用

$ emacs  --geometry 10x10 --fullscreen --no-splash ~/a.txt &

来自bash。 我的.emacs文件启动了emacs服务器。

如果我想从命令行编辑另一个文件,我使用

$ emacsclient -n ~/b.txt

将文件加载到现有的emacs中。

但我一直都弄错了,所有地狱都以各种方式破裂。

我如何制作一个bash命令' e ',检查emacs服务器是否已经在运行,并执行相应的命令?

尝试使用emacsclient -a开关总会产生不良和不明确的行为。

如果它也可以在控制台上运行时“做正确的事”,那就是额外的积分。

到目前为止,.bashrc中的这个函数定义似乎是一个完美的解决方案:

function e #open emacs in background and disown it, or if already running use emacsclient
{
 echo "emacs function backgrounds and disowns emacs, or calls client if server already running; see .bashrc";
 local FLUFFY="$@";
 local SERVERSOCKET=/tmp/emacs${UID}/server ;
 echo "trying to open: " $FLUFFY 
 echo " checking: " $SERVERSOCKET "for emacs server " ;
 # test for existence of emacs server socket 
 if [ -e $SERVERSOCKET ]; then
     echo "using emacsclient"
     emacsclient -n $FLUFFY;
 else
     echo "starting emacs: make tea..."
     emacs  --geometry 10x10 --fullscreen --no-splash $FLUFFY & disown ;
 fi;
}

这是从这个咒语得出的:

FLUFFY=~/b.txt ; if [ -e /tmp/emacs1000/server ]; then emacsclient -n $FLUFFY; else emacs  --geometry 10x10 --fullscreen --no-splash $FLUFFY & fi;

通过检查用户1000的emacs服务器套接字的存在来做我想要的。

暂无
暂无

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

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