I love using Emacs for Clojure development, although as I add to my configuration file I noticed start-up times have grown by a few milliseconds, which can feel like a life time when you have just thought of a new idea.
To speed things up I am now using
emacsclient, which loads your file into a currently running Emacs application (or starts Emacs if its not running).
The following is based on Emacs 24 installed from Emacs for MacOSX on Mac OSX 10.7.5 but should work for Ubuntu and other Linux/Unix systems.
The easiest way is to run Emacs and then start up the server once its running using
You can also configure emacs to start its server automatically when it run. Add the following to your
~/.emacs.d/init.el file to check if the server is running and start it if it is not:
It is also possible to call emacs on the command line with the
--daemon option to start the server as it runs. You could put this in a script or shell alias.
One thing that gets in the way of my Emacs 24 experience is Emacs 22, which seems to be installed by default in Mac OSX. A quick Google gives little in the way of removing this older version except to remove the executables from the path. I took a reversable option of renaming the following files to show the version and get them out of my way.
You could just put Emacs 24 at the front of your path, before
/usr/bin. As I have no intention to ever use Emacs 22 its simpler just to move it out of the way.
Assuming you have moved emacs 22 out of the way, the only way to call Emacs from the command line now is to use the full path of the Emacs binary. So, in my home directory I have a folder called
bin that contains all my scripts that save me effort and save my path from becoming messy. I added this folder to my executable path by adding a
~/.profile with the following simple path setting
~/bin folder I created the following script files as a convenience
Now to the fun stuff. When ever you want to edit a file you can simply use the command
emacsclient and up pops an Emacs window with your file, or using
emacsclient-terminal then Emacs displays itself in the current terminal window.
emacsclient filename emacsclient-terminal filename
If the Emacs server is already running, then you will see your editor window straight away.
If you have not run Emacs in this current session, then EmacsClient will run the Emacs server for you and automatically connect afterwards. This wont be instantaneous, but it will only need to do it once.
To exit the editing, save your work with
C-x C-s and close the editor window with
When you use EmacsClient then the terminal waits for your editing session to end. This is really convienient when calling Emacsclient from Git, which expects a reply when you have finished editing.
If you want to free up the terminal you are using to call EmacsClient, then use the
--no-wait option as so:
emacsclient -n filename
On my to-do list is using magit from within Emacs. Until then I am still using the command line to git version my code and push it up to a shared repository.
The only time I need to do anything special for Git and Emacs is when I have a merge conflict, or I forget to add a commit message using the
In either case, I wanted to be able to open the file in Emacs straight away. This can be done by setting the global configuration option for the git editor.
On the command line, run the following git command to setup git to call emacsclient when it needs to edit a file:
If for some reason you need to kill the Emacs server, you can do so within Emacs or use EmacsClient to close it.
A quick and dirty option that wont save your file, is just to kill emacs
emacsclient -e '(kill-emacs)'
A more elegant option is to save your work and then kill emacs
emacsclient -e '(client-save-kill-emacs)'
EmacsClient gives a really quick way to use all the power of Emacs and have really fast access to files you are working with on the command line. There are lots of options that come with EmacsClient I have not delved into. I hope to experiment with naming the Emacs server and evaluating between different Emacs frames using the server name. That sound fun. There is also
--eval option, to send Emacs Lisp code to the server to be evaluated. Nice.
What will you doing with EmacsClient?
This work is licensed under a Creative Commons Attribution 4.0 ShareAlike License, including custom images & stylesheets. Permissions beyond the scope of this license may be available at @jr0cket