TL;DR: Get LLMs to do things from Emacs, with gptel and your help. A short one today, without the usual flourishes. gptel is a large language model (LLM) client for Emacs. At its core is a wrapper around the HTTP APIs provided by all LLM providers, including the smaller language models you can run locally on your machine. At its surface… well, it tries not to have a surface at all, and blend in with Emacs’ design metaphors and affordances instead.| karthinks.com
Continuing my avocation of writing to increasingly niche audiences, today we have a matter at the intersection of several small Venn bubbles: the group of Emacs users who code in Emacs, who use Git (or version control) everywhere, who work using offshoot or feature branches, while using the diff-hl package to visually track changes in their buffers. As minutiae go, this one is quite minute, a real fringe matter.| karthinks.com
Update (2021-05-18): The inimitable Sacha Chua informs me that the functionality proposed in this post is already included in Emacs 28. If you’re using Emacs 27.2 or older, keep reading! Update (2021-05-16): Daniel Mendler, the author of the Consult library, points out that this functionality is also built into Consult as well as Ivy+Counsel. If you’re using these, check out consult-yank-pop (or equivalent) instead. A quick tweak to yanking in Emacs: Many completion systems provide a more...| karthinks.com
Window management in Emacs gets a bad rap. Some of this is deserved, but mostly this is a consequence of combining a very flexible and granular layout system with rather coarse controls. This leaves the door open to creating and using tools for handling windows that employ and provide better metaphors and affordances. As someone who’s spent an unnecessary amount of time trying different approaches to window management in Emacs over the decades, I decided to summarize them here.| karthinks.com
TL;DR: “We have X-references at home” Cross-references in Org mode are not as well developed as its (relatively) new citation system. Org’s built-in linking system is fairly comprehensive and exports to all formats well enough. But if you’re coming to Org from LaTeX, you might prefer something more familiar and oriented towards the label/references mental mapping than the anchor/link system. Over the decades, I drifted into Org mode from writing LaTeX, and brought along RefTeX support.| karthinks.com
A modest defense of the rodent So, Emacs and the mouse. This is an unexpectedly contentious topic, with discussions that end, at best, with careless dismissal. More often they turn into arguments with folks talking past one another. The advantages of using the mouse for common actions in Emacs are immediate and obvious. Window selection is a natural extension of basic mouse usage. Resizing windows is a snap. Context (right-click) menus See context-menu-mode.| karthinks.com
TL;DR: Sometimes Emacs needs a timeout A diamond is very pretty. But it is very hard to add to a diamond. A ball of mud is not so pretty. But you can always add more mud to a ball of mud. – Gerald Sussman, paraphrasing Joel Moses A common problem with Emacs’ giant ball of shared state: Any code can step on the feet of any other – including yours.| karthinks.com
Or: Further Musings on the Tedium of Long Key-Chords. In the past I’ve covered various bespoke approaches to the problem of repeating long key sequences: Transient, Hydra, repeat-mode (and repeat-mode’s helpers) require progressively less forethought and custom elisp chops to set up. Today we continue our aggressive descent into laziness with the simplest way yet to use any Emacs key prefix as a springboard for one-key access to commands. A quick glossary keymap: A “keymap” is an Emac...| karthinks.com
Addressing an innocuous question about the Notmuch email client’s default behavior took me surprisingly deep into the bowels of the package code. When the normal customization methods didn’t help, I realized it might be a good opportunity to live-code a solution. The hope was that it might outline a recipe for reaching into the elisp guts of any library and getting Emacs to do what you want – with no specific prior knowledge.| karthinks.com
If you use Emacs for more than editing text, there are many daily occasions to use Emacs as a pager. Here’s my list: Read-only files (with view-mode) Scrolling through emails (notmuch) RSS feed entries (elfeed) Reading ebooks (nov.el) Web browsing (eww) Man pages (man or woman) Help buffers and Info documents Git logs (magit or vc) System logs, compilation and debug output This list was about half as long ten years ago, it keeps growing!| karthinks.com
This is a post in my Latex editing series, a quick package announcement for better Latex previews. After complaining the other day about Latex previews in org-mode being unbearably slow, I decided to take a crack at adapting Org-mode to use AucTeX’s preview library, which is blazing fast in comparison: [Fast previews in Org] Direct link to video It was both easier and more annoying than I expected it to be, but perhaps less annoying on balance than org-latex-preview locking up Emacs for a g...| karthinks.com
This is a post in my Latex editing series, an awkward solution to a tiny problem. The Problem A common issue with Latex previews in Emacs: The preview images don’t scale when you rescale text in latex-mode or org-mode: [VIDEO] Direct link to video This makes it cumbersome to work with Latex math in Emacs when dealing with different sized monitors or when presenting from Emacs with Org Tree Slide, for example.| karthinks.com
Emacs is reasonably consistent across its major-modes in its common usage patterns and keybindings. For example, C-M-a and C-M-e consistently move you to the beginnings and ends of functions in various language modes, and C-c C-z moves the focus to REPLs and back. In read-only modes n and p move the cursor up and down, and w generally copies the path, address or URL of the buffer to the kill ring.| karthinks.com
One of the first customizations folks make to their Emacs is to hide the menu bar. This makes some sense if you’re using a completion UI like Ivy: it’s usually faster and more convenient to find an option using fuzzy completion in the minibuffer than it is to mouse over a series of menus. Also, the menu covers only options that are relevant to the end-user. If you want fine-grained customization or access to Emacs’ API, you’ll need to use a different interface (like customize).| karthinks.com
Emacs has multiple built-in libraries for folding code, as is the case for most things Emacs. The default interface it exposes for folding functions is unwieldy and cumbersome, as is the case for most things Emacs. There is some overlap between Hideshow-mode and Outline-minor-mode. The latter is mainly for folding and navigating nested Org-like headings, but can be extended with the Foldout library. (Also included in Emacs!) The former works well to hide nested blocks of code.| karthinks.com
Ever since Gilles Castel documented his method for taking math notes in real-time in Vim, I’ve noticed Emacs users asking if it’s possible to replicate this level of speed and convenience typing \(\LaTeX\) in Emacs1. Well, it’s Emacs. Of course all of this–and more–is possible. I write LaTeX all day, and I’m about as fast as when writing equations on paper. Sometimes a smidge faster. In this write-up I explain how, but first here’s what I mean:| karthinks.com
Do not use Elmo. Just making a note here. Following the release of mct.el, I packaged some similar code I had lying around to use Embark live collect buffers as an incremental completion system for Emacs. That is, it does roughly the same thing as other completion systems: allow you to select candidates by typing in stuff at the minibuffer. [VIDEO] Elmo is idiosyncratic. It does not show completions until you type some characters.| karthinks.com
One of the first things new Emacs users learn is the eval-last-sexp (C-x C-e) command and that Emacs can interpret elisp anywhere it appears. Here’s a quick tip about using this command when writing elisp that you may not have discovered. If you call it with a prefix (C-u) argument, it prints (or attempts to print) the result in place in the buffer. Better yet, call it with an argument of 0 (C-0 C-x C-e) to avoid truncating longer results.| karthinks.com
Using an RSS reader instead of visiting Youtube or other social media has many advantages, including that you have to deal with much less energy-sapping, will-eroding clickbait. Unfortunately feed entries can still have clickbaity titles that can DESTROY your patience! So I wrote a dumb-as-rocks declickbaiter for Elfeed. You WON’T BELIEVE the results! The Before (The After will SHOCK you!): The After: The Code: (add-hook 'elfeed-new-entry-hook #'elfeed-declickbait-entry) (defun elfeed-decli...| karthinks.com
Just updated Popper for Emacs with hinting in the echo area: When you toggle a popup, popups for the current context are listed in the echo area along with keyboard hints (M-1 through M-9 by default) to switch to them instantly. The listing is in the order in which the popups are displayed with popper-cycle. Here is a demo of this in action. There is a dispatch feature included that is currently undocumented.| karthinks.com
A quick note that I thought might be interesting to document. As befits a shell written in elisp, eshell is extremely easy to modify to your use. There are a few packages floating around that add autojump/fasd/z type functionality to eshell. These let you jump quickly to any previously visited directory. As it turns out it’s very easy to implement a more powerful version of this by piggybacking off of consult-dir.| karthinks.com
One of the problems with Emacs, especially out of the box, is that its constituents don’t communicate with each other as comprehensively as they ought to. This is expected given the bazaar nature of its development: it’s an amalgamation of elisp libraries written by different contributors over decades, few of whom were aware of many of Emacs’ existing capabilities they could reuse or plug into. I covered a couple of examples of this deficiency in my series on Batteries included with Ema...| karthinks.com
Wrote a thing to handle the annoying window flood in Emacs: Popper-mode was brewing for years as part of my config, I decided to bind it into reasonable shape and submit to MELPA. Code, MELPA, Extended demo, Reddit thread| karthinks.com
Just a short note for today, as the super-fast-latex post is still cooking: Emacs provides a few mechanisms to manage buffer/window state as a group. There’s current-window-configuration (and its register variants) and desktop-save, and you can act on groups of buffers by every predicate imaginable in ibuffer. But the window configurations vaporize when you shut down Emacs, and they don’t handle unopened file buffers. desktop-read is an all-or-nothing affair. Somehow there’s no clear wa...| karthinks.com
Continuing from last time, here are a dozen more tricks Emacs has up its sleeve that it’s shy about telling you. We continue to chip away at Emacs' discoverability problem, one demo at a time. Same rules as before: No packages, stock Emacs only No steep learning curves. Learn each feature in under five minutes or bust. (Up from two minutes last time.) No gimmicks.| karthinks.com
Emacs has a reputation for being borderline unusable out of the box, of being bloated but somehow surprisingly bare. This is largely a discoverability problem1. The solution the Internet has settled on seems to be “Emacs distributions” like Doom, Spacemacs or Prelude that glue together dozens (sometimes hundreds) of addons to deliver a batteries included, finely tuned and user-friendly experience from first launch. While it’s not for me, this does work great 2, and many of these packag...| karthinks.com
Elfeed, the feed reader for Emacs, is built on several clever ideas. The basic mode of interaction in Elfeed is through search, specifying what kinds of feeds you want to peruse at the moment. This removes the distinction between an inbox and a search result, which works surprisingly well with the expressive search syntax. The second is integration: search results can be stored as regular bookmarks, and jumping to the bookmark from anywhere in Emacs will run the corresponding query and presen...| karthinks.com
Update (2021-10-16): While this list was intended as a demonstration of the kinds of things you can do with Embark, there has been some interest by readers in reproducing these demos exactly on their machines. So I have added a “Play by play” section under each demo listing the sequence of actions in the demo. Embark is a fantastic and thoughtfully designed package for Emacs that flips Emacs’ action → object ordering without adding a learning curve.| karthinks.com
You’re using Avy wrong. Too harsh? Let me rephrase: you’re barely using Avy. Still too broad? Okay, the noninflammatory version: Avy, the Emacs package to jump around the screen, lends itself to efficient composable usage that’s obscured by default. Without burying the lede any further, here’s a demo that uses a single Avy command (avy-goto-char-timer) to do various things in multiple buffers and windows, all without manually moving the cursor:| karthinks.com
Emacs 29 is getting native Tree-Sitter support, and the buzz is hard to miss. Tree-Sitter maintains and provides a concrete parse tree of the buffer that you can query, but that’s as far as it goes. Acting on this information to provide context-aware navigation and editing tools is left to package authors, who have picked up this baton and started running with it! In the last few months we’ve had structural editing packages popping up all over the place.| karthinks.com
Are you tired of pressing C-x o repeatedly to switch to the window you want in Emacs? Or M-g n and M-g p to cycle through compile errors or grep matches? How about navigating outline headings with (yuck) C-c @ C-n and C-c @ C-p? The correct answer to the latter is that no one traverses headings this way, because these keybindings are atrocious. Even the shorter ones start to grate when you need to use them repeatedly in an editing session.| karthinks.com