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