Mercurial > emacs
annotate lisp/=cmulisp.el @ 1538:2d29bf379da3
(dired-mark-confirm): For `compress', say `Compress or uncompress'.
(dired-map-over-marks-check): Likewise.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 03 Nov 1992 09:25:26 +0000 |
parents | 35a17cd4ae62 |
children | bd3c525fa6fc |
rev | line source |
---|---|
957 | 1 ;;; cmulisp.el --- improved version of standard inferior-lisp mode |
2 | |
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. | |
8 | |
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. | |
13 ;;; | |
14 ;;; Change log at end of file. | |
15 | |
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). | |
22 | |
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. | |
27 | |
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. | |
31 | |
32 ;;; Needs fixin: | |
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, ...). | |
40 ;;; | |
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? | |
45 ;;; | |
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? | |
50 | |
51 (require 'comint) | |
52 ;; YOUR .EMACS FILE | |
53 ;;============================================================================= | |
54 ;; Some suggestions for your .emacs file. | |
55 ;; | |
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)) | |
59 ;; | |
60 ;; ; Autoload cmulisp from file cmulisp.el | |
61 ;; (autoload 'cmulisp "cmulisp" | |
62 ;; "Run an inferior Lisp process." | |
63 ;; t) | |
64 ;; | |
65 ;; ; Define C-c t to run my favorite command in cmulisp mode: | |
66 ;; (setq cmulisp-load-hook | |
67 ;; '((lambda () | |
68 ;; (define-key cmulisp-mode-map "\C-ct" 'favorite-cmd)))) | |
69 | |
70 | |
71 ;;; Brief Command Documentation: | |
72 ;;;============================================================================ | |
73 ;;; Comint Mode Commands: (common to cmulisp and all comint-derived modes) | |
74 ;;; | |
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 | |
90 ;;; top-level job. | |
91 ;;; comint-mode-hook is the comint mode hook. | |
92 | |
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. | |
98 ;;; | |
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. | |
112 | |
113 ;;; cmulisp Fires up the Lisp process. | |
114 ;;; lisp-compile-region Compile all forms in the current region. | |
115 ;;; | |
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. | |
126 | |
127 ;;; Read the rest of this file for more information. | |
128 | |
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.)") | |
134 | |
135 (defvar cmulisp-mode-map nil) | |
136 (cond ((not cmulisp-mode-map) | |
137 (setq cmulisp-mode-map | |
1368
35a17cd4ae62
(cmulisp-mode): Eliminate compatibility code calling
Richard M. Stallman <rms@gnu.org>
parents:
957
diff
changeset
|
138 (nconc (full-copy-sparse-keymap comint-mode-map) |
35a17cd4ae62
(cmulisp-mode): Eliminate compatibility code calling
Richard M. Stallman <rms@gnu.org>
parents:
957
diff
changeset
|
139 shared-lisp-mode-map)) |
957 | 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))) | |
147 | |
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) | |
162 | |
1368
35a17cd4ae62
(cmulisp-mode): Eliminate compatibility code calling
Richard M. Stallman <rms@gnu.org>
parents:
957
diff
changeset
|
163 (defvar cmulisp-buffer) |
957 | 164 |
165 ;;; This function exists for backwards compatibility. | |
166 ;;; Previous versions of this package bound commands to C-c <letter> | |
167 ;;; bindings, which is not allowed by the gnumacs standard. | |
168 | |
169 (defun cmulisp-install-letter-bindings () | |
170 "This function binds many cmulisp commands to C-c <letter> bindings, | |
171 where they are more accessible. C-c <letter> bindings are reserved for the | |
172 user, so these bindings are non-standard. If you want them, you should | |
173 have this function called by the cmulisp-load-hook: | |
174 (setq cmulisp-load-hook '(cmulisp-install-letter-bindings)) | |
175 You can modify this function to install just the bindings you want." | |
176 | |
177 (define-key lisp-mode-map "\C-ce" 'lisp-eval-defun-and-go) | |
178 (define-key lisp-mode-map "\C-cr" 'lisp-eval-region-and-go) | |
179 (define-key lisp-mode-map "\C-cc" 'lisp-compile-defun-and-go) | |
180 (define-key lisp-mode-map "\C-cz" 'switch-to-lisp) | |
181 (define-key lisp-mode-map "\C-cl" 'lisp-load-file) | |
182 (define-key lisp-mode-map "\C-ck" 'lisp-compile-file) | |
183 (define-key lisp-mode-map "\C-ca" 'lisp-show-arglist) | |
184 (define-key lisp-mode-map "\C-cd" 'lisp-describe-sym) | |
185 (define-key lisp-mode-map "\C-cf" 'lisp-show-function-documentation) | |
186 (define-key lisp-mode-map "\C-cv" 'lisp-show-variable-documentation) | |
187 | |
188 (define-key cmulisp-mode-map "\C-cl" 'lisp-load-file) | |
189 (define-key cmulisp-mode-map "\C-ck" 'lisp-compile-file) | |
190 (define-key cmulisp-mode-map "\C-ca" 'lisp-show-arglist) | |
191 (define-key cmulisp-mode-map "\C-cd" 'lisp-describe-sym) | |
192 (define-key cmulisp-mode-map "\C-cf" 'lisp-show-function-documentation) | |
193 (define-key cmulisp-mode-map "\C-cv" 'lisp-show-variable-documentation)) | |
194 | |
195 | |
196 (defvar inferior-lisp-program "lisp" | |
197 "*Program name for invoking an inferior Lisp with `cmulisp'.") | |
198 | |
199 (defvar inferior-lisp-load-command "(load \"%s\")\n" | |
200 "*Format-string for building a Lisp expression to load a file. | |
201 This format string should use %s to substitute a file name | |
202 and should result in a Lisp expression that will command the inferior Lisp | |
203 to load that file. The default works acceptably on most Lisps. | |
204 The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\\n\" | |
205 produces cosmetically superior output for this application, | |
206 but it works only in Common Lisp.") | |
207 | |
208 (defvar inferior-lisp-prompt "^[^> ]*>+:? *" | |
209 "Regexp to recognise prompts in the inferior Lisp. | |
210 Defaults to \"^[^> ]*>+:? *\", which works pretty good for Lucid, kcl, | |
211 and franz. This variable is used to initialise comint-prompt-regexp in the | |
212 cmulisp buffer. | |
213 | |
214 More precise choices: | |
215 Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\" | |
216 franz: \"^\\(->\\|<[0-9]*>:\\) *\" | |
217 kcl: \"^>+ *\" | |
218 | |
219 This is a fine thing to set in your .emacs file.") | |
220 | |
221 (defvar cmulisp-mode-hook '() | |
222 "*Hook for customising cmulisp mode") | |
223 | |
224 (defun cmulisp-mode () | |
225 "Major mode for interacting with an inferior Lisp process. | |
226 Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an | |
227 Emacs buffer. Variable inferior-lisp-program controls which Lisp interpreter | |
228 is run. Variables inferior-lisp-prompt, cmulisp-filter-regexp and | |
229 inferior-lisp-load-command can customize this mode for different Lisp | |
230 interpreters. | |
231 | |
232 For information on running multiple processes in multiple buffers, see | |
233 documentation for variable cmulisp-buffer. | |
234 | |
235 \\{cmulisp-mode-map} | |
236 | |
237 Customisation: Entry to this mode runs the hooks on comint-mode-hook and | |
238 cmulisp-mode-hook (in that order). | |
239 | |
240 You can send text to the inferior Lisp process from other buffers containing | |
241 Lisp source. | |
242 switch-to-lisp switches the current buffer to the Lisp process buffer. | |
243 lisp-eval-defun sends the current defun to the Lisp process. | |
244 lisp-compile-defun compiles the current defun. | |
245 lisp-eval-region sends the current region to the Lisp process. | |
246 lisp-compile-region compiles the current region. | |
247 | |
248 Prefixing the lisp-eval/compile-defun/region commands with | |
249 a \\[universal-argument] causes a switch to the Lisp process buffer after sending | |
250 the text. | |
251 | |
252 Commands: | |
253 Return after the end of the process' output sends the text from the | |
254 end of process to point. | |
255 Return before the end of the process' output copies the sexp ending at point | |
256 to the end of the process' output, and sends it. | |
257 Delete converts tabs to spaces as it moves back. | |
258 Tab indents for Lisp; with argument, shifts rest | |
259 of expression rigidly with the current line. | |
260 C-M-q does Tab on each line starting within following expression. | |
261 Paragraphs are separated only by blank lines. Semicolons start comments. | |
262 If you accidentally suspend your process, use \\[comint-continue-subjob] | |
263 to continue it." | |
264 (interactive) | |
265 (comint-mode) | |
266 (setq comint-prompt-regexp inferior-lisp-prompt) | |
267 (setq major-mode 'cmulisp-mode) | |
268 (setq mode-name "CMU Lisp") | |
269 (setq mode-line-process '(": %s")) | |
1368
35a17cd4ae62
(cmulisp-mode): Eliminate compatibility code calling
Richard M. Stallman <rms@gnu.org>
parents:
957
diff
changeset
|
270 (lisp-mode-variables t) |
957 | 271 (use-local-map cmulisp-mode-map) ;c-c c-k for "kompile" file |
272 (setq comint-get-old-input (function lisp-get-old-input)) | |
273 (setq comint-input-filter (function lisp-input-filter)) | |
274 (setq comint-input-sentinel 'ignore) | |
275 (run-hooks 'cmulisp-mode-hook)) | |
276 | |
277 (defun lisp-get-old-input () | |
278 "Snarf the sexp ending at point" | |
279 (save-excursion | |
280 (let ((end (point))) | |
281 (backward-sexp) | |
282 (buffer-substring (point) end)))) | |
283 | |
284 (defun lisp-input-filter (str) | |
285 "Don't save anything matching cmulisp-filter-regexp" | |
286 (not (string-match cmulisp-filter-regexp str))) | |
287 | |
288 (defun cmulisp (cmd) | |
289 "Run an inferior Lisp process, input and output via buffer *cmulisp*. | |
290 If there is a process already running in *cmulisp*, just switch to that buffer. | |
291 With argument, allows you to edit the command line (default is value | |
292 of inferior-lisp-program). Runs the hooks from cmulisp-mode-hook (after the | |
293 comint-mode-hook is run). | |
294 \(Type \\[describe-mode] in the process buffer for a list of commands.)" | |
295 (interactive (list (if current-prefix-arg | |
296 (read-string "Run lisp: " inferior-lisp-program) | |
297 inferior-lisp-program))) | |
298 (if (not (comint-check-proc "*cmulisp*")) | |
299 (let ((cmdlist (cmulisp-args-to-list cmd))) | |
300 (set-buffer (apply (function make-comint) "cmulisp" (car cmdlist) nil | |
301 (cdr cmdlist))) | |
302 (cmulisp-mode))) | |
303 (setq cmulisp-buffer "*cmulisp*") | |
304 (switch-to-buffer "*cmulisp*")) | |
305 | |
306 ;;; Break a string up into a list of arguments. | |
307 ;;; This will break if you have an argument with whitespace, as in | |
308 ;;; string = "-ab +c -x 'you lose'". | |
309 (defun cmulisp-args-to-list (string) | |
310 (let ((where (string-match "[ \t]" string))) | |
311 (cond ((null where) (list string)) | |
312 ((not (= where 0)) | |
313 (cons (substring string 0 where) | |
314 (tea-args-to-list (substring string (+ 1 where) | |
315 (length string))))) | |
316 (t (let ((pos (string-match "[^ \t]" string))) | |
317 (if (null pos) | |
318 nil | |
1368
35a17cd4ae62
(cmulisp-mode): Eliminate compatibility code calling
Richard M. Stallman <rms@gnu.org>
parents:
957
diff
changeset
|
319 (cmulisp-args-to-list (substring string pos |
957 | 320 (length string))))))))) |
321 | |
322 (defun lisp-eval-region (start end &optional and-go) | |
323 "Send the current region to the inferior Lisp process. | |
324 Prefix argument means switch-to-lisp afterwards." | |
325 (interactive "r\nP") | |
326 (comint-send-region (cmulisp-proc) start end) | |
327 (comint-send-string (cmulisp-proc) "\n") | |
328 (if and-go (switch-to-lisp t))) | |
329 | |
330 (defun lisp-eval-defun (&optional and-go) | |
331 "Send the current defun to the inferior Lisp process. | |
332 Prefix argument means switch-to-lisp afterwards." | |
333 (interactive "P") | |
334 (save-excursion | |
335 (end-of-defun) | |
336 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy | |
337 (let ((end (point))) | |
338 (beginning-of-defun) | |
339 (lisp-eval-region (point) end))) | |
340 (if and-go (switch-to-lisp t))) | |
341 | |
342 (defun lisp-eval-last-sexp (&optional and-go) | |
343 "Send the previous sexp to the inferior Lisp process. | |
344 Prefix argument means switch-to-lisp afterwards." | |
345 (interactive "P") | |
346 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go)) | |
347 | |
348 ;;; Common Lisp COMPILE sux. | |
349 (defun lisp-compile-region (start end &optional and-go) | |
350 "Compile the current region in the inferior Lisp process. | |
351 Prefix argument means switch-to-lisp afterwards." | |
352 (interactive "r\nP") | |
353 (comint-send-string (cmulisp-proc) | |
354 (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n" | |
355 (buffer-substring start end))) | |
356 (if and-go (switch-to-lisp t))) | |
357 | |
358 (defun lisp-compile-defun (&optional and-go) | |
359 "Compile the current defun in the inferior Lisp process. | |
360 Prefix argument means switch-to-lisp afterwards." | |
361 (interactive "P") | |
362 (save-excursion | |
363 (end-of-defun) | |
364 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy | |
365 (let ((e (point))) | |
366 (beginning-of-defun) | |
367 (lisp-compile-region (point) e))) | |
368 (if and-go (switch-to-lisp t))) | |
369 | |
370 (defun switch-to-lisp (eob-p) | |
371 "Switch to the inferior Lisp process buffer. | |
372 With argument, positions cursor at end of buffer." | |
373 (interactive "P") | |
374 (if (get-buffer cmulisp-buffer) | |
375 (pop-to-buffer cmulisp-buffer) | |
376 (error "No current process buffer. See variable cmulisp-buffer.")) | |
377 (cond (eob-p | |
378 (push-mark) | |
379 (goto-char (point-max))))) | |
380 | |
381 | |
382 ;;; Now that lisp-compile/eval-defun/region takes an optional prefix arg, | |
383 ;;; these commands are redundant. But they are kept around for the user | |
384 ;;; to bind if he wishes, for backwards functionality, and because it's | |
385 ;;; easier to type C-c e than C-u C-c C-e. | |
386 | |
387 (defun lisp-eval-region-and-go (start end) | |
388 "Send the current region to the inferior Lisp, | |
389 and switch to the process buffer." | |
390 (interactive "r") | |
391 (lisp-eval-region start end t)) | |
392 | |
393 (defun lisp-eval-defun-and-go () | |
394 "Send the current defun to the inferior Lisp, | |
395 and switch to the process buffer." | |
396 (interactive) | |
397 (lisp-eval-defun t)) | |
398 | |
399 (defun lisp-compile-region-and-go (start end) | |
400 "Compile the current region in the inferior Lisp, | |
401 and switch to the process buffer." | |
402 (interactive "r") | |
403 (lisp-compile-region start end t)) | |
404 | |
405 (defun lisp-compile-defun-and-go () | |
406 "Compile the current defun in the inferior Lisp, | |
407 and switch to the process buffer." | |
408 (interactive) | |
409 (lisp-compile-defun t)) | |
410 | |
411 ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust. | |
412 ;(defun lisp-compile-sexp (start end) | |
413 ; "Compile the s-expression bounded by START and END in the inferior lisp. | |
414 ;If the sexp isn't a DEFUN form, it is evaluated instead." | |
415 ; (cond ((looking-at "(defun\\s +") | |
416 ; (goto-char (match-end 0)) | |
417 ; (let ((name-start (point))) | |
418 ; (forward-sexp 1) | |
419 ; (process-send-string "cmulisp" (format "(compile '%s #'(lambda " | |
420 ; (buffer-substring name-start | |
421 ; (point))))) | |
422 ; (let ((body-start (point))) | |
423 ; (goto-char start) (forward-sexp 1) ; Can't use end-of-defun. | |
424 ; (process-send-region "cmulisp" (buffer-substring body-start (point)))) | |
425 ; (process-send-string "cmulisp" ")\n")) | |
426 ; (t (lisp-eval-region start end))))) | |
427 ; | |
428 ;(defun lisp-compile-region (start end) | |
429 ; "Each s-expression in the current region is compiled (if a DEFUN) | |
430 ;or evaluated (if not) in the inferior lisp." | |
431 ; (interactive "r") | |
432 ; (save-excursion | |
433 ; (goto-char start) (end-of-defun) (beginning-of-defun) ; error check | |
434 ; (if (< (point) start) (error "region begins in middle of defun")) | |
435 ; (goto-char start) | |
436 ; (let ((s start)) | |
437 ; (end-of-defun) | |
438 ; (while (<= (point) end) ; Zip through | |
439 ; (lisp-compile-sexp s (point)) ; compiling up defun-sized chunks. | |
440 ; (setq s (point)) | |
441 ; (end-of-defun)) | |
442 ; (if (< s end) (lisp-compile-sexp s end))))) | |
443 ;;; | |
444 ;;; End of HS-style code | |
445 | |
446 | |
447 (defvar lisp-prev-l/c-dir/file nil | |
448 "Saves the (directory . file) pair used in the last lisp-load-file or | |
449 lisp-compile-file command. Used for determining the default in the | |
450 next one.") | |
451 | |
452 (defvar lisp-source-modes '(lisp-mode) | |
453 "*Used to determine if a buffer contains Lisp source code. | |
454 If it's loaded into a buffer that is in one of these major modes, it's | |
455 considered a Lisp source file by lisp-load-file and lisp-compile-file. | |
456 Used by these commands to determine defaults.") | |
457 | |
458 (defun lisp-load-file (file-name) | |
459 "Load a Lisp file into the inferior Lisp process." | |
460 (interactive (comint-get-source "Load Lisp file: " lisp-prev-l/c-dir/file | |
461 lisp-source-modes nil)) ; NIL because LOAD | |
462 ; doesn't need an exact name | |
463 (comint-check-source file-name) ; Check to see if buffer needs saved. | |
464 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name) | |
465 (file-name-nondirectory file-name))) | |
466 (comint-send-string (cmulisp-proc) | |
467 (format inferior-lisp-load-command file-name)) | |
468 (switch-to-lisp t)) | |
469 | |
470 | |
471 (defun lisp-compile-file (file-name) | |
472 "Compile a Lisp file in the inferior Lisp process." | |
473 (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l/c-dir/file | |
474 lisp-source-modes nil)) ; NIL = don't need | |
475 ; suffix .lisp | |
476 (comint-check-source file-name) ; Check to see if buffer needs saved. | |
477 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name) | |
478 (file-name-nondirectory file-name))) | |
479 (comint-send-string (cmulisp-proc) (concat "(compile-file \"" | |
480 file-name | |
481 "\"\)\n")) | |
482 (switch-to-lisp t)) | |
483 | |
484 | |
485 | |
486 ;;; Documentation functions: function doc, var doc, arglist, and | |
487 ;;; describe symbol. | |
488 ;;; =========================================================================== | |
489 | |
490 ;;; Command strings | |
491 ;;; =============== | |
492 | |
493 (defvar lisp-function-doc-command | |
494 "(let ((fn '%s)) | |
495 (format t \"Documentation for ~a:~&~a\" | |
496 fn (documentation fn 'function)) | |
497 (values))\n" | |
498 "Command to query inferior Lisp for a function's documentation.") | |
499 | |
500 (defvar lisp-var-doc-command | |
501 "(let ((v '%s)) | |
502 (format t \"Documentation for ~a:~&~a\" | |
503 v (documentation v 'variable)) | |
504 (values))\n" | |
505 "Command to query inferior Lisp for a variable's documentation.") | |
506 | |
507 (defvar lisp-arglist-command | |
508 "(let ((fn '%s)) | |
509 (format t \"Arglist for ~a: ~a\" fn (arglist fn)) | |
510 (values))\n" | |
511 "Command to query inferior Lisp for a function's arglist.") | |
512 | |
513 (defvar lisp-describe-sym-command | |
514 "(describe '%s)\n" | |
515 "Command to query inferior Lisp for a variable's documentation.") | |
516 | |
517 | |
518 ;;; Ancillary functions | |
519 ;;; =================== | |
520 | |
521 ;;; Reads a string from the user. | |
522 (defun lisp-symprompt (prompt default) | |
523 (list (let* ((prompt (if default | |
524 (format "%s (default %s): " prompt default) | |
525 (concat prompt ": "))) | |
526 (ans (read-string prompt))) | |
527 (if (zerop (length ans)) default ans)))) | |
528 | |
529 | |
530 ;;; Adapted from function-called-at-point in help.el. | |
531 (defun lisp-fn-called-at-pt () | |
532 "Returns the name of the function called in the current call. | |
533 Nil if it can't find one." | |
534 (condition-case nil | |
535 (save-excursion | |
536 (save-restriction | |
537 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max)) | |
538 (backward-up-list 1) | |
539 (forward-char 1) | |
540 (let ((obj (read (current-buffer)))) | |
541 (and (symbolp obj) obj)))) | |
542 (error nil))) | |
543 | |
544 | |
545 ;;; Adapted from variable-at-point in help.el. | |
546 (defun lisp-var-at-pt () | |
547 (condition-case () | |
548 (save-excursion | |
549 (forward-sexp -1) | |
550 (skip-chars-forward "'") | |
551 (let ((obj (read (current-buffer)))) | |
552 (and (symbolp obj) obj))) | |
553 (error nil))) | |
554 | |
555 | |
556 ;;; Documentation functions: fn and var doc, arglist, and symbol describe. | |
557 ;;; ====================================================================== | |
558 | |
559 (defun lisp-show-function-documentation (fn) | |
560 "Send a command to the inferior Lisp to give documentation for function FN. | |
561 See variable lisp-function-doc-command." | |
562 (interactive (lisp-symprompt "Function doc" (lisp-fn-called-at-pt))) | |
563 (comint-proc-query (cmulisp-proc) (format lisp-function-doc-command fn))) | |
564 | |
565 (defun lisp-show-variable-documentation (var) | |
566 "Send a command to the inferior Lisp to give documentation for function FN. | |
567 See variable lisp-var-doc-command." | |
568 (interactive (lisp-symprompt "Variable doc" (lisp-var-at-pt))) | |
569 (comint-proc-query (cmulisp-proc) (format lisp-var-doc-command var))) | |
570 | |
571 (defun lisp-show-arglist (fn) | |
572 "Sends an query to the inferior Lisp for the arglist for function FN. | |
573 See variable lisp-arglist-command." | |
574 (interactive (lisp-symprompt "Arglist" (lisp-fn-called-at-pt))) | |
575 (comint-proc-query (cmulisp-proc) (format lisp-arglist-command fn))) | |
576 | |
577 (defun lisp-describe-sym (sym) | |
578 "Send a command to the inferior Lisp to describe symbol SYM. | |
579 See variable lisp-describe-sym-command." | |
580 (interactive (lisp-symprompt "Describe" (lisp-var-at-pt))) | |
581 (comint-proc-query (cmulisp-proc) (format lisp-describe-sym-command sym))) | |
582 | |
583 | |
584 (defvar cmulisp-buffer nil "*The current cmulisp process buffer. | |
585 | |
586 MULTIPLE PROCESS SUPPORT | |
587 =========================================================================== | |
588 Cmulisp.el supports, in a fairly simple fashion, running multiple Lisp | |
589 processes. To run multiple Lisp processes, you start the first up with | |
590 \\[cmulisp]. It will be in a buffer named *cmulisp*. Rename this buffer | |
591 with \\[rename-buffer]. You may now start up a new process with another | |
592 \\[cmulisp]. It will be in a new buffer, named *cmulisp*. You can | |
593 switch between the different process buffers with \\[switch-to-buffer]. | |
594 | |
595 Commands that send text from source buffers to Lisp processes -- | |
596 like lisp-eval-defun or lisp-show-arglist -- have to choose a process | |
597 to send to, when you have more than one Lisp process around. This | |
598 is determined by the global variable cmulisp-buffer. Suppose you | |
599 have three inferior lisps running: | |
600 Buffer Process | |
601 foo cmulisp | |
602 bar cmulisp<2> | |
603 *cmulisp* cmulisp<3> | |
604 If you do a \\[lisp-eval-defun] command on some Lisp source code, | |
605 what process do you send it to? | |
606 | |
607 - If you're in a process buffer (foo, bar, or *cmulisp*), | |
608 you send it to that process. | |
609 - If you're in some other buffer (e.g., a source file), you | |
610 send it to the process attached to buffer cmulisp-buffer. | |
611 This process selection is performed by function cmulisp-proc. | |
612 | |
613 Whenever \\[cmulisp] fires up a new process, it resets cmulisp-buffer | |
614 to be the new process's buffer. If you only run one process, this will | |
615 do the right thing. If you run multiple processes, you can change | |
616 cmulisp-buffer to another process buffer with \\[set-variable]. | |
617 | |
618 More sophisticated approaches are, of course, possible. If you find youself | |
619 needing to switch back and forth between multiple processes frequently, | |
620 you may wish to consider ilisp.el, a larger, more sophisticated package | |
621 for running inferior Lisp processes. The approach taken here is for a | |
622 minimal, simple implementation. Feel free to extend it.") | |
623 | |
624 (defun cmulisp-proc () | |
625 "Returns the current cmulisp process. See variable cmulisp-buffer." | |
626 (let ((proc (get-buffer-process (if (eq major-mode 'inferior-lisp-mode) | |
627 (current-buffer) | |
628 cmulisp-buffer)))) | |
629 (or proc | |
630 (error "No current process. See variable cmulisp-buffer")))) | |
631 | |
632 | |
633 ;;; Do the user's customisation... | |
634 ;;;=============================== | |
635 (defvar cmulisp-load-hook nil | |
636 "This hook is run when cmulisp is loaded in. | |
637 This is a good place to put keybindings.") | |
638 | |
639 (run-hooks 'cmulisp-load-hook) | |
640 | |
641 ;;; CHANGE LOG | |
642 ;;; =========================================================================== | |
643 ;;; 5/24/90 Olin | |
644 ;;; - Split cmulisp and cmushell modes into separate files. | |
645 ;;; Not only is this a good idea, it's apparently the way it'll be rel 19. | |
646 ;;; - Upgraded process sends to use comint-send-string instead of | |
647 ;;; process-send-string. | |
648 ;;; - Explicit references to process "cmulisp" have been replaced with | |
649 ;;; (cmulisp-proc). This allows better handling of multiple process bufs. | |
650 ;;; - Added process query and var/function/symbol documentation | |
651 ;;; commands. Based on code written by Douglas Roberts. | |
652 ;;; - Added lisp-eval-last-sexp, bound to C-x C-e. | |
653 ;;; | |
654 ;;; 9/20/90 Olin | |
655 ;;; Added a save-restriction to lisp-fn-called-at-pt. This bug and fix | |
656 ;;; reported by Lennart Staflin. | |
657 ;;; | |
658 ;;; 3/12/90 Olin | |
659 ;;; - lisp-load-file and lisp-compile-file no longer switch-to-lisp. | |
660 ;;; Tale suggested this. | |
661 ;;; - Reversed this decision 7/15/91. You need the visual feedback. | |
662 ;;; | |
663 ;;; 7/25/91 Olin | |
664 ;;; Changed all keybindings of the form C-c <letter>. These are | |
665 ;;; supposed to be reserved for the user to bind. This affected | |
666 ;;; mainly the compile/eval-defun/region[-and-go] commands. | |
667 ;;; This was painful, but necessary to adhere to the gnumacs standard. | |
668 ;;; For some backwards compatibility, see the | |
669 ;;; cmulisp-install-letter-bindings | |
670 ;;; function. | |
671 ;;; | |
672 ;;; 8/2/91 Olin | |
673 ;;; - The lisp-compile/eval-defun/region commands now take a prefix arg, | |
674 ;;; which means switch-to-lisp after sending the text to the Lisp process. | |
675 ;;; This obsoletes all the -and-go commands. The -and-go commands are | |
676 ;;; kept around for historical reasons, and because the user can bind | |
677 ;;; them to key sequences shorter than C-u C-c C-<letter>. | |
678 ;;; - If M-x cmulisp is invoked with a prefix arg, it allows you to | |
679 ;;; edit the command line. | |
680 | |
681 (provide 'cmulisp) | |
682 | |
683 ;;; cmulisp.el ends here |