* lisp/files.el (file-auto-mode-skip): New var.
[bpt/emacs.git] / doc / emacs / building.texi
CommitLineData
8cf51b2c 1@c This is part of the Emacs manual.
acaf905b 2@c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2012
8838673e 3@c Free Software Foundation, Inc.
8cf51b2c
GM
4@c See file emacs.texi for copying conditions.
5@node Building, Maintaining, Programs, Top
6@chapter Compiling and Testing Programs
7@cindex building programs
8@cindex program building
9@cindex running Lisp functions
10
b09d01da
CY
11 The previous chapter discusses the Emacs commands that are useful
12for making changes in programs. This chapter deals with commands that
13assist in the process of compiling and testing programs.
8cf51b2c
GM
14
15@menu
16* Compilation:: Compiling programs in languages other
17 than Lisp (C, Pascal, etc.).
18* Compilation Mode:: The mode for visiting compiler errors.
19* Compilation Shell:: Customizing your shell properly
20 for use in the compilation buffer.
21* Grep Searching:: Searching with grep.
22* Flymake:: Finding syntax errors on the fly.
8838673e 23* Debuggers:: Running symbolic debuggers for non-Lisp programs.
8cf51b2c
GM
24* Executing Lisp:: Various modes for editing Lisp programs,
25 with different facilities for running
26 the Lisp programs.
f3b316df
CY
27* Libraries: Lisp Libraries. How Lisp programs are loaded into Emacs.
28* Eval: Lisp Eval. Executing a single Lisp expression in Emacs.
29* Interaction: Lisp Interaction. Executing Lisp in an Emacs buffer.
8838673e 30* External Lisp:: Communicating through Emacs with a separate Lisp.
8cf51b2c
GM
31@end menu
32
33@node Compilation
34@section Running Compilations under Emacs
35@cindex inferior process
36@cindex make
37@cindex compilation errors
38@cindex error log
39
29eabb8e
CY
40 Emacs can run compilers for languages such as C and Fortran, feeding
41the compilation log into an Emacs buffer. It can also parse the error
42messages and show you where the errors occurred.
8cf51b2c
GM
43
44@table @kbd
45@item M-x compile
46Run a compiler asynchronously under Emacs, with error messages going to
1c64e6ed 47the @file{*compilation*} buffer.
8cf51b2c
GM
48@item M-x recompile
49Invoke a compiler with the same command as in the last invocation of
50@kbd{M-x compile}.
51@item M-x kill-compilation
52Kill the running compilation subprocess.
53@end table
54
55@findex compile
b09d01da
CY
56 To run @code{make} or another compilation command, type @kbd{M-x
57compile}. This reads a shell command line using the minibuffer, and
29eabb8e
CY
58then executes the command by running a shell as a subprocess (or
59@dfn{inferior process}) of Emacs. The output is inserted in a buffer
1c64e6ed 60named @file{*compilation*}. The current buffer's default directory is
29eabb8e
CY
61used as the working directory for the execution of the command;
62normally, therefore, compilation takes place in this directory.
8cf51b2c
GM
63
64@vindex compile-command
b09d01da
CY
65 The default compilation command is @samp{make -k}, which is usually
66correct for programs compiled using the @command{make} utility (the
67@samp{-k} flag tells @command{make} to continue compiling as much as
68possible after an error). @xref{Top,, Make, make, GNU Make Manual}.
69If you have done @kbd{M-x compile} before, the command that you
70specified is automatically stored in the variable
71@code{compile-command}; this is used as the default the next time you
72type @kbd{M-x compile}. A file can also specify a file-local value
73for @code{compile-command} (@pxref{File Variables}).
74
1c64e6ed 75 Starting a compilation displays the @file{*compilation*} buffer in
b09d01da
CY
76another window but does not select it. While the compilation is
77running, the word @samp{run} is shown in the major mode indicator for
1c64e6ed
GM
78the @file{*compilation*} buffer, and the word @samp{Compiling} appears
79in all mode lines. You do not have to keep the @file{*compilation*}
b09d01da
CY
80buffer visible while compilation is running; it continues in any case.
81When the compilation ends, for whatever reason, the mode line of the
1c64e6ed 82@file{*compilation*} buffer changes to say @samp{exit} (followed by
b09d01da
CY
83the exit code: @samp{[0]} for a normal exit), or @samp{signal} (if a
84signal terminated the process).
85
86 If you want to watch the compilation transcript as it appears,
1c64e6ed 87switch to the @file{*compilation*} buffer and move point to the end of
b09d01da
CY
88the buffer. When point is at the end, new compilation output is
89inserted above point, which remains at the end. Otherwise, point
90remains fixed while compilation output is added at the end of the
91buffer.
8cf51b2c
GM
92
93@cindex compilation buffer, keeping point at end
94@vindex compilation-scroll-output
07799e9a 95 If you change the variable @code{compilation-scroll-output} to a
1c64e6ed 96non-@code{nil} value, the @file{*compilation*} buffer scrolls
b09d01da
CY
97automatically to follow the output. If the value is
98@code{first-error}, scrolling stops when the first error appears,
99leaving point at that error. For any other non-@code{nil} value,
100scrolling continues until there is no more output.
8cf51b2c
GM
101
102@findex recompile
103 To rerun the last compilation with the same command, type @kbd{M-x
b09d01da
CY
104recompile}. This reuses the compilation command from the last
105invocation of @kbd{M-x compile}. It also reuses the
1c64e6ed 106@file{*compilation*} buffer and starts the compilation in its default
8cf51b2c
GM
107directory, which is the directory in which the previous compilation
108was started.
109
8cf51b2c
GM
110@findex kill-compilation
111 Starting a new compilation also kills any compilation already
1c64e6ed 112running in @file{*compilation*}, as the buffer can only handle one
8cf51b2c
GM
113compilation at any time. However, @kbd{M-x compile} asks for
114confirmation before actually killing a compilation that is running.
115You can also kill the compilation process with @kbd{M-x
116kill-compilation}.
117
bb033b5f 118 To run two compilations at once, start the first one, then rename
1c64e6ed 119the @file{*compilation*} buffer (perhaps using @code{rename-uniquely};
bb033b5f 120@pxref{Misc Buffer}), then switch buffers and start the other
1c64e6ed 121compilation. This will create a new @file{*compilation*} buffer.
8cf51b2c 122
8cf51b2c
GM
123@vindex compilation-environment
124 You can control the environment passed to the compilation command
125with the variable @code{compilation-environment}. Its value is a list
126of environment variable settings; each element should be a string of
127the form @code{"@var{envvarname}=@var{value}"}. These environment
128variable settings override the usual ones.
129
130@node Compilation Mode
131@section Compilation Mode
132
133@cindex Compilation mode
134@cindex mode, Compilation
b09d01da 135@cindex locus
1c64e6ed 136 The @file{*compilation*} buffer uses a major mode called Compilation
b09d01da
CY
137mode. Compilation mode turns each error message in the buffer into a
138hyperlink; you can move point to it and type @key{RET}, or click on it
139with the mouse (@pxref{Mouse References}), to visit the @dfn{locus} of
140the error message in a separate window. The locus is the specific
141position in a file where that error occurred.
142
143@findex compile-goto-error
144@vindex compilation-auto-jump-to-first-error
145 If you change the variable
146@code{compilation-auto-jump-to-first-error} to a non-@code{nil} value,
147Emacs automatically visits the locus of the first error message that
1c64e6ed 148appears in the @file{*compilation*} buffer.
b09d01da
CY
149
150 Compilation mode provides the following additional commands. These
1c64e6ed 151commands can also be used in @file{*grep*} buffers, where the
b09d01da
CY
152hyperlinks are search matches rather than error messages (@pxref{Grep
153Searching}).
8cf51b2c
GM
154
155@table @kbd
156@item M-g M-n
157@itemx M-g n
158@itemx C-x `
b09d01da 159Visit the locus of the next error message or match (@code{next-error}).
8cf51b2c
GM
160@item M-g M-p
161@itemx M-g p
b09d01da
CY
162Visit the locus of the previous error message or match
163(@code{previous-error}).
8cf51b2c 164@item M-n
b09d01da
CY
165Move point to the next error message or match, without visiting its
166locus (@code{compilation-next-error}).
8cf51b2c 167@item M-p
b09d01da
CY
168Move point to the previous error message or match, without visiting
169its locus (@code{compilation-previous-error}).
8cf51b2c 170@item M-@}
b09d01da
CY
171Move point to the next error message or match occurring in a different
172file (@code{compilation-next-file}).
8cf51b2c 173@item M-@{
b09d01da
CY
174Move point to the previous error message or match occurring in a
175different file (@code{compilation-previous-file}).
8cf51b2c
GM
176@item C-c C-f
177Toggle Next Error Follow minor mode, which makes cursor motion in the
178compilation buffer produce automatic source display.
179@end table
180
8cf51b2c
GM
181@kindex M-g M-n
182@kindex M-g n
183@kindex C-x `
184@findex next-error
185@vindex next-error-highlight
b09d01da
CY
186 To visit errors sequentially, type @w{@kbd{C-x `}}
187(@code{next-error}), or equivalently @kbd{M-g M-n} or @kbd{M-g n}.
188This command can be invoked from any buffer, not just a Compilation
189mode buffer. The first time you invoke it after a compilation, it
190visits the locus of the first error message. Each subsequent
191@w{@kbd{C-x `}} visits the next error, in a similar fashion. If you
192visit a specific error with @key{RET} or a mouse click in the
1c64e6ed 193@file{*compilation*} buffer, subsequent @w{@kbd{C-x `}} commands
b09d01da
CY
194advance from there. When @w{@kbd{C-x `}} finds no more error messages
195to visit, it signals an error. @w{@kbd{C-u C-x `}} starts again from
196the beginning of the compilation buffer, and visits the first locus.
197
198 @kbd{M-g M-p} or @kbd{M-g p} (@code{previous-error}) iterates
199through errors in the opposite direction.
200
201 The @code{next-error} and @code{previous-error} commands don't just
1c64e6ed
GM
202act on the errors or matches listed in @file{*compilation*} and
203@file{*grep*} buffers; they also know how to iterate through error or
b09d01da
CY
204match lists produced by other commands, such as @kbd{M-x occur}
205(@pxref{Other Repeating Search}). If you are already in a buffer
206containing error messages or matches, those are the ones that are
207iterated through; otherwise, Emacs looks for a buffer containing error
208messages or matches amongst the windows of the selected frame, then
209for one that @code{next-error} or @code{previous-error} previously
210iterated through, and finally amongst all other buffers. If the
211buffer chosen for iterating through is not currently displayed in a
212window, it will be displayed.
8cf51b2c
GM
213
214@vindex compilation-skip-threshold
b09d01da
CY
215 By default, the @code{next-error} and @code{previous-error} commands
216skip less important messages. The variable
217@code{compilation-skip-threshold} controls this. The default value,
2181, means to skip anything less important than a warning. A value of 2
219means to skip anything less important than an error, while 0 means not
220to skip any messages.
221
222 When Emacs visits the locus of an error message, it momentarily
223highlights the relevant source line. The duration of this highlight
224is determined by the variable @code{next-error-highlight}.
225
226@vindex compilation-context-lines
1c64e6ed 227 If the @file{*compilation*} buffer is shown in a window with a left
b09d01da
CY
228fringe (@pxref{Fringes}), the locus-visiting commands put an arrow in
229the fringe, pointing to the current error message. If the window has
0be641c0
CY
230no left fringe, such as on a text terminal, these commands scroll the
231window so that the current message is at the top of the window. If
232you change the variable @code{compilation-context-lines} to an integer
233value @var{n}, these commands scroll the window so that the current
234error message is @var{n} lines from the top, whether or not there is a
235fringe; the default value, @code{nil}, gives the behavior described
236above.
8cf51b2c
GM
237
238@vindex compilation-error-regexp-alist
239@vindex grep-regexp-alist
240 To parse messages from the compiler, Compilation mode uses the
241variable @code{compilation-error-regexp-alist} which lists various
b09d01da
CY
242error message formats and tells Emacs how to extract the locus from
243each. A similar variable, @code{grep-regexp-alist}, tells Emacs how
244to parse output from a @code{grep} command (@pxref{Grep Searching}).
8cf51b2c
GM
245
246@findex compilation-next-error
247@findex compilation-previous-error
248@findex compilation-next-file
249@findex compilation-previous-file
b09d01da
CY
250 Compilation mode also defines the keys @key{SPC} and @key{DEL} to
251scroll by screenfuls; @kbd{M-n} (@code{compilation-next-error}) and
252@kbd{M-p} (@code{compilation-previous-error}) to move to the next or
253previous error message; and @kbd{M-@{} (@code{compilation-next-file})
254and @kbd{M-@}} (@code{compilation-previous-file}) to move to the next
255or previous error message for a different source file.
8cf51b2c
GM
256
257@cindex Next Error Follow mode
258@findex next-error-follow-minor-mode
259 You can type @kbd{C-c C-f} to toggle Next Error Follow mode. In
260this minor mode, ordinary cursor motion in the compilation buffer
b09d01da
CY
261automatically updates the source buffer, i.e.@: moving the cursor over
262an error message causes the locus of that error to be displayed.
8cf51b2c
GM
263
264 The features of Compilation mode are also available in a minor mode
265called Compilation Minor mode. This lets you parse error messages in
b09d01da
CY
266any buffer, not just a normal compilation output buffer. Type
267@kbd{M-x compilation-minor-mode} to enable the minor mode. For
268instance, in an Rlogin buffer (@pxref{Remote Host}), Compilation minor
269mode automatically accesses remote source files by FTP (@pxref{File
270Names}).
8cf51b2c
GM
271
272@node Compilation Shell
273@section Subshells for Compilation
274
b09d01da
CY
275 The @kbd{M-x compile} command uses a shell to run the compilation
276command, but specifies the option for a noninteractive shell. This
277means, in particular, that the shell should start with no prompt. If
278you find your usual shell prompt making an unsightly appearance in the
1c64e6ed 279@file{*compilation*} buffer, it means you have made a mistake in your
b09d01da
CY
280shell's init file by setting the prompt unconditionally. (This init
281file may be named @file{.bashrc}, @file{.profile}, @file{.cshrc},
282@file{.shrc}, etc., depending on what shell you use.) The shell init
8cf51b2c
GM
283file should set the prompt only if there already is a prompt. Here's
284how to do it in bash:
285
286@example
287if [ "$@{PS1+set@}" = set ]
288then PS1=@dots{}
289fi
290@end example
291
292@noindent
293And here's how to do it in csh:
294
295@example
296if ($?prompt) set prompt = @dots{}
297@end example
298
b09d01da
CY
299 Emacs does not expect a compiler process to launch asynchronous
300subprocesses; if it does, and they keep running after the main
301compiler process has terminated, Emacs may kill them or their output
302may not arrive in Emacs. To avoid this problem, make the main
303compilation process wait for its subprocesses to finish. In a shell
304script, you can do this using @samp{$!} and @samp{wait}, like this:
305
306@example
307(sleep 10; echo 2nd)& pid=$! # @r{Record pid of subprocess}
308echo first message
309wait $pid # @r{Wait for subprocess}
310@end example
311
312@noindent
313If the background process does not output to the compilation buffer,
314so you only need to prevent it from being killed when the main
315compilation process terminates, this is sufficient:
316
317@example
318nohup @var{command}; sleep 1
319@end example
8cf51b2c 320
8cf51b2c 321@ifnottex
b09d01da
CY
322 On the MS-DOS ``operating system'', asynchronous subprocesses are
323not supported, so @kbd{M-x compile} runs the compilation command
324synchronously (i.e.@: you must wait until the command finishes before
325you can do anything else in Emacs). @xref{MS-DOS}.
8cf51b2c
GM
326@end ifnottex
327
328@node Grep Searching
329@section Searching with Grep under Emacs
330
331 Just as you can run a compiler from Emacs and then visit the lines
b09d01da
CY
332with compilation errors, you can also run @command{grep} and then
333visit the lines on which matches were found. This works by treating
16152b76 334the matches reported by @command{grep} as if they were ``errors''.
b09d01da 335The output buffer uses Grep mode, which is a variant of Compilation
8cf51b2c
GM
336mode (@pxref{Compilation Mode}).
337
338@table @kbd
339@item M-x grep
467e8d77 340@itemx M-x lgrep
b09d01da 341Run @command{grep} asynchronously under Emacs, listing matching lines in
1c64e6ed 342the buffer named @file{*grep*}.
8cf51b2c
GM
343@item M-x grep-find
344@itemx M-x find-grep
345@itemx M-x rgrep
b09d01da 346Run @command{grep} via @code{find}, and collect output in the
1c64e6ed 347@file{*grep*} buffer.
26e533e2 348@item M-x zrgrep
1c64e6ed 349Run @code{zgrep} and collect output in the @file{*grep*} buffer.
8cf51b2c 350@item M-x kill-grep
b09d01da 351Kill the running @command{grep} subprocess.
8cf51b2c
GM
352@end table
353
354@findex grep
b09d01da
CY
355 To run @command{grep}, type @kbd{M-x grep}, then enter a command line
356that specifies how to run @command{grep}. Use the same arguments you
357would give @command{grep} when running it normally: a @command{grep}-style
8cf51b2c
GM
358regexp (usually in single-quotes to quote the shell's special
359characters) followed by file names, which may use wildcards. If you
360specify a prefix argument for @kbd{M-x grep}, it finds the tag
361(@pxref{Tags}) in the buffer around point, and puts that into the
b09d01da 362default @command{grep} command.
8cf51b2c 363
b09d01da 364 Your command need not simply run @command{grep}; you can use any shell
8cf51b2c 365command that produces output in the same format. For instance, you
b09d01da 366can chain @command{grep} commands, like this:
8cf51b2c
GM
367
368@example
369grep -nH -e foo *.el | grep bar | grep toto
370@end example
371
1c64e6ed 372 The output from @command{grep} goes in the @file{*grep*} buffer. You
8cf51b2c
GM
373can find the corresponding lines in the original files using @w{@kbd{C-x
374`}}, @key{RET}, and so forth, just like compilation errors.
375
376 Some grep programs accept a @samp{--color} option to output special
377markers around matches for the purpose of highlighting. You can make
378use of this feature by setting @code{grep-highlight-matches} to
379@code{t}. When displaying a match in the source buffer, the exact
380match will be highlighted, instead of the entire source line.
381
382@findex grep-find
383@findex find-grep
384 The command @kbd{M-x grep-find} (also available as @kbd{M-x
385find-grep}) is similar to @kbd{M-x grep}, but it supplies a different
386initial default for the command---one that runs both @code{find} and
b09d01da 387@command{grep}, so as to search every file in a directory tree. See also
8cf51b2c
GM
388the @code{find-grep-dired} command, in @ref{Dired and Find}.
389
390@findex lgrep
391@findex rgrep
26e533e2 392@findex zrgrep
8cf51b2c 393 The commands @kbd{M-x lgrep} (local grep) and @kbd{M-x rgrep}
b09d01da 394(recursive grep) are more user-friendly versions of @command{grep} and
8cf51b2c
GM
395@code{grep-find}, which prompt separately for the regular expression
396to match, the files to search, and the base directory for the search.
26e533e2
CY
397Case sensitivity of the search is controlled by the current value of
398@code{case-fold-search}. The command @kbd{M-x zrgrep} is similar to
b09d01da
CY
399@kbd{M-x rgrep}, but it calls @command{zgrep} instead of
400@command{grep} to search the contents of gzipped files.
8cf51b2c 401
26e533e2 402 These commands build the shell commands based on the variables
8cf51b2c 403@code{grep-template} (for @code{lgrep}) and @code{grep-find-template}
26e533e2
CY
404(for @code{rgrep}). The files to search can use aliases defined in
405the variable @code{grep-files-aliases}.
8cf51b2c 406
b09d01da
CY
407@vindex grep-find-ignored-directories
408 Directories listed in the variable
409@code{grep-find-ignored-directories} are automatically skipped by
410@kbd{M-x rgrep}. The default value includes the data directories used
411by various version control systems.
8cf51b2c
GM
412
413@node Flymake
414@section Finding Syntax Errors On The Fly
415@cindex checking syntax
416
417 Flymake mode is a minor mode that performs on-the-fly syntax
418checking for many programming and markup languages, including C, C++,
419Perl, HTML, and @TeX{}/La@TeX{}. It is somewhat analogous to Flyspell
420mode, which performs spell checking for ordinary human languages in a
421similar fashion (@pxref{Spelling}). As you edit a file, Flymake mode
422runs an appropriate syntax checking tool in the background, using a
423temporary copy of the buffer. It then parses the error and warning
424messages, and highlights the erroneous lines in the buffer. The
425syntax checking tool used depends on the language; for example, for
426C/C++ files this is usually the C compiler. Flymake can also use
427build tools such as @code{make} for checking complicated projects.
428
9eb25ee8
GM
429 To enable Flymake mode, type @kbd{M-x flymake-mode}. You can jump to
430the errors that it finds by using @kbd{M-x
431flymake-goto-next-error} and @kbd{M-x flymake-goto-prev-error}.
432Use the command @kbd{M-x flymake-display-err-menu-for-current-line}
433to display any error messages associated with the current line.
8cf51b2c 434
b09d01da
CY
435 For more details about using Flymake,
436@ifnottex
437see @ref{Top, Flymake, Flymake, flymake, The Flymake Manual}.
438@end ifnottex
439@iftex
440see the Flymake Info manual, which is distributed with Emacs.
441@end iftex
8cf51b2c
GM
442
443@node Debuggers
444@section Running Debuggers Under Emacs
445@cindex debuggers
446@cindex GUD library
447@cindex GDB
448@cindex DBX
449@cindex SDB
450@cindex XDB
451@cindex Perldb
452@cindex JDB
453@cindex PDB
454
a03334ca 455The GUD (Grand Unified Debugger) library provides an Emacs interface
0595bd7e
CY
456to a wide variety of symbolic debuggers. It can run the GNU Debugger
457(GDB), as well as DBX, SDB, XDB, Perl's debugging mode, the Python
458debugger PDB, and the Java Debugger JDB.
8cf51b2c 459
0595bd7e
CY
460 Emacs provides a special interface to GDB, which uses extra Emacs
461windows to display the state of the debugged program. @xref{GDB
462Graphical Interface}.
463
464 Emacs also has a built-in debugger for Emacs Lisp programs.
465@xref{Debugging,, The Lisp Debugger, elisp, the Emacs Lisp Reference
466Manual}.
d35fdb5b 467
8cf51b2c 468@menu
8838673e
GM
469* Starting GUD:: How to start a debugger subprocess.
470* Debugger Operation:: Connection between the debugger and source buffers.
471* Commands of GUD:: Key bindings for common commands.
472* GUD Customization:: Defining your own commands for GUD.
b424697f 473* GDB Graphical Interface:: An enhanced mode that uses GDB features to
2d2f6581 474 implement a graphical debugging environment.
8cf51b2c
GM
475@end menu
476
477@node Starting GUD
b424697f 478@subsection Starting GUD
8cf51b2c 479
0595bd7e 480 There are several commands for starting a debugger subprocess, each
a03334ca 481corresponding to a particular debugger program.
8cf51b2c
GM
482
483@table @kbd
0595bd7e 484@item M-x gdb
b424697f 485@findex gdb
0595bd7e
CY
486Run GDB as a subprocess, and interact with it via an IDE-like Emacs
487interface. @xref{GDB Graphical Interface}, for more information about
488this command.
b424697f 489
0595bd7e 490@item M-x gud-gdb
4f45c619 491@findex gud-gdb
0595bd7e
CY
492Run GDB, using a GUD interaction buffer for input and output to the
493GDB subprocess (@pxref{Debugger Operation}). If such a buffer already
494exists, switch to it; otherwise, create the buffer and switch to it.
8cf51b2c 495
0595bd7e
CY
496The other commands in this list do the same, for other debugger
497programs.
8cf51b2c 498
0595bd7e 499@item M-x perldb
8cf51b2c 500@findex perldb
0595bd7e 501Run the Perl interpreter in debug mode.
8cf51b2c 502
0595bd7e 503@item M-x jdb
8cf51b2c 504@findex jdb
0595bd7e 505Run the Java debugger.
8cf51b2c 506
0595bd7e 507@item M-x pdb
8cf51b2c 508@findex pdb
0595bd7e
CY
509Run the Python debugger.
510
511@item M-x dbx
512@findex dbx
513Run the DBX debugger.
514
515@item M-x xdb
516@findex xdb
517@vindex gud-xdb-directories
518Run the XDB debugger.
519
520@item M-x sdb
521@findex sdb
522Run the SDB debugger.
8cf51b2c
GM
523@end table
524
0595bd7e
CY
525 Each of these commands reads a command line to invoke the debugger,
526using the minibuffer. The minibuffer's initial contents contain the
527standard executable name and options for the debugger, and sometimes
528also a guess for the name of the executable file you want to debug.
529Shell wildcards and variables are not allowed in this command line.
530Emacs assumes that the first command argument which does not start
531with a @samp{-} is the executable file name.
8cf51b2c 532
a03334ca 533@cindex remote host, debugging on
0595bd7e
CY
534 Tramp provides a facility for remote debugging, whereby both the
535debugger and the program being debugged are on the same remote host.
536@xref{Running a debugger on a remote host,,, tramp, The Tramp Manual},
537for details. This is separate from GDB's remote debugging feature,
538where the program and the debugger run on different machines
539(@pxref{Remote Debugging,, Debugging Remote Programs, gdb, The GNU
540debugger}).
8cf51b2c
GM
541
542@node Debugger Operation
b424697f 543@subsection Debugger Operation
0595bd7e 544@cindex GUD interaction buffer
8cf51b2c 545
0595bd7e
CY
546 The @dfn{GUD interaction buffer} is an Emacs buffer which is used to
547send text commands to a debugger subprocess, and record its output.
548This is the basic interface for interacting with a debugger, used by
549@kbd{M-x gud-gdb} and other commands listed in
550@iftex
551the preceding section.
0ab39399 552@end iftex
0595bd7e
CY
553@ifnottex
554@ref{Starting GUD}.
555@end ifnottex
556The @kbd{M-x gdb} command extends this interface with additional
557specialized buffers for controlling breakpoints, stack frames, and
558other aspects of the debugger state (@pxref{GDB Graphical Interface}).
559
560 The GUD interaction buffer uses a variant of Shell mode, so the
561Emacs commands defined by Shell mode are available (@pxref{Shell
562Mode}). Completion is available for most debugger commands
563(@pxref{Completion}), and you can use the usual Shell mode history
564commands to repeat them.
565@iftex
566See the next section
2785d024 567@end iftex
0595bd7e
CY
568@ifnottex
569@xref{Commands of GUD},
570@end ifnottex
571for special commands that can be used in the GUD interaction buffer.
572
573 As you debug a program, Emacs displays the relevant source files by
574visiting them in Emacs buffers, with an arrow in the left fringe
0be641c0
CY
575indicating the current execution line. (On a text terminal, the arrow
576appears as @samp{=>}, overlaid on the first two text columns.) Moving
577point in such a buffer does not move the arrow. You are free to edit
578these source files, but note that inserting or deleting lines will
579throw off the arrow's positioning, as Emacs has no way to figure out
580which edited source line corresponds to the line reported by the
0595bd7e
CY
581debugger subprocess. To update this information, you typically have
582to recompile and restart the program.
583
584@cindex GUD Tooltip mode
585@cindex mode, GUD Tooltip
586@findex gud-tooltip-mode
8cf51b2c 587@vindex gud-tooltip-echo-area
0595bd7e
CY
588 GUD Tooltip mode is a global minor mode that adds tooltip support to
589GUD. To toggle this mode, type @kbd{M-x gud-tooltip-mode}. It is
590disabled by default. If enabled, you can move the mouse cursor over a
591variable to show its value in a tooltip (@pxref{Tooltips}); this takes
592effect in the GUD interaction buffer, and in all source buffers with
593major modes listed in the variable @code{gud-tooltip-modes}. If the
594variable @code{gud-tooltip-echo-area} is non-@code{nil}, values are
595shown in the echo area instead of a tooltip.
596
597 When using GUD Tooltip mode with @kbd{M-x gud-gdb}, you should note
598that displaying an expression's value in GDB can sometimes expand a
599macro, potentially causing side effects in the debugged program. If
600you use the @kbd{M-x gdb} interface, this problem does not occur, as
601there is special code to avoid side-effects; furthermore, you can
602display macro definitions associated with an identifier when the
603program is not executing.
8cf51b2c
GM
604
605@node Commands of GUD
b424697f 606@subsection Commands of GUD
8cf51b2c 607
0595bd7e
CY
608 GUD provides commands for setting and clearing breakpoints,
609selecting stack frames, and stepping through the program.
8cf51b2c
GM
610
611@table @kbd
612@item C-x @key{SPC}
613@kindex C-x SPC
614Set a breakpoint on the source line that point is on.
615@end table
616
0595bd7e
CY
617 @kbd{C-x @key{SPC}} (@code{gud-break}), when called in a source
618buffer, sets a debugger breakpoint on the current source line. This
619command is available only after starting GUD. If you call it in a
620buffer that is not associated with any debugger subprocess, it signals
621a error.
622
8cf51b2c 623@kindex C-x C-a @r{(GUD)}
0595bd7e
CY
624 The following commands are available both in the GUD interaction
625buffer and globally, but with different key bindings. The keys
8cf51b2c 626starting with @kbd{C-c} are available only in the GUD interaction
0595bd7e
CY
627buffer, while those starting with @kbd{C-x C-a} are available
628globally. Some of these commands are also available via the tool bar;
629some are not supported by certain debuggers.
8cf51b2c
GM
630
631@table @kbd
632@item C-c C-l
633@kindex C-c C-l @r{(GUD)}
634@itemx C-x C-a C-l
635@findex gud-refresh
0595bd7e
CY
636Display, in another window, the last source line referred to in the
637GUD interaction buffer (@code{gud-refresh}).
8cf51b2c
GM
638
639@item C-c C-s
640@kindex C-c C-s @r{(GUD)}
641@itemx C-x C-a C-s
642@findex gud-step
0595bd7e
CY
643Execute the next single line of code (@code{gud-step}). If the line
644contains a function call, execution stops after entering the called
645function.
8cf51b2c
GM
646
647@item C-c C-n
648@kindex C-c C-n @r{(GUD)}
649@itemx C-x C-a C-n
650@findex gud-next
0595bd7e
CY
651Execute the next single line of code, stepping across function calls
652without stopping inside the functions (@code{gud-next}).
8cf51b2c
GM
653
654@item C-c C-i
655@kindex C-c C-i @r{(GUD)}
656@itemx C-x C-a C-i
657@findex gud-stepi
658Execute a single machine instruction (@code{gud-stepi}).
659
660@item C-c C-p
661@kindex C-c C-p @r{(GUD)}
662@itemx C-x C-a C-p
663@findex gud-print
664Evaluate the expression at point (@code{gud-print}). If Emacs
665does not print the exact expression that you want, mark it as a region
666first.
667
668@need 3000
669@item C-c C-r
670@kindex C-c C-r @r{(GUD)}
671@itemx C-x C-a C-r
672@findex gud-cont
673Continue execution without specifying any stopping point. The program
674will run until it hits a breakpoint, terminates, or gets a signal that
675the debugger is checking for (@code{gud-cont}).
676
677@need 1000
678@item C-c C-d
679@kindex C-c C-d @r{(GUD)}
680@itemx C-x C-a C-d
681@findex gud-remove
682Delete the breakpoint(s) on the current source line, if any
683(@code{gud-remove}). If you use this command in the GUD interaction
684buffer, it applies to the line where the program last stopped.
685
686@item C-c C-t
687@kindex C-c C-t @r{(GUD)}
688@itemx C-x C-a C-t
689@findex gud-tbreak
690Set a temporary breakpoint on the current source line, if any
691(@code{gud-tbreak}). If you use this command in the GUD interaction
692buffer, it applies to the line where the program last stopped.
693
694@item C-c <
695@kindex C-c < @r{(GUD)}
696@itemx C-x C-a <
697@findex gud-up
698Select the next enclosing stack frame (@code{gud-up}). This is
699equivalent to the GDB command @samp{up}.
700
701@item C-c >
702@kindex C-c > @r{(GUD)}
703@itemx C-x C-a >
704@findex gud-down
705Select the next inner stack frame (@code{gud-down}). This is
706equivalent to the GDB command @samp{down}.
707
708@item C-c C-u
709@kindex C-c C-u @r{(GUD)}
710@itemx C-x C-a C-u
711@findex gud-until
712Continue execution to the current line (@code{gud-until}). The
713program will run until it hits a breakpoint, terminates, gets a signal
714that the debugger is checking for, or reaches the line on which the
715cursor currently sits.
716
717@item C-c C-f
718@kindex C-c C-f @r{(GUD)}
719@itemx C-x C-a C-f
720@findex gud-finish
721Run the program until the selected stack frame returns or
722stops for some other reason (@code{gud-finish}).
723@end table
724
725 If you are using GDB, these additional key bindings are available:
726
727@table @kbd
728@item C-x C-a C-j
729@kindex C-x C-a C-j @r{(GUD)}
730@findex gud-jump
731Only useful in a source buffer, @code{gud-jump} transfers the
732program's execution point to the current line. In other words, the
733next line that the program executes will be the one where you gave the
734command. If the new execution line is in a different function from
735the previously one, GDB prompts for confirmation since the results may
736be bizarre. See the GDB manual entry regarding @code{jump} for
737details.
738
739@item @key{TAB}
740@kindex TAB @r{(GUD)}
741@findex gud-gdb-complete-command
742With GDB, complete a symbol name (@code{gud-gdb-complete-command}).
743This key is available only in the GUD interaction buffer.
744@end table
745
746 These commands interpret a numeric argument as a repeat count, when
747that makes sense.
748
749 Because @key{TAB} serves as a completion command, you can't use it to
750enter a tab as input to the program you are debugging with GDB.
751Instead, type @kbd{C-q @key{TAB}} to enter a tab.
752
753@node GUD Customization
b424697f 754@subsection GUD Customization
8cf51b2c
GM
755
756@vindex gdb-mode-hook
757@vindex dbx-mode-hook
758@vindex sdb-mode-hook
759@vindex xdb-mode-hook
760@vindex perldb-mode-hook
761@vindex pdb-mode-hook
762@vindex jdb-mode-hook
0595bd7e
CY
763 On startup, GUD runs one of the following hooks:
764@code{gdb-mode-hook}, if you are using GDB; @code{dbx-mode-hook}, if
765you are using DBX; @code{sdb-mode-hook}, if you are using SDB;
766@code{xdb-mode-hook}, if you are using XDB; @code{perldb-mode-hook},
767for Perl debugging mode; @code{pdb-mode-hook}, for PDB;
768@code{jdb-mode-hook}, for JDB. @xref{Hooks}.
769
770 The @code{gud-def} Lisp macro (@pxref{Defining Macros,,, elisp, the
771Emacs Lisp Reference Manual}) provides a convenient way to define an
772Emacs command that sends a particular command string to the debugger,
773and set up a key binding for in the GUD interaction buffer:
8cf51b2c
GM
774
775@findex gud-def
776@example
777(gud-def @var{function} @var{cmdstring} @var{binding} @var{docstring})
778@end example
779
780 This defines a command named @var{function} which sends
781@var{cmdstring} to the debugger process, and gives it the documentation
782string @var{docstring}. You can then use the command @var{function} in any
783buffer. If @var{binding} is non-@code{nil}, @code{gud-def} also binds
784the command to @kbd{C-c @var{binding}} in the GUD buffer's mode and to
785@kbd{C-x C-a @var{binding}} generally.
786
787 The command string @var{cmdstring} may contain certain
788@samp{%}-sequences that stand for data to be filled in at the time
789@var{function} is called:
790
791@table @samp
792@item %f
793The name of the current source file. If the current buffer is the GUD
794buffer, then the ``current source file'' is the file that the program
795stopped in.
796
797@item %l
798The number of the current source line. If the current buffer is the GUD
799buffer, then the ``current source line'' is the line that the program
800stopped in.
801
802@item %e
803In transient-mark-mode the text in the region, if it is active.
804Otherwise the text of the C lvalue or function-call expression at or
805adjacent to point.
806
807@item %a
808The text of the hexadecimal address at or adjacent to point.
809
810@item %p
811The numeric argument of the called function, as a decimal number. If
812the command is used without a numeric argument, @samp{%p} stands for the
813empty string.
814
815If you don't use @samp{%p} in the command string, the command you define
816ignores any numeric argument.
817
818@item %d
819The name of the directory of the current source file.
820
821@item %c
822Fully qualified class name derived from the expression surrounding point
823(jdb only).
824@end table
825
826@node GDB Graphical Interface
827@subsection GDB Graphical Interface
828
0595bd7e
CY
829 The command @kbd{M-x gdb} starts GDB in an IDE-like interface, with
830specialized buffers for controlling breakpoints, stack frames, and
831other aspects of the debugger state. It also provides additional ways
832to control the debugging session with the mouse, such as clicking in
833the fringe of a source buffer to set a breakpoint there.
8cf51b2c
GM
834
835@vindex gud-gdb-command-name
0595bd7e
CY
836 To run GDB using just the GUD interaction buffer interface, without
837these additional features, use @kbd{M-x gud-gdb} (@pxref{Starting
838GUD}). You must use this if you want to debug multiple programs
839within one Emacs session, as that is currently unsupported by @kbd{M-x
840gdb}.
841
842 Internally, @kbd{M-x gdb} informs GDB that its ``screen size'' is
843unlimited; for correct operation, you must not change GDB's screen
844height and width values during the debugging session.
8cf51b2c
GM
845
846@menu
691cf4a0 847* GDB User Interface Layout:: Control the number of displayed buffers.
8cf51b2c
GM
848* Source Buffers:: Use the mouse in the fringe/margin to
849 control your program.
850* Breakpoints Buffer:: A breakpoint control panel.
691cf4a0 851* Threads Buffer:: Displays your threads.
8cf51b2c 852* Stack Buffer:: Select a frame from the call stack.
0595bd7e 853* Other GDB Buffers:: Other buffers for controlling the GDB state.
8cf51b2c 854* Watch Expressions:: Monitor variable values in the speedbar.
691cf4a0 855* Multithreaded Debugging:: Debugging programs with several threads.
8cf51b2c
GM
856@end menu
857
691cf4a0 858@node GDB User Interface Layout
8cf51b2c
GM
859@subsubsection GDB User Interface Layout
860@cindex GDB User Interface layout
861
862@vindex gdb-many-windows
0595bd7e
CY
863 If the variable @code{gdb-many-windows} is @code{nil} (the default),
864@kbd{M-x gdb} normally displays only the GUD interaction buffer.
8cf51b2c 865However, if the variable @code{gdb-show-main} is also non-@code{nil},
0595bd7e
CY
866it starts with two windows: one displaying the GUD interaction buffer,
867and the other showing the source for the @code{main} function of the
868program you are debugging.
8cf51b2c
GM
869
870 If @code{gdb-many-windows} is non-@code{nil}, then @kbd{M-x gdb}
871displays the following frame layout:
872
873@smallexample
874@group
875+--------------------------------+--------------------------------+
0595bd7e 876| GUD interaction buffer | Locals/Registers buffer |
8cf51b2c
GM
877|--------------------------------+--------------------------------+
878| Primary Source buffer | I/O buffer for debugged pgm |
879|--------------------------------+--------------------------------+
0df6175c 880| Stack buffer | Breakpoints/Threads buffer |
8cf51b2c
GM
881+--------------------------------+--------------------------------+
882@end group
883@end smallexample
884
885 However, if @code{gdb-use-separate-io-buffer} is @code{nil}, the I/O
886buffer does not appear and the primary source buffer occupies the full
887width of the frame.
888
889@findex gdb-restore-windows
8cf51b2c 890@findex gdb-many-windows
0595bd7e
CY
891 If you ever change the window layout, you can restore the ``many
892windows'' layout by typing @kbd{M-x gdb-restore-windows}. To toggle
893between the many windows layout and a simple layout with just the GUD
894interaction buffer and a source file, type @kbd{M-x gdb-many-windows}.
8cf51b2c
GM
895
896 You may also specify additional GDB-related buffers to display,
897either in the same frame or a different one. Select the buffers you
0595bd7e
CY
898want by typing @code{M-x gdb-display-@var{buffertype}-buffer} or
899@code{M-x gdb-frame-@var{buffertype}-buffer}, where @var{buffertype}
900is the relevant buffer type, such as @samp{breakpoints}. You can do
901the same with the menu bar, with the @samp{GDB-Windows} and
902@samp{GDB-Frames} sub-menus of the @samp{GUD} menu.
903
904 When you finish debugging, kill the GUD interaction buffer with
905@kbd{C-x k}, which will also kill all the buffers associated with the
906session. However you need not do this if, after editing and
907re-compiling your source code within Emacs, you wish to continue
908debugging. When you restart execution, GDB automatically finds the
909new executable. Keeping the GUD interaction buffer has the advantage
910of keeping the shell history as well as GDB's breakpoints. You do
911need to check that the breakpoints in recently edited source files are
912still in the right places.
8cf51b2c
GM
913
914@node Source Buffers
915@subsubsection Source Buffers
0595bd7e 916@cindex fringes, for debugging
8cf51b2c 917
0595bd7e
CY
918@table @asis
919@item @kbd{Mouse-1} (in fringe)
920Set or clear a breakpoint on that line.
8cf51b2c 921
0595bd7e
CY
922@item @kbd{C-Mouse-1} (in fringe)
923Enable or disable a breakpoint on that line.
8cf51b2c 924
0595bd7e
CY
925@item @kbd{Mouse-3} (in fringe)
926Continue execution to that line.
8cf51b2c 927
0595bd7e
CY
928@item @kbd{C-Mouse-3} (in fringe)
929Jump to that line.
8cf51b2c
GM
930@end table
931
0595bd7e
CY
932 On a graphical display, you can click @kbd{Mouse-1} in the fringe of
933a source buffer, to set a breakpoint on that line (@pxref{Fringes}).
934A red dot appears in the fringe, where you clicked. If a breakpoint
935already exists there, the click removes it. A @kbd{C-Mouse-1} click
936enables or disables an existing breakpoint; a breakpoint that is
937disabled, but not unset, is indicated by a gray dot.
938
0be641c0 939 On a text terminal, or when fringes are disabled, enabled
0595bd7e
CY
940breakpoints are indicated with a @samp{B} character in the left margin
941of the window. Disabled breakpoints are indicated with @samp{b}.
942(The margin is only displayed if a breakpoint is present.)
943
944 A solid arrow in the left fringe of a source buffer indicates the
945line of the innermost frame where the debugged program has stopped. A
946hollow arrow indicates the current execution line of a higher-level
947frame. If you drag the arrow in the fringe with @kbd{Mouse-1}, that
948causes execution to advance to the line where you release the button.
949Alternatively, you can click @kbd{Mouse-3} in the fringe to advance to
950that line. You can click @kbd{C-Mouse-3} in the fringe to jump to
951that line without executing the intermediate lines. This command
952allows you to go backwards, which can be useful for running through
953code that has already executed, in order to examine its execution in
954more detail.
8cf51b2c
GM
955
956@node Breakpoints Buffer
957@subsubsection Breakpoints Buffer
958
0595bd7e
CY
959 The GDB Breakpoints buffer shows the breakpoints, watchpoints and
960catchpoints in the debugger session. @xref{Breakpoints,,, gdb, The
961GNU debugger}. It provides the following commands, which mostly apply
962to the @dfn{current breakpoint} (the breakpoint which point is on):
8cf51b2c
GM
963
964@table @kbd
965@item @key{SPC}
0595bd7e 966@kindex SPC @r{(GDB Breakpoints buffer)}
8cf51b2c 967@findex gdb-toggle-breakpoint
0595bd7e
CY
968Enable/disable current breakpoint (@code{gdb-toggle-breakpoint}). On
969a graphical display, this changes the color of the dot in the fringe
970of the source buffer at that line. The dot is red when the breakpoint
971is enabled, and gray when it is disabled.
8cf51b2c
GM
972
973@item D
0595bd7e 974@kindex D @r{(GDB Breakpoints buffer)}
8cf51b2c
GM
975@findex gdb-delete-breakpoint
976Delete the current breakpoint (@code{gdb-delete-breakpoint}).
977
978@item @key{RET}
0595bd7e 979@kindex RET @r{(GDB Breakpoints buffer)}
8cf51b2c
GM
980@findex gdb-goto-breakpoint
981Visit the source line for the current breakpoint
982(@code{gdb-goto-breakpoint}).
983
984@item Mouse-2
0595bd7e 985@kindex Mouse-2 @r{(GDB Breakpoints buffer)}
8cf51b2c
GM
986Visit the source line for the breakpoint you click on.
987@end table
988
691cf4a0 989@vindex gdb-show-threads-by-default
0595bd7e
CY
990 When @code{gdb-many-windows} is non-@code{nil}, the GDB Breakpoints
991buffer shares its window with the GDB Threads buffer. To switch from
992one to the other click with @kbd{Mouse-1} on the relevant button in
993the header line. If @code{gdb-show-threads-by-default} is
994non-@code{nil}, the GDB Threads buffer is the one shown by default.
691cf4a0
NR
995
996@node Threads Buffer
997@subsubsection Threads Buffer
998
999@findex gdb-select-thread
0595bd7e
CY
1000 The GDB Threads buffer displays a summary of the threads in the
1001debugged program. @xref{Threads, Threads, Debugging programs with
1002multiple threads, gdb, The GNU debugger}. To select a thread, move
1003point there and type @key{RET} (@code{gdb-select-thread}), or click on
1004it with @kbd{Mouse-2}. This also displays the associated source
1005buffer, and updates the contents of the other GDB buffers.
691cf4a0
NR
1006
1007 You can customize variables under @code{gdb-buffers} group to select
0595bd7e 1008fields included in GDB Threads buffer.
691cf4a0
NR
1009
1010@table @code
1011@item gdb-thread-buffer-verbose-names
1012@vindex gdb-thread-buffer-verbose-names
0595bd7e 1013Show long thread names like @samp{Thread 0x4e2ab70 (LWP 1983)}.
691cf4a0
NR
1014
1015@item gdb-thread-buffer-arguments
1016@vindex gdb-thread-buffer-arguments
0595bd7e 1017Show arguments of thread top frames.
691cf4a0
NR
1018
1019@item gdb-thread-buffer-locations
1020@vindex gdb-thread-buffer-locations
0595bd7e 1021Show file information or library names.
691cf4a0
NR
1022
1023@item gdb-thread-buffer-addresses
1024@vindex gdb-thread-buffer-addresses
1025Show addresses for thread frames in threads buffer.
1026@end table
1027
0595bd7e
CY
1028 To view information for several threads simultaneously, use the
1029following commands from the GDB Threads buffer.
691cf4a0
NR
1030
1031@table @kbd
1032@item d
1033@kindex d @r{(GDB threads buffer)}
1034@findex gdb-display-disassembly-for-thread
0595bd7e
CY
1035Display disassembly buffer for the thread at current line
1036(@code{gdb-display-disassembly-for-thread}).
691cf4a0
NR
1037
1038@item f
1039@kindex f @r{(GDB threads buffer)}
1040@findex gdb-display-stack-for-thread
0595bd7e 1041Display the GDB Stack buffer for the thread at current line
691cf4a0
NR
1042(@code{gdb-display-stack-for-thread}).
1043
1044@item l
1045@kindex l @r{(GDB threads buffer)}
1046@findex gdb-display-locals-for-thread
0595bd7e 1047Display the GDB Locals buffer for the thread at current line
691cf4a0
NR
1048(@code{gdb-display-locals-for-thread}).
1049
1050@item r
1051@kindex r @r{(GDB threads buffer)}
1052@findex gdb-display-registers-for-thread
0595bd7e 1053Display the GDB Registers buffer for the thread at current line
691cf4a0
NR
1054(@code{gdb-display-registers-for-thread}).
1055@end table
1056
0595bd7e
CY
1057@noindent
1058Their upper-case counterparts, @kbd{D}, @kbd{F} ,@kbd{L} and @kbd{R},
1059display the corresponding buffer in a new frame.
691cf4a0
NR
1060
1061 When you create a buffer showing information about some specific
1062thread, it becomes bound to that thread and keeps showing actual
0595bd7e
CY
1063information while you debug your program. The mode indicator for each
1064GDB buffer shows the number of thread it is showing information about.
1065The thread number is also included in the buffer name of bound
1066buffers.
691cf4a0 1067
0595bd7e
CY
1068 Further commands are available in the GDB Threads buffer which
1069depend on the mode of GDB that is used for controlling execution of
1070your program. @xref{Multithreaded Debugging}.
95dbaaea 1071
8cf51b2c
GM
1072@node Stack Buffer
1073@subsubsection Stack Buffer
1074
0595bd7e
CY
1075 The GDB Stack buffer displays a @dfn{call stack}, with one line for
1076each of the nested subroutine calls (@dfn{stack frames}) in the
1077debugger session. @xref{Backtrace,, Backtraces, gdb, The GNU
1078debugger}.
8cf51b2c
GM
1079
1080@findex gdb-frames-select
0595bd7e 1081 On graphical displays, the selected stack frame is indicated by an
0be641c0
CY
1082arrow in the fringe. On text terminals, or when fringes are disabled,
1083the selected stack frame is displayed in reverse contrast. To select
1084a stack frame, move point in its line and type @key{RET}
0595bd7e
CY
1085(@code{gdb-frames-select}), or click @kbd{Mouse-2} on it. Doing so
1086also updates the Locals buffer
1087@ifnottex
1088(@pxref{Other GDB Buffers}).
1089@end ifnottex
1090@iftex
1091(described in the next section).
1092@end iftex
8cf51b2c 1093
691cf4a0 1094@node Other GDB Buffers
0595bd7e 1095@subsubsection Other GDB Buffers
8cf51b2c
GM
1096
1097@table @asis
8cf51b2c 1098@item Locals Buffer
0595bd7e
CY
1099This buffer displays the values of local variables of the current
1100frame for simple data types (@pxref{Frame Info, Frame Info,
0df6175c 1101Information on a frame, gdb, The GNU debugger}). Press @key{RET} or
8cf51b2c
GM
1102click @kbd{Mouse-2} on the value if you want to edit it.
1103
1104Arrays and structures display their type only. With GDB 6.4 or later,
0595bd7e
CY
1105you can examine the value of the local variable at point by typing
1106@key{RET}, or with a @kbd{Mouse-2} click. With earlier versions of
1107GDB, use @key{RET} or @kbd{Mouse-2} on the type description
8cf51b2c
GM
1108(@samp{[struct/union]} or @samp{[array]}). @xref{Watch Expressions}.
1109
1110@item Registers Buffer
1111@findex toggle-gdb-all-registers
0595bd7e 1112This buffer displays the values held by the registers
8cf51b2c 1113(@pxref{Registers,,, gdb, The GNU debugger}). Press @key{RET} or
0595bd7e
CY
1114click @kbd{Mouse-2} on a register if you want to edit its value. With
1115GDB 6.4 or later, recently changed register values display with
1116@code{font-lock-warning-face}.
8cf51b2c 1117
0df6175c
CY
1118@item Assembler Buffer
1119The assembler buffer displays the current frame as machine code. An
8cf51b2c
GM
1120arrow points to the current instruction, and you can set and remove
1121breakpoints as in a source buffer. Breakpoint icons also appear in
1122the fringe or margin.
1123
8cf51b2c
GM
1124@item Memory Buffer
1125The memory buffer lets you examine sections of program memory
1126(@pxref{Memory, Memory, Examining memory, gdb, The GNU debugger}).
1127Click @kbd{Mouse-1} on the appropriate part of the header line to
1128change the starting address or number of data items that the buffer
4a3a621f
NR
1129displays. Alternatively, use @kbd{S} or @kbd{N} respectively. Click
1130@kbd{Mouse-3} on the header line to select the display format or unit
1131size for these data items.
8cf51b2c
GM
1132@end table
1133
691cf4a0 1134When @code{gdb-many-windows} is non-@code{nil}, the locals buffer
0595bd7e
CY
1135shares its window with the registers buffer, just like breakpoints and
1136threads buffers. To switch from one to the other, click with
0df6175c 1137@kbd{Mouse-1} on the relevant button in the header line.
1a19cb6a 1138
8cf51b2c
GM
1139@node Watch Expressions
1140@subsubsection Watch Expressions
1141@cindex Watching expressions in GDB
1142
1143@findex gud-watch
1144@kindex C-x C-a C-w @r{(GUD)}
1145 If you want to see how a variable changes each time your program
1146stops, move point into the variable name and click on the watch icon
1147in the tool bar (@code{gud-watch}) or type @kbd{C-x C-a C-w}. If you
1148specify a prefix argument, you can enter the variable name in the
1149minibuffer.
1150
0595bd7e
CY
1151 Each watch expression is displayed in the speedbar
1152(@pxref{Speedbar}). Complex data types, such as arrays, structures
1153and unions are represented in a tree format. Leaves and simple data
1154types show the name of the expression and its value and, when the
1155speedbar frame is selected, display the type as a tooltip. Higher
1156levels show the name, type and address value for pointers and just the
1157name and type otherwise. Root expressions also display the frame
1158address as a tooltip to help identify the frame in which they were
1159defined.
8cf51b2c
GM
1160
1161 To expand or contract a complex data type, click @kbd{Mouse-2} or
1162press @key{SPC} on the tag to the left of the expression. Emacs asks
1163for confirmation before expanding the expression if its number of
1164immediate children exceeds the value of the variable
1165@code{gdb-max-children}.
1166
1167@kindex D @r{(GDB speedbar)}
1168@findex gdb-var-delete
1169 To delete a complex watch expression, move point to the root
1170expression in the speedbar and type @kbd{D} (@code{gdb-var-delete}).
1171
1172@kindex RET @r{(GDB speedbar)}
1173@findex gdb-edit-value
1174 To edit a variable with a simple data type, or a simple element of a
1175complex data type, move point there in the speedbar and type @key{RET}
1176(@code{gdb-edit-value}). Or you can click @kbd{Mouse-2} on a value to
1177edit it. Either way, this reads the new value using the minibuffer.
1178
1179@vindex gdb-show-changed-values
1180 If you set the variable @code{gdb-show-changed-values} to
1181non-@code{nil} (the default value), Emacs uses
1182@code{font-lock-warning-face} to highlight values that have recently
1183changed and @code{shadow} face to make variables which have gone out of
1184scope less noticeable. When a variable goes out of scope you can't
1185edit its value.
1186
975900f9 1187@vindex gdb-delete-out-of-scope
32ef39ff
NR
1188 If the variable @code{gdb-delete-out-of-scope} is non-@code{nil}
1189(the default value), Emacs automatically deletes watch expressions
1190which go out of scope. Sometimes, when re-entering the same function,
de933755
CY
1191it may be useful to set this value to @code{nil} so that you don't
1192need to recreate the watch expression.
975900f9 1193
8cf51b2c
GM
1194@vindex gdb-use-colon-colon-notation
1195 If the variable @code{gdb-use-colon-colon-notation} is
1196non-@code{nil}, Emacs uses the @samp{@var{function}::@var{variable}}
1197format. This allows the user to display watch expressions which share
1198the same variable name. The default value is @code{nil}.
1199
1200@vindex gdb-speedbar-auto-raise
1201To automatically raise the speedbar every time the display of watch
1202expressions updates, set @code{gdb-speedbar-auto-raise} to
1203non-@code{nil}. This can be useful if you are debugging with a full
1204screen Emacs frame.
1205
691cf4a0 1206@node Multithreaded Debugging
0595bd7e 1207@subsubsection Multithreaded Debugging
691cf4a0 1208@cindex Multithreaded debugging in GDB
691cf4a0
NR
1209@cindex Non-stop debugging in GDB
1210
0595bd7e
CY
1211 In GDB's @dfn{all-stop mode}, whenever your program stops, all
1212execution threads stop. Likewise, whenever you restart the program,
1213all threads start executing. @xref{All-Stop Mode, , All-Stop Mode,
1214gdb, The GNU debugger}. For some multi-threaded targets, GDB supports
1215a further mode of operation, called @dfn{non-stop mode}, in which you
1216can examine stopped program threads in the debugger while other
1217threads continue to execute freely. @xref{Non-Stop Mode, , Non-Stop
1218Mode, gdb, The GNU debugger}. Versions of GDB prior to 7.0 do not
1219support non-stop mode, and it does not work on all targets.
691cf4a0
NR
1220
1221@vindex gdb-non-stop-setting
0595bd7e
CY
1222 The variable @code{gdb-non-stop-setting} determines whether Emacs
1223runs GDB in all-stop mode or non-stop mode. The default is @code{t},
1224which means it tries to use non-stop mode if that is available. If
1225you change the value to @code{nil}, or if non-stop mode is
1226unavailable, Emacs runs GDB in all-stop mode. The variable takes
1227effect when Emacs begins a debugging session; if you change its value,
1228you should restart any active debugging session.
691cf4a0
NR
1229
1230@vindex gdb-switch-when-another-stopped
0595bd7e
CY
1231 When a thread stops in non-stop mode, Emacs usually switches to that
1232thread. If you don't want Emacs to do this switch if another stopped
1233thread is already selected, change the variable
1234@code{gdb-switch-when-another-stopped} to @code{nil}.
691cf4a0
NR
1235
1236@vindex gdb-switch-reasons
0595bd7e
CY
1237 Emacs can decide whether or not to switch to the stopped thread
1238depending on the reason which caused the stop. Customize the variable
1239@code{gdb-switch-reasons} to select the stop reasons which will cause
1240a thread switch.
691cf4a0
NR
1241
1242@vindex gdb-stopped-hooks
0595bd7e 1243 The variable @code{gdb-stopped-hooks} allows you to execute your
691cf4a0
NR
1244functions whenever some thread stops.
1245
1246 In non-stop mode, you can switch between different modes for GUD
1247execution control commands.
1248
1249@vindex gdb-gud-control-all-threads
1250@table @dfn
1251@item Non-stop/A
1252
0595bd7e 1253 When @code{gdb-gud-control-all-threads} is @code{t} (the default
691cf4a0
NR
1254value), interruption and continuation commands apply to all threads,
1255so you can halt or continue all your threads with one command using
1256@code{gud-stop-subjob} and @code{gud-cont}, respectively. The
1257@samp{Go} button is shown on the toolbar when at least one thread is
1258stopped, whereas @samp{Stop} button is shown when at least one thread
1259is running.
1260
1261@item Non-stop/T
1262
1263When @code{gdb-gud-control-all-threads} is @code{nil}, only the
1264current thread is stopped/continued. @samp{Go} and @samp{Stop}
1265buttons on the GUD toolbar are shown depending on the state of current
1266thread.
1267@end table
1268
1269You can change the current value of @code{gdb-gud-control-all-threads}
1270from the tool bar or from @samp{GUD->GDB-MI} menu.
1271
1272 Stepping commands always apply to the current thread.
1273
691cf4a0
NR
1274 In non-stop mode, you can interrupt/continue your threads without
1275selecting them. Hitting @kbd{i} in threads buffer interrupts thread
1276under point, @kbd{c} continues it, @kbd{s} steps through. More such
1277commands may be added in the future.
1278
0595bd7e
CY
1279 Note that when you interrupt a thread, it stops with the
1280@samp{signal received} reason. If that reason is included in your
691cf4a0
NR
1281@code{gdb-switch-reasons} (it is by default), Emacs will switch to
1282that thread.
8d6bb99e 1283
8cf51b2c
GM
1284@node Executing Lisp
1285@section Executing Lisp Expressions
1286
29eabb8e
CY
1287 Emacs has major modes for several variants of Lisp. They use the
1288same editing commands as other programming language modes
1289(@pxref{Programs}). In addition, they provide special commands for
1290executing Lisp expressions.
8cf51b2c
GM
1291
1292@table @asis
29eabb8e
CY
1293@item Emacs Lisp mode
1294The mode for editing Emacs Lisp source files. It defines @kbd{C-M-x}
1295to evaluate the current top-level Lisp expression. @xref{Lisp Eval}.
1296
8cf51b2c 1297@item Lisp Interaction mode
29eabb8e
CY
1298The mode for an interactive Emacs Lisp session. It defines @kbd{C-j}
1299to evaluate the expression before point and insert its value in the
8cf51b2c 1300buffer. @xref{Lisp Interaction}.
29eabb8e 1301
8cf51b2c
GM
1302@item Lisp mode
1303The mode for editing source files of programs that run in Lisps other
29eabb8e
CY
1304than Emacs Lisp. It defines @kbd{C-M-x} to evaluate the current
1305top-level expression in an external Lisp. @xref{External Lisp}.
1306
8cf51b2c 1307@item Inferior Lisp mode
29eabb8e
CY
1308The mode for an interactive session with an external Lisp which is
1309being run as a subprocess (or @dfn{inferior process}) of Emacs.
1310@ifnottex
1311@xref{External Lisp}.
1312@end ifnottex
1313
8cf51b2c 1314@item Scheme mode
29eabb8e
CY
1315Like Lisp mode, but for Scheme programs.
1316
8cf51b2c 1317@item Inferior Scheme mode
29eabb8e 1318Like Inferior Lisp mode, but for Scheme.
8cf51b2c
GM
1319@end table
1320
8cf51b2c
GM
1321@node Lisp Libraries
1322@section Libraries of Lisp Code for Emacs
1323@cindex libraries
1324@cindex loading Lisp code
1325
29eabb8e
CY
1326 Emacs Lisp code is stored in files whose names conventionally end in
1327@file{.el}. Such files are automatically visited in Emacs Lisp mode.
8cf51b2c
GM
1328
1329@cindex byte code
1330 Emacs Lisp code can be compiled into byte-code, which loads faster,
29eabb8e
CY
1331takes up less space, and executes faster. By convention, compiled
1332Emacs Lisp code goes in a separate file whose name ends in
1333@samp{.elc}. For example, the compiled code for @file{foo.el} goes in
1334@file{foo.elc}. @xref{Byte Compilation,, Byte Compilation, elisp, the
1335Emacs Lisp Reference Manual}.
8cf51b2c
GM
1336
1337@findex load-file
29eabb8e
CY
1338 To @dfn{load} an Emacs Lisp file, type @kbd{M-x load-file}. This
1339command reads a file name using the minibuffer, and executes the
1340contents of that file as Emacs Lisp code. It is not necessary to
1341visit the file first; this command reads the file directly from disk,
1342not from an existing Emacs buffer.
8cf51b2c
GM
1343
1344@findex load
1345@findex load-library
29eabb8e
CY
1346@cindex load path for Emacs Lisp
1347 If an Emacs Lisp file is installed in the Emacs Lisp @dfn{load path}
1348(defined below), you can load it by typing @kbd{M-x load-library},
1349instead of using @kbd{M-x load-file}. The @kbd{M-x load-library}
1350command prompts for a @dfn{library name} rather than a file name; it
1351searches through each directory in the Emacs Lisp load path, trying to
1352find a file matching that library name. If the library name is
1353@samp{@var{foo}}, it tries looking for files named
1354@file{@var{foo}.elc}, @file{@var{foo}.el}, and lastly just
1355@file{@var{foo}}; the first one found is loaded. This command prefers
1356@file{.elc} files over @file{.el} files because compiled files load
1357and run faster. If it finds that @file{@var{lib}.el} is newer than
1358@file{@var{lib}.elc}, it issues a warning, in case someone made
1359changes to the @file{.el} file and forgot to recompile it, but loads
1360the @file{.elc} file anyway. (Due to this behavior, you can save
1361unfinished edits to Emacs Lisp source files, and not recompile until
1362your changes are ready for use.)
1363
1364 Emacs Lisp programs usually load Emacs Lisp files using the
1365@code{load} function. This is similar to @code{load-library}, but is
1366lower-level and accepts additional arguments. @xref{How Programs Do
1367Loading,,, elisp, the Emacs Lisp Reference Manual}.
8cf51b2c 1368
8cf51b2c 1369@vindex load-path
29eabb8e
CY
1370 The Emacs Lisp load path is specified by the variable
1371@code{load-path}. Its value should be a list of directory names
1372(strings). These directories are searched, in the specified order, by
1373the @kbd{M-x load-library} command, the lower-level @code{load}
1374function, and other Emacs functions that find Emacs Lisp libraries. A
1375list entry in @code{load-path} can also have the special value
1376@code{nil}, which stands for the current default directory, but it is
1377almost always a bad idea to use this. (If you find yourself wishing
f3ed4f26 1378that @code{nil} were in the list, most likely what you really want is
29eabb8e 1379to use @kbd{M-x load-file}.)
1557ef4f
CY
1380
1381 The default value of @code{load-path} is a list of directories where
8cf51b2c 1382the Lisp code for Emacs itself is stored. If you have libraries of
29eabb8e
CY
1383your own in another directory, you can add that directory to the load
1384path. Unlike most other variables described in this manual,
1385@code{load-path} cannot be changed via the Customize interface
1386(@pxref{Easy Customization}), but you can add a directory to it by
1387putting a line like this in your init file (@pxref{Init File}):
1557ef4f
CY
1388
1389@example
29eabb8e 1390(add-to-list 'load-path "/path/to/my/lisp/library")
1557ef4f 1391@end example
8cf51b2c
GM
1392
1393@cindex autoload
29eabb8e
CY
1394 Some commands are @dfn{autoloaded}: when you run them, Emacs
1395automatically loads the associated library first. For instance, the
1396@kbd{M-x compile} command (@pxref{Compilation}) is autoloaded; if you
1397call it, Emacs automatically loads the @code{compile} library first.
1398In contrast, the command @kbd{M-x recompile} is not autoloaded, so it
1399is unavailable until you load the @code{compile} library.
8cf51b2c
GM
1400
1401@vindex load-dangerous-libraries
1402@cindex Lisp files byte-compiled by XEmacs
1403 By default, Emacs refuses to load compiled Lisp files which were
1404compiled with XEmacs, a modified versions of Emacs---they can cause
1405Emacs to crash. Set the variable @code{load-dangerous-libraries} to
1406@code{t} if you want to try loading them.
1407
1408@node Lisp Eval
1409@section Evaluating Emacs Lisp Expressions
29eabb8e
CY
1410@cindex Emacs Lisp mode
1411@cindex mode, Emacs Lisp
8cf51b2c
GM
1412
1413@findex emacs-lisp-mode
29eabb8e
CY
1414 Emacs Lisp mode is the major mode for editing Emacs Lisp. Its mode
1415command is @kbd{M-x emacs-lisp-mode}.
8cf51b2c 1416
29eabb8e
CY
1417 Emacs provides several commands for evaluating Emacs Lisp
1418expressions. You can use these commands in Emacs Lisp mode, to test
1419your Emacs Lisp code as it is being written. For example, after
1420re-writing a function, you can evaluate the function definition to
1421make it take effect for subsequent function calls. These commands are
1422also available globally, and can be used outside Emacs Lisp mode.
1423
1424@table @asis
1425@item @kbd{M-:}
1426Read a single Emacs Lisp expression in the minibuffer, evaluate it,
1427and print the value in the echo area (@code{eval-expression}).
1428@item @kbd{C-x C-e}
1429Evaluate the Emacs Lisp expression before point, and print the value
1430in the echo area (@code{eval-last-sexp}).
1431@item @kbd{C-M-x} @r{(in Emacs Lisp mode)}
1432@itemx @kbd{M-x eval-defun}
8cf51b2c
GM
1433Evaluate the defun containing or after point, and print the value in
1434the echo area (@code{eval-defun}).
29eabb8e
CY
1435@item @kbd{M-x eval-region}
1436Evaluate all the Emacs Lisp expressions in the region.
1437@item @kbd{M-x eval-buffer}
1438Evaluate all the Emacs Lisp expressions in the buffer.
8cf51b2c
GM
1439@end table
1440
1441@ifinfo
1442@c This uses ``colon'' instead of a literal `:' because Info cannot
1443@c cope with a `:' in a menu
1444@kindex M-@key{colon}
1445@end ifinfo
1446@ifnotinfo
1447@kindex M-:
1448@end ifnotinfo
1449@findex eval-expression
29eabb8e
CY
1450 @kbd{M-:} (@code{eval-expression}) reads an expression using the
1451minibuffer, and evaluates it. (Before evaluating the expression, the
1452current buffer switches back to the buffer that was current when you
1453typed @kbd{M-:}, not the minibuffer into which you typed the
1454expression.)
8cf51b2c
GM
1455
1456@kindex C-x C-e
1457@findex eval-last-sexp
29eabb8e
CY
1458 The command @kbd{C-x C-e} (@code{eval-last-sexp}) evaluates the
1459Emacs Lisp expression preceding point in the buffer, and displays the
1460value in the echo area. When the result of an evaluation is an
1461integer, you can type @kbd{C-x C-e} a second time to display the value
1462of the integer result in additional formats (octal, hexadecimal, and
1463character).
1464
1465 If @kbd{M-:} or @kbd{C-x C-e} is given a prefix argument, it inserts
1466the value into the current buffer at point, rather than displaying it
1467in the echo area. The argument's value does not matter.
1468
1469@kindex C-M-x @r{(Emacs Lisp mode)}
1470@findex eval-defun
1471 The @code{eval-defun} command is bound to @kbd{C-M-x} in Emacs Lisp
1472mode. It evaluates the top-level Lisp expression containing or
1473following point, and prints the value in the echo area. In this
1474context, a top-level expression is referred to as a ``defun'', but it
1475need not be an actual @code{defun} (function definition). In
1476particular, this command treats @code{defvar} expressions specially.
1477Normally, evaluating a @code{defvar} expression does nothing if the
1478variable it defines already has a value. But this command
1479unconditionally resets the variable to the initial value specified by
1480the @code{defvar}; this is convenient for debugging Emacs Lisp
1481programs. @code{defcustom} and @code{defface} expressions are treated
1482similarly. Note that the other commands documented in this section do
1483not have this special feature.
1484
1485 With a prefix argument, @kbd{C-M-x} instruments the function
1486definition for Edebug, the Emacs Lisp Debugger. @xref{Instrumenting,
1487Instrumenting for Edebug,, elisp, the Emacs Lisp Reference Manual}.
8cf51b2c
GM
1488
1489@findex eval-region
1490@findex eval-buffer
29eabb8e
CY
1491 The command @kbd{M-x eval-region} parses the text of the region as
1492one or more Lisp expressions, evaluating them one by one. @kbd{M-x
1493eval-buffer} is similar but evaluates the entire buffer.
8cf51b2c
GM
1494
1495@vindex eval-expression-print-level
1496@vindex eval-expression-print-length
1497@vindex eval-expression-debug-on-error
29eabb8e
CY
1498 The customizable variables @code{eval-expression-print-level} and
1499@code{eval-expression-print-length} control the maximum depth and
1500length of lists to print in the result of the evaluation commands
1501before abbreviating them. @code{eval-expression-debug-on-error}
1502controls whether evaluation errors invoke the debugger when these
1503commands are used; its default is @code{t}.
8cf51b2c
GM
1504
1505@node Lisp Interaction
1506@section Lisp Interaction Buffers
1507
29eabb8e 1508@findex lisp-interaction-mode
1c64e6ed 1509 When Emacs starts up, it contains a buffer named @file{*scratch*},
29eabb8e
CY
1510which is provided for evaluating Emacs Lisp expressions interactively.
1511Its major mode is Lisp Interaction mode. You can also enable Lisp
1512Interaction mode by typing @kbd{M-x lisp-interaction-mode}.
8cf51b2c 1513
a03334ca
CY
1514@findex eval-print-last-sexp
1515@kindex C-j @r{(Lisp Interaction mode)}
1c64e6ed 1516 In the @file{*scratch*} buffer, and other Lisp Interaction mode
29eabb8e
CY
1517buffers, @kbd{C-j} (@code{eval-print-last-sexp}) evaluates the Lisp
1518expression before point, and inserts the value at point. Thus, as you
1519type expressions into the buffer followed by @kbd{C-j} after each
1520expression, the buffer records a transcript of the evaluated
1521expressions and their values. All other commands in Lisp Interaction
1522mode are the same as in Emacs Lisp mode.
8cf51b2c 1523
be77bd45 1524@vindex initial-scratch-message
1c64e6ed 1525 At startup, the @file{*scratch*} buffer contains a short message, in
be77bd45
CY
1526the form of a Lisp comment, that explains what it is for. This
1527message is controlled by the variable @code{initial-scratch-message},
29eabb8e
CY
1528which should be either a string, or @code{nil} (which means to
1529suppress the message).
8cf51b2c
GM
1530
1531@findex ielm
29eabb8e
CY
1532 An alternative way of evaluating Emacs Lisp expressions
1533interactively is to use Inferior Emacs Lisp mode, which provides an
1534interface rather like Shell mode (@pxref{Shell Mode}) for evaluating
1535Emacs Lisp expressions. Type @kbd{M-x ielm} to create an
1c64e6ed 1536@file{*ielm*} buffer which uses this mode. For more information, see
29eabb8e 1537that command's documentation.
8cf51b2c
GM
1538
1539@node External Lisp
1540@section Running an External Lisp
29eabb8e
CY
1541@cindex Lisp mode
1542@cindex mode, Lisp
1543@cindex Common Lisp
8cf51b2c 1544
29eabb8e
CY
1545 Lisp mode is the major mode for editing programs written in
1546general-purpose Lisp dialects, such as Common Lisp. Its mode command
1547is @kbd{M-x lisp-mode}. Emacs uses Lisp mode automatically for files
1548whose names end in @file{.l}, @file{.lsp}, or @file{.lisp}.
8cf51b2c
GM
1549
1550@findex run-lisp
1551@vindex inferior-lisp-program
1552@kindex C-x C-z
29eabb8e
CY
1553 You can run an external Lisp session as a subprocess or
1554@dfn{inferior process} of Emacs, and pass expressions to it to be
1555evaluated. To begin an external Lisp session, type @kbd{M-x
1556run-lisp}. This runs the program named @command{lisp}, and sets it up
1557so that both input and output go through an Emacs buffer named
1c64e6ed 1558@file{*inferior-lisp*}. To change the name of the Lisp program run by
29eabb8e
CY
1559@kbd{M-x run-lisp}, change the variable @code{inferior-lisp-program}.
1560
1c64e6ed 1561 The major mode for the @file{*lisp*} buffer is Inferior Lisp mode,
29eabb8e
CY
1562which combines the characteristics of Lisp mode and Shell mode
1563(@pxref{Shell Mode}). To send input to the Lisp session, go to the
1c64e6ed 1564end of the @file{*lisp*} buffer and type the input, followed by
29eabb8e
CY
1565@key{RET}. Terminal output from the Lisp session is automatically
1566inserted in the buffer.
8cf51b2c
GM
1567
1568@kindex C-M-x @r{(Lisp mode)}
1569@findex lisp-eval-defun
29eabb8e
CY
1570 When you edit a Lisp program in Lisp mode, you can type @kbd{C-M-x}
1571(@code{lisp-eval-defun}) to send an expression from the Lisp mode
1572buffer to a Lisp session that you had started with @kbd{M-x run-lisp}.
1573The expression sent is the top-level Lisp expression at or following
1574point. The resulting value goes as usual into the
1c64e6ed 1575@file{*inferior-lisp*} buffer. Note that the effect of @kbd{C-M-x} in
29eabb8e
CY
1576Lisp mode is thus very similar to its effect in Emacs Lisp mode
1577(@pxref{Lisp Eval}), except that the expression is sent to a different
1578Lisp environment instead of being evaluated in Emacs.
1579
1580@findex scheme-mode
1581@findex run-scheme
1582@cindex Scheme mode
1583@cindex mode, Scheme
1584@kindex C-M-x @r{(Scheme mode)}
1585 The facilities for editing Scheme code, and for sending expressions
1586to a Scheme subprocess, are very similar. Scheme source files are
1587edited in Scheme mode, which can be explicitly enabled with @kbd{M-x
1588scheme-mode}. You can initiate a Scheme session by typing @kbd{M-x
1589run-scheme} (the buffer for interacting with Scheme is named
1c64e6ed 1590@file{*scheme*}), and send expressions to it by typing @kbd{C-M-x}.