1 ;;; cmulisp.el --- improved version of standard inferior-lisp mode
3 ;;; Copyright Olin Shivers (1988).
4 ;;; Please imagine a long, tedious, legalistic 5-page gnu-style copyright
5 ;;; notice appearing here to the effect that you may use this code any
6 ;;; way you like, as long as you don't charge money for it, remove this
7 ;;; notice, or hold me liable for its results.
9 ;;; This replaces the standard inferior-lisp mode.
10 ;;; Hacked from tea.el by Olin Shivers (shivers@cs.cmu.edu). 8/88
11 ;;; Please send me bug reports, bug fixes, and extensions, so that I can
12 ;;; merge them into the master source.
14 ;;; Change log at end of file.
16 ;;; This file defines a a lisp-in-a-buffer package (cmulisp mode) built on top
17 ;;; of comint mode. Cmulisp mode is similar to, and intended to replace, its
18 ;;; counterpart in the standard gnu emacs release. This replacements is more
19 ;;; featureful, robust, and uniform than the released version. The key
20 ;;; bindings are also more compatible with the bindings of Hemlock and Zwei
21 ;;; (the Lisp Machine emacs).
23 ;;; Since this mode is built on top of the general command-interpreter-in-
24 ;;; a-buffer mode (comint mode), it shares a common base functionality,
25 ;;; and a common set of bindings, with all modes derived from comint mode.
26 ;;; This makes these modes easier to use.
28 ;;; For documentation on the functionality provided by comint mode, and
29 ;;; the hooks available for customising it, see the file comint.el.
30 ;;; For further information on cmulisp mode, see the comments below.
33 ;;; The load-file/compile-file default mechanism could be smarter -- it
34 ;;; doesn't know about the relationship between filename extensions and
35 ;;; whether the file is source or executable. If you compile foo.lisp
36 ;;; with compile-file, then the next load-file should use foo.bin for
37 ;;; the default, not foo.lisp. This is tricky to do right, particularly
38 ;;; because the extension for executable files varies so much (.o, .bin,
39 ;;; .lbin, .mo, .vo, .ao, ...).
41 ;;; It would be nice if cmulisp (and inferior scheme, T, ...) modes
42 ;;; had a verbose minor mode wherein sending or compiling defuns, etc.
43 ;;; would be reflected in the transcript with suitable comments, e.g.
44 ;;; ";;; redefining fact". Several ways to do this. Which is right?
46 ;;; When sending text from a source file to a subprocess, the process-mark can
47 ;;; move off the window, so you can lose sight of the process interactions.
48 ;;; Maybe I should ensure the process mark is in the window when I send
49 ;;; text to the process? Switch selectable?
53 ;;=============================================================================
54 ;; Some suggestions for your .emacs file.
56 ;; ; If cmulisp lives in some non-standard directory, you must tell emacs
57 ;; ; where to get it. This may or may not be necessary.
58 ;; (setq load-path (cons (expand-file-name "~jones/lib/emacs") load-path))
60 ;; ; Autoload cmulisp from file cmulisp.el
61 ;; (autoload 'cmulisp "cmulisp"
62 ;; "Run an inferior Lisp process."
65 ;; ; Define C-c t to run my favorite command in cmulisp mode:
66 ;; (setq cmulisp-load-hook
68 ;; (define-key cmulisp-mode-map "\C-ct" 'favorite-cmd))))
71 ;;; Brief Command Documentation:
72 ;;;============================================================================
73 ;;; Comint Mode Commands: (common to cmulisp and all comint-derived modes)
75 ;;; m-p comint-previous-input Cycle backwards in input history
76 ;;; m-n comint-next-input Cycle forwards
77 ;;; m-c-r comint-previous-input-matching Search backwards in input history
78 ;;; return comint-send-input
79 ;;; c-a comint-bol Beginning of line; skip prompt.
80 ;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff.
81 ;;; c-c c-u comint-kill-input ^u
82 ;;; c-c c-w backward-kill-word ^w
83 ;;; c-c c-c comint-interrupt-subjob ^c
84 ;;; c-c c-z comint-stop-subjob ^z
85 ;;; c-c c-\ comint-quit-subjob ^\
86 ;;; c-c c-o comint-kill-output Delete last batch of process output
87 ;;; c-c c-r comint-show-output Show last batch of process output
88 ;;; send-invisible Read line w/o echo & send to proc
89 ;;; comint-continue-subjob Useful if you accidentally suspend
91 ;;; comint-mode-hook is the comint mode hook.
93 ;;; CMU Lisp Mode Commands:
94 ;;; c-m-x lisp-send-defun This binding is a gnu convention.
95 ;;; c-c c-l lisp-load-file Prompt for file name; tell Lisp to load it.
96 ;;; c-c c-k lisp-compile-file Prompt for file name; tell Lisp to kompile it.
97 ;;; Filename completion is available, of course.
99 ;;; Additionally, these commands are added to the key bindings of Lisp mode:
100 ;;; c-m-x lisp-eval-defun This binding is a gnu convention.
101 ;;; c-c c-e lisp-eval-defun Send the current defun to Lisp process.
102 ;;; c-x c-e lisp-eval-last-sexp Send the previous sexp to Lisp process.
103 ;;; c-c c-r lisp-eval-region Send the current region to Lisp process.
104 ;;; c-c c-c lisp-compile-defun Compile the current defun in Lisp process.
105 ;;; c-c c-z switch-to-lisp Switch to the Lisp process buffer.
106 ;;; c-c c-l lisp-load-file (See above. In a Lisp file buffer, default
107 ;;; c-c c-k lisp-compile-file is to load/compile the current file.)
108 ;;; c-c c-d lisp-describe-sym Query Lisp for a symbol's description.
109 ;;; c-c c-a lisp-show-arglist Query Lisp for function's arglist.
110 ;;; c-c c-f lisp-show-function-documentation Query Lisp for a function's doc.
111 ;;; c-c c-v lisp-show-variable-documentation Query Lisp for a variable's doc.
113 ;;; cmulisp Fires up the Lisp process.
114 ;;; lisp-compile-region Compile all forms in the current region.
116 ;;; CMU Lisp Mode Variables:
117 ;;; cmulisp-filter-regexp Match this => don't get saved on input hist
118 ;;; inferior-lisp-program Name of Lisp program run-lisp executes
119 ;;; inferior-lisp-load-command Customises lisp-load-file
120 ;;; cmulisp-mode-hook
121 ;;; inferior-lisp-prompt Initialises comint-prompt-regexp.
122 ;;; Backwards compatibility.
123 ;;; lisp-source-modes Anything loaded into a buffer that's in
124 ;;; one of these modes is considered Lisp
125 ;;; source by lisp-load/compile-file.
127 ;;; Read the rest of this file for more information.
129 (defvar cmulisp-filter-regexp
"\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'"
130 "*What not to save on inferior Lisp's input history
131 Input matching this regexp is not saved on the input history in cmulisp
132 mode. Default is whitespace followed by 0 or 1 single-letter :keyword
133 (as in :a, :c, etc.)")
135 (defvar cmulisp-mode-map nil
)
136 (cond ((not cmulisp-mode-map
)
137 (setq cmulisp-mode-map
138 (full-copy-sparse-keymap comint-mode-map
))
139 (lisp-mode-commands cmulisp-mode-map
)
140 (define-key cmulisp-mode-map
"\C-x\C-e" 'lisp-eval-last-sexp
)
141 (define-key cmulisp-mode-map
"\C-c\C-l" 'lisp-load-file
)
142 (define-key cmulisp-mode-map
"\C-c\C-k" 'lisp-compile-file
)
143 (define-key cmulisp-mode-map
"\C-c\C-a" 'lisp-show-arglist
)
144 (define-key cmulisp-mode-map
"\C-c\C-d" 'lisp-describe-sym
)
145 (define-key cmulisp-mode-map
"\C-c\C-f" 'lisp-show-function-documentation
)
146 (define-key cmulisp-mode-map
"\C-c\C-v" 'lisp-show-variable-documentation
)))
148 ;;; These commands augment Lisp mode, so you can process Lisp code in
149 ;;; the source files.
150 (define-key lisp-mode-map
"\M-\C-x" 'lisp-eval-defun
) ; Gnu convention
151 (define-key lisp-mode-map
"\C-x\C-e" 'lisp-eval-last-sexp
) ; Gnu convention
152 (define-key lisp-mode-map
"\C-c\C-e" 'lisp-eval-defun
)
153 (define-key lisp-mode-map
"\C-c\C-r" 'lisp-eval-region
)
154 (define-key lisp-mode-map
"\C-c\C-c" 'lisp-compile-defun
)
155 (define-key lisp-mode-map
"\C-c\C-z" 'switch-to-lisp
)
156 (define-key lisp-mode-map
"\C-c\C-l" 'lisp-load-file
)
157 (define-key lisp-mode-map
"\C-c\C-k" 'lisp-compile-file
) ; "kompile" file
158 (define-key lisp-mode-map
"\C-c\C-a" 'lisp-show-arglist
)
159 (define-key lisp-mode-map
"\C-c\C-d" 'lisp-describe-sym
)
160 (define-key lisp-mode-map
"\C-c\C-f" 'lisp-show-function-documentation
)
161 (define-key lisp-mode-map
"\C-c\C-v" 'lisp-show-variable-documentation
)
164 ;;; This function exists for backwards compatibility.
165 ;;; Previous versions of this package bound commands to C-c <letter>
166 ;;; bindings, which is not allowed by the gnumacs standard.
168 (defun cmulisp-install-letter-bindings ()
169 "This function binds many cmulisp commands to C-c <letter> bindings,
170 where they are more accessible. C-c <letter> bindings are reserved for the
171 user, so these bindings are non-standard. If you want them, you should
172 have this function called by the cmulisp-load-hook:
173 (setq cmulisp-load-hook '(cmulisp-install-letter-bindings))
174 You can modify this function to install just the bindings you want."
176 (define-key lisp-mode-map
"\C-ce" 'lisp-eval-defun-and-go
)
177 (define-key lisp-mode-map
"\C-cr" 'lisp-eval-region-and-go
)
178 (define-key lisp-mode-map
"\C-cc" 'lisp-compile-defun-and-go
)
179 (define-key lisp-mode-map
"\C-cz" 'switch-to-lisp
)
180 (define-key lisp-mode-map
"\C-cl" 'lisp-load-file
)
181 (define-key lisp-mode-map
"\C-ck" 'lisp-compile-file
)
182 (define-key lisp-mode-map
"\C-ca" 'lisp-show-arglist
)
183 (define-key lisp-mode-map
"\C-cd" 'lisp-describe-sym
)
184 (define-key lisp-mode-map
"\C-cf" 'lisp-show-function-documentation
)
185 (define-key lisp-mode-map
"\C-cv" 'lisp-show-variable-documentation
)
187 (define-key cmulisp-mode-map
"\C-cl" 'lisp-load-file
)
188 (define-key cmulisp-mode-map
"\C-ck" 'lisp-compile-file
)
189 (define-key cmulisp-mode-map
"\C-ca" 'lisp-show-arglist
)
190 (define-key cmulisp-mode-map
"\C-cd" 'lisp-describe-sym
)
191 (define-key cmulisp-mode-map
"\C-cf" 'lisp-show-function-documentation
)
192 (define-key cmulisp-mode-map
"\C-cv" 'lisp-show-variable-documentation
))
195 (defvar inferior-lisp-program
"lisp"
196 "*Program name for invoking an inferior Lisp with `cmulisp'.")
198 (defvar inferior-lisp-load-command
"(load \"%s\")\n"
199 "*Format-string for building a Lisp expression to load a file.
200 This format string should use %s to substitute a file name
201 and should result in a Lisp expression that will command the inferior Lisp
202 to load that file. The default works acceptably on most Lisps.
203 The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\\n\"
204 produces cosmetically superior output for this application,
205 but it works only in Common Lisp.")
207 (defvar inferior-lisp-prompt
"^[^> ]*>+:? *"
208 "Regexp to recognise prompts in the inferior Lisp.
209 Defaults to \"^[^> ]*>+:? *\", which works pretty good for Lucid, kcl,
210 and franz. This variable is used to initialise comint-prompt-regexp in the
213 More precise choices:
214 Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\"
215 franz: \"^\\(->\\|<[0-9]*>:\\) *\"
218 This is a fine thing to set in your .emacs file.")
220 (defvar cmulisp-mode-hook
'()
221 "*Hook for customising cmulisp mode")
223 (defun cmulisp-mode ()
224 "Major mode for interacting with an inferior Lisp process.
225 Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an
226 Emacs buffer. Variable inferior-lisp-program controls which Lisp interpreter
227 is run. Variables inferior-lisp-prompt, cmulisp-filter-regexp and
228 inferior-lisp-load-command can customize this mode for different Lisp
231 For information on running multiple processes in multiple buffers, see
232 documentation for variable cmulisp-buffer.
236 Customisation: Entry to this mode runs the hooks on comint-mode-hook and
237 cmulisp-mode-hook (in that order).
239 You can send text to the inferior Lisp process from other buffers containing
241 switch-to-lisp switches the current buffer to the Lisp process buffer.
242 lisp-eval-defun sends the current defun to the Lisp process.
243 lisp-compile-defun compiles the current defun.
244 lisp-eval-region sends the current region to the Lisp process.
245 lisp-compile-region compiles the current region.
247 Prefixing the lisp-eval/compile-defun/region commands with
248 a \\[universal-argument] causes a switch to the Lisp process buffer after sending
252 Return after the end of the process' output sends the text from the
253 end of process to point.
254 Return before the end of the process' output copies the sexp ending at point
255 to the end of the process' output, and sends it.
256 Delete converts tabs to spaces as it moves back.
257 Tab indents for Lisp; with argument, shifts rest
258 of expression rigidly with the current line.
259 C-M-q does Tab 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]
265 (setq comint-prompt-regexp inferior-lisp-prompt
)
266 (setq major-mode
'cmulisp-mode
)
267 (setq mode-name
"CMU Lisp")
268 (setq mode-line-process
'(": %s"))
269 (if (string-match "^18.4" emacs-version
) ; hack.
270 (lisp-mode-variables) ; This is right for 18.49
271 (lisp-mode-variables t
)) ; This is right for 18.50
272 (use-local-map cmulisp-mode-map
) ;c-c c-k for "kompile" file
273 (setq comint-get-old-input
(function lisp-get-old-input
))
274 (setq comint-input-filter
(function lisp-input-filter
))
275 (setq comint-input-sentinel
'ignore
)
276 (run-hooks 'cmulisp-mode-hook
))
278 (defun lisp-get-old-input ()
279 "Snarf the sexp ending at point"
283 (buffer-substring (point) end
))))
285 (defun lisp-input-filter (str)
286 "Don't save anything matching cmulisp-filter-regexp"
287 (not (string-match cmulisp-filter-regexp str
)))
290 "Run an inferior Lisp process, input and output via buffer *cmulisp*.
291 If there is a process already running in *cmulisp*, just switch to that buffer.
292 With argument, allows you to edit the command line (default is value
293 of inferior-lisp-program). Runs the hooks from cmulisp-mode-hook (after the
294 comint-mode-hook is run).
295 \(Type \\[describe-mode] in the process buffer for a list of commands.)"
296 (interactive (list (if current-prefix-arg
297 (read-string "Run lisp: " inferior-lisp-program
)
298 inferior-lisp-program
)))
299 (if (not (comint-check-proc "*cmulisp*"))
300 (let ((cmdlist (cmulisp-args-to-list cmd
)))
301 (set-buffer (apply (function make-comint
) "cmulisp" (car cmdlist
) nil
304 (setq cmulisp-buffer
"*cmulisp*")
305 (switch-to-buffer "*cmulisp*"))
307 ;;; Break a string up into a list of arguments.
308 ;;; This will break if you have an argument with whitespace, as in
309 ;;; string = "-ab +c -x 'you lose'".
310 (defun cmulisp-args-to-list (string)
311 (let ((where (string-match "[ \t]" string
)))
312 (cond ((null where
) (list string
))
314 (cons (substring string
0 where
)
315 (tea-args-to-list (substring string
(+ 1 where
)
317 (t (let ((pos (string-match "[^ \t]" string
)))
320 (cmulsip-args-to-list (substring string pos
321 (length string
)))))))))
323 (defun lisp-eval-region (start end
&optional and-go
)
324 "Send the current region to the inferior Lisp process.
325 Prefix argument means switch-to-lisp afterwards."
327 (comint-send-region (cmulisp-proc) start end
)
328 (comint-send-string (cmulisp-proc) "\n")
329 (if and-go
(switch-to-lisp t
)))
331 (defun lisp-eval-defun (&optional and-go
)
332 "Send the current defun to the inferior Lisp process.
333 Prefix argument means switch-to-lisp afterwards."
337 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
340 (lisp-eval-region (point) end
)))
341 (if and-go
(switch-to-lisp t
)))
343 (defun lisp-eval-last-sexp (&optional and-go
)
344 "Send the previous sexp to the inferior Lisp process.
345 Prefix argument means switch-to-lisp afterwards."
347 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go
))
349 ;;; Common Lisp COMPILE sux.
350 (defun lisp-compile-region (start end
&optional and-go
)
351 "Compile the current region in the inferior Lisp process.
352 Prefix argument means switch-to-lisp afterwards."
354 (comint-send-string (cmulisp-proc)
355 (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n"
356 (buffer-substring start end
)))
357 (if and-go
(switch-to-lisp t
)))
359 (defun lisp-compile-defun (&optional and-go
)
360 "Compile the current defun in the inferior Lisp process.
361 Prefix argument means switch-to-lisp afterwards."
365 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
368 (lisp-compile-region (point) e
)))
369 (if and-go
(switch-to-lisp t
)))
371 (defun switch-to-lisp (eob-p)
372 "Switch to the inferior Lisp process buffer.
373 With argument, positions cursor at end of buffer."
375 (if (get-buffer cmulisp-buffer
)
376 (pop-to-buffer cmulisp-buffer
)
377 (error "No current process buffer. See variable cmulisp-buffer."))
380 (goto-char (point-max)))))
383 ;;; Now that lisp-compile/eval-defun/region takes an optional prefix arg,
384 ;;; these commands are redundant. But they are kept around for the user
385 ;;; to bind if he wishes, for backwards functionality, and because it's
386 ;;; easier to type C-c e than C-u C-c C-e.
388 (defun lisp-eval-region-and-go (start end
)
389 "Send the current region to the inferior Lisp,
390 and switch to the process buffer."
392 (lisp-eval-region start end t
))
394 (defun lisp-eval-defun-and-go ()
395 "Send the current defun to the inferior Lisp,
396 and switch to the process buffer."
400 (defun lisp-compile-region-and-go (start end
)
401 "Compile the current region in the inferior Lisp,
402 and switch to the process buffer."
404 (lisp-compile-region start end t
))
406 (defun lisp-compile-defun-and-go ()
407 "Compile the current defun in the inferior Lisp,
408 and switch to the process buffer."
410 (lisp-compile-defun t))
412 ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust.
413 ;(defun lisp-compile-sexp (start end)
414 ; "Compile the s-expression bounded by START and END in the inferior lisp.
415 ;If the sexp isn't a DEFUN form, it is evaluated instead."
416 ; (cond ((looking-at "(defun\\s +")
417 ; (goto-char (match-end 0))
418 ; (let ((name-start (point)))
420 ; (process-send-string "cmulisp" (format "(compile '%s #'(lambda "
421 ; (buffer-substring name-start
423 ; (let ((body-start (point)))
424 ; (goto-char start) (forward-sexp 1) ; Can't use end-of-defun.
425 ; (process-send-region "cmulisp" (buffer-substring body-start (point))))
426 ; (process-send-string "cmulisp" ")\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."
434 ; (goto-char start) (end-of-defun) (beginning-of-defun) ; error check
435 ; (if (< (point) start) (error "region begins in middle of defun"))
439 ; (while (<= (point) end) ; Zip through
440 ; (lisp-compile-sexp s (point)) ; compiling up defun-sized chunks.
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 "Saves the (directory . file) pair used in the last lisp-load-file or
450 lisp-compile-file command. Used for determining the default in the
453 (defvar 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.")
459 (defun lisp-load-file (file-name)
460 "Load a Lisp file into the inferior Lisp process."
461 (interactive (comint-get-source "Load Lisp file: " lisp-prev-l
/c-dir
/file
462 lisp-source-modes nil
)) ; NIL because LOAD
463 ; doesn't need an exact name
464 (comint-check-source file-name
) ; Check to see if buffer needs saved.
465 (setq lisp-prev-l
/c-dir
/file
(cons (file-name-directory file-name
)
466 (file-name-nondirectory file-name
)))
467 (comint-send-string (cmulisp-proc)
468 (format inferior-lisp-load-command file-name
))
472 (defun lisp-compile-file (file-name)
473 "Compile a Lisp file in the inferior Lisp process."
474 (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l
/c-dir
/file
475 lisp-source-modes nil
)) ; NIL = don't need
477 (comint-check-source file-name
) ; Check to see if buffer needs saved.
478 (setq lisp-prev-l
/c-dir
/file
(cons (file-name-directory file-name
)
479 (file-name-nondirectory file-name
)))
480 (comint-send-string (cmulisp-proc) (concat "(compile-file \""
487 ;;; Documentation functions: function doc, var doc, arglist, and
489 ;;; ===========================================================================
494 (defvar lisp-function-doc-command
496 (format t \"Documentation for ~a:~&~a\"
497 fn (documentation fn 'function))
499 "Command to query inferior Lisp for a function's documentation.")
501 (defvar lisp-var-doc-command
503 (format t \"Documentation for ~a:~&~a\"
504 v (documentation v 'variable))
506 "Command to query inferior Lisp for a variable's documentation.")
508 (defvar lisp-arglist-command
510 (format t \"Arglist for ~a: ~a\" fn (arglist fn))
512 "Command to query inferior Lisp for a function's arglist.")
514 (defvar lisp-describe-sym-command
516 "Command to query inferior Lisp for a variable's documentation.")
519 ;;; Ancillary functions
520 ;;; ===================
522 ;;; Reads a string from the user.
523 (defun lisp-symprompt (prompt default
)
524 (list (let* ((prompt (if default
525 (format "%s (default %s): " prompt default
)
526 (concat prompt
": ")))
527 (ans (read-string prompt
)))
528 (if (zerop (length ans
)) default ans
))))
531 ;;; Adapted from function-called-at-point in help.el.
532 (defun lisp-fn-called-at-pt ()
533 "Returns the name of the function called in the current call.
534 Nil if it can't find one."
538 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
541 (let ((obj (read (current-buffer))))
542 (and (symbolp obj
) obj
))))
546 ;;; Adapted from variable-at-point in help.el.
547 (defun lisp-var-at-pt ()
551 (skip-chars-forward "'")
552 (let ((obj (read (current-buffer))))
553 (and (symbolp obj
) obj
)))
557 ;;; Documentation functions: fn and var doc, arglist, and symbol describe.
558 ;;; ======================================================================
560 (defun lisp-show-function-documentation (fn)
561 "Send a command to the inferior Lisp to give documentation for function FN.
562 See variable lisp-function-doc-command."
563 (interactive (lisp-symprompt "Function doc" (lisp-fn-called-at-pt)))
564 (comint-proc-query (cmulisp-proc) (format lisp-function-doc-command fn
)))
566 (defun lisp-show-variable-documentation (var)
567 "Send a command to the inferior Lisp to give documentation for function FN.
568 See variable lisp-var-doc-command."
569 (interactive (lisp-symprompt "Variable doc" (lisp-var-at-pt)))
570 (comint-proc-query (cmulisp-proc) (format lisp-var-doc-command var
)))
572 (defun lisp-show-arglist (fn)
573 "Sends an query to the inferior Lisp for the arglist for function FN.
574 See variable lisp-arglist-command."
575 (interactive (lisp-symprompt "Arglist" (lisp-fn-called-at-pt)))
576 (comint-proc-query (cmulisp-proc) (format lisp-arglist-command fn
)))
578 (defun lisp-describe-sym (sym)
579 "Send a command to the inferior Lisp to describe symbol SYM.
580 See variable lisp-describe-sym-command."
581 (interactive (lisp-symprompt "Describe" (lisp-var-at-pt)))
582 (comint-proc-query (cmulisp-proc) (format lisp-describe-sym-command sym
)))
585 (defvar cmulisp-buffer nil
"*The current cmulisp process buffer.
587 MULTIPLE PROCESS SUPPORT
588 ===========================================================================
589 Cmulisp.el supports, in a fairly simple fashion, running multiple Lisp
590 processes. To run multiple Lisp processes, you start the first up with
591 \\[cmulisp]. It will be in a buffer named *cmulisp*. Rename this buffer
592 with \\[rename-buffer]. You may now start up a new process with another
593 \\[cmulisp]. It will be in a new buffer, named *cmulisp*. You can
594 switch between the different process buffers with \\[switch-to-buffer].
596 Commands that send text from source buffers to Lisp processes --
597 like lisp-eval-defun or lisp-show-arglist -- have to choose a process
598 to send to, when you have more than one Lisp process around. This
599 is determined by the global variable cmulisp-buffer. Suppose you
600 have three inferior lisps running:
605 If you do a \\[lisp-eval-defun] command on some Lisp source code,
606 what process do you send it to?
608 - If you're in a process buffer (foo, bar, or *cmulisp*),
609 you send it to that process.
610 - If you're in some other buffer (e.g., a source file), you
611 send it to the process attached to buffer cmulisp-buffer.
612 This process selection is performed by function cmulisp-proc.
614 Whenever \\[cmulisp] fires up a new process, it resets cmulisp-buffer
615 to be the new process's buffer. If you only run one process, this will
616 do the right thing. If you run multiple processes, you can change
617 cmulisp-buffer to another process buffer with \\[set-variable].
619 More sophisticated approaches are, of course, possible. If you find youself
620 needing to switch back and forth between multiple processes frequently,
621 you may wish to consider ilisp.el, a larger, more sophisticated package
622 for running inferior Lisp processes. The approach taken here is for a
623 minimal, simple implementation. Feel free to extend it.")
625 (defun cmulisp-proc ()
626 "Returns the current cmulisp process. See variable cmulisp-buffer."
627 (let ((proc (get-buffer-process (if (eq major-mode
'inferior-lisp-mode
)
631 (error "No current process. See variable cmulisp-buffer"))))
634 ;;; Do the user's customisation...
635 ;;;===============================
636 (defvar cmulisp-load-hook nil
637 "This hook is run when cmulisp is loaded in.
638 This is a good place to put keybindings.")
640 (run-hooks 'cmulisp-load-hook
)
643 ;;; ===========================================================================
645 ;;; - Split cmulisp and cmushell modes into separate files.
646 ;;; Not only is this a good idea, it's apparently the way it'll be rel 19.
647 ;;; - Upgraded process sends to use comint-send-string instead of
648 ;;; process-send-string.
649 ;;; - Explicit references to process "cmulisp" have been replaced with
650 ;;; (cmulisp-proc). This allows better handling of multiple process bufs.
651 ;;; - Added process query and var/function/symbol documentation
652 ;;; commands. Based on code written by Douglas Roberts.
653 ;;; - Added lisp-eval-last-sexp, bound to C-x C-e.
656 ;;; Added a save-restriction to lisp-fn-called-at-pt. This bug and fix
657 ;;; reported by Lennart Staflin.
660 ;;; - lisp-load-file and lisp-compile-file no longer switch-to-lisp.
661 ;;; Tale suggested this.
662 ;;; - Reversed this decision 7/15/91. You need the visual feedback.
665 ;;; Changed all keybindings of the form C-c <letter>. These are
666 ;;; supposed to be reserved for the user to bind. This affected
667 ;;; mainly the compile/eval-defun/region[-and-go] commands.
668 ;;; This was painful, but necessary to adhere to the gnumacs standard.
669 ;;; For some backwards compatibility, see the
670 ;;; cmulisp-install-letter-bindings
674 ;;; - The lisp-compile/eval-defun/region commands now take a prefix arg,
675 ;;; which means switch-to-lisp after sending the text to the Lisp process.
676 ;;; This obsoletes all the -and-go commands. The -and-go commands are
677 ;;; kept around for historical reasons, and because the user can bind
678 ;;; them to key sequences shorter than C-u C-c C-<letter>.
679 ;;; - If M-x cmulisp is invoked with a prefix arg, it allows you to
680 ;;; edit the command line.
684 ;;; cmulisp.el ends here