A Beginner’s guide to Emacs
From LXF Wiki
Users moving to Linux from another OS quite understandably try to make themselves at home by hunting for tools with the same look and feel of applications they're used to. For many tasks, though, they would be better off leaving their comfort zone and trying out less familiar applications. Having been inspired by Unix and building directly on the GNU project, Linux comes with its own historical tools, at least for basic tasks. These tools are often superior to and more stable than recent Windows clones.
Unfortunately, many of the traditional GNU tools have the undeserved reputation of being difficult and hostile. A fairer statement is that they need to be learned and understood. For little effort, new and established users of Linux can get more out of their system with old apps.
In the specific area of text editing, many Linux users work with WordPad or Notepad clones, often bemoaning their lack of features. In fact, Linux has two excellent text editors, Emacs and Vi, each with its loyal followers always ready to fight each other in a worthless attempt to establish which one is better. Both are fine programs, and we hope we won't offend the Vi camp by dedicating this tutorial to some of the finer points of Emacs.
The always-on app
In my job, I need to code in various programming languages and write reports of my activity. Just like everyone else, I also write emails and browse the net. Finally, when I have some spare minutes, I like to play old arcade games like Tetris. While coding, independent of the language, I use my favourite IDE, which is Emacs. If I need to go to the command line, I get it directly inside Emacs. To write reports (be they in HTML or LaTeX) I use my favourite word processor, which is Emacs.
When I have to pay a quick visit to very simple websites or write an email to my collaborators... well, I have often at least two Emacs windows open, so why should I start another application? And if I want to play Tetris, guess what I use? That's right, it's good old Emacs. There is almost nothing that can't be done with this app.
One of the reasons why people refuse to use Emacs is that reputation of being difficult. This is simply underserved: it takes no more than 30 seconds to learn how to perform the basic Emacs editing operations (though you'll have to forget about shortcuts you're probably used to, such as Ctrl+Z for undo).
The other reason is that Emacs is often alleged of being bloated and slow. What some people refer to as bloated could be considered by others as feature-rich (think for instance of the quarrel over configurability in GNOME and KDE). Personally I prefer the latter interpretation for Emacs: think of it as curvy, not fat. As for the speed factor , I wouldn't consider slow an application that takes less than two seconds to open on a 1.7 GHz Pentium 4 and whose start-up time can be further reduced if one wishes.
In addition to all that, Emacs features a fast console-only mode, which makes it an ideal editing tool when X is not working or when you're using a remote machine over a slow line. Is there any reason why you shouldn't consider Emacs? The only scenario that springs to mind is when you need to save to proprietary formats or formats that can't be easily classified as raw text like .doc. But I'm pretty sure that Emacs will get there in the near future. In development Emacs is one of the main text editors on almost all Unix variants. Linux vendors offer variously customised versions (Fig 1 show the Emacs start-up window with Mandrake customisation) and it runs on countless platforms, including Windows, and can be modified for doing a single, arbitrary task.
Though the program is in continuous evolution (among the features of the latest 21.3 version are support for faces and embeddable images) it's very stable. A crash of an Emacs window is as rare as the explosion of a supernova. The success of the program has prompted developers of other popular editing programs to provide Emacs compatibility modes and Emacs-like shortcuts. Over the years, several clones of Emacs have appeared. One of the most popular is XEmacs, which is still very actively developed. In fact, such is the popularity of XEmacs' popularity that the original Emacs project is often referred to now as GNU Emacs.
Although separately developed and in part incompatible, GNU Emacs and XEmacs share many features, as well as design and the programming language. XEmacs is more innovative in many respects: usually, in terms of features it's always one release ahead of Emacs. But we're really talking about no more than tertiary features for a text editor.
Anatomy of the window
The structure of a typical GNU Emacs window is annotated in Fig 2. From top to bottom we find: the menu bar, where all the most used commands are within easy reach; the buffer, where the text of the file is displayed; the status bar, which displays various information about the file being edited (name, percentage, type and line number among others); and the mini buffer, which can be considered the Emacs command prompt.
In addition to these, XEmacs has an icon bar (see Fig 3). For this reason, it's sometimes preferred to GNU Emacs by new users. In fact, a patch is available with some distributions including Debian to add an icon bar to GNU Emacs, but this is not the default.
We will describe components in more detail (in particular the mini buffer, which implements the least obvious concepts) as we go along. For the moment, it will be enough to keep the terminology in mind.
It's reasonable to assume that you have either GNU Emacs or XEmacs installed. If in doubt, refer to the documentation of your distribution Emacs should be at least an optional package. If your distro does not package Emacs, I'd suggest you to reconsider your choice.
The distribution- and desktop-independent way to launch an Emacs window is to open a terminal emulator and write emacs & at the prompt. There may be shortcuts, such as selecting `Menu > Applications > Editors > Emacs' under Mandrake or pressing Alt+F2 then typing `emacs' under KDE (you can replace emacs with xemacs if you prefer). This will open an Emacs window called `scratch buffer', which should look like one of the three illustrations in this article.
You can now start typing your text into the buffer. When you're done, from the File menu you can select the option `Save buffer as'. This action will take you to the mini buffer. What appears there is the path of the directory from which you started Emacs. Just append the name you want to give to the file and press Enter: you've just created your first file with Emacs! Quit the app by simply killing the window or selecting `File > Exit Emacs'.
So ends your first lesson in Emacs and if you think it was difficult, I'd love to hear from you. LXF