*** empty log message ***
[emacs.git] / lisp / progmodes / inf-lisp.el
blobb1f953febf5a8257b0adc8f58ac8c46baa51931f
1 ;;; inf-lisp.el --- an inferior-lisp mode
3 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
4 ;; Last-Modified: 16 Jul 1992
5 ;; Keyword: processes, lisp
7 ;;; Copyright Olin Shivers (1988).
9 ;;; This file is part of GNU Emacs.
11 ;;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;;; it under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 2, or (at your option)
14 ;;; any later version.
16 ;;; GNU Emacs is distributed in the hope that it will be useful,
17 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 ;;; Commentary:
27 ;;; Hacked from tea.el by Olin Shivers (shivers@cs.cmu.edu). 8/88
29 ;;; This file defines a a lisp-in-a-buffer package (inferior-lisp
30 ;;; mode) built on top of comint mode. This version is more
31 ;;; featureful, robust, and uniform than the Emacs 18 version. The
32 ;;; key bindings are also more compatible with the bindings of Hemlock
33 ;;; and Zwei (the Lisp Machine emacs).
35 ;;; Since this mode is built on top of the general command-interpreter-in-
36 ;;; a-buffer mode (comint mode), it shares a common base functionality,
37 ;;; and a common set of bindings, with all modes derived from comint mode.
38 ;;; This makes these modes easier to use.
40 ;;; For documentation on the functionality provided by comint mode, and
41 ;;; the hooks available for customising it, see the file comint.el.
42 ;;; For further information on inferior-lisp mode, see the comments below.
44 ;;; Needs fixin:
45 ;;; The load-file/compile-file default mechanism could be smarter -- it
46 ;;; doesn't know about the relationship between filename extensions and
47 ;;; whether the file is source or executable. If you compile foo.lisp
48 ;;; with compile-file, then the next load-file should use foo.bin for
49 ;;; the default, not foo.lisp. This is tricky to do right, particularly
50 ;;; because the extension for executable files varies so much (.o, .bin,
51 ;;; .lbin, .mo, .vo, .ao, ...).
52 ;;;
53 ;;; It would be nice if inferior-lisp (and inferior scheme, T, ...) modes
54 ;;; had a verbose minor mode wherein sending or compiling defuns, etc.
55 ;;; would be reflected in the transcript with suitable comments, e.g.
56 ;;; ";;; redefining fact". Several ways to do this. Which is right?
57 ;;;
58 ;;; When sending text from a source file to a subprocess, the process-mark can
59 ;;; move off the window, so you can lose sight of the process interactions.
60 ;;; Maybe I should ensure the process mark is in the window when I send
61 ;;; text to the process? Switch selectable?
63 ;; YOUR .EMACS FILE
64 ;;=============================================================================
65 ;; Some suggestions for your .emacs file.
67 ;; ; If inferior-lisp lives in some non-standard directory, you must tell emacs
68 ;; ; where to get it. This may or may not be necessary.
69 ;; (setq load-path (cons (expand-file-name "~jones/lib/emacs") load-path))
71 ;; ; Autoload inferior-lisp from file inf-lisp.el
72 ;; (autoload 'inferior-lisp "inferior-lisp"
73 ;; "Run an inferior Lisp process."
74 ;; t)
76 ;; ; Define C-c t to run my favorite command in inferior-lisp mode:
77 ;; (setq inferior-lisp-load-hook
78 ;; '((lambda ()
79 ;; (define-key inferior-lisp-mode-map "\C-ct" 'favorite-cmd))))
82 ;;; Brief Command Documentation:
83 ;;;============================================================================
84 ;;; Comint Mode Commands: (common to inferior-lisp and all
85 ;;; comint-derived modes)
86 ;;;
87 ;;; m-p comint-previous-input Cycle backwards in input history
88 ;;; m-n comint-next-input Cycle forwards
89 ;;; m-c-r comint-previous-input-matching Search backwards in input history
90 ;;; return comint-send-input
91 ;;; c-a comint-bol Beginning of line; skip prompt.
92 ;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff.
93 ;;; c-c c-u comint-kill-input ^u
94 ;;; c-c c-w backward-kill-word ^w
95 ;;; c-c c-c comint-interrupt-subjob ^c
96 ;;; c-c c-z comint-stop-subjob ^z
97 ;;; c-c c-\ comint-quit-subjob ^\
98 ;;; c-c c-o comint-kill-output Delete last batch of process output
99 ;;; c-c c-r comint-show-output Show last batch of process output
100 ;;; send-invisible Read line w/o echo & send to proc
101 ;;; comint-continue-subjob Useful if you accidentally suspend
102 ;;; top-level job.
103 ;;; comint-mode-hook is the comint mode hook.
105 ;;; Inferior Lisp Mode Commands:
106 ;;; c-m-x lisp-send-defun This binding is a gnu convention.
107 ;;; c-c c-l lisp-load-file Prompt for file name; tell Lisp to load it.
108 ;;; c-c c-k lisp-compile-file Prompt for file name; tell Lisp to kompile it.
109 ;;; Filename completion is available, of course.
111 ;;; Additionally, these commands are added to the key bindings of Lisp mode:
112 ;;; c-m-x lisp-eval-defun This binding is a gnu convention.
113 ;;; c-c c-e lisp-eval-defun Send the current defun to Lisp process.
114 ;;; c-x c-e lisp-eval-last-sexp Send the previous sexp to Lisp process.
115 ;;; c-c c-r lisp-eval-region Send the current region to Lisp process.
116 ;;; c-c c-c lisp-compile-defun Compile the current defun in Lisp process.
117 ;;; c-c c-z switch-to-lisp Switch to the Lisp process buffer.
118 ;;; c-c c-l lisp-load-file (See above. In a Lisp file buffer, default
119 ;;; c-c c-k lisp-compile-file is to load/compile the current file.)
120 ;;; c-c c-d lisp-describe-sym Query Lisp for a symbol's description.
121 ;;; c-c c-a lisp-show-arglist Query Lisp for function's arglist.
122 ;;; c-c c-f lisp-show-function-documentation Query Lisp for a function's doc.
123 ;;; c-c c-v lisp-show-variable-documentation Query Lisp for a variable's doc.
125 ;;; inferior-lisp Fires up the Lisp process.
126 ;;; lisp-compile-region Compile all forms in the current region.
128 ;;; Inferior Lisp Mode Variables:
129 ;;; inferior-lisp-filter-regexp Match this => don't get saved on input hist
130 ;;; inferior-lisp-program Name of Lisp program run-lisp executes
131 ;;; inferior-lisp-load-command Customises lisp-load-file
132 ;;; inferior-lisp-mode-hook
133 ;;; inferior-lisp-prompt Initialises comint-prompt-regexp.
134 ;;; Backwards compatibility.
135 ;;; lisp-source-modes Anything loaded into a buffer that's in
136 ;;; one of these modes is considered Lisp
137 ;;; source by lisp-load/compile-file.
139 ;;; Read the rest of this file for more information.
141 ;;; Code:
143 (require 'comint)
144 (require 'lisp-mode)
147 (defvar inferior-lisp-filter-regexp "\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'"
148 "*What not to save on inferior Lisp's input history
149 Input matching this regexp is not saved on the input history in inferior-lisp
150 mode. Default is whitespace followed by 0 or 1 single-letter :keyword
151 (as in :a, :c, etc.)")
153 (defvar inferior-lisp-mode-map nil)
154 (cond ((not inferior-lisp-mode-map)
155 (setq inferior-lisp-mode-map
156 (full-copy-sparse-keymap comint-mode-map))
157 (setq inferior-lisp-mode-map
158 (nconc inferior-lisp-mode-map shared-lisp-mode-map))
159 (define-key inferior-lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp)
160 (define-key inferior-lisp-mode-map "\C-c\C-l" 'lisp-load-file)
161 (define-key inferior-lisp-mode-map "\C-c\C-k" 'lisp-compile-file)
162 (define-key inferior-lisp-mode-map "\C-c\C-a" 'lisp-show-arglist)
163 (define-key inferior-lisp-mode-map "\C-c\C-d" 'lisp-describe-sym)
164 (define-key inferior-lisp-mode-map "\C-c\C-f"
165 'lisp-show-function-documentation)
166 (define-key inferior-lisp-mode-map "\C-c\C-v"
167 'lisp-show-variable-documentation)))
169 ;;; These commands augment Lisp mode, so you can process Lisp code in
170 ;;; the source files.
171 (define-key lisp-mode-map "\M-\C-x" 'lisp-eval-defun) ; Gnu convention
172 (define-key lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp) ; Gnu convention
173 (define-key lisp-mode-map "\C-c\C-e" 'lisp-eval-defun)
174 (define-key lisp-mode-map "\C-c\C-r" 'lisp-eval-region)
175 (define-key lisp-mode-map "\C-c\C-c" 'lisp-compile-defun)
176 (define-key lisp-mode-map "\C-c\C-z" 'switch-to-lisp)
177 (define-key lisp-mode-map "\C-c\C-l" 'lisp-load-file)
178 (define-key lisp-mode-map "\C-c\C-k" 'lisp-compile-file) ; "kompile" file
179 (define-key lisp-mode-map "\C-c\C-a" 'lisp-show-arglist)
180 (define-key lisp-mode-map "\C-c\C-d" 'lisp-describe-sym)
181 (define-key lisp-mode-map "\C-c\C-f" 'lisp-show-function-documentation)
182 (define-key lisp-mode-map "\C-c\C-v" 'lisp-show-variable-documentation)
185 ;;; This function exists for backwards compatibility.
186 ;;; Previous versions of this package bound commands to C-c <letter>
187 ;;; bindings, which is not allowed by the gnumacs standard.
189 (defun inferior-lisp-install-letter-bindings ()
190 "This function binds many inferior-lisp commands to C-c <letter> bindings,
191 where they are more accessible. C-c <letter> bindings are reserved for the
192 user, so these bindings are non-standard. If you want them, you should
193 have this function called by the inferior-lisp-load-hook:
194 (setq inferior-lisp-load-hook '(inferior-lisp-install-letter-bindings))
195 You can modify this function to install just the bindings you want."
197 (define-key lisp-mode-map "\C-ce" 'lisp-eval-defun-and-go)
198 (define-key lisp-mode-map "\C-cr" 'lisp-eval-region-and-go)
199 (define-key lisp-mode-map "\C-cc" 'lisp-compile-defun-and-go)
200 (define-key lisp-mode-map "\C-cz" 'switch-to-lisp)
201 (define-key lisp-mode-map "\C-cl" 'lisp-load-file)
202 (define-key lisp-mode-map "\C-ck" 'lisp-compile-file)
203 (define-key lisp-mode-map "\C-ca" 'lisp-show-arglist)
204 (define-key lisp-mode-map "\C-cd" 'lisp-describe-sym)
205 (define-key lisp-mode-map "\C-cf" 'lisp-show-function-documentation)
206 (define-key lisp-mode-map "\C-cv" 'lisp-show-variable-documentation)
208 (define-key inferior-lisp-mode-map "\C-cl" 'lisp-load-file)
209 (define-key inferior-lisp-mode-map "\C-ck" 'lisp-compile-file)
210 (define-key inferior-lisp-mode-map "\C-ca" 'lisp-show-arglist)
211 (define-key inferior-lisp-mode-map "\C-cd" 'lisp-describe-sym)
212 (define-key inferior-lisp-mode-map "\C-cf" 'lisp-show-function-documentation)
213 (define-key inferior-lisp-mode-map "\C-cv"
214 'lisp-show-variable-documentation))
217 (defvar inferior-lisp-program "lisp"
218 "*Program name for invoking an inferior Lisp with `inferior-lisp'.")
220 (defvar inferior-lisp-load-command "(load \"%s\")\n"
221 "*Format-string for building a Lisp expression to load a file.
222 This format string should use %s to substitute a file name
223 and should result in a Lisp expression that will command the inferior Lisp
224 to load that file. The default works acceptably on most Lisps.
225 The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\\n\"
226 produces cosmetically superior output for this application,
227 but it works only in Common Lisp.")
229 (defvar inferior-lisp-prompt "^[^> ]*>+:? *"
230 "Regexp to recognise prompts in the inferior Lisp.
231 Defaults to \"^[^> ]*>+:? *\", which works pretty good for Lucid, kcl,
232 and franz. This variable is used to initialise comint-prompt-regexp in the
233 inferior-lisp buffer.
235 More precise choices:
236 Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\"
237 franz: \"^\\(->\\|<[0-9]*>:\\) *\"
238 kcl: \"^>+ *\"
240 This is a fine thing to set in your .emacs file.")
242 (defvar inferior-lisp-mode-hook '()
243 "*Hook for customising inferior-lisp mode")
245 (defun inferior-lisp-mode ()
246 "Major mode for interacting with an inferior Lisp process.
247 Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an
248 Emacs buffer. Variable inferior-lisp-program controls which Lisp interpreter
249 is run. Variables inferior-lisp-prompt, inferior-lisp-filter-regexp and
250 inferior-lisp-load-command can customize this mode for different Lisp
251 interpreters.
253 For information on running multiple processes in multiple buffers, see
254 documentation for variable inferior-lisp-buffer.
256 \\{inferior-lisp-mode-map}
258 Customisation: Entry to this mode runs the hooks on comint-mode-hook and
259 inferior-lisp-mode-hook (in that order).
261 You can send text to the inferior Lisp process from other buffers containing
262 Lisp source.
263 switch-to-lisp switches the current buffer to the Lisp process buffer.
264 lisp-eval-defun sends the current defun to the Lisp process.
265 lisp-compile-defun compiles the current defun.
266 lisp-eval-region sends the current region to the Lisp process.
267 lisp-compile-region compiles the current region.
269 Prefixing the lisp-eval/compile-defun/region commands with
270 a \\[universal-argument] causes a switch to the Lisp process buffer after sending
271 the text.
273 Commands:
274 Return after the end of the process' output sends the text from the
275 end of process to point.
276 Return before the end of the process' output copies the sexp ending at point
277 to the end of the process' output, and sends it.
278 Delete converts tabs to spaces as it moves back.
279 Tab indents for Lisp; with argument, shifts rest
280 of expression rigidly with the current line.
281 C-M-q does Tab on each line starting within following expression.
282 Paragraphs are separated only by blank lines. Semicolons start comments.
283 If you accidentally suspend your process, use \\[comint-continue-subjob]
284 to continue it."
285 (interactive)
286 (comint-mode)
287 (setq comint-prompt-regexp inferior-lisp-prompt)
288 (setq major-mode 'inferior-lisp-mode)
289 (setq mode-name "Inferior Lisp")
290 (setq mode-line-process '(": %s"))
291 (lisp-mode-variables t)
292 (use-local-map inferior-lisp-mode-map) ;c-c c-k for "kompile" file
293 (setq comint-get-old-input (function lisp-get-old-input))
294 (setq comint-input-filter (function lisp-input-filter))
295 (setq comint-input-sentinel 'ignore)
296 (run-hooks 'inferior-lisp-mode-hook))
298 (defun lisp-get-old-input ()
299 "Snarf the sexp ending at point"
300 (save-excursion
301 (let ((end (point)))
302 (backward-sexp)
303 (buffer-substring (point) end))))
305 (defun lisp-input-filter (str)
306 "Don't save anything matching inferior-lisp-filter-regexp"
307 (not (string-match inferior-lisp-filter-regexp str)))
309 (defun inferior-lisp (cmd)
310 "Run an inferior Lisp process, input and output via buffer *inferior-lisp*.
311 If there is a process already running in *inferior-lisp*, just switch
312 to that buffer.
313 With argument, allows you to edit the command line (default is value
314 of inferior-lisp-program). Runs the hooks from
315 inferior-lisp-mode-hook (after the comint-mode-hook is run).
316 \(Type \\[describe-mode] in the process buffer for a list of commands.)"
317 (interactive (list (if current-prefix-arg
318 (read-string "Run lisp: " inferior-lisp-program)
319 inferior-lisp-program)))
320 (if (not (comint-check-proc "*inferior-lisp*"))
321 (let ((cmdlist (inferior-lisp-args-to-list cmd)))
322 (set-buffer (apply (function make-comint)
323 "inferior-lisp" (car cmdlist) nil (cdr cmdlist)))
324 (inferior-lisp-mode)))
325 (setq inferior-lisp-buffer "*inferior-lisp*")
326 (switch-to-buffer "*inferior-lisp*"))
328 (fset 'run-lisp 'inferior-lisp)
330 ;;; Break a string up into a list of arguments.
331 ;;; This will break if you have an argument with whitespace, as in
332 ;;; string = "-ab +c -x 'you lose'".
333 (defun inferior-lisp-args-to-list (string)
334 (let ((where (string-match "[ \t]" string)))
335 (cond ((null where) (list string))
336 ((not (= where 0))
337 (cons (substring string 0 where)
338 (inferior-lisp-args-to-list (substring string (+ 1 where)
339 (length string)))))
340 (t (let ((pos (string-match "[^ \t]" string)))
341 (if (null pos)
343 (inferior-lisp-args-to-list (substring string pos
344 (length string)))))))))
346 (defun lisp-eval-region (start end &optional and-go)
347 "Send the current region to the inferior Lisp process.
348 Prefix argument means switch-to-lisp afterwards."
349 (interactive "r\nP")
350 (comint-send-region (inferior-lisp-proc) start end)
351 (comint-send-string (inferior-lisp-proc) "\n")
352 (if and-go (switch-to-lisp t)))
354 (defun lisp-eval-defun (&optional and-go)
355 "Send the current defun to the inferior Lisp process.
356 Prefix argument means switch-to-lisp afterwards."
357 (interactive "P")
358 (save-excursion
359 (end-of-defun)
360 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
361 (let ((end (point)))
362 (beginning-of-defun)
363 (lisp-eval-region (point) end)))
364 (if and-go (switch-to-lisp t)))
366 (defun lisp-eval-last-sexp (&optional and-go)
367 "Send the previous sexp to the inferior Lisp process.
368 Prefix argument means switch-to-lisp afterwards."
369 (interactive "P")
370 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go))
372 ;;; Common Lisp COMPILE sux.
373 (defun lisp-compile-region (start end &optional and-go)
374 "Compile the current region in the inferior Lisp process.
375 Prefix argument means switch-to-lisp afterwards."
376 (interactive "r\nP")
377 (comint-send-string
378 (inferior-lisp-proc)
379 (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n"
380 (buffer-substring start end)))
381 (if and-go (switch-to-lisp t)))
383 (defun lisp-compile-defun (&optional and-go)
384 "Compile the current defun in the inferior Lisp process.
385 Prefix argument means switch-to-lisp afterwards."
386 (interactive "P")
387 (save-excursion
388 (end-of-defun)
389 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
390 (let ((e (point)))
391 (beginning-of-defun)
392 (lisp-compile-region (point) e)))
393 (if and-go (switch-to-lisp t)))
395 (defun switch-to-lisp (eob-p)
396 "Switch to the inferior Lisp process buffer.
397 With argument, positions cursor at end of buffer."
398 (interactive "P")
399 (if (get-buffer inferior-lisp-buffer)
400 (pop-to-buffer inferior-lisp-buffer)
401 (error "No current process buffer. See variable inferior-lisp-buffer."))
402 (cond (eob-p
403 (push-mark)
404 (goto-char (point-max)))))
407 ;;; Now that lisp-compile/eval-defun/region takes an optional prefix arg,
408 ;;; these commands are redundant. But they are kept around for the user
409 ;;; to bind if he wishes, for backwards functionality, and because it's
410 ;;; easier to type C-c e than C-u C-c C-e.
412 (defun lisp-eval-region-and-go (start end)
413 "Send the current region to the inferior Lisp,
414 and switch to the process buffer."
415 (interactive "r")
416 (lisp-eval-region start end t))
418 (defun lisp-eval-defun-and-go ()
419 "Send the current defun to the inferior Lisp,
420 and switch to the process buffer."
421 (interactive)
422 (lisp-eval-defun t))
424 (defun lisp-compile-region-and-go (start end)
425 "Compile the current region in the inferior Lisp,
426 and switch to the process buffer."
427 (interactive "r")
428 (lisp-compile-region start end t))
430 (defun lisp-compile-defun-and-go ()
431 "Compile the current defun in the inferior Lisp,
432 and switch to the process buffer."
433 (interactive)
434 (lisp-compile-defun t))
436 ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust.
437 ;;; (defun lisp-compile-sexp (start end)
438 ;;; "Compile the s-expression bounded by START and END in the inferior lisp.
439 ;;; If the sexp isn't a DEFUN form, it is evaluated instead."
440 ;;; (cond ((looking-at "(defun\\s +")
441 ;;; (goto-char (match-end 0))
442 ;;; (let ((name-start (point)))
443 ;;; (forward-sexp 1)
444 ;;; (process-send-string "inferior-lisp"
445 ;;; (format "(compile '%s #'(lambda "
446 ;;; (buffer-substring name-start
447 ;;; (point)))))
448 ;;; (let ((body-start (point)))
449 ;;; (goto-char start) (forward-sexp 1) ; Can't use end-of-defun.
450 ;;; (process-send-region "inferior-lisp"
451 ;;; (buffer-substring body-start (point))))
452 ;;; (process-send-string "inferior-lisp" ")\n"))
453 ;;; (t (lisp-eval-region start end)))))
454 ;;;
455 ;;; (defun lisp-compile-region (start end)
456 ;;; "Each s-expression in the current region is compiled (if a DEFUN)
457 ;;; or evaluated (if not) in the inferior lisp."
458 ;;; (interactive "r")
459 ;;; (save-excursion
460 ;;; (goto-char start) (end-of-defun) (beginning-of-defun) ; error check
461 ;;; (if (< (point) start) (error "region begins in middle of defun"))
462 ;;; (goto-char start)
463 ;;; (let ((s start))
464 ;;; (end-of-defun)
465 ;;; (while (<= (point) end) ; Zip through
466 ;;; (lisp-compile-sexp s (point)) ; compiling up defun-sized chunks.
467 ;;; (setq s (point))
468 ;;; (end-of-defun))
469 ;;; (if (< s end) (lisp-compile-sexp s end)))))
470 ;;;
471 ;;; End of HS-style code
474 (defvar lisp-prev-l/c-dir/file nil
475 "Saves the (directory . file) pair used in the last lisp-load-file or
476 lisp-compile-file command. Used for determining the default in the
477 next one.")
479 (defvar lisp-source-modes '(lisp-mode)
480 "*Used to determine if a buffer contains Lisp source code.
481 If it's loaded into a buffer that is in one of these major modes, it's
482 considered a Lisp source file by lisp-load-file and lisp-compile-file.
483 Used by these commands to determine defaults.")
485 (defun lisp-load-file (file-name)
486 "Load a Lisp file into the inferior Lisp process."
487 (interactive (comint-get-source "Load Lisp file: " lisp-prev-l/c-dir/file
488 lisp-source-modes nil)) ; NIL because LOAD
489 ; doesn't need an exact name
490 (comint-check-source file-name) ; Check to see if buffer needs saved.
491 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name)
492 (file-name-nondirectory file-name)))
493 (comint-send-string (inferior-lisp-proc)
494 (format inferior-lisp-load-command file-name))
495 (switch-to-lisp t))
498 (defun lisp-compile-file (file-name)
499 "Compile a Lisp file in the inferior Lisp process."
500 (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l/c-dir/file
501 lisp-source-modes nil)) ; NIL = don't need
502 ; suffix .lisp
503 (comint-check-source file-name) ; Check to see if buffer needs saved.
504 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name)
505 (file-name-nondirectory file-name)))
506 (comint-send-string (inferior-lisp-proc) (concat "(compile-file \""
507 file-name
508 "\"\)\n"))
509 (switch-to-lisp t))
513 ;;; Documentation functions: function doc, var doc, arglist, and
514 ;;; describe symbol.
515 ;;; ===========================================================================
517 ;;; Command strings
518 ;;; ===============
520 (defvar lisp-function-doc-command
521 "(let ((fn '%s))
522 (format t \"Documentation for ~a:~&~a\"
523 fn (documentation fn 'function))
524 (values))\n"
525 "Command to query inferior Lisp for a function's documentation.")
527 (defvar lisp-var-doc-command
528 "(let ((v '%s))
529 (format t \"Documentation for ~a:~&~a\"
530 v (documentation v 'variable))
531 (values))\n"
532 "Command to query inferior Lisp for a variable's documentation.")
534 (defvar lisp-arglist-command
535 "(let ((fn '%s))
536 (format t \"Arglist for ~a: ~a\" fn (arglist fn))
537 (values))\n"
538 "Command to query inferior Lisp for a function's arglist.")
540 (defvar lisp-describe-sym-command
541 "(describe '%s)\n"
542 "Command to query inferior Lisp for a variable's documentation.")
545 ;;; Ancillary functions
546 ;;; ===================
548 ;;; Reads a string from the user.
549 (defun lisp-symprompt (prompt default)
550 (list (let* ((prompt (if default
551 (format "%s (default %s): " prompt default)
552 (concat prompt ": ")))
553 (ans (read-string prompt)))
554 (if (zerop (length ans)) default ans))))
557 ;;; Adapted from function-called-at-point in help.el.
558 (defun lisp-fn-called-at-pt ()
559 "Returns the name of the function called in the current call.
560 Nil if it can't find one."
561 (condition-case nil
562 (save-excursion
563 (save-restriction
564 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
565 (backward-up-list 1)
566 (forward-char 1)
567 (let ((obj (read (current-buffer))))
568 (and (symbolp obj) obj))))
569 (error nil)))
572 ;;; Adapted from variable-at-point in help.el.
573 (defun lisp-var-at-pt ()
574 (condition-case ()
575 (save-excursion
576 (forward-sexp -1)
577 (skip-chars-forward "'")
578 (let ((obj (read (current-buffer))))
579 (and (symbolp obj) obj)))
580 (error nil)))
583 ;;; Documentation functions: fn and var doc, arglist, and symbol describe.
584 ;;; ======================================================================
586 (defun lisp-show-function-documentation (fn)
587 "Send a command to the inferior Lisp to give documentation for function FN.
588 See variable lisp-function-doc-command."
589 (interactive (lisp-symprompt "Function doc" (lisp-fn-called-at-pt)))
590 (comint-proc-query (inferior-lisp-proc)
591 (format lisp-function-doc-command fn)))
593 (defun lisp-show-variable-documentation (var)
594 "Send a command to the inferior Lisp to give documentation for function FN.
595 See variable lisp-var-doc-command."
596 (interactive (lisp-symprompt "Variable doc" (lisp-var-at-pt)))
597 (comint-proc-query (inferior-lisp-proc) (format lisp-var-doc-command var)))
599 (defun lisp-show-arglist (fn)
600 "Sends an query to the inferior Lisp for the arglist for function FN.
601 See variable lisp-arglist-command."
602 (interactive (lisp-symprompt "Arglist" (lisp-fn-called-at-pt)))
603 (comint-proc-query (inferior-lisp-proc) (format lisp-arglist-command fn)))
605 (defun lisp-describe-sym (sym)
606 "Send a command to the inferior Lisp to describe symbol SYM.
607 See variable lisp-describe-sym-command."
608 (interactive (lisp-symprompt "Describe" (lisp-var-at-pt)))
609 (comint-proc-query (inferior-lisp-proc)
610 (format lisp-describe-sym-command sym)))
613 (defvar inferior-lisp-buffer nil "*The current inferior-lisp process buffer.
615 MULTIPLE PROCESS SUPPORT
616 ===========================================================================
617 Inf-lisp.el supports, in a fairly simple fashion, running multiple
618 Lisp processes. To run multiple Lisp processes, you start the first up
619 with \\[inferior-lisp]. It will be in a buffer named *inferior-lisp*.
620 Rename this buffer with \\[rename-buffer]. You may now start up a new
621 process with another \\[inferior-lisp]. It will be in a new buffer,
622 named *inferior-lisp*. You can switch between the different process
623 buffers with \\[switch-to-buffer].
625 Commands that send text from source buffers to Lisp processes --
626 like lisp-eval-defun or lisp-show-arglist -- have to choose a process
627 to send to, when you have more than one Lisp process around. This
628 is determined by the global variable inferior-lisp-buffer. Suppose you
629 have three inferior lisps running:
630 Buffer Process
631 foo inferior-lisp
632 bar inferior-lisp<2>
633 *inferior-lisp* inferior-lisp<3>
634 If you do a \\[lisp-eval-defun] command on some Lisp source code,
635 what process do you send it to?
637 - If you're in a process buffer (foo, bar, or *inferior-lisp*),
638 you send it to that process.
639 - If you're in some other buffer (e.g., a source file), you
640 send it to the process attached to buffer inferior-lisp-buffer.
641 This process selection is performed by function inferior-lisp-proc.
643 Whenever \\[inferior-lisp] fires up a new process, it resets
644 inferior-lisp-buffer to be the new process's buffer. If you only run
645 one process, this will do the right thing. If you run multiple
646 processes, you can change inferior-lisp-buffer to another process
647 buffer with \\[set-variable].
649 More sophisticated approaches are, of course, possible. If you find youself
650 needing to switch back and forth between multiple processes frequently,
651 you may wish to consider ilisp.el, a larger, more sophisticated package
652 for running inferior Lisp processes. The approach taken here is for a
653 minimal, simple implementation. Feel free to extend it.")
655 (defun inferior-lisp-proc ()
656 "Returns the current inferior-lisp process. See variable inferior-lisp-buffer."
657 (let ((proc (get-buffer-process (if (eq major-mode 'inferior-lisp-mode)
658 (current-buffer)
659 inferior-lisp-buffer))))
660 (or proc
661 (error "No current process. See variable inferior-lisp-buffer"))))
664 ;;; Do the user's customisation...
665 ;;;===============================
666 (defvar inferior-lisp-load-hook nil
667 "This hook is run when inferior-lisp is loaded in.
668 This is a good place to put keybindings.")
670 (run-hooks 'inferior-lisp-load-hook)
672 ;;; CHANGE LOG
673 ;;; ===========================================================================
674 ;;; 7/21/92 Jim Blandy
675 ;;; - Changed all uses of the cmulisp name or prefix to inferior-lisp;
676 ;;; this is now the official inferior lisp package. Use the global
677 ;;; ChangeLog from now on.
678 ;;; 5/24/90 Olin
679 ;;; - Split cmulisp and cmushell modes into separate files.
680 ;;; Not only is this a good idea, it's apparently the way it'll be rel 19.
681 ;;; - Upgraded process sends to use comint-send-string instead of
682 ;;; process-send-string.
683 ;;; - Explicit references to process "cmulisp" have been replaced with
684 ;;; (cmulisp-proc). This allows better handling of multiple process bufs.
685 ;;; - Added process query and var/function/symbol documentation
686 ;;; commands. Based on code written by Douglas Roberts.
687 ;;; - Added lisp-eval-last-sexp, bound to C-x C-e.
689 ;;; 9/20/90 Olin
690 ;;; Added a save-restriction to lisp-fn-called-at-pt. This bug and fix
691 ;;; reported by Lennart Staflin.
693 ;;; 3/12/90 Olin
694 ;;; - lisp-load-file and lisp-compile-file no longer switch-to-lisp.
695 ;;; Tale suggested this.
696 ;;; - Reversed this decision 7/15/91. You need the visual feedback.
698 ;;; 7/25/91 Olin
699 ;;; Changed all keybindings of the form C-c <letter>. These are
700 ;;; supposed to be reserved for the user to bind. This affected
701 ;;; mainly the compile/eval-defun/region[-and-go] commands.
702 ;;; This was painful, but necessary to adhere to the gnumacs standard.
703 ;;; For some backwards compatibility, see the
704 ;;; cmulisp-install-letter-bindings
705 ;;; function.
707 ;;; 8/2/91 Olin
708 ;;; - The lisp-compile/eval-defun/region commands now take a prefix arg,
709 ;;; which means switch-to-lisp after sending the text to the Lisp process.
710 ;;; This obsoletes all the -and-go commands. The -and-go commands are
711 ;;; kept around for historical reasons, and because the user can bind
712 ;;; them to key sequences shorter than C-u C-c C-<letter>.
713 ;;; - If M-x cmulisp is invoked with a prefix arg, it allows you to
714 ;;; edit the command line.
716 (provide 'inf-lisp)
718 ;;; inf-lisp.el ends here