Local Emacs Tutorial

Local Emacs Tutorial
Roger Burroughes <[email protected]> Editing Text With Emacs This section will give you some practice in using Emacs. It is divided into two parts: •
The first section allows you to try out some of the Emacs commands described in the systems lecture.
•
In the second section, you will put these commands into practice by editing some text. Either by using some supplied text (a poem by Robert Burns), or by creating your own text (for example, by making notes on some aspect of the course, or on the emacs tutorial itself). Note that Emacs uses files and buffers ­ a file is your text on disk (saved copy), a buffer is your text in memory (working copy). When you save your file, your working copy is written to disk to become your saved copy. Not saving your working copy means that your file won't be updated with any changes you have made.
Emacs Tutorial Choose one of the following methods to run the Emacs tutorial: Method 1: 1. Make sure you are in your home directory (type “cd” to return to your home directory if you’re not sure — and then “pwd” to check), make a copy of the Emacs Tutorial, rename it, and then put it in your home directory as follows: cp ˜infteach/system/emacs-tutorial my­tutorial
This takes a copy of the file emacs-tutorial, renames it my­tutorial (or use another name if you prefer), and places it in your home directory (assuming you are in your home directory, or have used “cd”). 2. Open the tutorial in Emacs by typing:
emacs my­tutorial
and work through the tutorial to the end. If there are any problems with, or comments on, or questions about the tutorial, make a note of them. Method 2: 1. Start emacs from the command line (just type “emacs” at the Unix prompt and hit “Return”)
or
Select “Emacs Text Editor” from the “Applications ⇒ Programming” menu.
2. Select “Emacs Tutorial” from the “Help” menu at the top of the Emacs window. To Quit: When you’ve finished, type “Ctrl­x, Ctrl­s” to save it1, then “Ctrl­x, Ctrl­c” to quit. 1 If you selected the “Emacs Tutorial” from the “Help” menu, the file will be saved as “TUTORIAL” in your home directory. Practice in using Emacs Make a copy of ˜infteach/system/poem in your home directory (use “cp
˜infteach/system/poem poem” from the command line — this will make a copy, called "poem", in your current working directory). Once you have done this, open the file with Emacs: % emacs poem (note that you get a new Emacs window, and no return of the Unix prompt in the invoking terminal window ­you won’t get the prompt back until you quit Emacs). 1. You will see that the underlining of the title is mis­aligned. Move the cursor (using the mouse or emacs command keys) to the second line and insert the appropriate number of spaces in front of the underlining. If you put in more spaces than you meant to, you can remove the surplus with the “<­” (Backspace) key.
2. The first line of the seventh stanza (line 34 of the file) is incomplete. At the moment it reads: They’ve ta’en a weapon, and , It should read: They’ve ta’en a weapon, long and sharp,
Insert the necessary words (use “Ctrl­U 3 4 Ctrl­N”2 to go to the correct line — assuming the cursor is at the top of the file, or use the mouse and cursor keys).
3. The eighth stanza is full of spelling mistakes — go through and correct them all (you can use spell­checking for this: "Tools => Spell Checking => Spell­Check Buffer", or ESC­$ with cursor at end of word to be checked).
4. The second last stanza has some (obvious!) rubbish at the end of it, so remove everything from “All of the next...” to “end of the junk”3.
5. The second and third stanzas are in the wrong order. Select the text to be moved (the second stanza and the blank line below it) by moving the cursor to the start of the second stanza, click and hold down the left mouse button, and drag the cursor down to the end of the stanza and release the button — you should see the text highlighted as you move, and it should stay highlighted when you release the mouse button. The highlighted lines area “region”, and can be cut out of the file with “Ctrl­W”. You can then move the cursor to the first line of the fourth stanza and paste the text back in with “Ctrl­Y”. If you move the cursor after cutting, and before pasting, you can move regions of text around the file.
2 This is how you give a numeric argument, in this case “34” (for 3 4). The next command or keystroke is executed this number of times, in this case “Ctrl­N” (next line) so the cursor moves down 34 lines. 3 Note that entire lines can be deleted with “Ctrl­K” (assuming you’re at the start of the line — otherwise “Ctrl­K” just deletes from the current cursor position to the end of the line). Take a look at the “Edit” menu. The “Cut” and “Paste” commands just used are duplicated here, as well as two related commands: •
Copy lets you duplicate the selected region by making it available for pasting without having to cut it first.
•
Clear lets you remove the selected region by cutting it without making it available for pasting. Notice how the menu items are greyed­out: they are not available for you to use when there is no region highlighted. There’s also the very useful “Undo” command in the “Edit” menu that will undo your last editing command. •
Make some comments on your experiences with the Emacs tutorial, using any notes you took during the work­through above (or make some up — we only need text to type here!) Once you’ve finished, save your file and exit Emacs (see the “To Quit” section of the “Emacs Tutorial” section above).