As in all labs, don't hesitate to ask for help as you work through the lab. If you aren't getting anywhere after staring at the screen for a minute or two, call someone over --- your neighbor, a lab assistant, or a professor --- to help you out.
emacs &The
& makes the program run in the background so
that you can continue to type other commands to the Unix shell should
you want to.
Be careful not to type another key until you've finished reading the help that comes up on the screen. Note that the `M-' key is the key between with the flag between Ctrl and Alt on the Linux machines.
C-u.
~/.emacs contains commands which get
executed by Emacs when it initially starts up. You may wish to edit
this file to customize the behavior of Emacs to your liking. (If the
file doesn't exist yet, you'll need to create it.)
As an example, you'll change Emacs so that the keystroke
M-g allows you to go to any line in a file by entering
its line number. Create and edit the file ~/.emacs,
placing the following line in the file. The line can be placed at the
start or end of the file (or almost anywhere in between).
(global-set-key "\M-g" 'goto-line)Schemers should recognize this command format as a Lisp dialect; using Emacs-Lisp you can define new behaviors and functions of your own.
M-g to see what emacs did before the change.
(I've found the built-in function useless. Hit C-g to
abort.) Launch a new emacs, type C-h t and try out
M-g again. See what it does when given a prefix
argument.
C++ files. The commands appear
in this link. While in that link, you should
highlight the region in netscape using your left-mouse button, and
then paste it in your .emacs buffer using the middle
mouse button.
I should explain what you've just put in your .emacs file. The command (load "~mc38/.emacs-mc38") tells emacs to load the file ~mc38/.emacs-mc38, which we'll maintain with commands to indent your C++ programs to more closely match the style guidelines in your text. (Be aware that this is a security risk, since you are entrusting us with the ability to put invasive commands there... but we won't.)
The command (add-hook ... changes the behavior of
emacs when editing C++ programs.
You may not like the features provided by (turn-on-auto-fill)
and (c-toggle-auto-state 1). The latter makes the keys
; and { and } and : all
electric keys, putting in newlines and indenting when you type
them. After trying these features out in a future lab, feel free to remove
them. I've found I like to edit code I've written with
c-toggle-auto-state turned off, while entering code from
scratch I like it turned on. You can turn it on and off with C-c
C-a. Or, you can quote the character to be sure it's inserted
non-electrically with, say, C-q {.
The last command instructs Emacs to color C++ keywords,
strings, and comments. In combination with auto-indentation, you'll
find you can locate most syntax errors quickly.
.emacs file and that M-g performs as indicated above.
.emacs file.
text.txt somewhere in your
home directory. Use the left-mouse button to select all the text
in the link that follows. Using the middle-mouse button, you can drop
this into your emacs buffer. Edit the text as the text itself
instructs.
This link is the text you need to edit.
~mc38/labs/emacs/names.txt in emacs. You
will see an unsorted list of names with each line in the form
last name, first names. The list is a list of registered
students from a similar C++ course at Berkeley a few
years ago.
Try editing the file. You'll notice that Emacs won't let you, since
you aren't the owner of the file. Use C-x C-w to write the
file somewhere in your home directory (~/mc38/names.txt is a
good choice.) C-x C-w is just like C-x C-s but it
asks for a name for where to save the file.
You'll find you still can't edit the file though. Notice the
%% on the far left side of your mode line. If you hit
C-x C-q (or, equivalently, M-x toggle-read-only),
you'll be able to edit the file. Note also that the %% goes
away.
C-h ? and emacs will guide you through them.
Note that {\tt info} has documentation on quite a few programs; not
just emacs. The first thing you'll want to do is to select
m~Emacs for menu item Emacs. Help clues on Emacs (including
how to navigate info) are in Paul Hilfinger's notes on GNU
Emacs.
Save the result using C-x C-s
Kusnadi,
Ali to a file named names1.txt somewhere in your home
directory and all the
remaining names to names2.txt. Save both files but do not
alter names.txt.
names1.txt and names2.txt, find a
sorting command to sort by first names. You will probably need to use
info and apropos again. Depening on the approach you try, you may
need to pass an argument to an emacs command for this part. Recall
that this is done in either of the following two ways:
M-arg M-x command C-u arg M-x commandA second possible approach will require you to set the mark and the point. If you have troubles locating help in info on this, ask us for help! Save the results.
names1.txt in one buffer and names2.txt in the
other.
Congratulations! You are done with the lab. Make sure you get your check-off points before you leave.
I followed by any two letters and then an A.
Catherine Huang Brent Allen Vincent etc.There are two ways you might think of