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