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))))
76 ;;; Brief Command Documentation:
77 ;;;============================================================================
78 ;;; Comint Mode Commands: (common to cmulisp and all comint-derived modes)
80 ;;; m-p comint-previous-input Cycle backwards in input history
81 ;;; m-n comint-next-input Cycle forwards
82 ;;; m-c-r comint-previous-input-matching Search backwards in input history
83 ;;; return comint-send-input
84 ;;; c-a comint-bol Beginning of line; skip prompt.
85 ;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff.
86 ;;; c-c c-u comint-kill-input ^u
87 ;;; c-c c-w backward-kill-word ^w
88 ;;; c-c c-c comint-interrupt-subjob ^c
89 ;;; c-c c-z comint-stop-subjob ^z
90 ;;; c-c c-\ comint-quit-subjob ^\
91 ;;; c-c c-o comint-kill-output Delete last batch of process output
92 ;;; c-c c-r comint-show-output Show last batch of process output
93 ;;; send-invisible Read line w/o echo & send to proc
94 ;;; comint-continue-subjob Useful if you accidentally suspend
96 ;;; comint-mode-hook is the comint mode hook.
98 ;;; CMU Lisp Mode Commands:
99 ;;; c-m-x lisp-send-defun This binding is a gnu convention.
100 ;;; c-c c-l lisp-load-file Prompt for file name; tell Lisp to load it.
101 ;;; c-c c-k lisp-compile-file Prompt for file name; tell Lisp to kompile it.
102 ;;; Filename completion is available, of course.
104 ;;; Additionally, these commands are added to the key bindings of Lisp mode:
105 ;;; c-m-x lisp-eval-defun This binding is a gnu convention.
106 ;;; c-c c-e lisp-eval-defun Send the current defun to Lisp process.
107 ;;; c-x c-e lisp-eval-last-sexp Send the previous sexp to Lisp process.
108 ;;; c-c c-r lisp-eval-region Send the current region to Lisp process.
109 ;;; c-c c-c lisp-compile-defun Compile the current defun in Lisp process.
110 ;;; c-c c-z switch-to-lisp Switch to the Lisp process buffer.
111 ;;; c-c c-l lisp-load-file (See above. In a Lisp file buffer, default
112 ;;; c-c c-k lisp-compile-file is to load/compile the current file.)
113 ;;; c-c c-d lisp-describe-sym Query Lisp for a symbol's description.
114 ;;; c-c c-a lisp-show-arglist Query Lisp for function's arglist.
115 ;;; c-c c-f lisp-show-function-documentation Query Lisp for a function's doc.
116 ;;; c-c c-v lisp-show-variable-documentation Query Lisp for a variable's doc.
118 ;;; cmulisp Fires up the Lisp process.
119 ;;; lisp-compile-region Compile all forms in the current region.
121 ;;; CMU Lisp Mode Variables:
122 ;;; cmulisp-filter-regexp Match this => don't get saved on input hist
123 ;;; inferior-lisp-program Name of Lisp program run-lisp executes
124 ;;; inferior-lisp-load-command Customises lisp-load-file
125 ;;; cmulisp-mode-hook
126 ;;; inferior-lisp-prompt Initialises comint-prompt-regexp.
127 ;;; Backwards compatibility.
128 ;;; lisp-source-modes Anything loaded into a buffer that's in
129 ;;; one of these modes is considered Lisp
130 ;;; source by lisp-load/compile-file.
132 ;;; Read the rest of this file for more information.
137 (defvar cmulisp-filter-regexp
"\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'"
138 "*What not to save on inferior Lisp's input history
139 Input matching this regexp is not saved on the input history in cmulisp
140 mode. Default is whitespace followed by 0 or 1 single-letter :keyword
141 (as in :a, :c, etc.)")
143 (defvar cmulisp-mode-map nil
)
144 (cond ((not cmulisp-mode-map
)
145 (setq cmulisp-mode-map
146 (nconc (full-copy-sparse-keymap comint-mode-map
)
147 shared-lisp-mode-map
))
148 (define-key cmulisp-mode-map
"\C-x\C-e" 'lisp-eval-last-sexp
)
149 (define-key cmulisp-mode-map
"\C-c\C-l" 'lisp-load-file
)
150 (define-key cmulisp-mode-map
"\C-c\C-k" 'lisp-compile-file
)
151 (define-key cmulisp-mode-map
"\C-c\C-a" 'lisp-show-arglist
)
152 (define-key cmulisp-mode-map
"\C-c\C-d" 'lisp-describe-sym
)
153 (define-key cmulisp-mode-map
"\C-c\C-f" 'lisp-show-function-documentation
)
154 (define-key cmulisp-mode-map
"\C-c\C-v" 'lisp-show-variable-documentation
)))
156 ;;; These commands augment Lisp mode, so you can process Lisp code in
157 ;;; the source files.
158 (define-key lisp-mode-map
"\M-\C-x" 'lisp-eval-defun
) ; Gnu convention
159 (define-key lisp-mode-map
"\C-x\C-e" 'lisp-eval-last-sexp
) ; Gnu convention
160 (define-key lisp-mode-map
"\C-c\C-e" 'lisp-eval-defun
)
161 (define-key lisp-mode-map
"\C-c\C-r" 'lisp-eval-region
)
162 (define-key lisp-mode-map
"\C-c\C-c" 'lisp-compile-defun
)
163 (define-key lisp-mode-map
"\C-c\C-z" 'switch-to-lisp
)
164 (define-key lisp-mode-map
"\C-c\C-l" 'lisp-load-file
)
165 (define-key lisp-mode-map
"\C-c\C-k" 'lisp-compile-file
) ; "kompile" file
166 (define-key lisp-mode-map
"\C-c\C-a" 'lisp-show-arglist
)
167 (define-key lisp-mode-map
"\C-c\C-d" 'lisp-describe-sym
)
168 (define-key lisp-mode-map
"\C-c\C-f" 'lisp-show-function-documentation
)
169 (define-key lisp-mode-map
"\C-c\C-v" 'lisp-show-variable-documentation
)
171 (defvar cmulisp-buffer
)
173 ;;; This function exists for backwards compatibility.
174 ;;; Previous versions of this package bound commands to C-c <letter>
175 ;;; bindings, which is not allowed by the gnumacs standard.
177 (defun cmulisp-install-letter-bindings ()
178 "This function binds many cmulisp commands to C-c <letter> bindings,
179 where they are more accessible. C-c <letter> bindings are reserved for the
180 user, so these bindings are non-standard. If you want them, you should
181 have this function called by the cmulisp-load-hook:
182 (setq cmulisp-load-hook '(cmulisp-install-letter-bindings))
183 You can modify this function to install just the bindings you want."
185 (define-key lisp-mode-map
"\C-ce" 'lisp-eval-defun-and-go
)
186 (define-key lisp-mode-map
"\C-cr" 'lisp-eval-region-and-go
)
187 (define-key lisp-mode-map
"\C-cc" 'lisp-compile-defun-and-go
)
188 (define-key lisp-mode-map
"\C-cz" 'switch-to-lisp
)
189 (define-key lisp-mode-map
"\C-cl" 'lisp-load-file
)
190 (define-key lisp-mode-map
"\C-ck" 'lisp-compile-file
)
191 (define-key lisp-mode-map
"\C-ca" 'lisp-show-arglist
)
192 (define-key lisp-mode-map
"\C-cd" 'lisp-describe-sym
)
193 (define-key lisp-mode-map
"\C-cf" 'lisp-show-function-documentation
)
194 (define-key lisp-mode-map
"\C-cv" 'lisp-show-variable-documentation
)
196 (define-key cmulisp-mode-map
"\C-cl" 'lisp-load-file
)
197 (define-key cmulisp-mode-map
"\C-ck" 'lisp-compile-file
)
198 (define-key cmulisp-mode-map
"\C-ca" 'lisp-show-arglist
)
199 (define-key cmulisp-mode-map
"\C-cd" 'lisp-describe-sym
)
200 (define-key cmulisp-mode-map
"\C-cf" 'lisp-show-function-documentation
)
201 (define-key cmulisp-mode-map
"\C-cv" 'lisp-show-variable-documentation
))
204 (defvar inferior-lisp-program
"lisp"
205 "*Program name for invoking an inferior Lisp with `cmulisp'.")
207 (defvar inferior-lisp-load-command
"(load \"%s\")\n"
208 "*Format-string for building a Lisp expression to load a file.
209 This format string should use %s to substitute a file name
210 and should result in a Lisp expression that will command the inferior Lisp
211 to load that file. The default works acceptably on most Lisps.
212 The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\\n\"
213 produces cosmetically superior output for this application,
214 but it works only in Common Lisp.")
216 (defvar inferior-lisp-prompt
"^[^> ]*>+:? *"
217 "Regexp to recognise prompts in the inferior Lisp.
218 Defaults to \"^[^> ]*>+:? *\", which works pretty good for Lucid, kcl,
219 and franz. This variable is used to initialise comint-prompt-regexp in the
222 More precise choices:
223 Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\"
224 franz: \"^\\(->\\|<[0-9]*>:\\) *\"
227 This is a fine thing to set in your .emacs file.")
229 (defvar cmulisp-mode-hook
'()
230 "*Hook for customising cmulisp mode")
232 (defun cmulisp-mode ()
233 "Major mode for interacting with an inferior Lisp process.
234 Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an
235 Emacs buffer. Variable inferior-lisp-program controls which Lisp interpreter
236 is run. Variables inferior-lisp-prompt, cmulisp-filter-regexp and
237 inferior-lisp-load-command can customize this mode for different Lisp
240 For information on running multiple processes in multiple buffers, see
241 documentation for variable cmulisp-buffer.
245 Customisation: Entry to this mode runs the hooks on comint-mode-hook and
246 cmulisp-mode-hook (in that order).
248 You can send text to the inferior Lisp process from other buffers containing
250 switch-to-lisp switches the current buffer to the Lisp process buffer.
251 lisp-eval-defun sends the current defun to the Lisp process.
252 lisp-compile-defun compiles the current defun.
253 lisp-eval-region sends the current region to the Lisp process.
254 lisp-compile-region compiles the current region.
256 Prefixing the lisp-eval/compile-defun/region commands with
257 a \\[universal-argument] causes a switch to the Lisp process buffer after sending
261 Return after the end of the process' output sends the text from the
262 end of process to point.
263 Return before the end of the process' output copies the sexp ending at point
264 to the end of the process' output, and sends it.
265 Delete converts tabs to spaces as it moves back.
266 Tab indents for Lisp; with argument, shifts rest
267 of expression rigidly with the current line.
268 C-M-q does Tab on each line starting within following expression.
269 Paragraphs are separated only by blank lines. Semicolons start comments.
270 If you accidentally suspend your process, use \\[comint-continue-subjob]
274 (setq comint-prompt-regexp inferior-lisp-prompt
)
275 (setq major-mode
'cmulisp-mode
)
276 (setq mode-name
"CMU Lisp")
277 (setq mode-line-process
'(": %s"))
278 (lisp-mode-variables t
)
279 (use-local-map cmulisp-mode-map
) ;c-c c-k for "kompile" file
280 (setq comint-get-old-input
(function lisp-get-old-input
))
281 (setq comint-input-filter
(function lisp-input-filter
))
282 (setq comint-input-sentinel
'ignore
)
283 (run-hooks 'cmulisp-mode-hook
))
285 (defun lisp-get-old-input ()
286 "Snarf the sexp ending at point"
290 (buffer-substring (point) end
))))
292 (defun lisp-input-filter (str)
293 "Don't save anything matching cmulisp-filter-regexp"
294 (not (string-match cmulisp-filter-regexp str
)))
297 "Run an inferior Lisp process, input and output via buffer *cmulisp*.
298 If there is a process already running in *cmulisp*, just switch to that buffer.
299 With argument, allows you to edit the command line (default is value
300 of inferior-lisp-program). Runs the hooks from cmulisp-mode-hook (after the
301 comint-mode-hook is run).
302 \(Type \\[describe-mode] in the process buffer for a list of commands.)"
303 (interactive (list (if current-prefix-arg
304 (read-string "Run lisp: " inferior-lisp-program
)
305 inferior-lisp-program
)))
306 (if (not (comint-check-proc "*cmulisp*"))
307 (let ((cmdlist (cmulisp-args-to-list cmd
)))
308 (set-buffer (apply (function make-comint
) "cmulisp" (car cmdlist
) nil
311 (setq cmulisp-buffer
"*cmulisp*")
312 (switch-to-buffer "*cmulisp*"))
314 ;;; Break a string up into a list of arguments.
315 ;;; This will break if you have an argument with whitespace, as in
316 ;;; string = "-ab +c -x 'you lose'".
317 (defun cmulisp-args-to-list (string)
318 (let ((where (string-match "[ \t]" string
)))
319 (cond ((null where
) (list string
))
321 (cons (substring string
0 where
)
322 (tea-args-to-list (substring string
(+ 1 where
)
324 (t (let ((pos (string-match "[^ \t]" string
)))
327 (cmulisp-args-to-list (substring string pos
328 (length string
)))))))))
330 (defun lisp-eval-region (start end
&optional and-go
)
331 "Send the current region to the inferior Lisp process.
332 Prefix argument means switch-to-lisp afterwards."
334 (comint-send-region (cmulisp-proc) start end
)
335 (comint-send-string (cmulisp-proc) "\n")
336 (if and-go
(switch-to-lisp t
)))
338 (defun lisp-eval-defun (&optional and-go
)
339 "Send the current defun to the inferior Lisp process.
340 Prefix argument means switch-to-lisp afterwards."
344 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
347 (lisp-eval-region (point) end
)))
348 (if and-go
(switch-to-lisp t
)))
350 (defun lisp-eval-last-sexp (&optional and-go
)
351 "Send the previous sexp to the inferior Lisp process.
352 Prefix argument means switch-to-lisp afterwards."
354 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go
))
356 ;;; Common Lisp COMPILE sux.
357 (defun lisp-compile-region (start end
&optional and-go
)
358 "Compile the current region in the inferior Lisp process.
359 Prefix argument means switch-to-lisp afterwards."
361 (comint-send-string (cmulisp-proc)
362 (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n"
363 (buffer-substring start end
)))
364 (if and-go
(switch-to-lisp t
)))
366 (defun lisp-compile-defun (&optional and-go
)
367 "Compile the current defun in the inferior Lisp process.
368 Prefix argument means switch-to-lisp afterwards."
372 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
375 (lisp-compile-region (point) e
)))
376 (if and-go
(switch-to-lisp t
)))
378 (defun switch-to-lisp (eob-p)
379 "Switch to the inferior Lisp process buffer.
380 With argument, positions cursor at end of buffer."
382 (if (get-buffer cmulisp-buffer
)
383 (pop-to-buffer cmulisp-buffer
)
384 (error "No current process buffer. See variable cmulisp-buffer."))
387 (goto-char (point-max)))))
390 ;;; Now that lisp-compile/eval-defun/region takes an optional prefix arg,
391 ;;; these commands are redundant. But they are kept around for the user
392 ;;; to bind if he wishes, for backwards functionality, and because it's
393 ;;; easier to type C-c e than C-u C-c C-e.
395 (defun lisp-eval-region-and-go (start end
)
396 "Send the current region to the inferior Lisp,
397 and switch to the process buffer."
399 (lisp-eval-region start end t
))
401 (defun lisp-eval-defun-and-go ()
402 "Send the current defun to the inferior Lisp,
403 and switch to the process buffer."
407 (defun lisp-compile-region-and-go (start end
)
408 "Compile the current region in the inferior Lisp,
409 and switch to the process buffer."
411 (lisp-compile-region start end t
))
413 (defun lisp-compile-defun-and-go ()
414 "Compile the current defun in the inferior Lisp,
415 and switch to the process buffer."
417 (lisp-compile-defun t))
419 ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust.
420 ;(defun lisp-compile-sexp (start end)
421 ; "Compile the s-expression bounded by START and END in the inferior lisp.
422 ;If the sexp isn't a DEFUN form, it is evaluated instead."
423 ; (cond ((looking-at "(defun\\s +")
424 ; (goto-char (match-end 0))
425 ; (let ((name-start (point)))
427 ; (process-send-string "cmulisp" (format "(compile '%s #'(lambda "
428 ; (buffer-substring name-start
430 ; (let ((body-start (point)))
431 ; (goto-char start) (forward-sexp 1) ; Can't use end-of-defun.
432 ; (process-send-region "cmulisp" (buffer-substring body-start (point))))
433 ; (process-send-string "cmulisp" ")\n"))
434 ; (t (lisp-eval-region start end)))))
436 ;(defun lisp-compile-region (start end)
437 ; "Each s-expression in the current region is compiled (if a DEFUN)
438 ;or evaluated (if not) in the inferior lisp."
441 ; (goto-char start) (end-of-defun) (beginning-of-defun) ; error check
442 ; (if (< (point) start) (error "region begins in middle of defun"))
446 ; (while (<= (point) end) ; Zip through
447 ; (lisp-compile-sexp s (point)) ; compiling up defun-sized chunks.
450 ; (if (< s end) (lisp-compile-sexp s end)))))
452 ;;; End of HS-style code
455 (defvar lisp-prev-l
/c-dir
/file nil
456 "Saves the (directory . file) pair used in the last lisp-load-file or
457 lisp-compile-file command. Used for determining the default in the
460 (defvar lisp-source-modes
'(lisp-mode)
461 "*Used to determine if a buffer contains Lisp source code.
462 If it's loaded into a buffer that is in one of these major modes, it's
463 considered a Lisp source file by lisp-load-file and lisp-compile-file.
464 Used by these commands to determine defaults.")
466 (defun lisp-load-file (file-name)
467 "Load a Lisp file into the inferior Lisp process."
468 (interactive (comint-get-source "Load Lisp file: " lisp-prev-l
/c-dir
/file
469 lisp-source-modes nil
)) ; NIL because LOAD
470 ; doesn't need an exact name
471 (comint-check-source file-name
) ; Check to see if buffer needs saved.
472 (setq lisp-prev-l
/c-dir
/file
(cons (file-name-directory file-name
)
473 (file-name-nondirectory file-name
)))
474 (comint-send-string (cmulisp-proc)
475 (format inferior-lisp-load-command file-name
))
479 (defun lisp-compile-file (file-name)
480 "Compile a Lisp file in the inferior Lisp process."
481 (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l
/c-dir
/file
482 lisp-source-modes nil
)) ; NIL = don't need
484 (comint-check-source file-name
) ; Check to see if buffer needs saved.
485 (setq lisp-prev-l
/c-dir
/file
(cons (file-name-directory file-name
)
486 (file-name-nondirectory file-name
)))
487 (comint-send-string (cmulisp-proc) (concat "(compile-file \""
494 ;;; Documentation functions: function doc, var doc, arglist, and
496 ;;; ===========================================================================
501 (defvar lisp-function-doc-command
503 (format t \"Documentation for ~a:~&~a\"
504 fn (documentation fn 'function))
506 "Command to query inferior Lisp for a function's documentation.")
508 (defvar lisp-var-doc-command
510 (format t \"Documentation for ~a:~&~a\"
511 v (documentation v 'variable))
513 "Command to query inferior Lisp for a variable's documentation.")
515 (defvar lisp-arglist-command
517 (format t \"Arglist for ~a: ~a\" fn (arglist fn))
519 "Command to query inferior Lisp for a function's arglist.")
521 (defvar lisp-describe-sym-command
523 "Command to query inferior Lisp for a variable's documentation.")
526 ;;; Ancillary functions
527 ;;; ===================
529 ;;; Reads a string from the user.
530 (defun lisp-symprompt (prompt default
)
531 (list (let* ((prompt (if default
532 (format "%s (default %s): " prompt default
)
533 (concat prompt
": ")))
534 (ans (read-string prompt
)))
535 (if (zerop (length ans
)) default ans
))))
538 ;;; Adapted from function-called-at-point in help.el.
539 (defun lisp-fn-called-at-pt ()
540 "Returns the name of the function called in the current call.
541 Nil if it can't find one."
545 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
548 (let ((obj (read (current-buffer))))
549 (and (symbolp obj
) obj
))))
553 ;;; Adapted from variable-at-point in help.el.
554 (defun lisp-var-at-pt ()
558 (skip-chars-forward "'")
559 (let ((obj (read (current-buffer))))
560 (and (symbolp obj
) obj
)))
564 ;;; Documentation functions: fn and var doc, arglist, and symbol describe.
565 ;;; ======================================================================
567 (defun lisp-show-function-documentation (fn)
568 "Send a command to the inferior Lisp to give documentation for function FN.
569 See variable lisp-function-doc-command."
570 (interactive (lisp-symprompt "Function doc" (lisp-fn-called-at-pt)))
571 (comint-proc-query (cmulisp-proc) (format lisp-function-doc-command fn
)))
573 (defun lisp-show-variable-documentation (var)
574 "Send a command to the inferior Lisp to give documentation for function FN.
575 See variable lisp-var-doc-command."
576 (interactive (lisp-symprompt "Variable doc" (lisp-var-at-pt)))
577 (comint-proc-query (cmulisp-proc) (format lisp-var-doc-command var
)))
579 (defun lisp-show-arglist (fn)
580 "Sends an query to the inferior Lisp for the arglist for function FN.
581 See variable lisp-arglist-command."
582 (interactive (lisp-symprompt "Arglist" (lisp-fn-called-at-pt)))
583 (comint-proc-query (cmulisp-proc) (format lisp-arglist-command fn
)))
585 (defun lisp-describe-sym (sym)
586 "Send a command to the inferior Lisp to describe symbol SYM.
587 See variable lisp-describe-sym-command."
588 (interactive (lisp-symprompt "Describe" (lisp-var-at-pt)))
589 (comint-proc-query (cmulisp-proc) (format lisp-describe-sym-command sym
)))
592 (defvar cmulisp-buffer nil
"*The current cmulisp process buffer.
594 MULTIPLE PROCESS SUPPORT
595 ===========================================================================
596 Cmulisp.el supports, in a fairly simple fashion, running multiple Lisp
597 processes. To run multiple Lisp processes, you start the first up with
598 \\[cmulisp]. It will be in a buffer named *cmulisp*. Rename this buffer
599 with \\[rename-buffer]. You may now start up a new process with another
600 \\[cmulisp]. It will be in a new buffer, named *cmulisp*. You can
601 switch between the different process buffers with \\[switch-to-buffer].
603 Commands that send text from source buffers to Lisp processes --
604 like lisp-eval-defun or lisp-show-arglist -- have to choose a process
605 to send to, when you have more than one Lisp process around. This
606 is determined by the global variable cmulisp-buffer. Suppose you
607 have three inferior lisps running:
612 If you do a \\[lisp-eval-defun] command on some Lisp source code,
613 what process do you send it to?
615 - If you're in a process buffer (foo, bar, or *cmulisp*),
616 you send it to that process.
617 - If you're in some other buffer (e.g., a source file), you
618 send it to the process attached to buffer cmulisp-buffer.
619 This process selection is performed by function cmulisp-proc.
621 Whenever \\[cmulisp] fires up a new process, it resets cmulisp-buffer
622 to be the new process's buffer. If you only run one process, this will
623 do the right thing. If you run multiple processes, you can change
624 cmulisp-buffer to another process buffer with \\[set-variable].
626 More sophisticated approaches are, of course, possible. If you find youself
627 needing to switch back and forth between multiple processes frequently,
628 you may wish to consider ilisp.el, a larger, more sophisticated package
629 for running inferior Lisp processes. The approach taken here is for a
630 minimal, simple implementation. Feel free to extend it.")
632 (defun cmulisp-proc ()
633 "Returns the current cmulisp process. See variable cmulisp-buffer."
634 (let ((proc (get-buffer-process (if (eq major-mode
'inferior-lisp-mode
)
638 (error "No current process. See variable cmulisp-buffer"))))
641 ;;; Do the user's customisation...
642 ;;;===============================
643 (defvar cmulisp-load-hook nil
644 "This hook is run when cmulisp is loaded in.
645 This is a good place to put keybindings.")
647 (run-hooks 'cmulisp-load-hook
)
650 ;;; ===========================================================================
652 ;;; - Split cmulisp and cmushell modes into separate files.
653 ;;; Not only is this a good idea, it's apparently the way it'll be rel 19.
654 ;;; - Upgraded process sends to use comint-send-string instead of
655 ;;; process-send-string.
656 ;;; - Explicit references to process "cmulisp" have been replaced with
657 ;;; (cmulisp-proc). This allows better handling of multiple process bufs.
658 ;;; - Added process query and var/function/symbol documentation
659 ;;; commands. Based on code written by Douglas Roberts.
660 ;;; - Added lisp-eval-last-sexp, bound to C-x C-e.
663 ;;; Added a save-restriction to lisp-fn-called-at-pt. This bug and fix
664 ;;; reported by Lennart Staflin.
667 ;;; - lisp-load-file and lisp-compile-file no longer switch-to-lisp.
668 ;;; Tale suggested this.
669 ;;; - Reversed this decision 7/15/91. You need the visual feedback.
672 ;;; Changed all keybindings of the form C-c <letter>. These are
673 ;;; supposed to be reserved for the user to bind. This affected
674 ;;; mainly the compile/eval-defun/region[-and-go] commands.
675 ;;; This was painful, but necessary to adhere to the gnumacs standard.
676 ;;; For some backwards compatibility, see the
677 ;;; cmulisp-install-letter-bindings
681 ;;; - The lisp-compile/eval-defun/region commands now take a prefix arg,
682 ;;; which means switch-to-lisp after sending the text to the Lisp process.
683 ;;; This obsoletes all the -and-go commands. The -and-go commands are
684 ;;; kept around for historical reasons, and because the user can bind
685 ;;; them to key sequences shorter than C-u C-c C-<letter>.
686 ;;; - If M-x cmulisp is invoked with a prefix arg, it allows you to
687 ;;; edit the command line.
691 ;;; cmulisp.el ends here