Mercurial > emacs
comparison lisp/emacs-lisp/lisp-mode.el @ 25703:00b4eac00979
(eval-defun, eval-last-sexp):
Bind print-level, print-length and debug-on-error.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 14 Sep 1999 07:00:36 +0000 |
parents | 556711217681 |
children | 5984b9cfea66 |
comparison
equal
deleted
inserted
replaced
25702:2b96c6e05f23 | 25703:00b4eac00979 |
---|---|
324 | 324 |
325 (defun eval-last-sexp (eval-last-sexp-arg-internal) | 325 (defun eval-last-sexp (eval-last-sexp-arg-internal) |
326 "Evaluate sexp before point; print value in minibuffer. | 326 "Evaluate sexp before point; print value in minibuffer. |
327 With argument, print output into current buffer." | 327 With argument, print output into current buffer." |
328 (interactive "P") | 328 (interactive "P") |
329 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t))) | 329 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t)) |
330 (prin1 (eval (let ((stab (syntax-table)) | 330 (debug-on-error eval-expression-debug-on-error)) |
331 (let ((value | |
332 (eval (let ((stab (syntax-table)) | |
331 (opoint (point)) | 333 (opoint (point)) |
332 ignore-quotes | 334 ignore-quotes |
333 expr) | 335 expr) |
334 (unwind-protect | 336 (unwind-protect |
335 (save-excursion | 337 (save-excursion |
366 (list 'lambda | 368 (list 'lambda |
367 '(&rest args) | 369 '(&rest args) |
368 expr | 370 expr |
369 'args))))) | 371 'args))))) |
370 expr)) | 372 expr)) |
371 (set-syntax-table stab))))))) | 373 (set-syntax-table stab)))))) |
374 (let ((print-length eval-expression-print-length) | |
375 (print-level eval-expression-print-level)) | |
376 (print value))))) | |
372 | 377 |
373 ;; Change defvar into defconst within FORM, | 378 ;; Change defvar into defconst within FORM, |
374 ;; and likewise for other constructs as necessary. | 379 ;; and likewise for other constructs as necessary. |
375 (defun eval-defun-1 (form) | 380 (defun eval-defun-1 (form) |
376 (cond ((and (eq (car form) 'defvar) | 381 (cond ((and (eq (car form) 'defvar) |
396 if it already has a value.\) | 401 if it already has a value.\) |
397 | 402 |
398 With argument, insert value in current buffer after the defun. | 403 With argument, insert value in current buffer after the defun. |
399 Return the result of evaluation." | 404 Return the result of evaluation." |
400 (interactive "P") | 405 (interactive "P") |
401 (save-excursion | 406 (let ((debug-on-error eval-expression-debug-on-error) |
402 ;; Arrange for eval-region to "read" the (possibly) altered form. | 407 (print-length eval-expression-print-length) |
403 ;; eval-region handles recording which file defines a function or | 408 (print-level eval-expression-print-level)) |
404 ;; variable. Re-written using `apply' to avoid capturing | 409 (save-excursion |
405 ;; variables like `end'. | 410 ;; Arrange for eval-region to "read" the (possibly) altered form. |
406 (apply | 411 ;; eval-region handles recording which file defines a function or |
407 #'eval-region | 412 ;; variable. Re-written using `apply' to avoid capturing |
408 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t)) | 413 ;; variables like `end'. |
409 beg end form) | 414 (apply |
410 ;; Read the form from the buffer, and record where it ends. | 415 #'eval-region |
411 (save-excursion | 416 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t)) |
412 (end-of-defun) | 417 beg end form) |
413 (beginning-of-defun) | 418 ;; Read the form from the buffer, and record where it ends. |
414 (setq beg (point)) | 419 (save-excursion |
415 (setq form (read (current-buffer))) | 420 (end-of-defun) |
416 (setq end (point))) | 421 (beginning-of-defun) |
417 ;; Alter the form if necessary, changing defvar into defconst, etc. | 422 (setq beg (point)) |
418 (setq form (eval-defun-1 (macroexpand form))) | 423 (setq form (read (current-buffer))) |
419 (list beg end standard-output | 424 (setq end (point))) |
420 `(lambda (ignore) | 425 ;; Alter the form if necessary, changing defvar into defconst, etc. |
421 ;; Skipping to the end of the specified region | 426 (setq form (eval-defun-1 (macroexpand form))) |
422 ;; will make eval-region return. | 427 (list beg end standard-output |
423 (goto-char ,end) | 428 `(lambda (ignore) |
424 ',form))))) | 429 ;; Skipping to the end of the specified region |
430 ;; will make eval-region return. | |
431 (goto-char ,end) | |
432 ',form)))))) | |
425 ;; The result of evaluation has been put onto VALUES. So return it. | 433 ;; The result of evaluation has been put onto VALUES. So return it. |
426 (car values)) | 434 (car values)) |
427 | 435 |
428 (defun lisp-comment-indent () | 436 (defun lisp-comment-indent () |
429 (if (looking-at "\\s<\\s<\\s<") | 437 (if (looking-at "\\s<\\s<\\s<") |