3 `async.el` is a module for doing asynchronous processing in Emacs.
7 Add to your `.emacs.el`:
9 (when (require 'dired-aux)
10 (require 'dired-async))
12 This will allow you to run asynchronously
13 the dired commands for copying, renaming and symlinking.
14 If you are a [helm](https://github.com/emacs-helm/helm) user, this will allow you
15 to copy, rename etc... asynchronously from [helm](https://github.com/emacs-helm/helm).
16 Note that with [helm](https://github.com/emacs-helm/helm)
17 you can disable this by running the copy, rename etc... commands with a prefix argument.
19 If you don't want to make dired/helm asynchronous, you can either
20 disable this with `dired-async-be-async` or just load `async.el`.
24 The interface is intended to be very easy to use:
28 async-start START-FUNC FINISH-FUNC
30 Execute START-FUNC (often a lambda) in a subordinate Emacs process. When
31 done, the return value is passed to FINISH-FUNC. Example:
34 ;; What to do in the child process
36 (message "This is a test")
40 ;; What to do when it finishes
42 (message "Async process done, result should be 222: %s" result)))
44 If FINISH-FUNC is `nil` or missing, a future is returned that can be inspected
45 using `async-get`, blocking until the value is ready. Example:
47 (let ((proc (async-start
48 ;; What to do in the child process
50 (message "This is a test")
54 (message "I'm going to do some work here") ;; ....
56 (message "Waiting on async process, result should be 222: %s"
59 If you don't want to use a callback, and you don't care about any return value
60 from the child process, pass the `'ignore` symbol as the second argument (if
61 you don't, and never call `async-get`, it will leave ``*emacs*`` process buffers
66 (delete-file "a remote file on a slow link" nil))
69 Note: Even when FINISH-FUNC is present, a future is still returned except that
70 it yields no value (since the value is passed to FINISH-FUNC). Calling
71 `async-get` on such a future always returns `nil`. It can still be useful,
72 however, as an argument to `async-ready` or `async-wait`.
74 ## async-start-process
76 async-start-process NAME PROGRAM FINISH-FUNC &rest PROGRAM-ARGS
78 Start the executable PROGRAM asynchronously. See `async-start`. PROGRAM is
79 passed PROGRAM-ARGS, calling FINISH-FUNC with the process object when done.
80 If FINISH-FUNC is `nil`, the future object will return the process object when
81 the program is finished. Set DEFAULT-DIRECTORY to change PROGRAM's current
88 Get the value from an asynchronously called function when it is ready. FUTURE is
89 returned by `async-start` or `async-start-process` when its FINISH-FUNC is
96 Query a FUTURE to see if its function's value is ready -- i.e., if no blocking
97 would result from a call to `async-get` on that FUTURE.
103 Wait for FUTURE to become ready.
105 ## async-inject-variables
107 async-inject-variables INCLUDE-REGEXP &optional PREDICATE EXCLUDE-REGEXP
109 Return a `setq` form that replicates part of the calling environment. It sets
110 the value for every variable matching INCLUDE-REGEXP and also PREDICATE. It
111 will not perform injection for any variable matching EXCLUDE-REGEXP (if
112 present). It is intended to be used as follows:
118 (insert ,(buffer-substring-no-properties (point-min) (point-max)))
119 ;; Pass in the variable environment for smtpmail
120 ,(async-inject-variables "\\`\\(smtpmail\\|\\(user-\\)?mail\\)-")