Endless Parentheses

Concise ramblings on Emacs productivity.

New in Emacs 25.1: Filtering by status and archive

For several reasons, the Package Menu’s f key has always flown a bit under the radar for me. Though the package-menu-filter command is great in principle, in practice its usefulness falls a little short for several reasons.

One reason, which is in no way its own fault, is that Emacs already has great searching facilities such as isearch or occur. It’s just easier and faster to fall back on what you know rather than try out something new. This not exactly something that needs fixing, but it can be improved by focusing the filter command on doing things what other facilities can’t do.

Now you might be thinking, “doesn’t this command filter by package keywords? Isearch can’t do that.”

And that takes us to the second (probably most relevant) reason. The list of keywords used by packages is an ugly mess. And that’s not something easy to fix. Before investing too much resource on this never-ending struggle against entropy, Emacs 25.1 will make a simple improvement that goes a long way. You can filter multiple comma-separated keywords at once. So, for instance, you can mitigate the redundancy between the theme and themes keywords by just searching for theme,themes.

Furthermore, sometimes there’s a good improvement available that is completely orthogonal to the problem you have. Instead of fixing up keywords, we can also have package-menu-filter offer other features that alternate facilities don’t —preferably one that doesn’t rely on the supernatural cooperation of a thousand monkeys typing elisp. As of Emacs 25.1, you may now filter packages by status or by archive, by writing arc:ARCHIVE and status:STATUS respectively when you invoke the command.

Of lesser importance, there was also a third usability issue with the command. It took a couple of seconds to load every time you invoked it. That, fortunately, was much simpler to solve, and I’ll even leave it as an exercise to the reader!

In the following (very streamline) function, place point anywhere you want and then invoke a single keybind (from emacs -q, your custom keybinds don’t count). If you do it right, you can improve its speed a hundred-fold. Can you see how?

(defun package-all-keywords ()
  "Collect all package keywords"
  ;; `package--mapc' simply calls the lambda on each
  ;; known package. `package-desc--keywords' returns
  ;; the package's list of keywords.
  (let ((key-list))
    (package--mapc
     (lambda (pkg)
       (setq key-list
             (append key-list
                     (package-desc--keywords pkg)))))
    key-list))

Check in again next Monday for the last post on this series, where we talk about prioritizing your package archives.

Tags: emacs-25, package, emacs

Say thanks on Gratipay
comments powered by Disqus