Center for Patient Care and Outcomes Research (PCOR)

EmailEmail    |   Bookmark Page Bookmark  |   RSS Feeds RSS  |   Print Page Print  

GNU Emacs and XEmacs FAQs

How do I use the GNU Emacs or XEmacs editor? 

Where possible, we will refer to GNU Emacs and XEmacs collectively as “emacs”.  GNU Emacs and XEmacs are highly customizable open source text editors/application development systems.  Emacs is free software released under the GNU Public License (GPL).

GNU Emacs came first, but it was slow to adopt an X Windows interface.  XEmacs was the first version of emacs to take advantage of X Windows which is how it got its name.  Later, GNU Emacs was enhanced to take advantage of X Windows too.  Emacs is available for nearly all versions of Unix or Unix-like operating systems, such as Linux and Mac OS X, that support X Windows. More recently, Emacs was also ported to MS Windows.  GNU Emacs has features that make it better suited to statistics so we prefer it, but we can use XEmacs in a pinch.


To start GNU Emacs, type the following at the command prompt:

kingkong:~:$ emacs &
 

To start XEmacs, type the following at the command prompt:

kingkong:~:$ xemacs &

This will open emacs with an introduction screen that has some useful reminders of important information.
 

Command Keys

You can perform a lot of operations from the Menu and the Toolbar that are self-explanatory.  Due to the constant mouse movements you may find these inconvenient; key combinations exist for many common operations.  On Sun keyboards, the Alt key is the menu accelerator, e.g., Alt-f displays the File menu.

Modifier Keys

C-KEY means hold down the Control key while pressing another KEY. For example, C-x means hold down Control while pressing x.

Sh-KEY means hold down the Shift key while pressing another KEY.

M-KEY means hold down the Meta key while pressing another KEY. On PC and Mac keyboards, the Meta key is usually the Alt key. On Sun keyboards, Meta keys are usually to the left and right of the spacebar and have a solid diamond symbol. If you don't have a Meta key, you can press Esc,  release, and then press KEY.

Execute an emacs command:  M-x COMMAND Enter
 

Getting out of Trouble

Cancel current command:  C-g

Exit Emacs:  C-x C-c
 

File Commands

Open a file or directory:  C-x C-f

Toggle files in a directory:
C-c o
M-x dired-omit-toggle

Open a file/URL in the cursor:
C-c f
right mouse button
M-x find-file-at-point

Save a file:  C-x C-s

Refresh a file:  F2

Toggle read-only status of file:  C-x C-q (or middle mouse button click on --%%- in the file/mode status: bottom left)


Text Commands

Undo changes:
C-x u
Undo

Copy region:
C-Insert
Copy

Cut region:
Sh-Delete
C-Delete
Cut

Paste region:
Sh-Insert
Paste

Select whole buffer as region:
C-x h
Props

Cut a rectangle of text:
M-x kill-rectangle
C-x r k

Paste a Cut rectangle of text:
M-x yank-rectangle
C-x r y

Fill paragraph:  M-q

Search forward:  C-s (Return stops search)

Search backward: C-r (Return stops search)

Search forward w/ wildcards:  M-C-s (Return stops search)

Search backward w/ wildcards: M-C-r (Return stops search)

Query-replace:  M-% (y for replace, n for no replace, ! for replace all, Return to stop)

Create a portrait .rtf file:  C-F1

Create a landscape .rtf file:  C-F2

Comment a region:
C-c c
M-x comment-region

Uncomment a region:
C-u C-c c
C-u M-x comment-region
 

Buffer Commands

Switch to the *shell* buffer:  F8

Send Control character:  C-q C-KEY

Split window for two views:  C-x 2

Unsplit window:  C-x 1

Compose an email message:  C-x m

Send an email message:  C-c C-c

Close a buffer:  C-x k

List all buffers:  C-x C-b

vi emulation on:  M-Esc

vi emulation toggle off/on:  C-z (from vi command mode to emacs and back)


Cursor Movement Commands

Move to beginning of line:
C-a
Home

Move to end of line:
C-e
End

Beginning of file:
C-Home

End of file:
C-End

Page down:
PageDown

Page up:
PageUp

Forward word:
M-f

Backward word:
M-b

Help

Emacs tutorial:  F1 t

Emacs manuals:  F1 i (or using your mouse to click on the "info" icon in the toolbar)

Search for help:  F1 a TEXT

Help for a key:  F1 k KEY

Help for an Emacs variable:  F1 v VARIABLE

Help for an Emacs command:  F1 f COMMAND

Help for an Emacs mode:  F1 m

Help for all keys currently available:  F1 b

Help for a UNIX command:  M-x man (this is preferable to typing "man COMMAND" in the *shell* buffer)
 

ESS Commands

Start R: M-x R

Start Stata: M-x stata

Batch submit a .sas program: F3

Batch submit a highlighted region of a .sas buffer: C-F3

Switch to the .sas buffer: F4

Switch to the .log, refresh and search for errors: F5

Switch to the .lst and refresh: F6

Switch to the .txt and refresh: F7

Open a SAS dataset with PROC FSVIEW: F9

Open a SAS dataset with PROC INSIGHT: C-F9

Switch to the .csv and refresh: F11

View a GSASFILE graph: F12

For more information about ESS, you can read the ESS manual from within emacs by typing F1 i (or using your mouse to click on the "info" icon in the toolbar) and scroll down to "* ESS: (ess). Emacs Speaks Statistics." The ESS manual is also available on the web at http://ess.r-project.org/Manual/ess.html

Fonts and Point Size

There are two ways to do this.  The first is probably the easiest.

On the Options menu, select Font.  From there you can pick the font that you want.  On our system, Lucidatypewriter seems to work well.  Now, from the Options menu, select Font Size.  From this list, select the point size that you want.  You can change these settings until you are satisfied with your choices.  Then, from the Options menu, select Save Options to Custom File.  From now on this will be your font and point size choice (until you decide to change it again).

Like all X Windows applications, you can specify the fonts/sizes/colors/etc., used by Emacs in ~/.Xresources  You can experiment with different settings for emacs at the command line.  For example, the menubar font:
prompt% emacs --xrm=Emacs.pane.menubar.font:10x20 &

You can see a list of the available fonts with: prompt% xlsfonts

After making your changes to ~/.Xresources, load your new settings and restart emacs:
prompt% xrdb -merge ~/.Xresources; emacs &
! ~/.Xresources

!Lines starting with ! are comments
Emacs.pane.menubar.font:10x20
! for XEmacs this setting would be the following
!XEmacs.pane.menubar.font:10x20

 

 

 

webmaster@mcw.edu
© 2014 Medical College of Wisconsin
Page Updated 07/15/2014