comparison lisp/emacs-lisp/lisp-mode.el @ 21490:366a1d025c6c

(eval-defun): Arrange to use eval-region even if we have to alter the form.
author Karl Heuer <kwzh@gnu.org>
date Mon, 13 Apr 1998 06:55:34 +0000
parents 2816d2c192fb
children afacb0a7e251
comparison
equal deleted inserted replaced
21489:a1a2beb0a09c 21490:366a1d025c6c
340 "Evaluate defun that point is in or before. 340 "Evaluate defun that point is in or before.
341 Print value in minibuffer. 341 Print value in minibuffer.
342 With argument, insert value in current buffer after the defun." 342 With argument, insert value in current buffer after the defun."
343 (interactive "P") 343 (interactive "P")
344 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t)) 344 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t))
345 (form (save-excursion 345 end form)
346 (end-of-defun) 346 ;; Read the form from the buffer, and record where it ends.
347 (beginning-of-defun) 347 (save-excursion
348 (read (current-buffer))))) 348 (end-of-defun)
349 (beginning-of-defun)
350 (setq form (read (current-buffer)))
351 (setq end (point)))
352 ;; Alter the form if necessary.
349 (cond ((and (eq (car form) 'defvar) 353 (cond ((and (eq (car form) 'defvar)
350 (cdr-safe (cdr-safe form))) 354 (cdr-safe (cdr-safe form)))
351 ;; Force variable to be bound. 355 ;; Force variable to be bound.
352 (setq form (cons 'defconst (cdr form)))) 356 (setq form (cons 'defconst (cdr form))))
353 ((and (eq (car form) 'defcustom) 357 ((and (eq (car form) 'defcustom)
354 (default-boundp (nth 1 form))) 358 (default-boundp (nth 1 form)))
355 ;; Force variable to be bound. 359 ;; Force variable to be bound.
356 (set-default (nth 1 form) (eval (nth 2 form))))) 360 (set-default (nth 1 form) (eval (nth 2 form)))))
357 (prin1 (eval form)))) 361 ;; Now arrange for eval-region to "read" the (possibly) altered form.
362 ;; eval-region handles recording which file defines a function or variable.
363 (save-excursion
364 (let ((load-read-function
365 #'(lambda (ignore)
366 ;; Skipping to the end of the specified region
367 ;; will make eval-region return.
368 (goto-char end)
369 form)))
370 (eval-region (point) end standard-output)))))
358 371
359 (defun lisp-comment-indent () 372 (defun lisp-comment-indent ()
360 (if (looking-at "\\s<\\s<\\s<") 373 (if (looking-at "\\s<\\s<\\s<")
361 (current-column) 374 (current-column)
362 (if (looking-at "\\s<\\s<") 375 (if (looking-at "\\s<\\s<")