neves@uwai.UUCP (04/14/85)
** Interacting with Lisp in GNU Emacs. ** bugs to David Neves GNU Emacs has a complete Lisp interpreter embedded in it. You can play with it by typing an s-expression in the *scratch* buffer and then hitting a linefeed (ctrl-j). However it will often be the case some other Lisp is needed (for example Franz Lisp). This note is to illustrate one way of debugging Lisp code by quickly going between the code in an Emacs buffer and the Lisp interpreter. (There is also Ledit mode but I do not know how to use it.) Preliminaries. 1. Enter Emacs 2. Start up a shell buffer by doing Meta-X shell <return> (to see the things you can do in a shell buffer type ctrl-h m) 3. When you see the unix prompt (%) type lisp to enter Franz. 4. load your lisp file into Franz. (load "foo.l") 5. load your lisp file into Emacs (with ctrl-x ctrl-f foo.l <return>) To send a function from Emacs to Franz. 1. Mark the Lisp function (by executing Meta-Ctrl-d, ie. <escape> <ctrl-d>). 2. Send the region to the lisp process by doing Meta-X send-region <return> shell <return> 3. To go back to the shell (Lisp) buffer do a ctrl-x b<return> That's it. One could write two functions to automate steps 1, 2, and 3. (defun mark-send nil "mark the current defun and send it to the shell buffer" (interactive) (save-excursion (mark-defun) (exchange-dot-and-mark) ;send a carriage return (beginning-of-line) ;after the (next-line 1) ;defun for Franz (send-region "shell" (mark) (dot)))) (defun mark-send-go nil "mark the current defun, send it to shell buffer, goto shell buffer" (interactive) (mark-send) (switch-to-buffer "*shell*")) It is possible to put these functions on a key (or several keys). For example, let us put mark-send on Meta-Ctrl-x and mark-send-go on Meta-Ctrl-z so that we can call them when in Lisp-Mode. After doing this we send a defun to lisp by moving the cursor to it and hitting Meta-Ctrl-x. If we wanted to go back to the shell buffer we would hit Meta-Ctrl-z. (define-key lisp-mode-map "\e\^x" 'mark-send) (define-key lisp-mode-map "\e\^z" 'mark-send-go) If using these functions quite often you might want to place the functions and the define-keys in your .emacs file (which is loaded automatically when emacs is called). You can also execute functions directly: e.g. by typing Meta-<esc> (mark-send-go) <return>. -- David Neves Computer Sciences Department University of Wisconsin-Madison Usenet: {allegra,heurikon,ihnp4,seismo,uwm-evax}!uwvax!neves Arpanet: neves@uwvax