Emacs is a word processor for the UNIX operating system. It is what most of the Brown CS department uses as a text editor. Emacs can perform hundreds of commands. You do not need to know most of these commands, but knowing a few common ones can make your task of coding much easier. Emacs commands either use the Control key (C-) or the Meta key (M-, it is the key next to the spacebar labeled by a diamond).
[Useful Emacs Commands & Features] [Keyboard Shortcuts] [Color Key]
Useful Emacs Commands & Features
Opening & Creating Files
To open a file you can either select Open... from the File menu or by typing C-x C-f. (Notice that this shortcut command is listed alongside the command in the menu.) These commands result in different ways to access your files.
-
Open... pops a file dialog box. This dialog box allows you to navigate through the directory structure through its two columns: the lefthand column allows you to select the directory; the righthand column allows you to select the file. You need to use the middle mouse button to actually select the directory or file. If you want to move up a directory level, click the middle mouse button on the .. option in the directory column.
-
The C-x C-f command brings up a prompt in the bottom section of the window. To access a file, type the filename in and hit return (you can use tab complete to expand the filename).
-
If you want to create a new file, use one of the above commands to get a file prompt and type in the name for the new file that you would like to create.
Working with Buffers
In Emacs, files are also referred to as buffers. If you have opened more than one file, you can switch between them by selecting the desired file/buffer from the Buffers menu. The keyboard shortcut for this is C-x b or C-x C-b. To "kill" or delete the current buffer you can use C-x k or select Delete Buffer from the file menu.
Creating New Windows & Frames
To open a new Emacs window (similar to opening a new window with a web browser) select New Frame from the File menu. To open a new window containing a specific file choose Open in New Frame... from the file menu.
Emacs also has the ability to display multiple files within the same frame. This can be done through windows. The Open in Other Window... command under the File menu opens a specific file in another window. To simply split the frame, use the Split Window command.
Sometimes you may find that Emacs splits the window when you do not want it to. To unsplit the window use the Un-Split command from the File menu.
Auto-Completion
One of the best features of Emacs is its ability to autocomplete words and expressions that you have already typed at least once. To complete a word, type the first few letters and then use M-/ (hold down the Meta key and then hit the / key). Emacs will make its best guess as to what the word is (it is not always correct!).
Exiting a Command Prompt
If you find yourself within an unwanted command prompt at the bottom of the frame, you can hit C-g to get out of the prompt.
Changing Font Colors
It is possible to change the color of the text in Emacs. To do this, select the Browse Faces... command from the Options menu. Again, to choose a particular option, use the middle mouse key.
The Status Bar
If you look at the bottom of the Emacs window, you will notice a status bar. This bar displays some useful information in the following format:
-----XEmacs: Filename (File Type Sample Font)----Line Number--% Completion in File---------
Top of PageEmacs Keyboard Shortcuts
| C-h | Online help session |
| C-x C-f | Open a file (new or existing) |
| C-x C-s | Save the file |
| C-x C-c | Exit emacs |
| C-g | Cancel current command operation |
| C-s | Search for characters (forward of cursor) |
| C-r | Search for characters (backwards of cursor) |
| <meta> | Exit a successful search |
| C-x i | Insert file at cursor position |
| C-x u | Undo last edit |
| C-x 2 | Divide the current window horizontally in two |
| C-x 3 | Divide the current window vertically |
| C-x 1 | Undo divided window |
| C-p | Go up a line |
| C-n | Go down a line |
| C-f | Go forward one character |
| C-b | Go backwards one character |
| C-v | Go forward one screen |
| M-v | Go backwards one screen |
| M-f | Go forward a word |
| M-b | Go backwards a word |
| C-a | Go to the beginning of a line |
| C-e | Go to the end of a line |
| M-a | Go backwards one sentence |
| M-e | Go forward one sentence |
| M-[ | Go backwards one paragraph |
| M-] | Go forward one paragraph |
| C-x [ | Go backwards one page |
| C-x ] | Go forward one page |
Emacs Color Code
So what do all those colors mean in emacs? Here's a complete listing for the default color scheme.
General and Flow of Control Keywords- class
- extends
- implements
- interface
- import
- new
- null
- package
- break
- case
- catch
- continue
- default
- do
- else
- for
- if
- return
- switch
- synchronized
- try
- throw
- throws
- while
Reference Names
- super
- this
Modifiers
- abstract
- final
- static
- private
- protected
- public
Base Types, Primitive Classes, and void
- byte
- boolean
- char
- double
- float
- int
- long
- short
- String
- void
Variable Names
Anything following a variable declaration (int, String, NGP.Container, etc.)
Functions and Class Names
Anything with () after it (or immediately following the word 'class')
Package Names
Anything immediately following the word 'package' or the package portion of a fully qualified class name (e.g. the NGP.Graphics of NGP.Graphics.FilledEllipse)
Semicolons, Braces, and other punctuation
- ;
- ()
- {}
Comments
- // these
- /* and these */
Strings
Anything between "..." or ' '.
