Replacing dash.el with Built-in Emacs APIs
dash.el
has long been a staple in the Emacs community and I give it a lot of
credit for driving some upstream API progress. By showing how many people wanted
to use dash.el
for various reasons (e.g. macros like -if-let
and -when-let
and numerous functions that transform sequences), a strong case could be made
with Emacs’s maintainers that core Emacs Lisp APIs needed to be
extended. Eventually that lead to the creation of subr-x.el
1 (bundled with
Emacs since 24.3) and seq.el
(bundled with Emacs since 26.1). The two packages
mostly obsolete dash.el
and I guess this contributed to it being used less and
less these days.
I recently took over the maintenance of the popular
Flycheck package and I’ve noticed that
it was still using dash.el
, despite targeting Emacs 26.1. As I plan to submit
Flycheck to the official NonGNU ELPA package repository, it couldn’t have
dependencies that are not present on GNU ELPA and NonGNU ELPA and I needed to
remove dash.el
. Doing so turned out to be trivial, as there were obvious built-in
alternatives for everything Flycheck was using:
- I replaced
-if-let(*)
and-when-let(*)
withif-let(*)
andwhen-let(*)
fromsubr-x.el
. - I replaced
-any?
and-first
withseq-find
,-all?
withseq-every-p
and-take
withseq-take
.
And that was it! The whole process literally took me 10 minutes, most of them spent checking whether seq-find
is the right replacement for -any?
and -first
.
One small caveat to keep in mind, when depending on the built-in Emacs packages
like seq.el
, is that you should typically stick to whatever version of the
package was bundled with the version of Emacs that you target (in my case Emacs
26.1 bundles seq.el
2.20), otherwise you’ll need to declare an explicit
package dependency on the newer version. Keep in mind, however, this might
cause some issues in packages that are depending on your package, but not declaring the same dependencies.2 Transitive dependencies in Emacs are a messy topic…
So, all it all it was a very quick and easy process and I can totally recommend
to other packages that are still relying only on basic dash.el
functionality
to replace it as well. Now Flycheck is totally dependency-free and it’s ready for submission
to NonGNU ELPA!
-
Originally authored by yours truly. ↩