comparison lisp/progmodes/inf-lisp.el @ 3663:25743b083fe8

Doc fixes. (run-lisp): Add autoload. (inferior-lisp-mode-map): Explicitly make local prefix keys.
author Richard M. Stallman <rms@gnu.org>
date Fri, 11 Jun 1993 20:11:10 +0000
parents 507f64624555
children f344542ac7fd
comparison
equal deleted inserted replaced
3662:edba0072c7ef 3663:25743b083fe8
1 ;;; inf-lisp.el --- an inferior-lisp mode 1 ;;; inf-lisp.el --- an inferior-lisp mode
2 ;;; Copyright (C) 1988 Free Software Foundation, Inc. 2 ;;; Copyright (C) 1988, 1993 Free Software Foundation, Inc.
3 3
4 ;; Author: Olin Shivers <shivers@cs.cmu.edu> 4 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
5 ;; Keywords: processes, lisp 5 ;; Keywords: processes, lisp
6 6
7 ;;; This file is part of GNU Emacs. 7 ;;; This file is part of GNU Emacs.
56 ;;; When sending text from a source file to a subprocess, the process-mark can 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. 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 58 ;;; Maybe I should ensure the process mark is in the window when I send
59 ;;; text to the process? Switch selectable? 59 ;;; text to the process? Switch selectable?
60 60
61 ;; YOUR .EMACS FILE
62 ;;=============================================================================
63 ;; Some suggestions for your .emacs file.
64 ;;
65 ;; ; If inferior-lisp lives in some non-standard directory, you must tell emacs
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 ;;
69 ;; ; Autoload inferior-lisp from file inf-lisp.el
70 ;; (autoload 'inferior-lisp "inferior-lisp"
71 ;; "Run an inferior Lisp process."
72 ;; t)
73 ;;
74 ;; ; Define C-c t to run my favorite command in inferior-lisp mode:
75 ;; (setq inferior-lisp-load-hook
76 ;; '((lambda ()
77 ;; (define-key inferior-lisp-mode-map "\C-ct" 'favorite-cmd))))
78
79
80 ;;; Brief Command Documentation:
81 ;;;============================================================================
82 ;;; Comint Mode Commands: (common to inferior-lisp and all
83 ;;; comint-derived modes)
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
103 ;;; Inferior Lisp Mode Commands:
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
123 ;;; inferior-lisp Fires up the Lisp process.
124 ;;; lisp-compile-region Compile all forms in the current region.
125 ;;;
126 ;;; Inferior Lisp Mode Variables:
127 ;;; inferior-lisp-filter-regexp Match this => don't get saved on input hist
128 ;;; inferior-lisp-program Name of Lisp program run-lisp executes
129 ;;; inferior-lisp-load-command Customises lisp-load-file
130 ;;; inferior-lisp-mode-hook
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.
138
139 ;;; Code: 61 ;;; Code:
140 62
141 (require 'comint) 63 (require 'comint)
142 (require 'lisp-mode) 64 (require 'lisp-mode)
143 65
144 66
145 ;;;###autoload 67 ;;;###autoload
146 (defvar inferior-lisp-filter-regexp "\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'" 68 (defvar inferior-lisp-filter-regexp "\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'"
147 "*What not to save on inferior Lisp's input history 69 "*What not to save on inferior Lisp's input history.
148 Input matching this regexp is not saved on the input history in inferior-lisp 70 Input matching this regexp is not saved on the input history in Inferior Lisp
149 mode. Default is whitespace followed by 0 or 1 single-letter :keyword 71 mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
150 (as in :a, :c, etc.)") 72 (as in :a, :c, etc.)")
151 73
152 (defvar inferior-lisp-mode-map nil) 74 (defvar inferior-lisp-mode-map nil)
153 (cond ((not inferior-lisp-mode-map) 75 (cond ((not inferior-lisp-mode-map)
154 (setq inferior-lisp-mode-map 76 (setq inferior-lisp-mode-map
155 (full-copy-sparse-keymap comint-mode-map)) 77 (full-copy-sparse-keymap comint-mode-map))
156 (setq inferior-lisp-mode-map 78 (setq inferior-lisp-mode-map
157 (nconc inferior-lisp-mode-map shared-lisp-mode-map)) 79 (nconc inferior-lisp-mode-map shared-lisp-mode-map))
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))
158 (define-key inferior-lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp) 85 (define-key inferior-lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp)
159 (define-key inferior-lisp-mode-map "\C-c\C-l" 'lisp-load-file) 86 (define-key inferior-lisp-mode-map "\C-c\C-l" 'lisp-load-file)
160 (define-key inferior-lisp-mode-map "\C-c\C-k" 'lisp-compile-file) 87 (define-key inferior-lisp-mode-map "\C-c\C-k" 'lisp-compile-file)
161 (define-key inferior-lisp-mode-map "\C-c\C-a" 'lisp-show-arglist) 88 (define-key inferior-lisp-mode-map "\C-c\C-a" 'lisp-show-arglist)
162 (define-key inferior-lisp-mode-map "\C-c\C-d" 'lisp-describe-sym) 89 (define-key inferior-lisp-mode-map "\C-c\C-d" 'lisp-describe-sym)
183 110
184 ;;; This function exists for backwards compatibility. 111 ;;; This function exists for backwards compatibility.
185 ;;; Previous versions of this package bound commands to C-c <letter> 112 ;;; Previous versions of this package bound commands to C-c <letter>
186 ;;; bindings, which is not allowed by the gnumacs standard. 113 ;;; bindings, which is not allowed by the gnumacs standard.
187 114
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."
188 (defun inferior-lisp-install-letter-bindings () 121 (defun inferior-lisp-install-letter-bindings ()
189 "This function binds many inferior-lisp commands to C-c <letter> bindings,
190 where they are more accessible. C-c <letter> bindings are reserved for the
191 user, so these bindings are non-standard. If you want them, you should
192 have this function called by the inferior-lisp-load-hook:
193 (setq inferior-lisp-load-hook '(inferior-lisp-install-letter-bindings))
194 You can modify this function to install just the bindings you want."
195
196 (define-key lisp-mode-map "\C-ce" 'lisp-eval-defun-and-go) 122 (define-key lisp-mode-map "\C-ce" 'lisp-eval-defun-and-go)
197 (define-key lisp-mode-map "\C-cr" 'lisp-eval-region-and-go) 123 (define-key lisp-mode-map "\C-cr" 'lisp-eval-region-and-go)
198 (define-key lisp-mode-map "\C-cc" 'lisp-compile-defun-and-go) 124 (define-key lisp-mode-map "\C-cc" 'lisp-compile-defun-and-go)
199 (define-key lisp-mode-map "\C-cz" 'switch-to-lisp) 125 (define-key lisp-mode-map "\C-cz" 'switch-to-lisp)
200 (define-key lisp-mode-map "\C-cl" 'lisp-load-file) 126 (define-key lisp-mode-map "\C-cl" 'lisp-load-file)
213 'lisp-show-variable-documentation)) 139 'lisp-show-variable-documentation))
214 140
215 141
216 ;;;###autoload 142 ;;;###autoload
217 (defvar inferior-lisp-program "lisp" 143 (defvar inferior-lisp-program "lisp"
218 "*Program name for invoking an inferior Lisp with `inferior-lisp'.") 144 "*Program name for invoking an inferior Lisp with for Inferior Lisp mode.")
219 145
220 ;;;###autoload 146 ;;;###autoload
221 (defvar inferior-lisp-load-command "(load \"%s\")\n" 147 (defvar inferior-lisp-load-command "(load \"%s\")\n"
222 "*Format-string for building a Lisp expression to load a file. 148 "*Format-string for building a Lisp expression to load a file.
223 This format string should use %s to substitute a file name 149 This format string should use `%s' to substitute a file name
224 and should result in a Lisp expression that will command the inferior Lisp 150 and should result in a Lisp expression that will command the inferior Lisp
225 to load that file. The default works acceptably on most Lisps. 151 to load that file. The default works acceptably on most Lisps.
226 The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\\n\" 152 The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\\n\"
227 produces cosmetically superior output for this application, 153 produces cosmetically superior output for this application,
228 but it works only in Common Lisp.") 154 but it works only in Common Lisp.")
229 155
230 ;;;###autoload 156 ;;;###autoload
231 (defvar inferior-lisp-prompt "^[^> ]*>+:? *" 157 (defvar inferior-lisp-prompt "^[^> ]*>+:? *"
232 "Regexp to recognise prompts in the inferior Lisp. 158 "Regexp to recognise prompts in the Inferior Lisp mode.
233 Defaults to \"^[^> ]*>+:? *\", which works pretty good for Lucid, kcl, 159 Defaults to \"^[^> ]*>+:? *\", which works pretty good for Lucid, kcl,
234 and franz. This variable is used to initialise comint-prompt-regexp in the 160 and franz. This variable is used to initialize `comint-prompt-regexp' in the
235 inferior-lisp buffer. 161 Inferior Lisp buffer.
236 162
237 More precise choices: 163 More precise choices:
238 Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\" 164 Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\"
239 franz: \"^\\(->\\|<[0-9]*>:\\) *\" 165 franz: \"^\\(->\\|<[0-9]*>:\\) *\"
240 kcl: \"^>+ *\" 166 kcl: \"^>+ *\"
241 167
242 This is a fine thing to set in your .emacs file.") 168 This is a fine thing to set in your .emacs file.")
243 169
244 ;;;###autoload 170 ;;;###autoload
245 (defvar inferior-lisp-mode-hook '() 171 (defvar inferior-lisp-mode-hook '()
246 "*Hook for customising inferior-lisp mode") 172 "*Hook for customising Inferior Lisp mode.")
247 173
248 (defun inferior-lisp-mode () 174 (defun inferior-lisp-mode ()
249 "Major mode for interacting with an inferior Lisp process. 175 "Major mode for interacting with an inferior Lisp process.
250 Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an 176 Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an
251 Emacs buffer. Variable inferior-lisp-program controls which Lisp interpreter 177 Emacs buffer. Variable `inferior-lisp-program' controls which Lisp interpreter
252 is run. Variables inferior-lisp-prompt, inferior-lisp-filter-regexp and 178 is run. Variables `inferior-lisp-prompt', `inferior-lisp-filter-regexp' and
253 inferior-lisp-load-command can customize this mode for different Lisp 179 `inferior-lisp-load-command' can customize this mode for different Lisp
254 interpreters. 180 interpreters.
255 181
256 For information on running multiple processes in multiple buffers, see 182 For information on running multiple processes in multiple buffers, see
257 documentation for variable inferior-lisp-buffer. 183 documentation for variable `inferior-lisp-buffer'.
258 184
259 \\{inferior-lisp-mode-map} 185 \\{inferior-lisp-mode-map}
260 186
261 Customisation: Entry to this mode runs the hooks on comint-mode-hook and 187 Customisation: Entry to this mode runs the hooks on `comint-mode-hook' and
262 inferior-lisp-mode-hook (in that order). 188 `inferior-lisp-mode-hook' (in that order).
263 189
264 You can send text to the inferior Lisp process from other buffers containing 190 You can send text to the inferior Lisp process from other buffers containing
265 Lisp source. 191 Lisp source.
266 switch-to-lisp switches the current buffer to the Lisp process buffer. 192 switch-to-lisp switches the current buffer to the Lisp process buffer.
267 lisp-eval-defun sends the current defun to the Lisp process. 193 lisp-eval-defun sends the current defun to the Lisp process.
297 (setq comint-input-filter (function lisp-input-filter)) 223 (setq comint-input-filter (function lisp-input-filter))
298 (setq comint-input-sentinel 'ignore) 224 (setq comint-input-sentinel 'ignore)
299 (run-hooks 'inferior-lisp-mode-hook)) 225 (run-hooks 'inferior-lisp-mode-hook))
300 226
301 (defun lisp-get-old-input () 227 (defun lisp-get-old-input ()
302 "Snarf the sexp ending at point" 228 "Return a string containing the sexp ending at point."
303 (save-excursion 229 (save-excursion
304 (let ((end (point))) 230 (let ((end (point)))
305 (backward-sexp) 231 (backward-sexp)
306 (buffer-substring (point) end)))) 232 (buffer-substring (point) end))))
307 233
308 (defun lisp-input-filter (str) 234 (defun lisp-input-filter (str)
309 "Don't save anything matching inferior-lisp-filter-regexp" 235 "t if STR does not match `inferior-lisp-filter-regexp'."
310 (not (string-match inferior-lisp-filter-regexp str))) 236 (not (string-match inferior-lisp-filter-regexp str)))
311 237
312 ;;;###autoload 238 ;;;###autoload
313 (defun inferior-lisp (cmd) 239 (defun inferior-lisp (cmd)
314 "Run an inferior Lisp process, input and output via buffer *inferior-lisp*. 240 "Run an inferior Lisp process, input and output via buffer `*inferior-lisp*'.
315 If there is a process already running in *inferior-lisp*, just switch 241 If there is a process already running in `*inferior-lisp*', just switch
316 to that buffer. 242 to that buffer.
317 With argument, allows you to edit the command line (default is value 243 With argument, allows you to edit the command line (default is value
318 of inferior-lisp-program). Runs the hooks from 244 of `inferior-lisp-program'). Runs the hooks from
319 inferior-lisp-mode-hook (after the comint-mode-hook is run). 245 `inferior-lisp-mode-hook' (after the `comint-mode-hook' is run).
320 \(Type \\[describe-mode] in the process buffer for a list of commands.)" 246 \(Type \\[describe-mode] in the process buffer for a list of commands.)"
321 (interactive (list (if current-prefix-arg 247 (interactive (list (if current-prefix-arg
322 (read-string "Run lisp: " inferior-lisp-program) 248 (read-string "Run lisp: " inferior-lisp-program)
323 inferior-lisp-program))) 249 inferior-lisp-program)))
324 (if (not (comint-check-proc "*inferior-lisp*")) 250 (if (not (comint-check-proc "*inferior-lisp*"))
327 "inferior-lisp" (car cmdlist) nil (cdr cmdlist))) 253 "inferior-lisp" (car cmdlist) nil (cdr cmdlist)))
328 (inferior-lisp-mode))) 254 (inferior-lisp-mode)))
329 (setq inferior-lisp-buffer "*inferior-lisp*") 255 (setq inferior-lisp-buffer "*inferior-lisp*")
330 (switch-to-buffer "*inferior-lisp*")) 256 (switch-to-buffer "*inferior-lisp*"))
331 257
332 (fset 'run-lisp 'inferior-lisp) 258 ;;;###autoload
259 (defalias 'run-lisp 'inferior-lisp)
333 260
334 ;;; Break a string up into a list of arguments. 261 ;;; Break a string up into a list of arguments.
335 ;;; This will break if you have an argument with whitespace, as in 262 ;;; This will break if you have an argument with whitespace, as in
336 ;;; string = "-ab +c -x 'you lose'". 263 ;;; string = "-ab +c -x 'you lose'".
337 (defun inferior-lisp-args-to-list (string) 264 (defun inferior-lisp-args-to-list (string)
347 (inferior-lisp-args-to-list (substring string pos 274 (inferior-lisp-args-to-list (substring string pos
348 (length string))))))))) 275 (length string)))))))))
349 276
350 (defun lisp-eval-region (start end &optional and-go) 277 (defun lisp-eval-region (start end &optional and-go)
351 "Send the current region to the inferior Lisp process. 278 "Send the current region to the inferior Lisp process.
352 Prefix argument means switch-to-lisp afterwards." 279 Prefix argument means switch to the Lisp buffer afterwards."
353 (interactive "r\nP") 280 (interactive "r\nP")
354 (comint-send-region (inferior-lisp-proc) start end) 281 (comint-send-region (inferior-lisp-proc) start end)
355 (comint-send-string (inferior-lisp-proc) "\n") 282 (comint-send-string (inferior-lisp-proc) "\n")
356 (if and-go (switch-to-lisp t))) 283 (if and-go (switch-to-lisp t)))
357 284
358 (defun lisp-eval-defun (&optional and-go) 285 (defun lisp-eval-defun (&optional and-go)
359 "Send the current defun to the inferior Lisp process. 286 "Send the current defun to the inferior Lisp process.
360 Prefix argument means switch-to-lisp afterwards." 287 Prefix argument means switch to the Lisp buffer afterwards."
361 (interactive "P") 288 (interactive "P")
362 (save-excursion 289 (save-excursion
363 (end-of-defun) 290 (end-of-defun)
364 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy 291 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
365 (let ((end (point))) 292 (let ((end (point)))
367 (lisp-eval-region (point) end))) 294 (lisp-eval-region (point) end)))
368 (if and-go (switch-to-lisp t))) 295 (if and-go (switch-to-lisp t)))
369 296
370 (defun lisp-eval-last-sexp (&optional and-go) 297 (defun lisp-eval-last-sexp (&optional and-go)
371 "Send the previous sexp to the inferior Lisp process. 298 "Send the previous sexp to the inferior Lisp process.
372 Prefix argument means switch-to-lisp afterwards." 299 Prefix argument means switch to the Lisp buffer afterwards."
373 (interactive "P") 300 (interactive "P")
374 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go)) 301 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go))
375 302
376 ;;; Common Lisp COMPILE sux. 303 ;;; Common Lisp COMPILE sux.
377 (defun lisp-compile-region (start end &optional and-go) 304 (defun lisp-compile-region (start end &optional and-go)
378 "Compile the current region in the inferior Lisp process. 305 "Compile the current region in the inferior Lisp process.
379 Prefix argument means switch-to-lisp afterwards." 306 Prefix argument means switch to the Lisp buffer afterwards."
380 (interactive "r\nP") 307 (interactive "r\nP")
381 (comint-send-string 308 (comint-send-string
382 (inferior-lisp-proc) 309 (inferior-lisp-proc)
383 (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n" 310 (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n"
384 (buffer-substring start end))) 311 (buffer-substring start end)))
385 (if and-go (switch-to-lisp t))) 312 (if and-go (switch-to-lisp t)))
386 313
387 (defun lisp-compile-defun (&optional and-go) 314 (defun lisp-compile-defun (&optional and-go)
388 "Compile the current defun in the inferior Lisp process. 315 "Compile the current defun in the inferior Lisp process.
389 Prefix argument means switch-to-lisp afterwards." 316 Prefix argument means switch to the Lisp buffer afterwards."
390 (interactive "P") 317 (interactive "P")
391 (save-excursion 318 (save-excursion
392 (end-of-defun) 319 (end-of-defun)
393 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy 320 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
394 (let ((e (point))) 321 (let ((e (point)))
412 ;;; these commands are redundant. But they are kept around for the user 339 ;;; these commands are redundant. But they are kept around for the user
413 ;;; to bind if he wishes, for backwards functionality, and because it's 340 ;;; to bind if he wishes, for backwards functionality, and because it's
414 ;;; easier to type C-c e than C-u C-c C-e. 341 ;;; easier to type C-c e than C-u C-c C-e.
415 342
416 (defun lisp-eval-region-and-go (start end) 343 (defun lisp-eval-region-and-go (start end)
417 "Send the current region to the inferior Lisp, 344 "Send the current region to the inferior Lisp, and switch to its buffer."
418 and switch to the process buffer."
419 (interactive "r") 345 (interactive "r")
420 (lisp-eval-region start end t)) 346 (lisp-eval-region start end t))
421 347
422 (defun lisp-eval-defun-and-go () 348 (defun lisp-eval-defun-and-go ()
423 "Send the current defun to the inferior Lisp, 349 "Send the current defun to the inferior Lisp, and switch to its buffer."
424 and switch to the process buffer."
425 (interactive) 350 (interactive)
426 (lisp-eval-defun t)) 351 (lisp-eval-defun t))
427 352
428 (defun lisp-compile-region-and-go (start end) 353 (defun lisp-compile-region-and-go (start end)
429 "Compile the current region in the inferior Lisp, 354 "Compile the current region in the inferior Lisp, and switch to its buffer."
430 and switch to the process buffer."
431 (interactive "r") 355 (interactive "r")
432 (lisp-compile-region start end t)) 356 (lisp-compile-region start end t))
433 357
434 (defun lisp-compile-defun-and-go () 358 (defun lisp-compile-defun-and-go ()
435 "Compile the current defun in the inferior Lisp, 359 "Compile the current defun in the inferior Lisp, and switch to its buffer."
436 and switch to the process buffer."
437 (interactive) 360 (interactive)
438 (lisp-compile-defun t)) 361 (lisp-compile-defun t))
439 362
440 ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust. 363 ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust.
441 ;;; (defun lisp-compile-sexp (start end) 364 ;;; (defun lisp-compile-sexp (start end)
474 ;;; 397 ;;;
475 ;;; End of HS-style code 398 ;;; End of HS-style code
476 399
477 400
478 (defvar lisp-prev-l/c-dir/file nil 401 (defvar lisp-prev-l/c-dir/file nil
479 "Saves the (directory . file) pair used in the last lisp-load-file or 402 "Record last directory and file used in loading or compiling.
480 lisp-compile-file command. Used for determining the default in the 403 This holds a cons cell of the form `(DIRECTORY . FILE)'
481 next one.") 404 describing the last `lisp-load-file' or `lisp-compile-file' command.")
482 405
483 (defvar lisp-source-modes '(lisp-mode) 406 (defvar lisp-source-modes '(lisp-mode)
484 "*Used to determine if a buffer contains Lisp source code. 407 "*Used to determine if a buffer contains Lisp source code.
485 If it's loaded into a buffer that is in one of these major modes, it's 408 If it's loaded into a buffer that is in one of these major modes, it's
486 considered a Lisp source file by lisp-load-file and lisp-compile-file. 409 considered a Lisp source file by `lisp-load-file' and `lisp-compile-file'.
487 Used by these commands to determine defaults.") 410 Used by these commands to determine defaults.")
488 411
489 (defun lisp-load-file (file-name) 412 (defun lisp-load-file (file-name)
490 "Load a Lisp file into the inferior Lisp process." 413 "Load a Lisp file into the inferior Lisp process."
491 (interactive (comint-get-source "Load Lisp file: " lisp-prev-l/c-dir/file 414 (interactive (comint-get-source "Load Lisp file: " lisp-prev-l/c-dir/file
559 482
560 483
561 ;;; Adapted from function-called-at-point in help.el. 484 ;;; Adapted from function-called-at-point in help.el.
562 (defun lisp-fn-called-at-pt () 485 (defun lisp-fn-called-at-pt ()
563 "Returns the name of the function called in the current call. 486 "Returns the name of the function called in the current call.
564 Nil if it can't find one." 487 The value is nil if it can't find one."
565 (condition-case nil 488 (condition-case nil
566 (save-excursion 489 (save-excursion
567 (save-restriction 490 (save-restriction
568 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max)) 491 (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
569 (backward-up-list 1) 492 (backward-up-list 1)
587 ;;; Documentation functions: fn and var doc, arglist, and symbol describe. 510 ;;; Documentation functions: fn and var doc, arglist, and symbol describe.
588 ;;; ====================================================================== 511 ;;; ======================================================================
589 512
590 (defun lisp-show-function-documentation (fn) 513 (defun lisp-show-function-documentation (fn)
591 "Send a command to the inferior Lisp to give documentation for function FN. 514 "Send a command to the inferior Lisp to give documentation for function FN.
592 See variable lisp-function-doc-command." 515 See variable `lisp-function-doc-command'."
593 (interactive (lisp-symprompt "Function doc" (lisp-fn-called-at-pt))) 516 (interactive (lisp-symprompt "Function doc" (lisp-fn-called-at-pt)))
594 (comint-proc-query (inferior-lisp-proc) 517 (comint-proc-query (inferior-lisp-proc)
595 (format lisp-function-doc-command fn))) 518 (format lisp-function-doc-command fn)))
596 519
597 (defun lisp-show-variable-documentation (var) 520 (defun lisp-show-variable-documentation (var)
598 "Send a command to the inferior Lisp to give documentation for function FN. 521 "Send a command to the inferior Lisp to give documentation for function FN.
599 See variable lisp-var-doc-command." 522 See variable `lisp-var-doc-command'."
600 (interactive (lisp-symprompt "Variable doc" (lisp-var-at-pt))) 523 (interactive (lisp-symprompt "Variable doc" (lisp-var-at-pt)))
601 (comint-proc-query (inferior-lisp-proc) (format lisp-var-doc-command var))) 524 (comint-proc-query (inferior-lisp-proc) (format lisp-var-doc-command var)))
602 525
603 (defun lisp-show-arglist (fn) 526 (defun lisp-show-arglist (fn)
604 "Sends an query to the inferior Lisp for the arglist for function FN. 527 "Send a query to the inferior Lisp for the arglist for function FN.
605 See variable lisp-arglist-command." 528 See variable `lisp-arglist-command'."
606 (interactive (lisp-symprompt "Arglist" (lisp-fn-called-at-pt))) 529 (interactive (lisp-symprompt "Arglist" (lisp-fn-called-at-pt)))
607 (comint-proc-query (inferior-lisp-proc) (format lisp-arglist-command fn))) 530 (comint-proc-query (inferior-lisp-proc) (format lisp-arglist-command fn)))
608 531
609 (defun lisp-describe-sym (sym) 532 (defun lisp-describe-sym (sym)
610 "Send a command to the inferior Lisp to describe symbol SYM. 533 "Send a command to the inferior Lisp to describe symbol SYM.
611 See variable lisp-describe-sym-command." 534 See variable `lisp-describe-sym-command'."
612 (interactive (lisp-symprompt "Describe" (lisp-var-at-pt))) 535 (interactive (lisp-symprompt "Describe" (lisp-var-at-pt)))
613 (comint-proc-query (inferior-lisp-proc) 536 (comint-proc-query (inferior-lisp-proc)
614 (format lisp-describe-sym-command sym))) 537 (format lisp-describe-sym-command sym)))
615 538
616 539
617 (defvar inferior-lisp-buffer nil "*The current inferior-lisp process buffer. 540 (defvar inferior-lisp-buffer nil "*The current inferior-lisp process buffer.
618 541
619 MULTIPLE PROCESS SUPPORT 542 MULTIPLE PROCESS SUPPORT
620 =========================================================================== 543 ===========================================================================
621 Inf-lisp.el supports, in a fairly simple fashion, running multiple 544 To run multiple Lisp processes, you start the first up
622 Lisp processes. To run multiple Lisp processes, you start the first up 545 with \\[inferior-lisp]. It will be in a buffer named `*inferior-lisp*'.
623 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
624 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,
625 process with another \\[inferior-lisp]. It will be in a new buffer, 548 named `*inferior-lisp*'. You can switch between the different process
626 named *inferior-lisp*. You can switch between the different process
627 buffers with \\[switch-to-buffer]. 549 buffers with \\[switch-to-buffer].
628 550
629 Commands that send text from source buffers to Lisp processes -- 551 Commands that send text from source buffers to Lisp processes --
630 like lisp-eval-defun or lisp-show-arglist -- have to choose a process 552 like `lisp-eval-defun' or `lisp-show-arglist' -- have to choose a process
631 to send to, when you have more than one Lisp process around. This 553 to send to, when you have more than one Lisp process around. This
632 is determined by the global variable inferior-lisp-buffer. Suppose you 554 is determined by the global variable `inferior-lisp-buffer'. Suppose you
633 have three inferior lisps running: 555 have three inferior Lisps running:
634 Buffer Process 556 Buffer Process
635 foo inferior-lisp 557 foo inferior-lisp
636 bar inferior-lisp<2> 558 bar inferior-lisp<2>
637 *inferior-lisp* inferior-lisp<3> 559 *inferior-lisp* inferior-lisp<3>
638 If you do a \\[lisp-eval-defun] command on some Lisp source code, 560 If you do a \\[lisp-eval-defun] command on some Lisp source code,
639 what process do you send it to? 561 what process do you send it to?
640 562
641 - If you're in a process buffer (foo, bar, or *inferior-lisp*), 563 - If you're in a process buffer (foo, bar, or *inferior-lisp*),
642 you send it to that process. 564 you send it to that process.
643 - If you're in some other buffer (e.g., a source file), you 565 - If you're in some other buffer (e.g., a source file), you
644 send it to the process attached to buffer inferior-lisp-buffer. 566 send it to the process attached to buffer `inferior-lisp-buffer'.
645 This process selection is performed by function inferior-lisp-proc. 567 This process selection is performed by function `inferior-lisp-proc'.
646 568
647 Whenever \\[inferior-lisp] fires up a new process, it resets 569 Whenever \\[inferior-lisp] fires up a new process, it resets
648 inferior-lisp-buffer to be the new process's buffer. If you only run 570 `inferior-lisp-buffer' to be the new process's buffer. If you only run
649 one process, this will do the right thing. If you run multiple 571 one process, this does the right thing. If you run multiple
650 processes, you can change inferior-lisp-buffer to another process 572 processes, you can change `inferior-lisp-buffer' to another process
651 buffer with \\[set-variable]. 573 buffer with \\[set-variable].")
652 574
653 More sophisticated approaches are, of course, possible. If you find yourself 575 ;; "Returns the current inferior Lisp process.
654 needing to switch back and forth between multiple processes frequently, 576 ;; See variable `inferior-lisp-buffer'."
655 you may wish to consider ilisp.el, a larger, more sophisticated package
656 for running inferior Lisp processes. The approach taken here is for a
657 minimal, simple implementation. Feel free to extend it.")
658
659 (defun inferior-lisp-proc () 577 (defun inferior-lisp-proc ()
660 "Returns the current inferior-lisp process. See variable inferior-lisp-buffer."
661 (let ((proc (get-buffer-process (if (eq major-mode 'inferior-lisp-mode) 578 (let ((proc (get-buffer-process (if (eq major-mode 'inferior-lisp-mode)
662 (current-buffer) 579 (current-buffer)
663 inferior-lisp-buffer)))) 580 inferior-lisp-buffer))))
664 (or proc 581 (or proc
665 (error "No current process. See variable inferior-lisp-buffer")))) 582 (error "No current process. See variable inferior-lisp-buffer"))))
666 583
667 584
668 ;;; Do the user's customisation... 585 ;;; Do the user's customisation...
669 ;;;=============================== 586 ;;;===============================
670 (defvar inferior-lisp-load-hook nil 587 (defvar inferior-lisp-load-hook nil
671 "This hook is run when inferior-lisp is loaded in. 588 "This hook is run when the library `inf-lisp' is loaded.
672 This is a good place to put keybindings.") 589 This is a good place to put keybindings.")
673 590
674 (run-hooks 'inferior-lisp-load-hook) 591 (run-hooks 'inferior-lisp-load-hook)
675 592
676 ;;; CHANGE LOG 593 ;;; CHANGE LOG