building.texi 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. @node Running, Abbrevs, Programs, Top
  2. @chapter Compiling and Testing Programs
  3. The previous chapter discusses the Emacs commands that are useful for
  4. making changes in programs. This chapter deals with commands that assist
  5. in the larger process of developing and maintaining programs.
  6. @menu
  7. * Compilation:: Compiling programs in languages other than Lisp
  8. (C, Pascal, etc.)
  9. * Modes: Lisp Modes. Various modes for editing Lisp programs, with
  10. different facilities for running the Lisp programs.
  11. * Libraries: Lisp Libraries. Creating Lisp programs to run in Emacs.
  12. * Eval: Lisp Eval. Executing a single Lisp expression in Emacs.
  13. * Debug: Lisp Debug. Debugging Lisp programs running in Emacs.
  14. * Interaction: Lisp Interaction. Executing Lisp in an Emacs buffer.
  15. * External Lisp:: Communicating through Emacs with a separate Lisp.
  16. @end menu
  17. @node Compilation, Lisp Modes, Running, Running
  18. @section Running ``make'', or Compilers Generally
  19. @cindex inferior process
  20. @cindex make
  21. @cindex compilation errors
  22. @cindex error log
  23. Emacs can run compilers for non-interactive languages like C and
  24. Fortran as inferior processes, feeding the error log into an Emacs buffer.
  25. It can also parse the error messages and visit the files in which errors
  26. are found, moving point to the line where the error occurred.
  27. @table @kbd
  28. @item M-x compile
  29. Run a compiler asynchronously under Emacs, with error messages to
  30. @samp{*compilation*} buffer.
  31. @item M-x grep
  32. Run @code{grep} asynchronously under Emacs, with matching lines
  33. listed in the buffer named @samp{*compilation*}.
  34. @item M-x kill-compilation
  35. Kill the process made by the @code{M-x compile} command.
  36. @item M-x kill-grep
  37. Kill the running compilation or @code{grep} subprocess.
  38. @item C-x `
  39. Visit the next compiler error message or @code{grep} match.
  40. @end table
  41. @findex compile
  42. To run @code{make} or another compiler, type @kbd{M-x compile}. This
  43. command reads a shell command line using the minibuffer, then executes
  44. the specified command line in an inferior shell with output going to the
  45. buffer named @samp{*compilation*}. By default, the current buffer's
  46. default directory is used as the working directory for the execution of
  47. the command; therefore, the makefile comes from this directory.
  48. @vindex compile-command
  49. When the shell command line is read, the minibuffer appears containing a
  50. default command line (the command you used the last time you typed
  51. @kbd{M-x compile}). If you type just @key{RET}, the same command line is used
  52. again. The first @kbd{M-x compile} provides @code{make -k} as the default.
  53. The default is taken from the variable @code{compile-command}; if the
  54. appropriate compilation command for a file is something other than
  55. @code{make -k}, it can be useful to have the file specify a local value for
  56. @code{compile-command} (@pxref{File Variables}).
  57. @cindex compiling files
  58. When you start a compilation, the buffer @samp{*compilation*} is
  59. displayed in another window but not selected. Its mode line displays
  60. the word @samp{run} or @samp{exit} in the parentheses to tell you whether
  61. compilation is finished. You do not have to keep this buffer visible;
  62. compilation continues in any case.
  63. @findex kill-compilation
  64. To kill the compilation process, type @kbd{M-x kill-compilation}. The mode
  65. line of the @samp{*compilation*} buffer changes to say @samp{signal}
  66. instead of @samp{run}. Starting a new compilation also kills any
  67. running compilation, as only one can occur at any time. Starting a new
  68. compilation prompts for confirmation before actually killing a
  69. compilation that is running.@refill
  70. @kindex C-x `
  71. @findex next-error
  72. To parse the compiler error messages, type @kbd{C-x `}
  73. (@code{next-error}). The character following @kbd{C-x} is the grave
  74. accent, not the single quote. The command displays the buffer
  75. @samp{*compilation*} in one window and the buffer in which the next
  76. error occurred in another window. Point in that buffer is moved to the
  77. line where the error was found. The corresponding error message is
  78. scrolled to the top of the window in which @samp{*compilation*} is
  79. displayed.
  80. The first time you use @kbd{C-x `} after the start of a compilation, it
  81. parses all the error messages, visits all the files that have error
  82. messages, and creates markers pointing at the lines the error messages
  83. refer to. It then moves to the first error message location. Subsequent
  84. uses of @kbd{C-x `} advance down the data set up by the first use. When
  85. the preparsed error messages are exhausted, the next @kbd{C-x `} checks for
  86. any more error messages that have come in; this is useful if you start
  87. editing compiler errors while compilation is still going on. If no
  88. additional error messages have come in, @kbd{C-x `} reports an error.
  89. @kbd{C-u C-x `} discards the preparsed error message data and parses the
  90. @samp{*compilation*} buffer again, then displays the first error.
  91. This way, you can process the same set of errors again.
  92. Instead of running a compiler, you can run @code{grep} and see the
  93. lines on which matches were found. To do this, type @kbd{M-x grep} with
  94. an argument line that contains the same arguments you would give to
  95. @code{grep}: a @code{grep}-style regexp (usually in single quotes to
  96. quote the shell's special characters) followed by filenames, which may
  97. use wildcard characters. The output from @code{grep} goes in the
  98. @samp{*compilation*} buffer. You can use @kbd{C-x `} to find the lines that
  99. match as if they were compilation errors.
  100. Note: a shell is used to run the compile command, but the shell is not
  101. run in interactive mode. In particular, this means that the shell starts
  102. up with no prompt. If you find your usual shell prompt making an
  103. unsightly appearance in the @samp{*compilation*} buffer, it means you
  104. have made a mistake in your shell's initialization file (@file{.cshrc}
  105. or @file{.shrc} or @dots{}) by setting the prompt unconditionally. The
  106. shell initialization file should set the prompt only if there already is
  107. a prompt. Here's how to do it in @code{csh}:
  108. @example
  109. if ($?prompt) set prompt = ...
  110. @end example
  111. @node Lisp Modes, Lisp Libraries, Compilation, Running
  112. @section Major Modes for Lisp
  113. Emacs has four different major modes for Lisp. They are the same in
  114. terms of editing commands, but differ in the commands for executing Lisp
  115. expressions.
  116. @table @asis
  117. @item Emacs-Lisp mode
  118. The mode for editing source files of programs to run in Emacs Lisp.
  119. This mode defines @kbd{C-M-x} to evaluate the current defun.
  120. @xref{Lisp Libraries}.
  121. @item Lisp Interaction mode
  122. The mode for an interactive session with Emacs Lisp. It defines
  123. @key{LFD} to evaluate the sexp before point and insert its value in the
  124. buffer. @xref{Lisp Interaction}.
  125. @item Lisp mode
  126. The mode for editing source files of programs that run in other dialects
  127. of Lisp than Emacs Lisp. This mode defines @kbd{C-M-x} to send the
  128. current defun to an inferior Lisp process. @xref{External Lisp}.
  129. @item Inferior Lisp mode
  130. The mode for an interactive session with an inferior Lisp process.
  131. This mode combines the special features of Lisp mode and Shell mode
  132. (@pxref{Shell Mode}).
  133. @item Scheme mode
  134. Like Lisp mode but for Scheme programs.
  135. @item Inferior Scheme mode
  136. The mode for an interactive session with an inferior Scheme process.
  137. @end table
  138. @node Lisp Libraries, Lisp Eval, Lisp Modes, Running
  139. @section Libraries of Lisp Code for Emacs
  140. @cindex libraries
  141. @cindex loading Lisp code
  142. Lisp code for Emacs editing commands is stored in files whose names
  143. conventionally end in @file{.el}. This ending tells Emacs to edit them in
  144. Emacs-Lisp mode (@pxref{Lisp Modes}).
  145. @menu
  146. * Loading:: Loading libraries of Lisp code into Emacs for use.
  147. * Compiling Libraries:: Compiling a library makes it load and run faster.
  148. * Mocklisp:: Converting Mocklisp to Lisp so XEmacs can run it.
  149. @end menu
  150. @node Loading, Compiling Libraries, Lisp Libraries, Lisp Libraries
  151. @subsection Loading Libraries
  152. @table @kbd
  153. @item M-x load-file @var{file}
  154. Load the file @var{file} of Lisp code.
  155. @item M-x load-library @var{library}
  156. Load the library named @var{library}.
  157. @item M-x locate-library @var{library} &optional @var{nosuffix}
  158. Show the full path name of Emacs library @var{library}.
  159. @end table
  160. @findex load-file
  161. To execute a file of Emacs Lisp, use @kbd{M-x load-file}. This
  162. command reads the file name you provide in the minibuffer, then executes
  163. the contents of that file as Lisp code. It is not necessary to visit
  164. the file first; in fact, this command reads the file as found on
  165. disk, not the text in an Emacs buffer.
  166. @findex load
  167. @findex load-library
  168. Once a file of Lisp code is installed in the Emacs Lisp library
  169. directories, users can load it using @kbd{M-x load-library}. Programs can
  170. load it by calling @code{load-library}, or with @code{load}, a more primitive
  171. function that is similar but accepts some additional arguments.
  172. @kbd{M-x load-library} differs from @kbd{M-x load-file} in that it
  173. searches a sequence of directories and tries three file names in each
  174. directory. The three names are: first, the specified name with @file{.elc}
  175. appended; second, the name with @file{.el} appended; third, the specified
  176. name alone. A @file{.elc} file would be the result of compiling the Lisp
  177. file into byte code; if possible, it is loaded in preference to the Lisp
  178. file itself because the compiled file loads and runs faster.
  179. @cindex loading libraries
  180. Because the argument to @code{load-library} is usually not in itself
  181. a valid file name, file name completion is not available. In fact, when
  182. using this command, you usually do not know exactly what file name
  183. will be used.
  184. @vindex load-path
  185. The sequence of directories searched by @kbd{M-x load-library} is
  186. specified by the variable @code{load-path}, a list of strings that are
  187. directory names. The elements of this list may not begin with "@samp{~}",
  188. so you must call @code{expand-file-name} on them before adding them to
  189. the list. The default value of the list contains the directory where
  190. the Lisp code for Emacs itself is stored. If you have libraries of your
  191. own, put them in a single directory and add that directory to
  192. @code{load-path}. @code{nil} in this list stands for the current
  193. default directory, but it is probably not a good idea to put @code{nil}
  194. in the list. If you start wishing that @code{nil} were in the list, you
  195. should probably use @kbd{M-x load-file} for this case.
  196. The variable is initialized by the @b{EMACSLOADPATH} environment
  197. variable. If no value is specified, the variable takes the default value
  198. specified in the file @file{paths.h} when Emacs was built. If a path
  199. isn't specified in @file{paths.h}, a default value is obtained from the
  200. file system, near the directory in which the Emacs executable resides.
  201. @findex locate-library
  202. Like @kbd{M-x load-library}, @kbd{M-x locate-library} searches the
  203. directories in @code{load-path} to find the file that @kbd{M-x load-library}
  204. would load. If the optional second argument @var{nosuffix} is
  205. non-@code{nil}, the suffixes @file{.elc} or @file{.el} are not added to
  206. the specified name @var{library} (like calling @code{load} instead of
  207. @code{load-library}).
  208. @cindex autoload
  209. You often do not have to give any command to load a library, because the
  210. commands defined in the library are set up to @dfn{autoload} that library.
  211. Running any of those commands causes @code{load} to be called to load the
  212. library; this replaces the autoload definitions with the real ones from the
  213. library.
  214. If autoloading a file does not finish, either because of an error or
  215. because of a @kbd{C-g} quit, all function definitions made by the file
  216. are undone automatically. So are any calls to @code{provide}. As a
  217. consequence, the entire file is loaded a second time if you use one of
  218. the autoloadable commands again. This prevents problems when the
  219. command is no longer autoloading but is working incorrectly because the file
  220. was only partially loaded. Function definitions are undone only for
  221. autoloading; explicit calls to @code{load} do not undo anything if
  222. loading is not completed.
  223. @vindex after-load-alist
  224. The variable @code{after-load-alist} takes an alist of expressions to be
  225. evaluated when particular files are loaded. Each element has the form
  226. @code{(@var{filename} forms...)}. When @code{load} is run and the filename
  227. argument is @var{filename}, the forms in the corresponding element are
  228. executed at the end of loading.
  229. @var{filename} must match exactly. Normally @var{filename} is the
  230. name of a library, with no directory specified, since that is how load
  231. is normally called. An error in @code{forms} does not undo the load, but
  232. it does prevent execution of the rest of the @code{forms}.
  233. @node Compiling Libraries, Mocklisp, Loading, Lisp Libraries
  234. @subsection Compiling Libraries
  235. @cindex byte code
  236. Emacs Lisp code can be compiled into byte-code which loads faster,
  237. takes up less space when loaded, and executes faster.
  238. @table @kbd
  239. @item M-x batch-byte-compile
  240. Run byte-compile-file on the files remaining on the command line.
  241. @item M-x byte-compile-buffer &optional @var{buffer}
  242. Byte-compile and evaluate contents of @var{buffer} (default is current
  243. buffer).
  244. @item M-x byte-compile-file
  245. Compile a file of Lisp code named @var{filename} into a file of byte code.
  246. @item M-x byte-compile-and-load-file @var{filename}
  247. Compile a file of Lisp code named @var{filename} into a file of byte
  248. code and load it.
  249. @item M-x byte-recompile-directory @var{directory}
  250. Recompile every @file{.el} file in @var{directory} that needs recompilation.
  251. @item M-x disassemble
  252. Print disassembled code for @var{object} on (optional) @var{stream}.
  253. @findex make-obsolete
  254. @item M-x make-obsolete @var{function new}
  255. Make the byte-compiler warn that @var{function} is obsolete and @var{new}
  256. should be used instead.
  257. @end table
  258. @findex byte-compile-file
  259. @findex byte-compile-and-load-file
  260. @findex byte-compile-buffer
  261. @kbd{byte-compile-file} creates a byte-code compiled file from an
  262. Emacs-Lisp source file. The default argument for this function is the
  263. file visited in the current buffer. The function reads the specified
  264. file, compiles it into byte code, and writes an output file whose name
  265. is made by appending @file{c} to the input file name. Thus, the file
  266. @file{rmail.el} would be compiled into @file{rmail.elc}. To compile a
  267. file of Lisp code named @var{filename} into a file of byte code and
  268. then load it, use @code{byte-compile-and-load-file}. To compile and
  269. evaluate Lisp code in a given buffer, use @code{byte-compile-buffer}.
  270. @findex byte-recompile-directory
  271. To recompile all changed Lisp files in a directory, use @kbd{M-x
  272. byte-recompile-directory}. Specify just the directory name as an argument.
  273. Each @file{.el} file that has been byte-compiled before is byte-compiled
  274. again if it has changed since the previous compilation. A numeric argument
  275. to this command tells it to offer to compile each @file{.el} file that has
  276. not been compiled yet. You must answer @kbd{y} or @kbd{n} to each
  277. offer.
  278. @findex batch-byte-compile
  279. You can use the function @code{batch-byte-compile} to invoke Emacs
  280. non-interactively from the shell to do byte compilation. When you use
  281. this function, the files to be compiled are specified with command-line
  282. arguments. Use a shell command of the form:
  283. @example
  284. emacs -batch -f batch-byte-compile @var{files}...
  285. @end example
  286. Directory names may also be given as arguments; in that case,
  287. @code{byte-recompile-directory} is invoked on each such directory.
  288. @code{batch-byte-compile} uses all remaining command-line arguments as
  289. file or directory names, then kills the Emacs process.
  290. @findex disassemble
  291. @kbd{M-x disassemble} explains the result of byte compilation. Its
  292. argument is a function name. It displays the byte-compiled code in a help
  293. window in symbolic form, one instruction per line. If the instruction
  294. refers to a variable or constant, that is shown, too.
  295. @node Mocklisp,,Compiling Libraries,Lisp Libraries
  296. @subsection Converting Mocklisp to Lisp
  297. @cindex mocklisp
  298. @findex convert-mocklisp-buffer
  299. XEmacs can run Mocklisp files by converting them to Emacs Lisp first.
  300. To convert a Mocklisp file, visit it and then type @kbd{M-x
  301. convert-mocklisp-buffer}. Then save the resulting buffer of Lisp file in a
  302. file whose name ends in @file{.el} and use the new file as a Lisp library.
  303. You cannot currently byte-compile converted Mocklisp code.
  304. The reason is that converted Mocklisp code uses some special Lisp features
  305. to deal with Mocklisp's incompatible ideas of how arguments are evaluated
  306. and which values signify ``true'' or ``false''.
  307. @node Lisp Eval, Lisp Debug, Lisp Libraries, Running
  308. @section Evaluating Emacs-Lisp Expressions
  309. @cindex Emacs-Lisp mode
  310. @findex emacs-lisp-mode
  311. Lisp programs intended to be run in Emacs should be edited in
  312. Emacs-Lisp mode; this will happen automatically for file names ending in
  313. @file{.el}. By contrast, Lisp mode itself should be used for editing
  314. Lisp programs intended for other Lisp systems. Emacs-Lisp mode can be
  315. selected with the command @kbd{M-x emacs-lisp-mode}.
  316. For testing of Lisp programs to run in Emacs, it is useful to be able
  317. to evaluate part of the program as it is found in the Emacs buffer. For
  318. example, if you change the text of a Lisp function definition and then
  319. evaluate the definition, Emacs installs the change for future calls to the
  320. function. Evaluation of Lisp expressions is also useful in any kind of
  321. editing task for invoking non-interactive functions (functions that are
  322. not commands).
  323. @table @kbd
  324. @item M-:
  325. Read a Lisp expression in the minibuffer, evaluate it, and print the
  326. value in the minibuffer (@code{eval-expression}).
  327. @item C-x C-e
  328. Evaluate the Lisp expression before point, and print the value in the
  329. minibuffer (@code{eval-last-sexp}).
  330. @item C-M-x
  331. Evaluate the defun containing point or after point, and print the value in
  332. the minibuffer (@code{eval-defun}).
  333. @item M-x eval-region
  334. Evaluate all the Lisp expressions in the region.
  335. @item M-x eval-current-buffer
  336. Evaluate all the Lisp expressions in the buffer.
  337. @end table
  338. @kindex M-:
  339. @findex eval-expression
  340. @kbd{M-:} (@code{eval-expression}) is the most basic command
  341. for evaluating a Lisp expression interactively. It reads the expression
  342. using the minibuffer, so you can execute any expression on a buffer
  343. regardless of what the buffer contains. When evaluation is complete,
  344. the current buffer is once again the buffer that was current when
  345. @kbd{M-:} was typed.
  346. @kindex C-M-x
  347. @findex eval-defun
  348. In Emacs-Lisp mode, the key @kbd{C-M-x} is bound to the function
  349. @code{eval-defun}, which parses the defun containing point or following point
  350. as a Lisp expression and evaluates it. The value is printed in the echo
  351. area. This command is convenient for installing in the Lisp environment
  352. changes that you have just made in the text of a function definition.
  353. @kindex C-x C-e
  354. @findex eval-last-sexp
  355. The command @kbd{C-x C-e} (@code{eval-last-sexp}) performs a similar job
  356. but is available in all major modes, not just Emacs-Lisp mode. It finds
  357. the sexp before point, reads it as a Lisp expression, evaluates it, and
  358. prints the value in the echo area. It is sometimes useful to type in an
  359. expression and then, with point still after it, type @kbd{C-x C-e}.
  360. If @kbd{C-M-x} or @kbd{C-x C-e} are given a numeric argument, they
  361. print the value by inserting it into the current buffer at point, rather
  362. than in the echo area. The argument value does not matter.
  363. @findex eval-region
  364. @findex eval-current-buffer
  365. The most general command for evaluating Lisp expressions from a buffer
  366. is @code{eval-region}. @kbd{M-x eval-region} parses the text of the
  367. region as one or more Lisp expressions, evaluating them one by one.
  368. @kbd{M-x eval-current-buffer} is similar, but it evaluates the entire
  369. buffer. This is a reasonable way to install the contents of a file of
  370. Lisp code that you are just ready to test. After finding and fixing a
  371. bug, use @kbd{C-M-x} on each function that you change, to keep the Lisp
  372. world in step with the source file.
  373. @node Lisp Debug, Lisp Interaction, Lisp Eval, Running
  374. @section The Emacs-Lisp Debugger
  375. @cindex debugger
  376. @vindex debug-on-error
  377. @vindex debug-on-quit
  378. XEmacs contains a debugger for Lisp programs executing inside it.
  379. This debugger is normally not used; many commands frequently get Lisp
  380. errors when invoked in inappropriate contexts (such as @kbd{C-f} at the
  381. end of the buffer) and it would be unpleasant to enter a special
  382. debugging mode in this case. When you want to make Lisp errors invoke
  383. the debugger, you must set the variable @code{debug-on-error} to
  384. non-@code{nil}. Quitting with @kbd{C-g} is not considered an error, and
  385. @code{debug-on-error} has no effect on the handling of @kbd{C-g}.
  386. However, if you set @code{debug-on-quit} to be non-@code{nil}, @kbd{C-g} will
  387. invoke the debugger. This can be useful for debugging an infinite loop;
  388. type @kbd{C-g} once the loop has had time to reach its steady state.
  389. @code{debug-on-quit} has no effect on errors.@refill
  390. @findex debug-on-entry
  391. @findex cancel-debug-on-entry
  392. @findex debug
  393. You can make Emacs enter the debugger when a specified function
  394. is called or at a particular place in Lisp code. Use @kbd{M-x
  395. debug-on-entry} with argument @var{fun-name} to have Emacs enter the
  396. debugger as soon as @var{fun-name} is called. Use
  397. @kbd{M-x cancel-debug-on-entry} to make the function stop entering the
  398. debugger when called. (Redefining the function also does this.) To enter
  399. the debugger from some other place in Lisp code, you must insert the
  400. expression @code{(debug)} there and install the changed code with
  401. @kbd{C-M-x}. @xref{Lisp Eval}.@refill
  402. When the debugger is entered, it displays the previously selected buffer
  403. in one window and a buffer named @samp{*Backtrace*} in another window. The
  404. backtrace buffer contains one line for each level of Lisp function
  405. execution currently going on. At the beginning of the buffer is a message
  406. describing the reason that the debugger was invoked, for example, an
  407. error message if it was invoked due to an error.
  408. The backtrace buffer is read-only and is in Backtrace mode, a special
  409. major mode in which letters are defined as debugger commands. The
  410. usual Emacs editing commands are available; you can switch windows to
  411. examine the buffer that was being edited at the time of the error, and
  412. you can switch buffers, visit files, and perform any other editing
  413. operations. However, the debugger is a recursive editing level
  414. (@pxref{Recursive Edit}); it is a good idea to return to the backtrace
  415. buffer and explicitly exit the debugger when you don't want to use it any
  416. more. Exiting the debugger kills the backtrace buffer.
  417. @cindex current stack frame
  418. The contents of the backtrace buffer show you the functions that are
  419. executing and the arguments that were given to them. It also allows you
  420. to specify a stack frame by moving point to the line describing that
  421. frame. The frame whose line point is on is considered the @dfn{current
  422. frame}. Some of the debugger commands operate on the current frame.
  423. Debugger commands are mainly used for stepping through code one
  424. expression at a time. Here is a list of them:
  425. @table @kbd
  426. @item c
  427. Exit the debugger and continue execution. In most cases, execution of
  428. the program continues as if the debugger had never been entered (aside
  429. from the effect of any variables or data structures you may have changed
  430. while inside the debugger). This includes entry to the debugger due to
  431. function entry or exit, explicit invocation, and quitting or certain
  432. errors. Most errors cannot be continued; trying to continue an error usually
  433. causes the same error to occur again.
  434. @item d
  435. Continue execution, but enter the debugger the next time a Lisp
  436. function is called. This allows you to step through the
  437. subexpressions of an expression, and see what the subexpressions do and
  438. what values they compute.
  439. When you enter the debugger this way, Emacs flags the stack frame for the
  440. function call from which you entered. The same function is then called
  441. when you exit the frame. To cancel this flag, use @kbd{u}.
  442. @item b
  443. Set up to enter the debugger when the current frame is exited. Frames
  444. that invoke the debugger on exit are flagged with stars.
  445. @item u
  446. Don't enter the debugger when the current frame is exited. This
  447. cancels a @kbd{b} command on a frame.
  448. @item e
  449. Read a Lisp expression in the minibuffer, evaluate it, and print the
  450. value in the echo area. This is equivalent to the command @kbd{M-:}.
  451. @item q
  452. Terminate the program being debugged; return to top-level Emacs
  453. command execution.
  454. If the debugger was entered due to a @kbd{C-g} but you really want
  455. to quit, not to debug, use the @kbd{q} command.
  456. @item r
  457. Return a value from the debugger. The value is computed by reading an
  458. expression with the minibuffer and evaluating it.
  459. The value returned by the debugger makes a difference when the debugger
  460. was invoked due to exit from a Lisp call frame (as requested with @kbd{b});
  461. then the value specified in the @kbd{r} command is used as the value of
  462. that frame.
  463. The debugger's return value also matters with many errors. For example,
  464. @code{wrong-type-argument} errors will use the debugger's return value
  465. instead of the invalid argument; @code{no-catch} errors will use the
  466. debugger value as a throw tag instead of the tag that was not found.
  467. If an error was signaled by calling the Lisp function @code{signal},
  468. the debugger's return value is returned as the value of @code{signal}.
  469. @end table
  470. @node Lisp Interaction, External Lisp, Lisp Debug, Running
  471. @section Lisp Interaction Buffers
  472. The buffer @samp{*scratch*}, which is selected when Emacs starts up, is
  473. provided for evaluating Lisp expressions interactively inside Emacs. Both
  474. the expressions you evaluate and their output goes in the buffer.
  475. The @samp{*scratch*} buffer's major mode is Lisp Interaction mode, which
  476. is the same as Emacs-Lisp mode except for one command, @key{LFD}. In
  477. Emacs-Lisp mode, @key{LFD} is an indentation command. In Lisp
  478. Interaction mode, @key{LFD} is bound to @code{eval-print-last-sexp}. This
  479. function reads the Lisp expression before point, evaluates it, and inserts
  480. the value in printed representation before point.
  481. The way to use the @samp{*scratch*} buffer is to insert Lisp
  482. expressions at the end, ending each one with @key{LFD} so that it will
  483. be evaluated. The result is a complete typescript of the expressions
  484. you have evaluated and their values.
  485. @findex lisp-interaction-mode
  486. The rationale for this feature is that Emacs must have a buffer when it
  487. starts up, but that buffer is not useful for editing files since a new
  488. buffer is made for every file that you visit. The Lisp interpreter
  489. typescript is the most useful thing I can think of for the initial buffer
  490. to do. @kbd{M-x lisp-interaction-mode} will put any buffer in Lisp
  491. Interaction mode.
  492. @node External Lisp,, Lisp Interaction, Running
  493. @section Running an External Lisp
  494. Emacs has facilities for running programs in other Lisp systems. You can
  495. run a Lisp process as an inferior of Emacs, and pass expressions to it to
  496. be evaluated. You can also pass changed function definitions directly from
  497. the Emacs buffers in which you edit the Lisp programs to the inferior Lisp
  498. process.
  499. @findex run-lisp
  500. To run an inferior Lisp process, type @kbd{M-x run-lisp}. This runs the
  501. program named @code{lisp}, the same program you would run by typing
  502. @code{lisp} as a shell command, with both input and output going through an
  503. Emacs buffer named @samp{*lisp*}. In other words, any ``terminal output''
  504. from Lisp will go into the buffer, advancing point, and any ``terminal
  505. input'' for Lisp comes from text in the buffer. To give input to Lisp, go
  506. to the end of the buffer and type the input, terminated by @key{RET}. The
  507. @samp{*lisp*} buffer is in Inferior Lisp mode, which has all the
  508. special characteristics of Lisp mode and Shell mode (@pxref{Shell Mode}).
  509. @findex lisp-mode
  510. Use Lisp mode to run the source files of programs in external Lisps.
  511. You can select this mode with @kbd{M-x lisp-mode}. It is used automatically
  512. for files whose names end in @file{.l} or @file{.lisp}, as most Lisp
  513. systems usually expect.
  514. @kindex C-M-x
  515. @findex lisp-send-defun
  516. When you edit a function in a Lisp program you are running, the easiest
  517. way to send the changed definition to the inferior Lisp process is the key
  518. @kbd{C-M-x}. In Lisp mode, this key runs the function @code{lisp-send-defun},
  519. which finds the defun around or following point and sends it as input to
  520. the Lisp process. (Emacs can send input to any inferior process regardless
  521. of what buffer is current.)
  522. Contrast the meanings of @kbd{C-M-x} in Lisp mode (for editing programs
  523. to be run in another Lisp system) and Emacs-Lisp mode (for editing Lisp
  524. programs to be run in Emacs): in both modes it has the effect of installing
  525. the function definition that point is in, but the way of doing so is
  526. different according to where the relevant Lisp environment is found.
  527. @xref{Lisp Modes}.