The number one function that I call that sometimes hang for a significant amount of time is ‘gnus’. I decided to try running it in a thread, and it worked surprisingly well. Initial loading of the messages can now be done in the background.
To prevent myself from running this function more than once at the same time, I created a wrapper function for this, and I have extracted it into a macro.
I'd like to have people's opinions on this strategy, and if it might be reasonable to default ‘gnus’ to do this when run on Emacs versions with concurrency support.
(defmacro define-background-function-wrapper (bg-function fn)
(let ((is-loading-sym (intern (concat "*" (symbol-name bg-function) "-is-loading*"))))
(defvar ,is-loading-sym nil)
(defun ,bg-function ()
(message ,(concat (symbol-name fn) " is already loading")))
(setq ,is-loading-sym t)
(make-thread (lambda ()
(setq ,is-loading-sym nil))))))))
It's invoked like ‘(define-background-function-wrapper bg-gnus gnus)’. This will then define the function ‘bg-gnus’ that runs ‘gnus‘ in a thread.