(defvar ielm-match-data nil
"Match data saved at the end of last command.")
+(defvar ielm-*1 nil
+ "During IELM evaluation, most recent value evaluated in IELM.
+Normally identical to `*'. However, if the working buffer is an IELM
+buffer, distinct from the process buffer, then `*' gives the value in
+the working buffer, `*1' the value in the process buffer.
+The intended value is only accessible during IELM evaluation.")
+
+(defvar *2 nil
+ "During IELM evaluation, second-most-recent value evaluated in IELM.
+Normally identical to `**'. However, if the working buffer is an IELM
+buffer, distinct from the process buffer, then `**' gives the value in
+the working buffer, `*2' the value in the process buffer.
+The intended value is only accessible during IELM evaluation.")
+
+(defvar *3 nil
+ "During IELM evaluation, third-most-recent value evaluated in IELM.
+Normally identical to `***'. However, if the working buffer is an IELM
+buffer, distinct from the process buffer, then `***' gives the value in
+the working buffer, `*3' the value in the process buffer.
+The intended value is only accessible during IELM evaluation.")
+
;;; System variables
(defvar ielm-working-buffer nil
ielm-error-type "IELM Error"
ielm-wbuf (current-buffer))
(if (ielm-is-whitespace (substring ielm-string ielm-pos))
- ;; need this awful let convolution to work around
- ;; an Emacs bug involving local vbls and let binding
- (let ((*save *)
- (**save **)
- (***save ***))
+ ;; To correctly handle the ielm-local variables *,
+ ;; ** and ***, we need a temporary buffer to be
+ ;; current at entry to the inner of the next two let
+ ;; forms. We need another temporary buffer to exit
+ ;; that same let. To avoid problems, neither of
+ ;; these buffers should be alive during the
+ ;; evaluation of ielm-form.
+ (let ((*1 *)
+ (*2 **)
+ (*3 ***)
+ ielm-temp-buffer)
(set-match-data ielm-match-data)
(save-excursion
- (set-buffer ielm-working-buffer)
- (condition-case err
- (let ((* *save)
- (** **save)
- (*** ***save)
- (ielm-obuf (current-buffer)))
- (setq ielm-result (eval ielm-form))
- (setq ielm-wbuf (current-buffer))
- ;; The eval may have changed current-buffer;
- ;; need to set it back here to avoid a bug
- ;; in let. Don't want to use save-excursion
- ;; because we want to allow changes in point.
- (set-buffer ielm-obuf))
- (error (setq ielm-result (error-message-string err))
- (setq ielm-error-type "Eval error"))
- (quit (setq ielm-result "Quit during evaluation")
- (setq ielm-error-type "Eval error"))))
+ (with-temp-buffer
+ (condition-case err
+ (unwind-protect
+ ;; The next let form creates default
+ ;; bindings for *, ** and ***. But
+ ;; these default bindings are
+ ;; identical to the ielm-local
+ ;; bindings. Hence, during the
+ ;; evaluation of ielm-form, the
+ ;; ielm-local values are going to be
+ ;; used in all buffers except for
+ ;; other ielm buffers, which override
+ ;; them. Normally, the variables *1,
+ ;; *2 and *3 also have default
+ ;; bindings, which are not overridden.
+ (let ((* *1)
+ (** *2)
+ (*** *3))
+ (kill-buffer (current-buffer))
+ (set-buffer ielm-wbuf)
+ (setq ielm-result (eval ielm-form))
+ (setq ielm-wbuf (current-buffer))
+ (setq
+ ielm-temp-buffer
+ (generate-new-buffer " *ielm-temp*"))
+ (set-buffer ielm-temp-buffer))
+ (when ielm-temp-buffer
+ (kill-buffer ielm-temp-buffer)))
+ (error (setq ielm-result (ielm-format-error err))
+ (setq ielm-error-type "Eval error"))
+ (quit (setq ielm-result "Quit during evaluation")
+ (setq ielm-error-type "Eval error")))))
(setq ielm-match-data (match-data)))
(setq ielm-error-type "IELM error")
(setq ielm-result "More than one sexp in input"))))
* \\[comint-dynamic-complete] completes Lisp symbols (or filenames, within strings),
or indents the line if there is nothing to complete.
-During evaluations, the values of the variables `*', `**', and `***'
-are the results of the previous, second previous and third previous
-evaluations respectively.
-
The current working buffer may be changed (with a call to
`set-buffer', or with \\[ielm-change-working-buffer]), and its value
is preserved between successive evaluations. In this way, expressions
Display the name of the working buffer with \\[ielm-print-working-buffer],
or the buffer itself with \\[ielm-display-working-buffer].
+During evaluations, the values of the variables `*', `**', and `***'
+are the results of the previous, second previous and third previous
+evaluations respectively. If the working buffer is another IELM
+buffer, then the values in the working buffer are used. The variables
+`*1', `*2' and `*3', yield the process buffer values.
+
Expressions evaluated by IELM are not subject to `debug-on-quit' or
`debug-on-error'.
(setq fill-paragraph-function 'lisp-fill-paragraph)
;; Value holders
- (setq * nil)
(make-local-variable '*)
- (setq ** nil)
+ (setq * nil)
(make-local-variable '**)
- (setq *** nil)
+ (setq ** nil)
(make-local-variable '***)
+ (setq *** nil)
(set (make-local-variable 'ielm-match-data) nil)
;; font-lock support