]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/lisp-mode.el
entered into RCS
[gnu-emacs] / lisp / emacs-lisp / lisp-mode.el
index a9447376498c91fb9abb0c3d31c581e55b55b1bb..b0f823e010378bd80903f3a1bb9eb6246d273185 100644 (file)
@@ -1,11 +1,15 @@
-;; Lisp mode, and its idiosyncratic commands.
+;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands.
+
 ;; Copyright (C) 1985 Free Software Foundation, Inc.
 
+;; Maintainer: FSF
+;; Keywords: lisp, languages
+
 ;; 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 1, or (at your option)
+;; 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,
@@ -17,7 +21,6 @@
 ;; along with GNU Emacs; see the file COPYING.  If not, write to
 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-
 (defvar lisp-mode-syntax-table nil "")
 (defvar emacs-lisp-mode-syntax-table nil "")
 (defvar lisp-mode-abbrev-table nil "")
       (modify-syntax-entry ?\[ "(]  " emacs-lisp-mode-syntax-table)
       (modify-syntax-entry ?\] ")[  " emacs-lisp-mode-syntax-table)))
 
+(if (not lisp-mode-syntax-table)
+    (progn (setq lisp-mode-syntax-table
+                (copy-syntax-table emacs-lisp-mode-syntax-table))
+          (modify-syntax-entry ?\| "\"   " lisp-mode-syntax-table)
+          (modify-syntax-entry ?\[ "_   " lisp-mode-syntax-table)
+          (modify-syntax-entry ?\] "_   " lisp-mode-syntax-table)))
+
 (define-abbrev-table 'lisp-mode-abbrev-table ())
 
 (defun lisp-mode-variables (lisp-syntax)
   (cond (lisp-syntax
-         (if (not lisp-mode-syntax-table)
-             (progn (setq lisp-mode-syntax-table
-                          (copy-syntax-table emacs-lisp-mode-syntax-table))
-                    (modify-syntax-entry ?\| "\"   "
-                                         lisp-mode-syntax-table)
-                    (modify-syntax-entry ?\[ "_   "
-                                         lisp-mode-syntax-table)
-                    (modify-syntax-entry ?\] "_   "
-                                         lisp-mode-syntax-table)))
          (set-syntax-table lisp-mode-syntax-table)))
   (setq local-abbrev-table lisp-mode-abbrev-table)
   (make-local-variable 'paragraph-start)
@@ -112,6 +113,7 @@ All commands in shared-lisp-mode-map are inherited by this map.")
     ()
   (setq emacs-lisp-mode-map
        (nconc (make-sparse-keymap) shared-lisp-mode-map))
+  (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol)
   (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun))
 
 (defun emacs-lisp-mode ()
@@ -177,6 +179,7 @@ All commands in `shared-lisp-mode-map' are inherited by this map.")
   (setq lisp-interaction-mode-map
        (nconc (make-sparse-keymap) shared-lisp-mode-map))
   (define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun)
+  (define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol)
   (define-key lisp-interaction-mode-map "\n" 'eval-print-last-sexp))
 
 (defun lisp-interaction-mode ()
@@ -203,21 +206,25 @@ if that value is non-nil."
 (defun eval-print-last-sexp ()
   "Evaluate sexp before point; print value into current buffer."
   (interactive)
-  (newline)
-  (eval-last-sexp t)
-  (newline))
+  (let ((standard-output (current-buffer)))
+    (terpri)
+    (eval-last-sexp t)
+    (terpri)))
 \f
 (defun eval-last-sexp (arg)
   "Evaluate sexp before point; print value in minibuffer.
 With argument, print output into current buffer."
   (interactive "P")
-  (let ((standard-output (if arg (current-buffer) t)))
+  (let ((standard-output (if arg (current-buffer) t))
+       (opoint (point)))
     (prin1 (let ((stab (syntax-table)))
             (eval (unwind-protect
                       (save-excursion
                         (set-syntax-table emacs-lisp-mode-syntax-table)
                         (forward-sexp -1)
-                        (read (current-buffer)))
+                        (save-restriction
+                          (narrow-to-region (point-min) opoint)
+                          (read (current-buffer))))
                     (set-syntax-table stab)))))))
 
 (defun eval-defun (arg)
@@ -256,7 +263,7 @@ rigidly along with this one."
     (skip-chars-forward " \t")
     (if (looking-at "\\s<\\s<\\s<")
        ;; Don't alter indentation of a ;;; comment line.
-       nil
+       (goto-char (- (point-max) pos))
       (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<")))
          ;; Single-semicolon comment lines should be indented
          ;; as comment lines, not as code.
@@ -477,6 +484,7 @@ of the start of the containing expression."
 (put 'save-excursion 'lisp-indent-function 0)
 (put 'save-window-excursion 'lisp-indent-function 0)
 (put 'save-restriction 'lisp-indent-function 0)
+(put 'save-match-data 'lisp-indent-function 0)
 (put 'let 'lisp-indent-function 1)
 (put 'let* 'lisp-indent-function 1)
 (put 'while 'lisp-indent-function 1)
@@ -491,9 +499,11 @@ of the start of the containing expression."
 If optional arg ENDPOS is given, indent each line, stopping when
 ENDPOS is encountered."
   (interactive)
-  (let ((indent-stack (list nil)) (next-depth 0) last-depth bol
-       outer-loop-done inner-loop-done state this-indent
-       (last-point (point)))
+  (let ((indent-stack (list nil))
+       (next-depth 0)
+       (starting-point (point))
+       (last-point (point))
+       last-depth bol outer-loop-done inner-loop-done state this-indent)
     ;; Get error now if we don't have a complete sexp after point.
     (save-excursion (forward-sexp 1))
     (save-excursion
@@ -530,10 +540,12 @@ ENDPOS is encountered."
                (setcar (nthcdr 5 state) nil))
            (setq inner-loop-done t)))
        (and endpos
-            (while (<= next-depth 0)
-              (setq indent-stack (append indent-stack (list nil)))
-              (setq next-depth (1+ next-depth))
-              (setq last-depth (1+ last-depth))))
+            (<= next-depth 0)
+            (progn
+              (setq indent-stack (append indent-stack
+                                         (make-list (- next-depth) nil))
+                    last-depth (- last-depth next-depth)
+                    next-depth 0)))
        (or outer-loop-done
            (setq outer-loop-done (<= next-depth 0)))
        (if outer-loop-done
@@ -558,7 +570,7 @@ ENDPOS is encountered."
                (setq this-indent (car indent-stack))
              (let ((val (calculate-lisp-indent
                          (if (car indent-stack) (- (car indent-stack))
-                           last-point))))
+                           starting-point))))
                (if (integerp val)
                    (setcar indent-stack
                            (setq this-indent val))
@@ -613,3 +625,7 @@ means don't indent that line."
                                        (progn
                                          (forward-line 1) (point))
                                        nil nil state))))))
+
+(provide 'lisp-mode)
+
+;;; lisp-mode.el ends here