Go to the first, previous, next, last section, table of contents.
The usual way to invoke Emacs is to type emacs RET at the shell (for XEmacs, type xemacs RET). Emacs clears the screen and then displays an initial advisory message and copyright notice. You can begin typing Emacs commands immediately afterward.
Some operating systems insist on discarding all type-ahead when Emacs starts up; they give Emacs no way to prevent this. Therefore, it is wise to wait until Emacs clears the screen before typing the first editing command.
Before Emacs reads the first command, you have not had a chance to
give a command to specify a file to edit. Since Emacs must always have a
current buffer for editing, it presents a buffer, by default, a buffer named
`*scratch*'. The buffer is in Lisp Interaction
mode; you can use it to type Lisp expressions and evaluate them, or you
can ignore that capability and simply doodle. You can specify a
different major mode for this buffer by setting the variable
initial-major-mode in your init file. See section The Init File, .emacs.
It is possible to give Emacs arguments in the shell command line to specify files to visit, Lisp files to load, and functions to call.
There are two commands for exiting Emacs because there are two kinds of exiting: suspending Emacs and killing Emacs. Suspending means stopping Emacs temporarily and returning control to its superior (usually the shell), allowing you to resume editing later in the same Emacs job, with the same files, same kill ring, same undo history, and so on. This is the usual way to exit. Killing Emacs means destroying the Emacs job. You can run Emacs again later, but you will get a fresh Emacs; there is no way to resume the same editing session after it has been killed.
suspend-emacs). If used under the X window system,
shrink the X window containing the Emacs frame to an icon (see below).
save-buffers-kill-emacs).
If you use XEmacs under the X window system, C-z shrinks the X window containing the Emacs frame to an icon. The Emacs process is stopped temporarily, and control is returned to the window manager. If more than one frame is associated with the Emacs process, only the frame from which you used C-z is retained. The X windows containing the other Emacs frames are closed.
To activate the "suspended" Emacs, use the appropriate window manager mouse gestures. Usually left-clicking on the icon reactivates and reopens the X window containing the Emacs frame, but the window manager you use determines what exactly happens. To actually kill the Emacs process, use C-x C-c or the Exit Emacs item on the File menu.
On systems that do not permit programs to be suspended, C-z runs
an inferior shell that communicates directly with the terminal, and
Emacs waits until you exit the subshell. On these systems, the only way
to return to the shell from which Emacs was started (to log out, for
example) is to kill Emacs. C-d or exit are typical
commands to exit a subshell.
To kill Emacs, type C-x C-c (save-buffers-kill-emacs). A
two-character key is used for this to make it harder to type. In
XEmacs, selecting the Exit Emacs option of the File menu is an
alternate way of issuing the command.
Unless a numeric argument is used, this command first offers to save any modified buffers. If you do not save all buffers, you are asked for reconfirmation with yes before killing Emacs, since any changes not saved will be lost. If any subprocesses are still running, C-x C-c asks you to confirm killing them, since killing Emacs kills the subprocesses simultaneously.
In most programs running on Unix, certain characters may instantly suspend or kill the program. (In Berkeley Unix these characters are normally C-z and C-c.) This Unix feature is turned off while you are in Emacs. The meanings of C-z and C-x C-c as keys in Emacs were inspired by the standard Berkeley Unix meanings of C-z and C-c, but that is their only relationship with Unix. You could customize these keys to do anything (see section Keymaps).
XEmacs supports command line arguments you can use to request various actions when invoking Emacs. The commands are for compatibility with other editors and for sophisticated activities. If you are using XEmacs under the X window system, you can also use a number of standard Xt command line arguments. Command line arguments are not usually needed for editing with Emacs; new users can skip this section.
Many editors are designed to be started afresh each time you want to edit. You start the editor to edit one file; then exit the editor. The next time you want to edit either another file or the same one, you start the editor again. Under these circumstances, it makes sense to use a command line argument to say which file to edit.
The recommended way to use XEmacs is to start it only once, just after you log in, and do all your editing in the same Emacs process. Each time you want to edit a file, you visit it using the existing Emacs. Emacs creates a new buffer for each file, and (unless you kill some of the buffers) Emacs eventually has many files in it ready for editing. Usually you do not kill the Emacs process until you are about to log out. Since you usually read files by typing commands to Emacs, command line arguments for specifying a file when Emacs is started are seldom needed.
Emacs accepts command-line arguments that specify files to visit, functions to call, and other activities and operating modes. If you are running XEmacs under the X window system, a number of standard Xt command line arguments are available as well.
The following subsections list:
Command line arguments are processed in the order they appear on the command line; however, certain arguments (the ones in the second table) must be at the front of the list if they are used.
Here are the arguments allowed:
find-file. See section Visiting Files.
find-file, then go to line number
linenum in it.
load.
See section Libraries of Lisp Code for Emacs.
% xemacs -version XEmacs 19.13 of Mon Aug 21 1995 on willow (usg-unix-v) [formerly Lucid Emacs]
The following arguments are recognized only at the beginning of the command line. If more than one of them appears, they must appear in the order in which they appear in this table.
stderr only what would normally be printed
in the echo area under program control.
Batch mode is used for running programs written in Emacs Lisp from shell
scripts, makefiles, and so on. Normally the `-l' switch or
`-f' switch will be used as well, to invoke a Lisp program to do
the batch processing.
`-batch' implies `-q' (do not load an init file). It also
causes Emacs to kill itself after all command switches have been
processed. In addition, auto-saving is not done except in buffers for
which it has been explicitly requested.
Note that the init file can get access to the command line argument
values as the elements of a list in the variable
command-line-args. (The arguments in the second table above will
already have been processed and will not be in the list.) The init file
can override the normal processing of the other arguments by setting
this variable.
One way to use command switches is to visit many files automatically:
xemacs *.c
passes each .c file as a separate argument to Emacs, so that
Emacs visits each file (see section Visiting Files).
Here is an advanced example that assumes you have a Lisp program file called `hack-c-program.el' which, when loaded, performs some useful operation on the current buffer, expected to be a C program.
xemacs -batch foo.c -l hack-c-program -f save-buffer -kill > log
Here Emacs is told to visit `foo.c', load `hack-c-program.el'
(which makes changes in the visited file), save `foo.c' (note that
save-buffer is the function that C-x C-s is bound to), and
then exit to the shell from which the command was executed. `-batch'
guarantees there will be no problem redirecting output to `log',
because Emacs will not assume that it has a display terminal to work
with.
If you are running XEmacs under X, a number of options are available to control color, border, and window title and icon name:
frame-title-format variable, which controls the title of the X
window corresponding to the selected frame. This is the same format as
mode-line-format.
frame-icon-title-format variable, which controls the title of
the icon corresponding to the selected frame.
In addition, XEmacs allows you to use a number of standard Xt command line arguments.
argv[0]) as
the resource manager name.
Go to the first, previous, next, last section, table of contents.