* lisp/emacs-lisp/lisp-mode.el (eval-defun-2): Simplify, using lexical-binding.
[bpt/emacs.git] / lisp / ielm.el
index a105730..4280a49 100644 (file)
@@ -1,6 +1,6 @@
 ;;; ielm.el --- interaction mode for Emacs Lisp
 
-;; Copyright (C) 1994, 2001-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 2001-2013 Free Software Foundation, Inc.
 
 ;; Author: David Smith <maa036@lancaster.ac.uk>
 ;; Maintainer: FSF
@@ -59,10 +59,10 @@ override the read-only-ness of IELM prompts is to call
 `comint-kill-whole-line' or `comint-kill-region' with no
 narrowing in effect.  This way you will be certain that none of
 the remaining prompts will be accidentally messed up.  You may
-wish to put something like the following in your `.emacs' file:
+wish to put something like the following in your init file:
 
 \(add-hook 'ielm-mode-hook
-         '(lambda ()
+         (lambda ()
             (define-key ielm-map \"\\C-w\" 'comint-kill-region)
             (define-key ielm-map [C-S-backspace]
               'comint-kill-whole-line)))
@@ -167,7 +167,7 @@ This variable is buffer-local.")
 
 (defvar ielm-map
   (let ((map (make-sparse-keymap)))
-    (define-key map "\t" 'comint-dynamic-complete)
+    (define-key map "\t" 'completion-at-point)
     (define-key map "\C-m" 'ielm-return)
     (define-key map "\C-j" 'ielm-send-input)
     (define-key map "\e\C-x" 'eval-defun)         ; for consistency with
@@ -184,6 +184,13 @@ This variable is buffer-local.")
   "Keymap for IELM mode.")
 (defvaralias 'inferior-emacs-lisp-mode-map 'ielm-map)
 
+(easy-menu-define ielm-menu ielm-map
+  "IELM mode menu."
+  '("IELM"
+    ["Change Working Buffer" ielm-change-working-buffer t]
+    ["Display Working Buffer" ielm-display-working-buffer t]
+    ["Print Working Buffer" ielm-print-working-buffer t]))
+
 (defvar ielm-font-lock-keywords
   '(("\\(^\\*\\*\\*[^*]+\\*\\*\\*\\)\\(.*$\\)"
      (1 font-lock-comment-face)
@@ -202,12 +209,13 @@ This variable is buffer-local.")
 
 (defun ielm-complete-symbol nil
   "Complete the Lisp symbol before point."
-  ;; A wrapper for lisp-complete symbol that returns non-nil if
+  ;; A wrapper for completion-at-point that returns non-nil if
   ;; completion has occurred
   (let* ((btick (buffer-modified-tick))
         (cbuffer (get-buffer "*Completions*"))
-        (ctick (and cbuffer (buffer-modified-tick cbuffer))))
-    (lisp-complete-symbol)
+        (ctick (and cbuffer (buffer-modified-tick cbuffer)))
+        (completion-at-point-functions '(lisp-completion-at-point)))
+    (completion-at-point)
      ;; completion has occurred if:
     (or
      ;; the buffer has been modified
@@ -282,7 +290,7 @@ simply inserts a newline."
 
 (defvar ielm-input)
 
-(defun ielm-input-sender (proc input)
+(defun ielm-input-sender (_proc input)
   ;; Just sets the variable ielm-input, which is in the scope of
   ;; `ielm-send-input's call.
   (setq ielm-input input))
@@ -303,8 +311,17 @@ simply inserts a newline."
 
 ;;; Evaluation
 
