Function: compile-defun

compile-defun is an autoloaded, interactive and byte-compiled function defined in bytecomp.el.gz.

Signature

(compile-defun &optional ARG)

Documentation

Compile and evaluate the current top-level form.

Print the result in the echo area. With argument ARG, insert value in current buffer after the form.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/bytecomp.el.gz
;;; compiling a single function
;;;###autoload
(defun compile-defun (&optional arg)
  "Compile and evaluate the current top-level form.
Print the result in the echo area.
With argument ARG, insert value in current buffer after the form."
  (interactive "P")
  (save-excursion
    (end-of-defun)
    (beginning-of-defun)
    (let* ((byte-compile-current-file (current-buffer))
	   (byte-compile-current-buffer (current-buffer))
	   (byte-compile-read-position (point))
	   (byte-compile-last-position byte-compile-read-position)
	   (byte-compile-last-warned-form 'nothing)
	   (value (eval
		   (let ((read-with-symbol-positions (current-buffer))
			 (read-symbol-positions-list nil))
		     (displaying-byte-compile-warnings
		      (byte-compile-sexp
                       (eval-sexp-add-defvars
                        (read (current-buffer))
                        byte-compile-read-position))))
                   lexical-binding)))
      (cond (arg
	     (message "Compiling from buffer... done.")
	     (prin1 value (current-buffer))
	     (insert "\n"))
	    ((message "%s" (prin1-to-string value)))))))