Commit | Line | Data |
---|---|---|
6bf7aab6 | 1 | @c This is part of the Emacs manual. |
62eda0e2 | 2 | @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 2001, 2002, 2003, |
6ed161e1 | 3 | @c 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
6bf7aab6 | 4 | @c See file emacs.texi for copying conditions. |
321ca37f | 5 | @iftex |
6bf7aab6 | 6 | @chapter Entering and Exiting Emacs |
321ca37f CY |
7 | |
8 | This chapter explains how to enter Emacs, and how to exit it. | |
9 | @end iftex | |
10 | ||
11 | @ifnottex | |
12 | @raisesections | |
13 | @end ifnottex | |
14 | ||
15 | @node Entering Emacs, Exiting, Commands, Top | |
16 | @section Entering Emacs | |
6bf7aab6 | 17 | @cindex entering Emacs |
177c0ea7 | 18 | @cindex starting Emacs |
6bf7aab6 | 19 | |
708bf232 | 20 | The usual way to invoke Emacs is with the shell command |
321ca37f CY |
21 | @command{emacs}. From a terminal window running in the X Window |
22 | System, you can also run Emacs in the background with | |
23 | @command{emacs&}; this way, Emacs won't tie up the terminal window, so | |
24 | you can use it to run other shell commands. | |
25 | ||
26 | @cindex startup screen | |
27 | When Emacs starts up, the initial frame displays a special buffer | |
6edf847b CY |
28 | named @samp{*GNU Emacs*}. This buffer contains some information about |
29 | Emacs, and includes @dfn{links} to common tasks that might be useful | |
30 | to beginning users. For instance, activating the @samp{Emacs | |
31 | Tutorial} link opens the Emacs tutorial; this does the same thing as | |
32 | the command @kbd{C-h t} (@code{help-with-tutorial}). To activate a | |
33 | link, either move point onto it and type @kbd{@key{RET}}, or click on | |
34 | it with @kbd{mouse-1} (the left mouse button). | |
321ca37f CY |
35 | |
36 | Using a command line argument, you can tell Emacs to visit one or | |
37 | more specific files as soon as it starts up. For example, | |
38 | @command{emacs foo.txt} starts Emacs with a buffer displaying the | |
39 | contents of the file @samp{foo.txt}. This feature exists mainly for | |
40 | compatibility with other editors, which are designed to edit one file | |
41 | at a time: once you are done with that file, you exit the editor, and | |
42 | start it again the next time you need it. | |
43 | ||
44 | Using Emacs in this way---starting it afresh each time you want to | |
45 | edit a file---is unnecessary and wasteful. Emacs can visit more than | |
46 | one file in a single editing session, and exiting the Emacs session | |
47 | loses valuable accumulated context, such as the kill ring, registers, | |
48 | undo history, and mark ring. These features, described later in the | |
49 | manual, are useful for performing edits across multiple files, or | |
50 | continuing edits to a single file. | |
51 | ||
52 | The recommended way to use Emacs is to start it only once, just | |
6bf7aab6 | 53 | after you log in, and do all your editing in the same Emacs session. |
321ca37f CY |
54 | Each time you edit a file, visit it with the existing Emacs, which |
55 | eventually has many files in it ready for editing. @xref{Files}, for | |
56 | more information on visiting more than one file. | |
6bf7aab6 | 57 | |
c9a769c8 RS |
58 | To edit a file from another program while Emacs is running, you can |
59 | use the @command{emacsclient} helper program to open a file in the | |
60 | already running Emacs. @xref{Emacs Server}. | |
9f1cc7eb | 61 | |
321ca37f CY |
62 | Emacs accepts other command line arguments that tell it to load |
63 | certain Lisp files, call certain functions, and so forth. These | |
64 | features exist mainly for advanced users. @xref{Emacs Invocation}. | |
6cca5de0 | 65 | |
6edf847b | 66 | @vindex inhibit-startup-screen |
be77bd45 CY |
67 | If the variable @code{inhibit-startup-screen} is non-@code{nil}, |
68 | Emacs does not display the startup screen. In that case, if one or | |
69 | more files were specified on the command line, Emacs simply displays | |
70 | those files; otherwise, it displays a buffer named @samp{*scratch*}, | |
71 | which can be used to evaluate Emacs Lisp expressions interactively. | |
72 | @xref{Lisp Interaction}. You can set the variable | |
73 | @code{inhibit-startup-screen} using the Customize facility | |
61b9fed1 CY |
74 | (@pxref{Easy Customization}), or by editing your initialization file |
75 | (@pxref{Init File}).@footnote{Note that setting | |
76 | @code{inhibit-startup-screen} in @file{site-start.el} doesn't work, | |
77 | because the startup screen is set up before reading | |
78 | @file{site-start.el}. @xref{Init File}, for information about | |
79 | @file{site-start.el}.} | |
6edf847b | 80 | |
be77bd45 CY |
81 | You can also force Emacs to display a file or directory at startup |
82 | by setting the variable @code{initial-buffer-choice} to a | |
83 | non-@code{nil} value. (In that case, even if you specify one or more | |
84 | files on the command line, Emacs opens but does not display them.) | |
85 | The value of @code{initial-buffer-choice} can be either the name of | |
86 | the desired file or directory, or @code{t}, which means to display the | |
87 | @samp{*scratch*} buffer. | |
88 | ||
6bf7aab6 DL |
89 | @node Exiting, Basic, Entering Emacs, Top |
90 | @section Exiting Emacs | |
91 | @cindex exiting | |
92 | @cindex killing Emacs | |
6bf7aab6 DL |
93 | @cindex leaving Emacs |
94 | @cindex quitting Emacs | |
95 | ||
6bf7aab6 | 96 | @table @kbd |
321ca37f | 97 | @item C-x C-c |
a115d013 | 98 | Kill Emacs (@code{save-buffers-kill-terminal}). |
6bf7aab6 | 99 | @item C-z |
2e18b114 CY |
100 | On a text terminal, suspend Emacs (@code{suspend-emacs}); on a |
101 | graphical display, iconify (or ``minimize'') the selected frame | |
6bf7aab6 | 102 | (@code{iconify-or-deiconify-frame}). |
6bf7aab6 DL |
103 | @end table |
104 | ||
6bf7aab6 | 105 | @kindex C-x C-c |
a115d013 | 106 | @findex save-buffers-kill-terminal |
321ca37f | 107 | @dfn{Killing} Emacs means terminating the Emacs program. To do |
a115d013 | 108 | this, type @kbd{C-x C-c} (@code{save-buffers-kill-terminal}). A |
321ca37f CY |
109 | two-character key is used to make it harder to type by accident. If |
110 | there are any modified file-visiting buffers when you type @kbd{C-x | |
111 | C-c}, Emacs first offers to save these buffers. If you do not save | |
112 | them all, it asks for confirmation again, since the unsaved changes | |
113 | will be lost. Emacs also asks for confirmation if any subprocesses | |
114 | are still running, since killing Emacs will also kill the subprocesses | |
115 | (@pxref{Shell}). | |
116 | ||
a115d013 CY |
117 | @kbd{C-x C-c} behaves specially if you are using Emacs as a server. |
118 | If you type it from a ``client frame'', it closes the client | |
119 | connection. @xref{Emacs Server}. | |
120 | ||
321ca37f CY |
121 | Emacs can, optionally, record certain session information when you |
122 | kill it, such as the files you were visiting at the time. This | |
123 | information is then available the next time you start Emacs. | |
124 | @xref{Saving Emacs Sessions}. | |
6bf7aab6 | 125 | |
e020c833 EZ |
126 | @vindex confirm-kill-emacs |
127 | If the value of the variable @code{confirm-kill-emacs} is | |
128 | non-@code{nil}, @kbd{C-x C-c} assumes that its value is a predicate | |
321ca37f CY |
129 | function, and calls that function. If the result of the function call |
130 | is non-@code{nil}, the session is killed, otherwise Emacs continues to | |
131 | run. One convenient function to use as the value of | |
132 | @code{confirm-kill-emacs} is the function @code{yes-or-no-p}. The | |
133 | default value of @code{confirm-kill-emacs} is @code{nil}. | |
134 | ||
a115d013 CY |
135 | @findex kill-emacs |
136 | To kill Emacs without being prompted about saving, type @kbd{M-x | |
137 | kill-emacs}. | |
138 | ||
321ca37f CY |
139 | @cindex minimizing a frame |
140 | @cindex iconifying | |
141 | @cindex suspending | |
142 | You can ``exit'' Emacs in two other ways. On a graphical display, | |
143 | you can @dfn{iconify} (or @dfn{minimize}) an Emacs frame; depending on | |
144 | the window system, this either replaces the Emacs frame with a tiny | |
145 | ``icon'' or conceals the frame entirely (@pxref{Frames}). On a | |
146 | text-only terminal, you can @dfn{suspend} Emacs; this means stopping | |
147 | the Emacs program temporarily, returning control to its parent process | |
148 | (usually a shell). | |
149 | ||
150 | @kindex C-z | |
151 | @findex iconify-or-deiconify-frame | |
152 | @findex suspend-emacs | |
153 | On a graphical display, @kbd{C-z} runs the command | |
154 | @code{iconify-or-deiconify-frame}, which iconifies the selected Emacs | |
155 | frame. On a text terminal, @kbd{C-z} runs the command | |
156 | @code{suspend-emacs}, which suspends Emacs. | |
157 | ||
158 | After iconifying or suspending Emacs, you can return to it and | |
159 | continue editing wherever you left off. The way to do this depends on | |
160 | the window system or shell. In most common shells, you can resume | |
161 | Emacs after suspending it with the shell command @command{%emacs}. | |
162 | ||
163 | @vindex cannot-suspend | |
164 | On very old systems that don't support suspending programs, | |
165 | @kbd{C-z} starts an inferior shell that communicates directly with the | |
166 | terminal, and Emacs waits until you exit the subshell. (The way to | |
167 | exit the subshell is usually @kbd{C-d} or @command{exit}.) On these | |
168 | systems, you can only get back to the shell from which Emacs was run | |
169 | (to log out, for example) when you kill Emacs. Suspending can also | |
170 | fail if you run Emacs under a shell that doesn't support suspending | |
171 | jobs, even if the system itself does support it. In this case, you | |
172 | can set the variable @code{cannot-suspend} to a non-@code{nil} value | |
173 | to force @kbd{C-z} to start an inferior shell. | |
174 | ||
175 | Text-only terminals usually listen for certain special characters | |
6bf7aab6 | 176 | whose meaning is to kill or suspend the program you are running. |
321ca37f CY |
177 | @b{This terminal feature is turned off while you are in Emacs.} The |
178 | meanings of @kbd{C-z} and @kbd{C-x C-c} as keys in Emacs were inspired | |
179 | by the use of @kbd{C-z} and @kbd{C-c} on several operating systems as | |
180 | the characters for stopping or killing a program, but that is their | |
181 | only relationship with the operating system. You can customize these | |
182 | keys to run any commands of your choice (@pxref{Keymaps}). | |
ab5796a9 | 183 | |
6cca5de0 LT |
184 | @ifnottex |
185 | @lowersections | |
186 | @end ifnottex | |
187 | ||
ab5796a9 MB |
188 | @ignore |
189 | arch-tag: df798d8b-f253-4113-b585-f528f078a944 | |
190 | @end ignore |