-(defun ielm-eval-input (ielm-string)
-  "Evaluate the Lisp expression IELM-STRING, and pretty-print the result."
+(defvar ielm-string)
+(defvar ielm-form)
+(defvar ielm-pos)
+(defvar ielm-result)
+(defvar ielm-error-type)
+(defvar ielm-output)
+(defvar ielm-wbuf)
+(defvar ielm-pmark)
+
+(defun ielm-eval-input (input-string)
+  "Evaluate the Lisp expression INPUT-STRING, and pretty-print the result."
   ;; This is the function that actually `sends' the input to the
   ;; `inferior Lisp process'. All comint-send-input does is works out
   ;; what that input is.  What this function does is evaluates that
@@ -317,7 +334,8 @@ simply inserts a newline."
   ;;
   ;; NOTE: all temporary variables in this function will be in scope
   ;; during the eval, and so need to have non-clashing names.
-  (let (ielm-form                      ; form to evaluate
+  (let ((ielm-string input-string)      ; input expression, as a string
+        ielm-form                      ; form to evaluate
        ielm-pos                        ; End posn of parse in string
        ielm-result                     ; Result, or error message
        ielm-error-type                 ; string, nil if no error
@@ -395,7 +413,7 @@ simply inserts a newline."
 
       (goto-char ielm-pmark)
       (unless ielm-error-type
-       (condition-case err
+       (condition-case nil
            ;; Self-referential objects cause loops in the printer, so
            ;; trap quits here. May as well do errors, too
            (setq ielm-output (concat ielm-output (pp-to-string ielm-result)))
@@ -444,7 +462,7 @@ Uses the interface provided by `comint-mode' (which see).
   Inputs longer than one line are moved to the line following the
   prompt (but see variable `ielm-dynamic-multiline-inputs').
 
-* \\[comint-dynamic-complete] completes Lisp symbols (or filenames, within strings),
+* \\[completion-at-point] completes Lisp symbols (or filenames, within strings),
   or indents the line if there is nothing to complete.
 
 The current working buffer may be changed (with a call to `set-buffer',
@@ -481,7 +499,7 @@ Customized bindings may be defined in `ielm-map', which currently contains:
   (set (make-local-variable 'paragraph-start) comint-prompt-regexp)
   (setq comint-input-sender 'ielm-input-sender)
   (setq comint-process-echoes nil)
-  (set (make-local-variable 'comint-dynamic-complete-functions)
+  (set (make-local-variable 'completion-at-point-functions)
        '(ielm-tab comint-replace-by-expanded-history
         ielm-complete-filename ielm-complete-symbol))
   (set (make-local-variable 'ielm-prompt-internal) ielm-prompt)
@@ -489,12 +507,13 @@ Customized bindings may be defined in `ielm-map', which currently contains:
   (setq comint-get-old-input 'ielm-get-old-input)
   (set (make-local-variable 'comint-completion-addsuffix) '("/" . ""))
   (setq mode-line-process '(":%s on " (:eval (buffer-name ielm-working-buffer))))
+  ;; Useful for `hs-minor-mode'.
+  (setq-local comment-start ";")
+  (setq-local comment-use-global-state t)
 
   (set (make-local-variable 'indent-line-function) 'ielm-indent-line)
   (set (make-local-variable 'ielm-working-buffer) (current-buffer))
   (set (make-local-variable 'fill-paragraph-function) 'lisp-fill-paragraph)
-  (add-hook 'completion-at-point-functions
-            'lisp-completion-at-point nil 'local)
 
   ;; Value holders
   (set (make-local-variable '*) nil)
@@ -543,8 +562,6 @@ Customized bindings may be defined in `ielm-map', which currently contains:
 
 ;;; User command
 
-;;;###autoload (add-hook 'same-window-buffer-names (purecopy "*ielm*"))
-
 ;;;###autoload
 (defun ielm nil
   "Interactively evaluate Emacs Lisp expressions.
@@ -555,7 +572,7 @@ Switches to the buffer `*ielm*', or creates it if it does not exist."
       (with-current-buffer (get-buffer-create "*ielm*")
        (unless (zerop (buffer-size)) (setq old-point (point)))
        (inferior-emacs-lisp-mode)))
-    (pop-to-buffer "*ielm*")
+    (switch-to-buffer "*ielm*")
     (when old-point (push-mark old-point))))
 
 (provide 'ielm)