Emacs

Emacs

From Emacs website, were (pretty nice website they have now :)) it reads:

An extensible, customizable, free/libre text editor — and more.

Emacs can be customisable in every since way, any part, any command, any part of ui, and logic can be custom to what you need. Specially if you a have a bit of knowledge on Lisp (not mandatory).

There are several flavours of Emacs, like: Prelude, Aquamacs, XEmacs, etc. The big difference between all of these flavours is their native customization, they have already pre made packages and configurations.

Where I’m going to try and describe some basic configurations that you can apply to the vannila emacs.

All of these explanations assume ur using OSX.

Instalation

Installing emacs is really easy:

brew install emacs --with-cocoa

If you don’t have the brew command (you should), go to Homebrew and follow the steps to install.

After that you can run:

emacs

and you will see something like this:

Emacs load file

Don’t be to worried about how it looks, because we can customize it.

Baby Steps

While focusing on the Emacs window you get greeted by the ugly Welcome to GNU Emacs.

Emacs allows you to work without ever removing your hands from the keyboard. So it has a lot of keyboards shortcut’s, most of them starting with the key CTRL shown has C.

Let’s try and quit emacs using the shortcut C-x-c (Ctrl + x while still pressing on CTRL, press c) and emacs will go away.

Lets try adding some basic configurations for emacs.

By default, and according to what the gurus say, you should have or clear a .emacs.d directory in your home directory. Inside this directory we will try to put all stuff related to emacs.

For now the main file we are interested is the file init.el that we are going to create inside .emacs.d so the end path will be ~/.emacs.d/init.el. Inside this empty file we will put all our configs for emacs.

Initial Configuration

How are we going to create this file… easy, fire emacs, when its open press C-x-f and you will see this on the bottom of emacs:

Emacs Footer

Emacs is asking you to put the path to the file you want to open, if that file does not exist, it will create one.

So in front of Find file: ~/ type .emacs.d/init.el

Emacs will show a white screen with the cursor blink ready for us to type. The first thing we are going to add to this configuration is this line:

;;enable emacs to store its state between sessions
(desktop-save-mode 1)

Don’t worry to much about the styling or the parenthesis (Crazy Lisp stuff :)) This simple lisp command is going to tell emacs to store all the current state (buffers, windows, etc) between sessions, even if you close and open emacs. Really useful :D

Comments in Lisp start with two semicolons ;;

To save the current file, lets press C-x-s

Ok, cool. Now to apply (make emacs read the config) these changes you can do it in 2 ways, either close and open emacs (C-x-c) or by asking emacs to reload the init.el file.

One of the important shortcuts we need to learn is the Alt aka Meta key. By pressing Alt-x and you can look at the minibar (bottom of emacs) and see M-x, again emacs is waiting for us to do something. This Alt-x that we just did allow us to call commands/functions that exist in emacs.

Emacs M-x

So now just type load-file and press Enter.

Emacs load file

After this we just need to point to the path of our init.el, ~/.emacs.d/init.el

Adding some colours

Now that we done with the reloading. Lets add some config to load a theme. Emacs has several default themes:

  • adwaita
  • deeper-blue
  • leuven
  • tango-dark
  • tango
  • etc…

I’m going to choose tango-dark, you can choose any of the others. To add this theme, lets write in our init.el:

;;theme
(load-theme 'tango-dark t)

If you save C-x-s and reload init.el the theme gets applied.

This way we have nice theme :)