(defmacro async-inject-environment
(include-regexp &optional predicate exclude-regexp)
"Inject a part of the parent environment into an async function."
- `(setq
- ,@(let (bindings)
- (mapatoms
- (lambda (sym)
- (if (and (boundp sym)
- (or (null include-regexp)
- (string-match include-regexp (symbol-name sym)))
- (not (string-match
- (or exclude-regexp "-syntax-table\\'")
- (symbol-name sym))))
- (let ((value (symbol-value sym)))
- (when (or (null predicate)
- (funcall (or predicate
- (lambda (sym)
- (let ((value (symbol-value sym)))
- (or (not (functionp value))
- (symbolp value))))) sym))
- (setq bindings (cons `(quote ,value)
- bindings))
- (setq bindings (cons sym bindings)))))))
- bindings)))
+ `'(setq
+ ,@(let (bindings)
+ (mapatoms
+ (lambda (sym)
+ (if (and (boundp sym)
+ (or (null include-regexp)
+ (string-match include-regexp (symbol-name sym)))
+ (not (string-match
+ (or exclude-regexp "-syntax-table\\'")
+ (symbol-name sym))))
+ (let ((value (symbol-value sym)))
+ (when (funcall (or predicate
+ (lambda (sym)
+ (let ((value (symbol-value sym)))
+ (or (not (functionp value))
+ (symbolp value)))))
+ sym)
+ (setq bindings (cons `(quote ,value) bindings)
+ bindings (cons sym bindings)))))))
+ bindings)))
(defun async-when-done (proc &optional change)
"Process sentinal used to retrieve the value from the child process."
(require 'smtpmail)
(defun async-smtpmail-send-it ()
- (macroexpand
- '(async-start
- `(lambda ()
- (require 'smtpmail)
- (with-temp-buffer
- (insert ,(buffer-substring-no-properties (point-min) (point-max)))
- ;; Pass in the variable environment for smtpmail
- (async-inject-environment "\\`\\(smtpmail\\|\\(user-\\)?mail\\)-")
- (smtpmail-send-it)))
- 'ignore)))
+ (async-start
+ `(lambda ()
+ (require 'smtpmail)
+ (with-temp-buffer
+ (insert ,(buffer-substring-no-properties (point-min) (point-max)))
+ ;; Pass in the variable environment for smtpmail
+ ,(async-inject-environment "\\`\\(smtpmail\\|\\(user-\\)?mail\\)-")
+ (smtpmail-send-it)))
+ 'ignore))
(provide 'smtpmail-async)