[英]How do I start emacs from the command line but use emacsclient if a server is already running?
I'm using emacs under Ubuntu 我在Ubuntu下使用emacs
If I want to edit a.txt then I either click on the emacs icon or use 如果我想编辑a.txt,那么我点击emacs图标或使用
$ emacs --geometry 10x10 --fullscreen --no-splash ~/a.txt &
from bash. 来自bash。 My .emacs file starts the emacs server.
我的.emacs文件启动了emacs服务器。
If I then want to edit another file from the command line, I use 如果我想从命令行编辑另一个文件,我使用
$ emacsclient -n ~/b.txt
to load the file into the existing emacs. 将文件加载到现有的emacs中。
but I keep getting it wrong, and all hell breaks loose in various ways. 但我一直都弄错了,所有地狱都以各种方式破裂。
How would I make a bash command ' e ', that checks whether the emacs server is already running, and executes the appropriate command? 我如何制作一个bash命令' e ',检查emacs服务器是否已经在运行,并执行相应的命令?
Attempts to use the emacsclient -a
switch invariably produce undesirable and ill-determined behaviour. 尝试使用
emacsclient -a
开关总会产生不良和不明确的行为。
Extra points if it can 'do the right thing' when run on a console too. 如果它也可以在控制台上运行时“做正确的事”,那就是额外的积分。
So far this function definition in .bashrc seems to be a perfect solution: 到目前为止,.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;
}
which was derived from this incantation: 这是从这个咒语得出的:
FLUFFY=~/b.txt ; if [ -e /tmp/emacs1000/server ]; then emacsclient -n $FLUFFY; else emacs --geometry 10x10 --fullscreen --no-splash $FLUFFY & fi;
which does what I want by checking for the existence of the emacs server socket for user 1000. 通过检查用户1000的emacs服务器套接字的存在来做我想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.