*** empty log message ***
[bpt/emacs.git] / lisp / progmodes / inf-lisp.el
CommitLineData
c0274f38
ER
1;;; cmulisp.el --- improved version of standard inferior-lisp mode
2
2f790b20
JB
3;;; Copyright Olin Shivers (1988).
4;;; Please imagine a long, tedious, legalistic 5-page gnu-style copyright
5;;; notice appearing here to the effect that you may use this code any
6;;; way you like, as long as you don't charge money for it, remove this
7;;; notice, or hold me liable for its results.
8
9;;; This replaces the standard inferior-lisp mode.
10;;; Hacked from tea.el by Olin Shivers (shivers@cs.cmu.edu). 8/88
11;;; Please send me bug reports, bug fixes, and extensions, so that I can
12;;; merge them into the master source.
13;;;
14;;; Change log at end of file.
15
16;;; This file defines a a lisp-in-a-buffer package (cmulisp mode) built on top
17;;; of comint mode. Cmulisp mode is similar to, and intended to replace, its
18;;; counterpart in the standard gnu emacs release. This replacements is more
19;;; featureful, robust, and uniform than the released version. The key
20;;; bindings are also more compatible with the bindings of Hemlock and Zwei
21;;; (the Lisp Machine emacs).
22
23;;; Since this mode is built on top of the general command-interpreter-in-
24;;; a-buffer mode (comint mode), it shares a common base functionality,
25;;; and a common set of bindings, with all modes derived from comint mode.
26;;; This makes these modes easier to use.
27
28;;; For documentation on the functionality provided by comint mode, and
29;;; the hooks available for customising it, see the file comint.el.
30;;; For further information on cmulisp mode, see the comments below.
31
32;;; Needs fixin:
33;;; The load-file/compile-file default mechanism could be smarter -- it
34;;; doesn't know about the relationship between filename extensions and
35;;; whether the file is source or executable. If you compile foo.lisp
36;;; with compile-file, then the next load-file should use foo.bin for
37;;; the default, not foo.lisp. This is tricky to do right, particularly
38;;; because the extension for executable files varies so much (.o, .bin,
39;;; .lbin, .mo, .vo, .ao, ...).
40;;;
41;;; It would be nice if cmulisp (and inferior scheme, T, ...) modes
42;;; had a verbose minor mode wherein sending or compiling defuns, etc.
43;;; would be reflected in the transcript with suitable comments, e.g.
44;;; ";;; redefining fact". Several ways to do this. Which is right?
45;;;
46;;; When sending text from a source file to a subprocess, the process-mark can
47;;; move off the window, so you can lose sight of the process interactions.
48;;; Maybe I should ensure the process mark is in the window when I send
49;;; text to the process? Switch selectable?
50
51(require 'comint)
2f790b20
JB
52;; YOUR .EMACS FILE
53;;=============================================================================
54;; Some suggestions for your .emacs file.
55;;
56;; ; If cmulisp lives in some non-standard directory, you must tell emacs
57;; ; where to get it. This may or may not be necessary.
58;; (setq load-path (cons (expand-file-name "~jones/lib/emacs") load-path))
59;;
60;; ; Autoload cmulisp from file cmulisp.el
61;; (autoload 'cmulisp "cmulisp"
62;; "Run an inferior Lisp process."
63;; t)
64;;
65;; ; Define C-c t to run my favorite command in cmulisp mode:
66;; (setq cmulisp-load-hook
67;; '((lambda ()
68;; (define-key cmulisp-mode-map "\C-ct" 'favorite-cmd))))
69
70\f
71;;; Brief Command Documentation:
72;;;============================================================================
73;;; Comint Mode Commands: (common to cmulisp and all comint-derived modes)
74;;;
75;;; m-p comint-previous-input Cycle backwards in input history
76;;; m-n comint-next-input Cycle forwards
77;;; m-c-r comint-previous-input-matching Search backwards in input history
78;;; return comint-send-input
79;;; c-a comint-bol Beginning of line; skip prompt.
80;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff.
81;;; c-c c-u comint-kill-input ^u
82;;; c-c c-w backward-kill-word ^w
83;;; c-c c-c comint-interrupt-subjob ^c
84;;; c-c c-z comint-stop-subjob ^z
85;;; c-c c-\ comint-quit-subjob ^\
86;;; c-c c-o comint-kill-output Delete last batch of process output
87;;; c-c c-r comint-show-output Show last batch of process output
88;;; send-invisible Read line w/o echo & send to proc
89;;; comint-continue-subjob Useful if you accidentally suspend
90;;; top-level job.
91;;; comint-mode-hook is the comint mode hook.
92
93;;; CMU Lisp Mode Commands:
94;;; c-m-x lisp-send-defun This binding is a gnu convention.
95;;; c-c c-l lisp-load-file Prompt for file name; tell Lisp to load it.
96;;; c-c c-k lisp-compile-file Prompt for file name; tell Lisp to kompile it.
97;;; Filename completion is available, of course.
98;;;
99;;; Additionally, these commands are added to the key bindings of Lisp mode:
100;;; c-m-x lisp-eval-defun This binding is a gnu convention.
101;;; c-c c-e lisp-eval-defun Send the current defun to Lisp process.
102;;; c-x c-e lisp-eval-last-sexp Send the previous sexp to Lisp process.
103;;; c-c m-e lisp-eval-defun-and-go After sending the defun, switch-to-lisp.
104;;; c-c c-r lisp-eval-region Send the current region to Lisp process.
105;;; c-c m-r lisp-eval-region-and-go After sending the region, switch-to-lisp.
106;;; c-c c-c lisp-compile-defun Compile the current defun in Lisp process.
107;;; c-c m-c lisp-compile-defun-and-go After compiling defun, switch-to-lisp.
108;;; c-c c-z switch-to-lisp Switch to the Lisp process buffer.
109;;; c-c c-l lisp-load-file (See above. In a Lisp file buffer, default
110;;; c-c c-k lisp-compile-file is to load/compile the current file.)
111;;; c-c c-d lisp-describe-sym Query Lisp for a symbol's description.
112;;; c-c c-a lisp-show-arglist Query Lisp for function's arglist.
113;;; c-c c-f lisp-show-function-documentation Query Lisp for a function's doc.
114;;; c-c c-v lisp-show-variable-documentation Query Lisp for a variable's doc.
115
116;;; cmulisp Fires up the Lisp process.
117;;; lisp-compile-region Compile all forms in the current region.
118;;; lisp-compile-region-and-go After compiling region, switch-to-lisp.
119;;;
120;;; CMU Lisp Mode Variables:
121;;; cmulisp-filter-regexp Match this => don't get saved on input hist
122;;; inferior-lisp-program Name of Lisp program run-lisp executes
123;;; inferior-lisp-load-command Customises lisp-load-file
124;;; cmulisp-mode-hook
125;;; inferior-lisp-prompt Initialises comint-prompt-regexp.
126;;; Backwards compatibility.
127;;; lisp-source-modes Anything loaded into a buffer that's in
128;;; one of these modes is considered Lisp
129;;; source by lisp-load/compile-file.
130
131;;; Read the rest of this file for more information.
132\f
133(defvar cmulisp-filter-regexp "\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'"
134 "*What not to save on inferior Lisp's input history
135Input matching this regexp is not saved on the input history in cmulisp
136mode. Default is whitespace followed by 0 or 1 single-letter :keyword
137(as in :a, :c, etc.)")
138
139(defvar cmulisp-mode-map nil)
140(cond ((not cmulisp-mode-map)
141 (setq cmulisp-mode-map
142 (full-copy-sparse-keymap comint-mode-map))
143 (lisp-mode-commands cmulisp-mode-map)
144 (define-key cmulisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp)
145 (define-key cmulisp-mode-map "\C-c\C-l" 'lisp-load-file)
146 (define-key cmulisp-mode-map "\C-c\C-k" 'lisp-compile-file)
147 (define-key cmulisp-mode-map "\C-c\C-a" 'lisp-show-arglist)
148 (define-key cmulisp-mode-map "\C-c\C-d" 'lisp-describe-sym)
149 (define-key cmulisp-mode-map "\C-c\C-f" 'lisp-show-function-documentation)
150 (define-key cmulisp-mode-map "\C-c\C-v" 'lisp-show-variable-documentation)))
151
152;;; These commands augment Lisp mode, so you can process Lisp code in
153;;; the source files.
154(define-key lisp-mode-map "\M-\C-x" 'lisp-eval-defun) ; Gnu convention
155(define-key lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp) ; Gnu convention
156(define-key lisp-mode-map "\C-c\C-e" 'lisp-eval-defun)
157(define-key lisp-mode-map "\C-c\M-e" 'lisp-eval-defun-and-go)
158(define-key lisp-mode-map "\C-c\C-r" 'lisp-eval-region)
159(define-key lisp-mode-map "\C-c\M-r" 'lisp-eval-region-and-go)
160(define-key lisp-mode-map "\C-c\C-c" 'lisp-compile-defun)
161(define-key lisp-mode-map "\C-c\M-c" 'lisp-compile-defun-and-go)
162(define-key lisp-mode-map "\C-c\C-z" 'switch-to-lisp)
163(define-key lisp-mode-map "\C-c\C-l" 'lisp-load-file)
164(define-key lisp-mode-map "\C-c\C-k" 'lisp-compile-file) ; "kompile" file
165(define-key lisp-mode-map "\C-c\C-a" 'lisp-show-arglist)
166(define-key lisp-mode-map "\C-c\C-d" 'lisp-describe-sym)
167(define-key lisp-mode-map "\C-c\C-f" 'lisp-show-function-documentation)
168(define-key lisp-mode-map "\C-c\C-v" 'lisp-show-variable-documentation)
169
170
171(defvar inferior-lisp-program "lisp"
172 "*Program name for invoking an inferior Lisp with `cmulisp'.")
173
174(defvar inferior-lisp-load-command "(load \"%s\")\n"
175 "*Format-string for building a Lisp expression to load a file.
176This format string should use %s to substitute a file name
177and should result in a Lisp expression that will command the inferior Lisp
178to load that file. The default works acceptably on most Lisps.
179The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\\n\"
180produces cosmetically superior output for this application,
181but it works only in Common Lisp.")
182
183(defvar inferior-lisp-prompt "^[^> ]*>+:? *"
184 "Regexp to recognise prompts in the inferior Lisp.
185Defaults to \"^[^> ]*>+:? *\", which works pretty good for Lucid, kcl,
186and franz. This variable is used to initialise comint-prompt-regexp in the
187cmulisp buffer.
188
189More precise choices:
190Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\"
191franz: \"^\\(->\\|<[0-9]*>:\\) *\"
192kcl: \"^>+ *\"
193
194This is a fine thing to set in your .emacs file.")
195
196(defvar cmulisp-mode-hook '()
197 "*Hook for customising cmulisp mode")
198
199(defun cmulisp-mode ()
200 "Major mode for interacting with an inferior Lisp process.
201Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an
202Emacs buffer. Variable inferior-lisp-program controls which Lisp interpreter
203is run. Variables inferior-lisp-prompt, cmulisp-filter-regexp and
204inferior-lisp-load-command can customize this mode for different Lisp
205interpreters.
206
207For information on running multiple processes in multiple buffers, see
208documentation for variable cmulisp-buffer.
209
210\\{cmulisp-mode-map}
211
212Customisation: Entry to this mode runs the hooks on comint-mode-hook and
213cmulisp-mode-hook (in that order).
214
215You can send text to the inferior Lisp process from other buffers containing
216Lisp source.
217 switch-to-lisp switches the current buffer to the Lisp process buffer.
218 lisp-eval-defun sends the current defun to the Lisp process.
219 lisp-compile-defun compiles the current defun.
220 lisp-eval-region sends the current region to the Lisp process.
221 lisp-compile-region compiles the current region.
222
223 lisp-eval-defun-and-go, lisp-compile-defun-and-go,
224 lisp-eval-region-and-go, and lisp-compile-region-and-go
225 switch to the Lisp process buffer after sending their text.
226
227Commands:
228Return after the end of the process' output sends the text from the
229 end of process to point.
230Return before the end of the process' output copies the sexp ending at point
231 to the end of the process' output, and sends it.
232Delete converts tabs to spaces as it moves back.
233Tab indents for Lisp; with argument, shifts rest
234 of expression rigidly with the current line.
235C-M-q does Tab on each line starting within following expression.
236Paragraphs are separated only by blank lines. Semicolons start comments.
237If you accidentally suspend your process, use \\[comint-continue-subjob]
238to continue it."
239 (interactive)
240 (comint-mode)
241 (setq comint-prompt-regexp inferior-lisp-prompt)
242 (setq major-mode 'cmulisp-mode)
243 (setq mode-name "CMU Lisp")
244 (setq mode-line-process '(": %s"))
245 (if (string-match "^18.4" emacs-version) ; hack.
246 (lisp-mode-variables) ; This is right for 18.49
247 (lisp-mode-variables t)) ; This is right for 18.50
248 (use-local-map cmulisp-mode-map) ;c-c c-k for "kompile" file
249 (setq comint-get-old-input (function lisp-get-old-input))
250 (setq comint-input-filter (function lisp-input-filter))
251 (setq comint-input-sentinel 'ignore)
252 (run-hooks 'cmulisp-mode-hook))
253
254(defun lisp-get-old-input ()
255 "Snarf the sexp ending at point"
256 (save-excursion
257 (let ((end (point)))
258 (backward-sexp)
259 (buffer-substring (point) end))))
260
261(defun lisp-input-filter (str)
262 "Don't save anything matching cmulisp-filter-regexp"
263 (not (string-match cmulisp-filter-regexp str)))
264
265(defun cmulisp ()
266 "Run an inferior Lisp process, input and output via buffer *cmulisp*.
267If there is a process already running in *cmulisp*, just switch to that buffer.
268Takes the program name from the variable inferior-lisp-program.
269\(Type \\[describe-mode] in the process buffer for a list of commands.)"
270 (interactive)
271 (cond ((not (comint-check-proc "*cmulisp*"))
272 (set-buffer (make-comint "cmulisp" inferior-lisp-program))
273 (cmulisp-mode)))
274 (setq cmulisp-buffer "*cmulisp*")
275 (switch-to-buffer "*cmulisp*"))
276
277(defun lisp-eval-region (start end)
278 "Send the current region to the inferior Lisp process."
279 (interactive "r")
280 (comint-send-region (cmulisp-proc) start end)
281 (comint-send-string (cmulisp-proc) "\n"))
282
283(defun lisp-eval-defun ()
284 "Send the current defun to the inferior Lisp process."
285 (interactive)
286 (save-excursion
287 (end-of-defun)
288 (let ((end (point)))
289 (beginning-of-defun)
290 (lisp-eval-region (point) end))))
291
292(defun lisp-eval-last-sexp ()
293 "Send the previous sexp to the inferior Lisp process."
294 (interactive)
295 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point)))
296
297;;; CommonLisp COMPILE sux.
298(defun lisp-compile-region (start end)
299 "Compile the current region in the inferior Lisp process."
300 (interactive "r")
301 (comint-send-string (cmulisp-proc)
302 (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n"
303 (buffer-substring start end))))
304
305(defun lisp-compile-defun ()
306 "Compile the current defun in the inferior Lisp process."
307 (interactive)
308 (save-excursion
309 (end-of-defun)
310 (let ((e (point)))
311 (beginning-of-defun)
312 (lisp-compile-region (point) e))))
313
314(defun switch-to-lisp (eob-p)
315 "Switch to the inferior Lisp process buffer.
316With argument, positions cursor at end of buffer."
317 (interactive "P")
318 (if (get-buffer cmulisp-buffer)
319 (pop-to-buffer cmulisp-buffer)
320 (error "No current process buffer. See variable cmulisp-buffer."))
321 (cond (eob-p
322 (push-mark)
323 (goto-char (point-max)))))
324
325(defun lisp-eval-region-and-go (start end)
326 "Send the current region to the inferior Lisp,
327and switch to the process buffer."
328 (interactive "r")
329 (lisp-eval-region start end)
330 (switch-to-lisp t))
331
332(defun lisp-eval-defun-and-go ()
333 "Send the current defun to the inferior Lisp,
334and switch to the process buffer."
335 (interactive)
336 (lisp-eval-defun)
337 (switch-to-lisp t))
338
339(defun lisp-compile-region-and-go (start end)
340 "Compile the current region in the inferior Lisp,
341and switch to the process buffer."
342 (interactive "r")
343 (lisp-compile-region start end)
344 (switch-to-lisp t))
345
346(defun lisp-compile-defun-and-go ()
347 "Compile the current defun in the inferior Lisp,
348and switch to the process buffer."
349 (interactive)
350 (lisp-compile-defun)
351 (switch-to-lisp t))
352
353;;; A version of the form in H. Shevis' soar-mode.el package. Less robust.
354;(defun lisp-compile-sexp (start end)
355; "Compile the s-expression bounded by START and END in the inferior lisp.
356;If the sexp isn't a DEFUN form, it is evaluated instead."
357; (cond ((looking-at "(defun\\s +")
358; (goto-char (match-end 0))
359; (let ((name-start (point)))
360; (forward-sexp 1)
361; (process-send-string "cmulisp" (format "(compile '%s #'(lambda "
362; (buffer-substring name-start
363; (point)))))
364; (let ((body-start (point)))
365; (goto-char start) (forward-sexp 1) ; Can't use end-of-defun.
366; (process-send-region "cmulisp" (buffer-substring body-start (point))))
367; (process-send-string "cmulisp" ")\n"))
368; (t (lisp-eval-region start end)))))
369;
370;(defun lisp-compile-region (start end)
371; "Each s-expression in the current region is compiled (if a DEFUN)
372;or evaluated (if not) in the inferior lisp."
373; (interactive "r")
374; (save-excursion
375; (goto-char start) (end-of-defun) (beginning-of-defun) ; error check
376; (if (< (point) start) (error "region begins in middle of defun"))
377; (goto-char start)
378; (let ((s start))
379; (end-of-defun)
380; (while (<= (point) end) ; Zip through
381; (lisp-compile-sexp s (point)) ; compiling up defun-sized chunks.
382; (setq s (point))
383; (end-of-defun))
384; (if (< s end) (lisp-compile-sexp s end)))))
385;;;
386;;; End of HS-style code
387
388
389(defvar lisp-prev-l/c-dir/file nil
390 "Saves the (directory . file) pair used in the last lisp-load-file or
391lisp-compile-file command. Used for determining the default in the
392next one.")
393
394(defvar lisp-source-modes '(lisp-mode)
395 "*Used to determine if a buffer contains Lisp source code.
396If it's loaded into a buffer that is in one of these major modes, it's
397considered a Lisp source file by lisp-load-file and lisp-compile-file.
398Used by these commands to determine defaults.")
399
400(defun lisp-load-file (file-name)
401 "Load a Lisp file into the inferior Lisp process."
402 (interactive (comint-get-source "Load Lisp file: " lisp-prev-l/c-dir/file
403 lisp-source-modes nil)) ; NIL because LOAD
404 ; doesn't need an exact name
405 (comint-check-source file-name) ; Check to see if buffer needs saved.
406 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name)
407 (file-name-nondirectory file-name)))
408 (comint-send-string (cmulisp-proc)
409 (format inferior-lisp-load-command file-name)))
410
411
412(defun lisp-compile-file (file-name)
413 "Compile a Lisp file in the inferior Lisp process."
414 (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l/c-dir/file
415 lisp-source-modes nil)) ; NIL = don't need
416 ; suffix .lisp
417 (comint-check-source file-name) ; Check to see if buffer needs saved.
418 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name)
419 (file-name-nondirectory file-name)))
420 (comint-send-string (cmulisp-proc) (concat "(compile-file \""
421 file-name
422 "\"\)\n")))
423
424
425\f
426;;; Documentation functions: function doc, var doc, arglist, and
427;;; describe symbol.
428;;; ===========================================================================
429
430;;; Command strings
431;;; ===============
432
433(defvar lisp-function-doc-command
434 "(let ((fn '%s))
435 (format t \"Documentation for ~a:~&~a\"
436 fn (documentation fn 'function))
437 (values))\n"
438 "Command to query inferior Lisp for a function's documentation.")
439
440(defvar lisp-var-doc-command
441 "(let ((v '%s))
442 (format t \"Documentation for ~a:~&~a\"
443 v (documentation v 'variable))
444 (values))\n"
445 "Command to query inferior Lisp for a variable's documentation.")
446
447(defvar lisp-arglist-command
448 "(let ((fn '%s))
449 (format t \"Arglist for ~a: ~a\" fn (arglist fn))
450 (values))\n"
451 "Command to query inferior Lisp for a function's arglist.")
452
453(defvar lisp-describe-sym-command
454 "(describe '%s)\n"
455 "Command to query inferior Lisp for a variable's documentation.")
456
457
458;;; Ancillary functions
459;;; ===================
460
461;;; Reads a string from the user.
462(defun lisp-symprompt (prompt default)
463 (list (let* ((prompt (if default
464 (format "%s (default %s): " prompt default)
465 (concat prompt ": ")))
466 (ans (read-string prompt)))
467 (if (zerop (length ans)) default ans))))
468
469
470;;; Adapted from function-called-at-point in help.el.
471(defun lisp-fn-called-at-pt ()
472 "Returns the name of the function called in the current call.
473Nil if it can't find one."
474 (condition-case nil
475 (save-excursion
476 (save-restriction
477 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
478 (backward-up-list 1)
479 (forward-char 1)
480 (let ((obj (read (current-buffer))))
481 (and (symbolp obj) obj))))
482 (error nil)))
483
484
485;;; Adapted from variable-at-point in help.el.
486(defun lisp-var-at-pt ()
487 (condition-case ()
488 (save-excursion
489 (forward-sexp -1)
490 (skip-chars-forward "'")
491 (let ((obj (read (current-buffer))))
492 (and (symbolp obj) obj)))
493 (error nil)))
494
495
496;;; Documentation functions: fn and var doc, arglist, and symbol describe.
497;;; ======================================================================
498
499(defun lisp-show-function-documentation (fn)
500 "Send a command to the inferior Lisp to give documentation for function FN.
501See variable lisp-function-doc-command."
502 (interactive (lisp-symprompt "Function doc" (lisp-fn-called-at-pt)))
503 (comint-proc-query (cmulisp-proc) (format lisp-function-doc-command fn)))
504
505(defun lisp-show-variable-documentation (var)
506 "Send a command to the inferior Lisp to give documentation for function FN.
507See variable lisp-var-doc-command."
508 (interactive (lisp-symprompt "Variable doc" (lisp-var-at-pt)))
509 (comint-proc-query (cmulisp-proc) (format lisp-var-doc-command var)))
510
511(defun lisp-show-arglist (fn)
512 "Sends an query to the inferior Lisp for the arglist for function FN.
513See variable lisp-arglist-command."
514 (interactive (lisp-symprompt "Arglist" (lisp-fn-called-at-pt)))
515 (comint-proc-query (cmulisp-proc) (format lisp-arglist-command fn)))
516
517(defun lisp-describe-sym (sym)
518 "Send a command to the inferior Lisp to describe symbol SYM.
519See variable lisp-describe-sym-command."
520 (interactive (lisp-symprompt "Describe" (lisp-var-at-pt)))
521 (comint-proc-query (cmulisp-proc) (format lisp-describe-sym-command sym)))
522
523\f
524(defvar cmulisp-buffer nil "*The current cmulisp process buffer.
525
526MULTIPLE PROCESS SUPPORT
527===========================================================================
528Cmulisp.el supports, in a fairly simple fashion, running multiple Lisp
529processes. To run multiple Lisp processes, you start the first up with
530\\[cmulisp]. It will be in a buffer named *cmulisp*. Rename this buffer
531with \\[rename-buffer]. You may now start up a new process with another
532\\[cmulisp]. It will be in a new buffer, named *cmulisp*. You can
533switch between the different process buffers with \\[switch-to-buffer].
534
535Commands that send text from source buffers to Lisp processes --
536like lisp-eval-defun or lisp-show-arglist -- have to choose a process
537to send to, when you have more than one Lisp process around. This
538is determined by the global variable cmulisp-buffer. Suppose you
539have three inferior lisps running:
540 Buffer Process
541 foo cmulisp
542 bar cmulisp<2>
543 *cmulisp* cmulisp<3>
544If you do a \\[lisp-eval-defun-and-go] command on some Lisp source code,
545what process do you send it to?
546
547- If you're in a process buffer (foo, bar, or *cmulisp*),
548 you send it to that process.
549- If you're in some other buffer (e.g., a source file), you
550 send it to the process attached to buffer cmulisp-buffer.
551This process selection is performed by function cmulisp-proc.
552
553Whenever \\[cmulisp] fires up a new process, it resets cmulisp-buffer
554to be the new process's buffer. If you only run one process, this will
555do the right thing. If you run multiple processes, you can change
556cmulisp-buffer to another process buffer with \\[set-variable].
557
558More sophisticated approaches are, of course, possible. If you find youself
559needing to switch back and forth between multiple processes frequently,
560you may wish to consider ilisp.el, a larger, more sophisticated package
561for running inferior Lisp processes. The approach taken here is for a
562minimal, simple implementation. Feel free to extend it.")
563
564(defun cmulisp-proc ()
565 "Returns the current cmulisp process. See variable cmulisp-buffer."
566 (let ((proc (get-buffer-process (if (eq major-mode 'inferior-lisp-mode)
567 (current-buffer)
568 cmulisp-buffer))))
569 (or proc
570 (error "No current process. See variable cmulisp-buffer"))))
571
572
573;;; Do the user's customisation...
574;;;===============================
575(defvar cmulisp-load-hook nil
576 "This hook is run when cmulisp is loaded in.
577This is a good place to put keybindings.")
578
579(run-hooks 'cmulisp-load-hook)
580
581;;; CHANGE LOG
582;;; ===========================================================================
583;;; 5/24/90 Olin
584;;; - Split cmulisp and cmushell modes into separate files.
585;;; Not only is this a good idea, it's apparently the way it'll be rel 19.
586;;; - Upgraded process sends to use comint-send-string instead of
587;;; process-send-string.
588;;; - Explicit references to process "cmulisp" have been replaced with
589;;; (cmulisp-proc). This allows better handling of multiple process bufs.
590;;; - Added process query and var/function/symbol documentation
591;;; commands. Based on code written by Douglas Roberts.
592;;; - Added lisp-eval-last-sexp, bound to C-x C-e.
593;;;
594;;; 9/20/90 Olin
595;;; Added a save-restriction to lisp-fn-called-at-pt. This bug and fix
596;;; reported by Lennart Staflin.
597;;;
598;;; 3/12/90 Olin
599;;; - lisp-load-file and lisp-compile-file no longer switch-to-lisp.
600;;; Tale suggested this.
49116ac0
JB
601
602(provide 'cmulisp)
603
c0274f38 604;;; cmulisp.el ends here