Emacs
Prof. Brian D. Davison
Computer Science & Engineering, Lehigh University
Announcements
- We will not always meet in this room.
- On scheduled days (not every week), we will meet instead in the
Packard Lab 122 computer lab, which has 20+ Sun workstations (plus a
couple of PCs running Linux).
- We will meet there (not here) on Monday Jan 24 to introduce
you to the machines and do some lab exercises.
Questions about HW0 (due tonight)
- How do you find out about something?
Questions about HW0 (due tonight)
- How do you find out about something?
- Look in textbooks (they have an index!)
- Google (perhaps with additional terms if needed)
- UNIX man pages
- Ask another student
- Ask the professor or TA
Homework HW1 (due Friday)
- Almost as simple as HW0.
- Reminder: your CSE/ECE Sun account is entirely separate from your
university account.
- They can have different passwords
- You can have another home page at
http://www.cse.lehigh.edu/~your-id/
- You can receive email at this account at your-id@cse.lehigh.edu
- Please test that email to your CSE/ECE account is sent to wherever you
read your email (since I and the grading system may send messages to you
there).
Editing Text Files
- What are your favorite editors?
- Which ones are likely to be available under UNIX?
- What are the popular and powerful ones?
- How do you start them?
- How do you quit them?
GNU Emacs
- One of, if not the, most popular and full-featured editors
- Available for most every platform/OS
- More than just an editor; it can also
- Read email
- Provide an interface in which you can compile, run, and debug your code
- Browse the web
- Provide psychoanalysis (similar to ELIZA)
- Interpret LISP programs
Emacs History
- Emacs is the extensible, customizable, self-documenting real-time display editor
- Originally developed in the 1970s by Richard M. Stallman
- The name was chosen as an abbreviation of Editor MACroS
- Emacs development continues. Modern emacs:
- Is highly extensible through the Emacs Lisp language
- Provides many filetype-specific modes (e.g., source code, HTML, etc.)
- Supports many languages and fonts
Running Emacs
- Start emacs by typing emacs (and return) at a shell prompt
- If you are running within X-windows, a new window will open
- Otherwise, emacs will run full-screen (within the starting terminal)
- Menus are available (use F10 to operate if not running within X-Windows)
Operating Emacs
- Emacs provides many, many keyboard shortcuts (as well as longer commands)
- Every keystroke is a command to emacs; printing characters are generally bound to a command that prints itself
- Some combinations of keystrokes have special meanings
- C-x (spoken as "control x") means to press and hold the control key while you press the x key once
- M-x (spoken as "meta x") means to press and hold the meta key while you press the x key once
- C-M-x ("control meta x") is the combination of the three
- Example command sequence: C-x C-f will prompt you for the name of a file to open
The Meta Key
- Modern PC-style keyboards do not have a "Meta" key
- Instead, often the ALT key will work
- If not, the ESC key can be used, but as a separate keystroke (since it is not a key modifier like CTRL, SHIFT and ALT) which is slower
Essential Commands
- Quitting Emacs
- C-x C-c -- Exit emacs permanently
- C-z -- Suspend emacs (iconify under X)
- File Commands
- C-x C-f -- Open a file for editing
- C-x C-s -- Save current file to disk
- C-x i -- Insert contents of another file
- C-x C-w -- Write/Save-As
- C-x k -- Close current file
- C-x b -- Switch to different buffer (open file)
Essential Commands
- Handling Errors
- C-g -- Aborts the current command
- C-_ or C-x u -- Undoes most recent change
- C-l -- Redraw screen
- Searching
- C-s -- Search forward
- C-r -- Reverse search
- RET -- Abort current search at current location
- Repeated C-s or C-r will search for next location
Essential Commands
- Cutting and Pasting
- Backspace (and sometimes C-Backspace) will usually delete letter to left
- C-d (and often Delete key) will delete letter under cursor
- C-k -- Kill to end of line (i.e., cut)
- C-y -- Yank from kill buffer (i.e., paste)
- A sequence of repeated C-k will put all such lines in the same buffer
- A sequence of repeated C-y will past entire buffer each time
- Search and Replace
- M-% -- Replace text1 with text2, asking permission each time (RET to stop)
- M-x replace-string -- Replace all subsequent occurences
Essential Commands
- Moving Around
- C-f (Forward) and C-b (Backward) one character
- M-f (Forward) and M-f (Backward) one word
- C-n (Next line) and C-p (Previous line)
- C-a (Beginning of line) and C-e (End of line)
- C-v (Next screen) and M-v (Previous screen)
- Arrow keys and PageUp/PageDown/Home/End sometimes work
- Miscellaneous
- TAB -- Indent current line (depending on mode)
- C-x 1 -- delete all other windows within emacs
Files Created By Emacs
- Emacs will let you open new files
- If you close a file that was modified (without saving), it leaves a temporary file called #filename#
- If you edit and save an existing file, emacs renames the old file as filename~
Emacs Resources
- Emacs is a large, complex editor
- Useful references
- Friday's quiz will be on emacs. Sample prior quizzes can be found
here and
here. Note that
I will only ask you about material from class or assigned readings.