Posts

  • Smarter Minibuffer Prompts in Projectile

    Projectile asks you a lot of questions. What do you want to search for? Replace it with what? Which command should I run? For as long as I can remember those prompts were about as dumb as a prompt can be - an empty line, maybe with the symbol at point as the default, and you had to type the rest.

    That’s a bit silly when you think about it, because by the time Projectile asks you something it already knows quite a lot - the project you’re in, the function your cursor is sitting in, the Makefile at the root of the project and what’s in it. I’ve been meaning to do something about this for ages, and in the upcoming Projectile 3.5 a bunch of prompts finally start to use that knowledge. Let’s go over them!

    The Search Prompt

    Every command that asks what to search for (projectile-search, projectile-grep, projectile-ripgrep, the search reviewer, projectile-find-references and friends) now uses the same prompt. It’s still a plain text prompt, so whatever you type is what gets searched for, but it has learned a few new tricks:

    • RET on an empty prompt searches for the symbol at point (or the region), as before
    • M-n goes through a few more guesses - the name of the function you’re in, the name of the current file and the last thing you looked for with Isearch
    • M-p goes through your previous searches, and the search prompts now have a history of their own
    • TAB completes the word before point against the identifiers that occur in the project (super handy)

    Here’s all of this in action:

    The search prompt going through its suggestions with M-n and then completing a typed prefix against the project's identifiers with TAB

    The TAB completion is my favorite part. I can never remember whether something was named projectile-replace-review or projectile-review-replace, and now I don’t have to! The candidates are sorted by how often they show up in the project, so the names you actually use end up at the top.

    Where do the candidates come from? There’s no index and no tags file involved. Projectile just runs rg (or git grep, if you don’t have ripgrep installed) for the prefix you’ve typed and collects the words that start with it. That takes a few milliseconds on a small project and a fraction of a second on something as big as Emacs itself. Not too shabby, right? You need to type at least two characters for the completion to kick in. And if you don’t like it, you can always turn it off:

    (setq projectile-search-complete-identifiers nil)
    

    Note: You might be wondering why the prompt isn’t simply using completing-read. That would have been the easiest way to get completion, but with something like Vertico pressing RET would then select the current candidate instead of what you’ve typed, and I really don’t want a search prompt that second-guesses my input. That’s why it’s a plain read-from-minibuffer with a completion-at-point function installed in it, so TAB works the same way it does in a code buffer. In the screencast above the candidates are displayed by consult-completion-in-region. Without it you’ll get the stock *Completions* buffer.

    The Replace Prompts

    projectile-replace reads what to replace with the same prompt, so everything above applies there as well. When it asks what to replace it with, M-n brings up the original text. After all, most replacements are a small edit of the thing they replace (e.g. a rename), so it’s nice not to have to type it again.

    With a prefix argument the search and replace commands ask which files to work on, and those prompts now complete over the file extensions that are actually present in the project. (the most common ones come first)

    The Command Prompts

    The compile, test and run prompts got the same treatment. M-p has always gone through the commands you’ve run before. Now M-n goes the other way - through commands you haven’t run yet, but the project suggests - the default command for the project’s type, followed by the commands of its tasks (Make targets, npm scripts, just recipes and so on). The tasks named after what you’re doing come first, so the test prompt starts with things like make test:

    The test command prompt going from npm test through the project's test tasks with M-n

    The same suggestions show up on M-n when you run a shell command in the project root with s-p ! or s-p &.

    Filtering Search Results

    Projectile’s search and replace results buffers have had filters for a while - k/d to keep or flush matches by line, and K/D to do the same by file. The file filters expect a regular expression and most of the time people type pretty much the same thing there - something like ^test/.

    Now the prompt suggests it for you. The default is the directory of the match at point, and M-n goes on to that file’s extension, the file itself and then the top-level directories that have matches, busiest first. Getting rid of all the matches in the tests is D RET:

    Flushing every match under test/ from the search results by accepting the default the prompt suggests

    Odds and Ends

    • C-u s-p C (projectile-find-changed-file with a prefix argument) asks for a revision to compare against. It now defaults to the project’s main branch, whatever it happens to be called, and it completes over tags as well, so “what changed since the last release” is a M-n or two away.
    • projectile-add-known-project starts at the root of the project you’re in, instead of whatever subdirectory the current buffer lives in.

    M-n is Underrated

    You’ve probably noticed that M-n shows up in pretty much every section of this article. Every Emacs user knows that M-p in the minibuffer goes back through the history. I’m not sure how many people know that M-n goes forward, into what the Emacs manual calls “future history” - a list of guesses that the command has made about what you might want to type. A lot of built-in commands provide those (try M-n at the query-replace or find-file prompts), but you’ll never see them unless you ask, so they are easy to miss. It’s one of those fairly obscure Emacs features that really deserve to be better known.

    For package authors that’s probably the cheapest way to make a prompt smarter. The functions that read from the minibuffer (read-string, read-from-minibuffer, completing-read, read-shell-command) all accept a list as their default value, and that list is what M-n goes through:

    (read-string "Search for: " nil 'my-search-history
                 (delq nil
                       (list (thing-at-point 'symbol t)
                             (add-log-current-defun)
                             (and buffer-file-name
                                  (file-name-base buffer-file-name)))))
    

    It doesn’t get in anyone’s way, it works with every completion framework, and it’s only a few lines of code. I plan to write a bit more about M-n soon, as it certainly deserves an article of its own.

    Closing Thoughts

    None of those changes is a big deal on its own, but together they make Projectile feel a lot smarter to me. All of this will be a part of Projectile 3.5, and most of it is already available in the master branch if you want to play with it today. If you can think of other prompts that could do a better job of guessing what you want - I’d love to hear about them!

    That’s all I have for you today. Keep hacking!

  • Emacs Prelude 2.2

    Emacs Prelude 2.2 is out! 2.0 and 2.1 shipped within a few days of each other back in March, while 2.2 took eight months and about 150 commits. It’s a big one!

    Read More
  • Working with Git Worktrees in Magit

    I’ll admit that until fairly recently I had no idea git worktrees existed. They’ve been part of git for a decade1 and I never once needed them. Feature branches did the job just fine - create a branch, do the work, merge it, delete it, and start over.

    What finally introduced me to worktrees was, of all things, AI coding agents. Tools like Claude Code create a worktree for each task, so several agents (or several sessions of the same agent) can work on the same repo in parallel without stepping on each other - or on you. Suddenly my projects directory was full of cider-this and cider-that siblings, and I figured I should understand what’s actually going on there.

    1. They were introduced in git 2.5, released all the way back in July 2015. ↩

    Read More
  • Meet Utterson, my Jekyll blogging helper

    Back in 2019 I wrote about dealing with Jekyll post URLs, where I shared a tiny command that spared me from having to remember the exact file name of every article I wanted to link to. That command has been in my config ever since, and over the years it quietly grew a few siblings. Recently I finally gathered them all in one place and turned them into a small package - utterson.

    The common Jekyll tasks

    I guess anyone who blogs with Jekyll knows the drill. Jekyll is great and I have no intention of switching, but a few of its conventions generate a steady trickle of manual work:

    • posts live in _posts and their file names have to start with the publication date, as in 2026-08-26-some-post.md
    • every article needs a bit of YAML front matter at the top - a layout, a title, a date, some tags
    • linking to another post means using a Liquid tag that wants that date-prefixed file name, which nobody remembers
    • images and other assets need URLs relative to the site root, not to the article you happen to be editing

    None of this is hard. All of it is annoying, and all of it is exactly the sort of mechanical work an editor should be doing on your behalf. So over the years I wrote a command for each chore, dropped it in my init.el and moved on with my life.

    Why I finally cleaned this up

    The tipping point was the last command I added - promoting a draft to a post.

    I write most articles in _drafts, where jekyll serve --drafts shows them but a deploy doesn’t. Publishing one used to mean renaming the file by hand to add today’s date, then editing the date in the front matter to match, then convincing git that this was a rename rather than a delete plus a brand new file. Three chances to get something wrong, and I certainly got it wrong more than once.

    Once that was automated I took a look at what had accumulated in my config and realized it wasn’t a bag of snippets anymore - it was a workflow. And since every person blogging with Jekyll from Emacs deals with exactly the same chores, there was no good reason to keep it to myself. So I spent an evening extracting the lot, wrote some tests, and gave it a name.1

    There are other Jekyll packages for Emacs, of course. Both hyde and easy-jekyll aim to be something like an IDE for your site, with dashboards, deployment and preview buffers. That’s a perfectly reasonable thing to want, it’s just never been what I wanted. My site lives in git, I deploy it with a push, and I’ve already got Magit and a browser. All I ever wanted was for the bookkeeping to stop being my problem.

    So utterson is deliberately small. It knows that a Jekyll site is a folder of Markdown files with YAML front matter, and that’s about the extent of its ambitions. Renames go through vc, so git records them as renames and the history of an article follows it around. Nothing in there ever deploys anything.

    Taking it for a spin

    The package is not on MELPA (yet?), so for the time being it’s package-vc territory:

    (use-package utterson
      :vc (:url "https://github.com/bbatsov/utterson" :rev :newest)
      :custom
      ;; where to look for sites, when you invoke a command outside one
      (utterson-search-path '("~/projects/"))
      :config
      ;; the commands live in a keymap that you bind wherever you please
      (keymap-set utterson-mode-map "C-c j" 'utterson-command-map)
      (global-utterson-mode +1))
    

    global-utterson-mode enables the minor mode in the buffers of any folder that has a _config.yml in it, so the commands are around while you’re working on a site and nowhere else.

    C-c j p starts a post. It asks for a title, offers a file name slug derived from it (which you’re free to shorten right there, and I usually do), then asks for tags, completing against every tag the site already uses. That last bit is how you avoid ending up with both Emacs and emacs in your tag cloud. Finally it writes the front matter, saves the file and leaves the cursor exactly where you’re about to start writing:

    ---
    layout: post
    title: Meet Utterson, my Jekyll blogging helper
    date: 2026-08-26 15:01 +0300
    tags:
    - Jekyll
    - Blogs
    - Packages
    ---
    

    That block, as it happens, is the one this very article started with. Here’s the whole thing in action:

    Creating a new post with utterson: the title prompt, the slug derived from it, tag completion, and the finished front matter

    C-c j d does the same in _drafts and C-c j t moves an article between the two, dating it on the way in and staging the rename with git. C-c j r is for the article you wrote a couple of weeks ago and never got around to publishing - it sets the date to now and renames the file to match. Both of them take a prefix argument if you’d rather type a date than accept the current time, which is how you schedule something for next Monday morning.

    Publishing a draft looks like this - notice that the file name, the date in the front matter and git’s idea of what happened all stay in sync:

    Publishing a draft with utterson: the file is renamed with today's date, the front matter date is updated, and git records a rename

    The linking commands are the descendants of that 2019 snippet, all grown up. C-c j u inserts a post_url tag, completing over your posts newest first and showing you each post’s title next to its file name, and C-c j l inserts the entire Markdown link, already titled after the post it points to:

    Inserting a link to another post: the completion list shows every post newest first, with its title next to the file name

    C-c j i inserts an image, C-c j I copies a file into your images folder first (perfect for a screenshot that’s still sitting on your desktop under a name like Screenshot 2026-08-26 at 15.01.12.png), and C-c j a links to anything else under assets. And C-c j s runs jekyll serve in a buffer, because sooner or later you do want to look at the thing.

    Note: There’s a menu as well, in case you’d rather click your way around while the keybindings are still settling in.

    Epilogue

    It’s early days for the package, even though most of the code behind it has been in daily use for years. If you blog with Jekyll from Emacs, I’d love to hear which of your own little chores it doesn’t cover yet - that’s the fastest way for it to get better.

    And if you don’t blog with Jekyll - what does your setup look like? I’ve got the feeling that quite a few of you are writing your posts in org-mode and I’m always curious about the workflows people come up with.

    That’s all I have for you today! Keep hacking!

    1. Gabriel John Utterson is Doctor Jekyll’s loyal friend and lawyer - the man who keeps his affairs in order. Naming things is hard, but every now and then you get lucky. ↩

  • Flycheck 38: Might & Magic

    Not all those who wander are lost.

    – J.R.R. Tolkien

    Today I’m happy to announce Flycheck 38 - easily the biggest and most ambitious Flycheck release since I took over the stewardship of the project. It’s the release where Flycheck grows a proper story for language servers, gets the kind of inline diagnostics you’d expect from a modern editor, and learns to apply fixes - all without giving up the checker model that made it popular in the first place.

    The version number, I’ll admit, doesn’t do this one justice - it’s just the next integer after 37, and nothing about “38” whispers “special”. But that’s how it goes with version numbers: some releases are more special than others, and you’d rarely guess which from the number alone.

    Read More

Subscribe via RSS | View Older Posts