comparison lisp/emacs-lisp/lisp-mode.el @ 25434:9a7891b32d1a

(eval-defun): Expand macros, and specially handle defvar inside their expansions. (eval-defun-1): New subroutine.
author Richard M. Stallman <rms@gnu.org>
date Sun, 29 Aug 1999 19:53:27 +0000
parents ee107cab4019
children 4feb8ce584a5
comparison
equal deleted inserted replaced
25433:3141f8df24cc 25434:9a7891b32d1a
342 expr 342 expr
343 'args))))) 343 'args)))))
344 expr)) 344 expr))
345 (set-syntax-table stab))))))) 345 (set-syntax-table stab)))))))
346 346
347 ;; Change defvar into defconst within FORM,
348 ;; and likewise for other constructs as necessary.
349 (defun eval-defun-1 (form)
350 (cond ((and (eq (car form) 'defvar)
351 (cdr-safe (cdr-safe form)))
352 ;; Force variable to be bound.
353 (cons 'defconst (cdr form)))
354 ((and (eq (car form) 'defcustom)
355 (default-boundp (nth 1 form)))
356 ;; Force variable to be bound.
357 (set-default (nth 1 form) (eval (nth 2 form)))
358 form)
359 ((eq (car form) 'progn)
360 (cons 'progn (mapcar 'eval-defun-1 (cdr form))))
361 (t form)))
362
347 (defun eval-defun (eval-defun-arg-internal) 363 (defun eval-defun (eval-defun-arg-internal)
348 "Evaluate defun that point is in or before. 364 "Evaluate defun that point is in or before.
349 The value is displayed in the minibuffer. 365 The value is displayed in the minibuffer.
350 If the current defun is actually a call to `defvar', 366 If the current defun is actually a call to `defvar',
351 then reset the variable using the initial value expression 367 then reset the variable using the initial value expression
370 (end-of-defun) 386 (end-of-defun)
371 (beginning-of-defun) 387 (beginning-of-defun)
372 (setq beg (point)) 388 (setq beg (point))
373 (setq form (read (current-buffer))) 389 (setq form (read (current-buffer)))
374 (setq end (point))) 390 (setq end (point)))
375 ;; Alter the form if necessary. 391 ;; Alter the form if necessary, changing defvar into defconst, etc.
376 (cond ((and (eq (car form) 'defvar) 392 (setq form (eval-defun-1 (macroexpand form)))
377 (cdr-safe (cdr-safe form)))
378 ;; Force variable to be bound.
379 (setq form (cons 'defconst (cdr form))))
380 ((and (eq (car form) 'defcustom)
381 (default-boundp (nth 1 form)))
382 ;; Force variable to be bound.
383 (set-default (nth 1 form) (eval (nth 2 form)))))
384 (list beg end standard-output 393 (list beg end standard-output
385 `(lambda (ignore) 394 `(lambda (ignore)
386 ;; Skipping to the end of the specified region 395 ;; Skipping to the end of the specified region
387 ;; will make eval-region return. 396 ;; will make eval-region return.
388 (goto-char ,end) 397 (goto-char ,end)