• Stars
    star
    832
  • Rank 54,811 (Top 2 %)
  • Language
    Emacs Lisp
  • License
    GNU General Publi...
  • Created over 12 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple library for asynchronous processing in Emacs

License GPL 3 GNU ELPA MELPA MELPA Stable

emacs-async

async.el is a module for doing asynchronous processing in Emacs. Some async applications are provided as well with this package:

  • Dired-async
  • smtp-mail-async
  • async-bytecomp

Install

You can install emacs-async package from MELPA using package.el.

You can also install from sources, in this case you should install using make and make install to ensure emacs-async is installed in a standard load-path destination where other packages can find it easily when compiling.

Install dired-async

Add to your .emacs.el:

(autoload 'dired-async-mode "dired-async.el" nil t)
(dired-async-mode 1)

This will allow you to run asynchronously the dired commands for copying, renaming and symlinking. If you are a helm user, this will allow you to copy, rename etc... asynchronously from helm. Note that with helm you can disable this by running the copy, rename etc... commands with a prefix argument.

If you don't want to make dired/helm asynchronous disable it with dired-async-mode.

Debian and Ubuntu

Users of Debian 9 or later or Ubuntu 16.04 or later may simply apt-get install elpa-async.

Authentication and user interaction

Some authentications require user interaction, for example answering to a prompt, entering a passwords etc. Your async implementation should avoid any such user interaction, to avoid being stuck with a prompt you will not be able to answer to in the child emacs. For all what is remote (mails, tramp etc...) you have to let emacs manage your identification with auth-sources, so that you do not have to enter a password.

Basically all you need is something like this in your init file:

(use-package auth-source
  :no-require t
  :config (setq auth-sources '("~/.authinfo.gpg" "~/.netrc")))

And a "~/.authinfo.gpg" file containing entries such as

default port sudo login root password xxxxxxxx

or

machine xxxxx port xxx login xxx password xxxxxxx

for more specific hosts (smtp, mails etc...)

See auth-sources manual for more infos.

NOTE: For all your async implementations in emacs-26+ versions that handle remote files (tramp), you will have to let-bind async-quiet-switch to -q to workaround a tramp bug that prevent emacs -Q to use auth-sources mechanism.

Enable asynchronous compilation of your (M)elpa packages

By default emacs package.el compile packages in its running emacs session. This is not a problem when installing a new package (which is not actually loaded in current emacs) but it may create errors and bad compilation when upgrading a package (old version of package is already loaded and running in current emacs). You can remedy to this by allowing async to compile your packages asynchronously, (helm and magit actually do this by default, so if you are using these packages they will compile asynchronously) to do this, add to your init file:

(async-bytecomp-package-mode 1)

You can control which packages will compile async with async-bytecomp-allowed-packages. Set it to '(all) to be sure you will compile all packages asynchronously.

Send mails asynchronously with smtp mail async

To enable this feature, ensure smtp-mail-async.el is loaded and use

(setq message-send-mail-function 'async-smtpmail-send-it).

WARNINGS:

  • When using recent emacs (25+) the network security manager maybe called interactively in child emacs and make async-smtpmail-send-it fail, so be sure to send email once synchronously before using async-smtpmail-send-it as your message-send-mail-function.

  • You may loose your sent mail if your network is down, so ensure to queue your mails if so. you can do this automatically, see issue #64.

Async usage

The interface is intended to be very easy to use:

async-start

async-start START-FUNC FINISH-FUNC

Execute START-FUNC (often a lambda) in a subordinate Emacs process. When done, the return value is passed to FINISH-FUNC. Example:

(async-start
   ;; What to do in the child process
   (lambda ()
     (message "This is a test")
     (sleep-for 3)
     222)

   ;; What to do when it finishes
   (lambda (result)
     (message "Async process done, result should be 222: %s" result)))

If FINISH-FUNC is nil or missing, a future is returned that can be inspected using async-get, blocking until the value is ready. Example:

(let ((proc (async-start
               ;; What to do in the child process
               (lambda ()
                 (message "This is a test")
                 (sleep-for 3)
                 222))))

    (message "I'm going to do some work here") ;; ....

    (message "Waiting on async process, result should be 222: %s"
             (async-get proc)))

If you don't want to use a callback, and you don't care about any return value from the child process, pass the 'ignore symbol as the second argument (if you don't, and never call async-get, it will leave *emacs* process buffers hanging around):

(async-start
 (lambda ()
   (delete-file "a remote file on a slow link" nil))
 'ignore)

Note: Even when FINISH-FUNC is present, a future is still returned except that it yields no value (since the value is passed to FINISH-FUNC). Calling async-get on such a future always returns nil. It can still be useful, however, as an argument to async-ready or async-wait.

async-start-process

async-start-process NAME PROGRAM FINISH-FUNC &rest PROGRAM-ARGS

Start the executable PROGRAM asynchronously. See async-start. PROGRAM is passed PROGRAM-ARGS, calling FINISH-FUNC with the process object when done. If FINISH-FUNC is nil, the future object will return the process object when the program is finished. Set DEFAULT-DIRECTORY to change PROGRAM's current working directory.

async-get

async-get FUTURE

Get the value from an asynchronously called function when it is ready. FUTURE is returned by async-start or async-start-process when its FINISH-FUNC is nil.

async-ready

async-ready FUTURE

Query a FUTURE to see if its function's value is ready -- i.e., if no blocking would result from a call to async-get on that FUTURE.

async-wait

async-wait FUTURE

Wait for FUTURE to become ready.

async-inject-variables

async-inject-variables INCLUDE-REGEXP &optional PREDICATE EXCLUDE-REGEXP

Return a setq form that replicates part of the calling environment. It sets the value for every variable matching INCLUDE-REGEXP and also PREDICATE. It will not perform injection for any variable matching EXCLUDE-REGEXP (if present). It is intended to be used as follows:

(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-variables "\\`\\(smtpmail\\|\\(user-\\)?mail\\)-")
        (smtpmail-send-it)))
   'ignore)

async-let

async-let BINDINGS &rest FORMS

Allow to establish let bindings asynchronously. Each value of binding can refer to the symbols already bound in BINDINGS (like let*). FORMS are executed once BINDINGS have been evaluated, but without blocking emacs.

Examples:

(async-let ((x "hello")
            (y "world"))
  (message "%s %s" x y))
  
(async-let ((x (* 5 2))
            (y (+ x 4))
            (z (+ x y)))
  (message "%d + %d = %d" x y z))

Note that if you bind something to nil and set it afterward in body, the evaluation of this binding will NOT be asynchronous, but will happen in you current emacs, blocking it if the evaluation of this value is sufficiently important, e.g:

(async-let ((x "hello")
            (y "world")
            z)
  (setq z (+ 1 2)) ;; Huge calculation of Z will block emacs.
  (message "%s %s %d" x y z))

IOW if the calculation of Z is huge and you want it asynchronous evaluate it in BINDINGS but not in FORMS.

More Repositories

1

use-package

A use-package declaration for simplifying your .emacs
Emacs Lisp
4,399
star
2

git-scripts

A bunch of random scripts I've either written, downloaded or clipped from #git.
Shell
1,322
star
3

git-from-the-bottom-up

An introduction to the architecture and design of the Git content manager
766
star
4

category-theory

An axiom-free formalization of category theory in Coq for personal study and practical work
Coq
744
star
5

dot-emacs

My .emacs.el file and other personal Emacs goodies
Emacs Lisp
606
star
6

alert

A Growl-like alerts notifier for Emacs
Emacs Lisp
426
star
7

nix-config

My local Nix configuration
Emacs Lisp
399
star
8

gitlib

Haskell
176
star
9

coq-haskell

A library for formalizing Haskell types and functions in Coq
Coq
159
star
10

org-mode

This is a very old fork of Org-mode, but it's the version I still use every day
Emacs Lisp
155
star
11

emacs-chess

A complete chess client written in Emacs Lisp.
Emacs Lisp
122
star
12

coq-pipes

Coq
100
star
13

git-undo-el

A command for Emacs to regress or "undo" a region back through its Git history
Emacs Lisp
87
star
14

control-theory

Control theory in Haskell: Data structures, algorithms and adapters
Haskell
80
star
15

putting-lenses-to-work

A presentation for BayHac 2017 on how I uses lenses at work
Haskell
75
star
16

nix-update-el

An Emacs command for updating fetch declarations in place
Emacs Lisp
71
star
17

una

A universal interface to multiple unarchiving tools
Haskell
68
star
18

use-package-examples

Example declarations to demonstrate the features of use-package
52
star
19

regex-tool

A regular expression IDE for Emacs, to help with the creation and testing of regular expressions.
Emacs Lisp
50
star
20

git-annex-el

Emacs integration for the git-annex tool by Joey Hess
Emacs Lisp
43
star
21

notes

Haskell
42
star
22

z3cat

Use Conal Elliott's concat library to compile regular Haskell functions into Z3 equations
Haskell
38
star
23

emacs-release

A history of Emacs releases, under version control
Emacs Lisp
36
star
24

newartisans

HTML
35
star
25

emacs-pl

Emacs Lisp
31
star
26

bytestring-fiat

An implementation of the Haskell ByteString library using the Fiat system from MIT
Coq
31
star
27

periods

Common Lisp library for manipulating date/time objects at a higher level
Common Lisp
29
star
28

c2hsc

Utility for creating .hsc files from C API header files
Haskell
26
star
29

trade-journal

Code for keep an investment trade journal
Haskell
25
star
30

simple-conduit

Haskell
25
star
31

gdtoa

David M. Gay's floating-point conversion library
C
25
star
32

hours

Utility for showing hours worked within a work month against a target
Haskell
24
star
33

thinking-with-functions

A brief presentation on Denotational Design, based on Conal Elliott's work
Nix
23
star
34

comparable

A library for comparing data structures in Rust, oriented toward testing
Rust
21
star
35

async-pool

Haskell
21
star
36

parsec-free

Haskell
20
star
37

pushme

A script I use for synchronizing directories and ZFS pools between systems
Haskell
20
star
38

haskell-config

My haskell-mode configuration for Emacs
Emacs Lisp
19
star
39

categorical

Compiling to STLC to categories in Haskell and Coq, using Conal Elliot's work
Haskell
19
star
40

ghc-dynamic-example

An example of dynamically loading a Haskell source module
Haskell
18
star
41

scripts

Various and sundry shell scripts used on my system
Shell
17
star
42

linearscan

Coq
17
star
43

coq-lattice

A reflection-based proof tactic for lattices in Coq
Coq
16
star
44

git-all

Utility for finding all Git repositories that need attention
Haskell
16
star
45

coq-cds4ltl

A formalization of finite, constructive log analysis using linear temporal logic
Coq
16
star
46

springboard

An Emacs mode based on Helm that makes it easy to bounce around projects
Emacs Lisp
15
star
47

logging

Haskell
15
star
48

ready-lisp

A distribution of Aquamacs, SBCL and SLIME which offers the simplest way to run Common Lisp on Mac OS X
Emacs Lisp
14
star
49

haskell-to-c

Sample code to build a C library from a Haskell module, then call it from C
Haskell
12
star
50

markdown.net

A Markdown and SmartyPants processor written in C# for .NET.
C#
12
star
51

svndump

Library for parsing Subversion dump files from Haskell
Haskell
12
star
52

hello

Hello world project templates for getting started quickly with Nix
Nix
11
star
53

software-foundations

Nix-enabled and fully building mirror of Software Foundations WITHOUT SOLUTIONS
HTML
10
star
54

remember

A mode for Emacs which makes it easy to quickly jot down information.
Emacs Lisp
10
star
55

dirscan

Stateful directory scanning in Python. Makes a great ~/.Trash cleaner.
Python
9
star
56

pipes-files

Haskell
9
star
57

monad-extras

Haskell
9
star
58

cambl

Common Lisp library for working with commoditized amounts and balances
Common Lisp
9
star
59

sizes

Recursively show space (size and i-nodes) used in subdirectories
Haskell
9
star
60

disk-catalog

A Python script for cataloging offline media and disk archives.
Python
8
star
61

erc-yank

Automagically create a Gist in ERC if pasting more than 5 lines
Emacs Lisp
8
star
62

hierarchy

Haskell
8
star
63

simple-ltl

A simple compiler from LTL formulas to state machines
Haskell
7
star
64

linearscan-hoopl

Haskell
7
star
65

pcomplete

A programmable TAB completion facility for Emacs Lisp programmers. Used by Eshell.
Emacs Lisp
7
star
66

subconvert

A script to faithfully convert Subversion repositories to Git
C++
7
star
67

red-black

An efficient implementation of red-black trees for Common Lisp, by Jรผrgen Bรถhms Heimatseiten
Common Lisp
6
star
68

stringable

A Stringable type class, in the spirit of Foldable and Traversable
Haskell
6
star
69

gnus-harvest

Harvest e-mail addresses from read/written Gnus articles
Emacs Lisp
5
star
70

start-kadena

My own Nix script for starting and testing a Kadena node
Nix
5
star
71

ipcvar

Haskell
5
star
72

set-theory

Coq
5
star
73

pipes-async

Haskell
5
star
74

eval-expr

Enhanced eval-expression command
Emacs Lisp
5
star
75

planner

A day-planner-like planning tool for Emacs; uses Muse to publish plan pages.
Emacs Lisp
5
star
76

sacred-writings

A bilingual typesetting of the Hidden Words
TeX
4
star
77

sitebuilder

Common Hakyll builder for my websites
Haskell
4
star
78

bcalc

Haskell
4
star
79

refine-freer

Experiments with an extensible refinement framework
Coq
4
star
80

wallet

Information about staking and management ICP tokens on the Internet Computer
Nix
4
star
81

haskell-infra

Some files related to administration of Haskell infrastructure
4
star
82

firewall

A rigorous set of firewall scripts for BSD ipfw, and Linux iptables
Shell
4
star
83

linkdups

Intelligently hard-link duplicate files in a directory tree
Python
4
star
84

haskell-c-stack

Experiments to determine how the C stack relates to the Haskell FFI
Haskell
3
star
85

runmany

Run multiple commands, interleaving output and errors
Haskell
3
star
86

johnwiegley

My personal website, at johnwiegley.com
HTML
3
star
87

zomega

A computational reflection based solver for expressions involving Z (but tunable)
Coq
3
star
88

rehoo

Utility to combine lots and lots of .hoo files in parallel
Haskell
3
star
89

consistent

Haskell
3
star
90

sshify

Script for setting up publickey authentication on new hosts
Shell
3
star
91

monad-base-control

A rewrite of monad-control which provides only MonadBaseControl
Haskell
3
star
92

haskell-quantification

Presentation on quantification in Haskell for South Bay Haskell
Haskell
3
star
93

muse

The Emacs Muse, a complete publishing environment written for Emacs.
Emacs Lisp
3
star
94

helm-hoogle

Use helm to navigate query results from Hoogle
Emacs Lisp
2
star
95

org-beamer-template

A quick template from which to start new presentations
Emacs Lisp
2
star
96

aasaan

A library for transliterating between different representations of the Arabic alphabet.
C++
2
star
97

kleisli

Haskell
2
star
98

z3-generate-api

A tool to generate Haskell wrappers around the Z3 C API
Haskell
2
star
99

project-euler

My solutions to Project Euler in Haskell
Haskell
2
star
100

church-list

Haskell
2
star