Hacker News new | ask | show | jobs
by atjoslin 4079 days ago
Run `emacs -nw --daemon` to start a background emacs server.

Now, you can do `emacsclient -nw <file>` to boot up with almost no startup time. I have vi aliased to this, and `emacs -nw --daemon` opened by launchctl.

A gotcha: If you change your emacs config and need to restart, be sure to `pkill emacs` to get rid of the daemon.

6 comments

I have these in ~/.bash_aliases:

    alias e="emacsclient -t -a ''"
    alias eb="emacsbare"
    alias ec="emacsclient -c -n -a ''"
    alias emacsbare="emacs -nw -Q --eval \"(load-theme 'misterioso)\""
    alias vim="e"
    alias vi="e"
eb/emacsbare very quickly fires up a "clean" (ignores init files) terminal-mode Emacs instance.

e/vim/vi launches a terminal-mode client for the Emacs daemon, which only takes a split-second if the daemon is already running. If the daemon isn't running, it gets started automatically by virtue of the empty string being passed with the -a flag, per the man page for emacsclient.

ec launches a "gui-mode" (X/quartz) client for the daemon, which is started automatically if isn't running, same as before.

UniPress "Evil Software Hoarder [TM]" Emacs had a vi emulation mode such that when you typed ":q", it flipped you over into an Emacs shell window with key bindings to behave just like you'd expect had you actually exited your text editor. Of course the shell mode was hacked so "vi foo.c" would flip you back into a vi-mode buffer on foo.c. Poor innocent vi users didn't even realize they hadn't left the editor! It was kind of like being in the Ematrix.
Actually, inside any client, you can do M-x eval-buffer and re-evaluate your whole .emacs.

http://www.gnu.org/software/emacs/manual/html_node/emacs/Lis...

A note: I' be careful though, because depending on how you create your variables, thing can go wrong, I guess: if you-re going to use eval-buffer on your whole .emacs, I'd better use, for example, add-hook instead to add-to-list:

    (add-hook c-mode-hook 'linum'mode)
instead of:

    (add-to-list c-mode-hook 'linum-mode)
Just saying. Have fun with your configs :)
The first arg to add-hook must be a symbol, like so:

   (add-hook 'c-mode-hook 'linum-mode)
Or `emacsclient -e '(kill-emacs)'` in case you have anything open or whatever.
The one thing I hate about emacs client (and I was bitching about it on #emacs the other day as well) is that in OS X, a windowed client will just "hang" when exited. It will still be visible in the cmd-tab list, and thus isn't truly exited. Hence, if I want to remove that annoying non-running client, I basically have to kill the daemon and restart. This is particularly annoying when I'm editing configuration.

And in many cases, using just the terminal isn't enough because there are quite a few quirks when using emacs in the terminal, the most recent one I found was that <shift><tab> is interpreted as M-[.

I wish there was some way to fix this. :(

I don't have an `.app`-ified copy of Emacs around to check, but there is a way to hide apps from the Dock and the Cmd-Tab switcher; see http://hints.macworld.com/article.php?story=2001070119151826... . Specifically, you can add

    <key>LSUIElement</key>
    <true />
to your app's Info plist (at `$PATH_TO_APP/Contents/Info.plist`). As the other comments point out, this also hides the app's menubar, which may or may not be desireable.
I think the hanging thing can be solved by invoking emacsclient in the following way: `emacsclient -n`.
-n serves a different purpose (the command returns immediately). Even when using that flag, there will be an Emacs icon in the cmd-tab list and the dock after the client is closed.
It's not the client that hangs around in the cmd-tab list (and as an icon in the dock) – what's signified is the process for the Emacs daemon.

I agree that it would be nice if it could be configured/made to disappear.

I use terminal-mode emacsclient on my Mac all day everyday, and `C-h k` shows <shift+tab> is interpreted as <backtab>. That's the case for Terminal.app and iTerm2, though I only use the latter. I'm not sure why yours interprets it as M-[.

if you're going to daemonize, make sure you use lucid emacs, unless you're the kind of person who never restarts their X server.

the gtk version crashes the emacs server when X exits, see: https://bugzilla.gnome.org/show_bug.cgi?id=85715