branch: master
commit 93b05a955584cd8f3f7b75c5888c41db7bc7c878
Author: Ryan C. Thompson <[email protected]>
Commit: Ryan C. Thompson <[email protected]>
More robust evaluation and closure-protection of start-func
---
async.el | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/async.el b/async.el
index 8f893b9..c4485d6 100644
--- a/async.el
+++ b/async.el
@@ -260,10 +260,21 @@ passed to FINISH-FUNC). Call `async-get' on such a
future always
returns nil. It can still be useful, however, as an argument to
`async-ready' or `async-wait'."
(require 'find-func)
- (let ((procvar (make-symbol "proc"))
- ;; Avoid accidental lexical closures by evaluating START-FUNC
- ;; in an empty lexical environment.
- (start-func (eval start-func t)))
+ (let* ((procvar (make-symbol "proc"))
+ ;; Evaluate START-FUNC if it isn't aready a function.
+ (start-func
+ (if (functionp start-func)
+ start-func
+ (eval start-func)))
+ (start-func
+ (if (eq (car start-func) 'lambda)
+ (eval start-func t)
+ start-func)))
+ ;; If START-FUNC is a lambda, prevent it from creating a lexical
+ ;; closure by evaluating it in an empty lexical environment.
+ (when (eq (car start-func) 'lambda)
+ (setq start-func
+ (eval start-func t)))
`(let* ((sexp #',start-func)
(,procvar
(async-start-process