home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / comint / inf-lisp.el < prev    next >
Encoding:
Text File  |  1995-03-25  |  26.0 KB  |  640 lines

  1. ;;; inf-lisp.el --- an inferior-lisp mode
  2. ;;; Copyright (C) 1988, 1993 Free Software Foundation, Inc.
  3.  
  4. ;; Author: Olin Shivers <shivers@cs.cmu.edu>
  5. ;; Keywords: processes, lisp
  6.  
  7. ;; This file is part of XEmacs.
  8.  
  9. ;; XEmacs is free software; you can redistribute it and/or modify it
  10. ;; 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. ;; XEmacs is distributed in the hope that it will be useful, but
  15. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. ;; General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  21. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. ;;; Commentary:
  24.  
  25. ;;; Hacked from tea.el by Olin Shivers (shivers@cs.cmu.edu). 8/88
  26.  
  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).
  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 customizing it, see the file comint.el.
  40. ;;; For further information on inferior-lisp mode, see the comments below.
  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. ;;;
  51. ;;; It would be nice if inferior-lisp (and inferior scheme, T, ...) modes
  52. ;;; had a verbose minor mode wherein sending or compiling defuns, etc.
  53. ;;; would be reflected in the transcript with suitable comments, e.g.
  54. ;;; ";;; redefining fact". Several ways to do this. Which is right?
  55. ;;;
  56. ;;; When sending text from a source file to a subprocess, the process-mark can 
  57. ;;; move off the window, so you can lose sight of the process interactions.
  58. ;;; Maybe I should ensure the process mark is in the window when I send
  59. ;;; text to the process? Switch selectable?
  60.  
  61. ;;; Code:
  62.  
  63. (require 'comint)
  64. (require 'lisp-mode)
  65.  
  66.  
  67. ;;;jwz: ilisp is better, don't ###autoload
  68. (defvar inferior-lisp-filter-regexp "\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'"
  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 
  72. (as in :a, :c, etc.)")
  73.  
  74. (defvar inferior-lisp-mode-map nil)
  75. (cond ((not inferior-lisp-mode-map)
  76.        (setq inferior-lisp-mode-map (make-sparse-keymap))
  77.        (set-keymap-name inferior-lisp-mode-map 'inferior-lisp-mode-map)
  78.        (set-keymap-parent inferior-lisp-mode-map comint-mode-map)
  79.  
  80.        ;;>>> ARRGG!  Need multiple parents
  81.        ;(set-keymap-parent inferior-lisp-mode-map shared-lisp-mode-map)
  82.     ;; This used to be done by calling `lisp-mode-commands' in lisp-mode.el
  83.     (define-key inferior-lisp-mode-map "\e\C-q" 'indent-sexp)
  84.     (define-key inferior-lisp-mode-map "\177" 'backward-delete-char-untabify)
  85.        (define-key inferior-lisp-mode-map "\t" 'lisp-indent-line)
  86.  
  87.        (define-key inferior-lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp)
  88.        (define-key inferior-lisp-mode-map "\C-c\C-l" 'lisp-load-file)
  89.        (define-key inferior-lisp-mode-map "\C-c\C-k" 'lisp-compile-file)
  90.        (define-key inferior-lisp-mode-map "\C-c\C-a" 'lisp-show-arglist)
  91.        (define-key inferior-lisp-mode-map "\C-c\C-d" 'lisp-describe-sym)
  92.        (define-key inferior-lisp-mode-map "\C-c\C-f"
  93.      'lisp-show-function-documentation)
  94.        (define-key inferior-lisp-mode-map "\C-c\C-v"
  95.      'lisp-show-variable-documentation)))
  96.  
  97. ;;; These commands augment Lisp mode, so you can process Lisp code in
  98. ;;; the source files.
  99. (define-key lisp-mode-map "\M-\C-x"  'lisp-eval-defun)     ; Gnu convention
  100. (define-key lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp) ; Gnu convention
  101. (define-key lisp-mode-map "\C-c\C-e" 'lisp-eval-defun)
  102. (define-key lisp-mode-map "\C-c\C-r" 'lisp-eval-region)
  103. (define-key lisp-mode-map "\C-c\C-c" 'lisp-compile-defun)
  104. (define-key lisp-mode-map "\C-c\C-z" 'switch-to-lisp)
  105. (define-key lisp-mode-map "\C-c\C-l" 'lisp-load-file)
  106. (define-key lisp-mode-map "\C-c\C-k" 'lisp-compile-file)  ; "kompile" file
  107. (define-key lisp-mode-map "\C-c\C-a" 'lisp-show-arglist)
  108. (define-key lisp-mode-map "\C-c\C-d" 'lisp-describe-sym)
  109. (define-key lisp-mode-map "\C-c\C-f" 'lisp-show-function-documentation)
  110. (define-key lisp-mode-map "\C-c\C-v" 'lisp-show-variable-documentation)
  111.  
  112. ;;; This function exists for backwards compatibility.
  113. ;;; Previous versions of this package bound commands to C-c <letter>
  114. ;;; bindings, which is not allowed by the gnumacs standard.
  115.  
  116. ;;;  "This function binds many inferior-lisp commands to C-c <letter> bindings,
  117. ;;;where they are more accessible. C-c <letter> bindings are reserved for the
  118. ;;;user, so these bindings are non-standard. If you want them, you should
  119. ;;;have this function called by the inferior-lisp-load-hook:
  120. ;;;    (setq inferior-lisp-load-hook '(inferior-lisp-install-letter-bindings))
  121. ;;;You can modify this function to install just the bindings you want."
  122. (defun inferior-lisp-install-letter-bindings ()
  123.   (define-key lisp-mode-map "\C-ce" 'lisp-eval-defun-and-go)
  124.   (define-key lisp-mode-map "\C-cr" 'lisp-eval-region-and-go)
  125.   (define-key lisp-mode-map "\C-cc" 'lisp-compile-defun-and-go)
  126.   (define-key lisp-mode-map "\C-cz" 'switch-to-lisp)
  127.   (define-key lisp-mode-map "\C-cl" 'lisp-load-file)
  128.   (define-key lisp-mode-map "\C-ck" 'lisp-compile-file)
  129.   (define-key lisp-mode-map "\C-ca" 'lisp-show-arglist)
  130.   (define-key lisp-mode-map "\C-cd" 'lisp-describe-sym)
  131.   (define-key lisp-mode-map "\C-cf" 'lisp-show-function-documentation)
  132.   (define-key lisp-mode-map "\C-cv" 'lisp-show-variable-documentation)
  133.   
  134.   (define-key inferior-lisp-mode-map "\C-cl" 'lisp-load-file)
  135.   (define-key inferior-lisp-mode-map "\C-ck" 'lisp-compile-file)
  136.   (define-key inferior-lisp-mode-map "\C-ca" 'lisp-show-arglist)
  137.   (define-key inferior-lisp-mode-map "\C-cd" 'lisp-describe-sym)
  138.   (define-key inferior-lisp-mode-map "\C-cf" 'lisp-show-function-documentation)
  139.   (define-key inferior-lisp-mode-map "\C-cv"
  140.     'lisp-show-variable-documentation))
  141.  
  142.  
  143. ;;;jwz: ilisp is better, don't ###autoload
  144. (defvar inferior-lisp-program "lisp"
  145.   "*Program name for invoking an inferior Lisp with for Inferior Lisp mode.")
  146.  
  147. ;;;jwz: ilisp is better, don't ###autoload
  148. (defvar inferior-lisp-load-command "(load \"%s\")\n"
  149.   "*Format-string for building a Lisp expression to load a file.
  150. This format string should use `%s' to substitute a file name
  151. and should result in a Lisp expression that will command the inferior Lisp
  152. to load that file.  The default works acceptably on most Lisps.
  153. The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\\n\"
  154. produces cosmetically superior output for this application,
  155. but it works only in Common Lisp.")
  156.  
  157. ;;;jwz: ilisp is better, don't ###autoload
  158. (defvar inferior-lisp-prompt "^[^> ]*>+:? *"
  159.   "Regexp to recognise prompts in the Inferior Lisp mode.
  160. Defaults to \"^[^> ]*>+:? *\", which works pretty good for Lucid, kcl,
  161. and franz. This variable is used to initialize `comint-prompt-regexp' in the 
  162. Inferior Lisp buffer.
  163.  
  164. More precise choices:
  165. Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\"
  166. franz: \"^\\(->\\|<[0-9]*>:\\) *\"
  167. kcl: \"^>+ *\"
  168.  
  169. This is a fine thing to set in your .emacs file.")
  170.  
  171. (defvar inferior-lisp-buffer nil "*The current inferior-lisp process buffer.
  172.  
  173. MULTIPLE PROCESS SUPPORT
  174. ===========================================================================
  175. To run multiple Lisp processes, you start the first up
  176. with \\[inferior-lisp].  It will be in a buffer named `*inferior-lisp*'.
  177. Rename this buffer with \\[rename-buffer].  You may now start up a new
  178. process with another \\[inferior-lisp].  It will be in a new buffer,
  179. named `*inferior-lisp*'.  You can switch between the different process
  180. buffers with \\[switch-to-buffer].
  181.  
  182. Commands that send text from source buffers to Lisp processes --
  183. like `lisp-eval-defun' or `lisp-show-arglist' -- have to choose a process
  184. to send to, when you have more than one Lisp process around.  This
  185. is determined by the global variable `inferior-lisp-buffer'.  Suppose you
  186. have three inferior Lisps running:
  187.     Buffer              Process
  188.     foo                 inferior-lisp
  189.     bar                 inferior-lisp<2>
  190.     *inferior-lisp*     inferior-lisp<3>
  191. If you do a \\[lisp-eval-defun] command on some Lisp source code, 
  192. what process do you send it to?
  193.  
  194. - If you're in a process buffer (foo, bar, or *inferior-lisp*), 
  195.   you send it to that process.
  196. - If you're in some other buffer (e.g., a source file), you
  197.   send it to the process attached to buffer `inferior-lisp-buffer'.
  198. This process selection is performed by function `inferior-lisp-proc'.
  199.  
  200. Whenever \\[inferior-lisp] fires up a new process, it resets
  201. `inferior-lisp-buffer' to be the new process's buffer.  If you only run
  202. one process, this does the right thing.  If you run multiple
  203. processes, you can change `inferior-lisp-buffer' to another process
  204. buffer with \\[set-variable].")
  205.  
  206. ;;;jwz: ilisp is better, don't ###autoload
  207. (defvar inferior-lisp-mode-hook '() 
  208.   "*Hook for customizing Inferior Lisp mode.")
  209.  
  210. (defun inferior-lisp-mode () 
  211.   "Major mode for interacting with an inferior Lisp process.  
  212. Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an
  213. Emacs buffer.  Variable `inferior-lisp-program' controls which Lisp interpreter
  214. is run.  Variables `inferior-lisp-prompt', `inferior-lisp-filter-regexp' and
  215. `inferior-lisp-load-command' can customize this mode for different Lisp
  216. interpreters.
  217.  
  218. For information on running multiple processes in multiple buffers, see
  219. documentation for variable `inferior-lisp-buffer'.
  220.  
  221. \\{inferior-lisp-mode-map}
  222.  
  223. Customization: Entry to this mode runs the hooks on `comint-mode-hook' and
  224. `inferior-lisp-mode-hook' (in that order).
  225.  
  226. You can send text to the inferior Lisp process from other buffers containing
  227. Lisp source.  
  228.     switch-to-lisp switches the current buffer to the Lisp process buffer.
  229.     lisp-eval-defun sends the current defun to the Lisp process.
  230.     lisp-compile-defun compiles the current defun.
  231.     lisp-eval-region sends the current region to the Lisp process.
  232.     lisp-compile-region compiles the current region.
  233.  
  234.     Prefixing the lisp-eval/compile-defun/region commands with
  235.     a \\[universal-argument] causes a switch to the Lisp process buffer after sending
  236.     the text.
  237.  
  238. Commands:
  239. Return after the end of the process' output sends the text from the 
  240.     end of process to point.
  241. Return before the end of the process' output copies the sexp ending at point
  242.     to the end of the process' output, and sends it.
  243. Delete converts tabs to spaces as it moves back.
  244. Tab indents for Lisp; with argument, shifts rest
  245.     of expression rigidly with the current line.
  246. C-M-q does Tab on each line starting within following expression.
  247. Paragraphs are separated only by blank lines.  Semicolons start comments.
  248. If you accidentally suspend your process, use \\[comint-continue-subjob]
  249. to continue it."
  250.   (interactive)
  251.   (comint-mode)
  252.   (setq comint-prompt-regexp inferior-lisp-prompt)
  253.   (setq major-mode 'inferior-lisp-mode)
  254.   (setq mode-name "Inferior Lisp")
  255.   (setq mode-line-process '(": %s"))
  256.   (lisp-mode-variables t)
  257.   (use-local-map inferior-lisp-mode-map)    ;c-c c-k for "kompile" file
  258.   (setq comint-get-old-input (function lisp-get-old-input))
  259.   (setq comint-input-filter (function lisp-input-filter))
  260.   (setq comint-input-sentinel 'ignore)
  261.   (run-hooks 'inferior-lisp-mode-hook))
  262.  
  263. (defun lisp-get-old-input ()
  264.   "Return a string containing the sexp ending at point."
  265.   (save-excursion
  266.     (let ((end (point)))
  267.       (backward-sexp)
  268.       (buffer-substring (point) end))))
  269.  
  270. (defun lisp-input-filter (str)
  271.   "t if STR does not match `inferior-lisp-filter-regexp'."
  272.   (not (string-match inferior-lisp-filter-regexp str)))
  273.  
  274. ;;;jwz: ilisp is better, don't ###autoload
  275. (defun inferior-lisp (cmd)
  276.   "Run an inferior Lisp process, input and output via buffer `*inferior-lisp*'.
  277. If there is a process already running in `*inferior-lisp*', just switch
  278. to that buffer.
  279. With argument, allows you to edit the command line (default is value
  280. of `inferior-lisp-program').  Runs the hooks from
  281. `inferior-lisp-mode-hook' (after the `comint-mode-hook' is run).
  282. \(Type \\[describe-mode] in the process buffer for a list of commands.)"
  283.   (interactive (list (if current-prefix-arg
  284.              (read-string "Run lisp: " inferior-lisp-program)
  285.                inferior-lisp-program)))
  286.   (if (not (comint-check-proc "*inferior-lisp*"))
  287.       (let ((cmdlist (inferior-lisp-args-to-list cmd)))
  288.     (set-buffer (apply (function make-comint)
  289.                "inferior-lisp" (car cmdlist) nil (cdr cmdlist)))
  290.     (inferior-lisp-mode)))
  291.   (setq inferior-lisp-buffer "*inferior-lisp*")
  292.   (switch-to-buffer "*inferior-lisp*"))
  293.  
  294. ;;;jwz: ilisp is better, don't ###autoload
  295. (define-function 'run-lisp 'inferior-lisp)
  296.  
  297. ;;; Break a string up into a list of arguments.
  298. ;;; This will break if you have an argument with whitespace, as in
  299. ;;; string = "-ab +c -x 'you lose'".
  300. (defun inferior-lisp-args-to-list (string)
  301.   (let ((where (string-match "[ \t]" string)))
  302.     (cond ((null where) (list string))
  303.       ((not (= where 0))
  304.        (cons (substring string 0 where)
  305.          (inferior-lisp-args-to-list (substring string (+ 1 where)
  306.                             (length string)))))
  307.       (t (let ((pos (string-match "[^ \t]" string)))
  308.            (if (null pos)
  309.            nil
  310.          (inferior-lisp-args-to-list (substring string pos
  311.                             (length string)))))))))
  312.  
  313. (defun lisp-eval-region (start end &optional and-go)
  314.   "Send the current region to the inferior Lisp process.
  315. Prefix argument means switch to the Lisp buffer afterwards."
  316.   (interactive "r\nP")
  317.   (comint-send-region (inferior-lisp-proc) start end)
  318.   (comint-send-string (inferior-lisp-proc) "\n")
  319.   (if and-go (switch-to-lisp t)))
  320.  
  321. (defun lisp-eval-defun (&optional and-go)
  322.   "Send the current defun to the inferior Lisp process.
  323. Prefix argument means switch to the Lisp buffer afterwards."
  324.   (interactive "P")
  325.   (save-excursion
  326.    (end-of-defun)
  327.     (skip-chars-backward " \t\n\r\f") ;  Makes allegro happy
  328.    (let ((end (point)))
  329.      (beginning-of-defun)
  330.       (lisp-eval-region (point) end)))
  331.   (if and-go (switch-to-lisp t)))
  332.              
  333. (defun lisp-eval-last-sexp (&optional and-go)
  334.   "Send the previous sexp to the inferior Lisp process.
  335. Prefix argument means switch to the Lisp buffer afterwards."
  336.   (interactive "P")
  337.   (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go))
  338.  
  339. ;;; Common Lisp COMPILE sux. 
  340. (defun lisp-compile-region (start end &optional and-go)
  341.   "Compile the current region in the inferior Lisp process.
  342. Prefix argument means switch to the Lisp buffer afterwards."
  343.   (interactive "r\nP")
  344.   (comint-send-string
  345.    (inferior-lisp-proc)
  346.    (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n"
  347.        (buffer-substring start end)))
  348.   (if and-go (switch-to-lisp t)))
  349.              
  350. (defun lisp-compile-defun (&optional and-go)
  351.   "Compile the current defun in the inferior Lisp process.
  352. Prefix argument means switch to the Lisp buffer afterwards."
  353.   (interactive "P")
  354.   (save-excursion
  355.     (end-of-defun)
  356.     (skip-chars-backward " \t\n\r\f") ;  Makes allegro happy
  357.     (let ((e (point)))
  358.       (beginning-of-defun)
  359.       (lisp-compile-region (point) e)))
  360.   (if and-go (switch-to-lisp t)))
  361.  
  362. (defun switch-to-lisp (eob-p)
  363.   "Switch to the inferior Lisp process buffer.
  364. With argument, positions cursor at end of buffer."
  365.   (interactive "P")
  366.   (if (get-buffer inferior-lisp-buffer)
  367.       (pop-to-buffer inferior-lisp-buffer)
  368.     (error "No current inferior Lisp buffer"))
  369.   (cond (eob-p
  370.      (push-mark)
  371.      (goto-char (point-max)))))
  372.  
  373.  
  374. ;;; Now that lisp-compile/eval-defun/region takes an optional prefix arg,
  375. ;;; these commands are redundant. But they are kept around for the user
  376. ;;; to bind if he wishes, for backwards functionality, and because it's
  377. ;;; easier to type C-c e than C-u C-c C-e.
  378.  
  379. (defun lisp-eval-region-and-go (start end)
  380.   "Send the current region to the inferior Lisp, and switch to its buffer."
  381.   (interactive "r")
  382.   (lisp-eval-region start end t))
  383.  
  384. (defun lisp-eval-defun-and-go ()
  385.   "Send the current defun to the inferior Lisp, and switch to its buffer."
  386.   (interactive)
  387.   (lisp-eval-defun t))
  388.  
  389. (defun lisp-compile-region-and-go (start end)
  390.   "Compile the current region in the inferior Lisp, and switch to its buffer."
  391.   (interactive "r")
  392.   (lisp-compile-region start end t))
  393.  
  394. (defun lisp-compile-defun-and-go ()
  395.   "Compile the current defun in the inferior Lisp, and switch to its buffer."
  396.   (interactive)
  397.   (lisp-compile-defun t))
  398.  
  399. ;;; A version of the form in H. Shevis' soar-mode.el package. Less robust.
  400. ;;; (defun lisp-compile-sexp (start end)
  401. ;;;   "Compile the s-expression bounded by START and END in the inferior lisp.
  402. ;;; If the sexp isn't a DEFUN form, it is evaluated instead."
  403. ;;;   (cond ((looking-at "(defun\\s +")
  404. ;;;      (goto-char (match-end 0))
  405. ;;;      (let ((name-start (point)))
  406. ;;;        (forward-sexp 1)
  407. ;;;        (process-send-string "inferior-lisp"
  408. ;;;                 (format "(compile '%s #'(lambda "
  409. ;;;                     (buffer-substring name-start
  410. ;;;                               (point)))))
  411. ;;;      (let ((body-start (point)))
  412. ;;;        (goto-char start) (forward-sexp 1) ; Can't use end-of-defun.
  413. ;;;        (process-send-region "inferior-lisp"
  414. ;;;                 (buffer-substring body-start (point))))
  415. ;;;      (process-send-string "inferior-lisp" ")\n"))
  416. ;;;     (t (lisp-eval-region start end)))))
  417. ;;; 
  418. ;;; (defun lisp-compile-region (start end)
  419. ;;;   "Each s-expression in the current region is compiled (if a DEFUN)
  420. ;;; or evaluated (if not) in the inferior lisp."
  421. ;;;   (interactive "r")
  422. ;;;   (save-excursion
  423. ;;;     (goto-char start) (end-of-defun) (beginning-of-defun) ; error check
  424. ;;;     (if (< (point) start) (error "region begins in middle of defun"))
  425. ;;;     (goto-char start)
  426. ;;;     (let ((s start))
  427. ;;;       (end-of-defun)
  428. ;;;       (while (<= (point) end) ; Zip through
  429. ;;;     (lisp-compile-sexp s (point)) ; compiling up defun-sized chunks.
  430. ;;;     (setq s (point))
  431. ;;;     (end-of-defun))
  432. ;;;       (if (< s end) (lisp-compile-sexp s end)))))
  433. ;;; 
  434. ;;; End of HS-style code
  435.  
  436.  
  437. (defvar lisp-prev-l/c-dir/file nil
  438.   "Record last directory and file used in loading or compiling.
  439. This holds a cons cell of the form `(DIRECTORY . FILE)'
  440. describing the last `lisp-load-file' or `lisp-compile-file' command.")
  441.  
  442. (defvar lisp-source-modes '(lisp-mode)
  443.   "*Used to determine if a buffer contains Lisp source code.
  444. If it's loaded into a buffer that is in one of these major modes, it's
  445. considered a Lisp source file by `lisp-load-file' and `lisp-compile-file'.
  446. Used by these commands to determine defaults.")
  447.  
  448. (defun lisp-load-file (file-name)
  449.   "Load a Lisp file into the inferior Lisp process."
  450.   (interactive (comint-get-source "Load Lisp file: " lisp-prev-l/c-dir/file
  451.                   lisp-source-modes nil))  ; NIL because LOAD
  452.                     ; doesn't need an exact name
  453.   (comint-check-source file-name) ; Check to see if buffer needs saved.
  454.   (setq lisp-prev-l/c-dir/file (cons (file-name-directory    file-name)
  455.                      (file-name-nondirectory file-name)))
  456.   (comint-send-string (inferior-lisp-proc)
  457.               (format inferior-lisp-load-command file-name))
  458.   (switch-to-lisp t))
  459.  
  460. (defun lisp-compile-file (file-name)
  461.   "Compile a Lisp file in the inferior Lisp process."
  462.   (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l/c-dir/file
  463.                   lisp-source-modes nil)) ; NIL = don't need
  464.                                                           ; suffix .lisp
  465.   (comint-check-source file-name) ; Check to see if buffer needs saved.
  466.   (setq lisp-prev-l/c-dir/file (cons (file-name-directory    file-name)
  467.                      (file-name-nondirectory file-name)))
  468.   (comint-send-string (inferior-lisp-proc) (concat "(compile-file \""
  469.                            file-name
  470.                            "\"\)\n"))
  471.   (switch-to-lisp t))
  472.  
  473.  
  474.  
  475. ;;; Documentation functions: function doc, var doc, arglist, and
  476. ;;; describe symbol.
  477. ;;; ===========================================================================
  478.  
  479. ;;; Command strings
  480. ;;; ===============
  481.  
  482. (defvar lisp-function-doc-command
  483.   "(let ((fn '%s))
  484.      (format t \"Documentation for ~a:~&~a\"
  485.          fn (documentation fn 'function))
  486.      (values))\n"
  487.   "Command to query inferior Lisp for a function's documentation.")
  488.  
  489. (defvar lisp-var-doc-command
  490.   "(let ((v '%s))
  491.      (format t \"Documentation for ~a:~&~a\"
  492.          v (documentation v 'variable))
  493.      (values))\n"
  494.   "Command to query inferior Lisp for a variable's documentation.")
  495.  
  496. (defvar lisp-arglist-command
  497.   "(let ((fn '%s))
  498.      (format t \"Arglist for ~a: ~a\" fn (arglist fn))
  499.      (values))\n"
  500.   "Command to query inferior Lisp for a function's arglist.")
  501.  
  502. (defvar lisp-describe-sym-command
  503.   "(describe '%s)\n"
  504.   "Command to query inferior Lisp for a variable's documentation.")
  505.  
  506.  
  507. ;;; Ancillary functions
  508. ;;; ===================
  509.  
  510. ;;; Reads a string from the user.
  511. (defun lisp-symprompt (prompt default)
  512.   (list (let* ((prompt (if default
  513.                (format "%s (default %s): " prompt default)
  514.              (concat prompt ": ")))
  515.            (ans (read-string prompt)))
  516.       (if (zerop (length ans)) default ans))))
  517.  
  518.  
  519. ;;; Adapted from function-called-at-point in help.el.
  520. (defun lisp-fn-called-at-pt ()
  521.   "Returns the name of the function called in the current call.
  522. The value is nil if it can't find one."
  523.   (condition-case nil
  524.       (save-excursion
  525.     (save-restriction
  526.       (narrow-to-region (max (point-min) (- (point) 1000)) (point-max))
  527.       (backward-up-list 1)
  528.       (forward-char 1)
  529.       (let ((obj (read (current-buffer))))
  530.         (and (symbolp obj) obj))))
  531.     (error nil)))
  532.  
  533.  
  534. ;;; Adapted from variable-at-point in help.el.
  535. (defun lisp-var-at-pt ()
  536.   (condition-case ()
  537.       (save-excursion
  538.     (forward-sexp -1)
  539.     (skip-chars-forward "'")
  540.     (let ((obj (read (current-buffer))))
  541.       (and (symbolp obj) obj)))
  542.     (error nil)))
  543.  
  544.  
  545. ;;; Documentation functions: fn and var doc, arglist, and symbol describe.
  546. ;;; ======================================================================
  547.  
  548. (defun lisp-show-function-documentation (fn)
  549.   "Send a command to the inferior Lisp to give documentation for function FN.
  550. See variable `lisp-function-doc-command'."
  551.   (interactive (lisp-symprompt "Function doc" (lisp-fn-called-at-pt)))
  552.   (comint-proc-query (inferior-lisp-proc)
  553.              (format lisp-function-doc-command fn)))
  554.  
  555. (defun lisp-show-variable-documentation (var)
  556.   "Send a command to the inferior Lisp to give documentation for function FN.
  557. See variable `lisp-var-doc-command'."
  558.   (interactive (lisp-symprompt "Variable doc" (lisp-var-at-pt)))
  559.   (comint-proc-query (inferior-lisp-proc) (format lisp-var-doc-command var)))
  560.  
  561. (defun lisp-show-arglist (fn)
  562.   "Send a query to the inferior Lisp for the arglist for function FN.
  563. See variable `lisp-arglist-command'."
  564.   (interactive (lisp-symprompt "Arglist" (lisp-fn-called-at-pt)))
  565.   (comint-proc-query (inferior-lisp-proc) (format lisp-arglist-command fn)))
  566.  
  567. (defun lisp-describe-sym (sym)
  568.   "Send a command to the inferior Lisp to describe symbol SYM.
  569. See variable `lisp-describe-sym-command'."
  570.   (interactive (lisp-symprompt "Describe" (lisp-var-at-pt)))
  571.   (comint-proc-query (inferior-lisp-proc)
  572.              (format lisp-describe-sym-command sym)))
  573.  
  574.  
  575. ;;  "Returns the current inferior Lisp process.
  576. ;; See variable `inferior-lisp-buffer'."
  577. (defun inferior-lisp-proc ()
  578.   (let ((proc (get-buffer-process (if (eq major-mode 'inferior-lisp-mode)
  579.                       (current-buffer)
  580.                     inferior-lisp-buffer))))
  581.     (or proc
  582.     (error "No current process. See variable inferior-lisp-buffer"))))
  583.  
  584.  
  585. ;;; Do the user's customization...
  586. ;;;===============================
  587. (defvar inferior-lisp-load-hook nil
  588.   "This hook is run when the library `inf-lisp' is loaded.
  589. This is a good place to put keybindings.")
  590.  
  591. (run-hooks 'inferior-lisp-load-hook)
  592.  
  593. ;;; CHANGE LOG
  594. ;;; ===========================================================================
  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.
  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.
  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.
  636.  
  637. (provide 'inf-lisp)
  638.  
  639. ;;; inf-lisp.el ends here
  640.