1

In my bash terminal I have emacs set to run in XWindows. I prefer this to not freeze my terminal session so I run:

emacs filename &

Is there anyway to alias this? I have tried:

xemacs='emacs $1 &'

with no luck.

1

You can create a script to do that for you:

#!/bin/sh
emacs "$@" &
2
  • 2
    to protect arguments that have whitespace, use "$@" instead of $* – glenn jackman Jun 27 '11 at 21:43
  • Thanks, I knew that, but forgot... updated my answer. – Flimzy Jun 27 '11 at 21:47
1

Assuming you're using bash...you can create a shell function by adding this to your .bashrc:

emacs () {
  /usr/bin/emacs "$@" &
}

It accomplishes the same thing as a wrapper, but without the extra wrapper.

2
  • 1
    That is an extra wrapper. The only practical difference is that once it's defined, it's stored in memory, rather than on the file system. – Flimzy Jun 28 '11 at 19:07
  • Yes, that is a more precise way to put it. I personally find it distasteful to have several one line shell scripts. With modern systems with plenty of RAM and disk space it is purely an aesthetic decision. – bahamat Jul 5 '11 at 6:33
0

TL;DR alias "ec=emacsclient -cnqua ''"; ec my_file


I recommend running Emacs in daemon/server mode, where it opens a socket and remains in background waiting for a client to connect.

The most common client, distributed with Emacs and immediately available, is emacsclient.

An important feature of emacsclient is that it can also start Emacs, in daemon mode, if said socket is not available.

To satisfy your requirements you need to start emacsclient with a few non-default options but this can be achieved using a shell alias, e.g.,

$ alias "ec=emacsclient -cnqua ''" # the void string '' is IMPORTANT

where (from emacsclient --help)

-c, --create-frame      Create a new frame instead of trying to
                        use the current Emacs frame

the above ensures that Emacs opens a new frame and doesn't uses the terminal

-n, --no-wait           Don't wait for the server to return

the above frees your terminal

-q, --quiet             Don't display messages on success
-u, --suppress-output   Don't display return values from the server

the above silences as much as possible the client

-a EDITOR, --alternate-editor=EDITOR
                        Editor to fallback to if the server is not running
                        If EDITOR is the empty string, start Emacs in daemon
                        mode and try connecting again

the above is the key, if an Emacs server/daemon is not running, the option -a '' will start a new Emacs server.

You can kill the new frames using the window manager as you see fit but to kill the server you have to use the Emacs command M-x kill-server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.