DOC PREVIEW
Princeton COS 217 - Launching Emacs

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Princeton University COS 217: Introduction to Programming Systems Emacs Tutorial This tutorial describes how to use a minimal subset of the Emacs editor. See the Emacs summary sheet distributed in precept for more information. Also see Chapter 3 of our Programming with GNU Software (Loukides & Oram) textbook, and http://www.gnu.org/software/emacs/. The tutorial assumes that you have copied the file /u/cos217/.emacs to your home directory, as described in the "A Minimal COS 217 Computing Environment" handout from our first precept. It also assumes that you have copied files named hello.c, circle.c, and testintmath.c into your working directory. (Those files contain C programs that we will describe in upcoming precepts.) Those files are available in the directory /u/cos217/emacstestfiles. You can issue this command: cp /u/cos217/emacstestfiles/* . to copy them to your working directory. Throughout the tutorial text in boldface indicates hands-on activities. Background Emacs was created in the mid 1970s by Richard Stallman. Originally it was a set of "editing macros" for an editor that now is extinct. Emacs is popular, for a few reasons. Emacs is: • Free. It's a component of the GNU tool set from the Free Software Foundation. • Highly customizable. Emacs is written in the LISP programming language, and is easy to customize via that language. • Integrated with other GNU software. In particular, Emacs is integrated with the Bash history mechanism. Essentially you can think of the Bash history list as a "file"; you can use Emacs commands to scroll through and edit that file, and thereby easily reissue previous commands or variants thereof. Emacs also is integrated with the GCC compiler driver, as this tutorial describes. Finally, and probably most importantly, Emacs is integrated with GDB debugger. A future precept will describe that integration. Emacs is a "modal" editor. That is, at any given time, Emacs is in one of several modes. In the COS 217 course you will use "C mode," "Assembler mode," and "Text mode." Emacs determines its mode based upon filename extensions. If the current file has a name whose extension is ".c", then Emacs will be in "C mode." If the current file has a name whose extension is ".s", then Emacs will be in "Assembler mode." By default, Emacs is in "Text mode." Launching Emacs To launch Emacs, issue the emacs command followed by the name of the file that you wish to create or edit. For example, issue this command at the Bash prompt: Page 1 of 6emacs testintmath.c Emacs loads the contents of the testintmath.c into a buffer in memory, and displays that buffer in the window. It places the point over the first character in the first line of the buffer. Note the Emacs terminology: A buffer is an area of memory. A window is a graphical entity that displays the contents of a specified buffer. The point is a small black box which overlays a character, thus indicating which character is the "current" character. Notation Throughout this document: • "Esc somechar" means "type the Esc key followed by the somechar key." • "Ctrl-somechar" means "type the somechar key while holding down the Ctrl key." for any character somechar. Incidentally, "Alt-somechar" (that is, type the somechar key while holding down the Alt key) has the same effect in Emacs as "ESC somechar" does. The .emacs File When you launch Emacs, it looks for a file named .emacs in your home directory. If Emacs finds that file, it assumes that the file contains configuration function calls, and executes them. Take a look at the .emacs file that you've copied to your home directory. Issue the command "cat .emacs" to do that. The file is thoroughly commented; please study it at your leisure. In particular, note this line: (setq c-default-style "ellemtel") As described below, Emacs automatically indents your C code according to whatever indentation style you specify. That line sets the indentation style to "ellemtel." The commented-out lines that immediately follow in the .emacs file show the names of some other styles. Any of those styles is fine in the context of the COS 217 course. Experiment! See which you like best. Calling Functions In Emacs, all work is accomplished by calling functions. The syntax for calling a function is: Esc x function For example, the forward-char function moves the point forward one character: Esc x forward-char Emacs moves the point forward one character within the buffer each time you call the forward-char function. Call forward-char a few times. Clearly there must be a better way to move the point! More generally, there must be a better way to call often-used functions. Page 2 of 6Key Bindings There indeed is a better way. The most often-used functions are bound to keystrokes. For example, the forward-char function is bound to the keystroke Ctrl-f. Type Ctrl-f a few times. The forward-char function also is bound to the right-arrow key. Type the right-arrow key a few times. Many keystrokes are bound by default. You also can bind your own, typically by placing a function call of this form in your .emacs file: (global-set-key keystrokes 'function) But few new Emacs users create their own keystroke bindings. Moving the Point The simplest way to move the point is via the forward-char, backward-char, next-line and previous-line functions, each of which is bound to an arrow key. Type the arrow keys to move the point right, left, down, and up several times. The beginning-of-line and end-of-line functions have intuitive meanings. They are bound to the Ctrl-a and Ctrl-e keystrokes, respectively. They may also be bound to the Home and End keys, respectively; but Home and End may or may not work with your terminal emulation software. Type Ctrl-a, Ctrl-e, Home, and End several times. Perhaps counter-intuitively, the scroll-up function moves the window downward in the buffer; equivalently, it moves the buffer upward in the window. The scroll-up function is bound to Ctrl-v, and also may be bound to the PageDn key. The scroll-down function moves the window upward in the buffer. That is, it moves the buffer downward in the window. The scroll-down function is bound to ESC v, and also may be bound to the PageUp key. Type Ctrl-v, PageDn, ESC v, and PageUp several times. The end-of-buffer function moves the point to the end of the buffer; it is bound to Esc >. The beginning-of-buffer


View Full Document

Princeton COS 217 - Launching Emacs

Documents in this Course
Summary

Summary

4 pages

Lecture

Lecture

4 pages

Generics

Generics

14 pages

Generics

Generics

16 pages

Lecture

Lecture

20 pages

Debugging

Debugging

35 pages

Types

Types

7 pages

Lecture

Lecture

21 pages

Assembler

Assembler

16 pages

Lecture

Lecture

20 pages

Lecture

Lecture

39 pages

Testing

Testing

44 pages

Pipeline

Pipeline

19 pages

Lecture

Lecture

6 pages

Signals

Signals

67 pages

Building

Building

17 pages

Lecture

Lecture

7 pages

Modules

Modules

12 pages

Generics

Generics

16 pages

Testing

Testing

22 pages

Signals

Signals

34 pages

Lecture

Lecture

19 pages

Load more
Download Launching Emacs
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Launching Emacs and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Launching Emacs 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?