Skip to content

Instantly share code, notes, and snippets.

@kiwanami
Created December 16, 2016 16:05
Show Gist options
  • Save kiwanami/2265393d43d04a936c818c19eec3b4dd to your computer and use it in GitHub Desktop.
Save kiwanami/2265393d43d04a936c818c19eec3b4dd to your computer and use it in GitHub Desktop.
(defmacro define-background-function-wrapper (bg-function fn)
(let ((is-loading-sym (intern (concat "*" (symbol-name bg-function) "-is-loading*"))))
`(progn
(defvar ,is-loading-sym nil)
(defun ,bg-function ()
(interactive)
(when ,is-loading-sym
(message ,(concat (symbol-name fn) " is already loading")))
(setq ,is-loading-sym t)
(make-thread (lambda ()
(unwind-protect
(,fn)
(setq ,is-loading-sym nil))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment