John Wiegley and Sacha Chua on use-package

A couple years ago, John Wiegley and Sacha Chua made a video about Wiegley’s use-package package. I’ve mentioned it a couple of times in passing but never written about it. Recently, I stumbled across it again and rewatched it.

There’s a lot of interesting material in the video and I decided that even though it’s old it was worth writing about. If you aren’t already using use-package, you should definitely take a look. The package really does make your configuration simpler and more logical. It can even be used to speed up Emacs’ start time: Wiegley reports that he has over 200 package and his Emacs starts in about a third of a second.

Even if, like me, you’re already using use-package, there’s still a good reason to spend a half hour watching the video. Wiegley discusses some things I didn’t know about. First is the macrostep package. If you only use it to see exactly what use-package is doing, it’s worth installing. The use-package macro confuses many people. If you watch the video and then expand an invocation of the macro in your configuration, you’ll easily understand what’s going on. It’s really easy to use and if you bind a key sequence to invoke it1, it won’t be loaded until you need it.

Another thing I learned is that you can fold the text in a buffer so that any text that starts more than n columns from the left margin isn’t shown. Oddly, this is a built in functionality (bound to Ctrl+x $) so you don’t need to get anything to use it.

Once you start using use-package, you’ll automatically pull in bind-key so you’ll have describe-personal-keybindings available. When you invoke it, you’ll get a nice list of all the keybindings you’ve defined along with what, if anything, they replaced. That can be really handy for organizing your configuration.

Finally, one of the nice things about use-package is that you can configure it to record how long it takes to load and configure the packages it loads. That can really be handy for tracking down the hot spots in your configuration load time. It all goes into the *Message* buffer so you can ignore it except when you need it.

I really like use-package and have converted my entire init.el to use it. If you aren’t already using it, you should start and the video will go a long way towards convincing you of that.

UPDATE [2017-07-21 Fri 11:58]: Added link to video.

Footnotes:

1

Or you can ask use-package to delay loading it explicitly.

This entry was posted in General and tagged . Bookmark the permalink.
  • Kaligule

    How can you write an article about a video and then not link it?

    • jcs

      Oops. Sorry. Link added.

  • For example this is pretty useful:


    (setq use-package-always-ensure t)

    • jcs

      I use use-package to require and configure built-in packages too. If the package in not in ELPA (of various flavors), I get an error if I specify :ensure t. Do you know what happens what happens in this case if use-package-always-ensure t is specified?

      • I just tried it and my Emacs was really unhappy and complaining all the time.

        • Win Treese

          You can use :ensure nil on built-in packages in this situation (that is, with use-package-always-ensure t).

          • jcs

            Of course. Dumb of me not to think of that.

          • Win Treese

            It's not that obvious. My original idea was that :ensure t meant "ensure that this library is present", rather than "ensure that this package has been downloaded".

          • Thank you.

  • Karl

    Does anybody know the command John is using all the time to replace some elisp code with its definition(s)? I tried abbrev-expand but it does nothing but consume up CPU time.

    • NoonianAtall

      Haven't watched the video yet, but maybe it's eval-print-last-sexp.

      • Karl

        Unfortunately not: eval-print-last-sexp replaces an expression with its result. I am looking for the command which does replace an expression with its definition. So it is rather the opposite ;-)
        Thanks for any pointer.

        • NoonianAtall

          Sorry, I don't understand what you mean by "replace an expression with its definition." Can you give an example?

          • Karl

            Look at the video at 2:50.

          • NoonianAtall

            I guess you mean macrostep? If you rewind to 2:40 he mentions it.

          • Karl

            Thanks! I completely misinterpreted his comment ;-)
            You're right - macrostep it is. Thanks for helping me find this great thing!

  • Bubbles

    So you looove use-package. Me too ;)