Return to the Essence of Text Editing| Emacs Redux
Tree-sitter has taken the world of programming by a storm. Together with LSP, it’s probably the technology that has influenced the most programming editors and IDEs in the past several years. And now that Emacs 29+ comes with built-in Tree-sitter support I’ve been spending a lot of quality time with it, working on clojure-ts-mode and neocaml-mode. There’s a lot I’d like to share with you about using Tree-sitter effectively, but today I’ll focus on a different topic. When most people...| Emacs Redux
Today’s article is going to be a bit more weird than usual… mostly because I’ve set to write about one topic, and ended up about writing something completely different in the end… Here we go! TL;DR Many common macOS keybindings (e.g. Command-s, Command-z, Command-f, etc) work in Emacs. And, of course, it’s well known that macOS uses by default Emacs-like (readline) keybindings everywhere. (e.g. C-a and C-e) I’m guessing 99% of Emacs users know that the most common ways to start is...| Emacs Redux
I’ll be pretty brief today. keyboard-quit (C-g) is one of the most used commands, but unfortunately it’s not very smart. Most annoyingly, it doesn’t work as expected when the minibuffer is active. Fortunately, fixing such problems (and then some) is trivial in Emacs: (defun er-keyboard-quit () "Smater version of the built-in `keyboard-quit'. The generic `keyboard-quit' does not do the expected thing when the minibuffer is open. Whereas we want it to close the minibuffer, even without ex...| Emacs Redux
For many years most Emacs users used setq to set the various configuration options of Emacs and the packages that they were using. This probably wasn’t the best option (read on), but it was the most popular way of doing things. Now, however, it’s finally time for a change!1 Why do we need setopt? In Emacs 29, a new macro setopt was introduced to provide a more appropriate method for setting user options (variables defined with defcustom). As mentioned above, traditionally, Emacs users hav...| Emacs Redux
I’ve been a long time user of flyspell-mode and flyspell-prog-mode, but admittedly I keep forgetting some of it’s keybindings. And there aren’t that many of them to begin with! This article is my n-th attempt to help me memorize anything besides C-c $. So, here we go: M-t (flyspell-auto-correct-word) - press this while in word with typo in it to trigger auto-correct. You can press it repeatedly to cycle through the list of candidates. C-, (flyspell-goto-next-error) - go to the next typo...| Emacs Redux
A well-known Emacs performance optimization advice is to boost the garbage collector threshold (so GC collections happen less frequently). That’s something I’ve had in my Emacs config for ages: ;; reduce the frequency of garbage collection by making it happen on ;; each 50MB of allocated data (the default is on every 0.76MB) (setq gc-cons-threshold 50000000) Probably I should increase it to 100MB+ these days, given the proliferation of more resource-hungry tooling (e.g. LSP). On the other...| Emacs Redux
Relative line numbers (relative to the current line) are super popular in the world of Vim, because there it’s super easy to move n lines up or down wiht j and k. In the world of Emacs most of us tend to just go some line using M-g g using a absolute line number or using avy (avy-goto-line). That being said, relative line numbers are easy to enable in Emacs and quite handy if you’re into evil-mode: (setq display-line-numbers-type 'relative) (global-display-line-numbers-mode +1) Relative l...| Emacs Redux
isearch is probably one of the most widely known Emacs commands. Every Emacs user knows that they can run it using C-s (to search forward) and C-r to search backwards. Everyone also knows they can keep pressing C-s and C-r to go over the list of matches in the current buffer. Even at this point that’s a very useful command. But that doesn’t even scratch the surface of what isearch can do! After you’ve started isearch you can actually do a lot more than pressing C-s and C-r: Type DEL to ...| Emacs Redux
The Escape key (ESC) is legendary in vim, Emacs’s arch-rival. It’s so commonly used (mostly to switch back to normal mode and interrupt commands in progress) that you’ll find many articles on where to remap it (e.g. to Caps Lock), and there are also many keyboards that place ESC where ~ normally is, to make it more accessible.1 In Emacs-land, however, we never really speak about ESC… Why so? Well, we use C-g to interrupt commands, and we obviously don’t have modal editing, at least ...| Emacs Redux
I recently wrote an article on debugging Emacs commands. In it I mentioned M-x toggle-debug-on-error and debug-on-error briefly, but after posting the article I realized that many people probably don’t understand how this works exactly. The obvious thing that happens when debug-on-error is enabled is that when an error happen you’re seeing its backtrace (or stacktrace, depending on the terminology you prefer). What’s not so obvious (even, if it’s in the name) is that this buffer is ac...| Emacs Redux
If you’re using Emacs long enough sooner or later you’ll run into some Emacs command that’s misbehaving and you’ll need to debug it somehow.1 If the command is just blowing up, probably you’ll be able to figure out what’s going on by looking at its backtrace. To get meaningful backtraces you can either run M-x toggle-debug-on-error or add this to your Emacs config: (setq debug-on-error t) Sometimes that will be enough, but other times you’ll need to dig deeper… Fortunately for...| Emacs Redux
Most of the time people ask how to add new keybindings to Emacs and that makes perfect sense. Occasionally, however, the topic of removing keybindings also emerges - e.g. recently Paredit added a keybinding that messed up some REPL mode that were enabling it. The solution was to remove the problematic keybinding: (define-key paredit-mode-map (kbd "RET") nil) Basically to remove a keybinding you just have to set it to nil. This works both for mode-specific keybindings (as demonstrated above) a...| Emacs Redux