Replace last-command-char with last-command-event.
[bpt/emacs.git] / lisp / progmodes / inf-lisp.el
index 5bf7d1b..d3c7d99 100644 (file)
@@ -1,16 +1,17 @@
 ;;; inf-lisp.el --- an inferior-lisp mode
 
-;; Copyright (C) 1988, 1993, 1994 Free Software Foundation, Inc.
+;; Copyright (C) 1988, 1993, 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+;; Free Software Foundation, Inc.
 
 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
 ;; Keywords: processes, lisp
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; 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.
+;; the Free Software Foundation, either version 3 of the License, 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
@@ -18,9 +19,7 @@
 ;; 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, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -232,30 +231,37 @@ documentation for variable `inferior-lisp-buffer'.
 
 \\{inferior-lisp-mode-map}
 
-Customisation: Entry to this mode runs the hooks on `comint-mode-hook' and
+Customization: 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.
-    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.
-    lisp-eval-region sends the current region to the Lisp process.
-    lisp-compile-region compiles the current region.
+    `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.
+    `lisp-eval-region' sends the current region to the Lisp process.
+    `lisp-compile-region' compiles the current region.
 
     Prefixing the lisp-eval/compile-defun/region commands with
     a \\[universal-argument] causes a switch to the Lisp process buffer after sending
     the text.
 
-Commands:
-Return after the end of the process' output sends the text from the
+Commands:\\<inferior-lisp-mode-map>
+\\[comint-send-input] 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
+\\[comint-send-input] before the end of the process' output copies the sexp ending at point
     to the end of the process' output, and sends it.
-Delete converts tabs to spaces as it moves back.
-Tab indents for Lisp; with argument, shifts rest
+\\[comint-copy-old-input] copies the sexp ending at point to the end of the process' output,
+    allowing you to edit it before sending it.
+If `comint-use-prompt-regexp' is nil (the default), \\[comint-insert-input] on old input
+   copies the entire old input to the end of the process' output, allowing
+   you to edit it before sending it.  When not used on old input, or if
+   `comint-use-prompt-regexp' is non-nil, \\[comint-insert-input] behaves according to
+   its global binding.
+\\[backward-delete-char-untabify] converts tabs to spaces as it moves back.
+\\[lisp-indent-line] indents for Lisp; with argument, shifts rest
     of expression rigidly with the current line.
-C-M-q does Tab on each line starting within following expression.
+\\[indent-sexp] does \\[lisp-indent-line] on each line starting within following expression.
 Paragraphs are separated only by blank lines.  Semicolons start comments.
 If you accidentally suspend your process, use \\[comint-continue-subjob]
 to continue it."
@@ -315,16 +321,40 @@ Prefix argument means switch to the Lisp buffer afterwards."
   (comint-send-string (inferior-lisp-proc) "\n")
   (if and-go (switch-to-lisp t)))
 
-(defun lisp-eval-defun (&optional and-go)
+(defun lisp-compile-string (string)
+  "Send the string to the inferior Lisp process to be compiled and executed."
+  (comint-send-string
+   (inferior-lisp-proc)
+   (format "(funcall (compile nil (lambda () %s)))\n" string)))
+
+(defun lisp-eval-string (string)
+  "Send the string to the inferior Lisp process to be executed."
+  (comint-send-string (inferior-lisp-proc) (concat string "\n")))
+
+(defun lisp-do-defun (do-string do-region)
   "Send the current defun to the inferior Lisp process.
-Prefix argument means switch to the Lisp buffer afterwards."
-  (interactive "P")
+The actually processing is done by `do-string' and `do-region'
+ which determine whether the code is compiled before evaluation.
+DEFVAR forms reset the variables to the init values."
   (save-excursion
     (end-of-defun)
     (skip-chars-backward " \t\n\r\f") ;  Makes allegro happy
-    (let ((end (point)))
+    (let ((end (point)) (case-fold-search t))
       (beginning-of-defun)
-      (lisp-eval-region (point) end)))
+      (if (looking-at "(defvar")
+          (funcall do-string
+                   ;; replace `defvar' with `defparameter'
+                   (concat "(defparameter "
+                           (buffer-substring-no-properties (+ (point) 7) end)
+                           "\n"))
+        (funcall do-region (point) end)))))
+
+(defun lisp-eval-defun (&optional and-go)
+  "Send the current defun to the inferior Lisp process.
+DEFVAR forms reset the variables to the init values.
+Prefix argument means switch to the Lisp buffer afterwards."
+  (interactive "P")
+  (lisp-do-defun 'lisp-eval-string 'lisp-eval-region)
   (if and-go (switch-to-lisp t)))
 
 (defun lisp-eval-last-sexp (&optional and-go)
@@ -333,27 +363,19 @@ 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.
 (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."
   (interactive "r\nP")
-  (comint-send-string
-   (inferior-lisp-proc)
-   (format "(funcall (compile nil `(lambda () (progn 'compile %s))))\n"
-          (buffer-substring start end)))
+  (lisp-compile-string (buffer-substring-no-properties start end))
   (if and-go (switch-to-lisp t)))
 
 (defun lisp-compile-defun (&optional and-go)
   "Compile the current defun in the inferior Lisp process.
+DEFVAR forms reset the variables to the init values.
 Prefix argument means switch to the Lisp buffer afterwards."
   (interactive "P")
-  (save-excursion
-    (end-of-defun)
-    (skip-chars-backward " \t\n\r\f") ;  Makes allegro happy
-    (let ((e (point)))
-      (beginning-of-defun)
-      (lisp-compile-region (point) e)))
+  (lisp-do-defun 'lisp-compile-string 'lisp-compile-region)
   (if and-go (switch-to-lisp t)))
 
 (defun switch-to-lisp (eob-p)
@@ -640,5 +662,5 @@ See variable `lisp-describe-sym-command'."
 
 (provide 'inf-lisp)
 
-;;; arch-tag: 5b74abc3-a085-4b91-8ab8-8da6899d3b92
+;; arch-tag: 5b74abc3-a085-4b91-8ab8-8da6899d3b92
 ;;; inf-lisp.el ends here