(Top): Minor clarification.
[bpt/emacs.git] / man / entering.texi
... / ...
CommitLineData
1@c This is part of the Emacs manual.
2@c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 2002, 2003, 2004,
3@c 2005, 2006 Free Software Foundation, Inc.
4@c See file emacs.texi for copying conditions.
5@node Entering Emacs, Exiting, Text Characters, Top
6@chapter Entering and Exiting Emacs
7@cindex entering Emacs
8@cindex starting Emacs
9
10 The usual way to invoke Emacs is with the shell command
11@command{emacs}. Emacs clears the screen and then displays an initial
12help message and copyright notice. Some operating systems discard all
13type-ahead when Emacs starts up; they give Emacs no way to prevent
14this. If you ever use those systems, learn the habit of waiting for
15Emacs to clear the screen before typing your first editing command.
16
17 If you run Emacs from a shell window under the X Window System, run it
18in the background with @command{emacs&}. This way, Emacs does not tie up
19the shell window, so you can use that to run other shell commands while
20Emacs operates its own X windows. You can begin typing Emacs commands
21as soon as you direct your keyboard input to the Emacs frame.
22
23@vindex initial-major-mode
24 When Emacs starts up, it creates a buffer named @samp{*scratch*}.
25That's the buffer you start out in. The @samp{*scratch*} buffer uses
26Lisp Interaction mode; you can use it to type Lisp expressions and
27evaluate them, or you can ignore that capability and just write notes
28in it. (You can specify a different major mode for this buffer by
29setting the variable @code{initial-major-mode} in your init file.
30@xref{Init File}.)
31
32 It is possible to specify files to be visited, Lisp files to be
33loaded, and functions to be called, by giving Emacs arguments in the
34shell command line. @xref{Emacs Invocation}. But we don't recommend
35doing this. The feature exists mainly for compatibility with other
36editors.
37
38 Many other editors are designed to be started afresh each time you
39want to edit. You edit one file and then exit the editor. The next
40time you want to edit either another file or the same one, you must run
41the editor again. With these editors, it makes sense to use a
42command-line argument to say which file to edit.
43
44 But starting a new Emacs each time you want to edit a different file
45does not make sense. This would fail to take advantage of Emacs's
46ability to visit more than one file in a single editing session, and
47it would lose the other accumulated context, such as the kill ring,
48registers, undo history, and mark ring, that are useful for operating
49on multiple files or even one.
50
51 The recommended way to use GNU Emacs is to start it only once, just
52after you log in, and do all your editing in the same Emacs session.
53Each time you want to edit a different file, you visit it with the
54existing Emacs, which eventually comes to have many files in it ready
55for editing. Usually you do not kill the Emacs until you are about to
56log out. @xref{Files}, for more information on visiting more than one
57file.
58
59 If you want to edit a file from another program and already have
60Emacs running, you can use the @command{emacsclient} program to open a
61file in the already running Emacs. @xref{Emacs Server}, for more
62information on editing files with Emacs from other programs.
63
64@ifnottex
65@raisesections
66@end ifnottex
67
68@node Exiting, Basic, Entering Emacs, Top
69@section Exiting Emacs
70@cindex exiting
71@cindex killing Emacs
72@cindex suspending
73@cindex leaving Emacs
74@cindex quitting Emacs
75
76 There are two commands for exiting Emacs because there are three
77kinds of exiting: @dfn{suspending} Emacs, @dfn{Iconifying} Emacs, and
78@dfn{killing} Emacs.
79
80 @dfn{Suspending} means stopping Emacs temporarily and returning
81control to its parent process (usually a shell), allowing you to resume
82editing later in the same Emacs job, with the same buffers, same kill
83ring, same undo history, and so on. This is the usual way to exit Emacs
84when running on a text terminal.
85
86 @dfn{Iconifying} means replacing the Emacs frame with a small box
87somewhere on the screen. This is the usual way to exit Emacs when you're
88using a graphics terminal---if you bother to ``exit'' at all. (Just switching
89to another application is usually sufficient.)
90
91 @dfn{Killing} Emacs means destroying the Emacs job. You can run Emacs
92again later, but you will get a fresh Emacs; there is no way to resume
93the same editing session after it has been killed.
94
95@table @kbd
96@item C-z
97Suspend Emacs (@code{suspend-emacs}) or iconify a frame
98(@code{iconify-or-deiconify-frame}).
99@item C-x C-c
100Kill Emacs (@code{save-buffers-kill-emacs}).
101@end table
102
103@kindex C-z
104@findex suspend-emacs
105 To suspend or iconify Emacs, type @kbd{C-z} (@code{suspend-emacs}).
106On text terminals, this suspends Emacs. On graphical displays,
107it iconifies the Emacs frame.
108
109 Suspending Emacs takes you back to the shell from which you invoked
110Emacs. You can resume Emacs with the shell command @command{%emacs}
111in most common shells. On systems that don't support suspending
112programs, @kbd{C-z} starts an inferior shell that communicates
113directly with the terminal, and Emacs waits until you exit the subshell.
114(The way to do that is probably with @kbd{C-d} or @command{exit}, but
115it depends on which shell you use.) The only way on these systems to
116get back to the shell from which Emacs was run (to log out, for
117example) is to kill Emacs.
118
119 Suspending can fail if you run Emacs under a shell that doesn't
120support suspending programs, even if the system itself does support
121it. In such a case, you can set the variable @code{cannot-suspend} to
122a non-@code{nil} value to force @kbd{C-z} to start an inferior shell.
123(One might also describe Emacs's parent shell as ``inferior'' for
124failing to support job control properly, but that is a matter of
125taste.)
126
127 On graphical displays, @kbd{C-z} has a different meaning: it runs
128the command @code{iconify-or-deiconify-frame}, which temporarily
129iconifies (or ``minimizes'') the selected Emacs frame
130(@pxref{Frames}). Then you can use the window manager to get back to
131a shell window.
132
133@kindex C-x C-c
134@findex save-buffers-kill-emacs
135 To exit and kill Emacs, type @kbd{C-x C-c}
136(@code{save-buffers-kill-emacs}). A two-character key is used for
137this to make it harder to type by accident. This command first offers
138to save any modified file-visiting buffers. If you do not save them
139all, it asks for reconfirmation with @kbd{yes} before killing Emacs,
140since any changes not saved will be lost forever. Also, if any
141subprocesses are still running, @kbd{C-x C-c} asks for confirmation
142about them, since killing Emacs will also kill the subprocesses.
143
144@vindex confirm-kill-emacs
145 If the value of the variable @code{confirm-kill-emacs} is
146non-@code{nil}, @kbd{C-x C-c} assumes that its value is a predicate
147function, and calls that function. If the result is non-@code{nil}, the
148session is killed, otherwise Emacs continues to run. One convenient
149function to use as the value of @code{confirm-kill-emacs} is the
150function @code{yes-or-no-p}. The default value of
151@code{confirm-kill-emacs} is @code{nil}.
152
153 There is no way to resume an Emacs session once you have killed it.
154You can, however, arrange for Emacs to record certain session
155information when you kill it, such as which files are visited, so that
156the next time you start Emacs it will try to visit the same files and
157so on. @xref{Saving Emacs Sessions}.
158
159 The operating system usually listens for certain special characters
160whose meaning is to kill or suspend the program you are running.
161@b{This operating system feature is turned off while you are in Emacs.}
162The meanings of @kbd{C-z} and @kbd{C-x C-c} as keys in Emacs were
163inspired by the use of @kbd{C-z} and @kbd{C-c} on several operating
164systems as the characters for stopping or killing a program, but that is
165their only relationship with the operating system. You can customize
166these keys to run any commands of your choice (@pxref{Keymaps}).
167
168@ifnottex
169@lowersections
170@end ifnottex
171
172@ignore
173 arch-tag: df798d8b-f253-4113-b585-f528f078a944
174@end ignore