]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/inf-lisp.el
Change release version from 21.4 to 22.1 throughout.
[gnu-emacs] / lisp / progmodes / inf-lisp.el
index 2f5b608f864bd7b86985d32395f9d859a035ac28..83a0c9d3e20d067edcef30911e24faca702d0ed5 100644 (file)
@@ -1,62 +1,64 @@
 ;;; inf-lisp.el --- an inferior-lisp mode
-;;; Copyright (C) 1988, 1993 Free Software Foundation, Inc.
+
+;; Copyright (C) 1988, 1993, 1994 Free Software Foundation, Inc.
 
 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
 ;; Keywords: processes, lisp
 
-;;; This file is part of GNU Emacs.
+;; This file is part of GNU Emacs.
 
-;;; GNU Emacs is free software; you can redistribute it and/or modify
-;;; it under the terms of the GNU General Public License as published by
-;;; the Free Software Foundation; either version 2, or (at your option)
-;;; any later version.
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
 
-;;; GNU Emacs is distributed in the hope that it will be useful,
-;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;;; GNU General Public License for more details.
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
 
-;;; You should have received a copy of the GNU General Public License
-;;; along with GNU Emacs; see the file COPYING.  If not, write to
-;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 
-;;; Hacked from tea.el by Olin Shivers (shivers@cs.cmu.edu). 8/88
-
-;;; This file defines a a lisp-in-a-buffer package (inferior-lisp
-;;; mode) built on top of comint mode.  This version is more
-;;; featureful, robust, and uniform than the Emacs 18 version.  The
-;;; key bindings are also more compatible with the bindings of Hemlock
-;;; and Zwei (the Lisp Machine emacs).
-
-;;; Since this mode is built on top of the general command-interpreter-in-
-;;; a-buffer mode (comint mode), it shares a common base functionality, 
-;;; and a common set of bindings, with all modes derived from comint mode.
-;;; This makes these modes easier to use.
-
-;;; For documentation on the functionality provided by comint mode, and
-;;; the hooks available for customising it, see the file comint.el.
-;;; For further information on inferior-lisp mode, see the comments below.
-
-;;; Needs fixin:
-;;; The load-file/compile-file default mechanism could be smarter -- it
-;;; doesn't know about the relationship between filename extensions and
-;;; whether the file is source or executable. If you compile foo.lisp
-;;; with compile-file, then the next load-file should use foo.bin for
-;;; the default, not foo.lisp. This is tricky to do right, particularly
-;;; because the extension for executable files varies so much (.o, .bin,
-;;; .lbin, .mo, .vo, .ao, ...).
-;;;
-;;; It would be nice if inferior-lisp (and inferior scheme, T, ...) modes
-;;; had a verbose minor mode wherein sending or compiling defuns, etc.
-;;; would be reflected in the transcript with suitable comments, e.g.
-;;; ";;; redefining fact". Several ways to do this. Which is right?
-;;;
-;;; When sending text from a source file to a subprocess, the process-mark can 
-;;; move off the window, so you can lose sight of the process interactions.
-;;; Maybe I should ensure the process mark is in the window when I send
-;;; text to the process? Switch selectable?
+;; Hacked from tea.el by Olin Shivers (shivers@cs.cmu.edu). 8/88
+
+;; This file defines a lisp-in-a-buffer package (inferior-lisp mode)
+;; built on top of comint mode.  This version is more featureful,
+;; robust, and uniform than the Emacs 18 version.  The key bindings are
+;; also more compatible with the bindings of Hemlock and Zwei (the
+;; Lisp Machine emacs).
+
+;; Since this mode is built on top of the general command-interpreter-in-
+;; a-buffer mode (comint mode), it shares a common base functionality,
+;; and a common set of bindings, with all modes derived from comint mode.
+;; This makes these modes easier to use.
+
+;; For documentation on the functionality provided by comint mode, and
+;; the hooks available for customising it, see the file comint.el.
+;; For further information on inferior-lisp mode, see the comments below.
+
+;; Needs fixin:
+;; The load-file/compile-file default mechanism could be smarter -- it
+;; doesn't know about the relationship between filename extensions and
+;; whether the file is source or executable. If you compile foo.lisp
+;; with compile-file, then the next load-file should use foo.bin for
+;; the default, not foo.lisp. This is tricky to do right, particularly
+;; because the extension for executable files varies so much (.o, .bin,
+;; .lbin, .mo, .vo, .ao, ...).
+;;
+;; It would be nice if inferior-lisp (and inferior scheme, T, ...) modes
+;; had a verbose minor mode wherein sending or compiling defuns, etc.
+;; would be reflected in the transcript with suitable comments, e.g.
+;; ";;; redefining fact". Several ways to do this. Which is right?
+;;
+;; When sending text from a source file to a subprocess, the process-mark can
+;; move off the window, so you can lose sight of the process interactions.
+;; Maybe I should ensure the process mark is in the window when I send
+;; text to the process? Switch selectable?
 
 ;;; Code:
 
 (defvar inferior-lisp-filter-regexp "\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'"
   "*What not to save on inferior Lisp's input history.
 Input matching this regexp is not saved on the input history in Inferior Lisp
-mode.  Default is whitespace followed by 0 or 1 single-letter colon-keyword 
-(as in :a, :c, etc.)")
+mode.  Default is whitespace followed by 0 or 1 single-letter colon-keyword
+\(as in :a, :c, etc.)")
 
 (defvar inferior-lisp-mode-map nil)
-(cond ((not inferior-lisp-mode-map)
-       (setq inferior-lisp-mode-map
-            (full-copy-sparse-keymap comint-mode-map))
-       (setq inferior-lisp-mode-map
-            (nconc inferior-lisp-mode-map shared-lisp-mode-map))
-       (define-key inferior-lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp)
-       (define-key inferior-lisp-mode-map "\C-c\C-l" 'lisp-load-file)
-       (define-key inferior-lisp-mode-map "\C-c\C-k" 'lisp-compile-file)
-       (define-key inferior-lisp-mode-map "\C-c\C-a" 'lisp-show-arglist)
-       (define-key inferior-lisp-mode-map "\C-c\C-d" 'lisp-describe-sym)
-       (define-key inferior-lisp-mode-map "\C-c\C-f"
-        'lisp-show-function-documentation)
-       (define-key inferior-lisp-mode-map "\C-c\C-v"
-        'lisp-show-variable-documentation)))
+(unless inferior-lisp-mode-map
+  (setq inferior-lisp-mode-map (copy-keymap comint-mode-map))
+  (set-keymap-parent inferior-lisp-mode-map lisp-mode-shared-map)
+  (define-key inferior-lisp-mode-map "\C-x\C-e" 'lisp-eval-last-sexp)
+  (define-key inferior-lisp-mode-map "\C-c\C-l" 'lisp-load-file)
+  (define-key inferior-lisp-mode-map "\C-c\C-k" 'lisp-compile-file)
+  (define-key inferior-lisp-mode-map "\C-c\C-a" 'lisp-show-arglist)
+  (define-key inferior-lisp-mode-map "\C-c\C-d" 'lisp-describe-sym)
+  (define-key inferior-lisp-mode-map "\C-c\C-f"
+    'lisp-show-function-documentation)
+  (define-key inferior-lisp-mode-map "\C-c\C-v"
+    'lisp-show-variable-documentation))
 
 ;;; These commands augment Lisp mode, so you can process Lisp code in
 ;;; the source files.
@@ -124,7 +124,7 @@ mode.  Default is whitespace followed by 0 or 1 single-letter colon-keyword
   (define-key lisp-mode-map "\C-cd" 'lisp-describe-sym)
   (define-key lisp-mode-map "\C-cf" 'lisp-show-function-documentation)
   (define-key lisp-mode-map "\C-cv" 'lisp-show-variable-documentation)
-  
+
   (define-key inferior-lisp-mode-map "\C-cl" 'lisp-load-file)
   (define-key inferior-lisp-mode-map "\C-ck" 'lisp-compile-file)
   (define-key inferior-lisp-mode-map "\C-ca" 'lisp-show-arglist)
@@ -144,20 +144,23 @@ mode.  Default is whitespace followed by 0 or 1 single-letter colon-keyword
 This format string should use `%s' to substitute a file name
 and should result in a Lisp expression that will command the inferior Lisp
 to load that file.  The default works acceptably on most Lisps.
-The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\\n\"
+The string \"(progn (load \\\"%s\\\" :verbose nil :print t) (values))\\n\"
 produces cosmetically superior output for this application,
 but it works only in Common Lisp.")
 
 ;;;###autoload
-(defvar inferior-lisp-prompt "^[^> ]*>+:? *"
+(defvar inferior-lisp-prompt "^[^> \n]*>+:? *"
   "Regexp to recognise prompts in the Inferior Lisp mode.
-Defaults to \"^[^> ]*>+:? *\", which works pretty good for Lucid, kcl,
-and franz.  This variable is used to initialize `comint-prompt-regexp' in the 
+Defaults to \"^[^> \\n]*>+:? *\", which works pretty good for Lucid, kcl,
+and franz.  This variable is used to initialize `comint-prompt-regexp' in the
 Inferior Lisp buffer.
 
+This variable is only used if the variable
+`comint-use-prompt-regexp-instead-of-fields' is non-nil.
+
 More precise choices:
-Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\"
-franz: \"^\\(->\\|<[0-9]*>:\\) *\"
+Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\"
+franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\"
 kcl: \"^>+ *\"
 
 This is a fine thing to set in your .emacs file.")
@@ -182,10 +185,10 @@ have three inferior Lisps running:
     foo                 inferior-lisp
     bar                 inferior-lisp<2>
     *inferior-lisp*     inferior-lisp<3>
-If you do a \\[lisp-eval-defun] command on some Lisp source code, 
+If you do a \\[lisp-eval-defun] command on some Lisp source code,
 what process do you send it to?
 
-- If you're in a process buffer (foo, bar, or *inferior-lisp*), 
+- If you're in a process buffer (foo, bar, or *inferior-lisp*),
   you send it to that process.
 - If you're in some other buffer (e.g., a source file), you
   send it to the process attached to buffer `inferior-lisp-buffer'.
@@ -201,8 +204,10 @@ buffer with \\[set-variable].")
 (defvar inferior-lisp-mode-hook '()
   "*Hook for customising Inferior Lisp mode.")
 
-(defun inferior-lisp-mode () 
-  "Major mode for interacting with an inferior Lisp process.  
+(put 'inferior-lisp-mode 'mode-class 'special)
+
+(defun inferior-lisp-mode ()
+  "Major mode for interacting with an inferior Lisp process.
 Runs a Lisp interpreter as a subprocess of Emacs, with Lisp I/O through an
 Emacs buffer.  Variable `inferior-lisp-program' controls which Lisp interpreter
 is run.  Variables `inferior-lisp-prompt', `inferior-lisp-filter-regexp' and
@@ -218,7 +223,7 @@ Customisation: Entry to this mode runs the hooks on `comint-mode-hook' and
 `inferior-lisp-mode-hook' (in that order).
 
 You can send text to the inferior Lisp process from other buffers containing
-Lisp source.  
+Lisp source.
     switch-to-lisp switches the current buffer to the Lisp process buffer.
     lisp-eval-defun sends the current defun to the Lisp process.
     lisp-compile-defun compiles the current defun.
@@ -230,7 +235,7 @@ Lisp source.
     the text.
 
 Commands:
-Return after the end of the process' output sends the text from the 
+Return after the end of the process' output sends the text from the
     end of process to point.
 Return before the end of the process' output copies the sexp ending at point
     to the end of the process' output, and sends it.
@@ -246,12 +251,11 @@ to continue it."
   (setq comint-prompt-regexp inferior-lisp-prompt)
   (setq major-mode 'inferior-lisp-mode)
   (setq mode-name "Inferior Lisp")
-  (setq mode-line-process '(": %s"))
+  (setq mode-line-process '(":%s"))
   (lisp-mode-variables t)
   (use-local-map inferior-lisp-mode-map)    ;c-c c-k for "kompile" file
   (setq comint-get-old-input (function lisp-get-old-input))
   (setq comint-input-filter (function lisp-input-filter))
-  (setq comint-input-sentinel 'ignore)
   (run-hooks 'inferior-lisp-mode-hook))
 
 (defun lisp-get-old-input ()
@@ -278,32 +282,17 @@ of `inferior-lisp-program').  Runs the hooks from
                         (read-string "Run lisp: " inferior-lisp-program)
                       inferior-lisp-program)))
   (if (not (comint-check-proc "*inferior-lisp*"))
-      (let ((cmdlist (inferior-lisp-args-to-list cmd)))
+      (let ((cmdlist (split-string cmd)))
        (set-buffer (apply (function make-comint)
                           "inferior-lisp" (car cmdlist) nil (cdr cmdlist)))
        (inferior-lisp-mode)))
   (setq inferior-lisp-buffer "*inferior-lisp*")
-  (switch-to-buffer "*inferior-lisp*"))
+  (pop-to-buffer "*inferior-lisp*"))
+;;;###autoload (add-hook 'same-window-buffer-names "*inferior-lisp*")
 
 ;;;###autoload
 (defalias 'run-lisp 'inferior-lisp)
 
-;;; Break a string up into a list of arguments.
-;;; This will break if you have an argument with whitespace, as in
-;;; string = "-ab +c -x 'you lose'".
-(defun inferior-lisp-args-to-list (string)
-  (let ((where (string-match "[ \t]" string)))
-    (cond ((null where) (list string))
-         ((not (= where 0))
-          (cons (substring string 0 where)
-                (inferior-lisp-args-to-list (substring string (+ 1 where)
-                                                       (length string)))))
-         (t (let ((pos (string-match "[^ \t]" string)))
-              (if (null pos)
-                  nil
-                (inferior-lisp-args-to-list (substring string pos
-                                                       (length string)))))))))
-
 (defun lisp-eval-region (start end &optional and-go)
   "Send the current region to the inferior Lisp process.
 Prefix argument means switch to the Lisp buffer afterwards."
@@ -330,7 +319,7 @@ Prefix argument means switch to the Lisp buffer afterwards."
   (interactive "P")
   (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go))
 
-;;; Common Lisp COMPILE sux. 
+;;; Common Lisp COMPILE sux.
 (defun lisp-compile-region (start end &optional and-go)
   "Compile the current region in the inferior Lisp process.
 Prefix argument means switch to the Lisp buffer afterwards."
@@ -357,12 +346,17 @@ Prefix argument means switch to the Lisp buffer afterwards."
   "Switch to the inferior Lisp process buffer.
 With argument, positions cursor at end of buffer."
   (interactive "P")
-  (if (get-buffer inferior-lisp-buffer)
-      (pop-to-buffer inferior-lisp-buffer)
-    (error "No current inferior Lisp buffer"))
-  (cond (eob-p
+  (if (get-buffer-process inferior-lisp-buffer)
+      (let ((pop-up-frames
+            ;; Be willing to use another frame
+            ;; that already has the window in it.
+            (or pop-up-frames
+                (get-buffer-window inferior-lisp-buffer t))))
+       (pop-to-buffer inferior-lisp-buffer))
+      (run-lisp inferior-lisp-program))
+  (when eob-p
         (push-mark)
-        (goto-char (point-max)))))
+    (goto-char (point-max))))
 
 
 ;;; Now that lisp-compile/eval-defun/region takes an optional prefix arg,
@@ -408,7 +402,7 @@ With argument, positions cursor at end of buffer."
 ;;;                            (buffer-substring body-start (point))))
 ;;;     (process-send-string "inferior-lisp" ")\n"))
 ;;;    (t (lisp-eval-region start end)))))
-;;; 
+;;;
 ;;; (defun lisp-compile-region (start end)
 ;;;   "Each s-expression in the current region is compiled (if a DEFUN)
 ;;; or evaluated (if not) in the inferior lisp."
@@ -424,7 +418,7 @@ With argument, positions cursor at end of buffer."
 ;;;    (setq s (point))
 ;;;    (end-of-defun))
 ;;;       (if (< s end) (lisp-compile-sexp s end)))))
-;;; 
+;;;
 ;;; End of HS-style code
 
 
@@ -442,7 +436,7 @@ Used by these commands to determine defaults.")
 (defun lisp-load-file (file-name)
   "Load a Lisp file into the inferior Lisp process."
   (interactive (comint-get-source "Load Lisp file: " lisp-prev-l/c-dir/file
-                                 lisp-source-modes nil)) ; NIL because LOAD
+                                 lisp-source-modes nil)) ; nil because LOAD
                                        ; doesn't need an exact name
   (comint-check-source file-name) ; Check to see if buffer needs saved.
   (setq lisp-prev-l/c-dir/file (cons (file-name-directory    file-name)
@@ -455,7 +449,7 @@ Used by these commands to determine defaults.")
 (defun lisp-compile-file (file-name)
   "Compile a Lisp file in the inferior Lisp process."
   (interactive (comint-get-source "Compile Lisp file: " lisp-prev-l/c-dir/file
-                                 lisp-source-modes nil)) ; NIL = don't need
+                                 lisp-source-modes nil)) ; nil = don't need
                                        ; suffix .lisp
   (comint-check-source file-name) ; Check to see if buffer needs saved.
   (setq lisp-prev-l/c-dir/file (cons (file-name-directory    file-name)
@@ -592,7 +586,7 @@ This is a good place to put keybindings.")
 ;;;   this is now the official inferior lisp package.  Use the global
 ;;;   ChangeLog from now on.
 ;;; 5/24/90 Olin
-;;; - Split cmulisp and cmushell modes into separate files. 
+;;; - Split cmulisp and cmushell modes into separate files.
 ;;;   Not only is this a good idea, it's apparently the way it'll be rel 19.
 ;;; - Upgraded process sends to use comint-send-string instead of
 ;;;   process-send-string.
@@ -616,7 +610,7 @@ This is a good place to put keybindings.")
 ;;; supposed to be reserved for the user to bind. This affected
 ;;; mainly the compile/eval-defun/region[-and-go] commands.
 ;;; This was painful, but necessary to adhere to the gnumacs standard.
-;;; For some backwards compatibility, see the 
+;;; For some backwards compatibility, see the
 ;;;     cmulisp-install-letter-bindings
 ;;; function.
 ;;;
@@ -631,4 +625,5 @@ This is a good place to put keybindings.")
 
 (provide 'inf-lisp)
 
+;;; arch-tag: 5b74abc3-a085-4b91-8ab8-8da6899d3b92
 ;;; inf-lisp.el ends here