]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/inf-lisp.el
Convert consecutive FSF copyright years to ranges.
[gnu-emacs] / lisp / progmodes / inf-lisp.el
index 02d44e5501905b85306297d6d87089916a0b1cd3..5391c8d90918df95696117e3d6c65deab37f023f 100644 (file)
@@ -1,6 +1,6 @@
 ;;; inf-lisp.el --- an inferior-lisp mode
 
 ;;; inf-lisp.el --- an inferior-lisp mode
 
-;; Copyright (C) 1988, 1993, 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+;; Copyright (C) 1988, 1993-1994, 2001-2011
 ;; Free Software Foundation, Inc.
 
 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
 ;; Free Software Foundation, Inc.
 
 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
@@ -8,10 +8,10 @@
 
 ;; 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
+;; 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
 ;; 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
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
 ;; 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:
 
 
 ;;; Commentary:
 
@@ -74,7 +72,7 @@
 
 ;;;###autoload
 (defcustom inferior-lisp-filter-regexp
 
 ;;;###autoload
 (defcustom inferior-lisp-filter-regexp
-  "\\`\\s *\\(:\\(\\w\\|\\s_\\)\\)?\\s *\\'"
+  (purecopy "\\`\\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
   "*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
@@ -82,19 +80,17 @@ mode.  Default is whitespace followed by 0 or 1 single-letter colon-keyword
   :type 'regexp
   :group 'inferior-lisp)
 
   :type 'regexp
   :group 'inferior-lisp)
 
-(defvar inferior-lisp-mode-map nil)
-(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))
+(defvar inferior-lisp-mode-map
+  (let ((map (copy-keymap comint-mode-map)))
+    (set-keymap-parent map lisp-mode-shared-map)
+    (define-key map "\C-x\C-e" 'lisp-eval-last-sexp)
+    (define-key map "\C-c\C-l" 'lisp-load-file)
+    (define-key map "\C-c\C-k" 'lisp-compile-file)
+    (define-key map "\C-c\C-a" 'lisp-show-arglist)
+    (define-key map "\C-c\C-d" 'lisp-describe-sym)
+    (define-key map "\C-c\C-f" 'lisp-show-function-documentation)
+    (define-key map "\C-c\C-v" 'lisp-show-variable-documentation)
+    map))
 
 ;;; These commands augment Lisp mode, so you can process Lisp code in
 ;;; the source files.
 
 ;;; These commands augment Lisp mode, so you can process Lisp code in
 ;;; the source files.
@@ -143,13 +139,13 @@ mode.  Default is whitespace followed by 0 or 1 single-letter colon-keyword
     'lisp-show-variable-documentation))
 
 ;;;###autoload
     'lisp-show-variable-documentation))
 
 ;;;###autoload
-(defcustom inferior-lisp-program "lisp"
+(defcustom inferior-lisp-program (purecopy "lisp")
   "*Program name for invoking an inferior Lisp in Inferior Lisp mode."
   :type 'string
   :group 'inferior-lisp)
 
 ;;;###autoload
   "*Program name for invoking an inferior Lisp in Inferior Lisp mode."
   :type 'string
   :group 'inferior-lisp)
 
 ;;;###autoload
-(defcustom inferior-lisp-load-command "(load \"%s\")\n"
+(defcustom inferior-lisp-load-command (purecopy "(load \"%s\")\n")
   "*Format-string for building a Lisp expression to load a file.
 This format string should use `%s' to substitute a file name
 and should result in a Lisp expression that will command the inferior Lisp
   "*Format-string for building a Lisp expression to load a file.
 This format string should use `%s' to substitute a file name
 and should result in a Lisp expression that will command the inferior Lisp
@@ -161,7 +157,7 @@ but it works only in Common Lisp."
   :group 'inferior-lisp)
 
 ;;;###autoload
   :group 'inferior-lisp)
 
 ;;;###autoload
-(defcustom inferior-lisp-prompt "^[^> \n]*>+:? *"
+(defcustom inferior-lisp-prompt (purecopy "^[^> \n]*>+:? *")
   "Regexp to recognize prompts in the Inferior Lisp mode.
 Defaults to \"^[^> \\n]*>+:? *\", which works pretty good for Lucid, kcl,
 and franz.  This variable is used to initialize `comint-prompt-regexp' in the
   "Regexp to recognize prompts in the Inferior Lisp mode.
 Defaults to \"^[^> \\n]*>+:? *\", which works pretty good for Lucid, kcl,
 and franz.  This variable is used to initialize `comint-prompt-regexp' in the
@@ -216,11 +212,11 @@ buffer with \\[set-variable].")
 
 ;;;###autoload
 (defvar inferior-lisp-mode-hook '()
 
 ;;;###autoload
 (defvar inferior-lisp-mode-hook '()
-  "*Hook for customising Inferior Lisp mode.")
+  "*Hook for customizing Inferior Lisp mode.")
 
 (put 'inferior-lisp-mode 'mode-class 'special)
 
 
 (put 'inferior-lisp-mode 'mode-class 'special)
 
-(defun inferior-lisp-mode ()
+(define-derived-mode inferior-lisp-mode comint-mode "Inferior Lisp"
   "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
   "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
@@ -267,18 +263,11 @@ If `comint-use-prompt-regexp' is nil (the default), \\[comint-insert-input] on o
 Paragraphs are separated only by blank lines.  Semicolons start comments.
 If you accidentally suspend your process, use \\[comint-continue-subjob]
 to continue it."
 Paragraphs are separated only by blank lines.  Semicolons start comments.
 If you accidentally suspend your process, use \\[comint-continue-subjob]
 to continue it."
-  (interactive)
-  (delay-mode-hooks
-    (comint-mode))
   (setq comint-prompt-regexp inferior-lisp-prompt)
   (setq comint-prompt-regexp inferior-lisp-prompt)
-  (setq major-mode 'inferior-lisp-mode)
-  (setq mode-name "Inferior Lisp")
   (setq mode-line-process '(":%s"))
   (lisp-mode-variables t)
   (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-get-old-input (function lisp-get-old-input))
-  (setq comint-input-filter (function lisp-input-filter))
-  (run-mode-hooks 'inferior-lisp-mode-hook))
+  (setq comint-input-filter (function lisp-input-filter)))
 
 (defun lisp-get-old-input ()
   "Return a string containing the sexp ending at point."
 
 (defun lisp-get-old-input ()
   "Return a string containing the sexp ending at point."
@@ -310,7 +299,7 @@ of `inferior-lisp-program').  Runs the hooks from
        (inferior-lisp-mode)))
   (setq inferior-lisp-buffer "*inferior-lisp*")
   (pop-to-buffer "*inferior-lisp*"))
        (inferior-lisp-mode)))
   (setq inferior-lisp-buffer "*inferior-lisp*")
   (pop-to-buffer "*inferior-lisp*"))
-;;;###autoload (add-hook 'same-window-buffer-names "*inferior-lisp*")
+;;;###autoload (add-hook 'same-window-buffer-names (purecopy "*inferior-lisp*"))
 
 ;;;###autoload
 (defalias 'run-lisp 'inferior-lisp)
 
 ;;;###autoload
 (defalias 'run-lisp 'inferior-lisp)
@@ -323,16 +312,40 @@ Prefix argument means switch to the Lisp buffer afterwards."
   (comint-send-string (inferior-lisp-proc) "\n")
   (if and-go (switch-to-lisp t)))
 
   (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.
   "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
   (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)
       (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)
   (if and-go (switch-to-lisp t)))
 
 (defun lisp-eval-last-sexp (&optional and-go)
@@ -341,27 +354,19 @@ Prefix argument means switch to the Lisp buffer afterwards."
   (interactive "P")
   (lisp-eval-region (save-excursion (backward-sexp) (point)) (point) and-go))
 
   (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")
 (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.
   (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")
 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)
   (if and-go (switch-to-lisp t)))
 
 (defun switch-to-lisp (eob-p)
@@ -588,7 +593,7 @@ See variable `lisp-describe-sym-command'."
 ;;  "Returns the current inferior Lisp process.
 ;; See variable `inferior-lisp-buffer'."
 (defun inferior-lisp-proc ()
 ;;  "Returns the current inferior Lisp process.
 ;; See variable `inferior-lisp-buffer'."
 (defun inferior-lisp-proc ()
-  (let ((proc (get-buffer-process (if (eq major-mode 'inferior-lisp-mode)
+  (let ((proc (get-buffer-process (if (derived-mode-p 'inferior-lisp-mode)
                                      (current-buffer)
                                    inferior-lisp-buffer))))
     (or proc
                                      (current-buffer)
                                    inferior-lisp-buffer))))
     (or proc
@@ -648,5 +653,4 @@ See variable `lisp-describe-sym-command'."
 
 (provide 'inf-lisp)
 
 
 (provide 'inf-lisp)
 
-;;; arch-tag: 5b74abc3-a085-4b91-8ab8-8da6899d3b92
 ;;; inf-lisp.el ends here
 ;;; inf-lisp.el ends here