2007-05-29

Emacsclient

Emacs can be used as a server and each file can than be opened via emacsclient. This is handy to keep session lean and to have all working files in one pot. This works however only if emacs is already running. Up to now I had some shell scripts that eased the opening of emacs if it was not running, but I have just find out that it is fairly easy to do this in the following way - I have emacs 22 now:

Set emacs-snapshot as emacs:
sudo update-alternatives --config emacs

Set emacsclient.emacs-snapshot as emacsclient:
sudo update-alternatives --config emacsclient

Set environmental variables (say in ~/.bashrc):
export EDITOR=emacsclient

export VISUAL=$EDITOR

export ALTERNATE_EDITOR=emacs

Now you can call emacsclient on any file you would like to open it. If emacs is not yet running ALTERNATE_EDITOR will startup, which we defined to be emacs. Simple!

Typing emacsclient someFile is to long so I have the following in my ~/.bashrc. Using & also unlocks the terminal, which is handy.

edit ()
{
$EDITOR $@ &
}

No comments: