In this section we will discuss one of the most important tools you'll use: the text editor. By the end of this session you will be able to:
An editor is a program that helps you create and modify data. In this section, we are interested in text data; that is, characters that make up words, sentences, paragraphs, etc. In the future, we'll see that programs in languages like Java, Eiffel, C, and Modula-2 are also text. Whatever your purpose - creating a program, composing a term paper, or writing home for love, support, and money - you need a text editor.
Text editors come in many different varieties.
program is a powerful editor (and so much more) developed
for use with Unix.
One of the most useful features are modes which allow you to customize the editor for different tasks. The default is text mode which is used for normal text editing. However, we will also be using a Java mode that, in addition to editing the code, highlights reserved word in different colors and does autoindenting so your programs will conform to style standards.
Perhaps the most confusing thing about using
is that it often requires what at first
seem to be complex and arcane keystrokes to perform even simple tasks.
For example, to exit an editing session takes two double-keystrokes:
Ctrl-X then Ctrl-C. To make things
even more confusing, this is written as
C-x C-c in emacs terminology.
emacs does have some simple pull-down
menus, that act similarly to other graphical based
editors you are used to such as Word.
For example, you add text by just left-clicking where you want the
text entered and then entering the text, and you remove text by highlighting
it with the mouse and selecting the cut command
in the Files pull-down menu.
This allows you to use the editor immediately.
However, you should learn the major key commands as you go since they
are often faster and easier than pointing and clicking.
A good way to do this is to work though chapter 23 in Student Guide
to UNIX whenever you have some spare time.
The discussion below assumes you have logged onto a workstation and have the standard windows and icons in place.
The easiest way to start
is to go to the directory you want to edit in and type the command
Remember to press the
key after the command name.
This will cause the computer to run the
Another way is to bring up the Workspace menu by right clicking on the
desktop area, moving the cursor over the Programs
to bring up the Programs menu then over the |
The major difference is that if you use the Workspace menu, you will have to navigate through the directory stucture to the directory you want to edit it, whereas with the first method you are already there.
Soon you will see a window such as the following appear.
Notice the word
*scratch* at the bottom of the window. This
indicates that this is a scratch area which has no name yet.
If you were editing a file, the filename would appear in this spot.
emacswindow has 4 major parts:
The black rectangle in the upper left corner of the buffer is the cursor and indicates where you are working in the buffer.
NOTE: this is different from the mouse cursor.
Move the mouse and you'll see the mouse cursor arrow move but the
emacs black rectangle cursor will stay put.
ALSO NOTE: if the mouse cursor is inside the window
the rectangle will be solid and operations will be performed there.
If it is outside the window the rectangle will be hollow and, as you
emacs will be suspended.
For the rest of this section, the mouse cursor will be referred
to as the mouse-cursor and the
emacs black rectangle
cursor simply as the cursor.
To reposition the cursor move the mouse-cursor to where you want it and left-click.
To exit using the Files menu:
emacswill terminate and the window will disappear. If you have made changes in the scratch buffer, it will throw these changes out without asking for confirmation.
To exit using keystrokes, simply type what you see next
to the exit
emacs command, i.e., C-x C-c
(remember, C-x is
emacswill throw away stuff in the scratch buffer upon exiting emacs without asking for confirmation, it is a good idea to not be in the scratch buffer when you do something that you want to save. Creating a new file and opening an old file work in the same way. Make sure you are in the right directory. Choose Open File from the Files menu. The bottom line will show something like
Find file: ~/cs1/lab1/Now simply type the name of the file you want to open. If the file exists, this file will be opened. If not, you have created a new file with the name you typed in. If you decide that you don't want a new file after all, type C-g.
emacs, create a new file named
merchant, position the mouse anywhere inside the window and start entering the following quote from Shakespeare's The Merchant of Venice by simply typing.
The quality of mercy droppeth as the gentle rain from heaven.NOTE: the text will be entered where the cursor is in the buffer area, not at the mouse-cursor.
If you make a mistake, just use the backspace or delete key to back over it. .
Rats, we left off a part! Right after 'mercy' should be "is not strain'd, It".
To enter the omitted text, just position the mouse-cursor after the word 'mercy' and right click. This repositions the cursor and you can enter the omitted part.
To save the file, open the Files menu and select the item Save Buffer. If you want to save the file under a different name, choose Save Buffer As ... instead and type the desired file name.
Emacscan be tricky and occassionally extra windows will appear or a buffer area will split in two. This is because you have somehow done something to create a new buffer.
Emacswas designed before windowing systems and has a built in system of its own. It was designed to let you work with more than one buffer at a time. At this point, however, you probably don't want this.
Suppose you are editing your survey and you choose List All Buffers from the Buffer menu. You will see the following.
There are four buffers and two windows. (Since the buffer area is split into two windows only two buffers are displayed.) The buffer menu shows all four names.
To remove an unwanted buffer, position the cursor in the unwanted buffer (by moving the mouse-cursor into it and clicking) then use the mouse-cursor to select the Kill Current Buffer item in the Files menu. If you want to go back to viewing one buffer, select the buffer you want to keep in your window and choose One Window in the Files menu.
emacssupports the standard cut, copy and paste operations. They can be found in the Edit menu.
"Search for string:"-search:to appear in the echo area. Enter the text you are looking for by simply typing it. There is no need to move the mouse-cursor, as you do this. What you type will appear in the echo area.
To repeat the search choose Repeat Search in the Search menu. If you select the Search menu item again, you will have to re-enter the search string.
There are several ways to replace text.
Query replace:will appear in the echo area
Query replace text with :will appear in the echo area
yto replace the first match. or
!to replace all remaining matches.