Mercurial > emacs
comparison lisp/emacs-lisp/lisp-mode.el @ 25107:2aa414a532f2
(eval-defun): Re-written to avoid
capturing variables.
author | Dave Love <fx@gnu.org> |
---|---|
date | Thu, 29 Jul 1999 22:04:13 +0000 |
parents | 485668a57232 |
children | ee107cab4019 |
comparison
equal
deleted
inserted
replaced
25106:bfdfc5515d48 | 25107:2aa414a532f2 |
---|---|
1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands. | 1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands. |
2 | 2 |
3 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985, 1986, 1999 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Maintainer: FSF | 5 ;; Maintainer: FSF |
6 ;; Keywords: lisp, languages | 6 ;; Keywords: lisp, languages |
7 | 7 |
8 ;; This file is part of GNU Emacs. | 8 ;; This file is part of GNU Emacs. |
354 if it already has a value.\) | 354 if it already has a value.\) |
355 | 355 |
356 With argument, insert value in current buffer after the defun. | 356 With argument, insert value in current buffer after the defun. |
357 Return the result of evaluation." | 357 Return the result of evaluation." |
358 (interactive "P") | 358 (interactive "P") |
359 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t)) | 359 (save-excursion |
360 beg end form) | 360 ;; Arrange for eval-region to "read" the (possibly) altered form. |
361 ;; Read the form from the buffer, and record where it ends. | 361 ;; eval-region handles recording which file defines a function or |
362 (save-excursion | 362 ;; variable. Re-written using `apply' to avoid capturing |
363 (end-of-defun) | 363 ;; variables like `end'. |
364 (beginning-of-defun) | 364 (apply |
365 (setq beg (point)) | 365 #'eval-region |
366 (setq form (read (current-buffer))) | 366 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t)) |
367 (setq end (point))) | 367 beg end form) |
368 ;; Alter the form if necessary. | 368 ;; Read the form from the buffer, and record where it ends. |
369 (cond ((and (eq (car form) 'defvar) | 369 (save-excursion |
370 (cdr-safe (cdr-safe form))) | 370 (end-of-defun) |
371 ;; Force variable to be bound. | 371 (beginning-of-defun) |
372 (setq form (cons 'defconst (cdr form)))) | 372 (setq beg (point)) |
373 ((and (eq (car form) 'defcustom) | 373 (setq form (read (current-buffer))) |
374 (default-boundp (nth 1 form))) | 374 (setq end (point))) |
375 ;; Force variable to be bound. | 375 ;; Alter the form if necessary. |
376 (set-default (nth 1 form) (eval (nth 2 form))))) | 376 (cond ((and (eq (car form) 'defvar) |
377 ;; Now arrange for eval-region to "read" the (possibly) altered form. | 377 (cdr-safe (cdr-safe form))) |
378 ;; eval-region handles recording which file defines a function or variable. | 378 ;; Force variable to be bound. |
379 (save-excursion | 379 (setq form (cons 'defconst (cdr form)))) |
380 (eval-region beg end standard-output | 380 ((and (eq (car form) 'defcustom) |
381 #'(lambda (ignore) | 381 (default-boundp (nth 1 form))) |
382 ;; Skipping to the end of the specified region | 382 ;; Force variable to be bound. |
383 ;; will make eval-region return. | 383 (set-default (nth 1 form) (eval (nth 2 form))))) |
384 (goto-char end) | 384 (list beg end standard-output |
385 form)) | 385 `(lambda (ignore) |
386 ;; The result of evaluation has been put onto VALUES. | 386 ;; Skipping to the end of the specified region |
387 ;; So return it. | 387 ;; will make eval-region return. |
388 (car values)))) | 388 (goto-char ,end) |
389 ,form))))) | |
390 ;; The result of evaluation has been put onto VALUES. So return it. | |
391 (car values)) | |
389 | 392 |
390 (defun lisp-comment-indent () | 393 (defun lisp-comment-indent () |
391 (if (looking-at "\\s<\\s<\\s<") | 394 (if (looking-at "\\s<\\s<\\s<") |
392 (current-column) | 395 (current-column) |
393 (if (looking-at "\\s<\\s<") | 396 (if (looking-at "\\s<\\s<") |