aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2008-11-16 04:54:05 +0000
committerJuanma Barranquero2008-11-16 04:54:05 +0000
commit61c11870cc2f9e71e8c3608969b27afe323ce500 (patch)
tree2defa3b3a7d2581109a9a5686c1a4fe0a282857d
parent801a8da1124886daa99f04053a835ef698837bb2 (diff)
downloademacs-61c11870cc2f9e71e8c3608969b27afe323ce500.tar.gz
emacs-61c11870cc2f9e71e8c3608969b27afe323ce500.zip
* ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
(ielm-dynamic-multiline-inputs): Remove * from defcustom docstrings. (ielm-prompt-read-only, ielm-font-lock-keywords): Fix docstring typos. (ielm-map): Define within defvar. Add docstring. (ielm-tab, ielm-eval-input, ielm-get-old-input, ielm-return) (ielm-complete-filename): Use `when', `unless'. (ielm-is-whitespace-or-comment): Use `string-match-p'. (ielm-return, ielm-get-old-input): Use `looking-at-p'. (ielm-change-working-buffer): Check that the buffer is live. (inferior-emacs-lisp-mode): Define with `define-derived-mode'. Simplify. Reflow docstring. (inferior-emacs-lisp-mode-hook, inferior-emacs-lisp-mode-map): New aliases, to satisfy `define-derived-mode' expectations.
-rw-r--r--lisp/ChangeLog19
-rw-r--r--lisp/ielm.el338
2 files changed, 175 insertions, 182 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 923802156e7..f36bb2e761c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,19 @@
12008-11-16 Juanma Barranquero <lekktu@gmail.com>
2
3 * ielm.el (ielm-noisy, ielm-dynamic-return, ielm-mode-hook)
4 (ielm-dynamic-multiline-inputs): Remove * from defcustom docstrings.
5 (ielm-prompt-read-only, ielm-font-lock-keywords): Fix docstring typos.
6 (ielm-map): Define within defvar. Add docstring.
7 (ielm-tab, ielm-eval-input, ielm-get-old-input, ielm-return)
8 (ielm-complete-filename): Use `when', `unless'.
9 (ielm-is-whitespace-or-comment): Use `string-match-p'.
10 (ielm-return, ielm-get-old-input): Use `looking-at-p'.
11 (ielm-change-working-buffer): Check that the buffer is live.
12 (inferior-emacs-lisp-mode): Define with `define-derived-mode'.
13 Simplify. Reflow docstring.
14 (inferior-emacs-lisp-mode-hook, inferior-emacs-lisp-mode-map):
15 New aliases, to satisfy `define-derived-mode' expectations.
16
12008-11-15 Glenn Morris <rgm@gnu.org> 172008-11-15 Glenn Morris <rgm@gnu.org>
2 Martin Rudalics <rudalics@gmx.at> 18 Martin Rudalics <rudalics@gmx.at>
3 19
@@ -31,8 +47,7 @@
31 47
322008-11-14 Karl Fogel <kfogel@red-bean.com> 482008-11-14 Karl Fogel <kfogel@red-bean.com>
33 49
34 * files.el (file-precious-flag): Document that this flag is 50 * files.el (file-precious-flag): Document that this flag is advisory.
35 advisory.
36 51
372008-11-14 Shigeru Fukaya <shigeru.fukaya@gmail.com> 522008-11-14 Shigeru Fukaya <shigeru.fukaya@gmail.com>
38 53
diff --git a/lisp/ielm.el b/lisp/ielm.el
index d577b888147..e22b6eda8b2 100644
--- a/lisp/ielm.el
+++ b/lisp/ielm.el
@@ -44,7 +44,7 @@
44 44
45 45
46(defcustom ielm-noisy t 46(defcustom ielm-noisy t
47 "*If non-nil, IELM will beep on error." 47 "If non-nil, IELM will beep on error."
48 :type 'boolean 48 :type 'boolean
49 :group 'ielm) 49 :group 'ielm)
50 50
@@ -56,7 +56,7 @@ This works by setting the buffer-local value of `comint-prompt-read-only'.
56Setting that value directly affects new prompts in the current buffer. 56Setting that value directly affects new prompts in the current buffer.
57 57
58If this option is enabled, then the safe way to temporarily 58If this option is enabled, then the safe way to temporarily
59override the read-only-ness of ielm prompts is to call 59override the read-only-ness of IELM prompts is to call
60`comint-kill-whole-line' or `comint-kill-region' with no 60`comint-kill-whole-line' or `comint-kill-region' with no
61narrowing in effect. This way you will be certain that none of 61narrowing in effect. This way you will be certain that none of
62the remaining prompts will be accidentally messed up. You may 62the remaining prompts will be accidentally messed up. You may
@@ -71,7 +71,7 @@ wish to put something like the following in your `.emacs' file:
71If you set `comint-prompt-read-only' to t, you might wish to use 71If you set `comint-prompt-read-only' to t, you might wish to use
72`comint-mode-hook' and `comint-mode-map' instead of 72`comint-mode-hook' and `comint-mode-map' instead of
73`ielm-mode-hook' and `ielm-map'. That will affect all comint 73`ielm-mode-hook' and `ielm-map'. That will affect all comint
74buffers, including ielm buffers. If you sometimes use ielm on 74buffers, including IELM buffers. If you sometimes use IELM on
75text-only terminals or with `emacs -nw', you might wish to use 75text-only terminals or with `emacs -nw', you might wish to use
76another binding for `comint-kill-whole-line'." 76another binding for `comint-kill-whole-line'."
77 :type 'boolean 77 :type 'boolean
@@ -101,14 +101,14 @@ prevent a running IELM process from being messed up when the user
101customizes `ielm-prompt'.") 101customizes `ielm-prompt'.")
102 102
103(defcustom ielm-dynamic-return t 103(defcustom ielm-dynamic-return t
104 "*Controls whether \\<ielm-map>\\[ielm-return] has intelligent behavior in IELM. 104 "Controls whether \\<ielm-map>\\[ielm-return] has intelligent behavior in IELM.
105If non-nil, \\[ielm-return] evaluates input for complete sexps, or inserts a newline 105If non-nil, \\[ielm-return] evaluates input for complete sexps, or inserts a newline
106and indents for incomplete sexps. If nil, always inserts newlines." 106and indents for incomplete sexps. If nil, always inserts newlines."
107 :type 'boolean 107 :type 'boolean
108 :group 'ielm) 108 :group 'ielm)
109 109
110(defcustom ielm-dynamic-multiline-inputs t 110(defcustom ielm-dynamic-multiline-inputs t
111 "*Force multiline inputs to start from column zero? 111 "Force multiline inputs to start from column zero?
112If non-nil, after entering the first line of an incomplete sexp, a newline 112If non-nil, after entering the first line of an incomplete sexp, a newline
113will be inserted after the prompt, moving the input to the next line. 113will be inserted after the prompt, moving the input to the next line.
114This gives more frame width for large indented sexps, and allows functions 114This gives more frame width for large indented sexps, and allows functions
@@ -117,10 +117,11 @@ such as `edebug-defun' to work with such inputs."
117 :group 'ielm) 117 :group 'ielm)
118 118
119(defcustom ielm-mode-hook nil 119(defcustom ielm-mode-hook nil
120 "*Hooks to be run when IELM (`inferior-emacs-lisp-mode') is started." 120 "Hooks to be run when IELM (`inferior-emacs-lisp-mode') is started."
121 :options '(turn-on-eldoc-mode) 121 :options '(turn-on-eldoc-mode)
122 :type 'hook 122 :type 'hook
123 :group 'ielm) 123 :group 'ielm)
124(defvaralias 'inferior-emacs-lisp-mode-hook 'ielm-mode-hook)
124 125
125(defvar * nil 126(defvar * nil
126 "Most recent value evaluated in IELM.") 127 "Most recent value evaluated in IELM.")
@@ -165,45 +166,40 @@ This variable is buffer-local.")
165 "*** Welcome to IELM *** Type (describe-mode) for help.\n" 166 "*** Welcome to IELM *** Type (describe-mode) for help.\n"
166 "Message to display when IELM is started.") 167 "Message to display when IELM is started.")
167 168
168(defvar ielm-map nil) 169(defvar ielm-map
169(if ielm-map nil 170 (let ((map (make-sparse-keymap)))
170 (if (featurep 'xemacs) 171 (define-key map "\t" 'comint-dynamic-complete)
171 ;; Lemacs 172 (define-key map "\C-m" 'ielm-return)
172 (progn 173 (define-key map "\C-j" 'ielm-send-input)
173 (setq ielm-map (make-sparse-keymap)) 174 (define-key map "\e\C-x" 'eval-defun) ; for consistency with
174 (set-keymap-parent ielm-map comint-mode-map)) 175 (define-key map "\e\t" 'lisp-complete-symbol) ; lisp-interaction-mode
175 ;; FSF 176 ;; These bindings are from `lisp-mode-shared-map' -- can you inherit
176 (setq ielm-map (cons 'keymap comint-mode-map))) 177 ;; from more than one keymap??
177 (define-key ielm-map "\t" 'comint-dynamic-complete) 178 (define-key map "\e\C-q" 'indent-sexp)
178 (define-key ielm-map "\C-m" 'ielm-return) 179 (define-key map "\177" 'backward-delete-char-untabify)
179 (define-key ielm-map "\C-j" 'ielm-send-input) 180 ;; Some convenience bindings for setting the working buffer
180 (define-key ielm-map "\e\C-x" 'eval-defun) ; for consistency with 181 (define-key map "\C-c\C-b" 'ielm-change-working-buffer)
181 (define-key ielm-map "\e\t" 'lisp-complete-symbol) ; lisp-interaction-mode 182 (define-key map "\C-c\C-f" 'ielm-display-working-buffer)
182 ;; These bindings are from `lisp-mode-shared-map' -- can you inherit 183 (define-key map "\C-c\C-v" 'ielm-print-working-buffer)
183 ;; from more than one keymap?? 184 map)
184 (define-key ielm-map "\e\C-q" 'indent-sexp) 185 "Keymap for IELM mode.")
185 (define-key ielm-map "\177" 'backward-delete-char-untabify) 186(defvaralias 'inferior-emacs-lisp-mode-map 'ielm-map)
186 ;; Some convenience bindings for setting the working buffer
187 (define-key ielm-map "\C-c\C-b" 'ielm-change-working-buffer)
188 (define-key ielm-map "\C-c\C-f" 'ielm-display-working-buffer)
189 (define-key ielm-map "\C-c\C-v" 'ielm-print-working-buffer))
190 187
191(defvar ielm-font-lock-keywords 188(defvar ielm-font-lock-keywords
192 '(("\\(^\\*\\*\\*[^*]+\\*\\*\\*\\)\\(.*$\\)" 189 '(("\\(^\\*\\*\\*[^*]+\\*\\*\\*\\)\\(.*$\\)"
193 (1 font-lock-comment-face) 190 (1 font-lock-comment-face)
194 (2 font-lock-constant-face))) 191 (2 font-lock-constant-face)))
195 "Additional expressions to highlight in ielm buffers.") 192 "Additional expressions to highlight in IELM buffers.")
196 193
197;;; Completion stuff 194;;; Completion stuff
198 195
199(defun ielm-tab nil 196(defun ielm-tab nil
200 "Possibly indent the current line as Lisp code." 197 "Possibly indent the current line as Lisp code."
201 (interactive) 198 (interactive)
202 (if (or (eq (preceding-char) ?\n) 199 (when (or (eq (preceding-char) ?\n)
203 (eq (char-syntax (preceding-char)) ? )) 200 (eq (char-syntax (preceding-char)) ?\s))
204 (progn 201 (ielm-indent-line)
205 (ielm-indent-line) 202 t))
206 t)))
207 203
208(defun ielm-complete-symbol nil 204(defun ielm-complete-symbol nil
209 "Complete the Lisp symbol before point." 205 "Complete the Lisp symbol before point."
@@ -224,8 +220,8 @@ This variable is buffer-local.")
224 220
225(defun ielm-complete-filename nil 221(defun ielm-complete-filename nil
226 "Dynamically complete filename before point, if in a string." 222 "Dynamically complete filename before point, if in a string."
227 (if (nth 3 (parse-partial-sexp comint-last-input-start (point))) 223 (when (nth 3 (parse-partial-sexp comint-last-input-start (point)))
228 (comint-dynamic-complete-filename))) 224 (comint-dynamic-complete-filename)))
229 225
230(defun ielm-indent-line nil 226(defun ielm-indent-line nil
231 "Indent the current line as Lisp code if it is not a prompt line." 227 "Indent the current line as Lisp code if it is not a prompt line."
@@ -253,7 +249,10 @@ This is the buffer in which all sexps entered at the IELM prompt are
253evaluated. You can achieve the same effect with a call to 249evaluated. You can achieve the same effect with a call to
254`set-buffer' at the IELM prompt." 250`set-buffer' at the IELM prompt."
255 (interactive "bSet working buffer to: ") 251 (interactive "bSet working buffer to: ")
256 (setq ielm-working-buffer (or (get-buffer buf) (error "No such buffer"))) 252 (let ((buffer (get-buffer buf)))
253 (if (and buffer (buffer-live-p buffer))
254 (setq ielm-working-buffer buffer)
255 (error "No such buffer: %S" buf)))
257 (ielm-print-working-buffer)) 256 (ielm-print-working-buffer))
258 257
259;;; Other bindings 258;;; Other bindings
@@ -272,13 +271,13 @@ simply inserts a newline."
272 (point))))) 271 (point)))))
273 (if (and (< (car state) 1) (not (nth 3 state))) 272 (if (and (< (car state) 1) (not (nth 3 state)))
274 (ielm-send-input) 273 (ielm-send-input)
275 (if (and ielm-dynamic-multiline-inputs 274 (when (and ielm-dynamic-multiline-inputs
276 (save-excursion 275 (save-excursion
277 (beginning-of-line) 276 (beginning-of-line)
278 (looking-at comint-prompt-regexp))) 277 (looking-at-p comint-prompt-regexp)))
279 (save-excursion 278 (save-excursion
280 (goto-char (ielm-pm)) 279 (goto-char (ielm-pm))
281 (newline 1))) 280 (newline 1)))
282 (newline-and-indent))) 281 (newline-and-indent)))
283 (newline))) 282 (newline)))
284 283
@@ -300,8 +299,8 @@ simply inserts a newline."
300 299
301(defun ielm-is-whitespace-or-comment (string) 300(defun ielm-is-whitespace-or-comment (string)
302 "Return non-nil if STRING is all whitespace or a comment." 301 "Return non-nil if STRING is all whitespace or a comment."
303 (or (string= string "") 302 (or (string= string "")
304 (string-match "\\`[ \t\n]*\\(?:;.*\\)*\\'" string))) 303 (string-match-p "\\`[ \t\n]*\\(?:;.*\\)*\\'" string)))
305 304
306;;; Evaluation 305;;; Evaluation
307 306
@@ -323,100 +322,97 @@ simply inserts a newline."
323 ielm-pos ; End posn of parse in string 322 ielm-pos ; End posn of parse in string
324 ielm-result ; Result, or error message 323 ielm-result ; Result, or error message
325 ielm-error-type ; string, nil if no error 324 ielm-error-type ; string, nil if no error
326 (ielm-output "") ; result to display 325 (ielm-output "") ; result to display
327 (ielm-wbuf ielm-working-buffer) ; current buffer after evaluation 326 (ielm-wbuf ielm-working-buffer) ; current buffer after evaluation
328 (ielm-pmark (ielm-pm))) 327 (ielm-pmark (ielm-pm)))
329 (if (not (ielm-is-whitespace-or-comment ielm-string)) 328 (unless (ielm-is-whitespace-or-comment ielm-string)
330 (progn 329 (condition-case err
331 (condition-case err 330 (let ((rout (read-from-string ielm-string)))
332 (let (rout) 331 (setq ielm-form (car rout)
333 (setq rout (read-from-string ielm-string)) 332 ielm-pos (cdr rout)))
334 (setq ielm-form (car rout)) 333 (error (setq ielm-result (error-message-string err))
335 (setq ielm-pos (cdr rout))) 334 (setq ielm-error-type "Read error")))
336 (error (setq ielm-result (error-message-string err)) 335 (unless ielm-error-type
337 (setq ielm-error-type "Read error"))) 336 ;; Make sure working buffer has not been killed
338 (if ielm-error-type nil 337 (if (not (buffer-name ielm-working-buffer))
339 ;; Make sure working buffer has not been killed 338 (setq ielm-result "Working buffer has been killed"
340 (if (not (buffer-name ielm-working-buffer)) 339 ielm-error-type "IELM Error"
341 (setq ielm-result "Working buffer has been killed" 340 ielm-wbuf (current-buffer))
342 ielm-error-type "IELM Error" 341 (if (ielm-is-whitespace-or-comment (substring ielm-string ielm-pos))
343 ielm-wbuf (current-buffer)) 342 ;; To correctly handle the ielm-local variables *,
344 (if (ielm-is-whitespace-or-comment 343 ;; ** and ***, we need a temporary buffer to be
345 (substring ielm-string ielm-pos)) 344 ;; current at entry to the inner of the next two let
346 ;; To correctly handle the ielm-local variables *, 345 ;; forms. We need another temporary buffer to exit
347 ;; ** and ***, we need a temporary buffer to be 346 ;; that same let. To avoid problems, neither of
348 ;; current at entry to the inner of the next two let 347 ;; these buffers should be alive during the
349 ;; forms. We need another temporary buffer to exit 348 ;; evaluation of ielm-form.
350 ;; that same let. To avoid problems, neither of 349 (let ((*1 *)
351 ;; these buffers should be alive during the 350 (*2 **)
352 ;; evaluation of ielm-form. 351 (*3 ***)
353 (let ((*1 *) 352 ielm-temp-buffer)
354 (*2 **) 353 (set-match-data ielm-match-data)
355 (*3 ***) 354 (save-excursion
356 ielm-temp-buffer) 355 (with-temp-buffer
357 (set-match-data ielm-match-data) 356 (condition-case err
358 (save-excursion 357 (unwind-protect
359 (with-temp-buffer 358 ;; The next let form creates default
360 (condition-case err 359 ;; bindings for *, ** and ***. But
361 (unwind-protect 360 ;; these default bindings are
362 ;; The next let form creates default 361 ;; identical to the ielm-local
363 ;; bindings for *, ** and ***. But 362 ;; bindings. Hence, during the
364 ;; these default bindings are 363 ;; evaluation of ielm-form, the
365 ;; identical to the ielm-local 364 ;; ielm-local values are going to be
366 ;; bindings. Hence, during the 365 ;; used in all buffers except for
367 ;; evaluation of ielm-form, the 366 ;; other ielm buffers, which override
368 ;; ielm-local values are going to be 367 ;; them. Normally, the variables *1,
369 ;; used in all buffers except for 368 ;; *2 and *3 also have default
370 ;; other ielm buffers, which override 369 ;; bindings, which are not overridden.
371 ;; them. Normally, the variables *1, 370 (let ((* *1)
372 ;; *2 and *3 also have default 371 (** *2)
373 ;; bindings, which are not overridden. 372 (*** *3))
374 (let ((* *1) 373 (kill-buffer (current-buffer))
375 (** *2) 374 (set-buffer ielm-wbuf)
376 (*** *3)) 375 (setq ielm-result (eval ielm-form))
377 (kill-buffer (current-buffer)) 376 (setq ielm-wbuf (current-buffer))
378 (set-buffer ielm-wbuf) 377 (setq
379 (setq ielm-result (eval ielm-form)) 378 ielm-temp-buffer
380 (setq ielm-wbuf (current-buffer)) 379 (generate-new-buffer " *ielm-temp*"))
381 (setq 380 (set-buffer ielm-temp-buffer))
382 ielm-temp-buffer 381 (when ielm-temp-buffer
383 (generate-new-buffer " *ielm-temp*")) 382 (kill-buffer ielm-temp-buffer)))
384 (set-buffer ielm-temp-buffer)) 383 (error (setq ielm-result (error-message-string err))
385 (when ielm-temp-buffer 384 (setq ielm-error-type "Eval error"))
386 (kill-buffer ielm-temp-buffer))) 385 (quit (setq ielm-result "Quit during evaluation")
387 (error (setq ielm-result (error-message-string err)) 386 (setq ielm-error-type "Eval error")))))
388 (setq ielm-error-type "Eval error")) 387 (setq ielm-match-data (match-data)))
389 (quit (setq ielm-result "Quit during evaluation") 388 (setq ielm-error-type "IELM error")
390 (setq ielm-error-type "Eval error"))))) 389 (setq ielm-result "More than one sexp in input"))))
391 (setq ielm-match-data (match-data))) 390
392 (setq ielm-error-type "IELM error") 391 ;; If the eval changed the current buffer, mention it here
393 (setq ielm-result "More than one sexp in input")))) 392 (when (eq ielm-wbuf ielm-working-buffer)
394 393 (message "current buffer is now: %s" ielm-wbuf)
395 ;; If the eval changed the current buffer, mention it here 394 (setq ielm-working-buffer ielm-wbuf))
396 (if (eq ielm-wbuf ielm-working-buffer) nil 395
397 (message "current buffer is now: %s" ielm-wbuf) 396 (goto-char ielm-pmark)
398 (setq ielm-working-buffer ielm-wbuf)) 397 (unless ielm-error-type
399 398 (condition-case err
400 (goto-char ielm-pmark) 399 ;; Self-referential objects cause loops in the printer, so
401 (if (not ielm-error-type) 400 ;; trap quits here. May as well do errors, too
402 (condition-case err 401 (setq ielm-output (concat ielm-output (pp-to-string ielm-result)))
403 ;; Self-referential objects cause loops in the printer, so 402 (error (setq ielm-error-type "IELM Error")
404 ;; trap quits here. May as well do errors, too 403 (setq ielm-result "Error during pretty-printing (bug in pp)"))
405 (setq ielm-output (concat ielm-output (pp-to-string ielm-result))) 404 (quit (setq ielm-error-type "IELM Error")
406 (error (setq ielm-error-type "IELM Error") 405 (setq ielm-result "Quit during pretty-printing"))))
407 (setq ielm-result "Error during pretty-printing (bug in pp)")) 406 (if ielm-error-type
408 (quit (setq ielm-error-type "IELM Error") 407 (progn
409 (setq ielm-result "Quit during pretty-printing")))) 408 (when ielm-noisy (ding))
410 (if ielm-error-type 409 (setq ielm-output (concat ielm-output "*** " ielm-error-type " *** "))
411 (progn 410 (setq ielm-output (concat ielm-output ielm-result)))
412 (if ielm-noisy (ding)) 411 ;; There was no error, so shift the *** values
413 (setq ielm-output (concat ielm-output "*** " ielm-error-type " *** ")) 412 (setq *** **)
414 (setq ielm-output (concat ielm-output ielm-result))) 413 (setq ** *)
415 ;; There was no error, so shift the *** values 414 (setq * ielm-result))
416 (setq *** **) 415 (setq ielm-output (concat ielm-output "\n")))
417 (setq ** *)
418 (setq * ielm-result))
419 (setq ielm-output (concat ielm-output "\n"))))
420 (setq ielm-output (concat ielm-output ielm-prompt-internal)) 416 (setq ielm-output (concat ielm-output ielm-prompt-internal))
421 (comint-output-filter (ielm-process) ielm-output))) 417 (comint-output-filter (ielm-process) ielm-output)))
422 418
@@ -436,9 +432,7 @@ simply inserts a newline."
436 432
437;;; Major mode 433;;; Major mode
438 434
439(put 'inferior-emacs-lisp-mode 'mode-class 'special) 435(define-derived-mode inferior-emacs-lisp-mode comint-mode "IELM"
440
441(defun inferior-emacs-lisp-mode nil
442 "Major mode for interactively evaluating Emacs Lisp expressions. 436 "Major mode for interactively evaluating Emacs Lisp expressions.
443Uses the interface provided by `comint-mode' (which see). 437Uses the interface provided by `comint-mode' (which see).
444 438
@@ -453,12 +447,12 @@ Uses the interface provided by `comint-mode' (which see).
453* \\[comint-dynamic-complete] completes Lisp symbols (or filenames, within strings), 447* \\[comint-dynamic-complete] completes Lisp symbols (or filenames, within strings),
454 or indents the line if there is nothing to complete. 448 or indents the line if there is nothing to complete.
455 449
456The current working buffer may be changed (with a call to 450The current working buffer may be changed (with a call to `set-buffer',
457`set-buffer', or with \\[ielm-change-working-buffer]), and its value 451or with \\[ielm-change-working-buffer]), and its value is preserved between successive
458is preserved between successive evaluations. In this way, expressions 452evaluations. In this way, expressions may be evaluated in a different
459may be evaluated in a different buffer than the *ielm* buffer. 453buffer than the *ielm* buffer. By default, its name is shown on the
460By default, its name is shown on the mode line; you can always display 454mode line; you can always display it with \\[ielm-print-working-buffer], or the buffer itself
461it with \\[ielm-print-working-buffer], or the buffer itself with \\[ielm-display-working-buffer]. 455with \\[ielm-display-working-buffer].
462 456
463During evaluations, the values of the variables `*', `**', and `***' 457During evaluations, the values of the variables `*', `**', and `***'
464are the results of the previous, second previous and third previous 458are the results of the previous, second previous and third previous
@@ -480,49 +474,35 @@ The behavior of IELM may be customized with the following variables:
480 474
481Customized bindings may be defined in `ielm-map', which currently contains: 475Customized bindings may be defined in `ielm-map', which currently contains:
482\\{ielm-map}" 476\\{ielm-map}"
483 (interactive) 477 :syntax-table emacs-lisp-mode-syntax-table
484 (delay-mode-hooks 478
485 (comint-mode))
486 (setq comint-prompt-regexp (concat "^" (regexp-quote ielm-prompt))) 479 (setq comint-prompt-regexp (concat "^" (regexp-quote ielm-prompt)))
487 (set (make-local-variable 'paragraph-separate) "\\'") 480 (set (make-local-variable 'paragraph-separate) "\\'")
488 (make-local-variable 'paragraph-start) 481 (set (make-local-variable 'paragraph-start) comint-prompt-regexp)
489 (setq paragraph-start comint-prompt-regexp)
490 (setq comint-input-sender 'ielm-input-sender) 482 (setq comint-input-sender 'ielm-input-sender)
491 (setq comint-process-echoes nil) 483 (setq comint-process-echoes nil)
492 (make-local-variable 'comint-dynamic-complete-functions) 484 (set (make-local-variable 'comint-dynamic-complete-functions)
485 '(ielm-tab comint-replace-by-expanded-history
486 ielm-complete-filename ielm-complete-symbol))
493 (set (make-local-variable 'ielm-prompt-internal) ielm-prompt) 487 (set (make-local-variable 'ielm-prompt-internal) ielm-prompt)
494 (set (make-local-variable 'comint-prompt-read-only) ielm-prompt-read-only) 488 (set (make-local-variable 'comint-prompt-read-only) ielm-prompt-read-only)
495 (setq comint-dynamic-complete-functions
496 '(ielm-tab comint-replace-by-expanded-history ielm-complete-filename ielm-complete-symbol))
497 (setq comint-get-old-input 'ielm-get-old-input) 489 (setq comint-get-old-input 'ielm-get-old-input)
498 (make-local-variable 'comint-completion-addsuffix) 490 (set (make-local-variable 'comint-completion-addsuffix) '("/" . ""))
499 (setq comint-completion-addsuffix '("/" . ""))
500 (setq major-mode 'inferior-emacs-lisp-mode)
501 (setq mode-name "IELM")
502 (setq mode-line-process '(":%s on " (:eval (buffer-name ielm-working-buffer)))) 491 (setq mode-line-process '(":%s on " (:eval (buffer-name ielm-working-buffer))))
503 (use-local-map ielm-map)
504 (set-syntax-table emacs-lisp-mode-syntax-table)
505 492
506 (make-local-variable 'indent-line-function) 493 (set (make-local-variable 'indent-line-function) 'ielm-indent-line)
507 (make-local-variable 'ielm-working-buffer) 494 (set (make-local-variable 'ielm-working-buffer) (current-buffer))
508 (setq ielm-working-buffer (current-buffer)) 495 (set (make-local-variable 'fill-paragraph-function) 'lisp-fill-paragraph)
509 (setq indent-line-function 'ielm-indent-line)
510 (make-local-variable 'fill-paragraph-function)
511 (setq fill-paragraph-function 'lisp-fill-paragraph)
512 496
513 ;; Value holders 497 ;; Value holders
514 (make-local-variable '*) 498 (set (make-local-variable '*) nil)
515 (setq * nil) 499 (set (make-local-variable '**) nil)
516 (make-local-variable '**) 500 (set (make-local-variable '***) nil)
517 (setq ** nil)
518 (make-local-variable '***)
519 (setq *** nil)
520 (set (make-local-variable 'ielm-match-data) nil) 501 (set (make-local-variable 'ielm-match-data) nil)
521 502
522 ;; font-lock support 503 ;; font-lock support
523 (make-local-variable 'font-lock-defaults) 504 (set (make-local-variable 'font-lock-defaults)
524 (setq font-lock-defaults 505 '(ielm-font-lock-keywords nil nil ((?: . "w") (?- . "w") (?* . "w"))))
525 '(ielm-font-lock-keywords nil nil ((?: . "w") (?- . "w") (?* . "w"))))
526 506
527 ;; A dummy process to keep comint happy. It will never get any input 507 ;; A dummy process to keep comint happy. It will never get any input
528 (unless (comint-check-proc (current-buffer)) 508 (unless (comint-check-proc (current-buffer))
@@ -548,15 +528,13 @@ Customized bindings may be defined in `ielm-map', which currently contains:
548 '(rear-nonsticky t field output inhibit-line-move-field-capture t)))) 528 '(rear-nonsticky t field output inhibit-line-move-field-capture t))))
549 (comint-output-filter (ielm-process) ielm-prompt-internal) 529 (comint-output-filter (ielm-process) ielm-prompt-internal)
550 (set-marker comint-last-input-start (ielm-pm)) 530 (set-marker comint-last-input-start (ielm-pm))
551 (set-process-filter (get-buffer-process (current-buffer)) 'comint-output-filter)) 531 (set-process-filter (get-buffer-process (current-buffer)) 'comint-output-filter)))
552
553 (run-mode-hooks 'ielm-mode-hook))
554 532
555(defun ielm-get-old-input nil 533(defun ielm-get-old-input nil
556 ;; Return the previous input surrounding point 534 ;; Return the previous input surrounding point
557 (save-excursion 535 (save-excursion
558 (beginning-of-line) 536 (beginning-of-line)
559 (if (looking-at comint-prompt-regexp) nil 537 (unless (looking-at-p comint-prompt-regexp)
560 (re-search-backward comint-prompt-regexp)) 538 (re-search-backward comint-prompt-regexp))
561 (comint-skip-prompt) 539 (comint-skip-prompt)
562 (buffer-substring (point) (progn (forward-sexp 1) (point))))) 540 (buffer-substring (point) (progn (forward-sexp 1) (point)))))