annotate lisp/ielm.el @ 106377:10ceddf3698e

(try-expand-dabbrev-visible): Preserve point in the buffers visited. Remove redundant current-buffer-saving.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 03 Dec 2009 01:33:56 +0000
parents 0ad1fc06bfc8
children 806e9f7990d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; ielm.el --- interaction mode for Emacs Lisp
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14040
diff changeset
2
74442
b2e5081b9320 Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68651
diff changeset
3 ;; Copyright (C) 1994, 2001, 2002, 2003, 2004, 2005,
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 99630
diff changeset
4 ;; 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Author: David Smith <maa036@lancaster.ac.uk>
17976
852464ce5d6a Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 17649
diff changeset
7 ;; Maintainer: FSF
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Created: 25 Feb 1994
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; Keywords: lisp
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
16 ;; (at your option) any later version.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
28 ;; Provides a nice interface to evaluating Emacs Lisp expressions.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; Input is handled by the comint package, and output is passed
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; through the pretty-printer.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; To start: M-x ielm. Type C-h m in the *ielm* buffer for more info.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;; Code:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 (require 'comint)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 (require 'pp)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;; User variables
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
41 (defgroup ielm nil
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
42 "Interaction mode for Emacs Lisp."
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
43 :group 'lisp)
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
44
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
45
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
46 (defcustom ielm-noisy t
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
47 "If non-nil, IELM will beep on error."
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
48 :type 'boolean
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
49 :group 'ielm)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50
55121
06d6dda8a91c (ielm-prompt-read-only): New user option.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55104
diff changeset
51 (defcustom ielm-prompt-read-only t
06d6dda8a91c (ielm-prompt-read-only): New user option.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55104
diff changeset
52 "If non-nil, the IELM prompt is read only.
55296
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
53 The read only region includes the newline before the prompt.
55121
06d6dda8a91c (ielm-prompt-read-only): New user option.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55104
diff changeset
54 Setting this variable does not affect existing IELM runs.
55224
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
55 This works by setting the buffer-local value of `comint-prompt-read-only'.
55296
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
56 Setting that value directly affects new prompts in the current buffer.
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
57
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
58 If this option is enabled, then the safe way to temporarily
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
59 override the read-only-ness of IELM prompts is to call
55296
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
60 `comint-kill-whole-line' or `comint-kill-region' with no
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
61 narrowing in effect. This way you will be certain that none of
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
62 the remaining prompts will be accidentally messed up. You may
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
63 wish to put something like the following in your `.emacs' file:
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
64
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
65 \(add-hook 'ielm-mode-hook
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
66 '(lambda ()
61370
116c10e516e5 (ielm-prompt-read-only): Doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 59996
diff changeset
67 (define-key ielm-map \"\\C-w\" 'comint-kill-region)
55296
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
68 (define-key ielm-map [C-S-backspace]
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
69 'comint-kill-whole-line)))
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
70
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
71 If you set `comint-prompt-read-only' to t, you might wish to use
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
72 `comint-mode-hook' and `comint-mode-map' instead of
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
73 `ielm-mode-hook' and `ielm-map'. That will affect all comint
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
74 buffers, including IELM buffers. If you sometimes use IELM on
55296
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
75 text-only terminals or with `emacs -nw', you might wish to use
24a3d142d101 (ielm-prompt-read-only): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55224
diff changeset
76 another binding for `comint-kill-whole-line'."
55121
06d6dda8a91c (ielm-prompt-read-only): New user option.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55104
diff changeset
77 :type 'boolean
06d6dda8a91c (ielm-prompt-read-only): New user option.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55104
diff changeset
78 :group 'ielm
59996
aac0a33f5772 Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents: 56790
diff changeset
79 :version "22.1")
55121
06d6dda8a91c (ielm-prompt-read-only): New user option.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55104
diff changeset
80
43524
ca53e91e0186 (ielm-prompt): Allow customization; make it read-only.
Juanma Barranquero <lekktu@gmail.com>
parents: 43519
diff changeset
81 (defcustom ielm-prompt "ELISP> "
55121
06d6dda8a91c (ielm-prompt-read-only): New user option.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55104
diff changeset
82 "Prompt used in IELM.
55224
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
83 Setting this variable does not affect existing IELM runs.
55144
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
84
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
85 Interrupting the IELM process with \\<ielm-map>\\[comint-interrupt-subjob],
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
86 and then restarting it using \\[ielm], makes the then current
55224
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
87 default value affect _new_ prompts. Unless the new prompt
55144
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
88 differs only in text properties from the old one, IELM will no
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
89 longer recognize the old prompts. However, executing \\[ielm]
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
90 does not update the prompt of an *ielm* buffer with a running process.
55146
1a8fe9f88f09 (ielm-prompt-read-only, ielm-prompt): Minor doc fix.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55144
diff changeset
91 For IELM buffers that are not called `*ielm*', you can execute
55144
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
92 \\[inferior-emacs-lisp-mode] in that IELM buffer to update the value,
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
93 for new prompts. This works even if the buffer has a running process."
43524
ca53e91e0186 (ielm-prompt): Allow customization; make it read-only.
Juanma Barranquero <lekktu@gmail.com>
parents: 43519
diff changeset
94 :type 'string
55121
06d6dda8a91c (ielm-prompt-read-only): New user option.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55104
diff changeset
95 :group 'ielm)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
55224
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
97 (defvar ielm-prompt-internal "ELISP> "
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
98 "Stored value of `ielm-prompt' in the current IELM buffer.
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
99 This is an internal variable used by IELM. Its purpose is to
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
100 prevent a running IELM process from being messed up when the user
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
101 customizes `ielm-prompt'.")
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
102
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
103 (defcustom ielm-dynamic-return t
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
104 "Controls whether \\<ielm-map>\\[ielm-return] has intelligent behavior in IELM.
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
105 If non-nil, \\[ielm-return] evaluates input for complete sexps, or inserts a newline
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
106 and indents for incomplete sexps. If nil, always inserts newlines."
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
107 :type 'boolean
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
108 :group 'ielm)
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
109
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
110 (defcustom ielm-dynamic-multiline-inputs t
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
111 "Force multiline inputs to start from column zero?
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
112 If non-nil, after entering the first line of an incomplete sexp, a newline
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
113 will be inserted after the prompt, moving the input to the next line.
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
114 This gives more frame width for large indented sexps, and allows functions
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
115 such as `edebug-defun' to work with such inputs."
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
116 :type 'boolean
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
117 :group 'ielm)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
119 (defcustom ielm-mode-hook nil
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
120 "Hooks to be run when IELM (`inferior-emacs-lisp-mode') is started."
52446
2683a7145ceb (ielm-mode-hook): Add :options.
Dave Love <fx@gnu.org>
parents: 52401
diff changeset
121 :options '(turn-on-eldoc-mode)
17634
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
122 :type 'hook
247c2a11843d Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents: 17148
diff changeset
123 :group 'ielm)
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
124 (defvaralias 'inferior-emacs-lisp-mode-hook 'ielm-mode-hook)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
21834
8ba41a7b6464 (*, **, ***): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents: 21795
diff changeset
126 (defvar * nil
8ba41a7b6464 (*, **, ***): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents: 21795
diff changeset
127 "Most recent value evaluated in IELM.")
8ba41a7b6464 (*, **, ***): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents: 21795
diff changeset
128
8ba41a7b6464 (*, **, ***): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents: 21795
diff changeset
129 (defvar ** nil
8ba41a7b6464 (*, **, ***): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents: 21795
diff changeset
130 "Second-most-recent value evaluated in IELM.")
8ba41a7b6464 (*, **, ***): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents: 21795
diff changeset
131
8ba41a7b6464 (*, **, ***): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents: 21795
diff changeset
132 (defvar *** nil
8ba41a7b6464 (*, **, ***): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents: 21795
diff changeset
133 "Third-most-recent value evaluated in IELM.")
32367
7c181d033dae use lisp-mode-shared-map instead of shared-lisp-mode-map
Sam Steingold <sds@gnu.org>
parents: 30644
diff changeset
134
43519
a604392198d7 (ielm-match-data): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 43509
diff changeset
135 (defvar ielm-match-data nil
a604392198d7 (ielm-match-data): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 43509
diff changeset
136 "Match data saved at the end of last command.")
a604392198d7 (ielm-match-data): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 43509
diff changeset
137
47586
86b3a5572fda (*1): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 47551
diff changeset
138 (defvar *1 nil
47529
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
139 "During IELM evaluation, most recent value evaluated in IELM.
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
140 Normally identical to `*'. However, if the working buffer is an IELM
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
141 buffer, distinct from the process buffer, then `*' gives the value in
49588
37645a051842 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49161
diff changeset
142 the working buffer, `*1' the value in the process buffer.
47529
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
143 The intended value is only accessible during IELM evaluation.")
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
144
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
145 (defvar *2 nil
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
146 "During IELM evaluation, second-most-recent value evaluated in IELM.
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
147 Normally identical to `**'. However, if the working buffer is an IELM
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
148 buffer, distinct from the process buffer, then `**' gives the value in
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
149 the working buffer, `*2' the value in the process buffer.
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
150 The intended value is only accessible during IELM evaluation.")
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
151
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
152 (defvar *3 nil
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
153 "During IELM evaluation, third-most-recent value evaluated in IELM.
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
154 Normally identical to `***'. However, if the working buffer is an IELM
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
155 buffer, distinct from the process buffer, then `***' gives the value in
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
156 the working buffer, `*3' the value in the process buffer.
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
157 The intended value is only accessible during IELM evaluation.")
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
158
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 ;;; System variables
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (defvar ielm-working-buffer nil
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
162 "Buffer in which IELM sexps will be evaluated.
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
163 This variable is buffer-local.")
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
32367
7c181d033dae use lisp-mode-shared-map instead of shared-lisp-mode-map
Sam Steingold <sds@gnu.org>
parents: 30644
diff changeset
165 (defvar ielm-header
18400
16de434b8026 (ielm-header): Delete version and RCS header.
Richard M. Stallman <rms@gnu.org>
parents: 18387
diff changeset
166 "*** Welcome to IELM *** Type (describe-mode) for help.\n"
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
167 "Message to display when IELM is started.")
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
169 (defvar ielm-map
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
170 (let ((map (make-sparse-keymap)))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
171 (define-key map "\t" 'comint-dynamic-complete)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
172 (define-key map "\C-m" 'ielm-return)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
173 (define-key map "\C-j" 'ielm-send-input)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
174 (define-key map "\e\C-x" 'eval-defun) ; for consistency with
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
175 (define-key map "\e\t" 'lisp-complete-symbol) ; lisp-interaction-mode
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
176 ;; These bindings are from `lisp-mode-shared-map' -- can you inherit
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
177 ;; from more than one keymap??
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
178 (define-key map "\e\C-q" 'indent-sexp)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
179 (define-key map "\177" 'backward-delete-char-untabify)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
180 ;; Some convenience bindings for setting the working buffer
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
181 (define-key map "\C-c\C-b" 'ielm-change-working-buffer)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
182 (define-key map "\C-c\C-f" 'ielm-display-working-buffer)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
183 (define-key map "\C-c\C-v" 'ielm-print-working-buffer)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
184 map)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
185 "Keymap for IELM mode.")
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
186 (defvaralias 'inferior-emacs-lisp-mode-map 'ielm-map)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
12439
6141f81a80e5 (ielm-font-lock-keywords): New variable
Richard M. Stallman <rms@gnu.org>
parents: 10981
diff changeset
188 (defvar ielm-font-lock-keywords
55224
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
189 '(("\\(^\\*\\*\\*[^*]+\\*\\*\\*\\)\\(.*$\\)"
20953
f3f9df46d008 Changed font-lock-reference-face to font-lock-constant-face.
Simon Marshall <simon@gnu.org>
parents: 18400
diff changeset
190 (1 font-lock-comment-face)
f3f9df46d008 Changed font-lock-reference-face to font-lock-constant-face.
Simon Marshall <simon@gnu.org>
parents: 18400
diff changeset
191 (2 font-lock-constant-face)))
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
192 "Additional expressions to highlight in IELM buffers.")
32367
7c181d033dae use lisp-mode-shared-map instead of shared-lisp-mode-map
Sam Steingold <sds@gnu.org>
parents: 30644
diff changeset
193
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ;;; Completion stuff
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (defun ielm-tab nil
56790
80dba6d2451b (ielm-tab, ielm-complete-symbol): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 55296
diff changeset
197 "Possibly indent the current line as Lisp code."
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (interactive)
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
199 (when (or (eq (preceding-char) ?\n)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
200 (eq (char-syntax (preceding-char)) ?\s))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
201 (ielm-indent-line)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
202 t))
32367
7c181d033dae use lisp-mode-shared-map instead of shared-lisp-mode-map
Sam Steingold <sds@gnu.org>
parents: 30644
diff changeset
203
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (defun ielm-complete-symbol nil
56790
80dba6d2451b (ielm-tab, ielm-complete-symbol): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 55296
diff changeset
205 "Complete the Lisp symbol before point."
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
206 ;; A wrapper for lisp-complete symbol that returns non-nil if
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
207 ;; completion has occurred
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (let* ((btick (buffer-modified-tick))
7842
50676390b162 (ielm-complete-symbol): Likewise.
Richard M. Stallman <rms@gnu.org>
parents: 7275
diff changeset
209 (cbuffer (get-buffer "*Completions*"))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (ctick (and cbuffer (buffer-modified-tick cbuffer))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (lisp-complete-symbol)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 ;; completion has occurred if:
32367
7c181d033dae use lisp-mode-shared-map instead of shared-lisp-mode-map
Sam Steingold <sds@gnu.org>
parents: 30644
diff changeset
213 (or
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 ;; the buffer has been modified
32367
7c181d033dae use lisp-mode-shared-map instead of shared-lisp-mode-map
Sam Steingold <sds@gnu.org>
parents: 30644
diff changeset
215 (not (= btick (buffer-modified-tick)))
14040
187735b53d52 Comment fixes.
Karl Heuer <kwzh@gnu.org>
parents: 12439
diff changeset
216 ;; a completions buffer has been modified or created
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (if cbuffer
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (not (= ctick (buffer-modified-tick cbuffer)))
7842
50676390b162 (ielm-complete-symbol): Likewise.
Richard M. Stallman <rms@gnu.org>
parents: 7275
diff changeset
219 (get-buffer "*Completions*")))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (defun ielm-complete-filename nil
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
222 "Dynamically complete filename before point, if in a string."
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
223 (when (nth 3 (parse-partial-sexp comint-last-input-start (point)))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
224 (comint-dynamic-complete-filename)))
32367
7c181d033dae use lisp-mode-shared-map instead of shared-lisp-mode-map
Sam Steingold <sds@gnu.org>
parents: 30644
diff changeset
225
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (defun ielm-indent-line nil
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
227 "Indent the current line as Lisp code if it is not a prompt line."
30644
ce7385745191 (ielm-indent-line): Detect a "prompt" line by seeing if comint-bol
Miles Bader <miles@gnu.org>
parents: 21834
diff changeset
228 (when (save-excursion (comint-bol) (bolp))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (lisp-indent-line)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
231 ;;; Working buffer manipulation
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
232
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
233 (defun ielm-print-working-buffer nil
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
234 "Print the current IELM working buffer's name in the echo area."
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
235 (interactive)
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
236 (message "The current working buffer is: %s" (buffer-name ielm-working-buffer)))
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
237
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
238 (defun ielm-display-working-buffer nil
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
239 "Display the current IELM working buffer.
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
240 Don't forget that selecting that buffer will change its value of `point'
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
241 to its value of `window-point'!"
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
242 (interactive)
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
243 (display-buffer ielm-working-buffer)
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
244 (ielm-print-working-buffer))
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
245
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
246 (defun ielm-change-working-buffer (buf)
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
247 "Change the current IELM working buffer to BUF.
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
248 This is the buffer in which all sexps entered at the IELM prompt are
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
249 evaluated. You can achieve the same effect with a call to
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
250 `set-buffer' at the IELM prompt."
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
251 (interactive "bSet working buffer to: ")
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
252 (let ((buffer (get-buffer buf)))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
253 (if (and buffer (buffer-live-p buffer))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
254 (setq ielm-working-buffer buffer)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
255 (error "No such buffer: %S" buf)))
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
256 (ielm-print-working-buffer))
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
257
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 ;;; Other bindings
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (defun ielm-return nil
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
261 "Newline and indent, or evaluate the sexp before the prompt.
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
262 Complete sexps are evaluated; for incomplete sexps inserts a newline
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
263 and indents. If however `ielm-dynamic-return' is nil, this always
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
264 simply inserts a newline."
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (interactive)
32367
7c181d033dae use lisp-mode-shared-map instead of shared-lisp-mode-map
Sam Steingold <sds@gnu.org>
parents: 30644
diff changeset
266 (if ielm-dynamic-return
7c181d033dae use lisp-mode-shared-map instead of shared-lisp-mode-map
Sam Steingold <sds@gnu.org>
parents: 30644
diff changeset
267 (let ((state
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (save-excursion
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (end-of-line)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (parse-partial-sexp (ielm-pm)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (point)))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (if (and (< (car state) 1) (not (nth 3 state)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (ielm-send-input)
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
274 (when (and ielm-dynamic-multiline-inputs
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
275 (save-excursion
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
276 (beginning-of-line)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
277 (looking-at-p comint-prompt-regexp)))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
278 (save-excursion
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
279 (goto-char (ielm-pm))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
280 (newline 1)))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (newline-and-indent)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (newline)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283
17978
1471676365ac (ielm-input): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
284 (defvar ielm-input)
1471676365ac (ielm-input): New defvar.
Richard M. Stallman <rms@gnu.org>
parents: 17976
diff changeset
285
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (defun ielm-input-sender (proc input)
32367
7c181d033dae use lisp-mode-shared-map instead of shared-lisp-mode-map
Sam Steingold <sds@gnu.org>
parents: 30644
diff changeset
287 ;; Just sets the variable ielm-input, which is in the scope of
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
288 ;; `ielm-send-input's call.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (setq ielm-input input))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (defun ielm-send-input nil
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
292 "Evaluate the Emacs Lisp expression after the prompt."
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (interactive)
55224
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
294 (let (ielm-input) ; set by ielm-input-sender
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (comint-send-input) ; update history, markers etc.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (ielm-eval-input ielm-input)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 ;;; Utility functions
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299
91851
59ebf26b96e4 2008-02-15 Lawrence Mitchell <wence@gmx.li> (tiny change)
Bastien Guerry <bzg@altern.org>
parents: 87649
diff changeset
300 (defun ielm-is-whitespace-or-comment (string)
91877
66415e9a068a * ielm.el (ielm-is-whitespace-or-comment): Docstring fix.
Bastien Guerry <bzg@altern.org>
parents: 91851
diff changeset
301 "Return non-nil if STRING is all whitespace or a comment."
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
302 (or (string= string "")
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
303 (string-match-p "\\`[ \t\n]*\\(?:;.*\\)*\\'" string)))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 ;;; Evaluation
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
307 (defun ielm-eval-input (ielm-string)
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
308 "Evaluate the Lisp expression IELM-STRING, and pretty-print the result."
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 ;; This is the function that actually `sends' the input to the
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
310 ;; `inferior Lisp process'. All comint-send-input does is works out
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 ;; what that input is. What this function does is evaluates that
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 ;; input and produces `output' which gets inserted into the buffer,
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ;; along with a new prompt. A better way of doing this might have
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 ;; been to actually send the output to the `cat' process, and write
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 ;; this as in output filter that converted sexps in the output
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 ;; stream to their evaluated value. But that would have involved
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 ;; more process coordination than I was happy to deal with.
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
318 ;;
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
319 ;; NOTE: all temporary variables in this function will be in scope
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
320 ;; during the eval, and so need to have non-clashing names.
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
321 (let (ielm-form ; form to evaluate
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
322 ielm-pos ; End posn of parse in string
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
323 ielm-result ; Result, or error message
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
324 ielm-error-type ; string, nil if no error
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
325 (ielm-output "") ; result to display
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
326 (ielm-wbuf ielm-working-buffer) ; current buffer after evaluation
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
327 (ielm-pmark (ielm-pm)))
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
328 (unless (ielm-is-whitespace-or-comment ielm-string)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
329 (condition-case err
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
330 (let ((rout (read-from-string ielm-string)))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
331 (setq ielm-form (car rout)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
332 ielm-pos (cdr rout)))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
333 (error (setq ielm-result (error-message-string err))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
334 (setq ielm-error-type "Read error")))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
335 (unless ielm-error-type
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
336 ;; Make sure working buffer has not been killed
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
337 (if (not (buffer-name ielm-working-buffer))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
338 (setq ielm-result "Working buffer has been killed"
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
339 ielm-error-type "IELM Error"
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
340 ielm-wbuf (current-buffer))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
341 (if (ielm-is-whitespace-or-comment (substring ielm-string ielm-pos))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
342 ;; To correctly handle the ielm-local variables *,
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
343 ;; ** and ***, we need a temporary buffer to be
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
344 ;; current at entry to the inner of the next two let
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
345 ;; forms. We need another temporary buffer to exit
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
346 ;; that same let. To avoid problems, neither of
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
347 ;; these buffers should be alive during the
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
348 ;; evaluation of ielm-form.
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
349 (let ((*1 *)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
350 (*2 **)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
351 (*3 ***)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
352 ielm-temp-buffer)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
353 (set-match-data ielm-match-data)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
354 (save-excursion
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
355 (with-temp-buffer
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
356 (condition-case err
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
357 (unwind-protect
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
358 ;; The next let form creates default
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
359 ;; bindings for *, ** and ***. But
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
360 ;; these default bindings are
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
361 ;; identical to the ielm-local
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
362 ;; bindings. Hence, during the
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
363 ;; evaluation of ielm-form, the
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
364 ;; ielm-local values are going to be
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
365 ;; used in all buffers except for
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
366 ;; other ielm buffers, which override
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
367 ;; them. Normally, the variables *1,
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
368 ;; *2 and *3 also have default
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
369 ;; bindings, which are not overridden.
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
370 (let ((* *1)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
371 (** *2)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
372 (*** *3))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
373 (kill-buffer (current-buffer))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
374 (set-buffer ielm-wbuf)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
375 (setq ielm-result (eval ielm-form))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
376 (setq ielm-wbuf (current-buffer))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
377 (setq
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
378 ielm-temp-buffer
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
379 (generate-new-buffer " *ielm-temp*"))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
380 (set-buffer ielm-temp-buffer))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
381 (when ielm-temp-buffer
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
382 (kill-buffer ielm-temp-buffer)))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
383 (error (setq ielm-result (error-message-string err))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
384 (setq ielm-error-type "Eval error"))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
385 (quit (setq ielm-result "Quit during evaluation")
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
386 (setq ielm-error-type "Eval error")))))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
387 (setq ielm-match-data (match-data)))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
388 (setq ielm-error-type "IELM error")
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
389 (setq ielm-result "More than one sexp in input"))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
391 ;; If the eval changed the current buffer, mention it here
99630
c69e966c8062 (ielm-eval-input): Fix thinko in last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 99594
diff changeset
392 (unless (eq ielm-wbuf ielm-working-buffer)
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
393 (message "current buffer is now: %s" ielm-wbuf)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
394 (setq ielm-working-buffer ielm-wbuf))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
396 (goto-char ielm-pmark)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
397 (unless ielm-error-type
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
398 (condition-case err
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
399 ;; Self-referential objects cause loops in the printer, so
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
400 ;; trap quits here. May as well do errors, too
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
401 (setq ielm-output (concat ielm-output (pp-to-string ielm-result)))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
402 (error (setq ielm-error-type "IELM Error")
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
403 (setq ielm-result "Error during pretty-printing (bug in pp)"))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
404 (quit (setq ielm-error-type "IELM Error")
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
405 (setq ielm-result "Quit during pretty-printing"))))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
406 (if ielm-error-type
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
407 (progn
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
408 (when ielm-noisy (ding))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
409 (setq ielm-output (concat ielm-output "*** " ielm-error-type " *** "))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
410 (setq ielm-output (concat ielm-output ielm-result)))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
411 ;; There was no error, so shift the *** values
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
412 (setq *** **)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
413 (setq ** *)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
414 (setq * ielm-result))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
415 (setq ielm-output (concat ielm-output "\n")))
55224
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
416 (setq ielm-output (concat ielm-output ielm-prompt-internal))
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
417 (comint-output-filter (ielm-process) ielm-output)))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 ;;; Process and marker utilities
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (defun ielm-process nil
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
422 ;; Return the current buffer's process.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (get-buffer-process (current-buffer)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (defun ielm-pm nil
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
426 ;; Return the process mark of the current buffer.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (process-mark (get-buffer-process (current-buffer))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (defun ielm-set-pm (pos)
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
430 ;; Set the process mark in the current buffer to POS.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (set-marker (process-mark (get-buffer-process (current-buffer))) pos))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 ;;; Major mode
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
435 (define-derived-mode inferior-emacs-lisp-mode comint-mode "IELM"
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
436 "Major mode for interactively evaluating Emacs Lisp expressions.
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
437 Uses the interface provided by `comint-mode' (which see).
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
438
47969
cdc87bc8e049 (inferior-emacs-lisp-mode): If hexl not found, use cat. point-min != 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47626
diff changeset
439 * \\<ielm-map>\\[ielm-send-input] evaluates the sexp following the prompt. There must be at most
cdc87bc8e049 (inferior-emacs-lisp-mode): If hexl not found, use cat. point-min != 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47626
diff changeset
440 one top level sexp per prompt.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
442 * \\[ielm-return] inserts a newline and indents, or evaluates a
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
443 complete expression (but see variable `ielm-dynamic-return').
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
444 Inputs longer than one line are moved to the line following the
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
445 prompt (but see variable `ielm-dynamic-multiline-inputs').
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
446
32367
7c181d033dae use lisp-mode-shared-map instead of shared-lisp-mode-map
Sam Steingold <sds@gnu.org>
parents: 30644
diff changeset
447 * \\[comint-dynamic-complete] completes Lisp symbols (or filenames, within strings),
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
448 or indents the line if there is nothing to complete.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
450 The current working buffer may be changed (with a call to `set-buffer',
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
451 or with \\[ielm-change-working-buffer]), and its value is preserved between successive
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
452 evaluations. In this way, expressions may be evaluated in a different
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
453 buffer than the *ielm* buffer. By default, its name is shown on the
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
454 mode line; you can always display it with \\[ielm-print-working-buffer], or the buffer itself
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
455 with \\[ielm-display-working-buffer].
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456
47529
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
457 During evaluations, the values of the variables `*', `**', and `***'
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
458 are the results of the previous, second previous and third previous
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
459 evaluations respectively. If the working buffer is another IELM
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
460 buffer, then the values in the working buffer are used. The variables
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
461 `*1', `*2' and `*3', yield the process buffer values.
9b53ca22ace7 (*1, *2, *3): New variables.
Richard M. Stallman <rms@gnu.org>
parents: 46942
diff changeset
462
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
463 Expressions evaluated by IELM are not subject to `debug-on-quit' or
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
464 `debug-on-error'.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465
63253
20e759335619 (ielm-dynamic-return, inferior-emacs-lisp-mode): Fix spellings in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62875
diff changeset
466 The behavior of IELM may be customized with the following variables:
55104
60202911eed0 (inferior-emacs-lisp-mode): Fix docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 52446
diff changeset
467 * To stop beeping on error, set `ielm-noisy' to nil.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 * If you don't like the prompt, you can change it by setting `ielm-prompt'.
55121
06d6dda8a91c (ielm-prompt-read-only): New user option.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55104
diff changeset
469 * If you do not like that the prompt is (by default) read-only, set
06d6dda8a91c (ielm-prompt-read-only): New user option.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55104
diff changeset
470 `ielm-prompt-read-only' to nil.
55104
60202911eed0 (inferior-emacs-lisp-mode): Fix docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 52446
diff changeset
471 * Set `ielm-dynamic-return' to nil for bindings like `lisp-interaction-mode'.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 * Entry to this mode runs `comint-mode-hook' and `ielm-mode-hook'
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (in that order).
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474
55104
60202911eed0 (inferior-emacs-lisp-mode): Fix docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 52446
diff changeset
475 Customized bindings may be defined in `ielm-map', which currently contains:
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 \\{ielm-map}"
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
477 :syntax-table emacs-lisp-mode-syntax-table
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
478
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (setq comint-prompt-regexp (concat "^" (regexp-quote ielm-prompt)))
61878
75267b99e585 (inferior-emacs-lisp-mode): Set paragraph-separate buffer locally to
Luc Teirlinck <teirllm@auburn.edu>
parents: 61370
diff changeset
480 (set (make-local-variable 'paragraph-separate) "\\'")
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
481 (set (make-local-variable 'paragraph-start) comint-prompt-regexp)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (setq comint-input-sender 'ielm-input-sender)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (setq comint-process-echoes nil)
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
484 (set (make-local-variable 'comint-dynamic-complete-functions)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
485 '(ielm-tab comint-replace-by-expanded-history
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
486 ielm-complete-filename ielm-complete-symbol))
55224
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
487 (set (make-local-variable 'ielm-prompt-internal) ielm-prompt)
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
488 (set (make-local-variable 'comint-prompt-read-only) ielm-prompt-read-only)
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
489 (setq comint-get-old-input 'ielm-get-old-input)
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
490 (set (make-local-variable 'comint-completion-addsuffix) '("/" . ""))
55135
0d9ec2b24429 (inferior-emacs-lisp-mode): Display working buffer on the mode line. Bind
Juanma Barranquero <lekktu@gmail.com>
parents: 55121
diff changeset
491 (setq mode-line-process '(":%s on " (:eval (buffer-name ielm-working-buffer))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
493 (set (make-local-variable 'indent-line-function) 'ielm-indent-line)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
494 (set (make-local-variable 'ielm-working-buffer) (current-buffer))
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
495 (set (make-local-variable 'fill-paragraph-function) 'lisp-fill-paragraph)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
497 ;; Value holders
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
498 (set (make-local-variable '*) nil)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
499 (set (make-local-variable '**) nil)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
500 (set (make-local-variable '***) nil)
43519
a604392198d7 (ielm-match-data): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 43509
diff changeset
501 (set (make-local-variable 'ielm-match-data) nil)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502
12439
6141f81a80e5 (ielm-font-lock-keywords): New variable
Richard M. Stallman <rms@gnu.org>
parents: 10981
diff changeset
503 ;; font-lock support
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
504 (set (make-local-variable 'font-lock-defaults)
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
505 '(ielm-font-lock-keywords nil nil ((?: . "w") (?- . "w") (?* . "w"))))
32367
7c181d033dae use lisp-mode-shared-map instead of shared-lisp-mode-map
Sam Steingold <sds@gnu.org>
parents: 30644
diff changeset
506
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 ;; A dummy process to keep comint happy. It will never get any input
46942
15fab402303e [original idea from Luc Teirlinck <teirllm@mail.auburn.edu>]
Miles Bader <miles@gnu.org>
parents: 45833
diff changeset
508 (unless (comint-check-proc (current-buffer))
43509
d4b9f0aaf4f7 (inferior-emacs-lisp-mode): Use hexl for the dummy process.
Jason Rumney <jasonr@gnu.org>
parents: 32367
diff changeset
509 ;; Was cat, but on non-Unix platforms that might not exist, so
d4b9f0aaf4f7 (inferior-emacs-lisp-mode): Use hexl for the dummy process.
Jason Rumney <jasonr@gnu.org>
parents: 32367
diff changeset
510 ;; use hexl instead, which is part of the Emacs distribution.
47969
cdc87bc8e049 (inferior-emacs-lisp-mode): If hexl not found, use cat. point-min != 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47626
diff changeset
511 (condition-case nil
cdc87bc8e049 (inferior-emacs-lisp-mode): If hexl not found, use cat. point-min != 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47626
diff changeset
512 (start-process "ielm" (current-buffer) "hexl")
cdc87bc8e049 (inferior-emacs-lisp-mode): If hexl not found, use cat. point-min != 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 47626
diff changeset
513 (file-error (start-process "ielm" (current-buffer) "cat")))
56790
80dba6d2451b (ielm-tab, ielm-complete-symbol): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents: 55296
diff changeset
514 (set-process-query-on-exit-flag (ielm-process) nil)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (goto-char (point-max))
49588
37645a051842 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 49161
diff changeset
516
46942
15fab402303e [original idea from Luc Teirlinck <teirllm@mail.auburn.edu>]
Miles Bader <miles@gnu.org>
parents: 45833
diff changeset
517 ;; Lisp output can include raw characters that confuse comint's
15fab402303e [original idea from Luc Teirlinck <teirllm@mail.auburn.edu>]
Miles Bader <miles@gnu.org>
parents: 45833
diff changeset
518 ;; carriage control code.
15fab402303e [original idea from Luc Teirlinck <teirllm@mail.auburn.edu>]
Miles Bader <miles@gnu.org>
parents: 45833
diff changeset
519 (set (make-local-variable 'comint-inhibit-carriage-motion) t)
15fab402303e [original idea from Luc Teirlinck <teirllm@mail.auburn.edu>]
Miles Bader <miles@gnu.org>
parents: 45833
diff changeset
520
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 ;; Add a silly header
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 (insert ielm-header)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (ielm-set-pm (point-max))
61878
75267b99e585 (inferior-emacs-lisp-mode): Set paragraph-separate buffer locally to
Luc Teirlinck <teirllm@auburn.edu>
parents: 61370
diff changeset
524 (unless comint-use-prompt-regexp
55135
0d9ec2b24429 (inferior-emacs-lisp-mode): Display working buffer on the mode line. Bind
Juanma Barranquero <lekktu@gmail.com>
parents: 55121
diff changeset
525 (let ((inhibit-read-only t))
0d9ec2b24429 (inferior-emacs-lisp-mode): Display working buffer on the mode line. Bind
Juanma Barranquero <lekktu@gmail.com>
parents: 55121
diff changeset
526 (add-text-properties
0d9ec2b24429 (inferior-emacs-lisp-mode): Display working buffer on the mode line. Bind
Juanma Barranquero <lekktu@gmail.com>
parents: 55121
diff changeset
527 (point-min) (point-max)
0d9ec2b24429 (inferior-emacs-lisp-mode): Display working buffer on the mode line. Bind
Juanma Barranquero <lekktu@gmail.com>
parents: 55121
diff changeset
528 '(rear-nonsticky t field output inhibit-line-move-field-capture t))))
55224
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
529 (comint-output-filter (ielm-process) ielm-prompt-internal)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (set-marker comint-last-input-start (ielm-pm))
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
531 (set-process-filter (get-buffer-process (current-buffer)) 'comint-output-filter)))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
533 (defun ielm-get-old-input nil
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
534 ;; Return the previous input surrounding point
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
535 (save-excursion
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
536 (beginning-of-line)
99594
f7610a7d319c * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
Juanma Barranquero <lekktu@gmail.com>
parents: 94678
diff changeset
537 (unless (looking-at-p comint-prompt-regexp)
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
538 (re-search-backward comint-prompt-regexp))
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
539 (comint-skip-prompt)
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
540 (buffer-substring (point) (progn (forward-sexp 1) (point)))))
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
541
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 ;;; User command
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543
105798
0ad1fc06bfc8 * puresize.h (BASE_PURESIZE): Increase to 1470000.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 100908
diff changeset
544 ;;;###autoload (add-hook 'same-window-buffer-names (purecopy "*ielm*"))
10981
54697b892d3a (ielm): Use pop-to-buffer.
Richard M. Stallman <rms@gnu.org>
parents: 7842
diff changeset
545
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
546 ;;;###autoload
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (defun ielm nil
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
548 "Interactively evaluate Emacs Lisp expressions.
10981
54697b892d3a (ielm): Use pop-to-buffer.
Richard M. Stallman <rms@gnu.org>
parents: 7842
diff changeset
549 Switches to the buffer `*ielm*', or creates it if it does not exist."
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (interactive)
55144
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
551 (let (old-point)
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
552 (unless (comint-check-proc "*ielm*")
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
553 (with-current-buffer (get-buffer-create "*ielm*")
55224
649d109f3222 (ielm-prompt-read-only, ielm-prompt): Update docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55146
diff changeset
554 (unless (zerop (buffer-size)) (setq old-point (point)))
55144
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
555 (inferior-emacs-lisp-mode)))
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
556 (pop-to-buffer "*ielm*")
ab3d5c605cad (ielm-prompt-read-only, ielm-prompt): Expand docstring.
Luc Teirlinck <teirllm@auburn.edu>
parents: 55135
diff changeset
557 (when old-point (push-mark old-point))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558
18383
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 17978
diff changeset
559 (provide 'ielm)
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 17978
diff changeset
560
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 91877
diff changeset
561 ;; arch-tag: ef60e4c0-9c4f-4bdb-8402-271313329790
7275
cd1541f4c87c (ielm-dynamic-multiline-inputs): New variable.
Richard M. Stallman <rms@gnu.org>
parents: 7267
diff changeset
562 ;;; ielm.el ends here