Mercurial > emacs
annotate lisp/progmodes/inf-lisp.el @ 3706:5a563b062c0d
(term_get_fkeys): Use `prior', not `previous', for %8/kP.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 13 Jun 1993 00:41:51 +0000 |
parents | 25743b083fe8 |
children | f344542ac7fd |
rev | line source |
---|---|
835 | 1 ;;; inf-lisp.el --- an inferior-lisp mode |
3663 | 2 ;;; Copyright (C) 1988, 1993 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> |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
957
diff
changeset
|
5 ;; Keywords: 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 | |
798
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
727
diff
changeset
|
61 ;;; Code: |
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
727
diff
changeset
|
62 |
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
727
diff
changeset
|
63 (require 'comint) |
836 | 64 (require 'lisp-mode) |
65 | |
267 | 66 |
957 | 67 ;;;###autoload |
835 | 68 (defvar inferior-lisp-filter-regexp "\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'" |
3663 | 69 "*What not to save on inferior Lisp's input history. |
70 Input matching this regexp is not saved on the input history in Inferior Lisp | |
71 mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword | |
267 | 72 (as in :a, :c, etc.)") |
73 | |
835 | 74 (defvar inferior-lisp-mode-map nil) |
75 (cond ((not inferior-lisp-mode-map) | |
76 (setq inferior-lisp-mode-map | |
267 | 77 (full-copy-sparse-keymap comint-mode-map)) |
835 | 78 (setq inferior-lisp-mode-map |
79 (nconc inferior-lisp-mode-map shared-lisp-mode-map)) | |
3663 | 80 ;; Make separate prefix definitions so that we don't clobber the ones |
81 ;; inherited from other keymaps. | |
82 (define-key inferior-lisp-mode-map "\C-x" (make-sparse-keymap)) | |
83 (define-key inferior-lisp-mode-map "\C-c" (make-sparse-keymap)) | |
84 (define-key inferior-lisp-mode-map "\e" (make-sparse-keymap)) | |
835 | 85 (define-key inferior-lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp) |
86 (define-key inferior-lisp-mode-map "\C-c\C-l" 'lisp-load-file) | |
87 (define-key inferior-lisp-mode-map "\C-c\C-k" 'lisp-compile-file) | |
88 (define-key inferior-lisp-mode-map "\C-c\C-a" 'lisp-show-arglist) | |
89 (define-key inferior-lisp-mode-map "\C-c\C-d" 'lisp-describe-sym) | |
90 (define-key inferior-lisp-mode-map "\C-c\C-f" | |
91 'lisp-show-function-documentation) | |
92 (define-key inferior-lisp-mode-map "\C-c\C-v" | |
93 'lisp-show-variable-documentation))) | |
267 | 94 |
95 ;;; These commands augment Lisp mode, so you can process Lisp code in | |
96 ;;; the source files. | |
97 (define-key lisp-mode-map "\M-\C-x" 'lisp-eval-defun) ; Gnu convention | |
98 (define-key lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp) ; Gnu convention | |
99 (define-key lisp-mode-map "\C-c\C-e" 'lisp-eval-defun) | |
100 (define-key lisp-mode-map "\C-c\C-r" 'lisp-eval-region) | |
101 (define-key lisp-mode-map "\C-c\C-c" 'lisp-compile-defun) | |
102 (define-key lisp-mode-map "\C-c\C-z" 'switch-to-lisp) | |
103 (define-key lisp-mode-map "\C-c\C-l" 'lisp-load-file) | |
104 (define-key lisp-mode-map "\C-c\C-k" 'lisp-compile-file) ; "kompile" file | |
105 (define-key lisp-mode-map "\C-c\C-a" 'lisp-show-arglist) | |
106 (define-key lisp-mode-map "\C-c\C-d" 'lisp-describe-sym) | |
107 (define-key lisp-mode-map "\C-c\C-f" 'lisp-show-function-documentation) | |
108 (define-key lisp-mode-map "\C-c\C-v" 'lisp-show-variable-documentation) | |
109 | |
110 | |
727 | 111 ;;; This function exists for backwards compatibility. |
112 ;;; Previous versions of this package bound commands to C-c <letter> | |
113 ;;; bindings, which is not allowed by the gnumacs standard. | |
114 | |
3663 | 115 ;;; "This function binds many inferior-lisp commands to C-c <letter> bindings, |
116 ;;;where they are more accessible. C-c <letter> bindings are reserved for the | |
117 ;;;user, so these bindings are non-standard. If you want them, you should | |
118 ;;;have this function called by the inferior-lisp-load-hook: | |
119 ;;; (setq inferior-lisp-load-hook '(inferior-lisp-install-letter-bindings)) | |
120 ;;;You can modify this function to install just the bindings you want." | |
835 | 121 (defun inferior-lisp-install-letter-bindings () |
727 | 122 (define-key lisp-mode-map "\C-ce" 'lisp-eval-defun-and-go) |
123 (define-key lisp-mode-map "\C-cr" 'lisp-eval-region-and-go) | |
124 (define-key lisp-mode-map "\C-cc" 'lisp-compile-defun-and-go) | |
125 (define-key lisp-mode-map "\C-cz" 'switch-to-lisp) | |
126 (define-key lisp-mode-map "\C-cl" 'lisp-load-file) | |
127 (define-key lisp-mode-map "\C-ck" 'lisp-compile-file) | |
128 (define-key lisp-mode-map "\C-ca" 'lisp-show-arglist) | |
129 (define-key lisp-mode-map "\C-cd" 'lisp-describe-sym) | |
130 (define-key lisp-mode-map "\C-cf" 'lisp-show-function-documentation) | |
131 (define-key lisp-mode-map "\C-cv" 'lisp-show-variable-documentation) | |
835 | 132 |
133 (define-key inferior-lisp-mode-map "\C-cl" 'lisp-load-file) | |
134 (define-key inferior-lisp-mode-map "\C-ck" 'lisp-compile-file) | |
135 (define-key inferior-lisp-mode-map "\C-ca" 'lisp-show-arglist) | |
136 (define-key inferior-lisp-mode-map "\C-cd" 'lisp-describe-sym) | |
137 (define-key inferior-lisp-mode-map "\C-cf" 'lisp-show-function-documentation) | |
138 (define-key inferior-lisp-mode-map "\C-cv" | |
139 'lisp-show-variable-documentation)) | |
727 | 140 |
141 | |
957 | 142 ;;;###autoload |
267 | 143 (defvar inferior-lisp-program "lisp" |
3663 | 144 "*Program name for invoking an inferior Lisp with for Inferior Lisp mode.") |
267 | 145 |
957 | 146 ;;;###autoload |
267 | 147 (defvar inferior-lisp-load-command "(load \"%s\")\n" |
148 "*Format-string for building a Lisp expression to load a file. | |
3663 | 149 This format string should use `%s' to substitute a file name |
267 | 150 and should result in a Lisp expression that will command the inferior Lisp |
151 to load that file. The default works acceptably on most Lisps. | |
152 The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\\n\" | |
153 produces cosmetically superior output for this application, | |
154 but it works only in Common Lisp.") | |
155 | |
957 | 156 ;;;###autoload |
267 | 157 (defvar inferior-lisp-prompt "^[^> ]*>+:? *" |
3663 | 158 "Regexp to recognise prompts in the Inferior Lisp mode. |
267 | 159 Defaults to \"^[^> ]*>+:? *\", which works pretty good for Lucid, kcl, |
3663 | 160 and franz. This variable is used to initialize `comint-prompt-regexp' in the |
161 Inferior Lisp buffer. | |
267 | 162 |
163 More precise choices: | |
164 Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\" | |
165 franz: \"^\\(->\\|<[0-9]*>:\\) *\" | |
166 kcl: \"^>+ *\" | |
167 | |
168 This is a fine thing to set in your .emacs file.") | |
169 | |
957 | 170 ;;;###autoload |
835 | 171 (defvar inferior-lisp-mode-hook '() |
3663 | 172 "*Hook for customising Inferior Lisp mode.") |
267 | 173 |
835 | 174 (defun inferior-lisp-mode () |
267 | 175 "Major mode for interacting with an inferior Lisp process. |
176 Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an | |
3663 | 177 Emacs buffer. Variable `inferior-lisp-program' controls which Lisp interpreter |
178 is run. Variables `inferior-lisp-prompt', `inferior-lisp-filter-regexp' and | |
179 `inferior-lisp-load-command' can customize this mode for different Lisp | |
267 | 180 interpreters. |
181 | |
182 For information on running multiple processes in multiple buffers, see | |
3663 | 183 documentation for variable `inferior-lisp-buffer'. |
267 | 184 |
835 | 185 \\{inferior-lisp-mode-map} |
267 | 186 |
3663 | 187 Customisation: Entry to this mode runs the hooks on `comint-mode-hook' and |
188 `inferior-lisp-mode-hook' (in that order). | |
267 | 189 |
190 You can send text to the inferior Lisp process from other buffers containing | |
191 Lisp source. | |
192 switch-to-lisp switches the current buffer to the Lisp process buffer. | |
193 lisp-eval-defun sends the current defun to the Lisp process. | |
194 lisp-compile-defun compiles the current defun. | |
195 lisp-eval-region sends the current region to the Lisp process. | |
196 lisp-compile-region compiles the current region. | |
197 | |
727 | 198 Prefixing the lisp-eval/compile-defun/region commands with |
199 a \\[universal-argument] causes a switch to the Lisp process buffer after sending | |
200 the text. | |
267 | 201 |
202 Commands: | |
203 Return after the end of the process' output sends the text from the | |
204 end of process to point. | |
205 Return before the end of the process' output copies the sexp ending at point | |
206 to the end of the process' output, and sends it. | |
207 Delete converts tabs to spaces as it moves back. | |
208 Tab indents for Lisp; with argument, shifts rest | |
209 of expression rigidly with the current line. | |
210 C-M-q does Tab on each line starting within following expression. | |
211 Paragraphs are separated only by blank lines. Semicolons start comments. | |
212 If you accidentally suspend your process, use \\[comint-continue-subjob] | |
213 to continue it." | |
214 (interactive) | |
215 (comint-mode) | |
216 (setq comint-prompt-regexp inferior-lisp-prompt) | |
835 | 217 (setq major-mode 'inferior-lisp-mode) |
218 (setq mode-name "Inferior Lisp") | |
267 | 219 (setq mode-line-process '(": %s")) |
835 | 220 (lisp-mode-variables t) |
221 (use-local-map inferior-lisp-mode-map) ;c-c c-k for "kompile" file | |
267 | 222 (setq comint-get-old-input (function lisp-get-old-input)) |
223 (setq comint-input-filter (function lisp-input-filter)) | |
224 (setq comint-input-sentinel 'ignore) | |
835 | 225 (run-hooks 'inferior-lisp-mode-hook)) |
267 | 226 |
227 (defun lisp-get-old-input () | |
3663 | 228 "Return a string containing the sexp ending at point." |
267 | 229 (save-excursion |
230 (let ((end (point))) | |
231 (backward-sexp) | |
232 (buffer-substring (point) end)))) | |
233 | |
234 (defun lisp-input-filter (str) | |
3663 | 235 "t if STR does not match `inferior-lisp-filter-regexp'." |
835 | 236 (not (string-match inferior-lisp-filter-regexp str))) |
267 | 237 |
957 | 238 ;;;###autoload |
835 | 239 (defun inferior-lisp (cmd) |
3663 | 240 "Run an inferior Lisp process, input and output via buffer `*inferior-lisp*'. |
241 If there is a process already running in `*inferior-lisp*', just switch | |
835 | 242 to that buffer. |
727 | 243 With argument, allows you to edit the command line (default is value |
3663 | 244 of `inferior-lisp-program'). Runs the hooks from |
245 `inferior-lisp-mode-hook' (after the `comint-mode-hook' is run). | |
267 | 246 \(Type \\[describe-mode] in the process buffer for a list of commands.)" |
727 | 247 (interactive (list (if current-prefix-arg |
248 (read-string "Run lisp: " inferior-lisp-program) | |
835 | 249 inferior-lisp-program))) |
250 (if (not (comint-check-proc "*inferior-lisp*")) | |
251 (let ((cmdlist (inferior-lisp-args-to-list cmd))) | |
252 (set-buffer (apply (function make-comint) | |
253 "inferior-lisp" (car cmdlist) nil (cdr cmdlist))) | |
254 (inferior-lisp-mode))) | |
255 (setq inferior-lisp-buffer "*inferior-lisp*") | |
256 (switch-to-buffer "*inferior-lisp*")) | |
257 | |
3663 | 258 ;;;###autoload |
259 (defalias 'run-lisp 'inferior-lisp) | |
267 | 260 |
727 | 261 ;;; Break a string up into a list of arguments. |
262 ;;; This will break if you have an argument with whitespace, as in | |
263 ;;; string = "-ab +c -x 'you lose'". | |
835 | 264 (defun inferior-lisp-args-to-list (string) |
727 | 265 (let ((where (string-match "[ \t]" string))) |
266 (cond ((null where) (list string)) | |
267 ((not (= where 0)) | |
268 (cons (substring string 0 where) | |
835 | 269 (inferior-lisp-args-to-list (substring string (+ 1 where) |
270 (length string))))) | |
727 | 271 (t (let ((pos (string-match "[^ \t]" string))) |
272 (if (null pos) | |
273 nil | |
835 | 274 (inferior-lisp-args-to-list (substring string pos |
275 (length string))))))))) | |
727 | 276 |
277 (defun lisp-eval-region (start end &optional and-go) | |
278 "Send the current region to the inferior Lisp process. | |
3663 | 279 Prefix argument means switch to the Lisp buffer afterwards." |
727 | 280 (interactive "r\nP") |
835 | 281 (comint-send-region (inferior-lisp-proc) start end) |
282 (comint-send-string (inferior-lisp-proc) "\n") | |
727 | 283 (if and-go (switch-to-lisp t))) |
267 | 284 |
727 | 285 (defun lisp-eval-defun (&optional and-go) |
286 "Send the current defun to the inferior Lisp process. | |
3663 | 287 Prefix argument means switch to the Lisp buffer afterwards." |
727 | 288 (interactive "P") |
267 | 289 (save-excursion |
727 | 290 (end-of-defun) |
291 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy | |
292 (let ((end (point))) | |
293 (beginning-of-defun) | |
294 (lisp-eval-region (point) end))) | |
295 (if and-go (switch-to-lisp t))) | |
267 | 296 |
727 | 297 (defun lisp-eval-last-sexp (&optional and-go) |
298 "Send the previous sexp to the inferior Lisp process. | |
3663 | 299 Prefix argument means switch to the Lisp buffer afterwards." |
727 | 300 (interactive "P") |
301 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go)) | |
267 | 302 |
727 | 303 ;;; Common Lisp COMPILE sux. |
304 (defun lisp-compile-region (start end &optional and-go) | |
305 "Compile the current region in the inferior Lisp process. | |
3663 | 306 Prefix argument means switch to the Lisp buffer afterwards." |
727 | 307 (interactive "r\nP") |
835 | 308 (comint-send-string |
309 (inferior-lisp-proc) | |
310 (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n" | |
311 (buffer-substring start end))) | |
727 | 312 (if and-go (switch-to-lisp t))) |
835 | 313 |
727 | 314 (defun lisp-compile-defun (&optional and-go) |
315 "Compile the current defun in the inferior Lisp process. | |
3663 | 316 Prefix argument means switch to the Lisp buffer afterwards." |
727 | 317 (interactive "P") |
267 | 318 (save-excursion |
319 (end-of-defun) | |
727 | 320 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy |
267 | 321 (let ((e (point))) |
322 (beginning-of-defun) | |
727 | 323 (lisp-compile-region (point) e))) |
324 (if and-go (switch-to-lisp t))) | |
267 | 325 |
326 (defun switch-to-lisp (eob-p) | |
327 "Switch to the inferior Lisp process buffer. | |
328 With argument, positions cursor at end of buffer." | |
329 (interactive "P") | |
835 | 330 (if (get-buffer inferior-lisp-buffer) |
331 (pop-to-buffer inferior-lisp-buffer) | |
332 (error "No current process buffer. See variable inferior-lisp-buffer.")) | |
267 | 333 (cond (eob-p |
334 (push-mark) | |
335 (goto-char (point-max))))) | |
336 | |
727 | 337 |
338 ;;; Now that lisp-compile/eval-defun/region takes an optional prefix arg, | |
339 ;;; these commands are redundant. But they are kept around for the user | |
340 ;;; to bind if he wishes, for backwards functionality, and because it's | |
341 ;;; easier to type C-c e than C-u C-c C-e. | |
342 | |
267 | 343 (defun lisp-eval-region-and-go (start end) |
3663 | 344 "Send the current region to the inferior Lisp, and switch to its buffer." |
267 | 345 (interactive "r") |
727 | 346 (lisp-eval-region start end t)) |
267 | 347 |
348 (defun lisp-eval-defun-and-go () | |
3663 | 349 "Send the current defun to the inferior Lisp, and switch to its buffer." |
267 | 350 (interactive) |
727 | 351 (lisp-eval-defun t)) |
267 | 352 |
353 (defun lisp-compile-region-and-go (start end) | |
3663 | 354 "Compile the current region in the inferior Lisp, and switch to its buffer." |
267 | 355 (interactive "r") |
727 | 356 (lisp-compile-region start end t)) |
267 | 357 |
358 (defun lisp-compile-defun-and-go () | |
3663 | 359 "Compile the current defun in the inferior Lisp, and switch to its buffer." |
267 | 360 (interactive) |
727 | 361 (lisp-compile-defun t)) |
267 | 362 |
363 ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust. | |
835 | 364 ;;; (defun lisp-compile-sexp (start end) |
365 ;;; "Compile the s-expression bounded by START and END in the inferior lisp. | |
366 ;;; If the sexp isn't a DEFUN form, it is evaluated instead." | |
367 ;;; (cond ((looking-at "(defun\\s +") | |
368 ;;; (goto-char (match-end 0)) | |
369 ;;; (let ((name-start (point))) | |
370 ;;; (forward-sexp 1) | |
371 ;;; (process-send-string "inferior-lisp" | |
372 ;;; (format "(compile '%s #'(lambda " | |
373 ;;; (buffer-substring name-start | |
374 ;;; (point))))) | |
375 ;;; (let ((body-start (point))) | |
376 ;;; (goto-char start) (forward-sexp 1) ; Can't use end-of-defun. | |
377 ;;; (process-send-region "inferior-lisp" | |
378 ;;; (buffer-substring body-start (point)))) | |
379 ;;; (process-send-string "inferior-lisp" ")\n")) | |
380 ;;; (t (lisp-eval-region start end))))) | |
381 ;;; | |
382 ;;; (defun lisp-compile-region (start end) | |
383 ;;; "Each s-expression in the current region is compiled (if a DEFUN) | |
384 ;;; or evaluated (if not) in the inferior lisp." | |
385 ;;; (interactive "r") | |
386 ;;; (save-excursion | |
387 ;;; (goto-char start) (end-of-defun) (beginning-of-defun) ; error check | |
388 ;;; (if (< (point) start) (error "region begins in middle of defun")) | |
389 ;;; (goto-char start) | |
390 ;;; (let ((s start)) | |
391 ;;; (end-of-defun) | |
392 ;;; (while (<= (point) end) ; Zip through | |
393 ;;; (lisp-compile-sexp s (point)) ; compiling up defun-sized chunks. | |
394 ;;; (setq s (point)) | |
395 ;;; (end-of-defun)) | |
396 ;;; (if (< s end) (lisp-compile-sexp s end))))) | |
397 ;;; | |
267 | 398 ;;; End of HS-style code |
399 | |
400 | |
401 (defvar lisp-prev-l/c-dir/file nil | |
3663 | 402 "Record last directory and file used in loading or compiling. |
403 This holds a cons cell of the form `(DIRECTORY . FILE)' | |
404 describing the last `lisp-load-file' or `lisp-compile-file' command.") | |
267 | 405 |
406 (defvar lisp-source-modes '(lisp-mode) | |
407 "*Used to determine if a buffer contains Lisp source code. | |
408 If it's loaded into a buffer that is in one of these major modes, it's | |
3663 | 409 considered a Lisp source file by `lisp-load-file' and `lisp-compile-file'. |
267 | 410 Used by these commands to determine defaults.") |
411 | |
412 (defun lisp-load-file (file-name) | |
413 "Load a Lisp file into the inferior Lisp process." | |
414 (interactive (comint-get-source "Load Lisp file: " lisp-prev-l/c-dir/file | |
415 lisp-source-modes nil)) ; NIL because LOAD | |
835 | 416 ; doesn't need an exact name |
267 | 417 (comint-check-source file-name) ; Check to see if buffer needs saved. |
418 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name) | |
419 (file-name-nondirectory file-name))) | |
835 | 420 (comint-send-string (inferior-lisp-proc) |
727 | 421 (format inferior-lisp-load-command file-name)) |
422 (switch-to-lisp t)) | |
267 | 423 |
424 | |
425 (defun lisp-compile-file (file-name) | |
426 "Compile a Lisp file in the inferior Lisp process." | |
427 (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l/c-dir/file | |
428 lisp-source-modes nil)) ; NIL = don't need | |
835 | 429 ; suffix .lisp |
267 | 430 (comint-check-source file-name) ; Check to see if buffer needs saved. |
431 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name) | |
432 (file-name-nondirectory file-name))) | |
835 | 433 (comint-send-string (inferior-lisp-proc) (concat "(compile-file \"" |
434 file-name | |
435 "\"\)\n")) | |
727 | 436 (switch-to-lisp t)) |
267 | 437 |
438 | |
439 | |
440 ;;; Documentation functions: function doc, var doc, arglist, and | |
441 ;;; describe symbol. | |
442 ;;; =========================================================================== | |
443 | |
444 ;;; Command strings | |
445 ;;; =============== | |
446 | |
447 (defvar lisp-function-doc-command | |
448 "(let ((fn '%s)) | |
449 (format t \"Documentation for ~a:~&~a\" | |
450 fn (documentation fn 'function)) | |
451 (values))\n" | |
452 "Command to query inferior Lisp for a function's documentation.") | |
453 | |
454 (defvar lisp-var-doc-command | |
455 "(let ((v '%s)) | |
456 (format t \"Documentation for ~a:~&~a\" | |
457 v (documentation v 'variable)) | |
458 (values))\n" | |
459 "Command to query inferior Lisp for a variable's documentation.") | |
460 | |
461 (defvar lisp-arglist-command | |
462 "(let ((fn '%s)) | |
463 (format t \"Arglist for ~a: ~a\" fn (arglist fn)) | |
464 (values))\n" | |
465 "Command to query inferior Lisp for a function's arglist.") | |
466 | |
467 (defvar lisp-describe-sym-command | |
468 "(describe '%s)\n" | |
469 "Command to query inferior Lisp for a variable's documentation.") | |
470 | |
471 | |
472 ;;; Ancillary functions | |
473 ;;; =================== | |
474 | |
475 ;;; Reads a string from the user. | |
476 (defun lisp-symprompt (prompt default) | |
477 (list (let* ((prompt (if default | |
478 (format "%s (default %s): " prompt default) | |
835 | 479 (concat prompt ": "))) |
267 | 480 (ans (read-string prompt))) |
481 (if (zerop (length ans)) default ans)))) | |
482 | |
483 | |
484 ;;; Adapted from function-called-at-point in help.el. | |
485 (defun lisp-fn-called-at-pt () | |
486 "Returns the name of the function called in the current call. | |
3663 | 487 The value is nil if it can't find one." |
267 | 488 (condition-case nil |
489 (save-excursion | |
490 (save-restriction | |
491 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max)) | |
492 (backward-up-list 1) | |
493 (forward-char 1) | |
494 (let ((obj (read (current-buffer)))) | |
495 (and (symbolp obj) obj)))) | |
496 (error nil))) | |
497 | |
498 | |
499 ;;; Adapted from variable-at-point in help.el. | |
500 (defun lisp-var-at-pt () | |
501 (condition-case () | |
502 (save-excursion | |
503 (forward-sexp -1) | |
504 (skip-chars-forward "'") | |
505 (let ((obj (read (current-buffer)))) | |
506 (and (symbolp obj) obj))) | |
507 (error nil))) | |
508 | |
509 | |
510 ;;; Documentation functions: fn and var doc, arglist, and symbol describe. | |
511 ;;; ====================================================================== | |
512 | |
513 (defun lisp-show-function-documentation (fn) | |
514 "Send a command to the inferior Lisp to give documentation for function FN. | |
3663 | 515 See variable `lisp-function-doc-command'." |
267 | 516 (interactive (lisp-symprompt "Function doc" (lisp-fn-called-at-pt))) |
835 | 517 (comint-proc-query (inferior-lisp-proc) |
518 (format lisp-function-doc-command fn))) | |
267 | 519 |
520 (defun lisp-show-variable-documentation (var) | |
521 "Send a command to the inferior Lisp to give documentation for function FN. | |
3663 | 522 See variable `lisp-var-doc-command'." |
267 | 523 (interactive (lisp-symprompt "Variable doc" (lisp-var-at-pt))) |
835 | 524 (comint-proc-query (inferior-lisp-proc) (format lisp-var-doc-command var))) |
267 | 525 |
526 (defun lisp-show-arglist (fn) | |
3663 | 527 "Send a query to the inferior Lisp for the arglist for function FN. |
528 See variable `lisp-arglist-command'." | |
267 | 529 (interactive (lisp-symprompt "Arglist" (lisp-fn-called-at-pt))) |
835 | 530 (comint-proc-query (inferior-lisp-proc) (format lisp-arglist-command fn))) |
267 | 531 |
532 (defun lisp-describe-sym (sym) | |
533 "Send a command to the inferior Lisp to describe symbol SYM. | |
3663 | 534 See variable `lisp-describe-sym-command'." |
267 | 535 (interactive (lisp-symprompt "Describe" (lisp-var-at-pt))) |
835 | 536 (comint-proc-query (inferior-lisp-proc) |
537 (format lisp-describe-sym-command sym))) | |
267 | 538 |
539 | |
835 | 540 (defvar inferior-lisp-buffer nil "*The current inferior-lisp process buffer. |
267 | 541 |
542 MULTIPLE PROCESS SUPPORT | |
543 =========================================================================== | |
3663 | 544 To run multiple Lisp processes, you start the first up |
545 with \\[inferior-lisp]. It will be in a buffer named `*inferior-lisp*'. | |
546 Rename this buffer with \\[rename-buffer]. You may now start up a new | |
547 process with another \\[inferior-lisp]. It will be in a new buffer, | |
548 named `*inferior-lisp*'. You can switch between the different process | |
835 | 549 buffers with \\[switch-to-buffer]. |
267 | 550 |
551 Commands that send text from source buffers to Lisp processes -- | |
3663 | 552 like `lisp-eval-defun' or `lisp-show-arglist' -- have to choose a process |
553 to send to, when you have more than one Lisp process around. This | |
554 is determined by the global variable `inferior-lisp-buffer'. Suppose you | |
555 have three inferior Lisps running: | |
835 | 556 Buffer Process |
557 foo inferior-lisp | |
558 bar inferior-lisp<2> | |
559 *inferior-lisp* inferior-lisp<3> | |
727 | 560 If you do a \\[lisp-eval-defun] command on some Lisp source code, |
267 | 561 what process do you send it to? |
562 | |
835 | 563 - If you're in a process buffer (foo, bar, or *inferior-lisp*), |
267 | 564 you send it to that process. |
565 - If you're in some other buffer (e.g., a source file), you | |
3663 | 566 send it to the process attached to buffer `inferior-lisp-buffer'. |
567 This process selection is performed by function `inferior-lisp-proc'. | |
267 | 568 |
835 | 569 Whenever \\[inferior-lisp] fires up a new process, it resets |
3663 | 570 `inferior-lisp-buffer' to be the new process's buffer. If you only run |
571 one process, this does the right thing. If you run multiple | |
572 processes, you can change `inferior-lisp-buffer' to another process | |
573 buffer with \\[set-variable].") | |
267 | 574 |
3663 | 575 ;; "Returns the current inferior Lisp process. |
576 ;; See variable `inferior-lisp-buffer'." | |
835 | 577 (defun inferior-lisp-proc () |
267 | 578 (let ((proc (get-buffer-process (if (eq major-mode 'inferior-lisp-mode) |
579 (current-buffer) | |
835 | 580 inferior-lisp-buffer)))) |
267 | 581 (or proc |
835 | 582 (error "No current process. See variable inferior-lisp-buffer")))) |
267 | 583 |
584 | |
585 ;;; Do the user's customisation... | |
586 ;;;=============================== | |
835 | 587 (defvar inferior-lisp-load-hook nil |
3663 | 588 "This hook is run when the library `inf-lisp' is loaded. |
267 | 589 This is a good place to put keybindings.") |
835 | 590 |
591 (run-hooks 'inferior-lisp-load-hook) | |
267 | 592 |
593 ;;; CHANGE LOG | |
594 ;;; =========================================================================== | |
835 | 595 ;;; 7/21/92 Jim Blandy |
596 ;;; - Changed all uses of the cmulisp name or prefix to inferior-lisp; | |
597 ;;; this is now the official inferior lisp package. Use the global | |
598 ;;; ChangeLog from now on. | |
267 | 599 ;;; 5/24/90 Olin |
600 ;;; - Split cmulisp and cmushell modes into separate files. | |
601 ;;; Not only is this a good idea, it's apparently the way it'll be rel 19. | |
602 ;;; - Upgraded process sends to use comint-send-string instead of | |
603 ;;; process-send-string. | |
604 ;;; - Explicit references to process "cmulisp" have been replaced with | |
605 ;;; (cmulisp-proc). This allows better handling of multiple process bufs. | |
606 ;;; - Added process query and var/function/symbol documentation | |
607 ;;; commands. Based on code written by Douglas Roberts. | |
608 ;;; - Added lisp-eval-last-sexp, bound to C-x C-e. | |
609 ;;; | |
610 ;;; 9/20/90 Olin | |
611 ;;; Added a save-restriction to lisp-fn-called-at-pt. This bug and fix | |
612 ;;; reported by Lennart Staflin. | |
613 ;;; | |
614 ;;; 3/12/90 Olin | |
615 ;;; - lisp-load-file and lisp-compile-file no longer switch-to-lisp. | |
616 ;;; Tale suggested this. | |
727 | 617 ;;; - Reversed this decision 7/15/91. You need the visual feedback. |
618 ;;; | |
619 ;;; 7/25/91 Olin | |
620 ;;; Changed all keybindings of the form C-c <letter>. These are | |
621 ;;; supposed to be reserved for the user to bind. This affected | |
622 ;;; mainly the compile/eval-defun/region[-and-go] commands. | |
623 ;;; This was painful, but necessary to adhere to the gnumacs standard. | |
624 ;;; For some backwards compatibility, see the | |
625 ;;; cmulisp-install-letter-bindings | |
626 ;;; function. | |
627 ;;; | |
628 ;;; 8/2/91 Olin | |
629 ;;; - The lisp-compile/eval-defun/region commands now take a prefix arg, | |
630 ;;; which means switch-to-lisp after sending the text to the Lisp process. | |
631 ;;; This obsoletes all the -and-go commands. The -and-go commands are | |
632 ;;; kept around for historical reasons, and because the user can bind | |
633 ;;; them to key sequences shorter than C-u C-c C-<letter>. | |
634 ;;; - If M-x cmulisp is invoked with a prefix arg, it allows you to | |
635 ;;; edit the command line. | |
584 | 636 |
835 | 637 (provide 'inf-lisp) |
584 | 638 |
835 | 639 ;;; inf-lisp.el ends here |