簡體   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