Pick a Free OS

User login


Emacs: The programmer's editor

Emacs is one of the most preferred editors under Linux. This full-featured screen-based editor has gained enormous popularity due to its ease of use and extensibility. One can be sure that while using emacs, one won't end up in a nightmare situation, as is usually the case with an editor like 'vi'. Although used more often on a Unix-based system, emacs has been ported on a wide variety of Unices as well as DOS and Windows. On the GNU-Linux-based system, it is available in text mode and as an X application.

You can invoke emacs from the command prompt by the following command:

$ emacs

The above command name may be followed by a list of one or more filename(s) that are to be opened.

As soon as emacs starts up, it takes over your screen. Usually you see a Scratch-pad available for you. This brings us to the structure of the emacs editor, which usually comprises in-memory buffers. The Scratch-pad is a buffer where you can key in text and later convert it to a named document. Just like other editors emacs allows you to open multiple files at a time. Also it provides support for many programming languages including C, C++, Java, SGML, TeX, etc. It has modes for various languages, where it undertakes syntax checks like checking for braces and parentheses. Whenever you open a text file containing program code, emacs detects the programming language, and initiates the appropriate mode. Given below are some of the basic commands.

Opening a file

In order to open a file from within emacs, you need to use the command Ctrl-X F. Here the X & F need to be pressed in succession. This is the way most of the commands are entered. Upon issuing the above command, the cursor moves to the bottom of the screen.

The last line of the screen is called the Mini-buffer. This is the area where all commands are issued and messages are displayed. Here, enter the name of the file you want to open. If the file is non-existent, then a new file with the given name is created. Now the cursor moves over to the top-left of the emacs screen. Here you can type in your text as in a normal editor using arrow keys for movement and the usual backspace and Del keys. Later in this article, we look at some of the more advanced commands.

Saving a file