开发者

create emacs alias that starts in background?

开发者 https://www.devze.com 2022-12-20 04:10 出处:网络
I have an alias in bash that runs emacsclient if emacs daemon is already running and start emacs otherwise. However, in the event that a fresh instance of emacs is fired up, can I make it run in the b

I have an alias in bash that runs emacsclient if emacs daemon is already running and start emacs otherwise. However, in the event that a fresh instance of emacs is fired up, can I make it run in the background so I can still use that terminal (or close it)? In my bash profile, I have

alias ec="/usr/bin/emacsclient.emacs-snapshot -n -c -a /usr/bin/emacs-snapshot"

And I might be at the terminal and type

$ ec newfile

If emacs daemon is not already running, is there an alias I can create to make the line above do the equivalent of

$ emacs newfile &
开发者_开发知识库

instead of

$ emacs newfile

(I should also mention that I am using Linux Ubuntu and emacs-snapshot is assigned to the alias, 'emacs').

Thanks much!


Instead of calling /usr/bin/emacs-snapshot directly, write a script that calls /usr/bin/emacs-snapshot in the background and then returns:

#!/bin/sh
case $# in
  0) /usr/bin/emacs-snapshot &
  *) /usr/bin/emacs-snapshot "$@" &
esac

Then you call the script in the ordinary way; it will launch a background emacs process and return immediately.

If you want to get fancy you can use /bin/bash and disown the process after the esac (get the pid with $!).


While this is not the direct answer to your question, this is the more elegant way to "start emacs deamon or run emacsclient otherwise". Create the following alias: alias emacs=emacsclient -c -a "". As of man emacsclient:

-a, --alternate-editor=EDITOR ... If the value of EDITOR is the empty string, run `emacs --daemon' to start Emacs in daemon mode, and try to connect to it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号