Last active
August 29, 2015 14:10
-
-
Save pervognsen/770e024cb50a55624c15 to your computer and use it in GitHub Desktop.
autoeval.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defcustom autoeval-default-interval 1 "") | |
(defvar autoeval-sexps nil) | |
(defvar autoeval-interval autoeval-default-interval) | |
(defmacro autoeval (form) | |
`(progn | |
(push ',form autoeval-sexps) | |
(autoeval-start autoeval-interval))) | |
(defun autoeval-clear () | |
(setq autoeval-sexps nil)) | |
(defun autoeval-update () | |
(let ((results (mapcar (lambda (sexp) | |
(let ((value (condition-case err | |
(pp-to-string (eval sexp)) | |
(error (format "Error: %s" err))))) | |
(format "%s\n=> %s\n" (prin1-to-string sexp) value))) | |
autoeval-sexps))) | |
(with-read-only-buffer (get-buffer-create "*autoeval*") | |
(save-line-and-column | |
(erase-buffer) | |
(save-excursion | |
(insert (format "Updating every %s seconds.\n\n" autoeval-interval)) | |
(dolist (result results) | |
(insert (format "%s\n" result)))))))) | |
(defun autoeval-stop () | |
(cancel-function-timers 'autoeval-update)) | |
(defun autoeval-start (&optional interval) | |
(autoeval-stop) | |
(setq autoeval-interval (or interval autoeval-default-interval)) | |
(autoeval-update) | |
(run-with-timer autoeval-interval autoeval-interval 'autoeval-update)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment