This lab will introduce you to useful features of the emacs editor.
Why emacs? Word processing programs like Microsoft Word are great for editing text that is intended for human beings to read. However, if you are writing computer programs, you will need to use a different kind of editor - a plain text editor that produces simple ASCII text documents. There are other plain text editors which you main find useful. However, all the examples in this classes will use emacs, the editor the instructor prefers.
Another major reason for learning emacs: Most of the keyboard shortcuts used in emacs apply in R, Unix shells, and python. This means that the shortcuts you learn today will help you in nearly every other aspect of this course.
After you complete the following assignment, you will have a good enough working knowledge of emacs to proceed through the rest of the class. Read on....
What is emacs? Emacs is a text editor designed for writing computer programs. You can find versions for nearly every type of computer running every type of operating system, including Mac OS, Windows, and Unix.
On Apple computers, Aquamacs is probably the most popular and widely used version. On Unix, you may find Gnu Emacs or Xemacs. On Windows, you can download and run a free copy of Gnu Emacs.
Emacs, regardless of the version, has many useful features that make it ideal for programming tasks. Even better, many of the keyboard shortcuts you learn for emacs will work inside the python interpreter and the Unix terminal. (More on this later...) This lab assignment will help you get familiar with using emacs for text editing and programming.
To begin, read the questions below. Don't worry if you can't answer them right away. The purpose of reading them in advance is to help you assimilate information when you do run across the answers in the tutorial and elsewhere.
After you've read the questions, complete the exercises below.
Step ONE: Emacs in the terminal window.
Launch emacs in the terminal. First, launch a terminal window. On a Mac, do this by double-clicking the Macintosh Hard Drive icon that appears on your Desktop. This will open a new window that shows you a view of a file system. This view of the file system is sometimes called the Finder. Then, click the icon labeled Applications in the left-hand column. A list of all the applications that are installed on your computer should appear in the right side of the window. Note that the list of applications includes a folder named Utilities. Open the folder and double-click the icon labeled Terminal to launch a new terminal window. To launch emacs inside the terminal, just type emacs at the prompt - see below:
Read the first (introductory) screen that appears when you first launch emacs.
What's happening is that you are running emacs as a simple shell program, in which the emacs interface takes over the terminal window. This is not a very convenient way to run emacs, because you will not be able to use the mouse to navigate within the buffer, the emacs term for text you are currently editing. To quit, type Ctrl-x (lowercase x and control key at the same time) and then Ctrl-c (lowercase c and control keys at the same time).
You can also use Aquamacs, which appears in its own application window when you launch it. To launch Aquamacs on a Mac (assuming it's installed), go to Applications folder again and double-click the Aquamacs icon.
Herer is a sample screen from Aquamacs - see below. Note that Aquamacs does syntax highlighting. The document being edited in the screen shot is an HTML document (a Web page) and Aquamacs is smart enough to recognize HTML tag names and color those different from the rest of the content. You will see the same type of thing when you begin writing python code.
STEP TWO: Launch Aquamacs. Make sure that the "Show buffers in new frames" option under the Options menu is not checked.
| Aquamacs window |
|
STEP THREE: Emacs tutorial. Launch the tutorial by typing Ctrl-h t or by choosing the Tutorial option under the Help menu.
Work through the tutorial, answering the following questions as you go. Note that some commands in Aquamacs have been redefined; that is, their behaviors have been changed relative to other versions of emacs you might encounter. The tutorial makes note of these, displaying the modified key bindings in red font. This brings me to another key feature of emacs: customizability. You can modify your copy of emacs to change the meaning of shortcuts to suit your own taste. For instance, I always change the meaning of Control-F to "go-to-line" instead of the usual meaning.
Emacs Lab
Question 1
What is syntax highlighting?
Question 2
What is the minibuffer in emacs?
Question 3
What is an editing mode in emacs?Question 4
What does C-l do? (letter el not number one.)Question 5
What characters mark (a) the end of a sentance? (b) the end of a line?Question 6
Why don't people use Microsoft Word to write computer programs?Question 7
What keyboard shortcuts do the following?
Question 8
How do you copy and paste in emacs? Describe the sequence of commands you would use.Question 9
How do you search for a word (or sequence of letters) in emacs?
Question 10
Do research on-line. What is ASCII?