]> code.delx.au - gnu-emacs/blob - lisp/progmodes/inf-lisp.el
f2578c140661dc22f7b61c87326871888d3d75d4
[gnu-emacs] / lisp / progmodes / inf-lisp.el
1 ;;; inf-lisp.el --- an inferior-lisp mode
2
3 ;; Copyright (C) 1988, 1993-1994, 2001-2012 Free Software Foundation, Inc.
4
5 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
6 ;; Keywords: processes, lisp
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; Hacked from tea.el by Olin Shivers (shivers@cs.cmu.edu). 8/88
26
27 ;; This file defines a lisp-in-a-buffer package (inferior-lisp mode)
28 ;; built on top of comint mode. This version is more featureful,
29 ;; robust, and uniform than the Emacs 18 version. The key bindings are
30 ;; also more compatible with the bindings of Hemlock and Zwei (the
31 ;; Lisp Machine emacs).
32
33 ;; Since this mode is built on top of the general command-interpreter-in-
34 ;; a-buffer mode (comint mode), it shares a common base functionality,
35 ;; and a common set of bindings, with all modes derived from comint mode.
36 ;; This makes these modes easier to use.
37
38 ;; For documentation on the functionality provided by comint mode, and
39 ;; the hooks available for customizing it, see the file comint.el.
40 ;; For further information on inferior-lisp mode, see the comments below.
41
42 ;; Needs fixin:
43 ;; The load-file/compile-file default mechanism could be smarter -- it
44 ;; doesn't know about the relationship between filename extensions and
45 ;; whether the file is source or executable. If you compile foo.lisp
46 ;; with compile-file, then the next load-file should use foo.bin for
47 ;; the default, not foo.lisp. This is tricky to do right, particularly
48 ;; because the extension for executable files varies so much (.o, .bin,
49 ;; .lbin, .mo, .vo, .ao, ...).
50 ;;
51 ;; It would be nice if inferior-lisp (and inferior scheme, T, ...) modes
52 ;; had a verbose minor mode wherein sending or compiling defuns, etc.
53 ;; would be reflected in the transcript with suitable comments, e.g.
54 ;; ";;; redefining fact". Several ways to do this. Which is right?
55 ;;
56 ;; When sending text from a source file to a subprocess, the process-mark can
57 ;; move off the window, so you can lose sight of the process interactions.
58 ;; Maybe I should ensure the process mark is in the window when I send
59 ;; text to the process? Switch selectable?
60
61 ;;; Code:
62
63 (require 'comint)
64 (require 'lisp-mode)
65
66 \f
67 (defgroup inferior-lisp nil
68 "Run an outside Lisp in an Emacs buffer."
69 :group 'lisp
70 :version "22.1")
71
72 (defcustom inferior-lisp-filter-regexp
73 "\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'"
74 "What not to save on inferior Lisp's input history.
75 Input matching this regexp is not saved on the input history in Inferior Lisp
76 mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
77 \(as in :a, :c, etc.)"
78 :type 'regexp
79 :group 'inferior-lisp)
80
81 (defvar inferior-lisp-mode-map
82 (let ((map (copy-keymap comint-mode-map)))
83 (set-keymap-parent map lisp-mode-shared-map)
84 (define-key map "\C-x\C-e" 'lisp-eval-last-sexp)
85 (define-key map "\C-c\C-l" 'lisp-load-file)
86 (define-key map "\C-c\C-k" 'lisp-compile-file)
87 (define-key map "\C-c\C-a" 'lisp-show-arglist)
88 (define-key map "\C-c\C-d" 'lisp-describe-sym)
89 (define-key map "\C-c\C-f" 'lisp-show-function-documentation)
90 (define-key map "\C-c\C-v" 'lisp-show-variable-documentation)
91 map))
92
93 ;;; These commands augment Lisp mode, so you can process Lisp code in
94 ;;; the source files.
95 (define-key lisp-mode-map "\M-\C-x" 'lisp-eval-defun) ; Gnu convention
96 (define-key lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp) ; Gnu convention
97 (define-key lisp-mode-map "\C-c\C-e" 'lisp-eval-defun)
98 (define-key lisp-mode-map "\C-c\C-r" 'lisp-eval-region)
99 (define-key lisp-mode-map "\C-c\C-c" 'lisp-compile-defun)
100 (define-key lisp-mode-map "\C-c\C-z" 'switch-to-lisp)
101 (define-key lisp-mode-map "\C-c\C-l" 'lisp-load-file)
102 (define-key lisp-mode-map "\C-c\C-k" 'lisp-compile-file) ; "kompile" file
103 (define-key lisp-mode-map "\C-c\C-a" 'lisp-show-arglist)
104 (define-key lisp-mode-map "\C-c\C-d" 'lisp-describe-sym)
105 (define-key lisp-mode-map "\C-c\C-f" 'lisp-show-function-documentation)
106 (define-key lisp-mode-map "\C-c\C-v" 'lisp-show-variable-documentation)
107
108
109 ;;; This function exists for backwards compatibility.
110 ;;; Previous versions of this package bound commands to C-c <letter>
111 ;;; bindings, which is not allowed by the gnumacs standard.
112
113 ;;; "This function binds many inferior-lisp commands to C-c <letter> bindings,
114 ;;;where they are more accessible. C-c <letter> bindings are reserved for the
115 ;;;user, so these bindings are non-standard. If you want them, you should
116 ;;;have this function called by the inferior-lisp-load-hook:
117 ;;; (add-hook 'inferior-lisp-load-hook 'inferior-lisp-install-letter-bindings)
118 ;;;You can modify this function to install just the bindings you want."
119 (defun inferior-lisp-install-letter-bindings ()
120 (define-key lisp-mode-map "\C-ce" 'lisp-eval-defun-and-go)
121 (define-key lisp-mode-map "\C-cr" 'lisp-eval-region-and-go)
122 (define-key lisp-mode-map "\C-cc" 'lisp-compile-defun-and-go)
123 (define-key lisp-mode-map "\C-cz" 'switch-to-lisp)
124 (define-key lisp-mode-map "\C-cl" 'lisp-load-file)
125 (define-key lisp-mode-map "\C-ck" 'lisp-compile-file)
126 (define-key lisp-mode-map "\C-ca" 'lisp-show-arglist)
127 (define-key lisp-mode-map "\C-cd" 'lisp-describe-sym)
128 (define-key lisp-mode-map "\C-cf" 'lisp-show-function-documentation)
129 (define-key lisp-mode-map "\C-cv" 'lisp-show-variable-documentation)
130
131 (define-key inferior-lisp-mode-map "\C-cl" 'lisp-load-file)
132 (define-key inferior-lisp-mode-map "\C-ck" 'lisp-compile-file)
133 (define-key inferior-lisp-mode-map "\C-ca" 'lisp-show-arglist)
134 (define-key inferior-lisp-mode-map "\C-cd" 'lisp-describe-sym)
135 (define-key inferior-lisp-mode-map "\C-cf" 'lisp-show-function-documentation)
136 (define-key inferior-lisp-mode-map "\C-cv"
137 'lisp-show-variable-documentation))
138
139 (defcustom inferior-lisp-program "lisp"
140 "Program name for invoking an inferior Lisp in Inferior Lisp mode."
141 :type 'string
142 :group 'inferior-lisp)
143
144 (defcustom inferior-lisp-load-command "(load \"%s\")\n"
145 "Format-string for building a Lisp expression to load a file.
146 This format string should use `%s' to substitute a file name
147 and should result in a Lisp expression that will command the inferior Lisp
148 to load that file. The default works acceptably on most Lisps.
149 The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\n\"
150 produces cosmetically superior output for this application,
151 but it works only in Common Lisp."
152 :type 'string
153 :group 'inferior-lisp)
154
155 (defcustom inferior-lisp-prompt "^[^> \n]*>+:? *"
156 "Regexp to recognize prompts in the Inferior Lisp mode.
157 Defaults to \"^[^> \\n]*>+:? *\", which works pretty good for Lucid, kcl,
158 and franz. This variable is used to initialize `comint-prompt-regexp' in the
159 Inferior Lisp buffer.
160
161 This variable is only used if the variable
162 `comint-use-prompt-regexp' is non-nil.
163
164 More precise choices:
165 Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\"
166 franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\"
167 kcl: \"^>+ *\""
168 :type 'regexp
169 :group 'inferior-lisp)
170
171 (defvar inferior-lisp-buffer nil "*The current inferior-lisp process buffer.
172
173 MULTIPLE PROCESS SUPPORT
174 ===========================================================================
175 To run multiple Lisp processes, you start the first up
176 with \\[inferior-lisp]. It will be in a buffer named `*inferior-lisp*'.
177 Rename this buffer with \\[rename-buffer]. You may now start up a new
178 process with another \\[inferior-lisp]. It will be in a new buffer,
179 named `*inferior-lisp*'. You can switch between the different process
180 buffers with \\[switch-to-buffer].
181
182 Commands that send text from source buffers to Lisp processes --
183 like `lisp-eval-defun' or `lisp-show-arglist' -- have to choose a process
184 to send to, when you have more than one Lisp process around. This
185 is determined by the global variable `inferior-lisp-buffer'. Suppose you
186 have three inferior Lisps running:
187 Buffer Process
188 foo inferior-lisp
189 bar inferior-lisp<2>
190 *inferior-lisp* inferior-lisp<3>
191 If you do a \\[lisp-eval-defun] command on some Lisp source code,
192 what process do you send it to?
193
194 - If you're in a process buffer (foo, bar, or *inferior-lisp*),
195 you send it to that process.
196 - If you're in some other buffer (e.g., a source file), you
197 send it to the process attached to buffer `inferior-lisp-buffer'.
198 This process selection is performed by function `inferior-lisp-proc'.
199
200 Whenever \\[inferior-lisp] fires up a new process, it resets
201 `inferior-lisp-buffer' to be the new process's buffer. If you only run
202 one process, this does the right thing. If you run multiple
203 processes, you can change `inferior-lisp-buffer' to another process
204 buffer with \\[set-variable].")
205
206 (defvar inferior-lisp-mode-hook '()
207 "Hook for customizing Inferior Lisp mode.")
208
209 (put 'inferior-lisp-mode 'mode-class 'special)
210
211 (define-derived-mode inferior-lisp-mode comint-mode "Inferior Lisp"
212 "Major mode for interacting with an inferior Lisp process.
213 Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an
214 Emacs buffer. Variable `inferior-lisp-program' controls which Lisp interpreter
215 is run. Variables `inferior-lisp-prompt', `inferior-lisp-filter-regexp' and
216 `inferior-lisp-load-command' can customize this mode for different Lisp
217 interpreters.
218
219 For information on running multiple processes in multiple buffers, see
220 documentation for variable `inferior-lisp-buffer'.
221
222 \\{inferior-lisp-mode-map}
223
224 Customization: Entry to this mode runs the hooks on `comint-mode-hook' and
225 `inferior-lisp-mode-hook' (in that order).
226
227 You can send text to the inferior Lisp process from other buffers containing
228 Lisp source.
229 `switch-to-lisp' switches the current buffer to the Lisp process buffer.
230 `lisp-eval-defun' sends the current defun to the Lisp process.
231 `lisp-compile-defun' compiles the current defun.
232 `lisp-eval-region' sends the current region to the Lisp process.
233 `lisp-compile-region' compiles the current region.
234
235 Prefixing the lisp-eval/compile-defun/region commands with
236 a \\[universal-argument] causes a switch to the Lisp process buffer after sending
237 the text.
238
239 Commands:\\<inferior-lisp-mode-map>
240 \\[comint-send-input] after the end of the process' output sends the text from the
241 end of process to point.
242 \\[comint-send-input] before the end of the process' output copies the sexp ending at point
243 to the end of the process' output, and sends it.
244 \\[comint-copy-old-input] copies the sexp ending at point to the end of the process' output,
245 allowing you to edit it before sending it.
246 If `comint-use-prompt-regexp' is nil (the default), \\[comint-insert-input] on old input
247 copies the entire old input to the end of the process' output, allowing
248 you to edit it before sending it. When not used on old input, or if
249 `comint-use-prompt-regexp' is non-nil, \\[comint-insert-input] behaves according to
250 its global binding.
251 \\[backward-delete-char-untabify] converts tabs to spaces as it moves back.
252 \\[lisp-indent-line] indents for Lisp; with argument, shifts rest
253 of expression rigidly with the current line.
254 \\[indent-sexp] does \\[lisp-indent-line] on each line starting within following expression.
255 Paragraphs are separated only by blank lines. Semicolons start comments.
256 If you accidentally suspend your process, use \\[comint-continue-subjob]
257 to continue it."
258 (setq comint-prompt-regexp inferior-lisp-prompt)
259 (setq mode-line-process '(":%s"))
260 (lisp-mode-variables t)
261 (setq comint-get-old-input (function lisp-get-old-input))
262 (setq comint-input-filter (function lisp-input-filter)))
263
264 (defun lisp-get-old-input ()
265 "Return a string containing the sexp ending at point."
266 (save-excursion
267 (let ((end (point)))
268 (backward-sexp)
269 (buffer-substring (point) end))))
270
271 (defun lisp-input-filter (str)
272 "t if STR does not match `inferior-lisp-filter-regexp'."
273 (not (string-match inferior-lisp-filter-regexp str)))
274
275 ;;;###autoload
276 (defun inferior-lisp (cmd)
277 "Run an inferior Lisp process, input and output via buffer `*inferior-lisp*'.
278 If there is a process already running in `*inferior-lisp*', just switch
279 to that buffer.
280 With argument, allows you to edit the command line (default is value
281 of `inferior-lisp-program'). Runs the hooks from
282 `inferior-lisp-mode-hook' (after the `comint-mode-hook' is run).
283 \(Type \\[describe-mode] in the process buffer for a list of commands.)"
284 (interactive (list (if current-prefix-arg
285 (read-string "Run lisp: " inferior-lisp-program)
286 inferior-lisp-program)))
287 (if (not (comint-check-proc "*inferior-lisp*"))
288 (let ((cmdlist (split-string cmd)))
289 (set-buffer (apply (function make-comint)
290 "inferior-lisp" (car cmdlist) nil (cdr cmdlist)))
291 (inferior-lisp-mode)))
292 (setq inferior-lisp-buffer "*inferior-lisp*")
293 (pop-to-buffer-same-window "*inferior-lisp*"))
294
295 ;;;###autoload
296 (defalias 'run-lisp 'inferior-lisp)
297
298 (defun lisp-eval-region (start end &optional and-go)
299 "Send the current region to the inferior Lisp process.
300 Prefix argument means switch to the Lisp buffer afterwards."
301 (interactive "r\nP")
302 (comint-send-region (inferior-lisp-proc) start end)
303 (comint-send-string (inferior-lisp-proc) "\n")
304 (if and-go (switch-to-lisp t)))
305
306 (defun lisp-compile-string (string)
307 "Send the string to the inferior Lisp process to be compiled and executed."
308 (comint-send-string
309 (inferior-lisp-proc)
310 (format "(funcall (compile nil (lambda () %s)))\n" string)))
311
312 (defun lisp-eval-string (string)
313 "Send the string to the inferior Lisp process to be executed."
314 (comint-send-string (inferior-lisp-proc) (concat string "\n")))
315
316 (defun lisp-do-defun (do-string do-region)
317 "Send the current defun to the inferior Lisp process.
318 The actually processing is done by `do-string' and `do-region'
319 which determine whether the code is compiled before evaluation.
320 DEFVAR forms reset the variables to the init values."
321 (save-excursion
322 (end-of-defun)
323 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
324 (let ((end (point)) (case-fold-search t))
325 (beginning-of-defun)
326 (if (looking-at "(defvar")
327 (funcall do-string
328 ;; replace `defvar' with `defparameter'
329 (concat "(defparameter "
330 (buffer-substring-no-properties (+ (point) 7) end)
331 "\n"))
332 (funcall do-region (point) end)))))
333
334 (defun lisp-eval-defun (&optional and-go)
335 "Send the current defun to the inferior Lisp process.
336 DEFVAR forms reset the variables to the init values.
337 Prefix argument means switch to the Lisp buffer afterwards."
338 (interactive "P")
339 (lisp-do-defun 'lisp-eval-string 'lisp-eval-region)
340 (if and-go (switch-to-lisp t)))
341
342 (defun lisp-eval-last-sexp (&optional and-go)
343 "Send the previous sexp to the inferior Lisp process.
344 Prefix argument means switch to the Lisp buffer afterwards."
345 (interactive "P")
346 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go))
347
348 (defun lisp-compile-region (start end &optional and-go)
349 "Compile the current region in the inferior Lisp process.
350 Prefix argument means switch to the Lisp buffer afterwards."
351 (interactive "r\nP")
352 (lisp-compile-string (buffer-substring-no-properties start end))
353 (if and-go (switch-to-lisp t)))
354
355 (defun lisp-compile-defun (&optional and-go)
356 "Compile the current defun in the inferior Lisp process.
357 DEFVAR forms reset the variables to the init values.
358 Prefix argument means switch to the Lisp buffer afterwards."
359 (interactive "P")
360 (lisp-do-defun 'lisp-compile-string 'lisp-compile-region)
361 (if and-go (switch-to-lisp t)))
362
363 (defun switch-to-lisp (eob-p)
364 "Switch to the inferior Lisp process buffer.
365 With argument, positions cursor at end of buffer."
366 (interactive "P")
367 (if (get-buffer-process inferior-lisp-buffer)
368 (let ((pop-up-frames
369 ;; Be willing to use another frame
370 ;; that already has the window in it.
371 (or pop-up-frames
372 (get-buffer-window inferior-lisp-buffer t))))
373 (pop-to-buffer inferior-lisp-buffer))
374 (run-lisp inferior-lisp-program))
375 (when eob-p
376 (push-mark)
377 (goto-char (point-max))))
378
379
380 ;;; Now that lisp-compile/eval-defun/region takes an optional prefix arg,
381 ;;; these commands are redundant. But they are kept around for the user
382 ;;; to bind if he wishes, for backwards functionality, and because it's
383 ;;; easier to type C-c e than C-u C-c C-e.
384
385 (defun lisp-eval-region-and-go (start end)
386 "Send the current region to the inferior Lisp, and switch to its buffer."
387 (interactive "r")
388 (lisp-eval-region start end t))
389
390 (defun lisp-eval-defun-and-go ()
391 "Send the current defun to the inferior Lisp, and switch to its buffer."
392 (interactive)
393 (lisp-eval-defun t))
394
395 (defun lisp-compile-region-and-go (start end)
396 "Compile the current region in the inferior Lisp, and switch to its buffer."
397 (interactive "r")
398 (lisp-compile-region start end t))
399
400 (defun lisp-compile-defun-and-go ()
401 "Compile the current defun in the inferior Lisp, and switch to its buffer."
402 (interactive)
403 (lisp-compile-defun t))
404
405 ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust.
406 ;;; (defun lisp-compile-sexp (start end)
407 ;;; "Compile the s-expression bounded by START and END in the inferior lisp.
408 ;;; If the sexp isn't a DEFUN form, it is evaluated instead."
409 ;;; (cond ((looking-at "(defun\\s +")
410 ;;; (goto-char (match-end 0))
411 ;;; (let ((name-start (point)))
412 ;;; (forward-sexp 1)
413 ;;; (process-send-string "inferior-lisp"
414 ;;; (format "(compile '%s #'(lambda "
415 ;;; (buffer-substring name-start
416 ;;; (point)))))
417 ;;; (let ((body-start (point)))
418 ;;; (goto-char start) (forward-sexp 1) ; Can't use end-of-defun.
419 ;;; (process-send-region "inferior-lisp"
420 ;;; (buffer-substring body-start (point))))
421 ;;; (process-send-string "inferior-lisp" ")\n"))
422 ;;; (t (lisp-eval-region start end)))))
423 ;;;
424 ;;; (defun lisp-compile-region (start end)
425 ;;; "Each s-expression in the current region is compiled (if a DEFUN)
426 ;;; or evaluated (if not) in the inferior lisp."
427 ;;; (interactive "r")
428 ;;; (save-excursion
429 ;;; (goto-char start) (end-of-defun) (beginning-of-defun) ; error check
430 ;;; (if (< (point) start) (error "region begins in middle of defun"))
431 ;;; (goto-char start)
432 ;;; (let ((s start))
433 ;;; (end-of-defun)
434 ;;; (while (<= (point) end) ; Zip through
435 ;;; (lisp-compile-sexp s (point)) ; compiling up defun-sized chunks.
436 ;;; (setq s (point))
437 ;;; (end-of-defun))
438 ;;; (if (< s end) (lisp-compile-sexp s end)))))
439 ;;;
440 ;;; End of HS-style code
441
442
443 (defvar lisp-prev-l/c-dir/file nil
444 "Record last directory and file used in loading or compiling.
445 This holds a cons cell of the form `(DIRECTORY . FILE)'
446 describing the last `lisp-load-file' or `lisp-compile-file' command.")
447
448 (defcustom lisp-source-modes '(lisp-mode)
449 "Used to determine if a buffer contains Lisp source code.
450 If it's loaded into a buffer that is in one of these major modes, it's
451 considered a Lisp source file by `lisp-load-file' and `lisp-compile-file'.
452 Used by these commands to determine defaults."
453 :type '(repeat symbol)
454 :group 'inferior-lisp)
455
456 (defun lisp-load-file (file-name)
457 "Load a Lisp file into the inferior Lisp process."
458 (interactive (comint-get-source "Load Lisp file: " lisp-prev-l/c-dir/file
459 lisp-source-modes nil)) ; nil because LOAD
460 ; doesn't need an exact name
461 (comint-check-source file-name) ; Check to see if buffer needs saved.
462 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name)
463 (file-name-nondirectory file-name)))
464 (comint-send-string (inferior-lisp-proc)
465 (format inferior-lisp-load-command file-name))
466 (switch-to-lisp t))
467
468
469 (defun lisp-compile-file (file-name)
470 "Compile a Lisp file in the inferior Lisp process."
471 (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l/c-dir/file
472 lisp-source-modes nil)) ; nil = don't need
473 ; suffix .lisp
474 (comint-check-source file-name) ; Check to see if buffer needs saved.
475 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name)
476 (file-name-nondirectory file-name)))
477 (comint-send-string (inferior-lisp-proc) (concat "(compile-file \""
478 file-name
479 "\"\)\n"))
480 (switch-to-lisp t))
481
482
483 \f
484 ;;; Documentation functions: function doc, var doc, arglist, and
485 ;;; describe symbol.
486 ;;; ===========================================================================
487
488 ;;; Command strings
489 ;;; ===============
490
491 (defvar lisp-function-doc-command
492 "(let ((fn '%s))
493 (format t \"Documentation for ~a:~&~a\"
494 fn (documentation fn 'function))
495 (values))\n"
496 "Command to query inferior Lisp for a function's documentation.")
497
498 (defvar lisp-var-doc-command
499 "(let ((v '%s))
500 (format t \"Documentation for ~a:~&~a\"
501 v (documentation v 'variable))
502 (values))\n"
503 "Command to query inferior Lisp for a variable's documentation.")
504
505 (defvar lisp-arglist-command
506 "(let ((fn '%s))
507 (format t \"Arglist for ~a: ~a\" fn (arglist fn))
508 (values))\n"
509 "Command to query inferior Lisp for a function's arglist.")
510
511 (defvar lisp-describe-sym-command
512 "(describe '%s)\n"
513 "Command to query inferior Lisp for a variable's documentation.")
514
515
516 ;;; Ancillary functions
517 ;;; ===================
518
519 ;;; Reads a string from the user.
520 (defun lisp-symprompt (prompt default)
521 (list (let* ((prompt (if default
522 (format "%s (default %s): " prompt default)
523 (concat prompt ": ")))
524 (ans (read-string prompt)))
525 (if (zerop (length ans)) default ans))))
526
527
528 ;;; Adapted from function-called-at-point in help.el.
529 (defun lisp-fn-called-at-pt ()
530 "Returns the name of the function called in the current call.
531 The value is nil if it can't find one."
532 (condition-case nil
533 (save-excursion
534 (save-restriction
535 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
536 (backward-up-list 1)
537 (forward-char 1)
538 (let ((obj (read (current-buffer))))
539 (and (symbolp obj) obj))))
540 (error nil)))
541
542
543 ;;; Adapted from variable-at-point in help.el.
544 (defun lisp-var-at-pt ()
545 (condition-case ()
546 (save-excursion
547 (forward-sexp -1)
548 (skip-chars-forward "'")
549 (let ((obj (read (current-buffer))))
550 (and (symbolp obj) obj)))
551 (error nil)))
552
553
554 ;;; Documentation functions: fn and var doc, arglist, and symbol describe.
555 ;;; ======================================================================
556
557 (defun lisp-show-function-documentation (fn)
558 "Send a command to the inferior Lisp to give documentation for function FN.
559 See variable `lisp-function-doc-command'."
560 (interactive (lisp-symprompt "Function doc" (lisp-fn-called-at-pt)))
561 (comint-proc-query (inferior-lisp-proc)
562 (format lisp-function-doc-command fn)))
563
564 (defun lisp-show-variable-documentation (var)
565 "Send a command to the inferior Lisp to give documentation for function FN.
566 See variable `lisp-var-doc-command'."
567 (interactive (lisp-symprompt "Variable doc" (lisp-var-at-pt)))
568 (comint-proc-query (inferior-lisp-proc) (format lisp-var-doc-command var)))
569
570 (defun lisp-show-arglist (fn)
571 "Send a query to the inferior Lisp for the arglist for function FN.
572 See variable `lisp-arglist-command'."
573 (interactive (lisp-symprompt "Arglist" (lisp-fn-called-at-pt)))
574 (comint-proc-query (inferior-lisp-proc) (format lisp-arglist-command fn)))
575
576 (defun lisp-describe-sym (sym)
577 "Send a command to the inferior Lisp to describe symbol SYM.
578 See variable `lisp-describe-sym-command'."
579 (interactive (lisp-symprompt "Describe" (lisp-var-at-pt)))
580 (comint-proc-query (inferior-lisp-proc)
581 (format lisp-describe-sym-command sym)))
582
583 \f
584 ;; "Returns the current inferior Lisp process.
585 ;; See variable `inferior-lisp-buffer'."
586 (defun inferior-lisp-proc ()
587 (let ((proc (get-buffer-process (if (derived-mode-p 'inferior-lisp-mode)
588 (current-buffer)
589 inferior-lisp-buffer))))
590 (or proc
591 (error "No Lisp subprocess; see variable `inferior-lisp-buffer'"))))
592
593
594 ;;; Do the user's customization...
595 ;;;===============================
596 (defvar inferior-lisp-load-hook nil
597 "This hook is run when the library `inf-lisp' is loaded.")
598
599 (run-hooks 'inferior-lisp-load-hook)
600
601 ;;; CHANGE LOG
602 ;;; ===========================================================================
603 ;;; 7/21/92 Jim Blandy
604 ;;; - Changed all uses of the cmulisp name or prefix to inferior-lisp;
605 ;;; this is now the official inferior lisp package. Use the global
606 ;;; ChangeLog from now on.
607 ;;; 5/24/90 Olin
608 ;;; - Split cmulisp and cmushell modes into separate files.
609 ;;; Not only is this a good idea, it's apparently the way it'll be rel 19.
610 ;;; - Upgraded process sends to use comint-send-string instead of
611 ;;; process-send-string.
612 ;;; - Explicit references to process "cmulisp" have been replaced with
613 ;;; (cmulisp-proc). This allows better handling of multiple process bufs.
614 ;;; - Added process query and var/function/symbol documentation
615 ;;; commands. Based on code written by Douglas Roberts.
616 ;;; - Added lisp-eval-last-sexp, bound to C-x C-e.
617 ;;;
618 ;;; 9/20/90 Olin
619 ;;; Added a save-restriction to lisp-fn-called-at-pt. This bug and fix
620 ;;; reported by Lennart Staflin.
621 ;;;
622 ;;; 3/12/90 Olin
623 ;;; - lisp-load-file and lisp-compile-file no longer switch-to-lisp.
624 ;;; Tale suggested this.
625 ;;; - Reversed this decision 7/15/91. You need the visual feedback.
626 ;;;
627 ;;; 7/25/91 Olin
628 ;;; Changed all keybindings of the form C-c <letter>. These are
629 ;;; supposed to be reserved for the user to bind. This affected
630 ;;; mainly the compile/eval-defun/region[-and-go] commands.
631 ;;; This was painful, but necessary to adhere to the gnumacs standard.
632 ;;; For some backwards compatibility, see the
633 ;;; cmulisp-install-letter-bindings
634 ;;; function.
635 ;;;
636 ;;; 8/2/91 Olin
637 ;;; - The lisp-compile/eval-defun/region commands now take a prefix arg,
638 ;;; which means switch-to-lisp after sending the text to the Lisp process.
639 ;;; This obsoletes all the -and-go commands. The -and-go commands are
640 ;;; kept around for historical reasons, and because the user can bind
641 ;;; them to key sequences shorter than C-u C-c C-<letter>.
642 ;;; - If M-x cmulisp is invoked with a prefix arg, it allows you to
643 ;;; edit the command line.
644
645 (provide 'inf-lisp)
646
647 ;;; inf-lisp.el ends here