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