comparison lisp/progmodes/inf-lisp.el @ 727:540b047ece4d

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Wed, 24 Jun 1992 05:09:26 +0000
parents 8a533acedb77
children b7932f859d4e
comparison
equal deleted inserted replaced
726:5f08efa38dd0 727:540b047ece4d
98 ;;; 98 ;;;
99 ;;; Additionally, these commands are added to the key bindings of Lisp mode: 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. 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. 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. 102 ;;; c-x c-e lisp-eval-last-sexp Send the previous sexp to Lisp process.
103 ;;; c-c m-e lisp-eval-defun-and-go After sending the defun, switch-to-lisp.
104 ;;; c-c c-r lisp-eval-region Send the current region to Lisp process. 103 ;;; c-c c-r lisp-eval-region Send the current region to Lisp process.
105 ;;; c-c m-r lisp-eval-region-and-go After sending the region, switch-to-lisp.
106 ;;; c-c c-c lisp-compile-defun Compile the current defun in Lisp process. 104 ;;; c-c c-c lisp-compile-defun Compile the current defun in Lisp process.
107 ;;; c-c m-c lisp-compile-defun-and-go After compiling defun, switch-to-lisp.
108 ;;; c-c c-z switch-to-lisp Switch to the Lisp process buffer. 105 ;;; c-c c-z switch-to-lisp Switch to the Lisp process buffer.
109 ;;; c-c c-l lisp-load-file (See above. In a Lisp file buffer, default 106 ;;; c-c c-l lisp-load-file (See above. In a Lisp file buffer, default
110 ;;; c-c c-k lisp-compile-file is to load/compile the current file.) 107 ;;; c-c c-k lisp-compile-file is to load/compile the current file.)
111 ;;; c-c c-d lisp-describe-sym Query Lisp for a symbol's description. 108 ;;; c-c c-d lisp-describe-sym Query Lisp for a symbol's description.
112 ;;; c-c c-a lisp-show-arglist Query Lisp for function's arglist. 109 ;;; c-c c-a lisp-show-arglist Query Lisp for function's arglist.
113 ;;; c-c c-f lisp-show-function-documentation Query Lisp for a function's doc. 110 ;;; c-c c-f lisp-show-function-documentation Query Lisp for a function's doc.
114 ;;; c-c c-v lisp-show-variable-documentation Query Lisp for a variable's doc. 111 ;;; c-c c-v lisp-show-variable-documentation Query Lisp for a variable's doc.
115 112
116 ;;; cmulisp Fires up the Lisp process. 113 ;;; cmulisp Fires up the Lisp process.
117 ;;; lisp-compile-region Compile all forms in the current region. 114 ;;; lisp-compile-region Compile all forms in the current region.
118 ;;; lisp-compile-region-and-go After compiling region, switch-to-lisp.
119 ;;; 115 ;;;
120 ;;; CMU Lisp Mode Variables: 116 ;;; CMU Lisp Mode Variables:
121 ;;; cmulisp-filter-regexp Match this => don't get saved on input hist 117 ;;; cmulisp-filter-regexp Match this => don't get saved on input hist
122 ;;; inferior-lisp-program Name of Lisp program run-lisp executes 118 ;;; inferior-lisp-program Name of Lisp program run-lisp executes
123 ;;; inferior-lisp-load-command Customises lisp-load-file 119 ;;; inferior-lisp-load-command Customises lisp-load-file
152 ;;; These commands augment Lisp mode, so you can process Lisp code in 148 ;;; These commands augment Lisp mode, so you can process Lisp code in
153 ;;; the source files. 149 ;;; the source files.
154 (define-key lisp-mode-map "\M-\C-x" 'lisp-eval-defun) ; Gnu convention 150 (define-key lisp-mode-map "\M-\C-x" 'lisp-eval-defun) ; Gnu convention
155 (define-key lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp) ; Gnu convention 151 (define-key lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp) ; Gnu convention
156 (define-key lisp-mode-map "\C-c\C-e" 'lisp-eval-defun) 152 (define-key lisp-mode-map "\C-c\C-e" 'lisp-eval-defun)
157 (define-key lisp-mode-map "\C-c\M-e" 'lisp-eval-defun-and-go)
158 (define-key lisp-mode-map "\C-c\C-r" 'lisp-eval-region) 153 (define-key lisp-mode-map "\C-c\C-r" 'lisp-eval-region)
159 (define-key lisp-mode-map "\C-c\M-r" 'lisp-eval-region-and-go)
160 (define-key lisp-mode-map "\C-c\C-c" 'lisp-compile-defun) 154 (define-key lisp-mode-map "\C-c\C-c" 'lisp-compile-defun)
161 (define-key lisp-mode-map "\C-c\M-c" 'lisp-compile-defun-and-go)
162 (define-key lisp-mode-map "\C-c\C-z" 'switch-to-lisp) 155 (define-key lisp-mode-map "\C-c\C-z" 'switch-to-lisp)
163 (define-key lisp-mode-map "\C-c\C-l" 'lisp-load-file) 156 (define-key lisp-mode-map "\C-c\C-l" 'lisp-load-file)
164 (define-key lisp-mode-map "\C-c\C-k" 'lisp-compile-file) ; "kompile" file 157 (define-key lisp-mode-map "\C-c\C-k" 'lisp-compile-file) ; "kompile" file
165 (define-key lisp-mode-map "\C-c\C-a" 'lisp-show-arglist) 158 (define-key lisp-mode-map "\C-c\C-a" 'lisp-show-arglist)
166 (define-key lisp-mode-map "\C-c\C-d" 'lisp-describe-sym) 159 (define-key lisp-mode-map "\C-c\C-d" 'lisp-describe-sym)
167 (define-key lisp-mode-map "\C-c\C-f" 'lisp-show-function-documentation) 160 (define-key lisp-mode-map "\C-c\C-f" 'lisp-show-function-documentation)
168 (define-key lisp-mode-map "\C-c\C-v" 'lisp-show-variable-documentation) 161 (define-key lisp-mode-map "\C-c\C-v" 'lisp-show-variable-documentation)
162
163
164 ;;; This function exists for backwards compatibility.
165 ;;; Previous versions of this package bound commands to C-c <letter>
166 ;;; bindings, which is not allowed by the gnumacs standard.
167
168 (defun cmulisp-install-letter-bindings ()
169 "This function binds many cmulisp commands to C-c <letter> bindings,
170 where they are more accessible. C-c <letter> bindings are reserved for the
171 user, so these bindings are non-standard. If you want them, you should
172 have this function called by the cmulisp-load-hook:
173 (setq cmulisp-load-hook '(cmulisp-install-letter-bindings))
174 You can modify this function to install just the bindings you want."
175
176 (define-key lisp-mode-map "\C-ce" 'lisp-eval-defun-and-go)
177 (define-key lisp-mode-map "\C-cr" 'lisp-eval-region-and-go)
178 (define-key lisp-mode-map "\C-cc" 'lisp-compile-defun-and-go)
179 (define-key lisp-mode-map "\C-cz" 'switch-to-lisp)
180 (define-key lisp-mode-map "\C-cl" 'lisp-load-file)
181 (define-key lisp-mode-map "\C-ck" 'lisp-compile-file)
182 (define-key lisp-mode-map "\C-ca" 'lisp-show-arglist)
183 (define-key lisp-mode-map "\C-cd" 'lisp-describe-sym)
184 (define-key lisp-mode-map "\C-cf" 'lisp-show-function-documentation)
185 (define-key lisp-mode-map "\C-cv" 'lisp-show-variable-documentation)
186
187 (define-key cmulisp-mode-map "\C-cl" 'lisp-load-file)
188 (define-key cmulisp-mode-map "\C-ck" 'lisp-compile-file)
189 (define-key cmulisp-mode-map "\C-ca" 'lisp-show-arglist)
190 (define-key cmulisp-mode-map "\C-cd" 'lisp-describe-sym)
191 (define-key cmulisp-mode-map "\C-cf" 'lisp-show-function-documentation)
192 (define-key cmulisp-mode-map "\C-cv" 'lisp-show-variable-documentation))
169 193
170 194
171 (defvar inferior-lisp-program "lisp" 195 (defvar inferior-lisp-program "lisp"
172 "*Program name for invoking an inferior Lisp with `cmulisp'.") 196 "*Program name for invoking an inferior Lisp with `cmulisp'.")
173 197
218 lisp-eval-defun sends the current defun to the Lisp process. 242 lisp-eval-defun sends the current defun to the Lisp process.
219 lisp-compile-defun compiles the current defun. 243 lisp-compile-defun compiles the current defun.
220 lisp-eval-region sends the current region to the Lisp process. 244 lisp-eval-region sends the current region to the Lisp process.
221 lisp-compile-region compiles the current region. 245 lisp-compile-region compiles the current region.
222 246
223 lisp-eval-defun-and-go, lisp-compile-defun-and-go, 247 Prefixing the lisp-eval/compile-defun/region commands with
224 lisp-eval-region-and-go, and lisp-compile-region-and-go 248 a \\[universal-argument] causes a switch to the Lisp process buffer after sending
225 switch to the Lisp process buffer after sending their text. 249 the text.
226 250
227 Commands: 251 Commands:
228 Return after the end of the process' output sends the text from the 252 Return after the end of the process' output sends the text from the
229 end of process to point. 253 end of process to point.
230 Return before the end of the process' output copies the sexp ending at point 254 Return before the end of the process' output copies the sexp ending at point
260 284
261 (defun lisp-input-filter (str) 285 (defun lisp-input-filter (str)
262 "Don't save anything matching cmulisp-filter-regexp" 286 "Don't save anything matching cmulisp-filter-regexp"
263 (not (string-match cmulisp-filter-regexp str))) 287 (not (string-match cmulisp-filter-regexp str)))
264 288
265 (defun cmulisp () 289 (defun cmulisp (cmd)
266 "Run an inferior Lisp process, input and output via buffer *cmulisp*. 290 "Run an inferior Lisp process, input and output via buffer *cmulisp*.
267 If there is a process already running in *cmulisp*, just switch to that buffer. 291 If there is a process already running in *cmulisp*, just switch to that buffer.
268 Takes the program name from the variable inferior-lisp-program. 292 With argument, allows you to edit the command line (default is value
293 of inferior-lisp-program). Runs the hooks from cmulisp-mode-hook (after the
294 comint-mode-hook is run).
269 \(Type \\[describe-mode] in the process buffer for a list of commands.)" 295 \(Type \\[describe-mode] in the process buffer for a list of commands.)"
270 (interactive) 296 (interactive (list (if current-prefix-arg
271 (cond ((not (comint-check-proc "*cmulisp*")) 297 (read-string "Run lisp: " inferior-lisp-program)
272 (set-buffer (make-comint "cmulisp" inferior-lisp-program)) 298 inferior-lisp-program)))
299 (if (not (comint-check-proc "*cmulisp*"))
300 (let ((cmdlist (cmulisp-args-to-list cmd)))
301 (set-buffer (apply (function make-comint) "cmulisp" (car cmdlist) nil
302 (cdr cmdlist)))
273 (cmulisp-mode))) 303 (cmulisp-mode)))
274 (setq cmulisp-buffer "*cmulisp*") 304 (setq cmulisp-buffer "*cmulisp*")
275 (switch-to-buffer "*cmulisp*")) 305 (switch-to-buffer "*cmulisp*"))
276 306
277 (defun lisp-eval-region (start end) 307 ;;; Break a string up into a list of arguments.
278 "Send the current region to the inferior Lisp process." 308 ;;; This will break if you have an argument with whitespace, as in
279 (interactive "r") 309 ;;; string = "-ab +c -x 'you lose'".
310 (defun cmulisp-args-to-list (string)
311 (let ((where (string-match "[ \t]" string)))
312 (cond ((null where) (list string))
313 ((not (= where 0))
314 (cons (substring string 0 where)
315 (tea-args-to-list (substring string (+ 1 where)
316 (length string)))))
317 (t (let ((pos (string-match "[^ \t]" string)))
318 (if (null pos)
319 nil
320 (cmulsip-args-to-list (substring string pos
321 (length string)))))))))
322
323 (defun lisp-eval-region (start end &optional and-go)
324 "Send the current region to the inferior Lisp process.
325 Prefix argument means switch-to-lisp afterwards."
326 (interactive "r\nP")
280 (comint-send-region (cmulisp-proc) start end) 327 (comint-send-region (cmulisp-proc) start end)
281 (comint-send-string (cmulisp-proc) "\n")) 328 (comint-send-string (cmulisp-proc) "\n")
282 329 (if and-go (switch-to-lisp t)))
283 (defun lisp-eval-defun () 330
284 "Send the current defun to the inferior Lisp process." 331 (defun lisp-eval-defun (&optional and-go)
285 (interactive) 332 "Send the current defun to the inferior Lisp process.
333 Prefix argument means switch-to-lisp afterwards."
334 (interactive "P")
286 (save-excursion 335 (save-excursion
287 (end-of-defun) 336 (end-of-defun)
288 (let ((end (point))) 337 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
289 (beginning-of-defun) 338 (let ((end (point)))
290 (lisp-eval-region (point) end)))) 339 (beginning-of-defun)
291 340 (lisp-eval-region (point) end)))
292 (defun lisp-eval-last-sexp () 341 (if and-go (switch-to-lisp t)))
293 "Send the previous sexp to the inferior Lisp process." 342
294 (interactive) 343 (defun lisp-eval-last-sexp (&optional and-go)
295 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point))) 344 "Send the previous sexp to the inferior Lisp process.
296 345 Prefix argument means switch-to-lisp afterwards."
297 ;;; CommonLisp COMPILE sux. 346 (interactive "P")
298 (defun lisp-compile-region (start end) 347 (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go))
299 "Compile the current region in the inferior Lisp process." 348
300 (interactive "r") 349 ;;; Common Lisp COMPILE sux.
350 (defun lisp-compile-region (start end &optional and-go)
351 "Compile the current region in the inferior Lisp process.
352 Prefix argument means switch-to-lisp afterwards."
353 (interactive "r\nP")
301 (comint-send-string (cmulisp-proc) 354 (comint-send-string (cmulisp-proc)
302 (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n" 355 (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n"
303 (buffer-substring start end)))) 356 (buffer-substring start end)))
357 (if and-go (switch-to-lisp t)))
304 358
305 (defun lisp-compile-defun () 359 (defun lisp-compile-defun (&optional and-go)
306 "Compile the current defun in the inferior Lisp process." 360 "Compile the current defun in the inferior Lisp process.
307 (interactive) 361 Prefix argument means switch-to-lisp afterwards."
362 (interactive "P")
308 (save-excursion 363 (save-excursion
309 (end-of-defun) 364 (end-of-defun)
365 (skip-chars-backward " \t\n\r\f") ; Makes allegro happy
310 (let ((e (point))) 366 (let ((e (point)))
311 (beginning-of-defun) 367 (beginning-of-defun)
312 (lisp-compile-region (point) e)))) 368 (lisp-compile-region (point) e)))
369 (if and-go (switch-to-lisp t)))
313 370
314 (defun switch-to-lisp (eob-p) 371 (defun switch-to-lisp (eob-p)
315 "Switch to the inferior Lisp process buffer. 372 "Switch to the inferior Lisp process buffer.
316 With argument, positions cursor at end of buffer." 373 With argument, positions cursor at end of buffer."
317 (interactive "P") 374 (interactive "P")
320 (error "No current process buffer. See variable cmulisp-buffer.")) 377 (error "No current process buffer. See variable cmulisp-buffer."))
321 (cond (eob-p 378 (cond (eob-p
322 (push-mark) 379 (push-mark)
323 (goto-char (point-max))))) 380 (goto-char (point-max)))))
324 381
382
383 ;;; Now that lisp-compile/eval-defun/region takes an optional prefix arg,
384 ;;; these commands are redundant. But they are kept around for the user
385 ;;; to bind if he wishes, for backwards functionality, and because it's
386 ;;; easier to type C-c e than C-u C-c C-e.
387
325 (defun lisp-eval-region-and-go (start end) 388 (defun lisp-eval-region-and-go (start end)
326 "Send the current region to the inferior Lisp, 389 "Send the current region to the inferior Lisp,
327 and switch to the process buffer." 390 and switch to the process buffer."
328 (interactive "r") 391 (interactive "r")
329 (lisp-eval-region start end) 392 (lisp-eval-region start end t))
330 (switch-to-lisp t))
331 393
332 (defun lisp-eval-defun-and-go () 394 (defun lisp-eval-defun-and-go ()
333 "Send the current defun to the inferior Lisp, 395 "Send the current defun to the inferior Lisp,
334 and switch to the process buffer." 396 and switch to the process buffer."
335 (interactive) 397 (interactive)
336 (lisp-eval-defun) 398 (lisp-eval-defun t))
337 (switch-to-lisp t))
338 399
339 (defun lisp-compile-region-and-go (start end) 400 (defun lisp-compile-region-and-go (start end)
340 "Compile the current region in the inferior Lisp, 401 "Compile the current region in the inferior Lisp,
341 and switch to the process buffer." 402 and switch to the process buffer."
342 (interactive "r") 403 (interactive "r")
343 (lisp-compile-region start end) 404 (lisp-compile-region start end t))
344 (switch-to-lisp t))
345 405
346 (defun lisp-compile-defun-and-go () 406 (defun lisp-compile-defun-and-go ()
347 "Compile the current defun in the inferior Lisp, 407 "Compile the current defun in the inferior Lisp,
348 and switch to the process buffer." 408 and switch to the process buffer."
349 (interactive) 409 (interactive)
350 (lisp-compile-defun) 410 (lisp-compile-defun t))
351 (switch-to-lisp t))
352 411
353 ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust. 412 ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust.
354 ;(defun lisp-compile-sexp (start end) 413 ;(defun lisp-compile-sexp (start end)
355 ; "Compile the s-expression bounded by START and END in the inferior lisp. 414 ; "Compile the s-expression bounded by START and END in the inferior lisp.
356 ;If the sexp isn't a DEFUN form, it is evaluated instead." 415 ;If the sexp isn't a DEFUN form, it is evaluated instead."
404 ; doesn't need an exact name 463 ; doesn't need an exact name
405 (comint-check-source file-name) ; Check to see if buffer needs saved. 464 (comint-check-source file-name) ; Check to see if buffer needs saved.
406 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name) 465 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name)
407 (file-name-nondirectory file-name))) 466 (file-name-nondirectory file-name)))
408 (comint-send-string (cmulisp-proc) 467 (comint-send-string (cmulisp-proc)
409 (format inferior-lisp-load-command file-name))) 468 (format inferior-lisp-load-command file-name))
469 (switch-to-lisp t))
410 470
411 471
412 (defun lisp-compile-file (file-name) 472 (defun lisp-compile-file (file-name)
413 "Compile a Lisp file in the inferior Lisp process." 473 "Compile a Lisp file in the inferior Lisp process."
414 (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l/c-dir/file 474 (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l/c-dir/file
417 (comint-check-source file-name) ; Check to see if buffer needs saved. 477 (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) 478 (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name)
419 (file-name-nondirectory file-name))) 479 (file-name-nondirectory file-name)))
420 (comint-send-string (cmulisp-proc) (concat "(compile-file \"" 480 (comint-send-string (cmulisp-proc) (concat "(compile-file \""
421 file-name 481 file-name
422 "\"\)\n"))) 482 "\"\)\n"))
483 (switch-to-lisp t))
423 484
424 485
425 486
426 ;;; Documentation functions: function doc, var doc, arglist, and 487 ;;; Documentation functions: function doc, var doc, arglist, and
427 ;;; describe symbol. 488 ;;; describe symbol.
539 have three inferior lisps running: 600 have three inferior lisps running:
540 Buffer Process 601 Buffer Process
541 foo cmulisp 602 foo cmulisp
542 bar cmulisp<2> 603 bar cmulisp<2>
543 *cmulisp* cmulisp<3> 604 *cmulisp* cmulisp<3>
544 If you do a \\[lisp-eval-defun-and-go] command on some Lisp source code, 605 If you do a \\[lisp-eval-defun] command on some Lisp source code,
545 what process do you send it to? 606 what process do you send it to?
546 607
547 - If you're in a process buffer (foo, bar, or *cmulisp*), 608 - If you're in a process buffer (foo, bar, or *cmulisp*),
548 you send it to that process. 609 you send it to that process.
549 - If you're in some other buffer (e.g., a source file), you 610 - If you're in some other buffer (e.g., a source file), you
596 ;;; reported by Lennart Staflin. 657 ;;; reported by Lennart Staflin.
597 ;;; 658 ;;;
598 ;;; 3/12/90 Olin 659 ;;; 3/12/90 Olin
599 ;;; - lisp-load-file and lisp-compile-file no longer switch-to-lisp. 660 ;;; - lisp-load-file and lisp-compile-file no longer switch-to-lisp.
600 ;;; Tale suggested this. 661 ;;; Tale suggested this.
662 ;;; - Reversed this decision 7/15/91. You need the visual feedback.
663 ;;;
664 ;;; 7/25/91 Olin
665 ;;; Changed all keybindings of the form C-c <letter>. These are
666 ;;; supposed to be reserved for the user to bind. This affected
667 ;;; mainly the compile/eval-defun/region[-and-go] commands.
668 ;;; This was painful, but necessary to adhere to the gnumacs standard.
669 ;;; For some backwards compatibility, see the
670 ;;; cmulisp-install-letter-bindings
671 ;;; function.
672 ;;;
673 ;;; 8/2/91 Olin
674 ;;; - The lisp-compile/eval-defun/region commands now take a prefix arg,
675 ;;; which means switch-to-lisp after sending the text to the Lisp process.
676 ;;; This obsoletes all the -and-go commands. The -and-go commands are
677 ;;; kept around for historical reasons, and because the user can bind
678 ;;; them to key sequences shorter than C-u C-c C-<letter>.
679 ;;; - If M-x cmulisp is invoked with a prefix arg, it allows you to
680 ;;; edit the command line.
601 681
602 (provide 'cmulisp) 682 (provide 'cmulisp)
603 683
604 ;;; cmulisp.el ends here 684 ;;; cmulisp.el ends here