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