The Art Of Not Asking Why
JTR. This is. (also jtr@fosstodon.org) Emacs, org-mode, TiddlyWiki, Linux, DnD, gaming... also coffee, exercise, lifestyle, photography.
taonaw.comJTR. This is. (also jtr@fosstodon.org) Emacs, org-mode, TiddlyWiki, Linux, DnD, gaming... also coffee, exercise, lifestyle, photography.
taonaw.comlisp (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) ### UI and Fundamental Emacs tweaks: Most Emacs folks with a config file like this like to kill the toolbar, scrollbar, and menu bar. I find that the menu bar makes Emacs look more like the other programs, especially in macOS1. Besides, itâs nice to look every now and then and be reminded of good Emacs kung-fu I forgot exists (org-sort, Iâm sorry my friend, Iâll keep saying hi more often). This is why the menu-bar is commented out in my config; I want it, but I also want to remember I could turn it off if I wanted: lisp (tool-bar-mode -1) (scroll-bar-mode -1) ;; (menu-bar-mode -1) By default, help commands2 display the help buffer in a new window without selecting it. I find this annoying: if I bring up the help window, itâs usually because I want to scroll down to find something or copy (yank) something. On the other hand, if I just want to skim quickly in the help buffer, itâs helpful that the marker is on it for a quick q for quit. In addition, we want to be able to navigate help menus as Emacs intended if we follow the links in a help buffer. help-window-keep-selected allows us to keep help in its own dedicated window, so it wonât open in a separate window once we follow a link. Going back to the original is the same as we do in other browser-like buffers in Emacs, with l (like in Eww, for example). Likewise, we can go forward with r. I should also expand here on various help options; they definitely deserve a mention, but this is another huge topic (you can get an idea from the footer) that will take a couple of weeks. I will come back to this someday. lisp (setq help-window-select t) (setq help-window-keep-selected t) Lisp is full of parentheses, and itâs easy to lose track. Turning show-paren-mode on means that standing on an open or closed parentheses highlights its matching counterpart, which is handy. In addition, while weâre here: when we stand on an expression that is only showing a portion of an expression (meaning, we need to scroll down to see the rest) Emacs can highlight the expression for us to make sure we donât get confused â this is the mixed option below for show-paren-style. If you want to see the whole expression highlighted every time youâre on it, thereâs the option expression, which Iâm leaving here for reference for myself. For now, I think itâs too much visual noise, especially since weâre using org-edit-special, which also highlights what weâre working on. lisp (show-paren-mode t) (setq show-paren-style 'mixed) ;; (setq show-paren-style 'expression) And now, a true Emacs classic. I donât think Iâve seen a config without it: shortening âyesâ or âno,â answer to âyâ or ânâ like any other program known to mankind. use-short-answers was introduced in Emacs 28.1, which is a more graceful way to do this, intended exactly for this purpose. Before that, back when I started to use Emacs, it was done with (fset 'yes-or-no-p 'y-or-n-p). If you have an older Emacs version, youâd need it. lisp ;; (fset 'yes-or-no-p 'y-or-n-p) (setq use-short-answers t) This one was annoying until I learned this option exists from someone elseâs config years ago: âEmacs, please stop asking me if I want to kill process when exiting Emacs (Shell, etc.), just do it!â Yep. lisp (setq confirm-kill-processes nil) Emacs has two annoying keyboard shortcuts that I should have disabled as soon as I started using it: C-x C-c (exit Emacs) and C-z (minimize Emacs). Both of them are too easy to press by mistake, especially C-z, which is undo in many other programs. If I had a penny for each time I minimized Emacs by mistake⌠When we want to minimize Emacs (and why would you want to do that? Emacs deserves a prominent space on your screen), we can just do it by clicking the minimize window itself, shamefully using our mouse, as we do with other apps. And Exiting Emacs? With a shortcut that seems like it fits somewhere in org-mode? No thanks. Letâs disable those: lisp (global-unset-key (kbd "C-x C-c")) (global-unset-key (kbd "C-z")) Turn off the annoying error beep, which I first discovered in SUSE Linux by turning on a visual warning (a flash) instead. This will flash the top and bottom lines of our window instead of going âbeep!â lisp (setq visible-bell t) Turn on visual line mode so text lines âwrapâ inside the frame and donât continue beyond the windowâs edge. This is essential; I canât read in Emacs without it. And a newcomer I discovered recently: since Emacs 30, we also have global-visual-wrap-prefix-mode, which preserves indentation on wrapped lines. For example, in a list in org-mode (made of dashes one under the other), a long line of text that wraps will align under its starting point (dash) in the list instead of jumping back to column 0 (the start of the window, to the most left). This has been a huge pet peeve. Finally! lisp (global-visual-line-mode t) (global-visual-wrap-prefix-mode t) Winner mode (included in Emacs) is sort of âundoâ for changes in windowsâ layout in Emacs. C-c â goes back to our previous setting, and C-c â will âredoâ the layout we just left. I use it all the time as in âoops, I closed the wrong windowâ3. lisp (winner-mode t) Saw this over at https://emacsredux.com/blog/2026/04/07/stealing-from-the-best-emacs-configs/. This is a nice little trick, and it requires a bit of reading to understand what exactly it does: preventing Emacs from deleting whatever we have in the systemâs clipboard when we kill a line, so itâs still in the kill ring. Hereâs an example to help you grasp the idea and why itâs useful: 1. Weâre visiting a website with our default browser and copy its URL because we want to write about it in Emacs 2. We go to Emacs, and we kill the line weâre on because we need some space 3. Crap! Now we lost our paste in the clipboard, and we have to go back to the browser and grab that URL again! 4. Wait, which tab was it? Did we close it? Should we look in our browsing history? Ugh! Not anymore! With this little guy, when we kill the line (step 2 above), Emacs âinjectsâ it into the kill ring. Now, when we yank with C-y, we will still get the last line we killed, yes, butlook up the kill ring with M-y and voilĂ ! Your URL is there. No need to go find that URL again: lisp (setq save-interprogram-paste-before-kill t) You know how for years Emacs âjumpedâ when you scrolled down large embedded images in your org buffers? Letâs turn on pixel-scroll-precision-mode for pixel scrolling instead of the default line scrolling to fix this. Itâs pretty much what it reads: the default old way would âscrollâ (itâs actually not scrolling at all) by a line of text at a time. Since our image of, say, 600px in height is treated as a single line of text, it will jump to the end of it. With this option turned on, Emacs would read the pixels from your mouse wheels as you scroll, and we get the smooth scrolling weâre used to. Interesting to know: moving up and down the line without a mouse (arrows, or C-p and C-n) is moving by text lines, utilizing auto-windows-vscroll and line-move, which basically does in Emacs what arrow movement seems to be doing in modern applications: these apply this principle from the other direction â they natively work with pixels, so they treat these arrow movements as a fixed number of pixel movements, which is approximately a line of text. So, when you move up and down a large image (or say a PDF) in a browser, the browser thinks âok, the user is moving up one line of text, which is.. hm.. letâs see⌠ah, it says itâs exactly 40 pixels, so let me show thatâ. lisp (pixel-scroll-precision-mode t) test break âEmacs is the editor of tinkerers and artisans; those who are eternally dissatisfied with all other tools because of their adamantine rigidity. Crafting, or shaping, your tools to meet your exacting needs is what Emacs excels at. Because of that, Emacs is â much to the chagrin of everyone who picks it up for the first time â squarely aimed at people who already know Emacs.â In fact, if youâre curious about help and Emacs help, I suggest you head over there now and read that post. It expands on how to approach Emacs help by how to think Emacs, which is something that experienced Emacs users struggle to explain to newcomers. As for the history of help in Emacs, I think itâs pretty safe to say itâs been there since the start, or at least since Emacs became intended for public use, sometime around the 1980s. By that point, most of the core help parts we know today (the tutorial, C-h t; the Emacs Manual, C-h R; as well as the framework itself) were already in place. The help system was there before GNU Emacs, back in the days of TECO Emacs that RMS worked on at MIT in the 1970s. You could browse the original code from then (preserved by MIT) and see how Stallman explained what certain commands do in emacs.doc inside that repository. Another interesting find about Emacs itself (and the help system that comes with it) is the EMACS paper written by RMS back in 1981. For the help system, take a look at page 17: â6. Self-Documentation and Extensibilityâ and the following chapter in page 18: â7. Historyâ. Fascinating stuff. --- 1. And here, dear reader, I fell down a deep rabbit hole, one that pushed this post a couple of days. There are two parts to this. The Emacs part, which I will explore at some point in the near future, has to do with Emacsâ menu itself, which is controlled by easymenu.el. This is an old Emacs package thatâs been around since 1994, written by RMS himself â kind of. It was first created by Per Abrahamsen (who seems to be a bit of a mystery, but thatâs digging for another day). In turn, this package was taken from lmenu.el, which was part of yet a different Emacs fork at the time. In a regular Emacs style, the menu bar can be completely reconstructed and changed â and thatâs something I want to explore soon as a way to recall useful functions I keep forgetting exist (like having an âorganizeâ menu with something like âorg-sortâ under it). This will be a fun project of its own for another day. Meanwhile, the other, bigger rabbit hole is the story of the GUI menu itself as we have it today. Apple has a big role here, back in the days before Steve Jobs left Apple and worked on the Lisa. This seems to be the first usage of a graphical interface in personal computers, and the menu, which was taken from Xerox, was a big part of it (thereâs a short YouTube video there that would give you a quick brief of what happened). This means that I am right on keeping the menu in theme with the rest of the Mac apps, based on history! âŠď¸ 2. Emacsâ built-in help deserves its own series of posts. Looking at it now, from the eyes of someone who used it for a couple of years, I find Mickyâs description satisfying, reflecting what I felt at the time: âŠď¸ 3. I forget how exactly, but some research into winner-mode history (turns out itâs been around since 1997 â also, a lot of goodies here to look into!) led me down the path of tabs in Emacs, tab-bar in particular. I didnât think much about tabs in Emacs, but since Iâve been using Kubuntu for a while and experimented with its Workspaces, I understand the concept better. I looked into BSAGâs post, and it looks like you can hide the tabs while still displaying them on the mode line, and of course, you donât have to use the mouse. The concept of having a whole workplace completed with its unique window arrangement available with a single keyboard shortcut is alluring. Now, instead of playing around with where and how I want my windows to display, I can just save (or re-create) those, and I always have a âworkâ environment vs a âpersonalâ environment within the same Emacs frame. This can be a good organizational feature. Iâm going to dig more into this one. âŠď¸Option Shift Hyphen, as Sasha would tell you. In Linux, itâs a bit more involved: Ctrl Shift U to bring up a search for Unicode number reference, and then the number for em dash: 2014. This is all good and well, but what about Emacs, where I write most of my text? Emacs comes with abbrev-mode, a powerful text-expanding option that automatically converts something like âomâ to âorg-modeâ, or even âfoxâ to âThe quick brown fox jumps over the lazy dogâ if I wanted to. But the em dash is a bit more tricky. I could, if I wanted, create an abbreviation like âemâ to simply expand to âââ. But this doesnât make much sense. When converting org-mode to markdown (as I do when I post something), the built-in solution for Emacsâ markdown exporter is to convert --- (three dashes) to â, em dash â but this presents two annoyances. First, the built-in exporter would convert those to their character reference, as we just saw: ߞ. I explained this more in-depth previously. Second, even after I fixed this issue by using pandoc, I still see --- in org-mode, not â. This looks like the kind of thing abbrev-mode was made for, right? But itâs a bit more complicated. abbrev-mode triggers only when you type a space after a letter. So, âemâ to â would work, but - to â would not, because a dash is not part of a word1. The solution was simpler than I thought: expand-abbrev, which âExpands the abbrev before point, if there is an abbrev there. Effective when explicitly called even when âabbrev-modeâ is nil.â In other words, it calls expand-abbrev without needing to trigger it the usual way. We simply call the abbrev replacement directly. Now whenever I want an em dash, I type --- first, and then I make sure the marker is right after the last dash, and call expand-abbrev, which in my config is tied to C-x â. I then get an em dash in Emacs, and the exporter in Emacs (or pandoc, in my case) leaves it alone. --- 1. Prot has a related, interesting video about expanding abbrevs with non-word-like characters, which I already use. The problem here is that thereâs nothing âword-likeâ in â. We can work with something like â!wordâ or âword!â because the mechanism that catches abbrevs will recognize a word-like character before or after the â!â (using regex, as explained in the post) and trigger it, but in the case we have above, thereâs nothing that looks like a word to trigger it at all, so it does not work. âŠď¸org-id: You give a header an :ID: property (this is generated automatically1 when you link to a header) and you get a slug, usually a UUID (for me itâs something slightly else, more on that soon below). This stores the links in org-id-locations, which in turn points to a local file with all of these unique IDs. This is good for linking between headers in different files. ### Custom-ID We can set a :CUSTOM_ID: property for a header, and itâs only active in that file. Kind of like a table of contents in a book, with chapters (= headers) listed. If you donât have the book, you donât have its table of contents, so you know nothing about it. To point to a header that has a custom ID: [[#custom-id-value][description]]. ### Plain Target and Radio Target link These are buffer-specific only (no cross-reference between files). In this case, the links are tied to words (anchors), not headers. There are two kinds. The regular plain target link works when we set the anchor first with <<an anchor>>, then call it again with [[an anchor]]. Its more âmagicalâ brother is a radio target link, where we set an anchor like so <<<very special anchor>>> (three angle brackets) and then all we need to do is type very special anchor (no brackets this time), and it works. Note though that when you create a radio target for the first time, you have to revert the buffer or M-x org-update-radio-target-regexp for it to take effect. ### Footnotes 1 : this can be done with a function, org-id-get-create. For a deeper dive into how and why I set my org-id with a date format (not UUID), look here.