Skip to content

Introduction to (GNU) Emacs, part 1

Tuesday, February 17, 2009
tags: ,

So… I decided to finally start the blog I had registered about a year ago. I decided to start this blog by writing a series (I hope that I won’t get bored) of articles introducing GNU Emacs. Strange way to start a blog, I admit, but I have my reasons.

First of all I want to improve my Emacs skills, and I have found that a good way to improve your knowledge of something is to write about it. I have been using Emacs since 2002, but I still consider myself relatively a newbie. So do not be afraid to tell me what I am doing wrong.

The second reason, perhaps more important than the first, is that my girlfriend is using Emacs as well, and a few days ago she told me that I should explain the things I am doing while working. So this series of posts was born.

This has been a longer introduction than what I intended, so let us proceed to the actual topic of this post, which is installing Emacs, and basic commands for asking Emacs to help you.

Installing Emacs

There are many options for installing Emacs on your machine. These differ depending on the operating system. Take a look here for some of them. If you are running Ubuntu then you can also do the following:

$ sudo apt-get install emacs

In general most GNU/Linux distributions have their own way of installing packages. If you use something like this you can skip the rest of this section which describes how you can compile Emacs from source. You might ask why you would want to compile from source, and I will answer that the upcoming version 23 of Emacs has many lovely new features. Two of the most obvious are support for anti-aliased fonts in X11 and improved Unicode support.

I am running the CVS version of Emacs in an Ubuntu box, so this is the compilation process I will describe. Compiling from sources is not at all difficult if the box is sanely configured. To download the source use the command:

$ cvs -z3 co emacs

This will create a directory emacs/ inside your current directory where the source code of Emacs will reside. Change into the directory and type:

$ ./configure
$ make
# make install

Note that the for the last command to succeed you must be super user (and thus the different shell prompt ‘#’ vs ‘$’ for the normal user). The way to achieve this is different for different distributions. For instance in Ubuntu you would type

$ sudo make install

while in Debian you would type:

$ su root -
# make install
# logout

If anything goes wrong in the first step, probably there are some libraries missing. Reading the output of configure is not the most pleasant activity, but with enough persistence you will figure out what is wrong. Either install the missing library, or if it is optional disable it when you run configure again. For example to compile Emacs without support for JPG images you would type:

$ ./configure --without-jpeg

This and all the other valid options for configure can be shown by typing:

$ ./configure --help

Normally after the configuration step you should not have any problems compiling the code. Congratulations you have a brand new Emacs installed in your machine.

Basic commands for getting help

In what follows I will be using the standard notation for describing Emacs keystrokes, so you will see a lot of “C-x C-s” and “C-c <RET>” and “M-x” and the like. The short explanation is that an uppercase C followed by a lowercase letter (e.g. “x”) means press the key control in your keyboard and while you keep it pressed press the lowercase letter. So for instance the sequence “C-x C-s” means press control and while keeping it pressed press “x”, release both of them and then press control and while keeping it pressed press “s”. I hope this makes sense šŸ™‚ If it does not take a look here. Each of these keystrokes is called a character. The reason is explained more eloquently than I could hope to do in the previous link.

As I mentioned above “C-” is the symbol for control. “M-” is the meta key, but since most keyboards made after 1990 do not have a meta key, this is mapped to the alt key. Thus “M-x” means press alt and without releasing it press x and then release both. Finally <RET>, <TAB>, <ESC>, <SPC> and <DEL> are used to mean press the return (or enter), the tab, the escape, the space bar and the backspace.

You interact with Emacs much like you interact with most of the other programs: by issuing commands. Most of these commands are bound in a sequence of characters. You can also run each command by typing “M-x <command name>”

First of all I will talk for a family of commands even more basic than moving around. Getting help! Emacs is self-documenting and this must be a good thing, as long as you know how to access the documentation. The basic key prefix for accessing help is “C-h”. If you forget every other you can find everything if you remember one: “C-h C-h” (or “C-h ?”) which runs the command (help-for-help).

This is a starting point that explains the many options that you have after you type the character “C-h”. The most useful are:

  • “C-h k” (describe-key). If you type “C-h k” and a second sequence then, Emacs will show information about the second sequence. For instance pressing “C-h k C-h k” this is displayed in my Emacs:

C-h k runs the command describe-key, which is an interactive compiled
Lisp function in `help.el’.

It is bound to C-h k, <f1> k, <help> k, <menu-bar> <help-menu>
<describe> <describe-key-1>.

(describe-key &optional key untranslated up-event)

Display documentation of the function invoked by key.
key can be any kind of a key sequence; it can include keyboard events,
mouse events, and/or menu events.Ā  When calling from a program,
pass key as a string or a vector.

If non-nil, untranslated is a vector of the corresponding untranslated events.
It can also be a number, in which case the untranslated events from
the last key sequence entered are used.
up-event is the up-event that was discarded by reading key, or nil.

If key is a menu item or a tool-bar button that is disabled, this command
temporarily enables it to allow getting help on disabled items and buttons.

  • “C-h f” (describe-function). Does the same thing but for commands. You should give as input the name of a command.
  • “C-h b” (describe-bindings). Shows a list of character sequences
  • “C-h a” (apropos-command). Takes part of a command name, or a regular expression (more for them in a following post) and displays a list with command names that contain the part or match the regular expression, along with a short description of the command.

Finally Emacs comes with a tutorial which you can run by typing “C-h t” (help-with-tutorial), and which I strongly recommend.

Stay tuned for the next post that will include at least the commands for moving around.

One Comment leave one →
  1. Sunday, May 15, 2011 15:18

    Still waiting for part 2 šŸ˜›

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: