Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pervognsen/770e024cb50a55624c15 to your computer and use it in GitHub Desktop.
Save pervognsen/770e024cb50a55624c15 to your computer and use it in GitHub Desktop.
autoeval.el
(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