1 ;;; cmulisp.el --- improved version of standard inferior-lisp mode
3 ;;; Copyright Olin Shivers (1988).
5 ;; Keywords: processes, lisp
7 ;;; Please imagine a long, tedious, legalistic 5-page gnu-style copyright
8 ;;; notice appearing here to the effect that you may use this code any
9 ;;; way you like, as long as you don't charge money for it, remove this
10 ;;; notice, or hold me liable for its results.
14 ;;; This replaces the standard inferior-lisp mode.
15 ;;; Hacked from tea.el by Olin Shivers (shivers@cs.cmu.edu). 8/88
16 ;;; Please send me bug reports, bug fixes, and extensions, so that I can
17 ;;; merge them into the master source.
19 ;;; Change log at end of file.
21 ;;; This file defines a a lisp-in-a-buffer package (cmulisp mode) built on top
22 ;;; of comint mode. Cmulisp mode is similar to, and intended to replace, its
23 ;;; counterpart in the standard gnu emacs release. This replacements is more
24 ;;; featureful, robust, and uniform than the released version. The key
25 ;;; bindings are also more compatible with the bindings of Hemlock and Zwei
26 ;;; (the Lisp Machine emacs).
28 ;;; Since this mode is built on top of the general command-interpreter-in-
29 ;;; a-buffer mode (comint mode), it shares a common base functionality,
30 ;;; and a common set of bindings, with all modes derived from comint mode.
31 ;;; This makes these modes easier to use.
33 ;;; For documentation on the functionality provided by comint mode, and
34 ;;; the hooks available for customising it, see the file comint.el.
35 ;;; For further information on cmulisp mode, see the comments below.
38 ;;; The load-file/compile-file default mechanism could be smarter -- it
39 ;;; doesn't know about the relationship between filename extensions and
40 ;;; whether the file is source or executable. If you compile foo.lisp
41 ;;; with compile-file, then the next load-file should use foo.bin for
42 ;;; the default, not foo.lisp. This is tricky to do right, particularly
43 ;;; because the extension for executable files varies so much (.o, .bin,
44 ;;; .lbin, .mo, .vo, .ao, ...).
46 ;;; It would be nice if cmulisp (and inferior scheme, T, ...) modes
47 ;;; had a verbose minor mode wherein sending or compiling defuns, etc.
48 ;;; would be reflected in the transcript with suitable comments, e.g.
49 ;;; ";;; redefining fact". Several ways to do this. Which is right?
51 ;;; When sending text from a source file to a subprocess, the process-mark can
52 ;;; move off the window, so you can lose sight of the process interactions.
53 ;;; Maybe I should ensure the process mark is in the window when I send
54 ;;; text to the process? Switch selectable?
58 ;;=============================================================================
59 ;; Some suggestions for your .emacs file.
61 ;; ; If cmulisp lives in some non-standard directory, you must tell emacs
62 ;; ; where to get it. This may or may not be necessary.
63 ;; (setq load-path (cons (expand-file-name "~jones/lib/emacs") load-path))
65 ;; ; Autoload cmulisp from file cmulisp.el
66 ;; (autoload 'cmulisp "cmulisp"
67 ;; "Run an inferior Lisp process."
70 ;; ; Define C-c t to run my favorite command in cmulisp mode:
71 ;; (setq cmulisp-load-hook
73 ;; (define-key cmulisp-mode-map "\C-ct" 'favorite-cmd))))
75 ;; Brief Command Documentation:
76 ;;============================================================================
77 ;; Comint Mode Commands: (common to cmulisp and all comint-derived modes)
79 ;; m-p comint-previous-input Cycle backwards in input history
80 ;; m-n comint-next-input Cycle forwards
81 ;; m-c-r comint-previous-input-matching Search backwards in input history
82 ;; return comint-send-input
83 ;; c-a comint-bol Beginning of line; skip prompt.
84 ;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff.
85 ;; c-c c-u comint-kill-input ^u
86 ;; c-c c-w backward-kill-word ^w
87 ;; c-c c-c comint-interrupt-subjob ^c
88 ;; c-c c-z comint-stop-subjob ^z
89 ;; c-c c-\ comint-quit-subjob ^\
90 ;; c-c c-o comint-kill-output Delete last batch of process output
91 ;; c-c c-r comint-show-output Show last batch of process output
92 ;; send-invisible Read line w/o echo & send to proc
93 ;; comint-continue-subjob Useful if you accidentally suspend
95 ;; comint-mode-hook is the comint mode hook.
97 ;; CMU Lisp Mode Commands:
98 ;; c-m-x lisp-send-defun This binding is a gnu convention.
99 ;; c-c c-l lisp-load-file Prompt for file name; tell Lisp to load it.
100 ;; c-c c-k lisp-compile-file Prompt for file name; tell Lisp to kompile it.
101 ;; Filename completion is available, of course.
103 ;; Additionally, these commands are added to the key bindings of Lisp mode:
104 ;; c-m-x lisp-eval-defun This binding is a gnu convention.
105 ;; c-c c-e lisp-eval-defun Send the current defun to Lisp process.
106 ;; c-x c-e lisp-eval-last-sexp Send the previous sexp to Lisp process.
107 ;; c-c c-r lisp-eval-region Send the current region to Lisp process.
108 ;; c-c c-c lisp-compile-defun Compile the current defun in Lisp process.
109 ;; c-c c-z switch-to-lisp Switch to the Lisp process buffer.
110 ;; c-c c-l lisp-load-file (See above. In a Lisp file buffer, default
111 ;; c-c c-k lisp-compile-file is to load/compile the current file.)
112 ;; c-c c-d lisp-describe-sym Query Lisp for a symbol's description.
113 ;; c-c c-a lisp-show-arglist Query Lisp for function's arglist.
114 ;; c-c c-f lisp-show-function-documentation Query Lisp for a function's doc.
115 ;; c-c c-v lisp-show-variable-documentation Query Lisp for a variable's doc.
117 ;; cmulisp Fires up the Lisp process.
118 ;; lisp-compile-region Compile all forms in the current region.
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
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.
135 ;;; Read the rest of this file for more information.
140 (defvar cmulisp-filter-regexp
"\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'"
141 "*What not to save on inferior Lisp's input history
142 Input matching this regexp is not saved on the input history in cmulisp
143 mode. Default is whitespace followed by 0 or 1 single-letter :keyword
144 (as in :a, :c, etc.)")
146 (defvar cmulisp-mode-map nil
)
147 (cond ((not cmulisp-mode-map
)
148 (setq cmulisp-mode-map
149 (nconc (full-copy-sparse-keymap comint-mode-map
)
150 shared-lisp-mode-map
))
151 (define-key cmulisp-mode-map
"\C-x\C-e" 'lisp-eval-last-sexp
)
152 (define-key cmulisp-mode-map
"\C-c\C-l" 'lisp-load-file
)
153 (define-key cmulisp-mode-map
"\C-c\C-k" 'lisp-compile-file
)
154 (define-key cmulisp-mode-map
"\C-c\C-a" 'lisp-show-arglist
)
155 (define-key cmulisp-mode-map
"\C-c\C-d" 'lisp-describe-sym
)
156 (define-key cmulisp-mode-map
"\C-c\C-f" 'lisp-show-function-documentation
)
157 (define-key cmulisp-mode-map
"\C-c\C-v" 'lisp-show-variable-documentation
)))
159 ;;; These commands augment Lisp mode, so you can process Lisp code in
160 ;;; the source files.
161 (define-key lisp-mode-map
"\M-\C-x" 'lisp-eval-defun
) ; Gnu convention
162 (define-key lisp-mode-map
"\C-x\C-e" 'lisp-eval-last-sexp
) ; Gnu convention
163 (define-key lisp-mode-map
"\C-c\C-e" 'lisp-eval-defun
)
164 (define-key lisp-mode-map
"\C-c\C-r" 'lisp-eval-region
)
165 (define-key lisp-mode-map
"\C-c\C-c" 'lisp-compile-defun
)
166 (define-key lisp-mode-map
"\C-c\C-z" 'switch-to-lisp
)
167 (define-key lisp-mode-map
"\C-c\C-l" 'lisp-load-file
)
168 (define-key lisp-mode-map
"\C-c\C-k" 'lisp-compile-file
) ; "kompile" file
169 (define-key lisp-mode-map
"\C-c\C-a" 'lisp-show-arglist
)
170 (define-key lisp-mode-map
"\C-c\C-d" 'lisp-describe-sym
)
171 (define-key lisp-mode-map
"\C-c\C-f" 'lisp-show-function-documentation
)
172 (define-key lisp-mode-map
"\C-c\C-v" 'lisp-show-variable-documentation
)
174 (defvar cmulisp-buffer
)
176 ;;; This function exists for backwards compatibility.
177 ;;; Previous versions of this package bound commands to C-c <letter>
178 ;;; bindings, which is not allowed by the gnumacs standard.
180 (defun cmulisp-install-letter-bindings ()
181 "This function binds many cmulisp commands to C-c <letter> bindings,
182 where they are more accessible. C-c <letter> bindings are reserved for the
183 user, so these bindings are non-standard. If you want them, you should
184 have this function called by the cmulisp-load-hook:
185 (setq cmulisp-load-hook '(cmulisp-install-letter-bindings))
186 You can modify this function to install just the bindings you want."
188 (define-key lisp-mode-map
"\C-ce" 'lisp-eval-defun-and-go
)
189 (define-key lisp-mode-map
"\C-cr" 'lisp-eval-region-and-go
)
190 (define-key lisp-mode-map
"\C-cc" 'lisp-compile-defun-and-go
)
191 (define-key lisp-mode-map
"\C-cz" 'switch-to-lisp
)
192 (define-key lisp-mode-map
"\C-cl" 'lisp-load-file
)
193 (define-key lisp-mode-map
"\C-ck" 'lisp-compile-file
)
194 (define-key lisp-mode-map
"\C-ca" 'lisp-show-arglist
)
195 (define-key lisp-mode-map
"\C-cd" 'lisp-describe-sym
)
196 (define-key lisp-mode-map
"\C-cf" 'lisp-show-function-documentation
)
197 (define-key lisp-mode-map
"\C-cv" 'lisp-show-variable-documentation
)
199 (define-key cmulisp-mode-map
"\C-cl" 'lisp-load-file
)
200 (define-key cmulisp-mode-map
"\C-ck" 'lisp-compile-file
)
201 (define-key cmulisp-mode-map
"\C-ca" 'lisp-show-arglist
)
202 (define-key cmulisp-mode-map
"\C-cd" 'lisp-describe-sym
)
203 (define-key cmulisp-mode-map
"\C-cf" 'lisp-show-function-documentation
)
204 (define-key cmulisp-mode-map
"\C-cv" 'lisp-show-variable-documentation
))
207 (defvar inferior-lisp-program
"lisp"
208 "*Program name for invoking an inferior Lisp with `cmulisp'.")
210 (defvar inferior-lisp-load-command
"(load \"%s\")\n"
211 "*Format-string for building a Lisp expression to load a file.
212 This format string should use %s to substitute a file name
213 and should result in a Lisp expression that will command the inferior Lisp
214 to load that file. The default works acceptably on most Lisps.
215 The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\\n\"
216 produces cosmetically superior output for this application,
217 but it works only in Common Lisp.")
219 (defvar inferior-lisp-prompt
"^[^> ]*>+:? *"
220 "Regexp to recognise prompts in the inferior Lisp.
221 Defaults to \"^[^> ]*>+:? *\", which works pretty good for Lucid, kcl,
222 and franz. This variable is used to initialise comint-prompt-regexp in the
225 More precise choices:
226 Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\"
227 franz: \"^\\(->\\|<[0-9]*>:\\) *\"
230 This is a fine thing to set in your .emacs file.")
232 (defvar cmulisp-mode-hook
'()
233 "*Hook for customising cmulisp mode")
235 (defun cmulisp-mode ()
236 "Major mode for interacting with an inferior Lisp process.
237 Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an
238 Emacs buffer. Variable inferior-lisp-program controls which Lisp interpreter
239 is run. Variables inferior-lisp-prompt, cmulisp-filter-regexp and
240 inferior-lisp-load-command can customize this mode for different Lisp
243 For information on running multiple processes in multiple buffers, see
244 documentation for variable cmulisp-buffer.
248 Customisation: Entry to this mode runs the hooks on comint-mode-hook and
249 cmulisp-mode-hook (in that order).
251 You can send text to the inferior Lisp process from other buffers containing
253 switch-to-lisp switches the current buffer to the Lisp process buffer.
254 lisp-eval-defun sends the current defun to the Lisp process.
255 lisp-compile-defun compiles the current defun.
256 lisp-eval-region sends the current region to the Lisp process.
257 lisp-compile-region compiles the current region.
259 Prefixing the lisp-eval/compile-defun/region commands with
260 a \\[universal-argument] causes a switch to the Lisp process buffer after sending
264 Return after the end of the process' output sends the text from the
265 end of process to point.
266 Return before the end of the process' output copies the sexp ending at point
267 to the end of the process' output, and sends it.
268 Delete converts tabs to spaces as it moves back.
269 Tab indents for Lisp; with argument, shifts rest
270 of expression rigidly with the current line.
271 C-M-q does Tab on each line starting within following expression.
272 Paragraphs are separated only by blank lines. Semicolons start comments.
273 If you accidentally suspend your process, use \\[comint-continue-subjob]
277 (setq comint-prompt-regexp inferior-lisp-prompt
)
278 (setq major-mode
'cmulisp-mode
)
279 (setq mode-name
"CMU Lisp")
280 (setq mode-line-process
'(": %s"))
281 (lisp-mode-variables t
)
282 (use-local-map cmulisp-mode-map
) ;c-c c-k for "kompile" file
283 (setq comint-get-old-input
(function lisp-get-old-input
))
284 (setq comint-input-filter
(function lisp-input-filter
))
285 (setq comint-input-sentinel
'ignore
)
286 (run-hooks 'cmulisp-mode-hook
))
288 (defun lisp-get-old-input ()
289 "Snarf the sexp ending at point"
293 (buffer-substring (point) end
))))
295 (defun lisp-input-filter (str)
296 "Don't save anything matching cmulisp-filter-regexp"
297 (not (string-match cmulisp-filter-regexp str
)))
300 "Run an inferior Lisp process, input and output via buffer *cmulisp*.
301 If there is a process already running in *cmulisp*, just switch to that buffer.
302 With argument, allows you to edit the command line (default is value
303 of inferior-lisp-program). Runs the hooks from cmulisp-mode-hook (after the
304 comint-mode-hook is run).
305 \(Type \\[describe-mode] in the process buffer for a list of commands.)"
306 (interactive (list (if current-prefix-arg
307 (read-string "Run lisp: " inferior-lisp-program
)
308 inferior-lisp-program
)))
309 (if (not (comint-check-proc "*cmulisp*"))
310 (let ((cmdlist (cmulisp-args-to-list cmd
)))
311 (set-buffer (apply (function make-comint
) "cmulisp" (car cmdlist
) nil
314 (setq cmulisp-buffer
"*cmulisp*")
315 (switch-to-buffer "*cmulisp*"))
317 ;;; Break a string up into a list of arguments.
318 ;;; This will break if you have an argument with whitespace, as in
319 ;;; string = "-ab +c -x 'you lose'".
320 (defun cmulisp-args-to-list (string)
321 (let ((where (string-match "[ \t]" string
)))
322 (cond ((null where
) (list string
))
324 (cons (substring string
0 where
)
325 (tea-args-to-list (substring string
(+ 1 where
)
327 (t (let ((pos (string-match "[^ \t]" string
)))
330 (cmulisp-args-to-list (substring string pos
331 (length string
)))))))))
333 (defun lisp-eval-region (start end
&optional and-go
)
334 "Send the current region to the inferior Lisp process.
335 Prefix argument means switch-to-lisp afterwards."
337 (comint-send-region (cmulisp-proc) start end
)
338 (comint-send-string (cmulisp-proc) "\n")
339 (if and-go
(switch-to-lisp t
)))
341 (defun lisp-eval-defun (&optional and-go
)
342 "Send the current defun to the inferior Lisp process.
343 Prefix argument means switch-to-lisp afterwards."
347 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
350 (lisp-eval-region (point) end
)))
351 (if and-go
(switch-to-lisp t
)))
353 (defun lisp-eval-last-sexp (&optional and-go
)
354 "Send the previous sexp to the inferior Lisp process.
355 Prefix argument means switch-to-lisp afterwards."
357 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go
))
359 ;;; Common Lisp COMPILE sux.
360 (defun lisp-compile-region (start end
&optional and-go
)
361 "Compile the current region in the inferior Lisp process.
362 Prefix argument means switch-to-lisp afterwards."
364 (comint-send-string (cmulisp-proc)
365 (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n"
366 (buffer-substring start end
)))
367 (if and-go
(switch-to-lisp t
)))
369 (defun lisp-compile-defun (&optional and-go
)
370 "Compile the current defun in the inferior Lisp process.
371 Prefix argument means switch-to-lisp afterwards."
375 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
378 (lisp-compile-region (point) e
)))
379 (if and-go
(switch-to-lisp t
)))
381 (defun switch-to-lisp (eob-p)
382 "Switch to the inferior Lisp process buffer.
383 With argument, positions cursor at end of buffer."
385 (if (get-buffer cmulisp-buffer
)
386 (pop-to-buffer cmulisp-buffer
)
387 (error "No current process buffer. See variable cmulisp-buffer."))
390 (goto-char (point-max)))))
393 ;;; Now that lisp-compile/eval-defun/region takes an optional prefix arg,
394 ;;; these commands are redundant. But they are kept around for the user
395 ;;; to bind if he wishes, for backwards functionality, and because it's
396 ;;; easier to type C-c e than C-u C-c C-e.
398 (defun lisp-eval-region-and-go (start end
)
399 "Send the current region to the inferior Lisp,
400 and switch to the process buffer."
402 (lisp-eval-region start end t
))
404 (defun lisp-eval-defun-and-go ()
405 "Send the current defun to the inferior Lisp,
406 and switch to the process buffer."
410 (defun lisp-compile-region-and-go (start end
)
411 "Compile the current region in the inferior Lisp,
412 and switch to the process buffer."
414 (lisp-compile-region start end t
))
416 (defun lisp-compile-defun-and-go ()
417 "Compile the current defun in the inferior Lisp,
418 and switch to the process buffer."
420 (lisp-compile-defun t))
422 ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust.
423 ;(defun lisp-compile-sexp (start end)
424 ; "Compile the s-expression bounded by START and END in the inferior lisp.
425 ;If the sexp isn't a DEFUN form, it is evaluated instead."
426 ; (cond ((looking-at "(defun\\s +")
427 ; (goto-char (match-end 0))
428 ; (let ((name-start (point)))
430 ; (process-send-string "cmulisp" (format "(compile '%s #'(lambda "
431 ; (buffer-substring name-start
433 ; (let ((body-start (point)))
434 ; (goto-char start) (forward-sexp 1) ; Can't use end-of-defun.
435 ; (process-send-region "cmulisp" (buffer-substring body-start (point))))
436 ; (process-send-string "cmulisp" ")\n"))
437 ; (t (lisp-eval-region start end)))))
439 ;(defun lisp-compile-region (start end)
440 ; "Each s-expression in the current region is compiled (if a DEFUN)
441 ;or evaluated (if not) in the inferior lisp."
444 ; (goto-char start) (end-of-defun) (beginning-of-defun) ; error check
445 ; (if (< (point) start) (error "region begins in middle of defun"))
449 ; (while (<= (point) end) ; Zip through
450 ; (lisp-compile-sexp s (point)) ; compiling up defun-sized chunks.
453 ; (if (< s end) (lisp-compile-sexp s end)))))
455 ;;; End of HS-style code
458 (defvar lisp-prev-l
/c-dir
/file nil
459 "Saves the (directory . file) pair used in the last lisp-load-file or
460 lisp-compile-file command. Used for determining the default in the
463 (defvar lisp-source-modes
'(lisp-mode)
464 "*Used to determine if a buffer contains Lisp source code.
465 If it's loaded into a buffer that is in one of these major modes, it's
466 considered a Lisp source file by lisp-load-file and lisp-compile-file.
467 Used by these commands to determine defaults.")
469 (defun lisp-load-file (file-name)
470 "Load a Lisp file into the inferior Lisp process."
471 (interactive (comint-get-source "Load Lisp file: " lisp-prev-l
/c-dir
/file
472 lisp-source-modes nil
)) ; NIL because LOAD
473 ; doesn't need an exact name
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 (cmulisp-proc)
478 (format inferior-lisp-load-command file-name
))
482 (defun lisp-compile-file (file-name)
483 "Compile a Lisp file in the inferior Lisp process."
484 (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l
/c-dir
/file
485 lisp-source-modes nil
)) ; NIL = don't need
487 (comint-check-source file-name
) ; Check to see if buffer needs saved.
488 (setq lisp-prev-l
/c-dir
/file
(cons (file-name-directory file-name
)
489 (file-name-nondirectory file-name
)))
490 (comint-send-string (cmulisp-proc) (concat "(compile-file \""
497 ;;; Documentation functions: function doc, var doc, arglist, and
499 ;;; ===========================================================================
504 (defvar lisp-function-doc-command
506 (format t \"Documentation for ~a:~&~a\"
507 fn (documentation fn 'function))
509 "Command to query inferior Lisp for a function's documentation.")
511 (defvar lisp-var-doc-command
513 (format t \"Documentation for ~a:~&~a\"
514 v (documentation v 'variable))
516 "Command to query inferior Lisp for a variable's documentation.")
518 (defvar lisp-arglist-command
520 (format t \"Arglist for ~a: ~a\" fn (arglist fn))
522 "Command to query inferior Lisp for a function's arglist.")
524 (defvar lisp-describe-sym-command
526 "Command to query inferior Lisp for a variable's documentation.")
529 ;;; Ancillary functions
530 ;;; ===================
532 ;;; Reads a string from the user.
533 (defun lisp-symprompt (prompt default
)
534 (list (let* ((prompt (if default
535 (format "%s (default %s): " prompt default
)
536 (concat prompt
": ")))
537 (ans (read-string prompt
)))
538 (if (zerop (length ans
)) default ans
))))
541 ;;; Adapted from function-called-at-point in help.el.
542 (defun lisp-fn-called-at-pt ()
543 "Returns the name of the function called in the current call.
544 Nil if it can't find one."
548 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
551 (let ((obj (read (current-buffer))))
552 (and (symbolp obj
) obj
))))
556 ;;; Adapted from variable-at-point in help.el.
557 (defun lisp-var-at-pt ()
561 (skip-chars-forward "'")
562 (let ((obj (read (current-buffer))))
563 (and (symbolp obj
) obj
)))
567 ;;; Documentation functions: fn and var doc, arglist, and symbol describe.
568 ;;; ======================================================================
570 (defun lisp-show-function-documentation (fn)
571 "Send a command to the inferior Lisp to give documentation for function FN.
572 See variable lisp-function-doc-command."
573 (interactive (lisp-symprompt "Function doc" (lisp-fn-called-at-pt)))
574 (comint-proc-query (cmulisp-proc) (format lisp-function-doc-command fn
)))
576 (defun lisp-show-variable-documentation (var)
577 "Send a command to the inferior Lisp to give documentation for function FN.
578 See variable lisp-var-doc-command."
579 (interactive (lisp-symprompt "Variable doc" (lisp-var-at-pt)))
580 (comint-proc-query (cmulisp-proc) (format lisp-var-doc-command var
)))
582 (defun lisp-show-arglist (fn)
583 "Sends an query to the inferior Lisp for the arglist for function FN.
584 See variable lisp-arglist-command."
585 (interactive (lisp-symprompt "Arglist" (lisp-fn-called-at-pt)))
586 (comint-proc-query (cmulisp-proc) (format lisp-arglist-command fn
)))
588 (defun lisp-describe-sym (sym)
589 "Send a command to the inferior Lisp to describe symbol SYM.
590 See variable lisp-describe-sym-command."
591 (interactive (lisp-symprompt "Describe" (lisp-var-at-pt)))
592 (comint-proc-query (cmulisp-proc) (format lisp-describe-sym-command sym
)))
595 (defvar cmulisp-buffer nil
"*The current cmulisp process buffer.
597 MULTIPLE PROCESS SUPPORT
598 ===========================================================================
599 Cmulisp.el supports, in a fairly simple fashion, running multiple Lisp
600 processes. To run multiple Lisp processes, you start the first up with
601 \\[cmulisp]. It will be in a buffer named *cmulisp*. Rename this buffer
602 with \\[rename-buffer]. You may now start up a new process with another
603 \\[cmulisp]. It will be in a new buffer, named *cmulisp*. You can
604 switch between the different process buffers with \\[switch-to-buffer].
606 Commands that send text from source buffers to Lisp processes --
607 like lisp-eval-defun or lisp-show-arglist -- have to choose a process
608 to send to, when you have more than one Lisp process around. This
609 is determined by the global variable cmulisp-buffer. Suppose you
610 have three inferior lisps running:
615 If you do a \\[lisp-eval-defun] command on some Lisp source code,
616 what process do you send it to?
618 - If you're in a process buffer (foo, bar, or *cmulisp*),
619 you send it to that process.
620 - If you're in some other buffer (e.g., a source file), you
621 send it to the process attached to buffer cmulisp-buffer.
622 This process selection is performed by function cmulisp-proc.
624 Whenever \\[cmulisp] fires up a new process, it resets cmulisp-buffer
625 to be the new process's buffer. If you only run one process, this will
626 do the right thing. If you run multiple processes, you can change
627 cmulisp-buffer to another process buffer with \\[set-variable].
629 More sophisticated approaches are, of course, possible. If you find yourself
630 needing to switch back and forth between multiple processes frequently,
631 you may wish to consider ilisp.el, a larger, more sophisticated package
632 for running inferior Lisp processes. The approach taken here is for a
633 minimal, simple implementation. Feel free to extend it.")
635 (defun cmulisp-proc ()
636 "Returns the current cmulisp process. See variable cmulisp-buffer."
637 (let ((proc (get-buffer-process (if (eq major-mode
'inferior-lisp-mode
)
641 (error "No current process. See variable cmulisp-buffer"))))
644 ;;; Do the user's customisation...
645 ;;;===============================
646 (defvar cmulisp-load-hook nil
647 "This hook is run when cmulisp is loaded in.
648 This is a good place to put keybindings.")
650 (run-hooks 'cmulisp-load-hook
)
653 ;;; ===========================================================================
655 ;;; - Split cmulisp and cmushell modes into separate files.
656 ;;; Not only is this a good idea, it's apparently the way it'll be rel 19.
657 ;;; - Upgraded process sends to use comint-send-string instead of
658 ;;; process-send-string.
659 ;;; - Explicit references to process "cmulisp" have been replaced with
660 ;;; (cmulisp-proc). This allows better handling of multiple process bufs.
661 ;;; - Added process query and var/function/symbol documentation
662 ;;; commands. Based on code written by Douglas Roberts.
663 ;;; - Added lisp-eval-last-sexp, bound to C-x C-e.
666 ;;; Added a save-restriction to lisp-fn-called-at-pt. This bug and fix
667 ;;; reported by Lennart Staflin.
670 ;;; - lisp-load-file and lisp-compile-file no longer switch-to-lisp.
671 ;;; Tale suggested this.
672 ;;; - Reversed this decision 7/15/91. You need the visual feedback.
675 ;;; Changed all keybindings of the form C-c <letter>. These are
676 ;;; supposed to be reserved for the user to bind. This affected
677 ;;; mainly the compile/eval-defun/region[-and-go] commands.
678 ;;; This was painful, but necessary to adhere to the gnumacs standard.
679 ;;; For some backwards compatibility, see the
680 ;;; cmulisp-install-letter-bindings
684 ;;; - The lisp-compile/eval-defun/region commands now take a prefix arg,
685 ;;; which means switch-to-lisp after sending the text to the Lisp process.
686 ;;; This obsoletes all the -and-go commands. The -and-go commands are
687 ;;; kept around for historical reasons, and because the user can bind
688 ;;; them to key sequences shorter than C-u C-c C-<letter>.
689 ;;; - If M-x cmulisp is invoked with a prefix arg, it allows you to
690 ;;; edit the command line.
694 ;;; cmulisp.el ends here