<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Karthinks</title>
    <link>https://karthinks.com/</link>
    <description>Recent content on Karthinks</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <copyright>Karthik Chikmagalur</copyright>
    <lastBuildDate>Sun, 01 Nov 2026 08:00:00 -0700</lastBuildDate><atom:link href="https://karthinks.com/index.xml" rel="self" type="application/rss+xml" /><item>
      <title>Understanding Org&#39;s LaTeX previews</title>
      <link>https://karthinks.com/software/understanding-org-latex-preview/</link>
      <pubDate>Sun, 01 Nov 2026 08:00:00 -0700</pubDate>
      
      <guid>https://karthinks.com/software/understanding-org-latex-preview/</guid>
      <description>&lt;div class=&#34;subtitle&#34;&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;: LaTeX in Org mode now go &lt;strong&gt;whoosh&lt;/strong&gt;, all pretty like.  Install the development branch of Org mode to use it.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;After grumbling about the inadequacy of LaTeX previews in Emacs &amp;ndash; and specifically Org mode &amp;ndash; for over a decade, &lt;a href=&#34;https://tecosaur.net/&#34;&gt;Tecosaur&lt;/a&gt; and I decided to take the leap and rewrite the feature from the ground up.  The result is a preview system for LaTeX math that can provide near-WYSIWYG feedback but retains the properties we expect in the Emacs environment: text-first, extensible and composable.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--org-latex-preview-youtube-demo&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/olp-auto-mode-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/olp-auto-mode-1.mp4&#34;&gt;[org-latex-preview video demo 1]&lt;/a&gt;&lt;/video&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/olp-auto-mode-inline-3.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/olp-auto-mode-inline-1.mp4&#34;&gt;[org-latex-preview video demo 3: inline math]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;It&amp;rsquo;s not much code, but it contains many moving pieces and makes contact with several corners of Emacs.  Now that the feature is part of Org mode, I thought I would take this opportunity to document how it works from the ground up, and use it as a launchpad to explain relevant aspects of Emacs&amp;rsquo; event loop and its unofficial package API
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Emacs doesn&amp;rsquo;t really have a &amp;ldquo;package API&amp;rdquo;, since you build Emacs packages from the same elements as Emacs itself.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;This article is not an exhaustive demo of all the shiny new features, although there are a few videos peppered throughout.  It&amp;rsquo;s also not the user manual (not yet updated on orgmode.org) or a tutorial (see Tecosaur&amp;rsquo;s &lt;a href=&#34;https://blog.tecosaur.net/tmio/2026-11-01-preview.html&#34;&gt;This Month in Org&lt;/a&gt; writeup).&lt;/p&gt;
&lt;p&gt;Instead, it aims to provide an overview of the goals and design of the library, along with some explainers of relevant aspects of the Emacs API and tips to write your own features.  This write-up is for you if you are interested in&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a broad understanding of LaTeX preview generation (how and why),&lt;/li&gt;
&lt;li&gt;learning about Emacs&amp;rsquo; event loop, subprocess interaction, overlay-based display and UI, or&lt;/li&gt;
&lt;li&gt;a case study on building a non-trivial Emacs &amp;ldquo;application&amp;rdquo; from scratch.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;svg class=&#34;inline-svg&#34; xmlns:xlink=&#34;http://www.w3.org/1999/xlink&#34; width=&#34;396.39685pt&#34; height=&#34;396.39685pt&#34; viewBox=&#34;0 0 396.39685 396.39685&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34; version=&#34;1.1&#34;&gt;
 &lt;metadata&gt;
  &lt;rdf:RDF xmlns:dc=&#34;http://purl.org/dc/elements/1.1/&#34; xmlns:cc=&#34;http://creativecommons.org/ns#&#34; xmlns:rdf=&#34;http://www.w3.org/1999/02/22-rdf-syntax-ns#&#34;&gt;
   &lt;cc:Work&gt;
    &lt;dc:type rdf:resource=&#34;http://purl.org/dc/dcmitype/StillImage&#34;/&gt;
    &lt;dc:date&gt;2026-10-31T23:13:41.307683&lt;/dc:date&gt;
    &lt;dc:format&gt;image/svg+xml&lt;/dc:format&gt;
    &lt;dc:creator&gt;
     &lt;cc:Agent&gt;
      &lt;dc:title&gt;Matplotlib v3.11.1, https://matplotlib.org/&lt;/dc:title&gt;
     &lt;/cc:Agent&gt;
    &lt;/dc:creator&gt;
   &lt;/cc:Work&gt;
  &lt;/rdf:RDF&gt;
 &lt;/metadata&gt;
 
 &lt;g id=&#34;figure_1&#34;&gt;
  &lt;g id=&#34;patch_1&#34;&gt;
   &lt;path d=&#34;M 0 396.39685 
L 396.39685 396.39685 
L 396.39685 0 
L 0 0 
L 0 396.39685 
z
&#34; style=&#34;fill: none; opacity: 0&#34;/&gt;
  &lt;/g&gt;
  &lt;g id=&#34;axes_1&#34;&gt;
   &lt;g id=&#34;patch_2&#34;&gt;
    &lt;path d=&#34;M 19.467549 197.971654 
Q 198.425197 197.971654 377.382845 197.971654 
&#34; style=&#34;fill: none; stroke: #808080; stroke-width: 2.2; stroke-linecap: round&#34;/&gt;
    &lt;path d=&#34;M 27.467549 201.971654 
L 19.467549 197.971654 
L 27.467549 193.971654 
&#34; style=&#34;fill: none; stroke: #808080; stroke-width: 2.2; stroke-linecap: round&#34;/&gt;
    &lt;path d=&#34;M 369.382845 193.971654 
L 377.382845 197.971654 
L 369.382845 201.971654 
&#34; style=&#34;fill: none; stroke: #808080; stroke-width: 2.2; stroke-linecap: round&#34;/&gt;
   &lt;/g&gt;
   &lt;g id=&#34;patch_3&#34;&gt;
    &lt;path d=&#34;M 198.425197 376.929302 
Q 198.425197 197.971654 198.425197 19.014005 
&#34; style=&#34;fill: none; stroke: #808080; stroke-width: 2.2; stroke-linecap: round&#34;/&gt;
    &lt;path d=&#34;M 202.425197 368.929302 
L 198.425197 376.929302 
L 194.425197 368.929302 
&#34; style=&#34;fill: none; stroke: #808080; stroke-width: 2.2; stroke-linecap: round&#34;/&gt;
    &lt;path d=&#34;M 194.425197 27.014005 
L 198.425197 19.014005 
L 202.425197 27.014005 
&#34; style=&#34;fill: none; stroke: #808080; stroke-width: 2.2; stroke-linecap: round&#34;/&gt;
   &lt;/g&gt;
   &lt;g id=&#34;patch_4&#34;&gt;
    &lt;path d=&#34;M 26.418898 52.093465 
L 115.313386 52.093465 
Q 123.029291 52.093465 123.029291 44.377559 
L 123.029291 34.085433 
Q 123.029291 26.369528 115.313386 26.369528 
L 26.418898 26.369528 
Q 18.702992 26.369528 18.702992 34.085433 
L 18.702992 44.377559 
Q 18.702992 52.093465 26.418898 52.093465 
z
&#34; clip-path=&#34;url(#p9faeef5dad)&#34; style=&#34;fill: #a3b09a&#34;/&gt;
   &lt;/g&gt;
   &lt;g id=&#34;patch_5&#34;&gt;
    &lt;path d=&#34;M 252.873071 52.093465 
L 382.087559 52.093465 
Q 389.803465 52.093465 389.803465 44.377559 
L 389.803465 34.085433 
Q 389.803465 26.369528 382.087559 26.369528 
L 252.873071 26.369528 
Q 245.157165 26.369528 245.157165 34.085433 
L 245.157165 44.377559 
Q 245.157165 52.093465 252.873071 52.093465 
z
&#34; clip-path=&#34;url(#p9faeef5dad)&#34; style=&#34;fill: #a3b09a&#34;/&gt;
   &lt;/g&gt;
   &lt;g id=&#34;patch_6&#34;&gt;
    &lt;path d=&#34;M 11.31874 372.438425 
L 130.413543 372.438425 
Q 138.149291 372.438425 138.149291 364.702677 
L 138.149291 354.390236 
Q 138.149291 346.654488 130.413543 346.654488 
L 11.31874 346.654488 
Q 3.582992 346.654488 3.582992 354.390236 
L 3.582992 364.702677 
Q 3.582992 372.438425 11.31874 372.438425 
z
&#34; clip-path=&#34;url(#p9faeef5dad)&#34; style=&#34;fill: #a3b09a&#34;/&gt;
   &lt;/g&gt;
   &lt;g id=&#34;patch_7&#34;&gt;
    &lt;path d=&#34;M 278.702362 372.408425 
L 367.59685 372.408425 
Q 375.312756 372.408425 375.312756 364.69252 
L 375.312756 354.400394 
Q 375.312756 346.684488 367.59685 346.684488 
L 278.702362 346.684488 
Q 270.986457 346.684488 270.986457 354.400394 
L 270.986457 364.69252 
Q 270.986457 372.408425 278.702362 372.408425 
z
&#34; clip-path=&#34;url(#p9faeef5dad)&#34; style=&#34;fill: #a3b09a&#34;/&gt;
   &lt;/g&gt;
   &lt;g id=&#34;patch_8&#34;&gt;
    &lt;path d=&#34;M 55.788661 209.087622 
L 153.975118 209.087622 
Q 160.645039 209.087622 160.645039 202.417701 
L 160.645039 193.525606 
Q 160.645039 186.855685 153.975118 186.855685 
L 55.788661 186.855685 
Q 49.11874 186.855685 49.11874 193.525606 
L 49.11874 202.417701 
Q 49.11874 209.087622 55.788661 209.087622 
z
&#34; clip-path=&#34;url(#p9faeef5dad)&#34; style=&#34;fill: #b18bb1&#34;/&gt;
   &lt;/g&gt;
   &lt;g id=&#34;patch_9&#34;&gt;
    &lt;path d=&#34;M 249.789921 209.087622 
L 339.816378 209.087622 
Q 346.486299 209.087622 346.486299 202.417701 
L 346.486299 193.525606 
Q 346.486299 186.855685 339.816378 186.855685 
L 249.789921 186.855685 
Q 243.12 186.855685 243.12 193.525606 
L 243.12 202.417701 
Q 243.12 209.087622 249.789921 209.087622 
z
&#34; clip-path=&#34;url(#p9faeef5dad)&#34; style=&#34;fill: #b18bb1&#34;/&gt;
   &lt;/g&gt;
   &lt;g id=&#34;patch_10&#34;&gt;
    &lt;path d=&#34;M 192.958677 119.888504 
L 203.891717 119.888504 
Q 212.092346 119.888504 212.092346 111.687874 
L 212.092346 46.145197 
Q 212.092346 37.944567 203.891717 37.944567 
L 192.958677 37.944567 
Q 184.758047 37.944567 184.758047 46.145197 
L 184.758047 111.687874 
Q 184.758047 119.888504 192.958677 119.888504 
z
&#34; clip-path=&#34;url(#p9faeef5dad)&#34; style=&#34;fill: #b18bb1&#34;/&gt;
   &lt;/g&gt;
   &lt;g id=&#34;patch_11&#34;&gt;
    &lt;path d=&#34;M 192.958677 351.985512 
L 203.891717 351.985512 
Q 212.092346 351.985512 212.092346 343.784882 
L 212.092346 261.922205 
Q 212.092346 253.721575 203.891717 253.721575 
L 192.958677 253.721575 
Q 184.758047 253.721575 184.758047 261.922205 
L 184.758047 343.784882 
Q 184.758047 351.985512 192.958677 351.985512 
z
&#34; clip-path=&#34;url(#p9faeef5dad)&#34; style=&#34;fill: #b18bb1&#34;/&gt;
   &lt;/g&gt;
   &lt;g id=&#34;patch_12&#34;&gt;
    &lt;path d=&#34;M 69.653858 310.181783 
L 145.779213 310.181783 
Q 158.679685 310.181783 158.679685 297.281311 
L 158.679685 280.079319 
Q 158.679685 267.178846 145.779213 267.178846 
L 69.653858 267.178846 
Q 56.753386 267.178846 56.753386 280.079319 
L 56.753386 297.281311 
Q 56.753386 310.181783 69.653858 310.181783 
z
&#34; clip-path=&#34;url(#p9faeef5dad)&#34; style=&#34;fill: #d2a566&#34;/&gt;
   &lt;/g&gt;
   &lt;g id=&#34;patch_13&#34;&gt;
    &lt;a xlink:href=&#34;https://orgmode.org/manual/&#34; target=&#34;_blank&#34;&gt;
     &lt;path d=&#34;M 256.899213 310.294283 
L 321.368504 310.294283 
Q 334.337008 310.294283 334.337008 297.32578 
L 334.337008 280.03485 
Q 334.337008 267.066346 321.368504 267.066346 
L 256.899213 267.066346 
Q 243.930709 267.066346 243.930709 280.03485 
L 243.930709 297.32578 
Q 243.930709 310.294283 256.899213 310.294283 
z
&#34; clip-path=&#34;url(#p9faeef5dad)&#34; style=&#34;fill: #d2a566&#34;/&gt;
    &lt;/a&gt;
   &lt;/g&gt;
   &lt;g id=&#34;patch_14&#34;&gt;
    &lt;a xlink:href=&#34;https://blog.tecosaur.net/tmio/2026-11-01-preview.html&#34; target=&#34;_blank&#34;&gt;
     &lt;path d=&#34;M 253.191496 139.168252 
L 325.07622 139.168252 
Q 340.817008 139.168252 340.817008 123.427465 
L 340.817008 102.437102 
Q 340.817008 86.696315 325.07622 86.696315 
L 253.191496 86.696315 
Q 237.450709 86.696315 237.450709 102.437102 
L 237.450709 123.427465 
Q 237.450709 139.168252 253.191496 139.168252 
z
&#34; clip-path=&#34;url(#p9faeef5dad)&#34; style=&#34;fill: #d2a566&#34;/&gt;
    &lt;/a&gt;
   &lt;/g&gt;
   &lt;g id=&#34;text_1&#34;&gt;
    &lt;!-- Tutorials --&gt;
    &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(25.866142 44.511496) scale(0.2 -0.2)&#34;&gt;
     &lt;defs&gt;
      &lt;path id=&#34;UbuntuMono-Regular-37&#34; d=&#34;M 2950 3962 
L 2950 3514 
L 1862 3514 
L 1862 0 
L 1338 0 
L 1338 3514 
L 250 3514 
L 250 3962 
L 2950 3962 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-58&#34; d=&#34;M 2746 83 
Q 2573 38 2288 -13 
Q 2003 -64 1619 -64 
Q 1280 -64 1056 35 
Q 832 134 691 316 
Q 550 499 492 748 
Q 435 998 435 1299 
L 435 2970 
L 960 2970 
L 960 1414 
Q 960 864 1123 633 
Q 1286 403 1670 403 
Q 1754 403 1840 409 
Q 1926 416 2003 425 
Q 2080 435 2137 444 
Q 2195 454 2214 461 
L 2214 2970 
L 2746 2970 
L 2746 83 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-57&#34; d=&#34;M 1555 2970 
L 2810 2970 
L 2810 2528 
L 1555 2528 
L 1555 1146 
Q 1555 922 1587 781 
Q 1619 640 1692 553 
Q 1766 467 1881 435 
Q 1997 403 2163 403 
Q 2394 403 2534 441 
Q 2675 480 2803 544 
L 2880 96 
Q 2790 58 2595 -6 
Q 2400 -70 2112 -70 
Q 1779 -70 1568 6 
Q 1357 83 1238 236 
Q 1120 390 1075 617 
Q 1030 845 1030 1146 
L 1030 2528 
L 403 2528 
L 403 2970 
L 1030 2970 
L 1030 3802 
L 1555 3891 
L 1555 2970 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-52&#34; d=&#34;M 2944 1485 
Q 2944 1133 2845 848 
Q 2746 563 2566 358 
Q 2387 154 2137 42 
Q 1888 -70 1594 -70 
Q 1306 -70 1059 42 
Q 813 154 633 358 
Q 454 563 355 848 
Q 256 1133 256 1485 
Q 256 1837 355 2125 
Q 454 2413 633 2614 
Q 813 2816 1059 2928 
Q 1306 3040 1594 3040 
Q 1888 3040 2137 2928 
Q 2387 2816 2566 2614 
Q 2746 2413 2845 2125 
Q 2944 1837 2944 1485 
z
M 2400 1485 
Q 2400 1990 2182 2281 
Q 1965 2573 1594 2573 
Q 1229 2573 1014 2281 
Q 800 1990 800 1485 
Q 800 986 1014 694 
Q 1229 403 1594 403 
Q 1965 403 2182 694 
Q 2400 986 2400 1485 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-55&#34; d=&#34;M 685 0 
L 685 2810 
Q 1338 3034 2003 3034 
Q 2208 3034 2393 3018 
Q 2579 3002 2803 2950 
L 2707 2483 
Q 2502 2541 2345 2557 
Q 2189 2573 2003 2573 
Q 1613 2573 1210 2464 
L 1210 0 
L 685 0 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-4c&#34; d=&#34;M 1338 3430 
Q 1171 3430 1049 3545 
Q 928 3661 928 3859 
Q 928 4058 1049 4173 
Q 1171 4288 1338 4288 
Q 1510 4288 1628 4173 
Q 1747 4058 1747 3859 
Q 1747 3661 1628 3545 
Q 1510 3430 1338 3430 
z
M 1203 2528 
L 346 2528 
L 346 2970 
L 1728 2970 
L 1728 1146 
Q 1728 704 1849 553 
Q 1971 403 2214 403 
Q 2400 403 2557 448 
Q 2714 493 2803 544 
L 2880 96 
Q 2842 77 2771 48 
Q 2701 19 2608 -6 
Q 2515 -32 2403 -51 
Q 2291 -70 2170 -70 
Q 1888 -70 1702 6 
Q 1517 83 1405 236 
Q 1293 390 1248 617 
Q 1203 845 1203 1146 
L 1203 2528 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-44&#34; d=&#34;M 1632 378 
Q 1830 378 1987 390 
Q 2144 403 2246 422 
L 2246 1306 
Q 2144 1338 2000 1357 
Q 1856 1376 1696 1376 
Q 1549 1376 1408 1353 
Q 1267 1331 1158 1273 
Q 1050 1216 979 1123 
Q 909 1030 909 890 
Q 909 602 1104 490 
Q 1299 378 1632 378 
z
M 1581 3040 
Q 1914 3040 2141 2957 
Q 2368 2874 2509 2726 
Q 2650 2579 2707 2368 
Q 2765 2157 2765 1907 
L 2765 51 
Q 2579 19 2275 -25 
Q 1971 -70 1651 -70 
Q 1408 -70 1177 -28 
Q 947 13 768 118 
Q 589 224 480 409 
Q 371 595 371 883 
Q 371 1139 483 1315 
Q 595 1491 771 1600 
Q 947 1709 1174 1757 
Q 1402 1805 1632 1805 
Q 1946 1805 2246 1734 
L 2246 1882 
Q 2246 2016 2217 2141 
Q 2189 2266 2109 2368 
Q 2029 2470 1891 2531 
Q 1754 2592 1536 2592 
Q 1261 2592 1056 2553 
Q 851 2515 742 2477 
L 678 2912 
Q 787 2963 1040 3001 
Q 1293 3040 1581 3040 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-4f&#34; d=&#34;M 2163 -70 
Q 1882 -70 1696 6 
Q 1510 83 1401 236 
Q 1293 390 1248 617 
Q 1203 845 1203 1146 
L 1203 3955 
L 346 3955 
L 346 4403 
L 1728 4403 
L 1728 1146 
Q 1728 922 1757 781 
Q 1786 640 1846 553 
Q 1907 467 1996 435 
Q 2086 403 2208 403 
Q 2394 403 2554 448 
Q 2714 493 2803 544 
L 2880 96 
Q 2842 77 2771 48 
Q 2701 19 2605 -6 
Q 2509 -32 2397 -51 
Q 2285 -70 2163 -70 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-56&#34; d=&#34;M 2246 742 
Q 2246 902 2115 1004 
Q 1984 1107 1789 1184 
Q 1594 1261 1363 1334 
Q 1133 1408 937 1517 
Q 742 1626 611 1786 
Q 480 1946 480 2202 
Q 480 2560 771 2800 
Q 1062 3040 1683 3040 
Q 1926 3040 2185 3005 
Q 2445 2970 2630 2912 
L 2534 2438 
Q 2483 2464 2393 2493 
Q 2304 2522 2189 2544 
Q 2074 2566 1942 2579 
Q 1811 2592 1690 2592 
Q 998 2592 998 2214 
Q 998 2080 1129 1987 
Q 1261 1894 1459 1817 
Q 1658 1741 1888 1661 
Q 2118 1581 2316 1465 
Q 2515 1350 2646 1187 
Q 2778 1024 2778 774 
Q 2778 371 2464 150 
Q 2150 -70 1472 -70 
Q 1165 -70 909 -19 
Q 653 32 422 134 
L 525 614 
Q 749 512 995 445 
Q 1242 378 1523 378 
Q 2246 378 2246 742 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
     &lt;/defs&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-37&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-58&#34; transform=&#34;translate(50 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-57&#34; transform=&#34;translate(100 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-52&#34; transform=&#34;translate(150 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-55&#34; transform=&#34;translate(200 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-4c&#34; transform=&#34;translate(250 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-44&#34; transform=&#34;translate(300 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-4f&#34; transform=&#34;translate(350 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-56&#34; transform=&#34;translate(400 0)&#34;/&gt;
    &lt;/g&gt;
   &lt;/g&gt;
   &lt;g id=&#34;text_2&#34;&gt;
    &lt;!-- How-To Guides --&gt;
    &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(252.480315 44.511496) scale(0.2 -0.2)&#34;&gt;
     &lt;defs&gt;
      &lt;path id=&#34;UbuntuMono-Regular-2b&#34; d=&#34;M 2387 3962 
L 2912 3962 
L 2912 0 
L 2387 0 
L 2387 1843 
L 813 1843 
L 813 0 
L 288 0 
L 288 3962 
L 813 3962 
L 813 2291 
L 2387 2291 
L 2387 3962 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-5a&#34; d=&#34;M 2195 0 
Q 2099 218 2028 397 
Q 1958 576 1891 755 
Q 1824 934 1757 1129 
Q 1690 1325 1600 1574 
Q 1510 1325 1440 1129 
Q 1370 934 1302 755 
Q 1235 576 1161 397 
Q 1088 218 992 0 
L 595 0 
Q 416 787 297 1558 
Q 179 2330 122 2970 
L 621 2970 
Q 640 2720 662 2480 
Q 685 2240 717 1977 
Q 749 1715 790 1408 
Q 832 1101 883 717 
Q 986 973 1056 1165 
Q 1126 1357 1184 1529 
Q 1242 1702 1296 1881 
Q 1350 2061 1414 2285 
L 1811 2285 
Q 1875 2061 1926 1881 
Q 1978 1702 2035 1529 
Q 2093 1357 2157 1165 
Q 2221 973 2317 723 
Q 2374 1075 2419 1376 
Q 2464 1677 2496 1942 
Q 2528 2208 2553 2457 
Q 2579 2707 2598 2970 
L 3078 2970 
Q 3046 2650 3001 2285 
Q 2957 1920 2893 1536 
Q 2829 1152 2752 758 
Q 2675 365 2592 0 
L 2195 0 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-10&#34; d=&#34;M 896 1875 
L 2304 1875 
L 2304 1376 
L 896 1376 
L 896 1875 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-3&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-2a&#34; d=&#34;M 2387 1952 
L 2912 1952 
L 2912 96 
Q 2790 51 2521 -16 
Q 2253 -83 1888 -83 
Q 1530 -83 1235 54 
Q 941 192 733 454 
Q 525 717 409 1104 
Q 294 1491 294 1984 
Q 294 2483 422 2867 
Q 550 3251 771 3513 
Q 992 3776 1286 3913 
Q 1581 4051 1920 4051 
Q 2138 4051 2304 4019 
Q 2470 3987 2588 3942 
Q 2707 3898 2784 3850 
Q 2861 3802 2899 3776 
L 2726 3334 
Q 2579 3450 2377 3523 
Q 2176 3597 1952 3597 
Q 1709 3597 1501 3481 
Q 1293 3366 1145 3155 
Q 998 2944 915 2646 
Q 832 2349 832 1984 
Q 832 1626 905 1331 
Q 979 1037 1120 825 
Q 1261 614 1469 496 
Q 1677 378 1946 378 
Q 2131 378 2233 403 
Q 2336 429 2387 454 
L 2387 1952 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-47&#34; d=&#34;M 2214 2342 
Q 2125 2426 1952 2499 
Q 1779 2573 1594 2573 
Q 1382 2573 1232 2489 
Q 1082 2406 986 2262 
Q 890 2118 845 1916 
Q 800 1715 800 1485 
Q 800 966 1043 684 
Q 1286 403 1677 403 
Q 1875 403 2012 422 
Q 2150 442 2214 461 
L 2214 2342 
z
M 2214 4346 
L 2746 4435 
L 2746 83 
Q 2573 32 2304 -19 
Q 2035 -70 1677 -70 
Q 1357 -70 1094 38 
Q 832 147 646 348 
Q 461 550 358 838 
Q 256 1126 256 1485 
Q 256 1830 342 2115 
Q 429 2400 595 2605 
Q 762 2810 995 2925 
Q 1229 3040 1530 3040 
Q 1766 3040 1945 2982 
Q 2125 2925 2214 2861 
L 2214 4346 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-48&#34; d=&#34;M 1658 3040 
Q 2259 3040 2585 2665 
Q 2912 2291 2912 1530 
L 2912 1344 
L 787 1344 
Q 819 883 1091 643 
Q 1363 403 1856 403 
Q 2138 403 2336 448 
Q 2534 493 2637 544 
L 2707 96 
Q 2611 45 2361 -12 
Q 2112 -70 1798 -70 
Q 1414 -70 1123 48 
Q 832 166 640 371 
Q 448 576 352 861 
Q 256 1146 256 1478 
Q 256 1875 377 2169 
Q 499 2464 697 2656 
Q 896 2848 1145 2944 
Q 1395 3040 1658 3040 
z
M 2374 1773 
Q 2374 2150 2176 2371 
Q 1978 2592 1651 2592 
Q 1466 2592 1315 2521 
Q 1165 2451 1056 2336 
Q 947 2221 883 2073 
Q 819 1926 800 1773 
L 2374 1773 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
     &lt;/defs&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2b&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-52&#34; transform=&#34;translate(50 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-5a&#34; transform=&#34;translate(100 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-10&#34; transform=&#34;translate(150 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-37&#34; transform=&#34;translate(200 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-52&#34; transform=&#34;translate(250 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-3&#34; transform=&#34;translate(300 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2a&#34; transform=&#34;translate(350 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-58&#34; transform=&#34;translate(400 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-4c&#34; transform=&#34;translate(450 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-47&#34; transform=&#34;translate(500 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-48&#34; transform=&#34;translate(550 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-56&#34; transform=&#34;translate(600 0)&#34;/&gt;
    &lt;/g&gt;
   &lt;/g&gt;
   &lt;g id=&#34;text_3&#34;&gt;
    &lt;!-- Explanations --&gt;
    &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(10.866142 364.826457) scale(0.2 -0.2)&#34;&gt;
     &lt;defs&gt;
      &lt;path id=&#34;UbuntuMono-Regular-28&#34; d=&#34;M 582 0 
L 582 3962 
L 2803 3962 
L 2803 3514 
L 1107 3514 
L 1107 2298 
L 2592 2298 
L 2592 1850 
L 1107 1850 
L 1107 448 
L 2944 448 
L 2944 0 
L 582 0 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-5b&#34; d=&#34;M 2432 0 
Q 2368 128 2275 281 
Q 2182 435 2073 598 
Q 1965 762 1846 922 
Q 1728 1082 1613 1222 
Q 1498 1075 1370 915 
Q 1242 755 1123 592 
Q 1005 429 902 275 
Q 800 122 730 0 
L 186 0 
Q 397 384 701 790 
Q 1005 1197 1299 1562 
L 230 2970 
L 826 2970 
L 1626 1933 
L 2362 2970 
L 2925 2970 
L 1946 1594 
Q 2234 1216 2525 806 
Q 2816 397 3021 0 
L 2432 0 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-53&#34; d=&#34;M 2400 1478 
Q 2400 1997 2157 2281 
Q 1914 2566 1523 2566 
Q 1306 2566 1181 2547 
Q 1056 2528 986 2502 
L 986 627 
Q 1075 544 1248 473 
Q 1421 403 1606 403 
Q 1818 403 1968 486 
Q 2118 570 2214 714 
Q 2310 858 2355 1053 
Q 2400 1248 2400 1478 
z
M 2944 1478 
Q 2944 1139 2857 854 
Q 2771 570 2608 365 
Q 2445 160 2208 45 
Q 1971 -70 1670 -70 
Q 1434 -70 1254 -12 
Q 1075 45 986 115 
L 986 -1056 
L 454 -1056 
L 454 2880 
Q 627 2931 899 2982 
Q 1171 3034 1523 3034 
Q 1843 3034 2105 2925 
Q 2368 2816 2553 2614 
Q 2739 2413 2841 2125 
Q 2944 1837 2944 1478 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-51&#34; d=&#34;M 454 2886 
Q 742 2957 1027 2995 
Q 1312 3034 1562 3034 
Q 2157 3034 2461 2726 
Q 2765 2419 2765 1741 
L 2765 0 
L 2240 0 
L 2240 1645 
Q 2240 1933 2189 2112 
Q 2138 2291 2045 2390 
Q 1952 2490 1821 2528 
Q 1690 2566 1536 2566 
Q 1408 2566 1264 2550 
Q 1120 2534 986 2509 
L 986 0 
L 454 0 
L 454 2886 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
     &lt;/defs&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-28&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-5b&#34; transform=&#34;translate(50 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-53&#34; transform=&#34;translate(100 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-4f&#34; transform=&#34;translate(150 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-44&#34; transform=&#34;translate(200 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-51&#34; transform=&#34;translate(250 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-44&#34; transform=&#34;translate(300 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-57&#34; transform=&#34;translate(350 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-4c&#34; transform=&#34;translate(400 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-52&#34; transform=&#34;translate(450 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-51&#34; transform=&#34;translate(500 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-56&#34; transform=&#34;translate(550 0)&#34;/&gt;
    &lt;/g&gt;
   &lt;/g&gt;
   &lt;g id=&#34;text_4&#34;&gt;
    &lt;!-- Reference --&gt;
    &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(278.149606 364.826457) scale(0.2 -0.2)&#34;&gt;
     &lt;defs&gt;
      &lt;path id=&#34;UbuntuMono-Regular-35&#34; d=&#34;M 2758 2752 
Q 2758 2387 2566 2108 
Q 2374 1830 2048 1677 
Q 2144 1523 2262 1328 
Q 2381 1133 2502 912 
Q 2624 691 2742 457 
Q 2861 224 2963 0 
L 2400 0 
Q 2208 461 1981 883 
Q 1754 1306 1542 1568 
Q 1504 1562 1430 1562 
Q 1357 1562 1331 1562 
L 883 1562 
L 883 0 
L 352 0 
L 352 3904 
Q 448 3930 573 3949 
Q 698 3968 829 3977 
Q 960 3987 1088 3993 
Q 1216 4000 1318 4000 
Q 2035 4000 2396 3686 
Q 2758 3373 2758 2752 
z
M 1363 3546 
Q 1216 3546 1078 3542 
Q 941 3539 883 3526 
L 883 1997 
L 1222 1997 
Q 1453 1997 1635 2029 
Q 1818 2061 1949 2147 
Q 2080 2234 2150 2384 
Q 2221 2534 2221 2778 
Q 2221 3008 2150 3155 
Q 2080 3302 1965 3388 
Q 1850 3475 1693 3510 
Q 1536 3546 1363 3546 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-49&#34; d=&#34;M 1030 0 
L 1030 2528 
L 403 2528 
L 403 2970 
L 1030 2970 
L 1030 3238 
Q 1030 3584 1126 3811 
Q 1222 4038 1379 4179 
Q 1536 4320 1744 4377 
Q 1952 4435 2182 4435 
Q 2413 4435 2646 4384 
Q 2880 4333 3085 4262 
L 2989 3808 
Q 2848 3878 2637 3929 
Q 2426 3981 2208 3981 
Q 2074 3981 1955 3945 
Q 1837 3910 1747 3824 
Q 1658 3738 1606 3594 
Q 1555 3450 1555 3232 
L 1555 2970 
L 2752 2970 
L 2752 2528 
L 1555 2528 
L 1555 0 
L 1030 0 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-46&#34; d=&#34;M 314 1478 
Q 314 1882 442 2176 
Q 570 2470 794 2662 
Q 1018 2854 1315 2947 
Q 1613 3040 1952 3040 
Q 2170 3040 2384 3011 
Q 2598 2982 2842 2906 
L 2720 2451 
Q 2509 2528 2333 2550 
Q 2157 2573 1978 2573 
Q 1747 2573 1542 2512 
Q 1338 2451 1187 2320 
Q 1037 2189 947 1981 
Q 858 1773 858 1478 
Q 858 1197 941 995 
Q 1024 794 1174 662 
Q 1325 531 1536 467 
Q 1747 403 2003 403 
Q 2208 403 2397 425 
Q 2586 448 2810 525 
L 2886 83 
Q 2662 0 2432 -35 
Q 2202 -70 1933 -70 
Q 1574 -70 1276 29 
Q 979 128 764 320 
Q 550 512 432 803 
Q 314 1094 314 1478 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
     &lt;/defs&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-35&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-48&#34; transform=&#34;translate(50 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-49&#34; transform=&#34;translate(100 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-48&#34; transform=&#34;translate(150 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-55&#34; transform=&#34;translate(200 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-48&#34; transform=&#34;translate(250 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-51&#34; transform=&#34;translate(300 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-46&#34; transform=&#34;translate(350 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-48&#34; transform=&#34;translate(400 0)&#34;/&gt;
    &lt;/g&gt;
   &lt;/g&gt;
   &lt;g id=&#34;text_5&#34;&gt;
    &lt;!-- FOR LEARNING --&gt;
    &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(56.88189 202.195654) scale(0.16 -0.16)&#34;&gt;
     &lt;defs&gt;
      &lt;path id=&#34;UbuntuMono-Regular-29&#34; d=&#34;M 582 0 
L 582 3962 
L 2829 3962 
L 2829 3514 
L 1107 3514 
L 1107 2278 
L 2624 2278 
L 2624 1837 
L 1107 1837 
L 1107 0 
L 582 0 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-32&#34; d=&#34;M 186 1984 
Q 186 2515 288 2905 
Q 390 3296 576 3549 
Q 762 3802 1021 3926 
Q 1280 4051 1600 4051 
Q 1914 4051 2176 3926 
Q 2438 3802 2624 3549 
Q 2810 3296 2915 2905 
Q 3021 2515 3021 1984 
Q 3021 1453 2915 1062 
Q 2810 672 2624 416 
Q 2438 160 2176 38 
Q 1914 -83 1600 -83 
Q 1280 -83 1021 38 
Q 762 160 576 416 
Q 390 672 288 1062 
Q 186 1453 186 1984 
z
M 723 1984 
Q 723 1203 934 787 
Q 1146 371 1587 371 
Q 2035 371 2259 787 
Q 2483 1203 2483 1984 
Q 2483 2765 2259 3181 
Q 2035 3597 1587 3597 
Q 1146 3597 934 3181 
Q 723 2765 723 1984 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-2f&#34; d=&#34;M 2944 448 
L 2944 0 
L 582 0 
L 582 3962 
L 1107 3962 
L 1107 448 
L 2944 448 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-24&#34; d=&#34;M 2586 0 
L 2349 1037 
L 826 1037 
L 595 0 
L 58 0 
Q 166 422 300 915 
Q 435 1408 592 1926 
Q 749 2445 921 2966 
Q 1094 3488 1286 3962 
L 1939 3962 
Q 2125 3488 2294 2966 
Q 2464 2445 2614 1926 
Q 2765 1408 2899 915 
Q 3034 422 3142 0 
L 2586 0 
z
M 1594 3501 
Q 1446 3098 1273 2566 
Q 1101 2035 947 1472 
L 2227 1472 
Q 2080 2048 1910 2582 
Q 1741 3117 1594 3501 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-31&#34; d=&#34;M 2310 0 
Q 2093 531 1901 963 
Q 1709 1395 1533 1772 
Q 1357 2150 1184 2486 
Q 1011 2822 832 3162 
L 832 0 
L 352 0 
L 352 3962 
L 890 3962 
Q 1152 3482 1347 3123 
Q 1542 2765 1705 2429 
Q 1869 2093 2022 1737 
Q 2176 1382 2368 915 
L 2368 3962 
L 2848 3962 
L 2848 0 
L 2310 0 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-2c&#34; d=&#34;M 1862 3514 
L 1862 448 
L 2630 448 
L 2630 0 
L 570 0 
L 570 448 
L 1338 448 
L 1338 3514 
L 570 3514 
L 570 3962 
L 2630 3962 
L 2630 3514 
L 1862 3514 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
     &lt;/defs&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-29&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-32&#34; transform=&#34;translate(50 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-35&#34; transform=&#34;translate(100 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-3&#34; transform=&#34;translate(150 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2f&#34; transform=&#34;translate(200 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-28&#34; transform=&#34;translate(250 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-24&#34; transform=&#34;translate(300 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-35&#34; transform=&#34;translate(350 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-31&#34; transform=&#34;translate(400 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2c&#34; transform=&#34;translate(450 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-31&#34; transform=&#34;translate(500 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2a&#34; transform=&#34;translate(550 0)&#34;/&gt;
    &lt;/g&gt;
   &lt;/g&gt;
   &lt;g id=&#34;text_6&#34;&gt;
    &lt;!-- FOR WORKING --&gt;
    &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(250.80315 202.195654) scale(0.16 -0.16)&#34;&gt;
     &lt;defs&gt;
      &lt;path id=&#34;UbuntuMono-Regular-3a&#34; d=&#34;M 979 0 
L 486 0 
Q 429 390 387 860 
Q 346 1331 310 1843 
Q 275 2355 249 2892 
Q 224 3430 205 3962 
L 717 3962 
L 787 653 
L 1363 2458 
L 1824 2458 
L 2413 653 
L 2483 3962 
L 2995 3962 
Q 2976 3424 2947 2886 
Q 2918 2349 2880 1840 
Q 2842 1331 2797 864 
Q 2752 397 2701 0 
L 2214 0 
L 1594 1971 
L 979 0 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-2e&#34; d=&#34;M 3008 3962 
Q 2694 3494 2320 3033 
Q 1946 2573 1510 2112 
Q 1715 1939 1945 1708 
Q 2176 1478 2397 1206 
Q 2618 934 2813 627 
Q 3008 320 3142 0 
L 2547 0 
Q 2387 294 2201 576 
Q 2016 858 1808 1101 
Q 1600 1344 1379 1545 
Q 1158 1747 934 1894 
L 934 0 
L 410 0 
L 410 3962 
L 934 3962 
L 934 2195 
Q 1350 2624 1731 3091 
Q 2112 3558 2400 3962 
L 3008 3962 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
     &lt;/defs&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-29&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-32&#34; transform=&#34;translate(50 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-35&#34; transform=&#34;translate(100 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-3&#34; transform=&#34;translate(150 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-3a&#34; transform=&#34;translate(200 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-32&#34; transform=&#34;translate(250 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-35&#34; transform=&#34;translate(300 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2e&#34; transform=&#34;translate(350 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2c&#34; transform=&#34;translate(400 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-31&#34; transform=&#34;translate(450 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2a&#34; transform=&#34;translate(500 0)&#34;/&gt;
    &lt;/g&gt;
   &lt;/g&gt;
   &lt;g id=&#34;text_7&#34;&gt;
    &lt;!-- PRACTICAL --&gt;
    &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(202.649197 114.916535) rotate(-90) scale(0.16 -0.16)&#34;&gt;
     &lt;defs&gt;
      &lt;path id=&#34;UbuntuMono-Regular-33&#34; d=&#34;M 1504 4000 
Q 1856 4000 2121 3910 
Q 2387 3821 2563 3657 
Q 2739 3494 2825 3270 
Q 2912 3046 2912 2771 
Q 2912 2150 2547 1814 
Q 2182 1478 1453 1478 
L 992 1478 
L 992 0 
L 467 0 
L 467 3904 
Q 582 3930 720 3949 
Q 858 3968 995 3981 
Q 1133 3994 1264 3997 
Q 1395 4000 1504 4000 
z
M 1542 3546 
Q 1376 3546 1222 3542 
Q 1069 3539 992 3526 
L 992 1926 
L 1427 1926 
Q 1907 1926 2140 2118 
Q 2374 2310 2374 2752 
Q 2374 3546 1542 3546 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-Regular-26&#34; d=&#34;M 2944 166 
Q 2720 38 2467 -22 
Q 2214 -83 1926 -83 
Q 1574 -83 1276 41 
Q 979 166 761 419 
Q 544 672 419 1062 
Q 294 1453 294 1984 
Q 294 2490 425 2874 
Q 557 3258 781 3520 
Q 1005 3782 1305 3916 
Q 1606 4051 1946 4051 
Q 2182 4051 2428 3987 
Q 2675 3923 2912 3776 
L 2758 3341 
Q 2336 3584 1965 3584 
Q 1702 3584 1494 3472 
Q 1286 3360 1139 3149 
Q 992 2938 912 2643 
Q 832 2349 832 1984 
Q 832 1574 918 1273 
Q 1005 973 1158 774 
Q 1312 576 1526 480 
Q 1741 384 1990 384 
Q 2176 384 2381 432 
Q 2586 480 2803 602 
L 2944 166 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
     &lt;/defs&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-33&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-35&#34; transform=&#34;translate(50 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-24&#34; transform=&#34;translate(100 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-26&#34; transform=&#34;translate(150 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-37&#34; transform=&#34;translate(200 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2c&#34; transform=&#34;translate(250 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-26&#34; transform=&#34;translate(300 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-24&#34; transform=&#34;translate(350 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2f&#34; transform=&#34;translate(400 0)&#34;/&gt;
    &lt;/g&gt;
   &lt;/g&gt;
   &lt;g id=&#34;text_8&#34;&gt;
    &lt;!-- THEORETICAL --&gt;
    &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(202.649197 346.853543) rotate(-90) scale(0.16 -0.16)&#34;&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-37&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2b&#34; transform=&#34;translate(50 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-28&#34; transform=&#34;translate(100 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-32&#34; transform=&#34;translate(150 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-35&#34; transform=&#34;translate(200 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-28&#34; transform=&#34;translate(250 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-37&#34; transform=&#34;translate(300 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2c&#34; transform=&#34;translate(350 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-26&#34; transform=&#34;translate(400 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-24&#34; transform=&#34;translate(450 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-Regular-2f&#34; transform=&#34;translate(500 0)&#34;/&gt;
    &lt;/g&gt;
   &lt;/g&gt;
   &lt;g id=&#34;text_9&#34;&gt;
    &lt;!-- ⊙ You are --&gt;
    &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(63.997239 285.069721) scale(0.19 -0.19)&#34;&gt;
     &lt;defs&gt;
      &lt;path id=&#34;DejaVuSansMono-BoldOblique-834&#34; d=&#34;M 1403 2547 
L 2444 2547 
L 2444 1406 
L 1403 1406 
L 1403 2547 
z
M 1220 3721 
Q 1547 3859 1926 3859 
Q 2306 3859 2632 3721 
Q 2959 3584 3231 3316 
Q 3500 3044 3638 2716 
Q 3772 2391 3772 2006 
Q 3772 1631 3638 1303 
Q 3503 978 3231 706 
Q 2959 438 2632 300 
Q 2306 163 1926 163 
Q 1547 163 1220 300 
Q 894 438 622 706 
Q 350 978 216 1303 
Q 81 1631 81 2006 
Q 81 2391 216 2716 
Q 353 3044 622 3316 
Q 894 3584 1220 3721 
z
M 2400 3159 
Q 2181 3253 1926 3253 
Q 1672 3253 1450 3159 
Q 1234 3066 1053 2888 
Q 869 2703 780 2484 
Q 691 2266 691 2006 
Q 691 1756 780 1537 
Q 869 1319 1053 1134 
Q 1234 956 1450 863 
Q 1672 769 1926 769 
Q 2181 769 2400 863 
Q 2619 956 2800 1134 
Q 2984 1319 3073 1537 
Q 3163 1756 3163 2006 
Q 3163 2266 3073 2484 
Q 2984 2703 2800 2888 
Q 2619 3066 2400 3159 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-BoldItalic-3&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-BoldItalic-3c&#34; d=&#34;M 1990 2176 
Q 2093 2323 2240 2544 
Q 2387 2765 2540 3011 
Q 2694 3258 2844 3507 
Q 2995 3757 3110 3962 
L 3955 3962 
Q 3757 3635 3561 3328 
Q 3366 3021 3161 2720 
Q 2957 2419 2729 2121 
Q 2502 1824 2246 1510 
L 1882 0 
L 1094 0 
L 1453 1504 
Q 1254 2125 1126 2717 
Q 998 3309 909 3962 
L 1683 3962 
Q 1722 3501 1808 3037 
Q 1894 2573 1990 2176 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-BoldItalic-52&#34; d=&#34;M 1638 602 
Q 1830 602 1977 717 
Q 2125 832 2230 1005 
Q 2336 1178 2390 1379 
Q 2445 1581 2445 1760 
Q 2445 2061 2358 2233 
Q 2272 2406 2003 2406 
Q 1818 2406 1667 2291 
Q 1517 2176 1414 2003 
Q 1312 1830 1257 1628 
Q 1203 1427 1203 1248 
Q 1203 947 1289 774 
Q 1376 602 1638 602 
z
M 1478 -83 
Q 941 -83 678 224 
Q 416 531 416 1043 
Q 416 1427 531 1792 
Q 646 2157 870 2445 
Q 1094 2733 1427 2909 
Q 1760 3085 2195 3085 
Q 2662 3085 2947 2800 
Q 3232 2515 3232 1952 
Q 3232 1574 3123 1209 
Q 3014 845 2793 557 
Q 2573 269 2243 93 
Q 1914 -83 1478 -83 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-BoldItalic-58&#34; d=&#34;M 1414 -70 
Q 896 -70 691 173 
Q 486 416 486 838 
Q 486 1133 576 1523 
L 934 3008 
L 1722 3008 
L 1382 1574 
Q 1331 1382 1305 1225 
Q 1280 1069 1280 947 
Q 1280 614 1600 614 
Q 1779 614 1884 688 
Q 1990 762 2086 870 
Q 2099 960 2108 1043 
Q 2118 1126 2150 1235 
L 2573 3008 
L 3360 3008 
L 2931 1229 
Q 2906 1114 2890 1002 
Q 2874 890 2874 774 
Q 2874 589 2912 413 
Q 2950 237 3008 64 
L 2317 -51 
Q 2304 -26 2285 12 
Q 2266 51 2246 96 
Q 2227 141 2214 176 
Q 2202 211 2195 230 
Q 2067 134 1862 32 
Q 1658 -70 1414 -70 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-BoldItalic-44&#34; d=&#34;M 1606 602 
Q 1786 602 1907 682 
Q 2029 762 2118 870 
Q 2131 960 2144 1043 
Q 2157 1126 2182 1235 
L 2458 2374 
Q 2387 2394 2310 2400 
Q 2234 2406 2163 2406 
Q 1939 2406 1760 2300 
Q 1581 2195 1453 2022 
Q 1325 1850 1257 1626 
Q 1190 1402 1190 1165 
Q 1190 998 1219 889 
Q 1248 781 1302 717 
Q 1357 653 1433 627 
Q 1510 602 1606 602 
z
M 1318 -70 
Q 896 -64 653 233 
Q 410 531 410 1101 
Q 410 1536 557 1901 
Q 704 2266 960 2525 
Q 1216 2784 1558 2928 
Q 1901 3072 2285 3072 
Q 2547 3072 2816 3021 
Q 3085 2970 3360 2861 
L 2963 1229 
Q 2938 1114 2925 1002 
Q 2912 890 2912 774 
Q 2912 589 2947 413 
Q 2982 237 3040 64 
L 2349 -51 
Q 2336 -26 2317 12 
Q 2298 51 2278 96 
Q 2259 141 2246 176 
Q 2234 211 2227 230 
Q 2099 134 1881 32 
Q 1664 -70 1318 -70 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-BoldItalic-55&#34; d=&#34;M 3123 2227 
Q 3002 2272 2835 2297 
Q 2669 2323 2426 2323 
Q 2259 2323 2083 2300 
Q 1907 2278 1760 2227 
L 1229 0 
L 442 0 
L 1114 2810 
Q 1414 2931 1763 2998 
Q 2112 3066 2419 3066 
Q 2778 3066 3005 3034 
Q 3232 3002 3424 2950 
L 3123 2227 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;path id=&#34;UbuntuMono-BoldItalic-48&#34; d=&#34;M 1254 1069 
Q 1254 954 1292 861 
Q 1331 768 1417 704 
Q 1504 640 1648 605 
Q 1792 570 2010 570 
Q 2266 570 2496 624 
Q 2726 678 2835 730 
L 2886 134 
Q 2733 58 2457 -9 
Q 2182 -77 1856 -77 
Q 1491 -77 1228 16 
Q 966 109 800 275 
Q 634 442 557 669 
Q 480 896 480 1171 
Q 480 1542 605 1891 
Q 730 2240 970 2502 
Q 1210 2765 1552 2925 
Q 1894 3085 2336 3085 
Q 2778 3085 3059 2867 
Q 3341 2650 3341 2259 
Q 3341 1933 3181 1705 
Q 3021 1478 2739 1337 
Q 2458 1197 2077 1133 
Q 1696 1069 1254 1069 
z
M 2189 2458 
Q 1894 2458 1628 2256 
Q 1363 2054 1261 1613 
Q 1664 1613 1923 1664 
Q 2182 1715 2329 1795 
Q 2477 1875 2534 1971 
Q 2592 2067 2592 2150 
Q 2592 2298 2486 2378 
Q 2381 2458 2189 2458 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
     &lt;/defs&gt;
     &lt;use xlink:href=&#34;#DejaVuSansMono-BoldOblique-834&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-3&#34; transform=&#34;translate(60.203125 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-3c&#34; transform=&#34;translate(110.203125 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-52&#34; transform=&#34;translate(160.203125 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-58&#34; transform=&#34;translate(210.203125 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-3&#34; transform=&#34;translate(260.203125 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-44&#34; transform=&#34;translate(310.203125 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-55&#34; transform=&#34;translate(360.203125 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-48&#34; transform=&#34;translate(410.203125 0)&#34;/&gt;
    &lt;/g&gt;
    &lt;!-- here --&gt;
    &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(88.716535 302.322909) scale(0.19 -0.19)&#34;&gt;
     &lt;defs&gt;
      &lt;path id=&#34;UbuntuMono-BoldItalic-4b&#34; d=&#34;M 1786 2995 
Q 1894 3027 2009 3049 
Q 2125 3072 2234 3072 
Q 2707 3072 2944 2845 
Q 3181 2618 3181 2202 
Q 3181 2093 3165 1965 
Q 3149 1837 3117 1696 
L 2707 0 
L 1920 0 
L 2304 1594 
Q 2323 1696 2348 1805 
Q 2374 1914 2374 2022 
Q 2374 2170 2297 2282 
Q 2221 2394 2003 2394 
Q 1920 2394 1821 2378 
Q 1722 2362 1632 2323 
L 1069 0 
L 282 0 
L 1312 4307 
L 2131 4442 
L 1786 2995 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
     &lt;/defs&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-4b&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-48&#34; transform=&#34;translate(50 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-55&#34; transform=&#34;translate(100 0)&#34;/&gt;
     &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-48&#34; transform=&#34;translate(150 0)&#34;/&gt;
    &lt;/g&gt;
   &lt;/g&gt;
   &lt;g id=&#34;text_10&#34;&gt;
    &lt;a xlink:href=&#34;https://orgmode.org/manual/&#34; target=&#34;_blank&#34;&gt;
     &lt;!-- Org mode --&gt;
     &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(251.133858 285.061706) scale(0.19 -0.19)&#34;&gt;
      &lt;defs&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-32&#34; d=&#34;M 2349 4051 
Q 2867 4051 3161 3715 
Q 3456 3379 3456 2822 
Q 3456 2573 3417 2259 
Q 3379 1946 3289 1622 
Q 3200 1299 3053 992 
Q 2906 685 2694 445 
Q 2483 205 2198 61 
Q 1914 -83 1542 -83 
Q 1018 -83 723 253 
Q 429 589 429 1146 
Q 429 1395 467 1708 
Q 506 2022 598 2345 
Q 691 2669 835 2976 
Q 979 3283 1193 3523 
Q 1408 3763 1693 3907 
Q 1978 4051 2349 4051 
z
M 1632 602 
Q 1894 602 2089 826 
Q 2285 1050 2413 1379 
Q 2541 1709 2605 2083 
Q 2669 2458 2669 2765 
Q 2669 3014 2582 3190 
Q 2496 3366 2259 3366 
Q 1997 3366 1798 3142 
Q 1600 2918 1472 2588 
Q 1344 2259 1280 1881 
Q 1216 1504 1216 1203 
Q 1216 954 1302 778 
Q 1389 602 1632 602 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-4a&#34; d=&#34;M 2803 352 
Q 2714 -19 2579 -288 
Q 2445 -557 2237 -733 
Q 2029 -909 1741 -992 
Q 1453 -1075 1062 -1075 
Q 723 -1075 483 -1014 
Q 243 -954 6 -826 
L 282 -205 
Q 448 -275 656 -339 
Q 864 -403 1139 -403 
Q 1523 -403 1718 -240 
Q 1914 -77 1978 192 
L 2016 358 
Q 1875 288 1728 246 
Q 1581 205 1446 205 
Q 934 205 710 493 
Q 486 781 486 1254 
Q 486 1690 643 2029 
Q 800 2368 1062 2598 
Q 1325 2829 1661 2950 
Q 1997 3072 2355 3072 
Q 2624 3072 2896 3030 
Q 3168 2989 3411 2886 
L 2803 352 
z
M 2509 2394 
Q 2355 2432 2214 2432 
Q 1997 2432 1821 2339 
Q 1645 2246 1520 2092 
Q 1395 1939 1324 1734 
Q 1254 1530 1254 1312 
Q 1254 1120 1337 979 
Q 1421 838 1677 838 
Q 1766 838 1904 873 
Q 2042 909 2170 992 
L 2509 2394 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-50&#34; d=&#34;M 826 2874 
Q 1062 2957 1257 2998 
Q 1453 3040 1638 3040 
Q 1805 3040 1949 2989 
Q 2093 2938 2182 2816 
Q 2330 2931 2499 2985 
Q 2669 3040 2803 3040 
Q 3059 3040 3222 2883 
Q 3386 2726 3386 2394 
Q 3386 2317 3376 2230 
Q 3366 2144 3341 2054 
L 2854 0 
L 2214 0 
L 2714 2112 
Q 2726 2157 2732 2205 
Q 2739 2253 2739 2278 
Q 2739 2470 2566 2470 
Q 2502 2470 2444 2438 
Q 2387 2406 2336 2362 
Q 2336 2214 2298 2054 
L 2080 1146 
L 1459 1146 
L 1683 2099 
Q 1696 2138 1709 2189 
Q 1722 2240 1722 2291 
Q 1722 2355 1690 2409 
Q 1658 2464 1562 2464 
Q 1453 2464 1357 2432 
L 774 0 
L 134 0 
L 826 2874 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-47&#34; d=&#34;M 1606 602 
Q 1786 602 1907 682 
Q 2029 762 2118 870 
Q 2131 960 2144 1043 
Q 2157 1126 2182 1235 
L 2458 2374 
Q 2387 2394 2310 2400 
Q 2234 2406 2163 2406 
Q 1939 2406 1760 2300 
Q 1581 2195 1453 2022 
Q 1325 1850 1257 1626 
Q 1190 1402 1190 1165 
Q 1190 998 1219 889 
Q 1248 781 1302 717 
Q 1357 653 1433 627 
Q 1510 602 1606 602 
z
M 2963 1229 
Q 2938 1114 2925 1002 
Q 2912 890 2912 774 
Q 2912 589 2947 413 
Q 2982 237 3040 64 
L 2349 -51 
Q 2336 -26 2317 12 
Q 2298 51 2278 96 
Q 2259 141 2246 176 
Q 2234 211 2227 230 
Q 2099 134 1881 32 
Q 1664 -70 1318 -70 
Q 896 -64 653 233 
Q 410 531 410 1101 
Q 410 1536 557 1897 
Q 704 2259 957 2515 
Q 1210 2771 1552 2912 
Q 1894 3053 2278 3053 
Q 2451 3053 2611 3008 
L 2918 4307 
L 3738 4442 
L 2963 1229 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;/defs&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-32&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-55&#34; transform=&#34;translate(50 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-4a&#34; transform=&#34;translate(100 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-3&#34; transform=&#34;translate(150 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-50&#34; transform=&#34;translate(200 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-52&#34; transform=&#34;translate(250 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-47&#34; transform=&#34;translate(300 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-48&#34; transform=&#34;translate(350 0)&#34;/&gt;
     &lt;/g&gt;
    &lt;/a&gt;
    &lt;a xlink:href=&#34;https://orgmode.org/manual/&#34; target=&#34;_blank&#34;&gt;
     &lt;!-- manual --&gt;
     &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(260.633858 302.351112) scale(0.19 -0.19)&#34;&gt;
      &lt;defs&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-51&#34; d=&#34;M 973 2880 
Q 1171 2944 1491 3008 
Q 1811 3072 2176 3072 
Q 2714 3072 2947 2841 
Q 3181 2611 3181 2202 
Q 3181 2093 3165 1965 
Q 3149 1837 3117 1696 
L 2701 0 
L 1914 0 
L 2304 1594 
Q 2323 1696 2348 1805 
Q 2374 1914 2374 2022 
Q 2374 2170 2294 2282 
Q 2214 2394 2003 2394 
Q 1914 2394 1818 2378 
Q 1722 2362 1632 2323 
L 1069 0 
L 282 0 
L 973 2880 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-4f&#34; d=&#34;M 2912 128 
Q 2886 115 2812 80 
Q 2739 45 2617 13 
Q 2496 -19 2333 -44 
Q 2170 -70 1971 -70 
Q 1536 -70 1318 154 
Q 1101 378 1101 781 
Q 1101 890 1117 1008 
Q 1133 1126 1165 1254 
L 1760 3750 
L 928 3750 
L 1082 4403 
L 2701 4403 
L 1946 1203 
Q 1933 1139 1917 1065 
Q 1901 992 1901 934 
Q 1901 806 1971 710 
Q 2042 614 2259 614 
Q 2349 614 2441 630 
Q 2534 646 2617 672 
Q 2701 698 2765 717 
Q 2829 736 2861 749 
L 2912 128 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;/defs&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-50&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-44&#34; transform=&#34;translate(50 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-51&#34; transform=&#34;translate(100 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-58&#34; transform=&#34;translate(150 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-44&#34; transform=&#34;translate(200 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-4f&#34; transform=&#34;translate(250 0)&#34;/&gt;
     &lt;/g&gt;
    &lt;/a&gt;
   &lt;/g&gt;
   &lt;g id=&#34;text_11&#34;&gt;
    &lt;a xlink:href=&#34;https://blog.tecosaur.net/tmio/2026-11-01-preview.html&#34; target=&#34;_blank&#34;&gt;
     &lt;!-- Tecosaur&#39;s --&gt;
     &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(249.133858 102.612033) scale(0.16 -0.16)&#34;&gt;
      &lt;defs&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-37&#34; d=&#34;M 3859 3962 
L 3706 3309 
L 2656 3309 
L 1862 0 
L 1075 0 
L 1869 3309 
L 826 3309 
L 979 3962 
L 3859 3962 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-46&#34; d=&#34;M 493 1165 
Q 493 1581 640 1933 
Q 787 2285 1052 2537 
Q 1318 2790 1683 2934 
Q 2048 3078 2490 3078 
Q 2662 3078 2793 3065 
Q 2925 3053 3033 3030 
Q 3142 3008 3228 2979 
Q 3315 2950 3398 2912 
L 3117 2285 
Q 3014 2330 2854 2365 
Q 2694 2400 2490 2400 
Q 2227 2400 2009 2320 
Q 1792 2240 1629 2086 
Q 1466 1933 1376 1709 
Q 1286 1485 1286 1197 
Q 1286 1069 1318 963 
Q 1350 858 1436 781 
Q 1523 704 1673 659 
Q 1824 614 2054 614 
Q 2304 614 2518 662 
Q 2733 710 2842 762 
L 2918 134 
Q 2842 96 2752 57 
Q 2662 19 2540 -9 
Q 2419 -38 2256 -54 
Q 2093 -70 1869 -70 
Q 1478 -70 1216 29 
Q 954 128 794 294 
Q 634 461 563 688 
Q 493 915 493 1165 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-56&#34; d=&#34;M 1498 582 
Q 1837 582 1965 672 
Q 2093 762 2093 883 
Q 2093 941 2070 985 
Q 2048 1030 1993 1072 
Q 1939 1114 1843 1155 
Q 1747 1197 1600 1254 
Q 1421 1318 1286 1388 
Q 1152 1459 1062 1552 
Q 973 1645 928 1766 
Q 883 1888 883 2054 
Q 883 2522 1212 2803 
Q 1542 3085 2202 3085 
Q 2528 3085 2800 3027 
Q 3072 2970 3232 2893 
L 2944 2272 
Q 2797 2342 2608 2387 
Q 2419 2432 2131 2432 
Q 2067 2432 1987 2422 
Q 1907 2413 1836 2381 
Q 1766 2349 1718 2294 
Q 1670 2240 1670 2157 
Q 1670 2099 1686 2057 
Q 1702 2016 1753 1974 
Q 1805 1933 1901 1888 
Q 1997 1843 2157 1786 
Q 2349 1709 2486 1632 
Q 2624 1555 2717 1459 
Q 2810 1363 2851 1235 
Q 2893 1107 2893 928 
Q 2893 742 2816 563 
Q 2739 384 2576 240 
Q 2413 96 2150 6 
Q 1888 -83 1523 -83 
Q 1261 -83 1062 -51 
Q 864 -19 717 25 
Q 570 70 470 118 
Q 371 166 314 198 
L 608 819 
Q 736 749 960 665 
Q 1184 582 1498 582 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-a&#34; d=&#34;M 2899 4346 
L 2778 3846 
Q 2701 3526 2550 3145 
Q 2400 2765 2253 2432 
L 1792 2432 
Q 1798 2598 1811 2796 
Q 1824 2995 1843 3196 
Q 1862 3398 1891 3593 
Q 1920 3789 1958 3949 
L 2054 4346 
L 2899 4346 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;/defs&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-37&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-48&#34; transform=&#34;translate(50 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-46&#34; transform=&#34;translate(100 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-52&#34; transform=&#34;translate(150 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-56&#34; transform=&#34;translate(200 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-44&#34; transform=&#34;translate(250 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-58&#34; transform=&#34;translate(300 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-55&#34; transform=&#34;translate(350 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-a&#34; transform=&#34;translate(400 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-56&#34; transform=&#34;translate(450 0)&#34;/&gt;
     &lt;/g&gt;
    &lt;/a&gt;
    &lt;a xlink:href=&#34;https://blog.tecosaur.net/tmio/2026-11-01-preview.html&#34; target=&#34;_blank&#34;&gt;
     &lt;!-- &#34;This Month --&gt;
     &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(245.133858 117.141033) scale(0.16 -0.16)&#34;&gt;
      &lt;defs&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-5&#34; d=&#34;M 2291 4346 
L 2195 3942 
Q 2163 3795 2105 3619 
Q 2048 3443 1977 3257 
Q 1907 3072 1830 2889 
Q 1754 2707 1683 2547 
L 1235 2547 
Q 1242 2707 1251 2902 
Q 1261 3098 1280 3299 
Q 1299 3501 1328 3693 
Q 1357 3885 1395 4045 
L 1459 4346 
L 2291 4346 
z
M 3552 4346 
L 3462 3942 
Q 3430 3795 3372 3619 
Q 3315 3443 3244 3257 
Q 3174 3072 3097 2889 
Q 3021 2707 2944 2547 
L 2496 2547 
Q 2502 2707 2515 2902 
Q 2528 3098 2547 3299 
Q 2566 3501 2592 3693 
Q 2618 3885 2656 4045 
L 2726 4346 
L 3552 4346 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-4c&#34; d=&#34;M 2938 83 
Q 2701 -6 2493 -38 
Q 2285 -70 2106 -70 
Q 1651 -70 1433 150 
Q 1216 371 1216 774 
Q 1216 986 1286 1267 
L 1542 2355 
L 710 2355 
L 870 3008 
L 2490 3008 
L 2054 1171 
Q 2016 1037 2016 934 
Q 2016 614 2342 614 
Q 2451 614 2598 636 
Q 2746 659 2925 723 
L 2938 83 
z
M 2125 3373 
Q 1920 3373 1795 3481 
Q 1670 3590 1670 3821 
Q 1670 3942 1715 4048 
Q 1760 4154 1833 4224 
Q 1907 4294 2003 4336 
Q 2099 4378 2202 4378 
Q 2387 4378 2524 4269 
Q 2662 4160 2662 3917 
Q 2662 3802 2614 3699 
Q 2566 3597 2489 3526 
Q 2413 3456 2317 3414 
Q 2221 3373 2125 3373 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-30&#34; d=&#34;M 1862 3962 
Q 1875 3827 1897 3606 
Q 1920 3386 1939 3133 
Q 1958 2880 1974 2611 
Q 1990 2342 2003 2112 
L 2963 3962 
L 3686 3962 
Q 3558 2995 3363 2012 
Q 3168 1030 2944 0 
L 2221 0 
L 3014 3110 
L 2131 1402 
L 1574 1402 
Q 1562 1824 1533 2259 
Q 1504 2694 1472 3078 
L 762 0 
L 38 0 
Q 173 486 317 1011 
Q 461 1536 608 2057 
Q 755 2579 899 3065 
Q 1043 3552 1184 3962 
L 1862 3962 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
       &lt;path id=&#34;UbuntuMono-BoldItalic-57&#34; d=&#34;M 1306 2355 
L 704 2355 
L 864 3008 
L 1459 3008 
L 1638 3763 
L 2464 3891 
L 2246 3008 
L 3392 3008 
L 3232 2355 
L 2093 2355 
L 1811 1184 
Q 1779 1024 1779 934 
Q 1779 742 1910 678 
Q 2042 614 2208 614 
Q 2381 614 2563 656 
Q 2746 698 2918 768 
L 2912 109 
Q 2714 19 2474 -25 
Q 2234 -70 1997 -70 
Q 1485 -70 1232 150 
Q 979 371 979 794 
Q 979 896 992 1001 
Q 1005 1107 1037 1229 
L 1306 2355 
z
&#34; transform=&#34;scale(0.015625)&#34;/&gt;
      &lt;/defs&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-5&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-37&#34; transform=&#34;translate(50 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-4b&#34; transform=&#34;translate(100 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-4c&#34; transform=&#34;translate(150 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-56&#34; transform=&#34;translate(200 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-3&#34; transform=&#34;translate(250 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-30&#34; transform=&#34;translate(300 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-52&#34; transform=&#34;translate(350 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-51&#34; transform=&#34;translate(400 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-57&#34; transform=&#34;translate(450 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-4b&#34; transform=&#34;translate(500 0)&#34;/&gt;
     &lt;/g&gt;
    &lt;/a&gt;
    &lt;a xlink:href=&#34;https://blog.tecosaur.net/tmio/2026-11-01-preview.html&#34; target=&#34;_blank&#34;&gt;
     &lt;!-- in Org&#34; --&gt;
     &lt;g style=&#34;fill: #1f2a3f&#34; transform=&#34;translate(261.133858 131.653033) scale(0.16 -0.16)&#34;&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-4c&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-51&#34; transform=&#34;translate(50 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-3&#34; transform=&#34;translate(100 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-32&#34; transform=&#34;translate(150 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-55&#34; transform=&#34;translate(200 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-4a&#34; transform=&#34;translate(250 0)&#34;/&gt;
      &lt;use xlink:href=&#34;#UbuntuMono-BoldItalic-5&#34; transform=&#34;translate(300 0)&#34;/&gt;
     &lt;/g&gt;
    &lt;/a&gt;
   &lt;/g&gt;
  &lt;/g&gt;
 &lt;/g&gt;
 &lt;defs&gt;
  &lt;clipPath id=&#34;p9faeef5dad&#34;&gt;
   &lt;rect x=&#34;0&#34; y=&#34;0&#34; width=&#34;396.39685&#34; height=&#34;396.39685&#34;/&gt;
  &lt;/clipPath&gt;
 &lt;/defs&gt;
&lt;/svg&gt;
&lt;style&gt;
.detail-icon {
float: right;
width: 25px;
}
&lt;/style&gt;
&lt;h2 id=&#34;what-is-org-latex-preview&#34;&gt;What is &lt;code&gt;org-latex-preview&lt;/code&gt;?&lt;/h2&gt;
&lt;p&gt;This is a feature included with Org mode to preview LaTeX math snippets as images in Emacs buffers.  The contents of LaTeX fragments and environments in Org mode are replaced with rendered images.&lt;/p&gt;
&lt;div class=&#34;wide&#34; style=&#34;margin-top: 8px&#34;&gt;
&lt;div class=&#34;column&#34;&gt;
  &lt;a href=&#34;https://karthinks.com/img/olp-before-1.png&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/olp-before-1.png&#34; style=&#34;width:100%;border-radius:5px;box-shadow: 0px -5px 10px #421D5D&#34;&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;div class=&#34;column&#34;&gt;
  &lt;a href=&#34;https://karthinks.com/img/olp-after-1.png&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/olp-after-1.png&#34; style=&#34;width:100%;border-radius:5px;box-shadow: 0px -5px 10px #421D5D&#34;&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It has existed for decades at this point, but in a form that I consider barely usable; this rewrite overhauls the code base and adds a number of quality-of-life features.  There is a 13 minute demo that can give you a good idea of the new capabilities of Org mode:&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--org-latex-preview-everywhere-youtube-demo&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class=&#34;videocontainer&#34;&gt;&lt;iframe width=&#34;680&#34; height=&#34;382&#34; src=&#34;https://www.youtube-nocookie.com/embed/n-AfvuV-bYo&#34; title=&#34;YouTube video player&#34; frameborder=&#34;0&#34; allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&#34; allowfullscreen&gt;[&lt;a href=&#34;https://www.youtube.com/watch?v=n-AfvuV-bYo&#34;&gt;Video Demo (13:13)&lt;/a&gt;]&lt;/iframe&gt;&lt;/div&gt;
&lt;hr&gt;
&lt;p&gt;The bullet points, if you prefer:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Preview generation is fully asynchronous
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Or as asynchronous as Emacs in its current form allows.
&lt;/small&gt;&lt;/span&gt;
, with images placed continuously as they are generated&lt;/li&gt;
&lt;li&gt;Bulk generation: Preview 200 to 800 snippets per second&lt;/li&gt;
&lt;li&gt;Previews blend in correctly with surrounding colors&lt;/li&gt;
&lt;li&gt;Automatically match the current Emacs theme (even through theme changes)&lt;/li&gt;
&lt;li&gt;Previews are aligned with and scaled to match the font baseline and size&lt;/li&gt;
&lt;li&gt;Previews auto-generate for newly inserted LaTeX&lt;/li&gt;
&lt;li&gt;Previews auto-update as you change the underlying LaTeX&lt;/li&gt;
&lt;li&gt;Preview as you type: Live-previews of LaTeX fragments&lt;/li&gt;
&lt;li&gt;Consistent (correct) equation numbering across the document&lt;/li&gt;
&lt;li&gt;LaTeX compilation error reporting for previews&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And a couple more quick demos:&lt;/p&gt;
&lt;p&gt;&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/olp-auto-mode-2.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/olp-auto-mode-2.mp4&#34;&gt;[org-latex-preview video demo 2]&lt;/a&gt;&lt;/video&gt;&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/olp-auto-mode-tikz.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/olp-auto-mode-tikz.mp4&#34;&gt;[org-latex-preview tikz demo]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;The rest of this article is mostly about how it works, and briefly why.  As such, it has a &amp;ldquo;fractal&amp;rdquo; level of detail.  There is information intended&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;to give the casual reader a bird&amp;rsquo;s eye view of LaTeX preview generation,&lt;/li&gt;
&lt;li&gt;to give the motivated reader a detailed look at its many pieces,&lt;/li&gt;
&lt;li&gt;for the potential new Emacs package author looking for pointers on aspects of Emacs&amp;rsquo; API,&lt;/li&gt;
&lt;li&gt;for folks wanting to develop a similar feature for applications &lt;em&gt;other&lt;/em&gt; than Emacs,&lt;/li&gt;
&lt;li&gt;and information that is of no use whatsoever except to the future maintainers of the &lt;code&gt;org-latex-preview&lt;/code&gt; library.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To that end, many details are tucked away in blocks like the following.  You can safely ignore them in favor of the top-level headings, images and video demos.&lt;/p&gt;
&lt;div class=&#34;grid&#34;&gt;
&lt;details class=&#34;details implementation&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/lisp-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Implementation details&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Blocks like this describe the concrete implementation of aspects of the code.&lt;/p&gt;
&lt;p&gt;This is probably only interesting if you are looking to dive into the code itself, or if you are looking to write a similar package.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details class=&#34;details apinote&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Emacs API notes&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Blocks like this are for additional notes on aspects of Emacs&amp;rsquo; API, including the odd code snippets.&lt;/p&gt;
&lt;p&gt;Warning: Here be idiosyncratic takes.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details class=&#34;details orgnote&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/org-mode-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Org Mode notes&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Blocks like this describe other Org features relevant to LaTeX preview generation.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details class=&#34;details&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/term-logo.png&#34; class=detail-icon&gt;&lt;/span&gt; Command output&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Blocks like this describe CLI commands associated with this process, or their output.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;isn-t-this-a-narrow-feature-to-spend-so-much-time-on&#34;&gt;Isn&amp;rsquo;t this a narrow feature to spend so much time on?&lt;/h2&gt;
&lt;p&gt;Indeed, this feature&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;requires a LaTeX distribution installed,&lt;/li&gt;
&lt;li&gt;works only with Org mode (for now),&lt;/li&gt;
&lt;li&gt;and is glued together from several processes and grossly inefficient in the larger scheme of things.&lt;/li&gt;
&lt;li&gt;It&amp;rsquo;s also finicky, as all hyper-configurable software is.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;LaTeX was not built with the aim of minimizing latency.  Having to start multiple new processes even for a one-character change places a hard cap on what&amp;rsquo;s possible in terms of real-time feedback.  Implementing an equivalent preview feature for a system designed for modern computers, like Typst, is trivial in comparison.&lt;/p&gt;
&lt;p&gt;Moreover, as popular as Org mode is, it&amp;rsquo;s a small player in the space of markup languages.  The fraction of Org and LaTeX users who would prefer to use Org mode to write LaTeX is smaller still.  And while Org attempts to integrate well with LaTeX, navigating the mishmash of Org and LaTeX syntax presents an extra learning curve on top of learning to use the two markup languages individually.&lt;/p&gt;
&lt;p&gt;But it also has a few things going for it.&lt;/p&gt;
&lt;p&gt;First, LaTeX is ubiquitous, and Org mode is a far more convenient format for writing than raw LaTeX.  There is significantly less visual noise (think Markdown vs HTML), and Org provides an escape hatch for adding LaTeX verbatim.  Org&amp;rsquo;s simple interface for shuffling text around, monitoring task progress and executing code blocks makes it easy for eventual LaTeX documents to begin as Org files.  Since everything in Emacs composes with everything else, your system for (say) &lt;a href=&#34;https://karthinks.com/software/latex-input-for-impatient-scholars/&#34;&gt;fast LaTeX input&lt;/a&gt; transfers over to Org mode seamlessly.&lt;/p&gt;
&lt;p&gt;Second, the fact that Org is versatile as a publishing tool implies that some benefits of better LaTeX support transfer over to other formats too, like equations in HTML or ODT exports.&lt;/p&gt;
&lt;p&gt;There is a wide swath of applications built on Org mode that benefit from LaTeX math input, such as Org Roam and Org Noter.  For these applications converting Org documents to LaTeX is not the goal, as they are not primarily publication tools: they stick around as private digital archives, and better LaTeX support is a bonus to the user&amp;rsquo;s expressivity.&lt;/p&gt;
&lt;p&gt;Real-time feedback when editing LaTeX snippets is a categorical improvement to the user&amp;rsquo;s experience.  I did not realize this when I started work on &lt;code&gt;org-latex-preview&lt;/code&gt;, but now I wouldn&amp;rsquo;t want to LaTeX without it.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
It baffles me that web LaTeX editors (Overleaf etc) don&amp;rsquo;t provide this out of the box, especially as they target novice LaTeX users.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;Finally, we &lt;em&gt;can&lt;/em&gt; keep Org mode out of the picture: &lt;code&gt;org-latex-preview&lt;/code&gt; can technically work anywhere in Emacs, and in every major-mode. it&amp;rsquo;s just not there yet
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
(See &lt;a href=&#34;#latex-previews-everywhere-in-emacs&#34;&gt;below&lt;/a&gt;)
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;But perhaps the most germane reason is that Emacs users don&amp;rsquo;t shy away from settling comfortably into tiny, cramped and poorly insulated niches.  Comes with the territory!&lt;/p&gt;
&lt;h2 id=&#34;the-objectives&#34;&gt;The Objectives&lt;/h2&gt;
&lt;h3 id=&#34;never-block-emacs&#34;&gt;Never Block Emacs&lt;/h3&gt;
&lt;p&gt;Emacs users are closely acquainted with its frequent unresponsiveness.  You&amp;rsquo;re never more than one minor-mode or mode line indicator away from causing Emacs to block or lag.  While it&amp;rsquo;s not a big ask to wait a second for the result of an action &lt;em&gt;you&lt;/em&gt; initiate, the unresponsiveness often manifests as short random freezes, which is unacceptable.  But there&amp;rsquo;s more.  Beyond the annoyance and inconvenience, poor responsiveness denies us an entire class of uses: real-time feedback is everything for interactive applications.&lt;/p&gt;
&lt;p&gt;Owing to both its design and age, Emacs is not very well suited for asynchronous applications.  Certain patterns of asynchronous usage are viable (see below), but concurrency support is limited and parallelism is absent: no worker threads, channels, async-io, or anything of the like.&lt;/p&gt;
&lt;details class=&#34;details apinote&#34;&gt;
&lt;summary&gt;Generator-based async in Emacs lisp &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;I lied.  In addition to Elisp threads, there exist prototype libraries for async-io (&lt;a href=&#34;https://nullprogram.com/blog/2019/03/10/&#34;&gt;Chris Wellons&lt;/a&gt;) and channels/CSP (&lt;a href=&#34;https://andreyorst.gitlab.io/posts/2023-02-01-ad-hoc-async-in-emacs-lisp-via-generators/&#34;&gt;Andrey Listopadov&lt;/a&gt;) based on Emacs&amp;rsquo; &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Generators.html&#34;&gt;generators library&lt;/a&gt;, which in turn is implemented using continuation passing.  But generators as provided by this library do not have anywhere near the level of robustness or support you need to build actual applications: no introspection, error handling or debugging support, poor performance, and just overall jankiness.  I&amp;rsquo;ve tried and lived to regret it &amp;ndash; &lt;a href=&#34;https://github.com/karthink/elfeed-tube&#34;&gt;Elfeed Tube&lt;/a&gt; is a real mess.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&#34;https://elpa.gnu.org/packages/futur.html&#34;&gt;Futur&lt;/a&gt; package is another promising swing at an async-io style interface, but it&amp;rsquo;s new and I haven&amp;rsquo;t been able to try it yet.&lt;/p&gt;
&lt;p&gt;In any event, a more responsive &lt;code&gt;org-latex-preview&lt;/code&gt; would require parallelism and not just concurrency.  There is John Wiegley&amp;rsquo;s &lt;a href=&#34;https://github.com/jwiegley/emacs-async&#34;&gt;async library&lt;/a&gt; (and packages inspired by it, like &lt;a href=&#34;https://codeberg.org/FelipeLema/session-async.el&#34;&gt;session-async&lt;/a&gt;) that spawn a child Emacs that runs in parallel, but communication is limited and the overhead is sizeable, so this is a bit of a bludgeon.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;The upshot is this: we want &lt;code&gt;org-latex-preview&lt;/code&gt; to be as asynchronous as possible within Emacs&amp;rsquo; effectively single-threaded event loop model.  The goal is to minimize how long the user has to wait, in terms of both the overall run time and the fraction of that for which Emacs is unresponsive.  We end up having to trade these off against each other.&lt;/p&gt;
&lt;h3 id=&#34;go-fast--relative-to-latex-and-emacs&#34;&gt;Go Fast (relative to LaTeX and Emacs)&lt;/h3&gt;
&lt;p&gt;A close second concern is preview generation speed.  This is desirable both in the large and the small.  Previewing upwards of a hundred LaTeX math fragments in a math-heavy Org document used to be an exercise in patience.  Now it takes about one second, and can be much faster with some trade-offs.&lt;/p&gt;
&lt;style&gt;.center-table table { margin-left: auto;  margin-right: auto;  text-align: right;  }&lt;/style&gt;
&lt;div class=&#34;ox-hugo-table center-table&#34;&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;LaTeX Fragments&lt;/th&gt;
&lt;th&gt;Old preview system (s)&lt;/th&gt;
&lt;th&gt;&lt;code&gt;org-latex-preview&lt;/code&gt; (s)&lt;/th&gt;
&lt;th&gt;Speed up&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;35&lt;/td&gt;
&lt;td&gt;12.96&lt;/td&gt;
&lt;td&gt;0.43&lt;/td&gt;
&lt;td&gt;30x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;70&lt;/td&gt;
&lt;td&gt;22.59&lt;/td&gt;
&lt;td&gt;0.51&lt;/td&gt;
&lt;td&gt;44x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;160&lt;/td&gt;
&lt;td&gt;33.99&lt;/td&gt;
&lt;td&gt;0.68&lt;/td&gt;
&lt;td&gt;50x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;330&lt;/td&gt;
&lt;td&gt;84.95&lt;/td&gt;
&lt;td&gt;1.32&lt;/td&gt;
&lt;td&gt;64x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;660&lt;/td&gt;
&lt;td&gt;139.73&lt;/td&gt;
&lt;td&gt;1.96&lt;/td&gt;
&lt;td&gt;71x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1000&lt;/td&gt;
&lt;td&gt;194.16&lt;/td&gt;
&lt;td&gt;3.24&lt;/td&gt;
&lt;td&gt;60x&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a id=&#34;figure--timing-chart-svg-only&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/olp_preview_timing_chart_svg_only.svg&#34;
         alt=&#34;Figure 1: LaTeX preview generation times under the slowest settings. The vertical axis is time, and along each vertical line the red chunks correspond to intervals for which Emacs is blocked. We still manage to process a file with 250 LaTeX fragments in about a second with minimal impact on Emacs&amp;amp;rsquo; responsiveness.&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 1: &lt;/span&gt;LaTeX preview generation times under the slowest settings.  The vertical axis is time, and along each vertical line the red chunks correspond to intervals for which Emacs is blocked.  We still manage to process a file with 250 LaTeX fragments in about a second with minimal impact on Emacs&amp;rsquo; responsiveness.&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h3 id=&#34;provide-real-time-feedback&#34;&gt;Provide Real-Time Feedback&lt;/h3&gt;
&lt;p&gt;Speeding up bulk generation is at most a boost in convenience.  You don&amp;rsquo;t regenerate a large buffer&amp;rsquo;s worth of previews more than once every few sessions, and the resulting images are cached anyway.  The more interesting aspect is that speed enables a close to real-time feedback loop that wasn&amp;rsquo;t available before.  This is especially useful when you&amp;rsquo;re deep inside a messy structure like an array:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/olp-auto-mode-array.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/olp-auto-mode-array.mp4&#34;&gt;[Video: Live previews of a LaTeX array]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;No more counting field separators.  No more exiting, regenerating and re-examining snippets.  It&amp;rsquo;s the best parts of WYSIWYG and visible markup, together.&lt;/p&gt;
&lt;h3 id=&#34;look-pretty&#34;&gt;Look Pretty&lt;/h3&gt;
&lt;p&gt;Even in the niche of academic types who use Org mode with LaTeX, there are very different orientations.  There&amp;rsquo;s Org the transient format, where an Org document starts out as a rough sketch, a thought bubble translated to the screen, and soon transitions into a TeX file that becomes the source of truth.  There&amp;rsquo;s Org the intermediate publication format, where the document lives as an Org file, but its value is in the web page or PDF document it eventually becomes.  For the adherents of this style the appearance of the Org document is irrelevant.&lt;/p&gt;
&lt;p&gt;Finally, there&amp;rsquo;s the class of uses described &lt;a href=&#34;#isn-t-this-a-narrow-feature-to-spend-so-much-time-on&#34;&gt;above&lt;/a&gt;, where the desired output is the Org document itself, or a cross-linked collection of them.  These are folks who care about the aesthetics of Org documents and often suffer a thousand cuts in trying to make Emacs look &amp;ldquo;modern&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;One of the objectives of &lt;code&gt;org-latex-preview&lt;/code&gt; is to ease their self-imposed burden somewhat: LaTeX previews should blend in perfectly with the surrounding text.  This means&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;preview image sizing that is consistent with surrounding text,&lt;/li&gt;
&lt;li&gt;with perfect baseline alignment at any font size,&lt;/li&gt;
&lt;li&gt;and Emacs theme-aware colors that change automatically with the theme.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Getting the fonts to match is possible too, but requires some degree of compromise on the part of the user
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
You could start by using the variable-pitch Latin Modern font in your Org documents.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;Each of these is a long-standing issue with LaTeX previews in Org, and Stack Overflow and the usual haunts have decades of discussions on how to fix them, with band-aid after band-aid proposed as solutions.  We took an elephant gun to this problem, starting by throwing out the giant mess that was Org&amp;rsquo;s accreted LaTeX preview code of the past two decades.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a demo of theme-aware LaTeX preview colors:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/olp-theme-change.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/olp-theme-change.mp4&#34;&gt;[video demo: LaTeX previews that respect the color theme]&lt;/a&gt;&lt;/video&gt;
&lt;h3 id=&#34;windfalls-consistent-numbering-error-reporting&#34;&gt;Windfalls: Consistent numbering, error reporting&lt;/h3&gt;
&lt;p&gt;Finally, there are a few features we picked up along the way because they came free.&lt;/p&gt;
&lt;p&gt;Recording compilation errors was a simple matter since we scan the LaTeX output anyway.&lt;/p&gt;
&lt;p&gt;Consistent equation numbering was expensive in the past because numbering changes can propagate across the document, and parsing the Org document and LaTeX fragment compilation were both slow.  Recent changes to Org have made the former a non-issue (see the &lt;a href=&#34;#parsing&#34;&gt;parsing section below&lt;/a&gt;), and the &lt;a href=&#34;#figure--timing-chart-svg-only&#34;&gt;performance scaling&lt;/a&gt; of our bulk LaTeX runs has fixed the latter.&lt;/p&gt;
&lt;p&gt;There are several more minor features along for the ride, such as improvements to editing LaTeX with &lt;code&gt;org-edit-special&lt;/code&gt; (&lt;code&gt;C-c &#39;&lt;/code&gt;).&lt;/p&gt;
&lt;h2 id=&#34;the-emacs-api-an-overview&#34;&gt;The Emacs API: An Overview&lt;/h2&gt;
&lt;p&gt;As mentioned in the introduction, the LaTeX preview system draws on a few different facets of the Emacs API: mainly async process interaction (the &amp;ldquo;backend&amp;rdquo;) and overlays (the UI or &amp;ldquo;frontend&amp;rdquo;).  The live-updating behavior leans heavily on hooks and timers, and we join these pieces together with very simple Lispy data structures, like alists and plists.&lt;/p&gt;
&lt;p&gt;We also (naturally) use a few Org mode specific APIs, including ones developed by us for this purpose.  We cover these further below as we encounter them.&lt;/p&gt;
&lt;h3 id=&#34;the-substrate-emacs-event-loop&#34;&gt;The Substrate: Emacs&amp;rsquo; Event Loop&lt;/h3&gt;
&lt;p&gt;If you are designing an Emacs application that interacts with the outside world, it helps to start with a mental picture of Emacs&amp;rsquo; event loop.  To a first approximation, the main loop does only four things:&lt;/p&gt;
&lt;p&gt;&lt;a id=&#34;figure--emacs-event-loop-simple&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-event-loop-simple.png&#34;/&gt;
&lt;/figure&gt;

&lt;ul&gt;
&lt;li&gt;Read input events: This includes keyboard, mouse and touchscreen events, but also some OS signals.  This is the user&amp;rsquo;s interface to Emacs.&lt;/li&gt;
&lt;li&gt;Evaluate commands and redisplay: This is the heart of the Lisp evaluator, and Emacs&amp;rsquo; interface to the user.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Together these two connect the user and Emacs.  If the main loop did only these two things Emacs would still qualify for the title of &amp;ldquo;Lisp evaluator masquerading as a text editor&amp;rdquo;, but it wouldn&amp;rsquo;t be nearly as useful.  For that we need it to&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read subprocess output: This includes output from &amp;ldquo;regular&amp;rdquo; processes like shell commands or LaTeX, but also network requests. This connects Emacs to the world
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
(your computer and the network)
&lt;/small&gt;&lt;/span&gt;
, and vice-versa.  Command shells, LaTeX previews, LLM clients and most IDE features work because of this.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The last event loop function combines the above three, but across time:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Run timers: Schedule code for the future and run them when timers are ripe.  Somewhat tentatively, I&amp;rsquo;m including garbage collection here.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This design explains why timers in Emacs are not reliable in the absolute sense.  The timer runs not when it&amp;rsquo;s ripe, but when it&amp;rsquo;s ripe &lt;em&gt;and&lt;/em&gt; when the main loop gets around to it.  Nevertheless, scheduling code provides a much-needed degree of flexibility to a rigidly ordered task list.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; &amp;ldquo;To a first approximation&amp;rdquo;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;The way these four tasks are actually organized in the main loop code is less pleasing:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-event-loop-detailed.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Also, Emacs is obviously doing things outside of the event loop as well.  Font caches are compacted, Emacs is responding to the compositor and some OS signals, interacting with dynamic modules, and so on.  In the currently experimental MPS branch, some garbage collection activities also occur in the background.   These are invisible to the Lisp evaluator and thus out of scope when learning to build an Elisp package.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;the-backend-subprocess-interaction&#34;&gt;The Backend: Subprocess Interaction&lt;/h3&gt;
&lt;p&gt;&lt;a id=&#34;figure--async-interaction-via-processes&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/async-interaction-via-processes.png&#34; width=&#34;450px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;This design suggests that &lt;em&gt;Emacs can only do one thing at a time&lt;/em&gt;
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
As of Emacs 31
&lt;/small&gt;&lt;/span&gt;
, so that designing a responsive application is a steep ask.   But the situation is more nuanced:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Yes, the Lisp evaluator holds a global interpreter lock.  At any point in time Emacs is doing exactly one of the following: painting the screen (redisplay), updating syntax highlighting (fontification), running hook functions or timers, responding to window changes, handling keyboard input, and &amp;ndash; crucially for us &amp;ndash; interacting with subprocesses.  Every action is thus &lt;span class=&#34;Orange&#34;&gt;blocking&lt;/span&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The only &lt;span class=&#34;Purple&#34;&gt;asynchronous&lt;/span&gt; interaction possible is by starting an OS-level subprocess
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Another lie, since we have &lt;a href=&#34;#org-target--org-latex-preview-dynamic-modules&#34;&gt;dynamic modules, covered below&lt;/a&gt;.
&lt;/small&gt;&lt;/span&gt;
.  Emacs continues to run independently from the subprocess, but it still has to handle its &lt;code&gt;STDOUT&lt;/code&gt; and &lt;code&gt;STDERR&lt;/code&gt; streams and respond to process signals.  When it is doing this, it cannot pay attention to your input or anything else.  Again, Emacs can only do one thing at a time.&lt;/p&gt;
&lt;details class=&#34;details apinote&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Starting asynchronous subprocesses&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;There are multiple commands to start an asynchronous subprocess from Emacs (see &lt;code&gt;M-x shortdoc&lt;/code&gt; &lt;code&gt;process&lt;/code&gt;), but &lt;code&gt;start-process&lt;/code&gt; covers most common use cases.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my-process-object&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;start-process&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;name&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;buffer-name&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;program&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;--arg1&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;--arg2&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;...&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Processes are (optionally) associated with a buffer where process output is inserted.  To send a subprocess some input, there&amp;rsquo;s &lt;code&gt;process-send-string&lt;/code&gt; and &lt;code&gt;process-send-region&lt;/code&gt;.  Responding to process output and signals is the responsibility of process filters and sentinels (&lt;a href=&#34;#org-target--org-latex-preview-process-filters-sentinels&#34;&gt;next block&lt;/a&gt;).  &lt;code&gt;kill-process&lt;/code&gt; does what you&amp;rsquo;d expect.  All of these functions take the process object that &lt;code&gt;start-process&lt;/code&gt; returns as an argument.&lt;/p&gt;
&lt;p&gt;Except for some &lt;a href=&#34;#org-target--org-latex-preview-fiddly-details&#34;&gt;fiddly details&lt;/a&gt;, that&amp;rsquo;s essentially all there is to the process interaction API.  There are several variants of &lt;code&gt;start-process&lt;/code&gt; available &amp;ndash; the synchronous &lt;code&gt;call-process&lt;/code&gt;, the shell versions &lt;code&gt;start-process-shell-command&lt;/code&gt; and &lt;code&gt;call-process-shell-command&lt;/code&gt;, and so on.  The only one that does something different is the primitive &lt;code&gt;make-process&lt;/code&gt;, which is a more extensive version that can (additionally) create network processes, send data through TCP or Unix sockets and so on.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Emacs will try to prioritize user input events.  To do this it can delay tasks like reading from subprcesses if necessary.  &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Idle-Timers.html&#34;&gt;Idle timers&lt;/a&gt; are another example of this.  Some actions are thus &lt;span class=&#34;Green&#34;&gt;delayable&lt;/span&gt;, but they block Emacs when they (eventually) run.  There might be a penalty to pay afterwards, for instance when there&amp;rsquo;s more subprocess output to process as a result of delaying the task.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--org-latex-preview-process-filters-sentinels&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;details class=&#34;details apinote&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Process filters and sentinels: Handling process output&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;By default, Emacs inserts the output from a subprocess into the process buffer, or ignores it if there is no process buffer.  (Crucially, it still has to read the output from the process pipe.)  This is good enough for simple tasks.  To use or transform subprocess output in more specialized ways, you can write an elisp function that is used as a &lt;em&gt;process filter&lt;/em&gt;.  It is called whenever Emacs reads new process output.  In the language of shell commands, I think of process filters like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      $ start-process &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;some-process&amp;#34;&lt;/span&gt; 2&amp;gt;&amp;amp;&lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1&lt;/span&gt; | process-filter
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Process filters can be tricky to write if you want to parse structured process output, because the amount of data that Emacs reads from the pipe can be arbitrary.  Unless latency is a concern, it&amp;rsquo;s often preferable to work with &lt;em&gt;process sentinels&lt;/em&gt; for this reason.  Sentinels are the second tool Emacs makes available for reacting to processes.  A process sentinel is an elisp function (callback) called whenever the process changes state or raises a signal, including when it terminates.  Practically speaking, I think of them like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      $ start-process &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;some-process&amp;#34;&lt;/span&gt; 2&amp;gt;&amp;amp;&lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1&lt;/span&gt; &amp;gt; process-buffer &lt;span style=&#34;color:#333&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style=&#34;color:#666;background-color:#fff0f0;font-weight:bold&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666;background-color:#fff0f0;font-weight:bold&#34;&gt;&lt;/span&gt;          process-sentinel &amp;lt; process-buffer
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;They are typically used for cleaning up after the process, and updating Emacs&amp;rsquo; state depending on how the subprocess ends.  But you can use them to access the process buffer containing all the process output, and thus do whatever you would in the filter.&lt;/p&gt;
&lt;p&gt;Filters and sentinels can be attached to a subprocess object created with &lt;code&gt;start-process&lt;/code&gt; using &lt;code&gt;set-process-filter&lt;/code&gt; and &lt;code&gt;set-process-sentinel&lt;/code&gt; respectively.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Many blocking operations can be interrupted by signaling a &lt;code&gt;quit&lt;/code&gt;: this is what pressing &lt;code&gt;C-g&lt;/code&gt; does, with some variations, in most contexts.  Crucially for us, however, quitting is suppressed when Emacs is handling subprocess output or signals
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
This is to keep your &lt;code&gt;C-g&lt;/code&gt; from doing something unpredictable to &amp;ldquo;background&amp;rdquo; code that you didn&amp;rsquo;t initiate.
&lt;/small&gt;&lt;/span&gt;
.  If Emacs is blocked because it&amp;rsquo;s reading a large data dump&amp;hellip; well, tough luck.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;details class=&#34;details apinote&#34;&gt;
&lt;summary&gt;Interrupting code &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;&lt;code&gt;keyboard-quit&lt;/code&gt; (&lt;code&gt;C-g&lt;/code&gt;) is a &lt;em&gt;specific&lt;/em&gt; input that interrupts &lt;em&gt;any&lt;/em&gt; code, with a few exceptions.&lt;/p&gt;
&lt;p&gt;The obverse of this is to wrap code in a &lt;code&gt;while-no-input&lt;/code&gt; clause &amp;ndash; now &lt;em&gt;any&lt;/em&gt; input will interrupt the processing of &lt;em&gt;this&lt;/em&gt; specific block.  This can be used to do background processing in small chunks without making Emacs unresponsive, but there are subtleties involved that I&amp;rsquo;m not familiar with.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Despite these carveouts, a package that interacts heavily with external processes faces a latency-throughput tradeoff.  The more time Emacs spends starting processes and managing their output, the less attention it can pay to your input.  Designing Org&amp;rsquo;s LaTeX preview thus involves finding an acceptable balance.&lt;/p&gt;
&lt;p&gt;&lt;a id=&#34;figure--emacs-latency-vs-throughput&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-latency-vs-throughput.png&#34;
         alt=&#34;Figure 2: (Top) Emacs dealing with a &amp;amp;ldquo;fat&amp;amp;rdquo; high-throughput process, where it spends a chunk of time reading subprocess output. The time between reading your input and running the resulting command is thus longer than (bottom) the &amp;amp;ldquo;thin&amp;amp;rdquo; low-throughput case.&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 2: &lt;/span&gt;(Top) Emacs dealing with a &amp;ldquo;fat&amp;rdquo; high-throughput process, where it spends a chunk of time reading subprocess output.  The time between reading your input and running the resulting command is thus longer than (bottom) the &amp;ldquo;thin&amp;rdquo; low-throughput case.&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;It is &lt;em&gt;significantly&lt;/em&gt; easier to write a large Emacs library than an equally versatile plugin for most plugin systems built around multi-threaded GUI applications.  I say this as a non-programmer who has only succeeded at the former.  We lean on the interpreter lock in many ways, choosing &lt;a href=&#34;#how-it-works-data-flow&#34;&gt;simple data structures&lt;/a&gt; and &lt;a href=&#34;#how-it-works-control-flow&#34;&gt;control flow&lt;/a&gt; that wouldn&amp;rsquo;t work if Emacs was multi-threaded.  But most of Emacs wouldn&amp;rsquo;t work if Emacs was multi-threaded, anyway.  In for a penny&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;the-frontend-displaying-images-over-text&#34;&gt;The Frontend: Displaying images over text&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Overlays.html&#34;&gt;Overlays&lt;/a&gt; are a way to alter the appearance or behavior of regions of buffer text without modifying the text itself.  Displaying images is one of their most common uses: LaTeX preview images are overlaid on top of the source fragments.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/olp-before-and-after-2.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Once you have the preview images in hand, placing them in overlays and managing their state is essentially all the LaTeX preview code does.&lt;/p&gt;
&lt;p&gt;In fact, overlays account for much of the display trickery in Emacs:  Images over text?  Overlays. &amp;ldquo;Virtual text&amp;rdquo; like in &lt;code&gt;whitespace-mode&lt;/code&gt;?  Overlays.  &lt;a href=&#34;https://github.com/xiongtx/eros&#34;&gt;Inline results&lt;/a&gt; of code evaluation: overlays. &lt;a href=&#34;https://github.com/magnars/multiple-cursors.el&#34;&gt;Multiple cursors&lt;/a&gt;? Those are overlays.  Emacs has only one cursor.&lt;/p&gt;
&lt;details class=&#34;details apinote&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Making overlays&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;For a quick look into the overlay API, run &lt;code&gt;M-x shortdoc&lt;/code&gt; &lt;code&gt;overlay&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The even shorter version: We can create an overlay &lt;code&gt;ov&lt;/code&gt; from buffer position &lt;code&gt;BEG&lt;/code&gt; to &lt;code&gt;END&lt;/code&gt; with&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;make-overlay&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;BEG&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;END&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;and move it around with&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;move-overlay&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;NEW-BEG&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;NEW-END&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To avoid creating garbage, it is preferable to reuse overlays when possible instead of throwing them away with &lt;code&gt;(delete-overlay ov)&lt;/code&gt; and starting over. &lt;code&gt;move-overlay&lt;/code&gt; can move them to other buffers too.&lt;/p&gt;
&lt;p&gt;The only other tricky question is what happens to the overlay when text is inserted at its left or right boundaries.  Does it expand to contain the text?  This is left as an exercise for the reader.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;These alterations are specified by adding or modifying the overlay&amp;rsquo;s &amp;ldquo;properties&amp;rdquo;.  Like &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Symbol-Properties.html&#34;&gt;symbol properties&lt;/a&gt;, overlay properties are a way to store arbitrary information along with the overlay, and &lt;code&gt;org-latex-preview&lt;/code&gt; uses them to keep track of state, such as whether the preview image is out of date because the LaTeX fragment has been edited, and to store LaTeX compilation errors for the corresponding fragment.&lt;/p&gt;
&lt;details class=&#34;details apinote&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Overlay properties&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;To set and retrieve overlay properties, we can use&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prop&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;value&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-get&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prop&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;where the property &lt;code&gt;prop&lt;/code&gt; is any elisp symbol.  There is also an &lt;code&gt;overlay-properties&lt;/code&gt; function to access the full list.  Once again, &lt;code&gt;M-x shortdoc&lt;/code&gt; &lt;code&gt;overlay&lt;/code&gt; has us covered.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;figure class=&#34;alignright&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/olp-phi-overlaid.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Some properties have special meanings as interpreted by Emacs&amp;rsquo; display engine.  &lt;code&gt;display&lt;/code&gt;, the most common property, changes how the overlay region appears on screen, and this is typically set to the image we want to see in place of the text.&lt;/p&gt;
&lt;p&gt;But several more interesting modifications are possible with overlays, such as changing the face (font+style) of the underlying text, making it invisible, making it intangible to the cursor, or specifying keymaps that are activated when the cursor is within the bounds of the overlay.&lt;/p&gt;
&lt;details class=&#34;details apinote&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Fun with overlay properties&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;The only other detail we need is the &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Overlay-Properties.html&#34;&gt;list of overlay properties&lt;/a&gt; that Emacs considers special.  The &lt;code&gt;display&lt;/code&gt; property can be used to show an image instead of the text &amp;ldquo;below&amp;rdquo; (or &amp;ldquo;under&amp;rdquo;) the overlay, for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;img&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;create-image&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;/path/to/image.png&amp;#34;&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;display&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;img&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;p&gt;The &lt;code&gt;face&lt;/code&gt; property can change the display of the text.  Here we dim the text the overlay covers:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;face&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;shadow&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here are a few more interesting uses of other special overlay properties.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Send a message if the text under the overlay changes:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;notify-on-ov-change&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;after-p&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;beg&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;end&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;after-p&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;message&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Text changed: %s&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-substring-no-properties&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;beg&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;end&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;modification-hooks&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;list&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;notify-on-ov-change&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can use this to set up a &amp;ldquo;watcher&amp;rdquo; &amp;ndash; perhaps run a process when a region inside a buffer changes
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
If you want to set up a watcher on the contents of the entire buffer as opposed to a piece of it, you should avoid overlays and look at the hook &lt;code&gt;after-change-functions&lt;/code&gt; instead.  Be warned: it&amp;rsquo;s easy to slow down Emacs to a crawl this way if you&amp;rsquo;re not careful.
&lt;/small&gt;&lt;/span&gt;
!  This is not hypothetical: &lt;code&gt;preview-latex&lt;/code&gt; does this to &lt;a href=&#34;#precompilation&#34;&gt;re-dump the LaTeX preamble&lt;/a&gt; of TeX files (in the background) as you edit them.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Add a highlight and tooltip (&amp;ldquo;hover text&amp;rdquo;) when the mouse is on the overlay:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;mouse-face&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;highlight&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;help-echo&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;You&amp;#39;re on an overlay, pal.&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;p&gt;Open the displayed image externally when pressing &lt;code&gt;RET&lt;/code&gt; with the cursor on it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-put&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;keymap&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; (&lt;span style=&#34;color:#963&#34;&gt;define-keymap&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;RET&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; () (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#963&#34;&gt;when-let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;img&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;get-char-property&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;display&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 ((&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;imagep&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;img&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;image-property&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;img&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:file&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;start-process&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;view-image&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                      &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;xdg-open&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This works by defining a &lt;code&gt;keymap&lt;/code&gt; overlay property with the required function.  (On non-Linux systems, you will want to change &lt;code&gt;&amp;quot;xdg-open&amp;quot;&lt;/code&gt; to an equivalent command-line utility.)&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Center an image in a window:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;img&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;image-create&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;/path/to/image.png&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#963&#34;&gt;spacing&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;propertize&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; &amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;face&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;default&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;display&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;space&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:align-to&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;center&lt;/span&gt; (&lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.5&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;img&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;display&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;img&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;before-string&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;spacing&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This image stays centered as you resize the window:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/olp-overlay-image-centered.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/olp-overlay-image-centered.mp4&#34;&gt;[Video: Centered images using overlays]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;This one needs a little explanation:  The &lt;code&gt;before-string&lt;/code&gt; overlay property displays an object before the overlay itself.  The object we choose to display is some propertized text with a &lt;code&gt;display&lt;/code&gt; &lt;em&gt;text-property&lt;/em&gt;.  The &lt;code&gt;display&lt;/code&gt; text-property provides the means to &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Pixel-Specification.html&#34;&gt;insert spaces of specified widths&lt;/a&gt;, and a symbolic way to refer to the text margins, window center and horizontal window boundary positions.  Combining the two gives us (consistently) centered images in Emacs.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;the-reactive-ui-hooks-and-timers&#34;&gt;The Reactive UI: Hooks and Timers&lt;/h3&gt;
&lt;p&gt;In its basic form, the LaTeX preview feature involves no reactive behavior: there is one command to overlay preview images on LaTeX fragments, another to clear those overlays, and nothing else.&lt;/p&gt;
&lt;p&gt;But this is a far cry from our goal of real-time feedback.  For LaTeX previews to be automatically generated and updated as we type, we need both timers and &lt;em&gt;hooks&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Hooks are variables provided by Emacs where we can register code to run at certain points.  In this case, we want to react primarily to two kinds of user inputs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Cursor motion, so that entering a previewed LaTeX fragment reveals its source and leaving it re-displays the image.&lt;/li&gt;
&lt;li&gt;Buffer changes, so that a preview generation subprocess automatically fires when a new LaTeX fragment is typed in or an existing one is edited.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In turn, &lt;code&gt;org-latex-preview&lt;/code&gt; exposes hooks of its own for consumers to run additional processing.  These fire when LaTeX subprocesses finish, when overlays are created, and so on.&lt;/p&gt;
&lt;p&gt;Timers are complementary to hooks, used to space out or limit the consequences of hooks firing.  They are used&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;to keep these hooks from firing &lt;em&gt;all the time&lt;/em&gt;, which would create redundant subprocesses with each edit, locking up the main loop.  They provide the means to implement &lt;a href=&#34;https://karthinks.com/software/cool-your-heels-emacs/&#34;&gt;throttling and debouncing&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;to delay clean-up tasks like deleting intermediate LaTeX output until Emacs is idle.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;the-structure-of-org-latex-preview&#34;&gt;The structure of &lt;code&gt;org-latex-preview&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Besides basic Elisp data structures, that&amp;rsquo;s everything we need from Emacs to implement non-blocking, fast LaTeX previews.  Assuming you have a handle on what &lt;code&gt;org-latex-preview&lt;/code&gt; does, we can start peering into the how.&lt;/p&gt;
&lt;h3 id=&#34;how-it-works-control-flow&#34;&gt;How it works: control flow&lt;/h3&gt;
&lt;p&gt;Here is a high-level overview of the control flow of LaTeX preview generation:&lt;/p&gt;
&lt;p&gt;&lt;a id=&#34;figure--org-latex-preview-process-chart&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/olp-control-flowchart.svg&#34;
         alt=&#34;Figure 3: Control flow for Org mode&amp;amp;rsquo;s LaTeX preview system.&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 3: &lt;/span&gt;Control flow for Org mode&amp;rsquo;s LaTeX preview system.&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;This is a rough picture of how LaTeX previews are generated in Org mode, subdivided into tasks
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
The made-up term &amp;ldquo;task&amp;rdquo; corresponds to a handful of functions devoted, in our heads, to one purpose.
&lt;/small&gt;&lt;/span&gt;
.  Each action belongs to one of three categories:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&#34;Orange&#34;&gt;Blocking&lt;/span&gt; tasks: These must run synchronously and thus require the user to wait while Emacs is unresponsive.  We want this to be minimal and/or done ahead of time.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Green&#34;&gt;Delayable&lt;/span&gt; tasks: These tasks can be delayed if more immediate actions &amp;ndash; such as accepting user input &amp;ndash; are pending.  However, once such a task is started it runs synchronously and we&amp;rsquo;re locked in.  We want this work to be chunked into small independent pieces.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Purple&#34;&gt;Asynchronous&lt;/span&gt; tasks: These are subprocesses spawned by Emacs and managed by the OS.  Emacs monitors the process status and handles process output in a delayable fashion, but is otherwise unencumbered by them.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When a LaTeX preview command is issued, the first chunk of processing (the &lt;span class=&#34;Orange&#34;&gt;PREPARE&lt;/span&gt; block)&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;sets up overlays in the buffer that &amp;ldquo;cover&amp;rdquo; the fragments, with the intent to add preview images to them at the end,&lt;/li&gt;
&lt;li&gt;creates a TeX file containing the relevant LaTeX fragments from the Org buffer, along with a preamble.  This preamble is optionally precompiled, which can speed up processing considerably.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It then starts a two step process chain (the &lt;span class=&#34;Purple&#34;&gt;RUN&lt;/span&gt; block) that runs asynchronously.  The end result of a successful run is a preview image or series of images.&lt;/p&gt;
&lt;p&gt;The &lt;span class=&#34;Green&#34;&gt;PROCESS FILTERS&lt;/span&gt; block: From this point on until either process ends, Emacs checks in periodically through the associated process filter, acting on the &lt;code&gt;STDOUT&lt;/code&gt; to capture various bits of preview metadata.  It also keeps track of images that have finished processing, and (synchronously) caches them and adds them to the overlays in the buffer for these fragments.  This continuous update is doubly useful:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Previews start appearing in the buffer much faster, with the window viewport being updated first.&lt;/li&gt;
&lt;li&gt;This processing happens in small chunks instead of all at once at the end, so Emacs stays more (even if not fully) responsive to input.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;span class=&#34;Orange&#34;&gt;POSTPROCESS&lt;/span&gt; block: After the subprocesses have finished, Emacs runs their process sentinels, which clean up the detritus of this process chain, or reset the buffer if the preview run failed.&lt;/p&gt;
&lt;p&gt;And speaking of detritus&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;how-it-works-file-i-o&#34;&gt;How it works: file I/O&lt;/h3&gt;
&lt;p&gt;&lt;a id=&#34;figure--org-latex-preview-file-chart&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/olp-files-flowchart.svg&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;This figure shows the same process but with an emphasis on disk I/O.  The primary chain is &lt;span style=&#34;background: #88c0d0;color:black&#34;&gt;TeX file&lt;/span&gt; → &lt;span style=&#34;background: #88c0d0;color:black&#34;&gt;DVI/PDF output file&lt;/span&gt; → &lt;span style=&#34;background: #88c0d0;color:black&#34;&gt;SVG/PNG preview images&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Of the file categories involved in the process, we care about two: the &amp;ldquo;format dump file&amp;rdquo; produced by precompilation, and the preview images.  Both are cached and persisted across Emacs sessions.  All other produced files are deleted by the POSTPROCESS block.&lt;/p&gt;
&lt;h3 id=&#34;how-it-works-data-flow&#34;&gt;How it works: data flow&lt;/h3&gt;
&lt;p&gt;Displaying previews that are color-, alignment- and size-aware, along with associated information like errors, requires a considerable amount of bookkeeping.  Since this information arrives piecemeal and processing happens asynchronously in chunks, we also need some way of storing and passing along this context.  There are perhaps clever ways to do this, but we use a straightforward solution &amp;ndash; a (dynamic) global plist that associates each active process chain with its data (see &lt;a href=&#34;#org-target--org-latex-preview-org-async-explainer&#34;&gt;org-async&lt;/a&gt; below).&lt;/p&gt;
&lt;figure class=&#34;alignright&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/olp-data-extended-info.svg&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;All of the data generated and required for the many tasks in our process chain are captured in a single mutable container, referred to here &amp;ndash; for convenience &amp;ndash; as &amp;ldquo;Extended Info&amp;rdquo; (&lt;code&gt;extended-info&lt;/code&gt;).  This data includes&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;User preferences for the preview run, such as the LaTeX compiler in use,&lt;/li&gt;
&lt;li&gt;Input LaTeX strings to be rendered,&lt;/li&gt;
&lt;li&gt;Input file paths, output image paths and image cache details,&lt;/li&gt;
&lt;li&gt;Emacs&amp;rsquo; context like the current buffer &amp;ndash; which is important since we need to restore it before we can run asynchronous callbacks,&lt;/li&gt;
&lt;li&gt;Overlay positions and properties,&lt;/li&gt;
&lt;li&gt;Compilation errors,&lt;/li&gt;
&lt;li&gt;Computed preview geometry and fontsize for alignment,&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;and more besides.&lt;/p&gt;
&lt;details class=&#34;details implementation&#34;&gt;
&lt;summary&gt;&lt;code&gt;extended-info&lt;/code&gt;: implementation &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/lisp-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;&amp;ldquo;Extended Info&amp;rdquo; is implemented as a plist (property list).  Actually, almost every compound data structure &lt;code&gt;org-latex-preview&lt;/code&gt; uses is either an alist or a plist, which is just a linked-list under the hood.  &lt;code&gt;extended-info&lt;/code&gt; is also a tree since a few of its members are plists themselves (&lt;a href=&#34;#org0ce9534&#34;&gt;see below&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;We used property lists at first since they&amp;rsquo;re mutable and schema-less, and the design of the library was very fluid.  Unfortunately we are now well past the point where we could switch to something more structured like &lt;code&gt;cl-defstruct&lt;/code&gt;, so plists it is.&lt;/p&gt;
&lt;p&gt;If it&amp;rsquo;s any consolation, most of Org works with large property lists too.  Org&amp;rsquo;s export system passes around a big &lt;code&gt;plist&lt;/code&gt; bucket for communication in much the same way we do here.  Access can get expensive as they grow, but at least passing them around is cheap.  It&amp;rsquo;s&amp;hellip; not much of a consolation.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details class=&#34;details apinote&#34;&gt;
&lt;summary&gt;&lt;code&gt;apply&lt;/code&gt; yourself: property lists as arguments &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;plists have one other coincidental(?) advantage: You can splice them in as arguments to a &lt;code&gt;cl-defun&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Consider:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;cl-defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;foo&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;key&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;current-buffer&lt;/span&gt;)) (&lt;span style=&#34;color:#963&#34;&gt;valid-p&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;pred&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;ignore&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;allow-other-keys&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; body of foo&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  )
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This function has the signature&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;foo&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:buf&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;some-buffer&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:valid-p&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:pred&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;always&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;which is just a list with the name of the function followed by&amp;hellip; a plist.  So we can build up the plist programmatically and use it directly as &lt;code&gt;foo&lt;/code&gt;&amp;rsquo;s argument list:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;arglist&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;:buf&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;some-buffer&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:valid-p&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:pred&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;always&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:unknown-key&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;foo&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arglist&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&amp;rsquo;tis a silly thing but oh, so satisfying.  In fact, this is a convenient way to feed a job spec to &lt;code&gt;org-async&lt;/code&gt; (&lt;a href=&#34;#org-target--org-latex-preview-org-async-explainer&#34;&gt;see below&lt;/a&gt;).&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h4 id=&#34;how-extended-info-is-populated&#34;&gt;How &lt;code&gt;extended-info&lt;/code&gt; is populated&lt;/h4&gt;
&lt;p&gt;The setup functions in the &lt;span class=&#34;Orange&#34;&gt;PREPARE&lt;/span&gt; block initialize this bucket with data from parsing the buffer &amp;ndash; i.e., LaTeX fragment locations, equation numbers, etc.  From then on, each task updates &lt;code&gt;extended-info&lt;/code&gt; with progressively more information.  The structure of &lt;code&gt;extended-info&lt;/code&gt; and this flow of information into it is visualized in this &amp;ldquo;data flow&amp;rdquo; diagram:&lt;/p&gt;
&lt;div class=&#34;wide&#34;&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/olp-in-data-flowchart.svg&#34;/&gt;
&lt;/figure&gt;

&lt;/div&gt;
&lt;p&gt;Contained in &amp;ldquo;Extended Info&amp;rdquo;: &amp;ldquo;Processing Info&amp;rdquo; contains information about and relevant to the external process (LaTeX and the image converter).  &amp;ldquo;Fragment&amp;rdquo; is a list of metadata for fragments to be previewed, including the overlays that will eventually display the preview images.  All of this preview metadata is obtained from the outputs of the latex and image converter runs via the process filters.&lt;/p&gt;
&lt;p&gt;Note that Emacs&amp;rsquo; interpreter lock precludes data races and other concurrency issues, since only one function modifies &lt;code&gt;extended-info&lt;/code&gt; at a time.&lt;/p&gt;
&lt;h4 id=&#34;how-extended-info-is-accessed&#34;&gt;How &lt;code&gt;extended-info&lt;/code&gt; is accessed&lt;/h4&gt;
&lt;p&gt;The above chart only captures the flow of data in one direction: from the sources of computation into the &lt;code&gt;extended-info&lt;/code&gt; container.  Tasks that don&amp;rsquo;t modify &lt;code&gt;extended-info&lt;/code&gt; still need to read it  to do their jobs.  For example,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span class=&#34;Green&#34;&gt;Clean up temporary files&lt;/span&gt; needs the paths to the temporary files.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Orange&#34;&gt;Cache images and metadata&lt;/span&gt; needs the generated image paths, as well as all the geometry metadata.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Most functions in the process chain are passed &lt;code&gt;extended-info&lt;/code&gt;, or a subset thereof, as an argument.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/olp-out-data-flowchart.svg&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Once again, we get away with it because there are no concurrency problems when there is no concurrency.  This design pattern of passing around a single heap-allocated container across setup functions and callbacks works for all kinds of applications in Emacs.  This is exactly how Org&amp;rsquo;s (synchronous) export system manages information as well.&lt;/p&gt;
&lt;h2 id=&#34;org-latex-preview-pieces-and-the-org-api&#34;&gt;&lt;code&gt;org-latex-preview&lt;/code&gt; Pieces and the Org API&lt;/h2&gt;
&lt;p&gt;This is where we get into the weeds.  If you&amp;rsquo;re here for the bird&amp;rsquo;s eye view, you can skip ahead to &lt;a href=&#34;#live-previews-hooks-galore&#34;&gt;Live previews&lt;/a&gt; now.&lt;/p&gt;
&lt;h3 id=&#34;parsing&#34;&gt;Parsing&lt;/h3&gt;
&lt;p&gt;This is the &lt;span class=&#34;Orange&#34;&gt;Collect LaTeX Fragments&lt;/span&gt; task in the &lt;a href=&#34;#figure--org-latex-preview-process-chart&#34;&gt;control flow diagram&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Org&amp;rsquo;s syntax is &lt;a href=&#34;https://orgmode.org/worg/org-syntax.html#LaTeX_Fragments&#34;&gt;extensive&lt;/a&gt;, and parsing Org files used to involve a giant mess of regular expressions.  Thankfully the mess is now handled by the &lt;code&gt;org-element&lt;/code&gt; library, which provides a simple and powerful API for querying or acting on Org&amp;rsquo;s AST.  A fair amount of work has gone into making it perform well under the constraints of Emacs&amp;rsquo; single-threaded event loop
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Besides caching its state, it uses &lt;a href=&#34;#the-reactive-ui-hooks-and-timers&#34;&gt;timers&lt;/a&gt; to schedule parsing work outside of the times the user is interacting with Emacs.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;Crucially for us, Org has first-class support for LaTeX environments and fragments, and this greatly simplifies parsing and metadata handling.  This support is what makes using LaTeX in Org a pleasant experience in the first place.&lt;/p&gt;
&lt;details class=&#34;details orgnote&#34; id=&#34;org-latex-preview-org-element-explainer&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/org-mode-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; The &lt;code&gt;org-element&lt;/code&gt; library&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Added in late 2021, the &lt;code&gt;org-element&lt;/code&gt; library greatly simplifies the process of working with Org documents.&lt;/p&gt;
&lt;p&gt;I have a minimal working knowledge of the library, so this block covers only the aspects of &lt;code&gt;org-element&lt;/code&gt; that we use in &lt;code&gt;org-latex-preview&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Org&amp;rsquo;s syntax distinguishes between &amp;ldquo;elements&amp;rdquo; and &amp;ldquo;objects&amp;rdquo;, where anything &amp;ldquo;larger&amp;rdquo; than a paragraph is an element, and any syntax that could be contained within a paragraph is an object
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Incidentally, the default &lt;code&gt;mark-paragraph&lt;/code&gt; binding runs &lt;code&gt;org-mark-element&lt;/code&gt; in Org mode, which selects the smallest logical element is at point instead.  Try &lt;code&gt;M-h&lt;/code&gt; at different locations in an Org buffer to see what element you&amp;rsquo;re on!
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;This distinction matters to us because LaTeX text to be previewed can be either.  As you might expect, inline math (&lt;code&gt;$...$&lt;/code&gt; or &lt;code&gt;\(...\)&lt;/code&gt;) is an object, and LaTeX environments (&lt;code&gt;\begin{foo}...\end{foo}&lt;/code&gt;) are elements, and they differ in the way we must display the preview images.&lt;/p&gt;
&lt;p&gt;Every node in the AST as parsed by &lt;code&gt;org-element&lt;/code&gt; is made available as a plist whose keys are properties of the element.  These properties include the start and end positions of the element and its contents (&lt;code&gt;:begin&lt;/code&gt;, &lt;code&gt;:end&lt;/code&gt; and &lt;code&gt;:contents&lt;/code&gt;), as well as metadata like properties and keywords.  For example, every element can be named with a &lt;code&gt;#+name:&lt;/code&gt; keyword.&lt;/p&gt;
&lt;p&gt;These are the only things we need from &lt;code&gt;org-element&lt;/code&gt; as far as parsing goes.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;The objective of the parsing step is to find the bounds of LaTeX fragments in the buffer (or in some region).  In principle, we could do this with &lt;code&gt;org-element&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;org-element-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;org-element-parse-buffer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;latex-environment&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;latex-fragment&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;identity&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But this would be too slow, and would allocate far more memory than we need.  Instead, we use a simple regexp scan of the buffer to find the bounds of LaTeX fragments and environments, and &lt;code&gt;org-element&lt;/code&gt; only to gather specific metadata about these elements.&lt;/p&gt;
&lt;h3 id=&#34;preamble-generation&#34;&gt;Preamble generation&lt;/h3&gt;
&lt;p&gt;This is the &lt;span class=&#34;Orange&#34;&gt;Create preamble&lt;/span&gt; task in the &lt;a href=&#34;#figure--org-latex-preview-process-chart&#34;&gt;control flow diagram&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Many editor plugins (and web apps) implement LaTeX previews, usually via &lt;a href=&#34;https://www.mathjax.org/&#34;&gt;MathJax&lt;/a&gt; or &lt;a href=&#34;https://katex.org/&#34;&gt;KaTeX&lt;/a&gt;.  KaTeX is fast, and both function well for web pages with limited needs.  But they implement ersatz support for a limited number of LaTeX packages, and cannot consume an actual &amp;ldquo;full-fat&amp;rdquo; LaTeX preamble of the kind you might use when writing a research paper.  There is no &lt;code&gt;\usepackage{}&lt;/code&gt; macro or TikZ support, for example.&lt;/p&gt;
&lt;p&gt;By comparison, &lt;code&gt;org-latex-preview&lt;/code&gt; is backed by a full LaTeX engine and LaTeX distribution, so nothing is off the table.  Of course, this means we need a way to construct the preamble and feed it to the LaTeX engine.&lt;/p&gt;
&lt;p&gt;In addition to Emacs-wide settings (like &lt;code&gt;org-latex-preview-preamble&lt;/code&gt; and &lt;code&gt;org-latex-packages-alist&lt;/code&gt;), document-specific LaTeX headers can be specified with the &lt;code&gt;#+latex_header:&lt;/code&gt; directive:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-org&#34; data-lang=&#34;org&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#c00;font-weight:bold&#34;&gt;#+latex_header&lt;/span&gt;&lt;span style=&#34;color:#888&#34;&gt;: \newcommand{\sOmega}{{\scriptstyle \Omega}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#c00;font-weight:bold&#34;&gt;#+latex_header&lt;/span&gt;&lt;span style=&#34;color:#888&#34;&gt;: \DeclareMathOperator{\diag}{diag}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#c00;font-weight:bold&#34;&gt;#+latex_header&lt;/span&gt;&lt;span style=&#34;color:#888&#34;&gt;: \DeclareMathOperator{\toep}{toep}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#c00;font-weight:bold&#34;&gt;#+latex_header&lt;/span&gt;&lt;span style=&#34;color:#888&#34;&gt;: \usepackage{calc,cancel}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#c00;font-weight:bold&#34;&gt;#+latex_header&lt;/span&gt;&lt;span style=&#34;color:#888&#34;&gt;: \usepackage{rotating}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#c00;font-weight:bold&#34;&gt;#+latex_header&lt;/span&gt;&lt;span style=&#34;color:#888&#34;&gt;: \usepackage{tikz}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The combined preamble must be constructed when exporting the Org document to LaTeX, and this machinery lives in the &lt;code&gt;ox-latex&lt;/code&gt; library.  &lt;code&gt;org-latex-preview&lt;/code&gt; simply calls into it for the preamble.  Among other benefits, this means the preamble used for the preview run is identical to the one used for LaTeX exports
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
unless you &lt;em&gt;want&lt;/em&gt; them to differ, because of course Org provides ways to do that
&lt;/small&gt;&lt;/span&gt;
, so these truly are &lt;em&gt;previews&lt;/em&gt;.&lt;/p&gt;
&lt;details class=&#34;details orgnote&#34;&gt;
&lt;summary&gt;The &lt;code&gt;org-export&lt;/code&gt; (&lt;code&gt;ox&lt;/code&gt;) library &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/org-mode-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;The &lt;code&gt;ox&lt;/code&gt; library and its children, like &lt;code&gt;ox-latex&lt;/code&gt; provide an interface to convert Org documents to any other format, like Pandoc does.&lt;/p&gt;
&lt;p&gt;While the specifics (like collating a LaTeX preamble) are output-format dependent, the basic method is uniform and simple.  An exporter maps each Org syntax &lt;a href=&#34;#org76ac7ab&#34;&gt;element and object&lt;/a&gt; to a function that creates the equivalent in the output format, like image links to HTML &lt;code&gt;img&lt;/code&gt; tags, or &lt;code&gt;#+begin_quote ... #+end_quote&lt;/code&gt; blocks to HTML blockquotes elements.  The fact that the Org syntax supports LaTeX environments natively helps with LaTeX exports.&lt;/p&gt;
&lt;p&gt;Of course, when a clean mapping like this is not possible, you can work on the buffer directly and rip out and replace raw text.  Emacs, huh.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;This does make &lt;code&gt;ox-latex&lt;/code&gt; one of the few dependencies of &lt;code&gt;org-latex-preview&lt;/code&gt;, which is regrettable given the larger aim of &lt;a href=&#34;#latex-previews-everywhere-in-emacs&#34;&gt;providing LaTeX previews across Emacs&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;precompilation&#34;&gt;Precompilation&lt;/h3&gt;
&lt;p&gt;This is the &lt;span class=&#34;Orange&#34;&gt;Precompile LaTeX preamble&lt;/span&gt; task in the &lt;a href=&#34;#figure--org-latex-preview-process-chart&#34;&gt;control flow diagram&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To process a preamble, the LaTeX engine needs to tokenize and execute tens of thousands of lines of macro source.  For a complex preamble, the kind you would use for a book, this can take several seconds on a modern processor.&lt;/p&gt;
&lt;p&gt;Since &lt;code&gt;org-latex-preview&lt;/code&gt; aims to provide close to real-time feedback as you type, we resort to a trick from the 1990s: we serialize the entire engine state &amp;ndash; the string pool, macro bodies as token lists, font data, engine execution parameters and so on &amp;ndash; into a single binary memory image.  This process, called &lt;em&gt;format dumping&lt;/em&gt; or &lt;em&gt;precompilation&lt;/em&gt;, was automated for document preambles by David Carlisle&amp;rsquo;s &lt;code&gt;mylatex.ltx&lt;/code&gt;, modernized as the &lt;code&gt;mylatexformat&lt;/code&gt; package by Florent Chervet.&lt;/p&gt;
&lt;p&gt;The upshot is that precompilation saves a significant amount of LaTeX startup time, reducing and (almost) flattening it across all preamble sizes.&lt;/p&gt;
&lt;p&gt;Precompilation relies on a number of hacks and only works because pdftex has changed little for decades.  Unfortunately, precompilation is not supported at all by xelatex and only partially by lualatex
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
preambles that load OpenType fonts or Lua code are unsupported
&lt;/small&gt;&lt;/span&gt;
, so &lt;code&gt;org-latex-preview&lt;/code&gt; is slow with the Unicode engines.&lt;/p&gt;
&lt;p&gt;Under a &lt;a href=&#34;#how-a-modern-latex-preview-system-should-work&#34;&gt;different LaTeX preview architecture&lt;/a&gt;, none of this would be needed.  But it&amp;rsquo;s what we have so far: a very 90s solution for a very 90s editor.&lt;/p&gt;
&lt;h3 id=&#34;creating-the-tex-file&#34;&gt;Creating the TeX file&lt;/h3&gt;
&lt;p&gt;And speaking of being stuck with an old architecture, depending on pdflatex implies that we have to create and feed it a TeX file for each batch of previews
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
pdflatex and friends do accept input via STDIN, but this did not work out for finicky reasons.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;This is the &lt;span class=&#34;Orange&#34;&gt;Create TeX file&lt;/span&gt; task in the &lt;a href=&#34;#figure--org-latex-preview-process-chart&#34;&gt;control flow diagram&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As you might expect, the generated TeX file contains a reference to the precompiled dump file and a listing of all the LaTeX fragments to be previewed.  Instead of placing them into the document separated by something like &lt;code&gt;\pagebreak&lt;/code&gt;, we place them inside &lt;code&gt;\begin{preview}&lt;/code&gt; and &lt;code&gt;\end{preview}&lt;/code&gt; blocks provided by the &lt;a href=&#34;https://www.ctan.org/pkg/preview&#34;&gt;preview.sty&lt;/a&gt; CTAN package.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;preview.sty&lt;/code&gt; is authored by David Kastrup, who also wrote the Emacs-side &lt;code&gt;preview.el&lt;/code&gt; package that&amp;rsquo;s part of AUCTeX.  &lt;code&gt;preview.el&lt;/code&gt; was the inspiration for &lt;code&gt;org-latex-preview&lt;/code&gt; &amp;ndash; it was clear at least that previews in Org mode could be much, much faster.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;preview.sty&lt;/code&gt; does three critical things for us:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It places each preview snippet (enclosed within &lt;code&gt;\begin{preview}&lt;/code&gt; and &lt;code&gt;\end{preview}&lt;/code&gt; blocks) on a separate page in the LaTeX output;&lt;/li&gt;
&lt;li&gt;it finds the boundaries of the generated text and crops the page down to them;&lt;/li&gt;
&lt;li&gt;and it reports the font size, image size and baseline position in the LaTeX process&amp;rsquo; output stream.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These modifications were technically doable through a combination of other packages (Org&amp;rsquo;s old implementation used the tightpage option of the preview machinery), but in cumbersome and error-prone ways.&lt;/p&gt;
&lt;p&gt;This makes &lt;code&gt;preview.sty&lt;/code&gt; an external dependency of &lt;code&gt;org-latex-preview&lt;/code&gt;.  Fortunately this package is included by default even with minimal installs of all common LaTeX distributions.&lt;/p&gt;
&lt;h3 id=&#34;the-process-runner&#34;&gt;The process runner&lt;/h3&gt;
&lt;p&gt;The pipeline from the LaTeX fragment text in the TeX file to images suitable for preview consists of two steps.  A LaTeX engine (pdflatex, xelatex or lualatex) produces DVI, XDV or PDF output, which is fed to an image converter (dvisvgm, dvipng or imagemagick) to produce PNG or SVG images.  This is the &lt;span class=&#34;Purple&#34;&gt;RUN&lt;/span&gt; block of the &lt;a href=&#34;#figure--org-latex-preview-process-chart&#34;&gt;control flow diagram&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This involves a fair bit of bookkeeping, and Emacs&amp;rsquo; callback-based async process management (via &amp;ldquo;process sentinels&amp;rdquo; and &amp;ldquo;process filters&amp;rdquo;) isn&amp;rsquo;t the most ergonomic tool for this.  In the absence of reliable async-io support, we use &lt;code&gt;org-async&lt;/code&gt;, a declarative process chain manager now bundled with Org mode.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--org-latex-preview-org-async-explainer&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;details class=&#34;details orgnote&#34;&gt;
&lt;summary&gt;The &lt;code&gt;org-async&lt;/code&gt; library &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/org-mode-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Because we need to run a chain of processes with different callback behaviors depending on the exit statuses, &lt;code&gt;org-latex-preview&lt;/code&gt; uses &lt;code&gt;org-async&lt;/code&gt;, a process queue manager that wraps Emacs&amp;rsquo; &lt;code&gt;start-process&lt;/code&gt;, process filter and process sentinel API.  It handles a lot of the bookkeeping for us, providing for&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;declarative specification of a tree of processes that branch on the exit status of a process,&lt;/li&gt;
&lt;li&gt;including the ability to register multiple callbacks as required,&lt;/li&gt;
&lt;li&gt;keeping track of the context (the &lt;code&gt;extended-info&lt;/code&gt; bucket in our case) and passing it to the filter and sentinel,&lt;/li&gt;
&lt;li&gt;and limiting the pool of concurrent subprocesses and handling timeouts.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The global variable that keeps track of the context data between async calls is managed by &lt;code&gt;org-async&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;div class=&#34;warning&#34;&gt;
&lt;p&gt;The following code might be out of date, please refer to the Org manual.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;An example of an &lt;code&gt;org-async&lt;/code&gt; job spec might look like the following (simplified for clarity):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;task-spec&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;list&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-async-task&lt;/span&gt;             &lt;span style=&#34;color:#888&#34;&gt;; &amp;lt;-- LaTeX compilation task&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;latex&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;-interaction&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;nonstopmode&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;texfile.tex&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#007020&#34;&gt;:buffer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#007020&#34;&gt;:info&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;extended-info&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#007020&#34;&gt;:filter&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;latex-preview-filter&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#007020&#34;&gt;:failure&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;latex-failure-callback&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#007020&#34;&gt;:success&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;list&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-async-task&lt;/span&gt; &lt;span style=&#34;color:#888&#34;&gt;; &amp;lt;-- Image conversion task&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;dvisvgm&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;--page=1-&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;-o out-%p.svg&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;texfile.dvi&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           &lt;span style=&#34;color:#007020&#34;&gt;:buffer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           &lt;span style=&#34;color:#007020&#34;&gt;:info&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;extended-info&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           &lt;span style=&#34;color:#007020&#34;&gt;:filter&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;dvisvgm-place-previews-filter&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           &lt;span style=&#34;color:#007020&#34;&gt;:failure&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;list&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;dvisvgm-failure-callback&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                          &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;log-errors-callback&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                          &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;cleanup-callback&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           &lt;span style=&#34;color:#007020&#34;&gt;:success&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;list&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;check-fragments&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                          &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;cleanup-callabck&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Starting this process chain is simple:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;org-async-call&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;task-spec&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;org-async-call&lt;/code&gt; also provides other conveniences like timeouts, retries and concurrent subprocess limits.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--org-latex-preview-dvipng-parallel-path&#34;&gt;&lt;/span&gt;
An example of this bookkeeping is that the pipeline isn&amp;rsquo;t always serial.  When generating PNG images with dvipng, we start LaTeX and dvipng in parallel.  Dvipng processes pages of the DVI file as they appear, while the LaTeX process is still churning them out.  (Generating PNG preview images for a large Org buffer is much faster than the other routes.)&lt;/p&gt;
&lt;h3 id=&#34;tracking-with-process-filters&#34;&gt;Tracking with process filters&lt;/h3&gt;
&lt;p&gt;On the other side of the process invocation are the &amp;ldquo;process filters&amp;rdquo;, which are callbacks &lt;a href=&#34;#figure--emacs-event-loop-simple&#34;&gt;called by the event loop&lt;/a&gt; whenever Emacs reads chunks of subprocess output.  This is the &lt;span class=&#34;Green&#34;&gt;PROCESS FILTERS&lt;/span&gt; block in the &lt;a href=&#34;#figure--org-latex-preview-process-chart&#34;&gt;control flow diagram&lt;/a&gt;.&lt;/p&gt;
&lt;details class=&#34;details apinote&#34;&gt;
&lt;summary&gt;A shell metaphor for process filters &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Following the &lt;a href=&#34;#org-target--org-latex-preview-process-filters-sentinels&#34;&gt;shell metaphor for process filters&lt;/a&gt;, a simple way to think of a process filter for an Emacs subprocess is as a sink at the end of a Unix pipe:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;some-process 2&amp;gt;&amp;amp;&lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1&lt;/span&gt; | process-filter
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In the LaTeX preview case, the picture is a little more complex as there are multiple processes:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;latex -interaction nonstopmode -output-directory /tmp preview-file.tex | latex-process-filter; &lt;span style=&#34;color:#666;background-color:#fff0f0;font-weight:bold&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666;background-color:#fff0f0;font-weight:bold&#34;&gt;&lt;/span&gt;dvisvgm --page&lt;span style=&#34;color:#333&#34;&gt;=&lt;/span&gt;1- --bbox&lt;span style=&#34;color:#333&#34;&gt;=&lt;/span&gt;preview -o image-file.svg preview-file.dvi | image-converter-process-filter
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The analogy is different for each of the image converters.  Since &lt;a href=&#34;#org-target--org-latex-preview-dvipng-parallel-path&#34;&gt;dvipng runs in parallel with LaTeX&lt;/a&gt;, for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#333&#34;&gt;{&lt;/span&gt; latex -interaction nonstopmode -output-directory /tmp preview-file.tex | latex-process-filter; &lt;span style=&#34;color:#333&#34;&gt;}&lt;/span&gt; &amp;amp; &lt;span style=&#34;color:#666;background-color:#fff0f0;font-weight:bold&#34;&gt;\
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666;background-color:#fff0f0;font-weight:bold&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#333&#34;&gt;{&lt;/span&gt; dvipng --follow -T tight --depth --height -o image-%09d.png preview-file.dvi | image-converter-process-filter; &lt;span style=&#34;color:#333&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;In &lt;code&gt;org-latex-preview&lt;/code&gt;&amp;rsquo;s process filters we look for the output (DVI or image) file paths, but also a variety of metadata that preview.sty and dvisvgm emit.  This includes geometry information like the width, height and baseline alignment of the image, and any compilation errors.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Sample LaTeX output with &lt;code&gt;preview.sty&lt;/code&gt; &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/term-logo.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Preview: Fontsize 10pt
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;! Preview: Snippet 1 started.
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&amp;lt;-&amp;gt;&amp;lt;-&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;l.9 \begin{preview}
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Preview: Tightpage -32891 -32891 32891 32891
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;! Preview: Snippet 1 ended.(973936+0x22609920).
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&amp;lt;-&amp;gt;&amp;lt;-&amp;gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;l.14 \end{preview}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The printed information is cryptic.  Here&amp;rsquo;s what the numbers mean.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &amp;ldquo;tightpage&amp;rdquo; line reports margins around the rendered equation:
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         Margins:
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         left  bottom  right    top
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    Preview: Tightpage -32891  -32891  32891  32891
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;The unit is &amp;ldquo;Base pts&amp;rdquo;, which is 1:65536 of a pt.  (There is an additional factor of 72:72.27 on top relating a Base pt to a scaled point.)&lt;/li&gt;
&lt;li&gt;The next line reports the width, depth (below baseline) and height (from baseline) of the image.
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                height     depth    width
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    ! Preview: Snippet 1 ended.(973936  +  0     x  22609920).
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;Finally, any compilation errors reported for each preview in the above output (none here) are captured as well.
&lt;ul&gt;
&lt;li&gt;Errors are reported on lines starting with &amp;ldquo;lN&amp;rdquo;, where N is the line number.&lt;/li&gt;
&lt;li&gt;Messages are reported (as above) on lines starting with &amp;ldquo;!&amp;rdquo;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;a href=&#34;https://www.ctan.org/pkg/preview&#34;&gt;preview.sty manual&lt;/a&gt; provides more details and documents other options.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;Sample image converter output streams &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/term-logo.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;pre-processing DVI file (format version 2)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;processing page 1
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  applying bounding box set by preview package (version 13.1)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  width=346.003754pt, height=15.362961pt, depth=.501877pt
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  graphic size: 346.003754pt x 15.864838pt (121.606411mm x 5.575853mm)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  output written to /tmp/org-tex-ang3Se-000000001.svg
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;1 of 1 page converted in 0.16035 seconds
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;[1 (preview-latex version 13.1) (preview-latex tightpage option detected, will use its bounding box) depth=1 height=29]
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--org-latex-preview-fiddly-details&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;details class=&#34;details apinote&#34;&gt;
&lt;summary&gt;Fine-tuning Emacs&amp;rsquo; process interaction parameters&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;Whenever Emacs reads chunks of subprocess output&amp;hellip;&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This phrasing omits some important but fiddly details about how often and how much output is read at a time, in much the same way as the Unix pipe &lt;code&gt;|&lt;/code&gt; symbol does.&lt;/p&gt;
&lt;p&gt;While the event loop is switching between &lt;a href=&#34;#figure--emacs-event-loop-simple&#34;&gt;its four main tasks&lt;/a&gt; continuously, there  are (only) a couple of knobs available at the Elisp level to manage how Emacs reads subprocess output.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;read-process-output-max&lt;/code&gt; limits how much it reads in one event loop turn.  Setting it to a high value means output from chatty processes will be read sooner, but at the expense of blocking user input.  This is, essentially, Emacs&amp;rsquo; &lt;a href=&#34;#figure--emacs-latency-vs-throughput&#34;&gt;latency vs throughput&lt;/a&gt; curse in a nutshell.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;process-adaptive-read-buffering&lt;/code&gt; tries to delay reading from subprocesses that produce very small chunks of data at a time, as this is inefficient.  In practice turning this on has tended to make things worse instead of better when running most subprocesses.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Trying to optimize this for &lt;code&gt;org-latex-preview&lt;/code&gt; has proved to be&amp;hellip; difficult.  The rates and sizes of output emitted varies significantly between different LaTeX engines and image converters:&lt;/p&gt;
&lt;p&gt;&lt;a id=&#34;figure--timing-chart-svg-and-png&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/olp_preview_timing_chart_svg_and_png.svg&#34;
         alt=&#34;Figure 4: Intervals for which Emacs is blocked when previewing using SVG and PNG images. The vertical axis is time, and the solid chunks are periods where Emacs is unresponsive.&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 4: &lt;/span&gt;Intervals for which Emacs is blocked when previewing using SVG and PNG images.  The vertical axis is time, and the solid chunks are periods where Emacs is unresponsive.&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;They differ even between different versions of the same program across Texlive versions:&lt;/p&gt;
&lt;p&gt;&lt;a id=&#34;figure--org-latex-preview-texlive-2022-vs-2023&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/texlive2022-vs-texlive2023.svg&#34;
         alt=&#34;Figure 5: A time-aligned flamegraph profile showing process filter calls for the LaTeX and image converter processes when using Texlive 2022 and 2023. In the aggregate, the LaTeX and dvisvgm binaries shipped with Texlive 2023 aren&amp;amp;rsquo;t faster or slower than the former. They just have a different profile across time to which it is difficult to adjust.&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 5: &lt;/span&gt;A time-aligned flamegraph profile showing process filter calls for the LaTeX and image converter processes when using Texlive 2022 and 2023.  In the aggregate, the LaTeX and dvisvgm binaries shipped with Texlive 2023 aren&amp;rsquo;t faster or slower than the former.  They just have a different profile across time to which it is difficult to adjust.&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;&lt;code&gt;org-latex-preview&lt;/code&gt; settles for a broadly acceptable set of defaults in this regard.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;But the main reason we use process filters here is that we can place images in the buffer as they are generated (and read in from the process STDOUT by the event loop), and don&amp;rsquo;t have to wait for the LaTeX or image converter processes to end.&lt;/p&gt;
&lt;h3 id=&#34;cleaning-up-with-process-sentinels&#34;&gt;Cleaning up with process sentinels&lt;/h3&gt;
&lt;p&gt;The unfortunate result of being forced to do file I/O at each step of the pipeline is that we are left with a trail of intermediate files that need to be swept away
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Instead of, say, a block of shared memory that can simply be freed.
&lt;/small&gt;&lt;/span&gt;
.  This is the &lt;span class=&#34;Orange&#34;&gt;POSTPROCESS&lt;/span&gt; block in the &lt;a href=&#34;#figure--org-latex-preview-process-chart&#34;&gt;control flow diagram&lt;/a&gt;, accomplished in the &amp;ldquo;process sentinels&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;A process sentinel is a callback invoked by the event loop when the process changes status.  In principle this includes any status change (exit, signal, stop/continue), but in practice we only care about it after the process exits.&lt;/p&gt;
&lt;p&gt;Clearing the intermediate detritus of the compilation is not an urgent task, so &lt;code&gt;org-latex-preview&lt;/code&gt;&amp;rsquo;s process sentinels actually schedule this on an idle timer.  Their other major function in this design is to diagnose process failures and restart the job when the cause looks transient.&lt;/p&gt;
&lt;h3 id=&#34;caching&#34;&gt;Caching&lt;/h3&gt;
&lt;p&gt;This is the &lt;span class=&#34;Orange&#34;&gt;Cache images and metadata&lt;/span&gt; task in the &lt;a href=&#34;#figure--org-latex-preview-process-chart&#34;&gt;control flow diagram&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;LaTeX preview generation is an order of magnitude (or two) faster than what Org did before, so caching preview images might seem like a secondary concern.  But &lt;code&gt;org-latex-preview&lt;/code&gt; still caches images, for a few reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The same state may be encountered dozens of times when editing a fragment with live previews.&lt;/li&gt;
&lt;li&gt;We would like to avoid rerunning LaTeX in contexts where the Org document itself is the final output, such as in-Emacs slideshow programs.&lt;/li&gt;
&lt;li&gt;When exporting to other formats (HTML or ODT), &lt;code&gt;org-latex-preview&lt;/code&gt; is responsible for generating the images to be bundled with the web page or document.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In addition to the text of the LaTeX fragment itself, preview images are specific to the LaTeX preview pipeline configuration, the preamble, the Emacs theme and even the fragment&amp;rsquo;s position in the buffer when equation numbering is turned on.  To cache previews reproducibly, all of these inputs are hashed together as the key to the cached image.&lt;/p&gt;
&lt;details class=&#34;details orgnote&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/org-mode-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; The &lt;code&gt;org-persist&lt;/code&gt; library&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;While you can specify where the preview images should be cached relative to the document, &lt;code&gt;org-latex-preview&lt;/code&gt; defaults to using &lt;code&gt;org-persist&lt;/code&gt;, a general-purpose caching library that is part of Org mode.  &lt;code&gt;org-persist&lt;/code&gt; is used for various caching duties by Org mode, such as resources fetched from the Internet and the partial syntax trees of parsed Org buffers.&lt;/p&gt;
&lt;p&gt;Caching LaTeX preview images actually involves more than copying a file somewhere and serializing a hash table to disk.  We also need to store, as Elisp data, the image display geometry information, including the baseline alignment height.  The &lt;code&gt;org-persist&lt;/code&gt; API supports caching different container kinds for exactly this purpose.&lt;/p&gt;
&lt;p&gt;Finally, with sufficient time (or a large enough corpus) the cache of LaTeX images can grow to gigabytes in size, so cache entries are set to expire after a month, another function served by &lt;code&gt;org-persist&lt;/code&gt;&amp;rsquo;s built-in garbage collection.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;displaying-images-and-overlay-management&#34;&gt;Displaying images and overlay management&lt;/h3&gt;
&lt;p&gt;This covers the in-buffer UI and affordances of &lt;code&gt;org-latex-preview&lt;/code&gt;, indicated by the &lt;span class=&#34;Orange&#34;&gt;Create overlays&lt;/span&gt; and &lt;span class=&#34;Orange&#34;&gt;Place LaTeX previews&lt;/span&gt; blocks in the &lt;a href=&#34;#figure--org-latex-preview-process-chart&#34;&gt;control flow diagram&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Beyond what is covered in &lt;a href=&#34;#the-frontend-displaying-images-over-text&#34;&gt;displaying images over text&lt;/a&gt;, displaying the image itself is simple: the image just needs to be resized and aligned according to the recorded geometry.  The overlays themselves are set up before starting the LaTeX run, and a series of overlay properties are set or unset over the course of the process.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If an existing image is being updated, the overlay optionally gets a &amp;ldquo;face&amp;rdquo; property indicating that the preview is out of date.&lt;/li&gt;
&lt;li&gt;If this is a fresh preview, an overlay property marks it as &amp;ldquo;processing&amp;rdquo;, displayed in the fringe.&lt;/li&gt;
&lt;li&gt;If any compilation errors are captured, they&amp;rsquo;re placed as tooltip text via an overlay property.  Via the SVG&amp;rsquo;s &lt;code&gt;currentColor&lt;/code&gt; attribute, we also color the overlay image red to indicate that there was an error.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These are basic but (hopefully) intuitive indicators of the state of the preview.&lt;/p&gt;
&lt;h2 id=&#34;live-previews-hooks-galore&#34;&gt;Live previews: Hooks galore&lt;/h2&gt;
&lt;p&gt;The breakdown provided so far does not explain the claims we made in the objectives section, like real-time (or at least fast) feedback as you type.  As seen in the demos above, there is one more element to making the previews appear &amp;ldquo;live&amp;rdquo; and reactive to cursor movement or buffer edits.&lt;/p&gt;
&lt;p&gt;For the seamless hide/show behavior:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Moving the cursor into the region covered by the overlay should &amp;ldquo;open&amp;rdquo; the overlay, reveal the underlying text and move the image next to or below the LaTeX fragment.&lt;/li&gt;
&lt;li&gt;Moving the cursor out of the region should do the reverse, and &amp;ldquo;close up&amp;rdquo; the overlay.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For real-time feedback:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Editing a fragment with a visible preview marks the preview out of date, so the image should either disappear or be updated.&lt;/li&gt;
&lt;li&gt;If editing displaymath and the numbering changes, all other numbered environments in the buffer should be updated as well.&lt;/li&gt;
&lt;li&gt;Editing a previewed fragment in another buffer (with &lt;code&gt;org-edit-special&lt;/code&gt;, &lt;code&gt;C-c &#39;&lt;/code&gt;) should cause the preview to be updated as you type.&lt;/li&gt;
&lt;li&gt;When typing or pasting text, LaTeX environments need to be detected and parsed, and the preview pipeline started in real time.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All of these are achieved using hooks, which is ultimately the only mechanism we have to trigger reactive behavior in Emacs.  The hide/show behavior involves tracking the cursor position via &lt;code&gt;pre-command-hook&lt;/code&gt; and &lt;code&gt;post-command-hook&lt;/code&gt; (made buffer-local).  Buffer edits are tracked via &lt;code&gt;after-change-functions&lt;/code&gt;, but with several fast-fail heuristics to avoid slowing down Emacs
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
The difficulty of identifying, in real time, &lt;code&gt;$&lt;/code&gt; and &lt;code&gt;$$&lt;/code&gt; as LaTeX delimiter starts, delimiter ends, or as actual dollar signs is why live previews require the unambiguous &lt;code&gt;\(...\)&lt;/code&gt; and &lt;code&gt;\[...\]&lt;/code&gt; delimiters, even though the dollars are supported in non-live usage.
&lt;/small&gt;&lt;/span&gt;
.  The list goes on, since we need to track Org&amp;rsquo;s folding states, as well as changes in other buffers when using &lt;code&gt;org-edit-special&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The other strategy we&amp;rsquo;re forced to employ, given the event loop&amp;rsquo;s limitations, is to throttle and debounce pipeline calls, batching edits and avoiding race conditions between in-flight LaTeX runs &amp;ndash; the interpreter lock protects Elisp state, but independent subprocesses will happily interleave and clobber each other&amp;rsquo;s output.&lt;/p&gt;
&lt;p&gt;Finally, this feature is the source of dozens of edge cases, such as editing fragments inside folded regions (during global text replacement, say), or the many invalid intermediate states of a LaTeX fragment causing the preview to fail repeatedly.  Knocking down these bugs while keeping this path fast was a substantial portion of the effort over the years this library was developed
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Now that it&amp;rsquo;s part of Org mode and seeing more widespread use, there are no doubt several more edge cases waiting to be reported!
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;h2 id=&#34;latex-previews-everywhere-in-emacs&#34;&gt;LaTeX previews everywhere in Emacs&lt;/h2&gt;
&lt;p&gt;A proof of concept: the design of &lt;code&gt;org-latex-preview&lt;/code&gt; makes it possible to preview LaTeX outside of Org mode.  Here&amp;rsquo;s an example previewing LaTeX-formatted comments in a prog buffer (Clojure, here):&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/olp-prog-preview.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/olp-prog-preview.mp4&#34;&gt;[Video demo: LaTeX previews in prog-mode]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;In fact, you can use the same code to preview LaTeX fragments literally anywhere in Emacs, including, delightfully, the Emacs calculator.  This (18 minute) demo runs through a bunch of contexts outside of Org mode showcasing live LaTeX previews:&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--org-latex-preview-everywhere-youtube-demo&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class=&#34;videocontainer&#34;&gt;&lt;iframe width=&#34;680&#34; height=&#34;382&#34; src=&#34;https://www.youtube-nocookie.com/embed/u44X_th6_oY&#34; title=&#34;YouTube video player&#34; frameborder=&#34;0&#34; allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&#34; allowfullscreen&gt;[&lt;a href=&#34;https://www.youtube.com/watch?v=u44X_th6_oY&#34;&gt;Video Demo (18:00)&lt;/a&gt;]&lt;/iframe&gt;&lt;/div&gt;
&lt;hr&gt;
&lt;p&gt;While this feature exists only as a prototype, it&amp;rsquo;s simple to implement and extend.  To see why, let&amp;rsquo;s look again at the &lt;a href=&#34;#figure--org-latex-preview-process-chart&#34;&gt;preview process breakdown&lt;/a&gt;.  All tasks here are agnostic of Org mode save for two:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/olp-non-org-flowchart.svg&#34;/&gt;
&lt;/figure&gt;

&lt;ul&gt;
&lt;li&gt;&lt;span class=&#34;Orange&#34;&gt;Collect LaTeX fragments&lt;/span&gt;: currently handled by &lt;code&gt;org-element&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Orange&#34;&gt;Create preamble&lt;/span&gt;: currently assembled by the &lt;code&gt;org-export&lt;/code&gt; (&lt;code&gt;ox-latex&lt;/code&gt;) library.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To use LaTeX previews outside of Org mode, we only need providers for these two tasks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A parser that can identify the boundaries of LaTeX fragments in the buffer
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Technically you could reuse &lt;code&gt;org-element&lt;/code&gt; in non-Org buffers for this, but there will be many false negatives and occasional false positives.
&lt;/small&gt;&lt;/span&gt;
.  This does not need to be a full-fledged parser &amp;ndash; just a regexp scan of the buffer looking for &lt;code&gt;\begin{&lt;/code&gt; or &lt;code&gt;\[&lt;/code&gt; can suffice.  This is how the above demos were created.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A LaTeX preamble generator appropriate for the buffer.  This can just be a constant string (instead of a function) that includes a reasonable set of LaTeX packages.  I used Org&amp;rsquo;s default LaTeX preamble string everywhere in the above demos.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;The Emacs-wide API for &lt;code&gt;org-latex-preview&lt;/code&gt; &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/lisp-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;warning&#34;&gt;
&lt;p&gt;This description might be out of date, please refer to the Org manual.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;org-latex-preview&lt;/code&gt; tries to separate these independent concerns by providing the function &lt;code&gt;org-latex-preview-place&lt;/code&gt;, that generates previews anywhere in Emacs given the above information.  Previewing LaTeX fragments is as simple as:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;require&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-latex-preview&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;org-latex-preview-place&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;dvisvgm&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;entries&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;preamble&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;where &lt;code&gt;entries&lt;/code&gt; encodes the start and end positions of the fragments, and &lt;code&gt;preamble&lt;/code&gt; is the LaTeX preamble to use.&lt;/p&gt;
&lt;div class=&#34;grid&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; entries is a list of lists&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; Each entry is (start end),&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; or (start end contents)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;((&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1342&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1388&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; (&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1911&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2104&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; (&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2273&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2295&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\\( \\epsilon + 3 \\)&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; preamble is a preamble string&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; See `org-latex-preview-preamble&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\\documentclass{article}
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; [DEFAULT-PACKAGES]
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; [PACKAGES]
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; \\usepackage{xcolor}&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The positions in &lt;code&gt;entries&lt;/code&gt; would be obtained from your parser for the major mode.  For &lt;code&gt;preamble&lt;/code&gt; you can just reuse or tweak &lt;code&gt;org-latex-preview-preamble&lt;/code&gt; in a pinch.  See the function documentation for more details.&lt;/p&gt;
&lt;p&gt;Requiring the &lt;code&gt;org-latex-preview&lt;/code&gt; library will in turn load a few Org libraries (&lt;code&gt;org-element&lt;/code&gt;, &lt;code&gt;org-persist&lt;/code&gt;, &lt;code&gt;ox&lt;/code&gt; and &lt;code&gt;org-macs&lt;/code&gt;), but it does &lt;em&gt;not&lt;/em&gt; load all of Org.  We tried hard to keep from loading the 16,000-line behemoth that is &lt;code&gt;org.el&lt;/code&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;As of late 2026, abstracting the library from its major-mode adapters remains on the TODO list.&lt;/p&gt;
&lt;h2 id=&#34;how-a-modern-latex-preview-system-should-work&#34;&gt;How a modern LaTeX preview system &lt;em&gt;should&lt;/em&gt; work&lt;/h2&gt;
&lt;p&gt;When we started &lt;code&gt;org-latex-preview&lt;/code&gt; in 2021, live-updating previews were not available anywhere except one LaTeX formula-editing website and, to a lesser degree, &lt;a href=&#34;https://www.lyx.org/&#34;&gt;LyX&lt;/a&gt;.  We often wondered why, since &lt;code&gt;preview.sty&lt;/code&gt; did most of the work for you and the editor side was pretty simple to implement.  If &lt;code&gt;org-latex-preview&lt;/code&gt; were a thrown-together external Emacs package providing many of the same features (sans polish), it could have been written over a couple of weekends.  I know this because &lt;a href=&#34;https://github.com/karthink/org-preview&#34;&gt;I wrote it&lt;/a&gt;.  &lt;a href=&#34;https://github.com/karthink/org-auctex&#34;&gt;Twice&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Over the years, however, this feature has grown in ubiquity and there are plugins for most note-taking (Obsidian) and editing software (Neovim, VS Code) that provide this.  Emacs itself has at least four active implementations of live LaTeX previews now, and a frontier LLM can probably implement a basic version for your preferred platform with one prompt.&lt;/p&gt;
&lt;p&gt;Even so, Emacs remains the oldest platform to implement this feature, and does so in the most complete and mature form
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
As of 2026.
&lt;/small&gt;&lt;/span&gt;
.  Considering I spent a lot of this write-up complaining about the limitations of the Elisp runtime, this is remarkable.&lt;/p&gt;
&lt;p&gt;But creating temporary files after every buffer change and spawning separate LaTeX processes remains a terrible way to do real-time updates.  Precompilation is another hack, unsupported by LaTeX engines besides pdflatex.  While &lt;code&gt;org-latex-preview&lt;/code&gt; is a massive improvement over the previous LaTeX preview implementation for Org mode, it&amp;rsquo;s still the Elisp equivalent of a Bash script that got out of hand.  Quite simply, this is the wrong level at which to address the problem.  A better way to implement continuous previews would be to talk to a managed process over a pipe or socket.  The right approach here is to work at the level of the TeX engine, as &lt;a href=&#34;https://github.com/let-def/texpresso&#34;&gt;TeXPresso&lt;/a&gt; does.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--org-latex-preview-dynamic-modules&#34;&gt;&lt;/span&gt;
But it would be even better to avoid inter-process communication entirely and use an &lt;a href=&#34;https://www.phimulambda.org/blog/emacs-dynamic-module.html&#34;&gt;Emacs dynamic module&lt;/a&gt;, linking with a modern LaTeX library that does incremental (instead of batch) compilation.  &amp;ldquo;Lightweight&amp;rdquo; alternatives like KaTeX or MathJaX don&amp;rsquo;t cut it, since we need a full-fat LaTeX compiler, macros and all.  One possible candidate for this is &lt;a href=&#34;https://github.com/HenryXiaoYang/realtime-tex&#34;&gt;realtime-tex&lt;/a&gt;, the &lt;code&gt;rtex&lt;/code&gt; library, which embeds LuaLaTeX (the most modern of the LaTeX engines) and compiles incrementally and effectively instantaneously
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Although I would be inclined to wait for the project to mature.
&lt;/small&gt;&lt;/span&gt;
.  This would be a quality improvement almost as drastic as the one &lt;code&gt;org-latex-preview&lt;/code&gt; makes over its predecessor.&lt;/p&gt;
&lt;p&gt;Of course, a dynamic module linking an incremental compiler is a completely different architecture from what we have now, and would share at most the image display and UI layer.  So projects like this and the inevitable official Typst preview package for Org are tabled for another day.  Maybe you&amp;rsquo;ll be the one to implement them?&lt;/p&gt;
</description>
    </item><item>
      <title>Even More Batteries Included with Emacs</title>
      <link>https://karthinks.com/software/even-more-batteries-included-with-emacs/</link>
      <pubDate>Sun, 14 Jun 2026 00:05:00 -0700</pubDate>
      
      <guid>https://karthinks.com/software/even-more-batteries-included-with-emacs/</guid>
      <description>&lt;p&gt;Emacs features have a discoverability problem, and we&amp;rsquo;re chipping away at it one
demo at a time.  The years since I wrote the last one of these have yielded more
surprising and useful finds, so it&amp;rsquo;s time again for a &amp;ldquo;batteries included&amp;rdquo;
report.&lt;/p&gt;
&lt;details class=&#34;details implementation&#34; open&gt;
&lt;summary&gt;Note&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;This is the third in a series of articles highlighting useful but lesser-known
features included in Emacs.&lt;/p&gt;
&lt;p&gt;Parts 1 &amp;amp; 2:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://karthinks.com/software/batteries-included-with-emacs/&#34;&gt;Batteries included with Emacs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://karthinks.com/software/more-batteries-included-with-emacs/&#34;&gt;More batteries included with emacs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;ldquo;Lesser-known&amp;rdquo; is a subjective judgment.  Roughly, it means that at the time of
writing, I have seen these features mentioned fewer than five times &amp;ndash; and often
never &amp;ndash; in the past two decades of dipping in and out of online Emacs
discourse.  Some of the features covered in past entries &lt;em&gt;are&lt;/em&gt; well known and
often recommended today.  I claim no credit.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;If you&amp;rsquo;re a new Emacs user, &lt;em&gt;don&amp;rsquo;t start here&lt;/em&gt;.  This is not a getting-started
guide.  You will be better served by grokking basic Emacs concepts and sticking
to the most widely recommended packages.  Once you&amp;rsquo;ve experienced the Emacs
equivalents of thoughts like &amp;ldquo;Why didn&amp;rsquo;t anyone think to put wheels on luggage
until 1990?&amp;rdquo;, this series might be more helpful.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
My rule of thumb is that if you aren&amp;rsquo;t yet aware of undo-in-region, there is
much low hanging fruit for the picking, and you can come back to this article
after that supply has run out!
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;Veteran Emacs users tend to use some relatively niche Emacs features, but in my
experience it&amp;rsquo;s always a different subset for each user.  So if you&amp;rsquo;ve been
around the block a few times, I promise there will still be surprises below for
you as well!&lt;/p&gt;
&lt;p&gt;Same rules as before:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;No packages, &lt;strong&gt;stock Emacs only&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;No steep learning curves. &lt;strong&gt;Learn each feature in under five minutes or bust&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;No gimmicks&lt;/strong&gt;. No &lt;code&gt;doctor&lt;/code&gt;, &lt;code&gt;tetris&lt;/code&gt;, &lt;code&gt;snake&lt;/code&gt;, &lt;code&gt;dunnet&lt;/code&gt;, &lt;code&gt;zone&lt;/code&gt;,
&lt;code&gt;butterfly&lt;/code&gt;&amp;hellip; yes, we know about &lt;code&gt;dissociated-press&lt;/code&gt;.  Let&amp;rsquo;s move on.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Just the deltas&lt;/strong&gt;. No commonly mentioned packages like Flymake, doc-view,
outline-minor-mode, gnus or eww. Nothing that Emacs brings up automatically or
a nonspecific Google search gets you.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Assume a modern Emacs, 28.1+.&lt;/p&gt;
&lt;p&gt;Also, if you&amp;rsquo;re new to Emacs and still reading:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Emacs jargon&lt;/th&gt;
&lt;th&gt;Modern parlance&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;M-x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Alt + x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ctrl + x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Frame&lt;/td&gt;
&lt;td&gt;Emacs window&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Window&lt;/td&gt;
&lt;td&gt;split/pane&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Buffer&lt;/td&gt;
&lt;td&gt;Contiguous chunk of text/data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Point&lt;/td&gt;
&lt;td&gt;Cursor position in buffer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Active Region&lt;/td&gt;
&lt;td&gt;Text selection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Region&lt;/td&gt;
&lt;td&gt;Text selection (not highlighted)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Face&lt;/td&gt;
&lt;td&gt;Font, color and display properties&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;I&amp;rsquo;m Sorry.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Okay? Let&amp;rsquo;s go:&lt;/p&gt;
&lt;h2 id=&#34;dictionary-on-hover--m-x-dictionary-tooltip-mode&#34;&gt;Dictionary on hover (&lt;code&gt;M-x dictionary-tooltip-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Turn on &lt;code&gt;dictionary-tooltip-mode&lt;/code&gt; to see word meanings in tooltips when you
hover over them:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/dictionary-tooltip-01.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Of course, &lt;code&gt;tooltip-mode&lt;/code&gt; will need to be enabled as well, but that&amp;rsquo;s the
default.&lt;/p&gt;
&lt;p&gt;If you have local dictionaries set up, it will try those first.  Note that
Emacs&amp;rsquo; dictionary can look up contemporary jargon and lingo too, usually via
Wiktionary:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/dictionary-tooltip-demo-01.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/dictionary-tooltip-demo-01.mp4&#34;&gt;[VIDEO: Emacs dictionary-tooltip-mode demo]&lt;/a&gt;&lt;/video&gt;
&lt;h2 id=&#34;find-file-and-dired-with-wildcards&#34;&gt;&lt;code&gt;find-file&lt;/code&gt; and &lt;code&gt;dired&lt;/code&gt; with wildcards&lt;/h2&gt;
&lt;p&gt;A surprisingly little known utility of two of the most used Emacs commands: you
can use wildcards when using both &lt;code&gt;find-file&lt;/code&gt; and &lt;code&gt;dired&lt;/code&gt; interactively.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When finding files with &lt;code&gt;find-file&lt;/code&gt; (&lt;code&gt;C-x C-f&lt;/code&gt;), open multiple files at once
with a wildcard like &lt;code&gt;*foo*.txt&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;When opening a directory with Dired, produce a custom listing of specific
files by specifying a filename wildcard.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here&amp;rsquo;s a demo where both features are used to clean up some (very) old TeX
compilation artifacts and then open a bunch of LaTeX files at once:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/dired-wildcard-demo-01.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/dired-wildcard-demo-01.mp4&#34;&gt;[VIDEO: Emacs Dired and Find-File wildcards demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;Run Dired with a &amp;ldquo;two-level&amp;rdquo; wildcard &lt;code&gt;*/*_region_*&lt;/code&gt;: look for all files with
&lt;code&gt;&amp;quot;_region_&amp;quot;&lt;/code&gt;  in their name, but only in sub-directories.&lt;/li&gt;
&lt;li&gt;Dired produces a listing of these files.  (These are temporary files created by
AucTeX.)&lt;/li&gt;
&lt;li&gt;Select them all (with &lt;code&gt;dired-toggle-marks&lt;/code&gt;, bound to &lt;code&gt;t&lt;/code&gt;) and delete them.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;find-file&lt;/code&gt; with a wildcard, opening all TeX files in sub-directories.&lt;/li&gt;
&lt;li&gt;Check the list of buffers to see that several TeX files have been opened.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;(The command used to see the list of open buffers is &lt;code&gt;consult-buffer&lt;/code&gt;, and the
completions are displayed by &lt;code&gt;Corfu&lt;/code&gt;.)&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;The fact that this is possible when calling them programmatically is evident
from their function signatures.  But realizing that this capability is also
available during interactive use requires reading through the full docstring,
and no one has the time for that!&lt;/p&gt;
&lt;p&gt;In practice the Dired wildcard capability is superseded by a modern workflow
like &lt;code&gt;consult-find&lt;/code&gt; exported as a Dired buffer by &lt;code&gt;embark-export&lt;/code&gt;, but this
works out of the box.&lt;/p&gt;
&lt;h2 id=&#34;list-all-uris-with-m-x-ffap-menu&#34;&gt;List all URIs with &lt;code&gt;M-x ffap-menu&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;You might be familiar with Emacs&amp;rsquo; &amp;ldquo;find-file-at-point&amp;rdquo; feature, &lt;code&gt;M-x ffap&lt;/code&gt;, that
checks if the cursor is on a valid file path and offers to open it.&lt;/p&gt;
&lt;p&gt;This is accompanied by &lt;code&gt;ffap-menu&lt;/code&gt;, a less well known but equally handy command.
&lt;code&gt;ffap-menu&lt;/code&gt; scans the whole buffer for anything that looks like a file path or
URL and presents you with all of them:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/ffap-menu-demo-01.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/ffap-menu-demo-01.mp4&#34;&gt;[VIDEO: Emacs ffap-menu demo]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;Since it offers a &lt;code&gt;completing-read&lt;/code&gt; interface, this opens up a small universe of
possibilities: you can export the list of (possibly filtered) completions into a
buffer, copy or open all or any subset of them, or otherwise act on them right
away with Embark.&lt;/p&gt;
&lt;h3 id=&#34;addendum-listing-propertized-links&#34;&gt;Addendum: Listing propertized links&lt;/h3&gt;
&lt;p&gt;Many Emacs applications (like EWW) include URLs as text properties and not
plain-text links, and &lt;code&gt;ffap-menu&lt;/code&gt; misses them.  Inspired by &lt;code&gt;ffap-menu&lt;/code&gt;, I use a
home-brew version that fetches such links as well.&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/search-occur-browse-url-01.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/search-occur-browse-url-01.mp4&#34;&gt;[VIDEO: Find all URLs demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;Start with EWW showing a Wikipedia page, with imenu on the left.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;my/search-occur-browse-url&lt;/code&gt;, a custom command inspired by &lt;code&gt;ffap-menu&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Scroll through the list of page links, and scroll through the page itself.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;The enhanced version:&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Searching for all URLs in the buffer&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/search-occur-browse-url&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;use-generic-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Point browser at a URL in the buffer using completion.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;Which web browser to use depends on the value of the variable
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`browse-url-browser-function&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;Also see &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`my/search-occur-url&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;match&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;match-data&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;context&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;beg&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;shrp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#007020&#34;&gt;let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;before&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;string-replace&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\n&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-substring-no-properties&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                            &lt;span style=&#34;color:#963&#34;&gt;beg&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;max&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;line-beginning-position&lt;/span&gt;) (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;beg&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;30&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                  (&lt;span style=&#34;color:#963&#34;&gt;link&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;string-replace&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\n&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-substring-no-properties&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;beg&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                  (&lt;span style=&#34;color:#963&#34;&gt;after&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-substring-no-properties&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                          (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;) (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;min&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;line-end-position&lt;/span&gt;) (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;+&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;) &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;30&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;propertize&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; &amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;display&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;space&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:align-to&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;65&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;propertize&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;…&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;before&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;face&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;shadow&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;shrp&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;propertize&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;link&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;face&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;:inherit&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;shadow&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:weight&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;bold&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                                           &lt;span style=&#34;color:#007020&#34;&gt;:underline&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                       &lt;span style=&#34;color:#963&#34;&gt;link&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;propertize&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;after&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;…&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;face&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;shadow&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point-min&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;while&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;search-forward-regexp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/search-url-regexp&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;push&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cons&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;match-string-no-properties&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;context&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;match-beginning&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;match-data&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point-min&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;while&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;match&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;text-property-search-forward&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;shr-url&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;push&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cons&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;prop-match-value&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;match&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;context&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;prop-match-beginning&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;match&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;shrp&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;match-data&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;completion-extra-properties&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;:annotation-function&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;cand&lt;/span&gt;) (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; &amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cdr&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;assoc&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cand&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;match-data&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;url&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;completing-read&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Browse URL: &amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;match-data&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;use-generic-p&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;browse-url-generic&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;url&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;browse-url&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;url&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;h2 id=&#34;compare-windows--m-x-compare-windows&#34;&gt;Compare windows (&lt;code&gt;M-x compare-windows&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;There are more commands for comparing buffers and files in Emacs than you can
shake a stick at: there&amp;rsquo;s &lt;code&gt;diff&lt;/code&gt;, &lt;code&gt;diff-buffers&lt;/code&gt;, &lt;code&gt;diff-backup&lt;/code&gt;,
&lt;code&gt;diff-buffer-with-file&lt;/code&gt;, &lt;code&gt;dired-diff&lt;/code&gt;, &lt;code&gt;vc-diff&lt;/code&gt;, and a whole constellation of
&lt;code&gt;ediff-&lt;/code&gt;, &lt;code&gt;ediff-merge-&lt;/code&gt; and &lt;code&gt;ediff-directories-&lt;/code&gt; commands.  I lost count at
around twenty two, and can&amp;rsquo;t remember most of them.&lt;/p&gt;
&lt;p&gt;But my favorite diff command is the lightweight &lt;code&gt;compare-windows&lt;/code&gt;, which does
something very obvious and simple in a context-agnostic way.&lt;/p&gt;
&lt;p&gt;It compares the text of two windows starting from their respective cursor
positions, and stops at and reports the next mismatch.  The two windows are the
active one and whatever &lt;code&gt;other-window&lt;/code&gt; would select.  Obviously less powerful,
but so much easier and faster to run than Ediff
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Have you tried &lt;code&gt;ediff-regions-linewise&lt;/code&gt;?  Setting this up is a four step
process, involving selecting buffers, marking regions and calling
&lt;code&gt;exit-recursive-edit&lt;/code&gt; repeatedly, an advanced command that most Emacs users
should never encounter!
&lt;/small&gt;&lt;/span&gt;
or diff:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/compare-windows-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/compare-windows-demo.mp4&#34;&gt;[VIDEO: compare-windows Emacs demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Move the cursor to the beginnings of the text to compare in two windows.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;M-x compare-windows&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;That&amp;rsquo;s it.  It moves the cursors to the first mismatch and reports it.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;&lt;code&gt;compare-windows&lt;/code&gt; is only concerned with the actual text in the two windows, and
not the provenance of this text.  The buffer type, modification state, file,
version-control status &amp;ndash; all irrelevant!  You can even compare a
chunk of text in a buffer against another chunk a little further down in the
same buffer by displaying it in both windows.  In a silly yet effective way, it
can even compare directory contents, including file attributes:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/compare-windows-demo-02.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/compare-windows-demo-02.mp4&#34;&gt;[VIDEO: compare-windows Emacs demo 2]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Two directories containing some similar-looking files.&lt;/li&gt;
&lt;li&gt;Place the cursors on the same file in both windows.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;M-x compare-windows&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The cursors stop at the first reported mismatch, which is a file modification
time here.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;And yes, you can call it with a prefix argument to ignore whitespace differences.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;compare-windows&lt;/code&gt; is what you use when you find yourself playing
spot-the-difference between two views of any kind.  It is my most used &amp;ldquo;diff&amp;rdquo;
command.&lt;/p&gt;
&lt;h2 id=&#34;compare-directories-with-dired--m-x-dired-compare-directories&#34;&gt;Compare directories with Dired (&lt;code&gt;M-x dired-compare-directories&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;But speaking of comparing directories, Dired does (of course) provide a less
hacky way to do that.  &lt;code&gt;M-x dired-compare-directories&lt;/code&gt; in Dired prompts for a
directory to compare with, and marks all files whose names differ in both Dired
listings.  That covers the most common use case, and might be everything you
need.&lt;/p&gt;
&lt;p&gt;But we already did that with the rudimentary &lt;code&gt;compare-windows&lt;/code&gt;.
&lt;code&gt;dired-compare-directories&lt;/code&gt; is an actual file-level comparison, so you can
provide custom matching predicates involving any file attribute, like
modification times or sizes.  For instance,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you can mark the more recently modified version of a file with &lt;code&gt;(&amp;gt; mtime2 mtime1)&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;or mark files with the same name but different sizes with &lt;code&gt;(/= size1 size2)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In this example, &lt;code&gt;dired-compare-directories&lt;/code&gt; has marked (i) files that are not
common to the two listings and (ii) files with differing modification times:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/dired-compare-directories-01.png&#34;/&gt;
&lt;/figure&gt;

&lt;details class=&#34;details implementation&#34; open&gt;
&lt;summary&gt;An Ediff for every season&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;If you want something more interactive/prescribed there is also an
&lt;code&gt;ediff-directories&lt;/code&gt;, because there is an Ediff command for every occasion.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h2 id=&#34;highlight-buffer-changes--m-x-highlight-changes-mode&#34;&gt;Highlight buffer changes (&lt;code&gt;M-x highlight-changes-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;While we&amp;rsquo;re on the topic of spotting differences, &lt;code&gt;highlight-changes-mode&lt;/code&gt; is a
handy way to emphasize changes to the file, and a &amp;ldquo;live&amp;rdquo; alternative to diff
commands like &lt;code&gt;diff-buffer-with-file&lt;/code&gt;:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/highlight-changes-mode-demo-01.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/highlight-changes-mode-demo-01.mp4&#34;&gt;[VIDEO: Emacs highlight-changes-mode demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;Run the below code block syncing &lt;code&gt;highlight-changes-mode&lt;/code&gt; with &lt;code&gt;save-buffer&lt;/code&gt;.
Now changes are highlighted until the next save.&lt;/li&gt;
&lt;li&gt;Make some changes.  Notice that added/changed text is colored differently.&lt;/li&gt;
&lt;li&gt;Save the buffer, clearing the highlights in the process.&lt;/li&gt;
&lt;li&gt;Repeat the last two steps a couple of times.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Visualization with highlight-changes is determined only by the mode itself, and
changes are highlighted from the time the mode is turned on until it&amp;rsquo;s turned
off.  In general, this is not what we want.  What we would like instead is to
highlight &lt;em&gt;unsaved&lt;/em&gt; changes
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
There is &lt;code&gt;M-x highlight-compare-with-file&lt;/code&gt;, but this is non-ergonomic enough to
the point of being unusable.
&lt;/small&gt;&lt;/span&gt;
.  We could do this with some finesse, or just throw in a couple of hooks:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode-turn-off&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-1&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;highlight-changes-auto&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-file-name&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode-turn-on&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;after-save-hook&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode-turn-on&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;before-save-hook&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode-turn-off&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;text-mode-hook&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;highlight-changes-auto&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now all changes in text-mode buffers are automatically highlighted.&lt;/p&gt;
&lt;details open&gt;
&lt;summary&gt;&lt;code&gt;highlight-unsaved&lt;/code&gt; as a standalone feature&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;The highlight-changes visualization can be customized to be more subtle, but you
probably don&amp;rsquo;t want it turned on all the time nevertheless.  The above hook
logic can easily be turned into a minor-mode in its own right:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;require&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;hilit-chg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode-turn-off&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-1&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;define-minor-mode&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;highlight-unsaved-mode&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Highlight all changes until the buffer is saved.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:lighter&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;H&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;cond&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   ((&lt;span style=&#34;color:#963&#34;&gt;not&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-file-name&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;user-error&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Highlight-unsaved-mode is only meant for use in file-visiting buffers&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#963&#34;&gt;highlight-unsaved-mode&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;after-save-hook&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode-turn-on&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;before-save-hook&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode-turn-off&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;remove-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;after-save-hook&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode-turn-on&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;remove-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;before-save-hook&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;highlight-changes-mode-turn-off&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;hr&gt;
&lt;p&gt;Finally, &lt;code&gt;highlight-changes-mode&lt;/code&gt; provides an auxiliary capability: you can jump
to the next and previous change in the buffer with
&lt;code&gt;highlight-changes-next-change&lt;/code&gt; and &lt;code&gt;highlight-changes-previous-change&lt;/code&gt;.  Since
this is an independent consequence of change tracking you can use just this
navigation and turn off the change visualization with &lt;code&gt;M-x highlight-changes-remove-highlight&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;always-useful-vc-diff-commands&#34;&gt;Actually useful file backups (&lt;code&gt;vc-diff&lt;/code&gt; variants)&lt;/h2&gt;
&lt;p&gt;One last excursion to close out the theme of spotting and diffing changes.&lt;/p&gt;
&lt;p&gt;This will require a tangent through the topic of Emacs backup files and is
pushing both the five minute limit and the idea of a built-in, so please bear
with me.&lt;/p&gt;
&lt;h3 id=&#34;let-s-back-up&#34;&gt;Let&amp;rsquo;s back up&lt;/h3&gt;
&lt;p&gt;By default, Emacs makes a periodic backup of any file you edit and save.
This backup system is usually mentioned only in the context of being something
annoying you should disable (via &lt;code&gt;make-backup-files&lt;/code&gt;).  If you want actual
backups you could just use version control, right?&lt;/p&gt;
&lt;p&gt;If you have security concerns with sensitive files being copied to elsewhere on
disk, I sympathize.  But otherwise, I think this is largely an ergonomics issue.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Emacs litters your working directory with the backups, and&lt;/li&gt;
&lt;li&gt;doesn&amp;rsquo;t make it easy to peruse and work with the backup files.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Changing the former is a user option
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
For example, see &lt;code&gt;backup-directory-alist&lt;/code&gt;, &lt;code&gt;kept-old-versions&lt;/code&gt; and
&lt;code&gt;kept-new-versions&lt;/code&gt;.
&lt;/small&gt;&lt;/span&gt;
, but the latter is entirely the case of a missing user interface.&lt;/p&gt;
&lt;p&gt;The external package &lt;a href=&#34;https://github.com/lewang/backup-walker&#34;&gt;backup-walker&lt;/a&gt; provides this &amp;ldquo;time-machine&amp;rdquo; interface,
along with a couple of others.  But there is a simpler, satisfying fix available
that simultaneously solves another problem.&lt;/p&gt;
&lt;h3 id=&#34;vc--until-v-don-t&#34;&gt;VC (until V don&amp;rsquo;t)&lt;/h3&gt;
&lt;p&gt;Emacs&amp;rsquo; built-in VC package offers an interface for viewing past versions of
version-controlled files:&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;vc-diff&lt;/code&gt; (&lt;code&gt;C-x v =&lt;/code&gt;)&lt;/dt&gt;
&lt;dd&gt;Diffs the file against its immediate previous
version, or against a prescribed version when called with a prefix argument.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;vc-ediff&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Runs Ediff against the file&amp;rsquo;s previous version, or against a
prescribed version.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;vc-revision-other-window&lt;/code&gt; (&lt;code&gt;C-x v ~&lt;/code&gt;)&lt;/dt&gt;
&lt;dd&gt;Displays a previous version (immediate or
specified) of the file next to this one.&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;This is a handy interface
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
and not git-specific, unlike magit&amp;rsquo;s versions of these commands.
&lt;/small&gt;&lt;/span&gt;
, but of course they do nothing in files that aren&amp;rsquo;t version controlled.&lt;/p&gt;
&lt;p&gt;In the spirit of getting the most out of every fiber of muscle memory, we can
extend the &lt;code&gt;vc-&lt;/code&gt; interface for the purpose of inspecting backups as well.&lt;/p&gt;
&lt;h3 id=&#34;the-bridge&#34;&gt;The bridge&lt;/h3&gt;
&lt;p&gt;We can overload all three VC commands so they &lt;em&gt;always&lt;/em&gt; do something useful in a
file:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If the file is unsaved, &lt;code&gt;vc-diff&lt;/code&gt; (&lt;code&gt;vc-ediff&lt;/code&gt;) generates a diff of (runs Ediff
on) the buffer against the file.&lt;/li&gt;
&lt;li&gt;If the file is version controlled, run &lt;code&gt;vc-diff&lt;/code&gt; (&lt;code&gt;vc-ediff&lt;/code&gt;,
&lt;code&gt;vc-revision-other-window&lt;/code&gt;) as usual.&lt;/li&gt;
&lt;li&gt;If the file is not version controlled, diff against (Ediff, show) the latest
numbered backup, or a prescribed numbered backup when called with a prefix
argument.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This forces functions into a single consistent mental model:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Compare against the previous version, for whatever &amp;ldquo;previous&amp;rdquo; means in this
context.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;As a bonus, we are also free to forget about a few different diff commands that
have been subsumed here, such as &lt;code&gt;diff-buffer-with-file&lt;/code&gt; and &lt;code&gt;ediff-current-file&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Augmenting &lt;code&gt;vc-*&lt;/code&gt; commands&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/read-backup-file-name&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;if-let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;backup-files&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;file-backup-file-names&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;completing-read&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Backup version: &amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;backup-files&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;user-error&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;No backup files available for file %s&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-file-name&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/vc-diff&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Compare current buffer with its file, or file with backup or revision.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;With prefix ARG, compare the file with a selected backup when the file
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;is not under version control.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-modified-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;diff-buffer-with-file&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;current-buffer&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;condition-case&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;errdata&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;call-interactively&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;vc-diff&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;error&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;string-match-p&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;not under version control&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;cadr&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;errdata&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#963&#34;&gt;diff&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;my/read-backup-file-name&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-file-name&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-file-name&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#963&#34;&gt;diff-backup&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-file-name&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;signal&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;errdata&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/vc-ediff&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Run Ediff on the current buffer, file, or backup.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;With prefix ARG, compare the file with a selected backup when the file
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;is not under version control.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-modified-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;call-interactively&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;ediff-current-file&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;condition-case&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;errdata&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;call-interactively&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;vc-ediff&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;error&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;string-match-p&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;not under version control&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;cadr&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;errdata&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#963&#34;&gt;ediff-files&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;my/read-backup-file-name&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-file-name&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-file-name&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#963&#34;&gt;ediff-backup&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-file-name&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;signal&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;errdata&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/vc-revision-other-window&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Visit the current file&amp;#39;s past revision or backup in another window.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;With prefix ARG, visit a selected backup when the file is not under
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;version control.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;condition-case&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;errdata&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;call-interactively&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;vc-revision-other-window&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;error&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;string-match-p&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;not under version control&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;cadr&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;errdata&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#963&#34;&gt;find-file-other-window&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;my/read-backup-file-name&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-file-name&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;if-let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;backup&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;file-newest-backup&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-file-name&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#963&#34;&gt;find-file-other-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;backup&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;user-error&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;No backup files available for %s&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-file-name&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;signal&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;errdata&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;See &lt;a href=&#34;#scroll-all-windows--m-x-scroll-all-mode&#34;&gt;scroll all windows&lt;/a&gt; for a demonstration of the
generalized &lt;code&gt;vc-diff&lt;/code&gt; working with backup files.&lt;/p&gt;
&lt;h2 id=&#34;the-apropos-family&#34;&gt;The apropos &lt;em&gt;family&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;If you only use one help keybinding, it should be &lt;code&gt;C-h k&lt;/code&gt;, &lt;code&gt;describe-key&lt;/code&gt;, since
the very fact that every key press invokes a first-class function that you can
live-inspect and mess with can be a revelation.&lt;/p&gt;
&lt;p&gt;If you learn two, there is a strong case for &lt;code&gt;apropos&lt;/code&gt; being the second.  It
bridges the gap between not knowing what to search for and getting a full
picture of how things are laid out.  It&amp;rsquo;s a foot-in-the-door command.&lt;/p&gt;
&lt;p&gt;But you already know &lt;code&gt;apropos&lt;/code&gt;.  What&amp;rsquo;s less evident is that &lt;code&gt;apropos&lt;/code&gt; is a
whole family of commands that do increasingly specialized but useful look-ups
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
It&amp;rsquo;s ironic that the extended apropos family is itself not very discoverable.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;Bind them all under &lt;code&gt;C-h a&lt;/code&gt;, replacing &lt;code&gt;apropos&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;defvar-keymap&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;help-apropos-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:doc&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Keymap for apropos subcommands.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;a&amp;#34;&lt;/span&gt;   &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;apropos&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;l&amp;#34;&lt;/span&gt;   &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;apropos-library&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;f&amp;#34;&lt;/span&gt;   &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;apropos-function&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;x&amp;#34;&lt;/span&gt;   &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;apropos-command&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;v&amp;#34;&lt;/span&gt;   &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;apropos-variable&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;V&amp;#34;&lt;/span&gt;   &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;apropos-local-variable&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;u&amp;#34;&lt;/span&gt;   &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;apropos-user-option&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;d&amp;#34;&lt;/span&gt;   &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;apropos-documentation&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;C-f&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;customize-apropos-faces&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;g&amp;#34;&lt;/span&gt;   &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;customize-apropos-groups&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;o&amp;#34;&lt;/span&gt;   &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;customize-apropos-options&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;c&amp;#34;&lt;/span&gt;   &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;customize-apropos&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;i&amp;#34;&lt;/span&gt;   &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;info-apropos&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-set&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;help-map&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;a&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;help-apropos-map&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;details class=&#34;details implementation&#34; open&gt;
&lt;summary&gt;&lt;code&gt;prefix-help-command&lt;/code&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;You don&amp;rsquo;t need to remember any of these!  If you don&amp;rsquo;t already use a prompter like
&lt;code&gt;which-key&lt;/code&gt;, you can press &lt;code&gt;C-h&lt;/code&gt; after the prefix &lt;code&gt;C-h a&lt;/code&gt; to bring up a listing of the
available commands.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;My favorite of these is &lt;code&gt;customize-apropos&lt;/code&gt;: it produces a bespoke customization
buffer for perusing or changing all options matching the thing you searched for:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/customize-apropos-demo-01.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/customize-apropos-demo-01.mp4&#34;&gt;[VIDEO: Emacs customize-apropos demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;Invoke the apropos map prefix (&lt;code&gt;C-h a&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;C-h&lt;/code&gt; to see available commands under this prefix.  I used Embark for
this feature, but you should see a list of available commands no matter what.&lt;/li&gt;
&lt;li&gt;Pick &lt;code&gt;customize-apropos&lt;/code&gt; and search for &amp;ldquo;async&amp;rdquo;&lt;/li&gt;
&lt;li&gt;It produces a customize buffer with all options, faces and groups matching &amp;ldquo;async&amp;rdquo;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h2 id=&#34;find-func-goodies--m-x-find-function-on-key-m-x-find-function&#34;&gt;&lt;code&gt;find-func&lt;/code&gt; goodies (&lt;code&gt;M-x find-function-on-key&lt;/code&gt;, &lt;code&gt;M-x find-function&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;One of the most useful things you can do in Emacs, if you don&amp;rsquo;t like what a
keybinding does (or if you&amp;rsquo;re simply curious), is to jump to the definition of
the command it calls to see how to modify its behavior live.  Normally this is a
multi-step process:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Find the command invoked by the key: &lt;code&gt;describe-key&lt;/code&gt; or &lt;code&gt;C-h k&lt;/code&gt; + your key
sequence.&lt;/li&gt;
&lt;li&gt;Jump to its definition by pressing &lt;code&gt;s&lt;/code&gt; (for &amp;ldquo;source&amp;rdquo;).&lt;/li&gt;
&lt;li&gt;Get hacking or reading.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;code&gt;find-function-on-key&lt;/code&gt; obviates step 2, and takes you from keybinding to the
source.  Bind it to a key and you&amp;rsquo;re off to the races.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;C-h M-k&lt;/code&gt; for me, as it&amp;rsquo;s a variation of &lt;code&gt;describe-key&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-set&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;help-map&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-k&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;find-function-on-key&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Going from a keybinding to the source of the function in one step is a minor
shortcut for the common route, but it&amp;rsquo;s magical the first time you try it.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
No video demo, because the effect is so instantaneous a video would be both (i)
confusing and (ii) underwhelming!
&lt;/small&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&#34;copy-from-above-command-and-duplicate-dwim&#34;&gt;&lt;code&gt;copy-from-above-command&lt;/code&gt; and &lt;code&gt;duplicate-dwim&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Emacs recently added some missing editing commands that have been part of most
users&amp;rsquo; tool-belts for decades.  The two most useful of these are for duplicating
text with the cursor as the destination and source.  Respectively,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;copy-from-above-command&lt;/code&gt; copies text from the first non-blank line above the
current one, similar to Vim&amp;rsquo;s &lt;code&gt;C-y&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;duplicate-dwim&lt;/code&gt; copies text on the current line (or active region) below the
current one, similar to Vim&amp;rsquo;s &lt;code&gt;yy&amp;lt;N&amp;gt;p&lt;/code&gt;&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In typical Emacs fashion, slight tweaks can make these commands work how your
brain does:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;copy-from-above-command&lt;/code&gt; copies as many characters from the above line as the
prefix argument.  I typically want to copy the whole line, so I change the
prefix argument interpretation to &amp;ldquo;copy the above line and comment it out&amp;rdquo;, a
very common action when experimenting with code or prose:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;define-advice&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;copy-from-above-command&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;:around&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;) &lt;span style=&#34;color:#963&#34;&gt;comment&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;equal&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;current-prefix-arg&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;4&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;progn&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;forward-line&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;ln&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;line-number-at-pos&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;backward-char&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;skip-chars-backward&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\n\t &amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#007020&#34;&gt;unless&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;=&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;line-number-at-pos&lt;/span&gt;) &lt;span style=&#34;color:#963&#34;&gt;ln&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;comment-line&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note that the original prefix argument behavior still works, and you can copy
a fixed number of characters from above with a numeric prefix argument
(&lt;code&gt;C-&amp;lt;N&amp;gt;&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;duplicate-dwim&lt;/code&gt; has a choice to make about where to place the cursor after
the duplication: does the user mean to continue working with the duplicated
text or the original?&lt;/p&gt;
&lt;p&gt;You can make that choice for yourself by setting a user option.  I prefer to
move the cursor and region to the duplicated text:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;duplicate-region-final-position&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#963&#34;&gt;duplicate-line-final-position&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;turn-keystrokes-into-macros--m-x-kmacro-edit-lossage&#34;&gt;Turn keystrokes into macros (&lt;code&gt;M-x kmacro-edit-lossage&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Three facts about Emacs keyboard macros:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;They are far more powerful than many users realize
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
See Mickey Peterson&amp;rsquo;s excellent article &lt;a href=&#34;https://www.masteringemacs.org/article/keyboard-macros-are-misunderstood&#34;&gt;Keyboard Macros are Misunderstood&lt;/a&gt;
&lt;/small&gt;&lt;/span&gt;
.  We tend to associate macros with text transformations, but they capture
and playback &lt;em&gt;any&lt;/em&gt; sequence of actions in Emacs, including mouse clicks.  And
since this is Emacs, actions don&amp;rsquo;t have to correspond to text editing at all.
All the short video demos in this article were copied across Dired buffers,
processed with FFmpeg, renamed and inserted into the draft using a single
keyboard macro.&lt;/li&gt;
&lt;li&gt;They require a lot of premeditation and focus to use.  Unfortunately
&amp;ldquo;thinking in macros&amp;rdquo; is cognitively taxing.  Any error or non-generalizable
movement can scupper the whole attempt.  The &lt;a href=&#34;https://github.com/magnars/multiple-cursors.el&#34;&gt;multiple-cursors&lt;/a&gt; package and
others like it present alternative interfaces to keyboard macros that lower
the mental strain.&lt;/li&gt;
&lt;li&gt;But they still don&amp;rsquo;t solve the &amp;ldquo;foresight&amp;rdquo; problem: I need to know before the
fact that a sequence of actions will need to be repeatable, and start a
recording.  Coupled with the fact that you&amp;rsquo;re unlikely to get a complex
sequence right the first time, we&amp;rsquo;re back to the previous problem again.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Vim&amp;rsquo;s &lt;code&gt;.&lt;/code&gt; (dot) command is a solution here, since Vim is effectively
always recording a macro of your edits, and Emacs&amp;rsquo; &lt;code&gt;dot-mode&lt;/code&gt; package emulates this
with some success.  But these are still limited to buffer edits, and not full
fledged keyboard macros.&lt;/p&gt;
&lt;p&gt;Well.  Emacs provides the confusingly named &lt;code&gt;kmacro-edit-lossage&lt;/code&gt; command that
addresses this foresight problem, albeit in a manual way.  At any time, you can
view your &amp;ldquo;lossage&amp;rdquo;, a record of the last 300 or so key-presses with the
&lt;code&gt;view-lossage&lt;/code&gt; (&lt;code&gt;C-h l&lt;/code&gt;) command.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;kmacro-edit-lossage&lt;/code&gt; takes this further, and lets you create a macro from your
key-press history at any time.  The lossage is truly editable, you can and will
want to insert new commands into the lossage when creating a macro.  An example
of creating a macro from a keystroke sequence that is setting up a window split:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/kmacro-edit-lossage.png&#34;/&gt;
&lt;/figure&gt;

&lt;blockquote&gt;
&lt;p&gt;&amp;ldquo;Oh, I need to do the complex thing I just did 200 times&amp;rdquo;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In practice, I edit macros I&amp;rsquo;ve already defined with &lt;code&gt;edit-kbd-macro&lt;/code&gt; (&lt;code&gt;C-x C-k e&lt;/code&gt;) more than I fashion new ones from the lossage, but on the infrequent
occasions that call for &lt;code&gt;kmacro-edit-lossage&lt;/code&gt;, it&amp;rsquo;s a real lifesaver
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
The editing process generally requires a generous sprinkling of
&lt;code&gt;kbd-macro-query&lt;/code&gt; calls into the lossage to be truly generalizable.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;h2 id=&#34;subword-mode-superword-mode-and-word-syntax&#34;&gt;&lt;code&gt;subword-mode&lt;/code&gt;, &lt;code&gt;superword-mode&lt;/code&gt; and word syntax&lt;/h2&gt;
&lt;p&gt;Emacs offers word-based navigation and editing commands (&lt;code&gt;forward-word&lt;/code&gt;,
&lt;code&gt;forward-to-word&lt;/code&gt;, &lt;code&gt;kill-word&lt;/code&gt;&amp;hellip;) and major-mode-specific &lt;em&gt;syntax tables&lt;/em&gt;,
leaving the question of &amp;ldquo;what is a word?&amp;rdquo; up to you.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;subword-mode&lt;/code&gt; and &lt;code&gt;superword-mode&lt;/code&gt; are two different answers to this
question. With &lt;code&gt;subword-mode&lt;/code&gt; turned on, each component of a CamelCase symbol
counts as a word.  As the documentation helpfully illustrates:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#963&#34;&gt;Nomenclature&lt;/span&gt;           &lt;span style=&#34;color:#963&#34;&gt;Subwords&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#963&#34;&gt;===========================================================&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#963&#34;&gt;GtkWindow&lt;/span&gt;          &lt;span style=&#34;color:#963&#34;&gt;=&amp;gt;&lt;/span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Gtk&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Window&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#963&#34;&gt;EmacsFrameClass&lt;/span&gt;    &lt;span style=&#34;color:#963&#34;&gt;=&amp;gt;&lt;/span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Emacs&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Frame&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Class&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#963&#34;&gt;NSGraphicsContext&lt;/span&gt;  &lt;span style=&#34;color:#963&#34;&gt;=&amp;gt;&lt;/span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;NS&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Graphics&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Context&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;When &lt;code&gt;superword-mode&lt;/code&gt; is turned on, snake_case symbols like &lt;code&gt;this_is_a_symbol&lt;/code&gt;
counts as one word
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
The &lt;a href=&#34;https://github.com/akicho8/string-inflection&#34;&gt;string-inflection&lt;/a&gt; package provides a command to easily cycle between these
styles: &lt;code&gt;this_is_a_symbol&lt;/code&gt; &amp;ndash;&amp;gt; &lt;code&gt;this-is-a-symbol&lt;/code&gt; &amp;ndash;&amp;gt; &lt;code&gt;This_Is_A_Symbol&lt;/code&gt; &amp;ndash;&amp;gt;
&lt;code&gt;thisIsASymbol&lt;/code&gt; &amp;ndash;&amp;gt; &lt;code&gt;ThisIsASymbol&lt;/code&gt;.
&lt;/small&gt;&lt;/span&gt;
.  In practice, this is less useful than &lt;code&gt;subword-mode&lt;/code&gt;, since acting on
symbols is already well supported in Emacs via the &lt;code&gt;*-sexp&lt;/code&gt; commands.&lt;/p&gt;
&lt;p&gt;More generally, it can be worth taking a few minutes to modify the syntax table
of a major mode to fix annoyances you might be experiencing with structural
navigation.  In Lisp-y contexts, my most useful change is to make &amp;ldquo;:&amp;rdquo; be
considered part of a word, so that I can &lt;code&gt;backward-kill-word&lt;/code&gt; through keywords
like &lt;code&gt;:foo&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;lisp-data-mode-hook&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; () (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;modify-syntax-entry&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?:&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;w&amp;#34;&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In Org mode, it&amp;rsquo;s treating the delimiters &lt;code&gt;=&lt;/code&gt; and &lt;code&gt;~&lt;/code&gt; as word constituents:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-mode-hook&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;modify-syntax-entry&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?=&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;w&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;modify-syntax-entry&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?~&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;w&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;See &lt;code&gt;describe-syntax&lt;/code&gt; (&lt;code&gt;C-h s&lt;/code&gt;) and &lt;code&gt;modify-syntax-entry&lt;/code&gt; for how to specify the
syntax of characters.&lt;/p&gt;
&lt;h2 id=&#34;manipulate-image-display&#34;&gt;Manipulate image display&lt;/h2&gt;
&lt;p&gt;Almost everywhere that Emacs displays an image, you can manipulate the display
by placing the cursor on the image and pressing &lt;code&gt;i&lt;/code&gt;.  Here is an example with
images displayed in Elfeed (an RSS feed reader) and in Org mode:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/image-bindings-demo-01.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/image-bindings-demo-01.mp4&#34;&gt;[VIDEO: Demo of image-map bindings in Emacs]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;Preview an Org mode link to an image with &lt;code&gt;org-link-preview&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Zoom in with &lt;code&gt;i +&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Subsequent zooms and rotation don&amp;rsquo;t require the &lt;code&gt;i&lt;/code&gt; prefix because I use &lt;code&gt;repeat-mode&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Do the same to the image displayed in the Elfeed entry buffer.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;I used the keyboard in this demo, but you could just use the &lt;code&gt;C-&amp;lt;wheel&amp;gt;&lt;/code&gt;
shortcut familiar from browsers and other applications.&lt;/p&gt;
&lt;p&gt;The most useful bindings are &lt;code&gt;i +&lt;/code&gt; and &lt;code&gt;i -&lt;/code&gt; to zoom, and maybe &lt;code&gt;i r&lt;/code&gt; to rotate the
image by 90 degrees.  But you can do other things like cropping the image with &lt;code&gt;i c&lt;/code&gt; &amp;ndash; see
&lt;code&gt;M-x describe-keymap⮐  image-map&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you use &lt;a href=&#34;https://karthinks.com/software/it-bears-repeating/&#34;&gt;repeat-mode&lt;/a&gt;, you don&amp;rsquo;t need the &lt;code&gt;i&lt;/code&gt; prefix after the first invocation
either, you can repeat with just &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt; or &lt;code&gt;r&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This functionality is provided via a keymap placed over images, and nothing
needs to be turned on for this.  Note that only the image display is modified,
not the image on disk.&lt;/p&gt;
&lt;p&gt;In web-pages and rendered-HTML buffers, there is one more useful command:
pressing &lt;code&gt;z&lt;/code&gt; (&lt;code&gt;shr-zoom-image&lt;/code&gt;) will split the image into horizontal strips
across several lines, and cycle through different image sizes.  It&amp;rsquo;s an odd
command, probably intended to mitigate Emacs&amp;rsquo; display engine limitations when
dealing with large images.  But mitigate it does.  Useful if you visit websites
with huge images in Emacs.&lt;/p&gt;
&lt;h2 id=&#34;make-all-text-visible--m-x-visible-mode&#34;&gt;Make all text visible (&lt;code&gt;M-x visible-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Emacs can make buffer text selectively invisible.  Marking text as invisible is
the basis of all &amp;ldquo;folding&amp;rdquo; behavior &amp;ndash; think magit-section buffers, Outline
mode, Org mode and so on.  Every mode that provides folding also provides
keybindings to toggle the fold state, and pressing &lt;code&gt;TAB&lt;/code&gt; usually works.
&lt;em&gt;Usually&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In practice, these keybindings tend to be all over the place.  For when you
can&amp;rsquo;t be bothered to learn mode-specific conventions because you don&amp;rsquo;t use the
mode enough
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Or because the interface is &lt;em&gt;bonkers&lt;/em&gt;, like the default &lt;code&gt;outline-minor-mode&lt;/code&gt; keybindings.
&lt;/small&gt;&lt;/span&gt;
and just want to see all hidden text, you&amp;rsquo;ve got &lt;code&gt;visible-mode&lt;/code&gt;.&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/visible-mode-demo-01.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/visible-mode-demo-01.mp4&#34;&gt;[VIDEO: visible-mode Emacs demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;In a buffer with &lt;code&gt;outline-minor-mode&lt;/code&gt; enabled, run &lt;code&gt;visible-mode&lt;/code&gt;.  All text
is revealed.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;visible-mode&lt;/code&gt; again to restore the previous text invisibilty state.&lt;/li&gt;
&lt;li&gt;Switch to a magit buffer and run &lt;code&gt;visible-mode&lt;/code&gt; for similar effects.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;&lt;code&gt;visible-mode&lt;/code&gt; is somewhat low-level, it simply disables text invisibility
across the buffer until you call it again.  So if the buffer is presenting a
&amp;ldquo;reactive&amp;rdquo; UI where (un)folding text has dynamic effects, things can appear
broken until you disable &lt;code&gt;visible-mode&lt;/code&gt;.  As such, it&amp;rsquo;s intended as a temporary
measure or a debugging tool, but since it &lt;em&gt;always&lt;/em&gt; works it&amp;rsquo;s my go-to button
for showing all buffer text uniformly with one command.&lt;/p&gt;
&lt;h2 id=&#34;ignore-invisible-text--isearch-toggle-invisible&#34;&gt;Ignore invisible text (&lt;code&gt;isearch-toggle-invisible&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;And speaking of &lt;code&gt;visible-mode&lt;/code&gt;, some Emacs commands like Isearch ignore
text invisibility out of the box, making it easy to search across the actual
document text
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
As usual, the full behavior is more complicated.  Isearch also &lt;em&gt;restores&lt;/em&gt; the
invisibility when you move out of an invisible region that was temporarily
revealed.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;But this behavior also has a downside.  When the buffer as presented is intended
as a guide, automatically revealing invisible text breaks our assumptions about
what Isearch will do.  This is a problem when using Isearch as a navigation (and
not a search) tool.&lt;/p&gt;
&lt;p&gt;You can toggle searching invisible text when using Isearch with
&lt;code&gt;isearch-toggle-invisible&lt;/code&gt;, bound to &lt;code&gt;M-s i&lt;/code&gt; when searching:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/isearch-toggle-invisible-demo-01.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/isearch-toggle-invisible-demo-01.mp4&#34;&gt;[VIDEO: Emacs isearch-toggle-invisible demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;With the intent to jump to one of the last headings in this Org document, Isearch for &amp;ldquo;zero&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;The search skips to a match in a folded region instead.&lt;/li&gt;
&lt;li&gt;Cancel the match with &lt;code&gt;isearch-abort&lt;/code&gt; (&lt;code&gt;C-g&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Start Isearch again, and run &lt;code&gt;isearch-toggle-invisible&lt;/code&gt; (&lt;code&gt;M-s i&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Search for &amp;ldquo;zero&amp;rdquo;, jumping only to matches in the visible text&lt;/li&gt;
&lt;li&gt;Exit Isearch at the desired match.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;This keybinding is not arbitrary &amp;ndash; all the Isearch behavior toggles are under
the &lt;code&gt;M-s&lt;/code&gt; keymap, mirroring Isearch&amp;rsquo;s default binding of &lt;code&gt;C-s&lt;/code&gt;.  (But that&amp;rsquo;s a
whole article unto itself.)&lt;/p&gt;
&lt;h2 id=&#34;ruler--m-x-ruler-mode&#34;&gt;Ruler (&lt;code&gt;M-x ruler-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;At some point in its eventful past, Emacs was intended to possess WYSIWYG
word-processing features.  This is not surprising, it&amp;rsquo;s difficult to find
computing applications that Emacs doesn&amp;rsquo;t implement in its own janky, special
way.&lt;/p&gt;
&lt;p&gt;One of the byproducts of this ambition is that there are some semi-buried
WYSIWYG features lingering around.  The &lt;code&gt;center-&lt;/code&gt; commands are one such feature,
centering lines, paragraphs and regions relative to &lt;code&gt;fill-column&lt;/code&gt;.  Useful for
fancy comments in code&amp;hellip; and not much else, unless you like to print from Emacs
buffers.&lt;/p&gt;
&lt;p&gt;But customizable display margin and fringe widths are a welcome addition, as a
lot of functionality can be stuffed into this screen estate.  The only problem
with specifying widths like margins is actually doing it.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
You might think that the handily named &lt;code&gt;set-left-margin&lt;/code&gt; and &lt;code&gt;set-right-margin&lt;/code&gt;
commands do this, but they actually work like the &lt;code&gt;center&lt;/code&gt; commands, indenting
the actual buffer text.
&lt;/small&gt;&lt;/span&gt;
It&amp;rsquo;s surprisingly messy.  There is no direct command for this, and setting the
display margins does not take effect until the window is displayed again.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;ruler-mode&lt;/code&gt; has you covered:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;800&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/ruler-mode-demo-01.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/ruler-mode-demo-01.mp4&#34;&gt;[VIDEO: Demo of ruler-mode for Emacs]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by Play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;Turn on &lt;code&gt;ruler-mode&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Hover over the header-line for a tooltip with instructions.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;S-&amp;lt;mouse-1&amp;gt;&lt;/code&gt; and &lt;code&gt;S-&amp;lt;mouse-3&amp;gt;&lt;/code&gt; to set the left and right margin for the buffer.&lt;/li&gt;
&lt;li&gt;Drag &lt;code&gt;&amp;lt;mouse-2&amp;gt;&lt;/code&gt; to set the &lt;code&gt;fill-column&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Fill a paragraph to demonstrate the changed &lt;code&gt;fill-column&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Restore the margins and turn off &lt;code&gt;ruler-mode&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;As a bonus you can set the &lt;code&gt;fill-column&lt;/code&gt; too.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
You can also set the &lt;em&gt;goal column&lt;/em&gt;, but that&amp;rsquo;ll have to wait.
&lt;/small&gt;&lt;/span&gt;
Of course, you could use the &lt;code&gt;visual-fill-column&lt;/code&gt; or &lt;code&gt;olivetti&lt;/code&gt; packages for
this, but if you like to change the margins on the fly instead of toggling
between preset widths, ruler-mode is arguably even more user-friendly.&lt;/p&gt;
&lt;h2 id=&#34;refill-text--m-x-refill-mode&#34;&gt;Refill text (&lt;code&gt;M-x refill-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;On the theme of text widths, Emacs provides a handy series of &lt;code&gt;fill-&lt;/code&gt; commands
and an &lt;code&gt;auto-fill-mode&lt;/code&gt; for filling text as you type.&lt;/p&gt;
&lt;p&gt;The fact that &lt;code&gt;auto-fill-mode&lt;/code&gt; features prominently in Emacs&amp;rsquo; tutorial,
among the first things you&amp;rsquo;re expected to learn, suggests that Emacs takes
text filling very seriously, considering it a crucial text-editing feature.&lt;/p&gt;
&lt;p&gt;Personally, the only people I know devoting any of their attention to text
widths on computer screens are professional typesetters&amp;hellip; and some Emacs users.
If you&amp;rsquo;re reading this you might be one of them, so I ask you: isn&amp;rsquo;t it odd that
&lt;code&gt;auto-fill-mode&lt;/code&gt; is not actually automatic? It &lt;em&gt;only wraps the line you&amp;rsquo;re on&lt;/em&gt;,
leaving any earlier misalignment in the paragraph (caused by pasting text from
elsewhere, say) to be fixed manually.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;refill-mode&lt;/code&gt; is Emacs&amp;rsquo; actual automatic text-filling feature.  It ensures that
your document stays wrapped at the &lt;code&gt;fill-column&lt;/code&gt;:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/refill-mode-demo-01.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/refill-mode-demo-01.mp4&#34;&gt;[VIDEO: Refill mode for Emacs demo]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;&lt;code&gt;M-x refill-mode&lt;/code&gt; and you&amp;rsquo;re set.&lt;/p&gt;
&lt;h2 id=&#34;scroll-all-windows--m-x-scroll-all-mode&#34;&gt;Scroll all windows (&lt;code&gt;M-x scroll-all-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;There are two commonly recommended scroll-related commands that new Emacs users
find surprising, in the sense that they make you wonder why other software
doesn&amp;rsquo;t have them.&lt;/p&gt;
&lt;p&gt;The first is &lt;code&gt;scroll-other-window&lt;/code&gt;, for scrolling the window that isn&amp;rsquo;t selected
without having to switch to it first.  This is very handy when the next window
contains material that&amp;rsquo;s a reference for our work in this one.  The second is
&lt;code&gt;follow-mode&lt;/code&gt; (covered in an &lt;a href=&#34;https://karthinks.com/software/batteries-included-with-emacs/&#34;&gt;earlier installment&lt;/a&gt;), giving you a contiguous view
of a single buffer across multiple windows.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;scroll-all-mode&lt;/code&gt; is almost as useful, but lesser known than these two.  This
mode scrolls all windows on the frame simultaneously: very handy when you&amp;rsquo;re
looking at buffers that need to be &amp;ldquo;synced&amp;rdquo; in some way.  A common use for me is
eyeballing two versions of a file without having to get locked into an Ediff
session:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/scroll-all-mode-demo-01.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/scroll-all-mode-demo-01.mp4&#34;&gt;[VIDEO: scroll-mode for Emacs demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;Open a specific previous backup of the current file with
&lt;code&gt;vc-revision-other-window&lt;/code&gt; (actually &lt;a href=&#34;#always-useful-vc-diff-commands&#34;&gt;my spin on it, covered above&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Turn on &lt;code&gt;scroll-all-mode&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Scroll the window as usual.  All windows scroll simultaneously.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;It&amp;rsquo;s just &lt;code&gt;M-x scroll-all-mode&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;bonus-scrolling-other-windows-and-master-mode&#34;&gt;Bonus: scrolling other windows and &lt;code&gt;master-mode&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;While we&amp;rsquo;re on the topic of scrolling other windows, a common question is what
happens if you have more than two windows on screen, and the window you want to
scroll is &lt;em&gt;not&lt;/em&gt; the &amp;ldquo;next-window&amp;rdquo; that Emacs picks
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
This tip is recycled from &lt;a href=&#34;https://karthinks.com/software/emacs-window-management-almanac/&#34;&gt;The Emacs Window Management Almanac&lt;/a&gt;, but I wouldn&amp;rsquo;t
blame you for missing it in a 15,000 word sea of blather.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;One solution is the built-in &lt;code&gt;master-mode&lt;/code&gt;, where you can pre-designate (or
live-designate) buffers that should be scrollable from other buffers.&lt;/p&gt;
&lt;p&gt;But a more immediately useful method is to set the strategy used to find the
window to scroll.  One option is&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;other-window-scroll-default&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;get-lru-window&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;which will always scroll the least-recently-used window.  This is useful if the
window you want to scroll contains reference material that you won&amp;rsquo;t be editing,
so the window will rarely be selected.&lt;/p&gt;
&lt;p&gt;Alternatively, you might have two windows (of many), both of which see frequent
edits.  You&amp;rsquo;d then use the most-recently-used window as the other window to scroll:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;other-window-scroll-default&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;get-mru-window&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;not-this-one-dummy&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;next-window&lt;/span&gt;)               &lt;span style=&#34;color:#888&#34;&gt;;fall back to next window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;next-window&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;visible&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Some combination of these should make &lt;code&gt;scroll-other-window&lt;/code&gt; always
do-what-you-mean.&lt;/p&gt;
&lt;h2 id=&#34;refuse-to-terminate--m-x-emacs-lock-mode&#34;&gt;Refuse to terminate (&lt;code&gt;M-x emacs-lock-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;If you try to quit Emacs with unsaved files, Emacs refuses until you answer the
question of what to do about each of them.  Annoying perhaps, but a useful
check.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;emacs-lock-mode&lt;/code&gt; extends this idea and hands &lt;em&gt;you&lt;/em&gt; the controls.  Call it in any
buffer to &amp;ldquo;lock&amp;rdquo; it.&lt;/p&gt;
&lt;p&gt;Until the lock is disengaged, the buffer will refuse to be killed, throwing up a
message instead:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-nil&#34; data-lang=&#34;nil&#34;&gt;    Buffer &amp;#34;*scratch*&amp;#34; is locked and cannot be killed
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;and Emacs will refuse to exit:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-nil&#34; data-lang=&#34;nil&#34;&gt;    Emacs cannot exit because buffer &amp;#34;*scratch*&amp;#34; is locked
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is handy for non-file-visiting buffers containing information you don&amp;rsquo;t
want to accidentally lose, or just as a reminder that a task in that buffer is
pending, and you shouldn&amp;rsquo;t throw away the context.&lt;/p&gt;
&lt;p&gt;In a post Org-capture world, the former is rarely an issue, but locking is still
useful in shell and compilation buffers, websites or other special applications
that contain output or state you don&amp;rsquo;t want to lose.&lt;/p&gt;
&lt;h2 id=&#34;undelete-frames--m-x-undelete-frame-mode-and-m-x-undelete-frame&#34;&gt;Undelete frames (&lt;code&gt;M-x undelete-frame-mode&lt;/code&gt; and &lt;code&gt;M-x undelete-frame&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;If you accidentally close an Emacs frame with a carefully curated workspace,
&lt;code&gt;M-x undelete-frame&lt;/code&gt; has your back. Uh, if you&amp;rsquo;ve turned on
&lt;code&gt;undelete-frame-mode&lt;/code&gt;, that is.&lt;/p&gt;
&lt;p&gt;It does exactly what the more widely recommended (also built-in) &lt;code&gt;winner&lt;/code&gt; and
&lt;code&gt;tab-bar-history&lt;/code&gt; packages do, but for frames instead of windows.  Turn on
&lt;code&gt;undelete-frame-mode&lt;/code&gt; with your Emacs and don&amp;rsquo;t worry about closing frames
again.  It can restore up to the last 16 deleted frames.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;the-leftovers&#34;&gt;The leftovers&lt;/h2&gt;
&lt;p&gt;That&amp;rsquo;s twenty Emacs features I collided with in the last six years that have
survived contact with the reality of using Emacs in 2026.  Several more Emacs
libraries discovered by fat-fingering the keyboard ended up being more
interesting as archaeological artifacts than as reliable solutions to common
user needs.  &lt;code&gt;allout-mode&lt;/code&gt; is Org mode from a parallel universe, an outline
manager with features like Org&amp;rsquo;s speed-keys and even per-subtree encryption.
&lt;code&gt;shadowfile&lt;/code&gt; is implementing &lt;a href=&#34;https://github.com/bcpierce00/unison&#34;&gt;unison&lt;/a&gt; from inside Emacs, with questionable
utility.  &lt;code&gt;double-mode&lt;/code&gt; is a key-translation-based input-method for typing
non-keyboard characters that predates &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/emacs/Input-Methods.html&#34;&gt;quail&lt;/a&gt;.  The &lt;code&gt;bs&lt;/code&gt; library was someone&amp;rsquo;s
attempt at a smarter &lt;code&gt;list-buffers&lt;/code&gt; command, but &lt;code&gt;ibuffer&lt;/code&gt; blew everything else
out of the water so there&amp;rsquo;s no reason to use it.&lt;/p&gt;
&lt;p&gt;Other ostensibly handy features, like wrapping regions with delimiters using
&lt;code&gt;electric-pair-mode&lt;/code&gt;, didn&amp;rsquo;t make the cut because the ratio of finickiness to
utility is too high.  It&amp;rsquo;s better to just use an external package like
&lt;code&gt;wrap-region&lt;/code&gt;, &lt;code&gt;smartparens&lt;/code&gt; or &lt;code&gt;embrace&lt;/code&gt; for this.&lt;/p&gt;
&lt;p&gt;Then there&amp;rsquo;s the constellation of included Org and Org-adjacent libraries (like
&lt;code&gt;appt&lt;/code&gt;) that add interesting but obscure features to Org mode.  But that&amp;rsquo;s an
expansive story, best covered in a dedicated article.&lt;/p&gt;
&lt;p&gt;Finally, a lot of my serendipitous finds were libraries new and old that
are primarily of interest to Elisp developers.  The &lt;code&gt;thunk&lt;/code&gt; library is an
example of this.  These too deserve their own write-up.&lt;/p&gt;
&lt;p&gt;Still, I hope you found at least a couple of useful tips among the batteries
that passed testing.  The lisp directory that ships with Emacs isn&amp;rsquo;t &lt;em&gt;that&lt;/em&gt; big,
but somehow this barrel never runs dry.  I don&amp;rsquo;t doubt that more batteries
remain to be found, even if it takes me a few more years of typos to stumble
onto them.  Until then, happy Emacsing!&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;A mini rant: This is your cue to tell me that &lt;code&gt;yyp&lt;/code&gt;
is not a Vim command but a shining example of its &lt;em&gt;command composition
language&lt;/em&gt;, where &lt;code&gt;yy&lt;/code&gt; and &lt;code&gt;p&lt;/code&gt; do different things.  And mine to tell you that no
Vim user, including you or me, thinks about an exceedingly common action like
&lt;code&gt;yyp&lt;/code&gt; this way in practice.  Your fingers memorized the sequence years ago and
carry it out before you can muster the wherewithal to consider that you are
composing a yank and a paste.  It&amp;rsquo;s simply not a high-level cognitive action, so
this is a distinction without a difference.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>Tool use with gptel: looking for testers!</title>
      <link>https://karthinks.com/software/tool-use-with-gptel-looking-for-testers/</link>
      <pubDate>Tue, 31 Dec 2024 22:21:00 -0800</pubDate>
      
      <guid>https://karthinks.com/software/tool-use-with-gptel-looking-for-testers/</guid>
      <description>&lt;div class=&#34;subtitle&#34;&gt;
&lt;p&gt;TL;DR: Get LLMs to do things from Emacs, with gptel &lt;a href=&#34;#testing-tool-use&#34;&gt;and your help&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;A short one today, without the usual flourishes.  &lt;a href=&#34;https://github.com/karthink/gptel&#34;&gt;gptel&lt;/a&gt; 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 &lt;a href=&#34;https://en.wikipedia.org/wiki/Llama.cpp&#34;&gt;smaller language models&lt;/a&gt; you can run locally on your machine.  At its surface&amp;hellip; well, it tries not to have a surface at all, and blend in with Emacs&amp;rsquo; design metaphors and affordances instead.&lt;/p&gt;
&lt;p&gt;What does that mean?  For one, it&amp;rsquo;s available at any time and in any buffer, even in places where it probably shouldn&amp;rsquo;t, like tooltips and the minibuffer.  It treats text &amp;ndash; yours or that generated by LLMs &amp;ndash; as Emacs treats text.  You can sling it around, propertize it, redirect it, shove it into buffers and more.  You can save LLM conversation states by just saving the buffer, treat hierarchical Org documents as parallel conversation threads, and so on.  Second, it&amp;rsquo;s programmable: you can use a &lt;a href=&#34;https://github.com/karthink/gptel/wiki/Defining-custom-gptel-commands&#34;&gt;simple API&lt;/a&gt; to script gptel into your tools instead of adapting your tools to gptel
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Unfortunately, one caveat is that gptel is presently async-only, so you&amp;rsquo;ll have to write a callback instead of just inserting a call to &lt;code&gt;gptel-request&lt;/code&gt; in the middle of your code.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;This year old video, while significantly behind the current state of the project, illustrates some aspects of the design.&lt;/p&gt;
&lt;iframe width=&#34;704&#34; height=&#34;396&#34; src=&#34;https://www.youtube-nocookie.com/embed/bsRnh_brggM?si=0Kn7GM4qbowIRzXA&#34; title=&#34;YouTube video player&#34; frameborder=&#34;0&#34; allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&#34; referrerpolicy=&#34;strict-origin-when-cross-origin&#34; allowfullscreen&gt;&lt;/iframe&gt;
&lt;p&gt;A generalist tool like an LLM can be used in more ways than can be captured by any rigid design, and we&amp;rsquo;re some distance away from answering this simple question: &lt;strong&gt;Can the most flexible text editor ever written provide a generic interface to the most flexible text generator ever created?&lt;/strong&gt;  I am puzzled.&lt;/p&gt;
&lt;p&gt;And at some point &amp;ndash; not today &amp;ndash; I will write in detail about gptel&amp;rsquo;s evolving design and the challenges therein.  Today, however, I need &lt;em&gt;your&lt;/em&gt; help!&lt;/p&gt;
&lt;h2 id=&#34;tool-use-the-layman-s-version&#34;&gt;Tool use: the layman&amp;rsquo;s version&lt;/h2&gt;
&lt;p&gt;At some point folks realized that instead of training LLMs to do every task, it&amp;rsquo;s easier to train them to delegate actions to specialized tools.&lt;/p&gt;
&lt;p&gt;You can think of these tools as capabilities you equip the model with: the ability to look up information, run actions that modify the state of your computer, and so on.  This solves two common problems with using LLMs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Their knowledge of the world is limited to their training corpus &amp;ndash; and then further compressed in their internal representation.  With access to better information in the mix, it&amp;rsquo;s no longer just a game of asking a frustratingly cheerful oracle a question and wondering if it&amp;rsquo;s making up a load of hogwash.&lt;/li&gt;
&lt;li&gt;They can generate text (or other multi-media formats) but not actually &lt;em&gt;do&lt;/em&gt; anything useful, assuming you can trust them to not trip over themselves.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Of course, the downside is that now &lt;em&gt;you&amp;rsquo;re&lt;/em&gt; responsible for providing these &amp;ldquo;capabilities&amp;rdquo;, and defining the interface and levers that the LLM can choose to pull.  So tool use, or &amp;ldquo;function calling&amp;rdquo; is LLM usage where&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;you include a function specification along with your task/question to the LLM.  This includes a detailed listing of the function&amp;rsquo;s arguments, their types and so on.&lt;/li&gt;
&lt;li&gt;The LLM optionally decides to call the function, and supplies the arguments.&lt;/li&gt;
&lt;li&gt;You run the function call, and (optionally) feed the results back to the LLM.&lt;/li&gt;
&lt;li&gt;The LLM completes the task based on the information received.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can use this to give the LLM awareness of the world, by providing access to APIs, your filesystem, web search, Emacs etc.  You can get it to control your Emacs frame, for instance.&lt;/p&gt;
&lt;p&gt;And speaking of the Emacs frame&amp;hellip;&lt;/p&gt;
&lt;h2 id=&#34;tool-use-in-gptel&#34;&gt;Tool use in gptel&lt;/h2&gt;
&lt;p&gt;gptel supports tool use, but it&amp;rsquo;s not ready for primetime yet.  Here are a couple of illustrations.&lt;/p&gt;
&lt;p&gt;You can get it to write boilerplate so you don&amp;rsquo;t have to.  In this demo I provide an LLM with some basic filesystem capabilities, and get it to set up a Nix flake integrated with direnv:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/kn13qmU.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/gptel-tool-use-filesystem-demo.mp4&#34;&gt;[VIDEO: An LLM task with filesystem access]&lt;/a&gt;&lt;/video&gt;
&lt;details open&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Unlike the usual video narration on this blog this one&amp;rsquo;s going to be rather high level, as the tool use UI isn&amp;rsquo;t final.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Type in the query, with a reasonable amount of detail.&lt;/li&gt;
&lt;li&gt;Ensure that the filesystem tools are available to the LLM.  (The &amp;ldquo;scope&amp;rdquo; switch sets the tools buffer-locally.)&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;M-x gptel-send&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In the lower window, run the &lt;code&gt;watch&lt;/code&gt; command so we can see the &lt;code&gt;~/Desktop/ghostty&lt;/code&gt; directory being populated.&lt;/li&gt;
&lt;li&gt;After the LLM is done creating the directory and files we asked for, it opens the directory in &lt;code&gt;dired&lt;/code&gt; and reports its actions.&lt;/li&gt;
&lt;li&gt;Examine the &lt;code&gt;flake.nix&lt;/code&gt; and &lt;code&gt;.envrc&lt;/code&gt; files to make sure they look okay.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Here I give the LLM the ability to query my Elfeed and Wallabag databases, which covers most of the things I&amp;rsquo;ve read or watched on the Internet for the past twenty years.  I access both of them from Emacs
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
via the &lt;a href=&#34;https://github.com/skeeto/elfeed&#34;&gt;elfeed&lt;/a&gt; and &lt;a href=&#34;https://github.com/karthink/wombag&#34;&gt;wombag&lt;/a&gt; Emacs packages respectively.
&lt;/small&gt;&lt;/span&gt;
and they are only available locally on my computer.  I ask the LLM for details about something I vaguely remember watching a while ago:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/CskRHGZ.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/gptel-tool-use-feed-search-demo.mp4&#34;&gt;[VIDEO: An LLM task with local search capability]&lt;/a&gt;&lt;/video&gt;
&lt;details open&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Unlike the usual video narration on this blog this one&amp;rsquo;s going to be rather high level, as the tool use UI isn&amp;rsquo;t final.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Type in the query, with as much detail as I can remember.&lt;/li&gt;
&lt;li&gt;Ensure that the local search and web tools are available to the LLM.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;M-x gptel-send&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It finds the most likely search result from Elfeed, which is a Youtube video.&lt;/li&gt;
&lt;li&gt;It fetches the description and a transcript for the video, then summarizes it with links to some references.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;I wouldn&amp;rsquo;t get too excited by this second example &amp;ndash; there is no fancy vector embedding or similarity search going on.  The LLM just runs a standard keyword search against the Elfeed database, and we were fortunate that the result we were looking for contained the word &amp;ldquo;derivative&amp;rdquo; that I asked for.&lt;/p&gt;
&lt;p&gt;But you get the idea, I hope.&lt;/p&gt;
&lt;details class=&#34;details implementation&#34;&gt;
&lt;summary&gt;A sample tool definition&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;If you were curious, &amp;ldquo;tools&amp;rdquo; as used in the above demos are elisp functions coupled with descriptions of the schema.  Here is an example.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;gptel-make-tool&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:function&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;path&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;filename&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;content&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;full-path&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;expand-file-name&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;filename&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;path&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#007020&#34;&gt;with-temp-buffer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;insert&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;content&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#963&#34;&gt;write-file&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;full-path&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;format&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Created file %s in %s&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;filename&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;path&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:name&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;create_file&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:description&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Create a new file with the specified content&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:args&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;list&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;:name&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;path&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;	       &lt;span style=&#34;color:#007020&#34;&gt;:type&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;string&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;	       &lt;span style=&#34;color:#007020&#34;&gt;:description&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;The directory where to create the file&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;:name&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;filename&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;	       &lt;span style=&#34;color:#007020&#34;&gt;:type&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;string&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;	       &lt;span style=&#34;color:#007020&#34;&gt;:description&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;The name of the file to create&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;:name&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;content&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;	       &lt;span style=&#34;color:#007020&#34;&gt;:type&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;string&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;	       &lt;span style=&#34;color:#007020&#34;&gt;:description&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;The content to write to the file&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:category&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;filesystem&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;h2 id=&#34;testing-tool-use&#34;&gt;Testing tool use&lt;/h2&gt;
&lt;p&gt;There are dozens of uses for this kind of LLM usage, and dozens of ways in which this can break.  That&amp;rsquo;s where you come in.  If you&amp;rsquo;re interested in this kind of thing, please try out the &lt;code&gt;feature-tool-use&lt;/code&gt; branch of gptel &amp;ndash; kick the tires a bit.  Write your own tools for tasks you&amp;rsquo;d like to automate, and let me know what breaks, and what&amp;rsquo;s missing!&lt;/p&gt;
&lt;p&gt;You can find detailed instructions for testing tool use &lt;a href=&#34;https://github.com/karthink/gptel/issues/514&#34;&gt;on gptel&amp;rsquo;s issue tracker&lt;/a&gt;, which is also the best place to report issues or suggestions.  gptel does not currently ship with any tools, and the issue page includes the collection of tools that I used in the above demos.&lt;/p&gt;
&lt;h2 id=&#34;scratching-the-surface&#34;&gt;Scratching the surface&lt;/h2&gt;
&lt;p&gt;Following the theme of general befuddlement, I&amp;rsquo;m not sure yet about how any of this should work. The most I can confidently say is that as an Emacs-native LLM interface, gptel is quite far from any kind of optimum.  So here&amp;rsquo;s hoping we can inch our way there.&lt;/p&gt;
</description>
    </item><item>
      <title>Fringe Matters: Finding the Right Difference</title>
      <link>https://karthinks.com/software/fringe-matters-finding-the-right-difference/</link>
      <pubDate>Wed, 25 Dec 2024 22:11:00 -0800</pubDate>
      
      <guid>https://karthinks.com/software/fringe-matters-finding-the-right-difference/</guid>
      <description>&lt;p&gt;Continuing my avocation of writing to increasingly niche audiences, today we have a matter at the intersection of several small Venn bubbles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the group of Emacs users who code in Emacs,&lt;/li&gt;
&lt;li&gt;who use Git (or version control) everywhere,&lt;/li&gt;
&lt;li&gt;who work using offshoot or feature branches,&lt;/li&gt;
&lt;li&gt;while using the diff-hl package to visually track changes in their buffers.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As minutiae go, this one is quite &lt;em&gt;minute&lt;/em&gt;, a real fringe matter.  It&amp;rsquo;s also not a paen to Emacs&amp;rsquo; extensibility or composability, because as much as I enjoy beating that drum the feature we&amp;rsquo;re looking for is actually in plain sight for once.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s just really neat though, so I&amp;rsquo;m going to describe it to you.  You&amp;rsquo;re here now.  Settle in.&lt;/p&gt;
&lt;h2 id=&#34;rise-and-shine-dr-dot-diffman-dot-rise-and-shine-dot&#34;&gt;Rise and shine, Dr. Diffman.  Rise and shine.&lt;/h2&gt;
&lt;p&gt;If you load a file that&amp;rsquo;s tracked via version control into your editor, most modern text or code editors will indicate in the buffer the bits that have been modified since the last commit, i.e. the last set of registered changes.  Here&amp;rsquo;s the &lt;a href=&#34;https://zed.dev&#34;&gt;Zed editor&lt;/a&gt; showing this via yellow/red marks in the fringe to the left of the text:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/zed-diff-hl.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;In Emacs this is provided by Dmitry Gutov&amp;rsquo;s &lt;a href=&#34;https://github.com/dgutov/diff-hl&#34;&gt;diff-hl&lt;/a&gt; or Shohei Yoshida&amp;rsquo;s  &lt;a href=&#34;https://github.com/emacsorphanage/git-gutter&#34;&gt;git-gutter&lt;/a&gt; packages, with the former pictured here:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-diff-hl.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;This inline-indication business usually goes &lt;em&gt;much&lt;/em&gt; further, with editors annotating lines with when they were last changed, or whose fault it was.  My relatively tiny code or prose projects with 2-4 participants (at most) have little need for these fancier features.  Emacs makes it easy enough to generate them when required anyway
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
&lt;code&gt;vc-region-history&lt;/code&gt; (&lt;code&gt;C-x v h&lt;/code&gt;) and &lt;code&gt;vc-annotate&lt;/code&gt; (&lt;code&gt;C-x v g&lt;/code&gt;), respectively &amp;ndash; no Magit required.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;But diff-hl is mighty handy.  Being able to identify changed regions at a glance is good, but you can also navigate and act on them.  Jump between hunks with one key, see changes inline, mark or revert hunks and more:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/6ixIlZe.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/emacs-diff-hl-demo.mp4&#34;&gt;[VIDEO: diff-hl demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;The keys being pressed are indicated in the header.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;With &lt;code&gt;diff-hl-mode&lt;/code&gt; enabled in the buffer,&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;diff-hl-next-hunk&lt;/code&gt; (&lt;code&gt;C-x v n&lt;/code&gt;).  This moves the cursor to the next hunk,&lt;/li&gt;
&lt;li&gt;and it activates a &lt;a href=&#34;https://karthinks.com/software/it-bears-repeating/&#34;&gt;repeat-map&lt;/a&gt;, making subsequent diff-hl commands accessible with just &lt;code&gt;n&lt;/code&gt;, &lt;code&gt;p&lt;/code&gt; and so on.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;*&lt;/code&gt; (shortened from &lt;code&gt;C-x v *&lt;/code&gt; by &lt;code&gt;repeat-mode&lt;/code&gt;) to show inline diffs of changed hunks.&lt;/li&gt;
&lt;li&gt;After navigating some more, press &lt;code&gt;SPC&lt;/code&gt; (shortened from &lt;code&gt;C-x v SPC&lt;/code&gt; by &lt;code&gt;repeat-mode&lt;/code&gt;) to mark a hunk.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h2 id=&#34;the-right-diff-in-the-wrong-place-dot-dot-dot&#34;&gt;The right diff in the wrong place&amp;hellip;&lt;/h2&gt;
&lt;p&gt;There&amp;rsquo;s only one problem: when working on a branch with many commits, diff-hl tracks changes relative to the &lt;code&gt;HEAD&lt;/code&gt; of the branch.  This is almost never what I want when I&amp;rsquo;m working on a feature off in a different branch.  Representing each commit as a sphere, here&amp;rsquo;s what I mean:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/diff-hl-default-revision-tree.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;At this stage, the change from &lt;code&gt;feature&lt;/code&gt; / &lt;code&gt;HEAD&lt;/code&gt; to the worktree is at best an incomplete picture.  Unless looking for something very specific, it doesn&amp;rsquo;t help to highlight worktree changes against earlier commits on &lt;code&gt;feature&lt;/code&gt; either.  The previous commits in this branch are temporary checkpoints in an experiment, and don&amp;rsquo;t necessarily represent atomic, self-contained or meaningful changes &amp;ndash; hence the jumble of colors in each commit in the figure.  What I find actually helpful is to compare the contents of the buffer to the state of the &lt;em&gt;main branch&lt;/em&gt;:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/diff-hl-customized-revision-tree.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;This is, of course, readily accessible via Magit or VC via a couple of keystrokes.  Either one can produce pleasingly formatted diff buffers showing the right changes for any range.  But as mentioned above, being able to have the right changes indicated in the work buffer is only one of the advantages.  With diff-hl and the right range of changes indicated, you can jump between them, mark them, revert them and more.&lt;/p&gt;
&lt;p&gt;Recreating the commits in &lt;code&gt;feature&lt;/code&gt; to encode atomic &amp;ndash; or at least limited &amp;ndash; changes is on the docket, but for later.  This involves &amp;ldquo;unscrambling&amp;rdquo; the commits into uniformly colored spheres, often via an interactive rebase, or just selective git-resets:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/diff-hl-cleanup-commits.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Usually the true &amp;ldquo;shape&amp;rdquo; of the changes can only be limned at the end of the &lt;code&gt;feature&lt;/code&gt; experiment, at which point a &amp;ldquo;logical&amp;rdquo; history can be forged before merging into the main branch using your preferred strategy
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Unless your preferred strategy is to &lt;em&gt;squash&lt;/em&gt; all the carefully recreated, atomic commits into a giant merge commit.  Then your preferred strategy is wrong.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/diff-hl-merge-strategy.png&#34;/&gt;
&lt;/figure&gt;

&lt;h2 id=&#34;dot-dot-dot-can-make-all-the-difference-in-the-world-dot&#34;&gt;&amp;hellip;can make all the difference in the world.&lt;/h2&gt;
&lt;p&gt;As it turns out diff-hl understands this problem to a limited extent.  It provides a secondary minor-mode, &lt;code&gt;diff-hl-amend-mode&lt;/code&gt;, that shows the change markers with respect to &lt;code&gt;HEAD^&lt;/code&gt;, the parent of &lt;code&gt;HEAD&lt;/code&gt;.  This is typically what you want when your changes are intended to amend the latest commit instead of creating a new one.  While it&amp;rsquo;s not what we&amp;rsquo;re looking for, it&amp;rsquo;s a good starting point.&lt;/p&gt;
&lt;p&gt;But the mechanism is simple enough.  In this pseudo Elisp block:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;show-changes-between&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;from-commit&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;current-buffer-state&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;we&amp;rsquo;d like a way to set &lt;code&gt;from-commit&lt;/code&gt;, but just for this buffer or project.  If you use &lt;code&gt;diff-hl-amend-mode&lt;/code&gt;, &lt;code&gt;from-commit&lt;/code&gt; would be &lt;code&gt;HEAD^&lt;/code&gt;.  If we can set it to &lt;code&gt;master&lt;/code&gt; or &lt;code&gt;master^&lt;/code&gt; (or &lt;code&gt;main&lt;/code&gt;), we&amp;rsquo;re done.&lt;/p&gt;
&lt;p&gt;And set it we can.  &lt;code&gt;from-commit&lt;/code&gt; is actually a single global variable conveniently exposed by diff-hl: &lt;code&gt;diff-hl-reference-revision&lt;/code&gt;.  We can deal with the globality by making it buffer local.  And that&amp;rsquo;s it as far as the Elisp hacking goes &amp;ndash; no hooks or advice needed today.&lt;/p&gt;
&lt;h2 id=&#34;not-that-i-wish-to-imply-you-have-been-sleeping-on-the-margins-dot&#34;&gt;Not that I wish to imply you have been sleeping on the margins.&lt;/h2&gt;
&lt;p&gt;Only there&amp;rsquo;s still the matter of the interface.  The absolute spartan way of using this option would be to run &lt;code&gt;M-x eval-expression&lt;/code&gt; (&lt;code&gt;M-:&lt;/code&gt;) and type in&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq-local&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;diff-hl-reference-revision&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;master&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;On later uses, you can search the minibuffer history for this code via &lt;code&gt;minibuffer-complete-history&lt;/code&gt; (&lt;code&gt;M-r&lt;/code&gt;).  After a few weeks of this, the mild frustration mounts until it crosses a threshold: &lt;em&gt;I should really put this somewhere more convenient&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The logical next step is to define a command that does this.  diff-hl actually includes one
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
It&amp;rsquo;s &lt;code&gt;diff-hl-set-reference-rev&lt;/code&gt;
&lt;/small&gt;&lt;/span&gt;
, but that sets it globally, across Emacs.  So we sigh and grow our configuration files a little bit:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/diff-hl-set-reference&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Set the reference revision for showing diff-hl changes.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;Do so buffer-locally.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setq-local&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#963&#34;&gt;diff-hl-reference-revision&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;read-string&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;format&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Set reference revision (buffer %s): &amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-name&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;diff-hl-update&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Dust your hands, the problem&amp;rsquo;s solved.  &lt;code&gt;M-x my/diff-hl-set-reference&lt;/code&gt; works pleasingly for a few weeks, especially since the minibuffer completion system floats this up with frequent usage
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
You do use &lt;code&gt;savehist-mode&lt;/code&gt; or &lt;code&gt;prescient&lt;/code&gt;, right?
&lt;/small&gt;&lt;/span&gt;
for easy access.&lt;/p&gt;
&lt;p&gt;But eventually two further needs appear:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;I use this so often that I need it on a key, dammit.&lt;/li&gt;
&lt;li&gt;Can&amp;rsquo;t I just set this across my project instead of in every buffer?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Needs 1 and 2 obviate each other somewhat, in that either one makes it less necessary to call the &lt;code&gt;-set-reference&lt;/code&gt; command via &lt;code&gt;M-x&lt;/code&gt;.  But let&amp;rsquo;s address them separately anyway.&lt;/p&gt;
&lt;h3 id=&#34;all-the-effort-in-the-world-would-have-gone-to-waste-until-dot-dot-dot&#34;&gt;All the effort in the world would have gone to waste until&amp;hellip;&lt;/h3&gt;
&lt;p&gt;Setting up a keybind is easy if we can find room for it.  And then if we can remember it.  Emacs keymaps are crowded spaces.  On more than one occasion I&amp;rsquo;ve opened up my init file intending to add a handy keybinding for a useful command, only to discover that I already did months ago&amp;hellip; and then forgot it was available.&lt;/p&gt;
&lt;p&gt;To some extent you can mitigate this effect by placing it logically with the other diff-hl commands, which are conveniently grouped together into &lt;code&gt;diff-hl-command-map&lt;/code&gt;.  So assuming you use &lt;em&gt;any&lt;/em&gt; diff-hl commands, this one should show up in &lt;code&gt;which-key&lt;/code&gt; or your keymap prompter of choice.&lt;/p&gt;
&lt;p&gt;But in my case even this is a lost cause.  I already combine &lt;code&gt;vc-prefix-map&lt;/code&gt;, used by Emacs for version control actions, with &lt;code&gt;diff-hl-command-map&lt;/code&gt; under the &lt;code&gt;C-x v&lt;/code&gt; prefix because their functions are related.  So &lt;code&gt;C-x v&lt;/code&gt; is quite a busy junction.  Here&amp;rsquo;s which-key doing its best to show me what&amp;rsquo;s available:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/vc-prefix-map-preview.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;The solution is to place it where I turn on/off &lt;code&gt;diff-hl-mode&lt;/code&gt; in the first place: in a catchall transient menu I use to access all minor-modes I need in Emacs buffers
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
A good chunk of this menu deals with settings that make no sense for most Emacs users &amp;ndash; for example, a switch to toggle requiring sentence ends to be single/double spaced, adjust line-spacing on the fly, or switch between different sets of &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Completion-in-Buffers.html&#34;&gt;CAPFs&lt;/a&gt;.
&lt;/small&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/toggle-modes-transient.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Calling the diff-hl option from this menu with a prefix-arg now (essentially) runs the above function, allowing me to set the reference revision before turning on the mode (if required).&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/diff-hl-rev-comparison.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Here&amp;rsquo;s a demo combining this with a few other nifty diff-hl commands and &lt;a href=&#34;https://karthinks.com/software/it-bears-repeating/&#34;&gt;repeat-mode&lt;/a&gt;:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/kFPo8BW.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/diff-hl-toggle-modes-demo.mp4&#34;&gt;[VIDEO: Toggling diff-hl reference revision]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;The keys being pressed are indicated at the top.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Begin in a buffer in some feature branch that is some &amp;ldquo;distance&amp;rdquo; away from &lt;code&gt;master&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use diff-hl commands to navigate to hunks. diff-hl is currently showing buffer changes in the working tree against &lt;code&gt;HEAD&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;diff-hl-show-hunk&lt;/code&gt; (&lt;code&gt;C-x v *&lt;/code&gt;) to see the diffs for individual hunks inline.&lt;/li&gt;
&lt;li&gt;Call the &lt;code&gt;toggle-modes&lt;/code&gt; transient mentioned above.&lt;/li&gt;
&lt;li&gt;Choose the &lt;code&gt;g&lt;/code&gt; option with a prefix-arg (&lt;code&gt;C-u&lt;/code&gt;).  This causes the reference revision (the &lt;code&gt;from-commit&lt;/code&gt; we want) to be read from the minibuffer.  Ask to see changes from &lt;code&gt;master&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;diff-hl updates to mark changes from &lt;code&gt;master&lt;/code&gt;.  As you might expect, there are more changes &amp;ndash; everything that&amp;rsquo;s changed since &lt;code&gt;master&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Navigate through the changes again with diff-hl commands.&lt;/li&gt;
&lt;li&gt;Pick the &lt;code&gt;toggle-modes&lt;/code&gt; transient menu option again, this time setting the reference revision to &lt;code&gt;HEAD&lt;/code&gt;&amp;rsquo;s grandparent, &lt;code&gt;HEAD^^&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;diff-hl updates the changes again.  As you might expect, there are fewer changes.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Here&amp;rsquo;s the actual function that &lt;code&gt;g&lt;/code&gt; in the &lt;code&gt;toggle-modes&lt;/code&gt; menu is bound to:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Toggle &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`diff-hl-mode&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;With prefix ARG ensure &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`diff-hl-mode&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; and set revision to compare
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;against.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;null&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;diff-hl-mode&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;toggle&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;ref&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;read-string&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Reference revision for diff-hl: &amp;#34;&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;setq-local&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;diff-hl-reference-revision&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ref&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;diff-hl-mode&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;diff-hl-update&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;message&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Showing changes against %s&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ref&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;dot-dot-dot-well-let-s-just-say-your-hour-has-come-again-dot&#34;&gt;&amp;hellip;well, let&amp;rsquo;s just say your hour has come again.&lt;/h3&gt;
&lt;p&gt;As you might expect, the way to apply diff-hl&amp;rsquo;s reference revision setting to all buffers in a project is to use a &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html&#34;&gt;directory-local variable&lt;/a&gt;.  In most cases, setting it once per project (or git-worktree, in my case) is all you need.&lt;/p&gt;
&lt;p&gt;This approach requires a little forethought but no moment-to-moment busywork: Run &lt;code&gt;M-x add-dir-local-variable&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;with a major-mode choice of &lt;code&gt;nil&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;and setting the variable &lt;code&gt;diff-hl-reference-revision&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;to &lt;code&gt;&amp;quot;master&amp;quot;&lt;/code&gt; .&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This produces the following &lt;code&gt;.dir-locals.el&lt;/code&gt; file:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;;; Directory Local Variables            -*- no-byte-compile: t -*-&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;;; For more information see (info &amp;#34;(emacs) Directory Variables&amp;#34;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;((&lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;diff-hl-reference-revision&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;master&amp;#34;&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Typically you would want to chuck this file into version control as well &amp;ndash; but in this case that may be something you want to consider carefully!&lt;/p&gt;
&lt;h2 id=&#34;so-wake-up-dr-dot-diffman-dot-wake-up-and-mark-the-fringes-dot&#34;&gt;So, wake up, Dr. Diffman.  Wake up and mark the fringes.&lt;/h2&gt;
&lt;p&gt;Before I thought to adapt diff-hl to how I worked, I was coding in feature branches in a strange way.  I would make a bunch of work-in-progress checkpoint commits and store them on a remote, then soft-reset the branch to the original branch point so I could see indicators for all changed regions in buffers, jump between them with &lt;code&gt;diff-hl-next-hunk&lt;/code&gt; and so on.&lt;/p&gt;
&lt;p&gt;It took a while
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
a &amp;ldquo;while&amp;rdquo; is code for &lt;em&gt;years&lt;/em&gt;
&lt;/small&gt;&lt;/span&gt;
to consider that it didn&amp;rsquo;t have to be this way.  This isn&amp;rsquo;t an adjustment that requires Emacs&amp;rsquo; much vaunted flexibility &amp;ndash; you can probably do this in any editor that provides the diff-hl feature.  I just never thought to do it, and worked around the tool instead of making the tool work for me.  Well that&amp;rsquo;s sorted.&lt;/p&gt;
&lt;p&gt;There is no other upshot.  This yak has been shaved.  You&amp;rsquo;re free now, go mark some fringes.&lt;/p&gt;
</description>
    </item><item>
      <title>The Emacs Window Management Almanac</title>
      <link>https://karthinks.com/software/emacs-window-management-almanac/</link>
      <pubDate>Fri, 10 May 2024 16:13:00 -0700</pubDate>
      
      <guid>https://karthinks.com/software/emacs-window-management-almanac/</guid>
      <description>&lt;p&gt;Window management in Emacs gets a bad rap.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;As someone who&amp;rsquo;s spent an unnecessary amount of time trying different approaches to window management in Emacs over the decades, I decided to summarize them here.  Almanac might be overstating it a bit &amp;ndash; this is a primer to and a collection of window management resources and tips.&lt;/p&gt;
&lt;p&gt;Window management in Emacs bleeds into buffer, state, workspace and frame management, so it&amp;rsquo;s difficult to contain the scope of any article that aims to be comprehensive.  To that end,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;this write-up assumes that you&amp;rsquo;ve finished at least the Emacs tutorial and are familiar with basic Emacs terminology (what&amp;rsquo;s a buffer, window and a frame) and with window actions: splitting windows, deleting them or deleting other windows, and switching focus.&lt;/li&gt;
&lt;li&gt;There are only a few brief mentions of tabs, as they are primarily a tool for workspace management, as opposed to window management.&lt;/li&gt;
&lt;li&gt;I&amp;rsquo;m focusing on window/buffer management within an Emacs frame.  Many of the below tools work across frames just as well, but you&amp;rsquo;ll have to find the right switches to flip to enable cross-frame support.&lt;/li&gt;
&lt;li&gt;Finally, this is more &lt;em&gt;my&lt;/em&gt; almanac than a wiki: It covers only tools or ideas I&amp;rsquo;ve personally explored over the years, with brief mentions of potentially useful packages that I haven&amp;rsquo;t tried.  Any omissions are not value judgments, please let me know if I miss something useful.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;At some point this transitions from listing well known tools to tips, then hacks, and finally unvarnished opinions.  It&amp;rsquo;s front-loaded: the first chunk of the write-up gives you a 70% solution.  If you are new to Emacs, feel free to stop at 30%.  If you are an old hand, feel free to skip the first 30%.  It also lists substitutes: several ways to do the same things, &lt;strong&gt;so you can pick just one method&lt;/strong&gt; and ignore the rest.   Things get progressively more opinionated and idiosyncratic in the second half.&lt;/p&gt;
&lt;p&gt;If you are reading this in the future, this write-up is probably out of date.  The Emacs core is very stable, but the package ecosystem tends to drift around as packages are developed and abandoned.  The built-in solutions will still be around, but there are no guarantees on the third-party packages!  That said, the longer a package has been around the more likely it&amp;rsquo;s going to stick around in a functional state &amp;ndash;  even if only as a frozen entry in the &lt;a href=&#34;https://github.com/emacsorphanage&#34;&gt;Emacs Orphanage&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As new ideas emerge, there will be new approaches to window management that aren&amp;rsquo;t covered here.  These innovations don&amp;rsquo;t need to happen in the Emacs sphere &amp;ndash; Emacs likes to &lt;del&gt;steal&lt;/del&gt; reinvent ideas that originate elsewhere, much as other applications rediscover ideas that Emacs introduced in the 1990s.  So this topic might be worth revisiting afresh in a few years.&lt;/p&gt;
&lt;h2 id=&#34;what-we-mean-by-window-management&#34;&gt;What we mean by &amp;ldquo;window management&amp;rdquo;&lt;/h2&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-window-buffer-frame.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Emacs separates the idea of a &lt;strong&gt;window&lt;/strong&gt; (a &amp;ldquo;viewport&amp;rdquo; or &amp;ldquo;pane&amp;rdquo; in the frame) from the &lt;strong&gt;buffer&lt;/strong&gt;, a contiguous chunk of text that may or may not be the contents of a file.  These concepts are usually fused in IDEs and text editors &amp;ndash; this reduces the cognitive load of using the application, but closes the door on more flexible behavior and free-form arrangments.  For example, many editors don&amp;rsquo;t let you have two views of the same file, which is trivial in Emacs.  They&amp;rsquo;re often uncomfortable even with the idea of a dissociated buffer &amp;ndash; a buffer that does not represent the (possibly edited) contents of a file.  Reified concepts like Emacs&amp;rsquo; &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/emacs/Indirect-Buffers.html&#34;&gt;indirect buffers&lt;/a&gt; are completely foreign to them
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Unfortunately for Emacs, its current design rules out some clever ideas that other editors have implemented.  One example of this is the &lt;a href=&#34;https://github.com/perky/4coder_loco&#34;&gt;4coder&amp;rsquo;s yeetsheet&lt;/a&gt; or &lt;a href=&#34;https://www.youtube.com/watch?v=GB_oTjVVgDc&#34;&gt;Dion systems&amp;rsquo; views&lt;/a&gt;: You can have buffers whose contents are &amp;ldquo;live&amp;rdquo; substrings of multiple other buffers, &lt;em&gt;i.e.&lt;/em&gt; you can mix and match &lt;em&gt;pieces&lt;/em&gt; of buffers.  In Emacs the most you can have is indirect buffers, &lt;em&gt;i.e.&lt;/em&gt; full &amp;ldquo;live&amp;rdquo; copies of a buffer.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;Emacs allows you to do a lot more, but users have to contend with this cognitive cost.  New users pay thrice: they have to deal with getting windows into the right places in the frame, getting buffers into the right windows, &lt;em&gt;and&lt;/em&gt; they miss out on the upside because they don&amp;rsquo;t yet realize what this decoupling makes possible.  Hopefully this write-up can address two of these costs.&lt;/p&gt;
&lt;p&gt;For reference in the rest of this article, here&amp;rsquo;s a non-exploded schematic of an Emacs frame, with the left window selected:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-window-chart.png&#34;/&gt;
&lt;/figure&gt;

&lt;ul&gt;
&lt;li&gt;Each colored block is a window, the numbers represent buffers being shown in them.&lt;/li&gt;
&lt;li&gt;The active window is the one with a black border.&lt;/li&gt;
&lt;/ul&gt;
&lt;style&gt;
.detail-icon {
float: right;
width: 25px;
}
&lt;/style&gt;
&lt;h3 id=&#34;this-article-is-not-about&#34;&gt;This article is &lt;strong&gt;not&lt;/strong&gt; about…&lt;/h3&gt;
&lt;p&gt;Since actions with or on windows in Emacs are primitive, common and unavoidable operations at any level of Emacs usage, this topic is suprisingly subtle, broad and deep, and there&amp;rsquo;s only so much I can explore in 15,000 words.  So we begin with some disambiguation and a narrowing of focus.  This article is &lt;strong&gt;not&lt;/strong&gt; about the following things.&lt;/p&gt;
&lt;details open&gt;
&lt;summary&gt;Rules for displaying buffers&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;blockquote&gt;
&lt;p&gt;Emacs keeps popping up windows in the wrong places and destroying my window arrangement!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The situation is&amp;hellip; less than ideal.  Displaying buffers in the right windows &lt;em&gt;automagically&lt;/em&gt; is generally possible but this configuration is involved and requires knowledge of minutiae of the Emacs API, like &lt;code&gt;window-parameters&lt;/code&gt;, slots and dedicated windows.  the &lt;code&gt;display-buffer&lt;/code&gt; API is so involved that describing it takes up a big chunk of the Elisp manual, and even that concludes by saying &amp;ldquo;&lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/The-Zen-of-Buffer-Display.html&#34;&gt;just go with it&lt;/a&gt;&amp;rdquo;.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
And this is the one aimed at developers using elisp.  It&amp;rsquo;s not even the Emacs user manual!
&lt;/small&gt;&lt;/span&gt;
I mention automatic window management &lt;a href=&#34;#deal-with-windows-so-we-don-t-have-to-deal-with-windows&#34;&gt;briefly towards the end&lt;/a&gt;, but this article is &lt;strong&gt;not&lt;/strong&gt; about reining in the behavior of &lt;code&gt;display-buffer&lt;/code&gt;.  I recommend &lt;a href=&#34;https://www.masteringemacs.org/article/demystifying-emacs-window-manager&#34;&gt;Mickey Peterson&amp;rsquo;s article&lt;/a&gt; on demystifying the window manager for this, this &lt;a href=&#34;https://protesilaos.com/codelog/2024-02-08-emacs-window-rules-display-buffer-alist/&#34;&gt;video by Protesilaos Stavrou&lt;/a&gt;, or &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Displaying-Buffers.html&#34;&gt;the manual&lt;/a&gt; if you&amp;rsquo;ve got the stomach for it.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--window-configuration-persistence&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;details open&gt;
&lt;summary&gt;Window configuration persistence, workspaces or buffer isolation&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;blockquote&gt;
&lt;p&gt;I want Emacs to group together windows for a given task and persist them across sessions!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Two common factors affecting Emacs use:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Emacs sessions tend to be long lasting, and&lt;/li&gt;
&lt;li&gt;its gravity pulls users into using it for an increasing number of tasks.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The result is that you end up with hundreds of buffers and start looking for ways to group them, isolate the groups and then preserve them.  This is tied to window management, but only in the sense that your arrangement of windows is part of the state you want to preserve.  This is a finicky and complex subject, and well beyond the scope of this write-up.  Take your pick: between  &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/emacs/Tab-Bars.html&#34;&gt;tab-bar&lt;/a&gt;, &lt;a href=&#34;https://github.com/mclear-tools/tabspaces&#34;&gt;tabspaces&lt;/a&gt;, &lt;a href=&#34;https://depp.brause.cc/eyebrowse/&#34;&gt;eyebrowse&lt;/a&gt;, &lt;a href=&#34;https://github.com/minad/tab-bookmark&#34;&gt;tab-bookmark&lt;/a&gt;, &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Desktop-Save-Mode.html&#34;&gt;desktop.el&lt;/a&gt;, &lt;a href=&#34;https://github.com/Bad-ptr/persp-mode.el&#34;&gt;persp-mode.el&lt;/a&gt;, &lt;a href=&#34;https://github.com/nex3/perspective-el&#34;&gt;perspective&lt;/a&gt;, &lt;a href=&#34;https://github.com/fritzgrabo/project-tab-groups&#34;&gt;project-tab-groups&lt;/a&gt;, &lt;a href=&#34;https://gitlab.com/protesilaos/beframe&#34;&gt;beframe&lt;/a&gt; and &lt;a href=&#34;https://github.com/alphapapa/activities.el&#34;&gt;activities.el&lt;/a&gt; there is no paucity of projects to help you do this.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details open&gt;
&lt;summary&gt;Paradigmatic changes to window behavior in Emacs&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;blockquote&gt;
&lt;p&gt;Why is window placement in Emacs so capricious? Tiling window managers solved this problem ages ago!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Some packages provide all-encompassing, radical solutions to window arrangment and management &amp;ndash; essentially, they are &lt;em&gt;window managers&lt;/em&gt; for Emacs.  For example, &lt;a href=&#34;https://gitlab.com/ajgrf/edwina&#34;&gt;Edwina&lt;/a&gt; modifies Emacs&amp;rsquo; manual window-tree based behavior to enforce a master-and-stack &lt;a href=&#34;https://dwm.suckless.org/tutorial/&#34;&gt;DWM-style auto-tiling layout&lt;/a&gt;, with a complete suite of accompanying window management commands.  &lt;a href=&#34;https://www.gnu.org/software/hyperbole/man/hyperbole.html#HyControl&#34;&gt;HyControl&lt;/a&gt; provides a control panel for window layout actions and can display windows in a uniform grid on the frame, among other features.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Apologies for the terse and possibly inaccurate descriptions, I have only brief experience with these.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;In my experience &amp;ldquo;complete&amp;rdquo; solutions like these are great when you start using them, but eventually cause more friction than elation.  This is the case the more you customize Emacs, as the abstractions they build on top of the Emacs API end up limiting, as opposed to liberating you in the long run.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;hr&gt;
&lt;p&gt;So what&amp;rsquo;s left?  In this article, &lt;strong&gt;we mean window management in the manual and mundane sense&lt;/strong&gt;: switching window focus, moving buffers around windows, splitting or closing them and so on.  Even if you&amp;rsquo;ve got &lt;code&gt;display-buffer&lt;/code&gt; all sorted out and your windows grouped into workspaces, these are the kinds of things you &lt;em&gt;have&lt;/em&gt; to do with windows &amp;ndash; repeatedly and often &amp;ndash; in the course of minute-to-minute, regular editing.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s address a couple of common concerns and dismissals before we get started in earnest.&lt;/p&gt;
&lt;details open&gt;
&lt;summary&gt;The two-window perspective&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;blockquote&gt;
&lt;p&gt;This palaver is pointless, I need two windows at most.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Correction: You need at most two windows &lt;em&gt;at a time&lt;/em&gt;.  And that&amp;rsquo;s partly because corralling windows is a mess in Emacs.  Except during bursts of writing or coding, chances are you need easy access to more than one buffer &amp;ndash; for reference material or look-ups, search and compilation results, file access, shells and REPLs, table of contents and so on.  Whether these are on screen in windows all the time or easily displayed on demand is a matter of screen size and preference, but both involve interacting with windows and buffers &lt;em&gt;manually&lt;/em&gt;.  Both approaches are thus under the purview of &amp;ldquo;window management&amp;rdquo;, and addressed in this article.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details open&gt;
&lt;summary&gt;The pointer prescription&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;blockquote&gt;
&lt;p&gt;Just use the mouse?  This isn&amp;rsquo;t even an issue in most software.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The mouse is indeed the most natural way to navigate windows.  Without stepping into contentious discussions on economy of motion, RSI trouble or personal preferences, the main problem with the mouse approach is that the lack of a learning curve (relative to the keyboard) is balanced by the lack of expressivity (relative to the keyboard).&lt;/p&gt;
&lt;p&gt;Even so, you can &lt;a href=&#34;https://karthinks.com/software/different-strokes-for-different-folks/&#34;&gt;squeeze a lot more expressivity&lt;/a&gt; out of the mouse in Emacs than you can in most other applications
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
The &lt;a href=&#34;https://en.wikipedia.org/wiki/Acme_(text_editor)&#34;&gt;ACME editor&lt;/a&gt; might be the most notable exception.
&lt;/small&gt;&lt;/span&gt;
.  I use the mouse for managing windows in Emacs often &amp;ndash; but only in certain contexts, see &lt;a href=&#34;#mousing-around--built-in&#34;&gt;Mousing around&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h2 id=&#34;warming-up&#34;&gt;Warming up&lt;/h2&gt;
&lt;p&gt;Our appetizer: a short run-through of the most popular and commonly recommended window management options.  These cover changing the focused window, moving windows around and undoing oopsies, with a side of buffer management and bespoke window actions
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
This is the part you can skip if you&amp;rsquo;ve been around the block a few times.  Jump ahead to &lt;a href=&#34;#digging-in&#34;&gt;digging in&lt;/a&gt;.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;h3 id=&#34;other-window-and-the-next-window--built-in&#34;&gt;&lt;code&gt;other-window&lt;/code&gt; and the &amp;ldquo;next window&amp;rdquo; (built-in)&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;other-window&lt;/code&gt; offers: selecting windows&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;other-window&lt;/code&gt; (&lt;code&gt;C-x o&lt;/code&gt;) command is the baseline window switching experience.  It&amp;rsquo;s what the Emacs tutorial teaches you, and it works well enough when you have a small number of windows:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/other-window-chart.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;The window selection cycles (roughly) clockwise across the frame.  The advantage of this approach is simplicity &amp;ndash; it&amp;rsquo;s a single command and keybinding.  As you might expect or have experienced, it takes progressively more invocations to get somewhere as you accumulate more windows, and works best if you rarely have more than two windows showing at once.&lt;/p&gt;
&lt;details class=&#34;details apinote&#34; open&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Basic &lt;code&gt;other-window&lt;/code&gt; tips and tweaks&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;It&amp;rsquo;s possibly one of the most used Emacs commands &amp;ndash; bind it to a more convenient key like &lt;code&gt;M-o&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You can use digit arguments to skip windows or to cycle windows backwards.  &lt;code&gt;M-3 M-o&lt;/code&gt; will select three windows ahead, and &lt;code&gt;M-- M-2 M-o&lt;/code&gt; two windows back.  Unfortunately this requires a visual understanding of the order in which the cycling happens.  It&amp;rsquo;s not obvious which window is three windows away in more complex window layouts.&lt;/li&gt;
&lt;li&gt;Turn on &lt;code&gt;repeat-mode&lt;/code&gt; (&lt;code&gt;M-x repeat-mode&lt;/code&gt;) to continue switching windows with just &lt;code&gt;o&lt;/code&gt; and (backwards) &lt;code&gt;O&lt;/code&gt;.  &lt;code&gt;C-x o o o o...&lt;/code&gt; or &lt;code&gt;M-o o o o...&lt;/code&gt; is faster than &lt;code&gt;C-x o C-x o C-x o...&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details class=&#34;details implementation&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/lisp-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;  &lt;code&gt;other-window&lt;/code&gt; hacks&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;You can make &lt;code&gt;other-window&lt;/code&gt; skip over a window by setting its &lt;code&gt;no-other-window&lt;/code&gt; window parameter.  A window parameter is a property of Emacs&amp;rsquo; window data structure, and there are Elisp functions to set them.  This is usually something you&amp;rsquo;d specify in advance for certain classes of buffers in &lt;code&gt;display-buffer-alist&lt;/code&gt;, not a manual toggle.  If you&amp;rsquo;ve ever wondered why &lt;code&gt;other-window&lt;/code&gt; does not select the windows of fancy file-manager listings (like dired-sidebar or dirvish-side), this is it.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;If you only ever have two windows showing in Emacs, or if you don&amp;rsquo;t mind punching &lt;code&gt;o&lt;/code&gt; a few extra times, you can stop here.  The rest is just varying degrees of optimization applied to a problem that you probably (and perhaps realistically) don&amp;rsquo;t believe needs solving!&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--window-management-next-window&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;details open&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Understanding the &amp;ldquo;next window&amp;rdquo;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;The &amp;ldquo;next window&amp;rdquo; is the window that &lt;code&gt;other-window&lt;/code&gt; selects, usually clockwise from the current one.  You can access it in elisp by calling the &lt;code&gt;next-window&lt;/code&gt; function.  With daily usage, you automatically develop intuition for the clockwise ordering of windows in an Emacs frame &amp;ndash; in the sense that you &lt;em&gt;know&lt;/em&gt; instead of &lt;em&gt;think&lt;/em&gt;.  This is handy, because the notion of the next window is useful for more than just window selection.  There are better ways to select windows, or there wouldn&amp;rsquo;t be much to this write-up!  The next window is the default window for commands that operate in another window, like &lt;code&gt;scroll-other-window&lt;/code&gt;.  See &lt;a href=&#34;#do-you-need-to-switch-windows&#34;&gt;Do you need to switch windows?&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;windmove--built-in&#34;&gt;&lt;code&gt;windmove&lt;/code&gt; (built-in)&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;windmove&lt;/code&gt; offers: selecting windows, swapping buffers in windows, deleting them&lt;/p&gt;
&lt;p&gt;Windmove is a built-in Emacs library for moving the focus across windows &amp;ndash; and for moving buffers across windows &amp;ndash; by direction.  Vim users, this is what you expected.  &lt;code&gt;evil-mode&lt;/code&gt; users, you already use Windmove, you just don&amp;rsquo;t know it.&lt;/p&gt;
&lt;p&gt;If &lt;code&gt;other-window&lt;/code&gt; is the alt-tab of Emacs, Windmove is the tiling window manager equivalent.  It makes the spatial arrangement of windows in the frame relevant to the selection, which I imagine is the most natural way to do it short of using the mouse.&lt;/p&gt;
&lt;p&gt;Using Windmove is simple: bind &lt;code&gt;windmove-left&lt;/code&gt; (resp &lt;code&gt;-right&lt;/code&gt;, &lt;code&gt;-up&lt;/code&gt; and &lt;code&gt;-down&lt;/code&gt;) to a modifier or leader key plus whatever keys you associate with directions: &lt;code&gt;WASD&lt;/code&gt;, &lt;code&gt;HJKL&lt;/code&gt; or the arrow keys perhaps.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/windmove-chart.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;The fork: movement to the right in this schematic depends on what window is exactly to the right of the cursor.  Calling &lt;code&gt;windmove-right&lt;/code&gt; from near the top of buffer 1 moves the focus to buffer 2, starting near the bottom moves the focus to 3.&lt;/p&gt;
&lt;p&gt;You can also swap the buffers of windows directionally with Windmove, a handy way of rearranging windows on the frame
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Again, Windmove is how &lt;code&gt;evil-mode&lt;/code&gt; does this.
&lt;/small&gt;&lt;/span&gt;
.  The relevant commands are &lt;code&gt;windmove-swap-states-left&lt;/code&gt;, &lt;code&gt;-right&lt;/code&gt;, &lt;code&gt;-up&lt;/code&gt; and &lt;code&gt;-down&lt;/code&gt;.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/windmove-swap-chart.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Note that the focus moves along with the buffer when you do this.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s more yet to Windmove, you can delete the window next along any direction with &lt;code&gt;windmove-delete-*&lt;/code&gt;, for example.  But we cover better ways to do this below.&lt;/p&gt;
&lt;details class=&#34;details apinote&#34; open&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Tiling manager integration&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;If you use Emacs in a tiling environment, you&amp;rsquo;ve got a nested tiling window manager situation &amp;ndash; it might be desirable to integrate the two so you can (wind)move seamlessly across Emacs windows and OS windows with the same keys.  (Vim+tmux users should be familiar with this.)  It takes a bit of work but is quite doable: Pavel Korytov has an &lt;a href=&#34;https://sqrtminusone.xyz/posts/2021-10-04-emacs-i3/&#34;&gt;i3 integration&lt;/a&gt; description for Emacs+i3wm (and possibly Sway), and I wrote one for the &lt;a href=&#34;https://github.com/karthink/.emacs.d/blob/master/plugins/emacs-wm.el&#34;&gt;qtile&lt;/a&gt; window manager.  I discuss this project in &lt;a href=&#34;#the-tiling-wm-integrator&#34;&gt;more detail below&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;frames-only-mode&#34;&gt;frames-only-mode&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/davidshepherd7/frames-only-mode&#34;&gt;frames-only-mode&lt;/a&gt; offers: to leave Emacs window handling to the OS.&lt;/p&gt;
&lt;figure class=&#34;alignright&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/frames-only-mode.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;While we&amp;rsquo;re on the subject of tiling, another resolution to the nested window manager situation &amp;ndash; Emacs inside a tiling WM &amp;ndash; is to simply not bother with Emacs&amp;rsquo; window management.  Opening every buffer in a new frame instead of window makes corralling them the window manager&amp;rsquo;s job.  This puts Emacs buffers on par with OS windows, and you can manage both with the same keys.&lt;/p&gt;
&lt;p&gt;Most other commands described in this write-up (such as Avy, &lt;code&gt;winum&lt;/code&gt;, &lt;code&gt;ace-window&lt;/code&gt; or &lt;code&gt;scroll-other-window&lt;/code&gt;) can work across frames just as easily as windows, meaning that you can have the best of both approaches.  There are bound to be edge cases with other Emacs commands though &amp;ndash; many of them make assumptions about being able to split the frame at will
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
This is especially true of org-mode commands!  Thankfully the Org situation is slowly improving.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;div class=&#34;warning&#34;&gt;
&lt;p&gt;For Linux users:
I haven&amp;rsquo;t tried &lt;code&gt;frames-only-mode&lt;/code&gt; with Wayland compositors yet.&lt;/p&gt;
&lt;/div&gt;
&lt;h3 id=&#34;winum-mode&#34;&gt;&lt;code&gt;winum-mode&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/deb0ch/emacs-winum&#34;&gt;winum&lt;/a&gt; offers: Selecting and deleting windows&lt;/p&gt;
&lt;p&gt;Winum is next in the natural progression of the effort to switch between n windows: From O(n) (&lt;code&gt;other-window&lt;/code&gt;) to O(√n) (&lt;code&gt;windmove&lt;/code&gt;) to O(1).  It adds window numbers to the mode-line so you can select windows by number:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/winum-chart.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;There are two convenient bonus features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Invoking the command to switch to a window with a negative prefix argument deletes the window, and&lt;/li&gt;
&lt;li&gt;when the minibuffer is active, it is always assigned the number 0.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It&amp;rsquo;s simple and short, and works across Emacs frames.  &lt;code&gt;winum-mode&lt;/code&gt; is the method I use the most for switching windows.&lt;/p&gt;
&lt;details class=&#34;details apinote&#34; open&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/lisp-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Speeding up window access with winum&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;The default keybinding (&lt;code&gt;C-x w &amp;lt;n&amp;gt;&lt;/code&gt; to select window &lt;code&gt;n&lt;/code&gt;) is too verbose for my liking, as is any other two step keybinding.  If you don&amp;rsquo;t mind losing access to digit arguments with &lt;code&gt;M-0&lt;/code&gt; through &lt;code&gt;M-9&lt;/code&gt;, you can use them to select windows instead:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;defvar-keymap&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;winum-keymap&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:doc&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Keymap for winum-mode actions.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-0&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;winum-select-window-0-or-10&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-1&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;winum-select-window-1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-2&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;winum-select-window-2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-3&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;winum-select-window-3&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-4&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;winum-select-window-4&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-5&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;winum-select-window-5&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-6&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;winum-select-window-6&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-7&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;winum-select-window-7&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-8&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;winum-select-window-8&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-9&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;winum-select-window-9&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;require&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;winum&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;winum-mode&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;While it is possible to extend &lt;code&gt;winum-mode&lt;/code&gt; to include other actions on windows (or on buffers displayed in them) besides switching to or deleting them, there&amp;rsquo;s little reason to, thanks to the existence of&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;ace-window&#34;&gt;&lt;code&gt;ace-window&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Offers: &lt;em&gt;Any&lt;/em&gt; window or buffer management action&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/abo-abo/ace-window&#34;&gt;ace-window&lt;/a&gt; is the endgame for keyboard-driven Emacs window control.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;ace-window&lt;/code&gt; command places &amp;ldquo;hints&amp;rdquo; at the top of each window, and typing in the key switches focus to the corresponding one:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/ace-window-chart.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;So far it&amp;rsquo;s a slightly slower, two-stage version of winum.  You can turn on &lt;code&gt;ace-window-display-mode&lt;/code&gt; to have the hints always showing in the mode-line like winum&amp;rsquo;s window numbers, which speeds up the process a bit:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/ace-window-display-mode.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;ace-window is to windows what Avy is to characters on screen
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
The similar design is not a coincidence.  They&amp;rsquo;re both authored by &lt;a href=&#34;https://oremacs.com/&#34;&gt;Oleh Krehel&lt;/a&gt;.
&lt;/small&gt;&lt;/span&gt;
.  But jumping to a character on screen is the least useful of the many &lt;a href=&#34;https://karthinks.com/software/avy-can-do-anything/&#34;&gt;things you can do with Avy&lt;/a&gt;.  Similarly, if all ace-window could do was switch windows, there wouldn&amp;rsquo;t be much to recommend it.  Instead, it offers a generic method to &amp;ldquo;pick&amp;rdquo; a window, across all visible Emacs frames if necessary.  What you do with this window is up to you.  Similar to Avy, ace-window can dispatch actions on any window on the screen.  So you can delete windows, move or swap them around, split them, show buffers in them and more &amp;ndash; without moving away from your selected window.  These are just the built-in actions, provided as part of ace-window:
&lt;span class=&#34;org-target&#34; id=&#34;org-target--ace-window-default-actions&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;figure class=&#34;wide&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/ace-dispatch-chart.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Pressing &lt;code&gt;?&lt;/code&gt; when using &lt;code&gt;ace-window&lt;/code&gt; brings up the dispatch menu
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
See &lt;a href=&#34;https://karthinks.com/software/fifteen-ways-to-use-embark/&#34;&gt;Fifteen ways to use Embark&lt;/a&gt; for further explorations of this idea.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/7OFRShA.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/ace-dispatch-demo.mp4&#34;&gt;[VIDEO: ace-window dispatch demo]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;With two or more windows open, call &lt;code&gt;ace-window&lt;/code&gt;.  (For two windows or fewer, you will need to ensure that the variable &lt;code&gt;aw-dispatch-always&lt;/code&gt; is set to &lt;code&gt;t&lt;/code&gt;.)&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;?&lt;/code&gt; to bring up the dispatch menu.&lt;/li&gt;
&lt;li&gt;Press the dispatch key to split a window horizontally (&lt;code&gt;v&lt;/code&gt; in my video)&lt;/li&gt;
&lt;li&gt;Press the ace-window key corresponding to the buffer you want to split (&lt;code&gt;e&lt;/code&gt; in my video)&lt;/li&gt;
&lt;li&gt;Repeat steps 1 and 2&lt;/li&gt;
&lt;li&gt;Press the dispatch key to split a window vertically (&lt;code&gt;s&lt;/code&gt; in my video)&lt;/li&gt;
&lt;li&gt;Press the ace-window key corresponding to the buffer you want to split (&lt;code&gt;w&lt;/code&gt; in my video)&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;mousing-around--built-in&#34;&gt;Mousing around (built-in)&lt;/h3&gt;
&lt;p&gt;The mouse offers: Any window or buffer management action&lt;/p&gt;
&lt;p&gt;So, the pointer.  Finally.&lt;/p&gt;
&lt;p&gt;The advantanges of using the mouse for window management are immediate and obvious.  Window selection is a natural extension of basic mouse usage.  Resizing windows is a snap.  Context (right-click) menus and drag and drop support, which improve with each new Emacs release, are very intuitive
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
See &lt;code&gt;context-menu-mode&lt;/code&gt;.  Also, while not limited to window management, discoverability via Emacs&amp;rsquo; menu-bar is surprisingly good.
&lt;/small&gt;&lt;/span&gt;
.  Unfortunately, I have to address the rodent in the room before we can talk about mitigating the disadvantages, since Emacs users tend to be very opinionated about mouse usage.&lt;/p&gt;
&lt;p&gt;I never use the mouse in Emacs&amp;hellip; until I&amp;rsquo;m already using the mouse for something else.  Then driving Emacs with the mouse is actually the &lt;a href=&#34;https://karthinks.com/software/different-strokes-for-different-folks/&#34;&gt;path of least resistance&lt;/a&gt;.  If your hand&amp;rsquo;s already off the keyboard, it&amp;rsquo;s pretty easy to drive Emacs with the mouse:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/3G9Nk4p.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/strokes-window-handling.mp4&#34;&gt;[VIDEO: strokes window handling demo]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;This demo showcases the use of mouse gestures to do the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Split the frame vertically and horizontally&lt;/li&gt;
&lt;li&gt;Delete windows&lt;/li&gt;
&lt;li&gt;Cycle through buffers in windows&lt;/li&gt;
&lt;li&gt;Swap windows to the right and left&lt;/li&gt;
&lt;li&gt;Toggle between the last two buffers shown in a window&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;You may want to turn on focus-follows-mouse behavior:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; Consider setting this to a negative number&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;mouse-autoselect-window&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;transpose-frame--rotation-flip-and-flop&#34;&gt;&lt;code&gt;transpose-frame&lt;/code&gt; (rotation, flip and flop)&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/emacsorphanage/transpose-frame&#34;&gt;transpose-frame&lt;/a&gt; offers: easy window layout transformations.&lt;/p&gt;
&lt;p&gt;What it says on the tin: transpose-frame offers commands to rotate or mirror the window layout on the frame.  I found myself using these often enough to bind &lt;code&gt;rotate-frame&lt;/code&gt;, &lt;code&gt;flip-frame&lt;/code&gt; and &lt;code&gt;flop-frame&lt;/code&gt; to suitable keys.  Ironically, the &lt;code&gt;transpose-frame&lt;/code&gt; command itself is rarely useful &amp;ndash; it transposes along the main diagonal of the frame.&lt;/p&gt;
&lt;h4 id=&#34;rotate-frame&#34;&gt;&lt;code&gt;rotate-frame&lt;/code&gt;&lt;/h4&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/rotate-frame-chart.png&#34;/&gt;
&lt;/figure&gt;

&lt;h4 id=&#34;flip-frame&#34;&gt;&lt;code&gt;flip-frame&lt;/code&gt;&lt;/h4&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/flop-frame-chart.png&#34;/&gt;
&lt;/figure&gt;

&lt;h4 id=&#34;flop-frame&#34;&gt;&lt;code&gt;flop-frame&lt;/code&gt;&lt;/h4&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/flip-frame-chart.png&#34;/&gt;
&lt;/figure&gt;

&lt;h3 id=&#34;the-window-prefix-map--built-in&#34;&gt;The &lt;code&gt;window-prefix-map&lt;/code&gt; (built-in)&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;window-prefix-map&lt;/code&gt; offers: Bespoke window management commands&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;window-prefix-map&lt;/code&gt;, bound to &lt;code&gt;C-x w&lt;/code&gt; by default in Emacs, collects a few useful window-management commands:&lt;/p&gt;
&lt;h4 id=&#34;split-root-window-right-and-split-root-window-below&#34;&gt;&lt;code&gt;split-root-window-right&lt;/code&gt; and &lt;code&gt;split-root-window-below&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;Split the root window of the frame.  Better illustrated than explained:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-window-root-frame-split.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;These are bound to &lt;code&gt;C-x w 3&lt;/code&gt; and &lt;code&gt;C-x w 2&lt;/code&gt; respectively.&lt;/p&gt;
&lt;details open&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; The window tree&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;This is a good time to mention that windows in Emacs are arranged in a tree, with all &amp;ldquo;real&amp;rdquo; windows as leaves.  Each splitting action turns a leaf node into a parent of two windows: the window that was split and the new one.  This is very similar to the window arrangement in manual tiling window managers like &lt;code&gt;i3&lt;/code&gt; or &lt;code&gt;bspwm&lt;/code&gt;, leading to a redundancy we &lt;a href=&#34;#the-tiling-wm-integrator&#34;&gt;seek to patch over&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;These are the only built-in Emacs commands, to my knowledge, that allow you to modify the tree structure at a non-leaf level that doesn&amp;rsquo;t just clear the whole tree (as &lt;code&gt;delete-other-windows&lt;/code&gt; does).  Practically speaking, these are often useful to create a space for a logically separate task in the frame &amp;ndash; the default splitting commands only further dice up existing windows.&lt;/p&gt;
&lt;p&gt;Getting to grips with the tree arrangment should make a lot more fine-grained control available, but the tooling isn&amp;rsquo;t there yet &amp;ndash; &lt;a href=&#34;#window-tree&#34;&gt;see below&lt;/a&gt; for a proposal.&lt;/p&gt;
&lt;h4 id=&#34;tab-window-detach-and-tear-off-window&#34;&gt;&lt;code&gt;tab-window-detach&lt;/code&gt; and &lt;code&gt;tear-off-window&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;Handy commands to move a window into a new tab or a new frame.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-window-tear-off.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Like splitting the root window, these are quite handy for logical window management: grab a window and move it into a new tab or frame to start a new task.&lt;/p&gt;
&lt;p&gt;These are bound to &lt;code&gt;C-x w ^ t&lt;/code&gt; and &lt;code&gt;C-x w ^ f&lt;/code&gt;, which &lt;em&gt;sheesh&lt;/em&gt;.  You can do these as ace-window dispatch actions instead, since you can do &lt;em&gt;anything&lt;/em&gt; with ace-window.  Alternatively you can rebind these to the slightly saner &lt;code&gt;C-x w t&lt;/code&gt; and &lt;code&gt;C-x w f&lt;/code&gt;, which are currently unbound.  I prefer to just use the mouse when I need to tear off a window:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; mouse-9 is the &amp;#34;forward&amp;#34; button on my mousee&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-global-set&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-&amp;lt;mouse-9&amp;gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;tear-off-window&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;the-other-window-prefix--built-in&#34;&gt;The &lt;code&gt;other-window-prefix&lt;/code&gt; (built-in)&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;other-window-prefix&lt;/code&gt; offers a method to decouple window selection from buffer display, and solves &lt;strong&gt;three&lt;/strong&gt; window-related annoyances.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Annoyance I&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Many Emacs commands tightly couple a primary action, a buffer and a window.  For example, running &lt;code&gt;find-file&lt;/code&gt; involves selecting a file, creating a buffer and displaying it in the current window.  If you want to decouple the choice of window from the command, you have to pick one of several alternate commands: &lt;code&gt;find-file-other-window&lt;/code&gt;, &lt;code&gt;find-file-other-tab&lt;/code&gt; or &lt;code&gt;find-file-other-frame&lt;/code&gt;, each with its own keybinding.  If you want to open the file in read-only mode, you&amp;rsquo;ve got &lt;code&gt;find-file-read-only&lt;/code&gt;, &lt;code&gt;find-file-read-only-other-window&lt;/code&gt;, &lt;code&gt;find-file-read-only-other-tab&lt;/code&gt; and &lt;code&gt;find-file-read-only-other-frame&lt;/code&gt;.  More keybindings.&lt;/p&gt;
&lt;p&gt;Want the same choices when selecting a buffer?  You&amp;rsquo;ve got &lt;code&gt;switch-to-buffer-⋆&lt;/code&gt;, another constellation of commands.  Opening a bookmark with &lt;code&gt;bookmark-jump&lt;/code&gt;? Pick one of several &lt;code&gt;bookmark-jump-*&lt;/code&gt; commands. This is the road to &lt;em&gt;insanity&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The problem is the coupling: picking a window to display a buffer should be a separable action from the command&amp;rsquo;s primary function: opening a file, in this example.  The solution is to call &lt;code&gt;other-window-prefix&lt;/code&gt;, bound to (&lt;code&gt;C-x 4 4&lt;/code&gt;).  This makes it so that the next command &amp;ndash; &lt;em&gt;any&lt;/em&gt; command that involves displaying a buffer in a window &amp;ndash; is shown in the &lt;a href=&#34;#org-target--window-management-next-window&#34;&gt;next window&lt;/a&gt;, creating one if necessary.  Now you only need &lt;code&gt;find-file&lt;/code&gt;, &lt;code&gt;find-file-read-only&lt;/code&gt; and &lt;code&gt;switch-to-buffer&lt;/code&gt;, and can use the prefix to redirect the resulting buffer to another window when required:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;other-window-prefix&lt;/code&gt; (&lt;code&gt;C-x 4 4&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;find-file&lt;/code&gt;, &lt;code&gt;find-file-read-only&lt;/code&gt;, &lt;code&gt;switch-to-buffer&lt;/code&gt;, &lt;code&gt;bookmark-jump&lt;/code&gt;, or &lt;em&gt;any&lt;/em&gt; command that shows a buffer.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Result&lt;/em&gt;: the buffer is shown in the next window.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In a past write-up I&amp;rsquo;ve &lt;a href=&#34;https://karthinks.com/software/fifteen-ways-to-use-embark/#open-any-buffer-by-splitting-any-window&#34;&gt;mentioned Embark&lt;/a&gt; as &lt;em&gt;the way&lt;/em&gt;.  Indeed, Embark solves this problem more elegantly than the built-in &lt;code&gt;other-window-prefix&lt;/code&gt;.  But avoiding command proliferation is only the first of three problems &lt;code&gt;other-window-prefix&lt;/code&gt; solves.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Annoyance II&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In the above examples, we at least have the choice of calling &lt;code&gt;*command*-other-window&lt;/code&gt; instead of &lt;code&gt;*command*&lt;/code&gt;.  There are just too many options.  More often there are &lt;em&gt;none&lt;/em&gt;, and we&amp;rsquo;re at the mercy of fixed, undesirable behavior.  This is typically the case when activating a link-like object.  In this example (from the &lt;a href=&#34;https://github.com/magit/forge/&#34;&gt;Forge&lt;/a&gt; package), pressing &lt;code&gt;RET&lt;/code&gt; on an issue title opens the issue in the current buffer:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/sKmFQh0.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/other-window-prefix-without.mp4&#34;&gt;[VIDEO: Forge without other-window-prefix]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;This is a list of issues from a code repository, as displayed by the Forge package.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Press &lt;code&gt;RET&lt;/code&gt; on an issue.&lt;/li&gt;
&lt;li&gt;It opens in the current window, denying us &lt;a href=&#34;#the-back-and-forth-method&#34;&gt;the &lt;strong&gt;Listing &amp;amp; Item&lt;/strong&gt; pattern&lt;/a&gt;: a simultaneous view of the full listing and the selected issue.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Forge provides no way, as of this writing, to &amp;ldquo;open a link&amp;rdquo; in another window.  &lt;code&gt;other-window-prefix&lt;/code&gt; to the rescue:
&lt;span class=&#34;org-target&#34; id=&#34;org-target--window-management-forge-video&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/lz32LBD.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/other-window-prefix-with.mp4&#34;&gt;[VIDEO: Forge with other-window-prefix]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;other-window-prefix&lt;/code&gt;, via &lt;code&gt;C-x 4 4&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;RET&lt;/code&gt; on the issue.  It opens in the &amp;ldquo;next window&amp;rdquo; &amp;ndash; there isn&amp;rsquo;t one so a new window is created.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;&lt;strong&gt;Annoyance III&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The third problem it solves is the combination of the first two.  Consider: Magit, the sibling package to Forge, &lt;em&gt;does&lt;/em&gt; provide a way to do this.  It generally opens &amp;ldquo;links&amp;rdquo; in the next window if you use a universal arg (&lt;code&gt;C-u&lt;/code&gt;) before &lt;code&gt;RET&lt;/code&gt;.  Org mode, Notmuch, Elfeed and EWW all provide either no way or mutually distinct ways of opening links in a different window.  If Forge did provide a way, it would actually make things worse in a sense.  With &lt;code&gt;other-window-prefix&lt;/code&gt;, you&amp;rsquo;re blessedly free from having to customize or conform to each package author&amp;rsquo;s idea of how this should work.  Run &lt;code&gt;other-window-prefix&lt;/code&gt;, then activate the &amp;ldquo;link&amp;rdquo; object &amp;ndash; click on it with the mouse if you&amp;rsquo;d like.  It&amp;rsquo;s going to &lt;em&gt;uniformly&lt;/em&gt; open in the next window.&lt;/p&gt;
&lt;p&gt;See also: &lt;code&gt;same-window-prefix&lt;/code&gt; (&lt;code&gt;C-x 4 1&lt;/code&gt;), which forces the next command&amp;rsquo;s buffer (if there is one) to use the current window, and &lt;code&gt;other-frame-prefix&lt;/code&gt; (&lt;code&gt;C-x 5 5&lt;/code&gt;) and &lt;code&gt;other-tab-prefix&lt;/code&gt; (&lt;code&gt;C-x t t&lt;/code&gt;), which open the next command&amp;rsquo;s buffer in a new frame and tab respectively.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; What&amp;rsquo;s with these keybindings?&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;There is a method to the seeming madness of keybindings like &lt;code&gt;C-x 4 4&lt;/code&gt;,  &lt;code&gt;C-x 4 1&lt;/code&gt; and &lt;code&gt;C-x 5 5&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Keybindings involving specific window actions are grouped into prefixes, like a menu. &lt;code&gt;C-x 4&lt;/code&gt;, the &lt;code&gt;ctl-x-4-map&lt;/code&gt; broadly contains commands that use the &lt;code&gt;other-window&lt;/code&gt;.  For instance, &lt;code&gt;C-x 4 .&lt;/code&gt; jumps to the definition of the thing at point (like the default &lt;code&gt;M-.&lt;/code&gt;), but in the &lt;code&gt;other-window&lt;/code&gt;.  Most commands in the &lt;code&gt;ctl-x-5-map&lt;/code&gt; create a new frame.  Tab-bar actions are grouped under &lt;code&gt;C-x t&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The final &amp;ldquo;base&amp;rdquo; key in each map follows a consistent pattern: &lt;code&gt;f&lt;/code&gt; opens files, &lt;code&gt;r&lt;/code&gt; opens things in read-only mode, &lt;code&gt;b&lt;/code&gt; switches to buffers and so on.  The final &lt;code&gt;4&lt;/code&gt;,  &lt;code&gt;5&lt;/code&gt; and &lt;code&gt;t&lt;/code&gt; in &lt;code&gt;C-x 4 4&lt;/code&gt;,  &lt;code&gt;C-x 5 5&lt;/code&gt; and &lt;code&gt;C-x t t&lt;/code&gt; reinforce the idea that the next buffer action is going to be redirected to another window, a new frame and tab respectively.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Further below we take &lt;a href=&#34;#a-window-prefix-command-for-ace-window&#34;&gt;this approach to its logical extreme&lt;/a&gt; with (what else) ace-window, redirecting the next command&amp;rsquo;s buffer to any window, including ones we create just-in-time.&lt;/p&gt;
&lt;h3 id=&#34;saving-and-restoring-window-configurations&#34;&gt;Saving and restoring window configurations&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;window-configuration-to-register&lt;/code&gt; is a bit of a blunt instrument, but perfect as a big red reset button, especially if you&amp;rsquo;re new to Emacs.  At any point, you can save the current window configuration to a register
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
A register is a named bucket that can hold many kinds of data.  Each register is assigned to a character (like &lt;code&gt;a&lt;/code&gt; through &lt;code&gt;z&lt;/code&gt;), and operations on register are available under the &lt;code&gt;C-x r&lt;/code&gt; prefix.
&lt;/small&gt;&lt;/span&gt;
with this command, bound to &lt;code&gt;C-x r w&lt;/code&gt; by default.  After Emacs predictably messes up the frame, you can restore your saved configuration with &lt;code&gt;jump-to-register&lt;/code&gt; (&lt;code&gt;C-x r j&lt;/code&gt;).  That&amp;rsquo;s it.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/lisp-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Persisting window configurations across restarts&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;The elisp version of &lt;code&gt;window-configuration-to-register&lt;/code&gt; is the function &lt;code&gt;current-window-configuration&lt;/code&gt;, whose return value you can bind to a variable, and apply to the frame with &lt;code&gt;set-window-configuration&lt;/code&gt;.  Coupled with a way to persist this lisp object data to disk, such as with &lt;code&gt;prin1&lt;/code&gt; or via a library like &lt;code&gt;persist&lt;/code&gt; or &lt;code&gt;multisession&lt;/code&gt;, we have the seed of a state restoration feature that works across Emacs sessions.  Needless to say, this approach is rudimentary and you&amp;rsquo;re better off using one of the many packages listed above in &lt;a href=&#34;#org-target--window-configuration-persistence&#34;&gt;window configuration persistence&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;One issue with this method is that it restores the window arrangement down to each window&amp;rsquo;s cursor position, which is rarely what you want.&lt;/p&gt;
&lt;p&gt;Another problem is that it requires an unreasonable level of foresight to remember to save window configurations at appropriate times.  If only Emacs could do this automatically for us every time the window configuration changed&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;the-oops-options&#34;&gt;The &amp;ldquo;oops&amp;rdquo; options&lt;/h3&gt;
&lt;p&gt;&amp;hellip;which of course it can.  You can ask Emacs to maintain a stack of your past window arrangements, and cycle through them as you would through changes in a buffer with undo/redo.  You&amp;rsquo;ve got three minor-modes depending on how you use Emacs, and you can turn them on independently.&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;winner-mode&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;If you don&amp;rsquo;t use tabs.  Call &lt;code&gt;winner-undo&lt;/code&gt; and &lt;code&gt;winner-redo&lt;/code&gt; to undo/redo window configuration changes.  It maintains a separate window configuration history for each frame.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;tab-bar-history-mode&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;If you use tabs.  Each tab gets its own history stack.  The relevant commands are &lt;code&gt;tab-bar-history-back&lt;/code&gt; and &lt;code&gt;tab-bar-history-forward&lt;/code&gt;.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;undelete-frame-mode&lt;/code&gt; and &lt;code&gt;tab-undo&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;If you use create and delete frames or tabs all the time.  If you close a frame by accident, you can call &lt;code&gt;undelete-frame&lt;/code&gt;, bound to &lt;code&gt;C-x 5 u&lt;/code&gt;.  Ditto &lt;code&gt;tab-undo&lt;/code&gt;, bound to &lt;code&gt;C-x t u&lt;/code&gt;.&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;These options are handy for going on excursions, such as when you want to maximize the selected window temporarily before reverting to the previous arrangement.&lt;/p&gt;
&lt;p&gt;But &lt;code&gt;winner-mode&lt;/code&gt; &amp;amp; co are also frequently recommended as a band-aid for when &lt;em&gt;Emacs messes up&lt;/em&gt; your careful manual window arrangement, for instance by popping up windows in the wrong places, or resizing your window splits.  I think of this as an antipattern.  If you find yourself using &lt;code&gt;winner-undo&lt;/code&gt; (or equivalent) all the time to fix Emacs&amp;rsquo; behavior, the problem is Emacs displaying buffers in the wrong windows in the first place, a result of frustrating defaults.  See &lt;a href=&#34;#deal-with-windows-so-we-don-t-have-to-deal-with-windows&#34;&gt;the whack-a-mole problem&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;digging-in&#34;&gt;Digging in&lt;/h2&gt;
&lt;p&gt;With our appetite whetted, we can move onto our main course: Tweaks, customization and variations of the above tools that I&amp;rsquo;ve found to work better.&lt;/p&gt;
&lt;p&gt;Emacs can be frustrating on two levels.  It&amp;rsquo;s frustrating at first because you don&amp;rsquo;t know your way around the place, the keybindings and terminology are obtuse, and nothing works the way it does in other software.  Your attempts at mitigating its perceived shortcomings by installing packages leads to mysterious, cryptic errors.  The single-threadedness makes it too easy to accidentally slow things down to a crawl.  The garbage collector fires at the worst times.  Things that should just work, don&amp;rsquo;t.  The perceived shortcomings of Emacs are frustrating: &lt;strong&gt;Window management shouldn&amp;rsquo;t be this complicated!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Over time (years, decades?) you can develop a better mental model of what&amp;rsquo;s happening under the hood: how Emacs&amp;rsquo; event loop works, the anatomy of buffers, windows, keymaps, text properties and overlays &amp;ndash; the data structures Emacs is built on.  Perhaps you even steal some sneaking glances at the lumbering behemoth that is &lt;em&gt;redisplay&lt;/em&gt;.  You&amp;rsquo;re familiar with common Elisp idioms and macros, as well as the common traps.  Now the &lt;em&gt;actual&lt;/em&gt; shortcomings of Emacs&amp;rsquo; API are frustrating: &lt;strong&gt;Window management shouldn&amp;rsquo;t be this complicated!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Oops.&lt;/p&gt;
&lt;p&gt;So here we are.  The rest of this write-up is aimed at someone in between these two kinds of frustration.  It&amp;rsquo;s mostly me throwing out suggestions, many of them mutually exclusive, that might give you ideas of your own to work with windows.  Implementing these ideas will require a little tweaking, copying code verbatim might not give you the results you expect.  For this reason, I suggest coming back here with a little more Emacs mileage if you&amp;rsquo;re new to Emacs.&lt;/p&gt;
&lt;h3 id=&#34;the-back-and-forth-method&#34;&gt;The back-and-forth method&lt;/h3&gt;
&lt;p&gt;Offers: Quick window selection&lt;/p&gt;
&lt;p&gt;An observation: no matter how many simultaneous windows you have or require on screen, most of the time you only need to switch between two of them.  Examples include the &lt;strong&gt;Code &amp;amp; REPL&lt;/strong&gt; setup, the &lt;strong&gt;Code &amp;amp; Grep&lt;/strong&gt; (search results) setup, and the &lt;strong&gt;Prose &amp;amp; Notes&lt;/strong&gt; setup.  The &lt;strong&gt;Listing &amp;amp; Item&lt;/strong&gt; pattern is an example outside of programming or prose: this includes a calendar or agenda window with an expanded entry window, or an email inbox window with an opened email.&lt;/p&gt;
&lt;p&gt;The other windows on screen usually show useful information &amp;ndash; documentation, debugging info, messages, logs or command output, table of contents, a file explorer, document previews &amp;ndash; things you glance at often but switch to rarely.&lt;/p&gt;
&lt;p&gt;Usually major-modes provide semi-consistent keybindings to switch back and forth between two associated windows &amp;ndash; a common example is &lt;code&gt;C-c C-z&lt;/code&gt;, used by several programming modes in Emacs to switch between a code window and an associated REPL
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
This works for Org-babel blocks too via &lt;code&gt;org-babel-switch-to-session&lt;/code&gt;, bound via &lt;code&gt;org-babel-map&lt;/code&gt; to the slightly different &lt;code&gt;C-c C-v C-z&lt;/code&gt;.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;But we can generalize the idea and provide a command to switch between any pair of windows:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/window-back-and-forth.png&#34;/&gt;
&lt;/figure&gt;

&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;other-window-mru&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Select the most recently used window on this frame.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;when-let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;mru-window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;get-mru-window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;not-this-one-dummy&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;select-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;mru-window&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-global-set&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-o&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;other-window-mru&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It doesn&amp;rsquo;t matter how you select the second window for the back-and-forth &amp;ndash; you could use the &lt;a href=&#34;#mousing-around--built-in&#34;&gt;mouse&lt;/a&gt;, &lt;a href=&#34;#ace-window&#34;&gt;ace-window&lt;/a&gt;, &lt;a href=&#34;#winum-mode&#34;&gt;winum&lt;/a&gt; or any other method.  &lt;code&gt;other-window-mru&lt;/code&gt;&amp;rsquo;s got you covered from then on.&lt;/p&gt;
&lt;h3 id=&#34;improving-other-window&#34;&gt;Improving &lt;code&gt;other-window&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;We can retain the basic idea of &lt;code&gt;other-window&lt;/code&gt; &amp;ndash; move between windows in the frame in some cyclic ordering &amp;ndash; but improve the ordering to be more of a DWIM affair
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Do-What-I-Mean
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;other-window&lt;/code&gt; is a simple idea &amp;ndash; the simplest you&amp;rsquo;ll find in this write-up &amp;ndash; but you can play around with the order in which windows are selected to better fit how you work.&lt;/p&gt;
&lt;h4 id=&#34;double-duty&#34;&gt;Double duty&lt;/h4&gt;
&lt;p&gt;First, you could make &lt;code&gt;other-window&lt;/code&gt; split the frame when there&amp;rsquo;s only one window, giving the command a use when it has none.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;advice-add&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;other-window&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:before&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;other-window-split-if-single&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Split the frame if there is a single window.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;one-window-p&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;split-window-sensibly&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;switchy-window&#34;&gt;&lt;code&gt;switchy-window&lt;/code&gt;&lt;/h4&gt;
&lt;figure class=&#34;alignright&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/switchy-window-order.png&#34; width=&#34;300px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Another modification that you might find intuitive is to cycle through windows in order of last use instead of in clockwise spatial order, similar to alt-tab or how some web browsers cycle through tabs.  This is possible with some elbow grease, but this work has been done for us by the &lt;a href=&#34;https://elpa.gnu.org/packages/switchy-window.html&#34;&gt;switchy-window&lt;/a&gt; package, which provides a &lt;code&gt;switchy-window&lt;/code&gt; substitute command for &lt;code&gt;other-window&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When cycling through windows, switchy-window waits for a window to stay selected for a couple of seconds before marking it as used and updating the recency list.  In practice this works quite seamlessly &amp;ndash; calling &lt;code&gt;switchy-window&lt;/code&gt; moves you to to where you need to be most of the time.&lt;/p&gt;
&lt;p&gt;That said, I usually prefer the simpler variant described in &lt;a href=&#34;#the-back-and-forth-method&#34;&gt;the back-and-forth method&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&#34;other-window-alternating&#34;&gt;&lt;code&gt;other-window-alternating&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;And speaking of back-and-forth, here&amp;rsquo;s another &lt;code&gt;other-window&lt;/code&gt; variant &amp;ndash; it might sound confusing at first, but turns out to be a pleasingly DWIM affair.  Except when chaining &lt;code&gt;other-window&lt;/code&gt;, reverse the window-switching direction after each call.  With just two windows, this makes no difference.  With more, this makes alternating between two windows natural, even when the windows are not adjacent in the cyclic ordering.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defalias&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;other-window-alternating&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;direction&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Call &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`other-window&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;, switching directions each time.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;equal&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;last-command&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;other-window-alternating&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#963&#34;&gt;other-window&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;direction&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;direction&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;direction&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;other-window&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;direction&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;)))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-global-set&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-o&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;other-window-alternating&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; repeat-mode integration&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;put&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;other-window-alternating&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;repeat-map&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;other-window-repeat-map&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-set&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;other-window-repeat-map&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;o&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;other-window-alternating&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;window-magic-with-ace-window-dispatch&#34;&gt;Window magic with &lt;code&gt;ace-window&lt;/code&gt; dispatch&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;ace-window&lt;/code&gt; is to windows what &lt;code&gt;completing-read&lt;/code&gt; is to lists of strings, or Avy to characters on screen.  This makes it ideal as the first two of a three-step process to invoke &lt;em&gt;any&lt;/em&gt; action on &lt;em&gt;any&lt;/em&gt; window: the &lt;span class=&#34;Purple&#34;&gt;filter&lt;/span&gt; and &lt;span class=&#34;Orange&#34;&gt;selection&lt;/span&gt; steps:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-window-selection-pattern.png&#34;/&gt;
&lt;/figure&gt;

&lt;h4 id=&#34;aw-select-the-completing-read-for-emacs-windows&#34;&gt;&lt;code&gt;aw-select&lt;/code&gt;, the &lt;code&gt;completing-read&lt;/code&gt; for Emacs windows&lt;/h4&gt;
&lt;p&gt;The way ace-window is designed to be extended is by defining an &amp;ldquo;ace-window action&amp;rdquo; and adding a binding for it in &lt;code&gt;aw-dispatch-alist&lt;/code&gt;
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
It ships with several predefined actions, captured in &lt;a href=&#34;#org-target--ace-window-default-actions&#34;&gt;this schematic above&lt;/a&gt;.
&lt;/small&gt;&lt;/span&gt;
.  This function accepts a window and does something useful with it.  The &lt;code&gt;ace-window&lt;/code&gt; command acts as the entry point:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-window-selection-via-ace.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;This control flow is generally similar to how Avy works.  But as a &lt;code&gt;completing-read&lt;/code&gt; alternative, this is somewhat lacking &amp;ndash; we&amp;rsquo;d like to flip the pattern around and use &lt;code&gt;ace-window&lt;/code&gt;&amp;rsquo;s selection method in &lt;em&gt;our&lt;/em&gt; commands.  Conveniently, &lt;code&gt;aw-select&lt;/code&gt; does exactly that.&lt;/p&gt;
&lt;figure class=&#34;alignright&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-window-selection-ace-inside.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;The basic pattern is very simple: the call &lt;code&gt;(aw-select nil)&lt;/code&gt;
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
The argument to &lt;code&gt;aw-select&lt;/code&gt; is for adding a message to the mode-line during the selection process, we don&amp;rsquo;t bother with that.
&lt;/small&gt;&lt;/span&gt;
returns the window we select, which we can use for our task.  One example of such a task is to &lt;a href=&#34;#scroll-other-window--built-in&#34;&gt;set the window&lt;/a&gt; that &lt;code&gt;scroll-other-window&lt;/code&gt; should scroll.  Here are a couple more, but don&amp;rsquo;t try them just yet!  We&amp;rsquo;re going to generalize the idea a little further below.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;tear-off-window&lt;/code&gt; or &lt;code&gt;tab-window-detach&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Every interactive window command in Emacs acts on the current window.  Here we make a couple of commands in the &lt;a href=&#34;#the-window-prefix-map--built-in&#34;&gt;&lt;code&gt;window-prefix-map&lt;/code&gt; (&lt;code&gt;C-x w&lt;/code&gt;)&lt;/a&gt; something you can apply interactively to any window.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ace-tear-off-window&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Select a window with ace-window and tear it off the frame.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;This displays the window in a new frame, see &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`tear-off-window&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;when-let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;aw-select&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; ACE&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;window-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#963&#34;&gt;frame&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;make-frame&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;select-frame&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;frame&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;pop-to-buffer-same-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;delete-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ace-tab-window-detach&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Select a window with ace-window and move it to a new tab.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;when-let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;aw-select&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; ACE&amp;#34;&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;with-selected-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;tab-window-detach&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Of course, defining one ace-window-based command for each action isn&amp;rsquo;t a scalable or useful way to go about this.  It would be preferable to decouple the window selection step from the action step and generalize the latter.  We explore two distinct approaches to do this, starting with&amp;hellip;&lt;/p&gt;
&lt;h4 id=&#34;ace-window-one-command-any-command-with-ace-window&#34;&gt;&lt;code&gt;ace-window-one-command&lt;/code&gt;: Any command with ace-window&lt;/h4&gt;
&lt;p&gt;Generalizing the above examples gives us a pretty good idea of what the flipped &lt;code&gt;ace-window&lt;/code&gt; pattern should look like.  The most general and composable version would be the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;aw-select&lt;/code&gt; to pick a window (the &lt;code&gt;completing-read&lt;/code&gt; step)&lt;/li&gt;
&lt;li&gt;Run any action in this window&lt;/li&gt;
&lt;li&gt;Switch back to the original window.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We can do this by simulating Emacs&amp;rsquo; event loop, but in the chosen window: Switch windows, then read any key sequence and execute it before switching back.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ace-window-one-command&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;aw-select&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; ACE&amp;#34;&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;windowp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;with-selected-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;command&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;key-binding&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;read-key-sequence&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                          (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;format&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Run in %s...&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-name&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#963&#34;&gt;this-command&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;command&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;call-interactively&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;command&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-global-set&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;C-x O&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;ace-window-one-command&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In a demo, this looks the same as &lt;code&gt;ace-window&lt;/code&gt;, except that you select the window before executing the action.  The win here is the action: it works with &lt;em&gt;any&lt;/em&gt; simple command, there is no need to pre-configure actions in &lt;code&gt;aw-dispatch-alist&lt;/code&gt;.  There&amp;rsquo;s nothing to set up or memorize.  In this demo I use &lt;code&gt;ace-window-run-command&lt;/code&gt; to shrink an unselected window with &lt;code&gt;C-x -&lt;/code&gt; (the descriptively named &lt;code&gt;shrink-window-if-larger-than-buffer&lt;/code&gt;)&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/ov2rxst.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/ace-window-one-command-demo.mp4&#34;&gt;[VIDEO: ace-window-one-command demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Pulse the line to show which window is active.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;ace-window-one-action&lt;/code&gt; and select the Occur buffer to the top left.  Emacs waits for you to execute any single command.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;shrink-window-if-larger-than-buffer&lt;/code&gt;, using &lt;code&gt;C-x -&lt;/code&gt;.  This shrinks the Occur buffer, our cursor position and window is unchanged.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;&lt;code&gt;ace-window-one-command&lt;/code&gt; is a convenient way to quickly run any command in a different window, an idea we explore in &lt;a href=&#34;#switch-and-return-actions-in-other-windows&#34;&gt;more detail below&lt;/a&gt;.&lt;/p&gt;
&lt;details class=&#34;implementation&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Embark much?&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;This reversal of Emacs&amp;rsquo; (and ace-window&amp;rsquo;s) usual paradigm of &lt;span class=&#34;Green&#34;&gt;action&lt;/span&gt; → &lt;span class=&#34;Orange&#34;&gt;selection&lt;/span&gt; is at the heart of Embark, as covered in my write-up on &lt;a href=&#34;https://karthinks.com/software/fifteen-ways-to-use-embark/&#34;&gt;ways to use Embark&lt;/a&gt;.  Of course, this &amp;ldquo;object-first&amp;rdquo; approach is only one way to look at it &amp;ndash; Embark has many hearts.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h4 id=&#34;a-window-prefix-command-for-ace-window&#34;&gt;A window-prefix command for &lt;code&gt;ace-window&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;Handy as it is, the &lt;a href=&#34;#the-other-window-prefix--built-in&#34;&gt;&lt;code&gt;other-window-prefix&lt;/code&gt; system&lt;/a&gt; has the same problem as the &lt;code&gt;other-window&lt;/code&gt; command: it enforces a rigid cyclic ordering on the window it will pick, and about the most we can consistently expect is that the active window will not be taken over by the next command.  We can do better.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;aw-select&lt;/code&gt; gives us a bespoke solution with more control: we select the window that should be used if the next command involves displaying a buffer in a window.  In this example, we explicitly pick a window to show a man page in, since the &amp;ldquo;next window&amp;rdquo; is not where we want it:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/2dHJZAP.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/ace-window-prefix-demo-alt.mp4&#34;&gt;[VIDEO ace-window-prefix Man demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Pulse the line to indicate the active window (lower left)&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;ace-window-dispatch&lt;/code&gt; (&lt;code&gt;C-x 4 o&lt;/code&gt;), then &lt;code&gt;M-x man&lt;/code&gt; and choose &lt;code&gt;curl(1)&lt;/code&gt;.  Emacs waits for us to pick a window.&lt;/li&gt;
&lt;li&gt;Pick the window on the right with &amp;ldquo;e&amp;rdquo;.  The Man page is displayed in that window.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note that the Man elisp library actually offers a suite of options to customize where it should be displayed, in the fiddly way typical of all things Emacs.  We can sidestep that whole undertaking here.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Here&amp;rsquo;s the &lt;a href=&#34;#org-target--window-management-forge-video&#34;&gt;example from above&lt;/a&gt; of viewing a Forge link in a busy frame with many windows.  We compare the result of using &lt;code&gt;other-window-prefix&lt;/code&gt;, where a random window is chosen, to using &lt;code&gt;ace-window-prefix&lt;/code&gt;, where we can pick a specific window:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/BBa6AJu.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/ace-window-prefix-demo.mp4&#34;&gt;[VIDEO ace-window-prefix Forge demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;In this frame, the window &amp;ldquo;next&amp;rdquo; to the Forge topics window (the bottome one) is the one window at the top left.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Move down to the last listed topic and pulse the line (so you can find the active window)&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;other-window-prefix&lt;/code&gt; (&lt;code&gt;C-x 4 4&lt;/code&gt;) and press &lt;code&gt;RET&lt;/code&gt; on the &amp;ldquo;link&amp;rdquo;.  It opens in the top left window, not where we&amp;rsquo;d like to see it.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;tab-bar-history-back&lt;/code&gt; to restore the previous window configuration.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;ace-window-prefix&lt;/code&gt; (&lt;code&gt;C-x 4 o&lt;/code&gt;) instead, and press &lt;code&gt;RET&lt;/code&gt;.  Emacs waits for us to pick a window to show the resulting buffer in.&lt;/li&gt;
&lt;li&gt;Pick the window on the right with &amp;ldquo;r&amp;rdquo;.  Forge shows the link contents in that window.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;&lt;code&gt;ace-window&lt;/code&gt; works across visible frames, so we can pick any Emacs window on our screen.  Even better, we can use &lt;code&gt;ace-window&lt;/code&gt; actions to create new windows on the fly and use them instead.  Here I use an &lt;code&gt;ace-window&lt;/code&gt; action to create a new window to be used by the next command:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/DFNqQyC.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/ace-window-prefix-demo-2.mp4&#34;&gt;[VIDEO: ace-window-prefix demo 2]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Normally, activating an Org mode link opens it in the current window or the next one, depending on your Org settings.  We want something different.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Press &lt;code&gt;RET&lt;/code&gt; on the link to open the image in the next window.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;q&lt;/code&gt; to quit and return to the Org buffer.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;ace-window-prefix&lt;/code&gt; and press &lt;code&gt;RET&lt;/code&gt; on the link.  Emacs waits for us to pick a window to show the linked file in.&lt;/li&gt;
&lt;li&gt;Use an &lt;code&gt;ace-window&lt;/code&gt; action to split a window and select the split.  The action now finishes and the linked image is shown in that window.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;The implementation of &lt;code&gt;ace-window-prefix&lt;/code&gt; is actually simpler than &lt;code&gt;other-window-prefix&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ace-window-prefix&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Use &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`ace-window&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; to display the buffer of the next command.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;The next buffer is the buffer displayed by the next command invoked
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;immediately after this command (ignoring reading from the minibuffer).
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;Creates a new window before displaying the buffer.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;When &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`switch-to-buffer-obey-display-actions&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; is non-nil,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`switch-to-buffer&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; commands are also supported.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;display-buffer-override-next-command&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;type&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#963&#34;&gt;window&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;aw-select&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;propertize&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; ACE&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;face&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;mode-line-highlight&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#963&#34;&gt;type&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;reuse&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cons&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;type&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;[ace-window]&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;message&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Use &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`ace-window&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; to display next command buffer...&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In keeping with the keybinding pattern for the &lt;code&gt;⋆-window-prefix&lt;/code&gt; commands, we bind it to &lt;code&gt;C-x 4 o&lt;/code&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-global-set&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;C-x 4 o&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;ace-window-prefix&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;do-you-need-to-switch-windows&#34;&gt;&lt;em&gt;Do&lt;/em&gt; you need to switch windows?&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s pause for a moment to ask a basic question:  &lt;em&gt;why&lt;/em&gt; do you need to switch windows in the first place?  A little reductive thinking distills the answer down to two &amp;ndash; and only two &amp;ndash; possibilities:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Switch and stay&lt;/strong&gt;: To work persistently in the destination window, for some measure of &amp;ldquo;work&amp;rdquo;: this covers text editing in all its forms.  In this event the window we switch to becomes our primary work area.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Switch and return&lt;/strong&gt;: To interact with the window or its contents briefly.  Perhaps we want to scroll through, or copy some text before moving back, or to delete the window.  In this event the window is a temporary destination, for auxiliary purposes.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In either case, switching windows is a cost, not our objective.  Ideally this should happen automatically as part of our editing process.  So why not just &amp;ldquo;fold&amp;rdquo; this little chore into our primary editing action?&lt;/p&gt;
&lt;h3 id=&#34;switch-and-stay-avy-as-a-window-switcher&#34;&gt;Switch and stay: Avy as a window switcher&lt;/h3&gt;
&lt;p&gt;Eventually any kind of navigation in Emacs &lt;a href=&#34;https://karthinks.com/software/avy-can-do-anything/&#34;&gt;comes down to Avy&lt;/a&gt;.  If you are switching windows to edit (or select) text, you intend to move to a specific point on the screen.  Getting the cursor there is a two step process: switch windows, move the cursor to the right location.  Avy short-circuits this process into a single action.  It treats the frame as a single pool of jump locations: in helping you jump to any character(s) on the screen, it moves you across windows seamlessly:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/6DP2Rnx.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-basic-demo.mp4&#34;&gt;[VIDEO: Jumping with Avy]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;se&amp;rdquo;. This shows hints for all matches with &amp;ldquo;se&amp;rdquo;, including &amp;ldquo;sentence&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Type in the hint char corresponding to &amp;ldquo;sentence&amp;rdquo;, which is &lt;code&gt;g&lt;/code&gt; here.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;With a slight mental shift you can stop thinking of windows as distinct objects entirely, at least for the purposes of navigation.  Any character(s) &amp;ndash; across all visible Emacs windows and frames &amp;ndash; is a couple of keypresses away.  And it&amp;rsquo;s not the only way to jump across windows: you can jump back to your starting point (switching windows in the process) with &lt;code&gt;pop-global-mark&lt;/code&gt;, for instance:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/W4uUzso.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-jump-back-demo-2.mp4&#34;&gt;[VIDEO: Jumping with Avy and pop-global-mark]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;demo&amp;rdquo;. There is only one candidate for this string, so Avy jumps to the other window.&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;jump&amp;rdquo;. This shows hints for all matches with &amp;ldquo;jump&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Pick one of the matches. Avy jumps again, this time to the third window.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;pop-global-mark&lt;/code&gt; (&lt;code&gt;C-x C-SPC&lt;/code&gt;) to jump back to the previous location. (&lt;a href=&#34;#org-target--pop-global-mark-advice&#34;&gt;Details below&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;pop-global-mark&lt;/code&gt; (&lt;code&gt;C-x C-SPC&lt;/code&gt;) again to jump back to the previous location.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Making Avy window-agnostic&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;If Avy does not move you across windows and frames, you probably need to customize &lt;code&gt;avy-all-windows&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;While we&amp;rsquo;re here, consider customizing &lt;code&gt;avy-style&lt;/code&gt;, there&amp;rsquo;s more than one way to jump with Avy!&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Of course, this only scratches the surface of what you can do with Avy, but that&amp;rsquo;s well tread ground at this point.&lt;/p&gt;
&lt;h3 id=&#34;switch-and-return-actions-in-other-windows&#34;&gt;Switch and return: Actions in other windows&lt;/h3&gt;
&lt;p&gt;And here&amp;rsquo;s the other case.  Often the reason you switch windows is to run a single logical action &amp;ndash; perhaps a compound action like isearching to focus the view somewhere, before switching back to your main buffer.  This is the switch → act → switch-back dance.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;re going to automate this dance away in steps, working through solutions obvious and specific, through to repeatable and general, ending at the abstract and generic.&lt;/p&gt;
&lt;p&gt;The obvious first: if you find yourself performing this dance repeatedly, you can automate it with a keyboard macro (left as an exercise for the reader).  If the action is something you do all the time, you can go a step further and write a general-purpose command. &lt;a href=&#34;#ace-window-one-command-any-command-with-ace-window&#34;&gt;&lt;code&gt;ace-window-one-command&lt;/code&gt; above&lt;/a&gt; would be one way to do it.  Emacs paves the way for us with&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;scroll-other-window--built-in&#34;&gt;&lt;code&gt;scroll-other-window&lt;/code&gt; (built-in)&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;scroll-other-window&lt;/code&gt; and &lt;code&gt;scroll-other-window-down&lt;/code&gt; have been part of Emacs for ages, perhaps because it fits neatly into the two-window paradigm that Emacs&amp;rsquo; default settings are suited for: editing in one window while using the contents of the other one as a reference.  You can scroll up and down in the other window without leaving this one.  Note that this works with any number of windows: the window that is scrolled is the &amp;ldquo;&lt;a href=&#34;#other-window-and-the-next-window--built-in&#34;&gt;next window&lt;/a&gt;&amp;rdquo;, clockwise from the current one.  In this schematic, the selected window is the one with the border, the one that &lt;code&gt;scroll-other-window&lt;/code&gt; scrolls is the one with the arrows:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/scroll-other-window.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;With more than two windows this requires careful placement of windows to work as expected.  For instance, you cannot have three side-by-side buffers (1-3 above) and use 1 as a reference when working in both 2 and 3, since &lt;code&gt;scroll-other-window&lt;/code&gt; in 2 will scroll 3.  Thankfully, we can specify the rule by which to select the window for scrolling.  One option is&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;other-window-scroll-default&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;get-lru-window&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;which will always scroll the least-recently-used window, since you won&amp;rsquo;t be wading into buffer 1 &amp;ndash; the reference &amp;ndash; often.  Alternatively, you might want &lt;code&gt;scroll-other-window&lt;/code&gt; in buffers 2 and 3 to scroll each other as you switch between them and ignore buffer 1.  You&amp;rsquo;d then use the most-recently-used window:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;other-window-scroll-default&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;get-mru-window&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;not-this-one-dummy&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;next-window&lt;/span&gt;)               &lt;span style=&#34;color:#888&#34;&gt;;fall back to next window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;next-window&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;visible&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This works great with &lt;a href=&#34;#the-back-and-forth-method&#34;&gt;The back-and-forth method&lt;/a&gt;.&lt;/p&gt;
&lt;details class=&#34;details implementation&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/lisp-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Setting the window to scroll&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;There is another way to change the window that is scrolled instead: by setting a variable (&lt;code&gt;other-window-scroll-buffer&lt;/code&gt;), you can specify the buffer whose window should be scrolled instead of the next window.  But this is mostly an option for package authors.  To do it on the fly, we&amp;rsquo;d need to write another elisp command, something like&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ace-set-other-window&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Select a window with ace-window and set it as the \&amp;#34;other
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;window\&amp;#34; for the current one.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;when-let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;aw-select&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; ACE&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;window-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;setq-local&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;other-window-scroll-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is only useful if we want this association to be persistent.  Otherwise the LRU/MRU method does what we need most of the time.  See also &lt;a href=&#34;#master-mode-and-scroll-all-mode&#34;&gt;master-mode&lt;/a&gt; below.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details class=&#34;details apinote&#34; open&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Scrolling other windows: minutiae&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;The viability of the default bindings for &lt;code&gt;scroll-other-window&lt;/code&gt; (&lt;code&gt;C-M-v&lt;/code&gt; and &lt;code&gt;C-M-S-v&lt;/code&gt;) depends on your tolerance for modifiers.  A good candidate for remapping, especially if you use a modal input method.  &lt;code&gt;C-M-v&lt;/code&gt; can be invoked as &lt;code&gt;ESC C-v&lt;/code&gt; already, I bind the other one to &lt;code&gt;ESC M-v&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;scroll-other-window&lt;/code&gt; works from the minibuffer too.  The window scrolled is usually the one that the minibuffer-using command was invoked from, and can be set explicitly as the value of &lt;code&gt;minibuffer-scroll-window&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;From Emacs 29 onwards, &lt;code&gt;scroll-other-window&lt;/code&gt; is better at handling non-text buffers like PDFs, where scrolling is handled by special functions.  It now calls whatever the standard scrolling commands (&lt;code&gt;scroll-up-command&lt;/code&gt; and &lt;code&gt;scroll-down-command&lt;/code&gt;) are bound to.  To scroll PDF buffers managed by the pdf-tools package in the &amp;ldquo;next window&amp;rdquo; position, for instance:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#007020&#34;&gt;with-eval-after-load&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;pdf-tools&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#963&#34;&gt;keymap-set&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pdf-view-mode-map&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;remap&amp;gt; &amp;lt;scroll-up-command&amp;gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;pdf-view-scroll-up-or-next-page&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#963&#34;&gt;keymap-set&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pdf-view-mode-map&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;remap&amp;gt; &amp;lt;scroll-down-command&amp;gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;pdf-view-scroll-down-or-previous-page&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Another example: after rebinding the regular paging commands via &lt;code&gt;pixel-scroll-precision-mode&lt;/code&gt;, &lt;code&gt;scroll-other-window&lt;/code&gt; will smooth-scroll the other window:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;600&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/24MKcsv.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/scroll-other-window-precision-demo.mp4&#34;&gt;[VIDEO: smooth-scrolling with scroll-other-window]&lt;/a&gt;&lt;/video&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;isearch-other-window&#34;&gt;&lt;code&gt;isearch-other-window&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Continuing with the idea of using a buffer in another window as a reference, a straightforward extension of &lt;code&gt;scroll-other-window&lt;/code&gt; is to search the &amp;ldquo;next window&amp;rdquo; instead
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
&lt;code&gt;isearch&lt;/code&gt; is a fantastic navigational tool.
&lt;/small&gt;&lt;/span&gt;
.  We make sure to search in the same window that we&amp;rsquo;ve configured to scroll with &lt;code&gt;scroll-other-window&lt;/code&gt; above.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;isearch-other-window&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;regexp-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Function to isearch-forward in the next window.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;With prefix arg REGEXP-P, perform a regular expression search.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;unless&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;one-window-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;with-selected-window&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;other-window-for-scrolling&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;isearch-forward&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;regexp-p&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-global-set&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;C-M-s&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;isearch-other-window&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The function &lt;code&gt;other-window-for-scrolling&lt;/code&gt; returns a suitable window, respecting our choice of &lt;code&gt;other-window-scroll-default&lt;/code&gt; above.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s an example of using &lt;code&gt;isearch-other-window&lt;/code&gt; to work in a shell and a documentation (Man) buffer together:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/5BDYIsk.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/isearch-other-window-demo.mp4&#34;&gt;[VIDEO: isearch-other-window demo]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Type in a partial Curl command&lt;/li&gt;
&lt;li&gt;Invoke &lt;code&gt;isearch-other-window&lt;/code&gt; (&lt;code&gt;C-M-s&lt;/code&gt; here), which starts searching the Man buffer&lt;/li&gt;
&lt;li&gt;Search for &lt;code&gt;--ssl revoke&lt;/code&gt;, which finds the option we&amp;rsquo;re looking for.  (This special matching behavior is from setting &lt;code&gt;isearch-whitespace-regexp&lt;/code&gt;.)&lt;/li&gt;
&lt;li&gt;Pressing &lt;code&gt;RET&lt;/code&gt; ends isearch and we&amp;rsquo;re back in the shell.&lt;/li&gt;
&lt;li&gt;Scroll the other window with &lt;code&gt;scroll-other-window&lt;/code&gt;, then use &lt;code&gt;hippie-expand&lt;/code&gt; to type in the argument we want.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;The keybinding &lt;code&gt;C-M-s&lt;/code&gt; is already bound to &lt;code&gt;isearch-forward-regexp&lt;/code&gt;, but there are many other ways to call that command: via a prefix arg to &lt;code&gt;isearch-forward&lt;/code&gt; (&lt;code&gt;C-u C-s&lt;/code&gt;), or by toggling regexp search with &lt;code&gt;M-r&lt;/code&gt; when isearching, for instance.&lt;/p&gt;
&lt;details class=&#34;details implementation&#34;&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/lisp-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Performing actions in other windows&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;There are two simple ways to temporarily switch to another window in elisp: &lt;code&gt;(save-window-excursion (select-window somewin) ...)&lt;/code&gt; and &lt;code&gt;(with-selected-window somewin ...)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;For our purposes, the difference between them is that the former restores the window configuration at the time it was executed, which includes the buffer positions relative to the windows and the values of &lt;code&gt;(point)&lt;/code&gt; in the buffer.  The latter persists changes across the frame, and is typically what we want.  If the changes were not persistent, there would be no point to this exercise!&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;switch-buffers-in-the-next-window-dot&#34;&gt;Switch buffers in the next window.&lt;/h3&gt;
&lt;p&gt;You can have hundreds of buffers in Emacs but only a handful of windows.  This is, in fact, the source of the window management problem.  So any comprehensive solution has to involve changing buffers shown in existing windows.  The ace-window &lt;a href=&#34;#ace-window&#34;&gt;dispatch system&lt;/a&gt; is one solution.  But the built-in &lt;code&gt;next-buffer&lt;/code&gt; and &lt;code&gt;previous-buffer&lt;/code&gt; commands offer another easy 80% solution to changing buffers shown in other windows: we just automate away the window switching dance.  We don&amp;rsquo;t need a dedicated &lt;code&gt;next-buffer-other-window&lt;/code&gt; command for this &amp;ndash; we can just replace &lt;code&gt;next-buffer&lt;/code&gt; with the new function.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/next-buffer&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Switch to the next ARGth buffer.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;With a universal prefix arg, run in the next window.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;if-let&lt;/span&gt; (((&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;equal&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;4&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;other-window-for-scrolling&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;with-selected-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;next-buffer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prefix-arg&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;current-prefix-arg&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;next-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/previous-buffer&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Switch to the previous ARGth buffer.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;With a universal prefix arg, run in the next window.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;if-let&lt;/span&gt; (((&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;equal&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;4&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;other-window-for-scrolling&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;with-selected-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;previous-buffer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prefix-arg&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;current-prefix-arg&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;previous-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And we can take over &lt;code&gt;next-buffer&lt;/code&gt; and &lt;code&gt;previous-buffer&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-global-set&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;remap&amp;gt; &amp;lt;next-buffer&amp;gt;&amp;#34;&lt;/span&gt;     &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;my/next-buffer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-global-set&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;remap&amp;gt; &amp;lt;previous-buffer&amp;gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;my/previous-buffer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Finally, we define a fallback version of &lt;code&gt;switch-to-buffer&lt;/code&gt; and shove all of these into a repeat-map so we can call them consecutively with &lt;code&gt;n&lt;/code&gt;, &lt;code&gt;p&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; switch-to-buffer, but possibly in the next window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/switch-buffer&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;run-at-time&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#963&#34;&gt;if-let&lt;/span&gt; (((&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;equal&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;4&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;other-window-for-scrolling&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#007020&#34;&gt;with-selected-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;switch-to-buffer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#963&#34;&gt;read-buffer-to-switch&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;format&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Switch to buffer (%S)&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;call-interactively&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;switch-to-buffer&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;defvar-keymap&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;buffer-cycle-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:doc&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Keymap for cycling through buffers, intended for &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`repeat-mode&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:repeat&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;n&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;my/next-buffer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;p&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;my/previous-buffer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;b&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;my/switch-buffer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The result of this keymap gymnastics, with key descriptions in the top right:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/kfZiyqZ.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/next-buffer-with-repeat.mp4&#34;&gt;[VIDEO: next-buffer with repeat]&lt;/a&gt;&lt;/video&gt;
&lt;details open&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;Call &lt;code&gt;my/next-buffer&lt;/code&gt; or &lt;code&gt;my/previous-buffer&lt;/code&gt; (I&amp;rsquo;ve bound them to &lt;code&gt;C-x C-n&lt;/code&gt; and &lt;code&gt;C-x C-p&lt;/code&gt; instead of remapping the default &lt;code&gt;next-buffer&lt;/code&gt; binding &lt;code&gt;C-x &amp;lt;right&amp;gt;&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;This activates the repeat-map &lt;code&gt;buffer-cycle-map&lt;/code&gt;, so I can continue cycling through buffers with &lt;code&gt;n&lt;/code&gt; and &lt;code&gt;p&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Exit the repeat-map by pressing any other key.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;my/next-buffer&lt;/code&gt; with a prefix argument (&lt;code&gt;C-u C-x C-n&lt;/code&gt;).  This activates the &lt;code&gt;buffer-cycle-map&lt;/code&gt;, but in the &lt;em&gt;other&lt;/em&gt; window, so you can cycle buffers in the other window with &lt;code&gt;n&lt;/code&gt; and &lt;code&gt;p&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Pressing &lt;code&gt;b&lt;/code&gt; when the repeat map is active calls &lt;code&gt;switch-to-buffer&lt;/code&gt; in the window that is selected.  This is a fallback when the buffer you need is not one or two away in the window&amp;rsquo;s buffer history.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Using &lt;code&gt;b&lt;/code&gt; to display a buffer in another window is consistent with how &lt;code&gt;ace-window&lt;/code&gt;&amp;rsquo;s dispatch version works.&lt;/p&gt;
&lt;h3 id=&#34;master-mode-and-scroll-all-mode&#34;&gt;&lt;code&gt;master-mode&lt;/code&gt; and &lt;code&gt;scroll-all-mode&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;A passing note: Emacs provides &lt;code&gt;master-mode&lt;/code&gt;, a bespoke solution for performing actions in other windows without leaving this one.  You can designate a buffer as the &amp;ldquo;slave&amp;rdquo; buffer of the current buffer (the &amp;ldquo;master&amp;rdquo;).  This opens up a keymap for scrolling the slave buffer without leaving the current one.  By itself, this is a worse alternative to the more transparent and immediate solutions involving &lt;code&gt;other-window-scroll-default&lt;/code&gt; above.  But you can add to this keymap with the plumbing command &lt;code&gt;master-says&lt;/code&gt;, which helps you set up keys to do predefined actions in the slave buffer.  This built-in action, for example, recenters the slave buffer:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;master-says-recenter&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Recenter the slave buffer.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;See &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`recenter&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;master-says&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;recenter&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But this can be &lt;em&gt;any&lt;/em&gt; action: you could set a shell or compilation buffer as the slave buffer of every project buffer, and use &lt;code&gt;master-mode&lt;/code&gt; to page through them, copy the latest output, send commands and so on.&lt;/p&gt;
&lt;p&gt;And while we&amp;rsquo;re focused on scrolling, &lt;code&gt;scroll-all-mode&lt;/code&gt; is a simple way of tying together scroll actions in all windows on the frame.  On occasions where you want to keep two more more window views in sync, this is a handier method than scrolling the active window and then the other window.&lt;/p&gt;
&lt;h3 id=&#34;with-other-window-an-elisp-helper&#34;&gt;&lt;code&gt;with-other-window&lt;/code&gt;: An elisp helper&lt;/h3&gt;
&lt;p&gt;What&amp;rsquo;s better than writing a general-purpose command to automate one switch → act → switch-back dance?  A general-purpose macro to automate writing the general-purpose command!  We can decouple the action from the switching with a macro:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defmacro&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;with-other-window&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;body&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Execute forms in BODY in the other-window.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;unless&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;one-window-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;with-selected-window&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;other-window-for-scrolling&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#333&#34;&gt;,@&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;body&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The above examples become straightforward applications of this macro&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;isearch-other-window&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;regexp-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;with-other-window&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;isearch-forward&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;regexp-p&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;isearch-other-window-backwards&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;regexp-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;with-other-window&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;isearch-backward&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;regexp-p&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is the elisp counterpart to the interactive &lt;code&gt;ace-window-one-command&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;do-you-need-many-windows&#34;&gt;Do you &lt;em&gt;need&lt;/em&gt; many windows?&lt;/h2&gt;
&lt;p&gt;The world seems to have converged on a single UI for editors: one main window, a tab bar at the top (with one window per tab), a directory or contents sidebar on the left, an optional doodad on the right, and a terminal emulator below.&lt;/p&gt;
&lt;figure class=&#34;wide&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/modern-editor-layouts.jpeg&#34;
         alt=&#34;Modern text and code editor window layouts.  Clockwise from top left -- Zed, Neovim, Obsidian, VSCode.&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Every editor got the memo&amp;hellip; except Emacs, it appears.  You could recreate this window layout and workflow in Emacs.  Or any other, for that matter.  But all this furious window management behooves us to ask an even more basic question:  &lt;em&gt;Why even have more than one window?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s some merit to this: the screen could be devoted to one buffer at a time, with buffer-switching taking the place of window switching.  There&amp;rsquo;s no need to worry about resizing windows, and anything that pops up in the course of introspection or regular editing (like documentation windows) can be dismissed with a keypress, typically &lt;code&gt;q&lt;/code&gt;.  Special buffers like the file browser are accessible via dedicated commands like &lt;code&gt;dired-jump&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Relaxing this requirement to two-windows-at-a-time helps retain most of the hassle-free behavior while adding the benefits of using the second window as a live reference.  By default, Emacs is set up to do this well, as evidenced by &lt;code&gt;scroll-other-window&lt;/code&gt; and other commands.  No rigid layout imposed via decree from on high, but no chaotic structureless and windows popping up like weeds either.&lt;/p&gt;
&lt;p&gt;Effectively, we&amp;rsquo;ve circled our way back to &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/The-Zen-of-Buffer-Display.html&#34;&gt;The Zen of Buffer Display&lt;/a&gt;.  While it would be ironic if the window management freedom Emacs provides causes us to reject it, we &lt;em&gt;can&lt;/em&gt; route around the problem and not deal with windows at all, irrespective of how many we&amp;rsquo;d like to have on screen simultaneously.&lt;/p&gt;
&lt;p&gt;So here are two more strategies for window management, both of which involve minimizing dealing with windows.  The first one is &amp;ldquo;window management&amp;rdquo; in the loosest sense of the term:&lt;/p&gt;
&lt;h3 id=&#34;windows-are-made-up-let-s-ignore-them&#34;&gt;Windows are made up, let&amp;rsquo;s ignore them&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;#switch-and-stay-avy-as-a-window-switcher&#34;&gt;Window-agnostic jumping with Avy&lt;/a&gt; is a special case of a general idea: when using Emacs, we are primarily concerned with text.  As a container for text, a window can be an unnecessary abstraction.  This framing is natural when a destination is outside the screen contents, such as when jumping to definitions with &lt;code&gt;xref-find-definitions&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But there are several other ways to apply this window-agnosticism.  The &lt;code&gt;mark-ring&lt;/code&gt; and &lt;code&gt;global-mark-ring&lt;/code&gt; keep track of locations we jump from, letting us jump back with &lt;code&gt;pop-to-mark-command&lt;/code&gt; (&lt;code&gt;C-u C-SPC&lt;/code&gt;) and &lt;code&gt;pop-global-mark&lt;/code&gt; (&lt;code&gt;C-x C-SPC&lt;/code&gt;), the latter of which can jump across windows if necessary.  A package like &lt;a href=&#34;https://github.com/alphapapa/dogears.el&#34;&gt;dogears&lt;/a&gt; can provide more granular control and a nicer UI to retrace your steps.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--pop-global-mark-advice&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/lisp-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Making &lt;code&gt;pop-to-buffer&lt;/code&gt; jump across windows.&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;By default, &lt;code&gt;pop-global-mark&lt;/code&gt; always switches buffers (if required) in the current window.  We&amp;rsquo;d like it to double as a window-switcher, which requires a little advice:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;define-advice&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pop-global-mark&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;:around&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;pgm&lt;/span&gt;) &lt;span style=&#34;color:#963&#34;&gt;use-display-buffer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Make &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`pop-to-buffer&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; jump buffers via &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`display-buffer&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;cl-letf&lt;/span&gt; (((&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-function&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;switch-to-buffer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;pop-to-buffer&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pgm&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;To manually pin a position to jump back to later, there is &lt;code&gt;point-to-register&lt;/code&gt; (&lt;code&gt;C-x r SPC&lt;/code&gt;) and &lt;code&gt;jump-to-register&lt;/code&gt; (&lt;code&gt;C-x r j&lt;/code&gt;).  Again, this switches windows as a side-effect.&lt;/p&gt;
&lt;p&gt;For more permanent records, you can create and jump to bookmarks with &lt;code&gt;bookmark-set&lt;/code&gt; (&lt;code&gt;C-x r m&lt;/code&gt;) and &lt;code&gt;bookmark-jump&lt;/code&gt; (&lt;code&gt;C-x r b&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Between these, you have plenty of options for navigating across windows to locations that are meaningful, as ascertained by either Emacs or you.  These work just as well with a single window in an Emacs frame as they do with the canonical twenty-first century IDE window layout.&lt;/p&gt;
&lt;h3 id=&#34;deal-with-windows-so-we-don-t-have-to-deal-with-windows&#34;&gt;Deal with windows so we don&amp;rsquo;t have to deal with windows&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;i.e.&lt;/em&gt; Fixing the Whack-A-Mole window problem.&lt;/p&gt;
&lt;p&gt;As much as this write-up is about manual actions involving Emacs windows, it was unavoidable: at some point I was going to have to mention &lt;code&gt;display-buffer-alist&lt;/code&gt; and automatic window behavior.  The idea is simple.  Every time elisp code wants to show you a buffer, it tries to match the buffer it is displaying against a list of rules in this variable.  The matching entry specifies how it should be displayed.&lt;/p&gt;
&lt;p&gt;If we set up rules &amp;ndash; specifying window sizes, positions, roles, focus &amp;ndash; for every kind of buffer we see in our daily Emacs use, that&amp;rsquo;s most window management sorted&amp;hellip; right?&lt;/p&gt;
&lt;p&gt;Right, actually.  The reality hews close to the aspiration.  The problem with &lt;code&gt;display-buffer-alist&lt;/code&gt; is not that it &lt;em&gt;doesn&amp;rsquo;t&lt;/em&gt; work, but that it&amp;rsquo;s a &lt;em&gt;lot&lt;/em&gt; of work.  Creating rules for displaying buffers involves understanding many more aspects of Emacs&amp;rsquo; API than is reasonable for most users: buffer and mode predicates, window types and slots, display-buffer action functions, window parameters, and a whole lot more gibberish.  And at the end of this expedition into the elisp manual, there is no easy way to express a simple intention, like &amp;ldquo;do &lt;em&gt;not&lt;/em&gt; disturb my window arrangement&amp;rdquo;
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Specifying overreaching and overriding display-buffer preferences can do this, but they lead to dozens of edge cases and unintended behavior.
&lt;/small&gt;&lt;/span&gt;
.  As such, it&amp;rsquo;s a tool primarily used by package authors to surface a more approachable interface to specifying automatic window behaviors for their package.&lt;/p&gt;
&lt;p&gt;But in the spirit of the almanac, let&amp;rsquo;s not leave this topic empty handed.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The &lt;a href=&#34;https://depp.brause.cc/shackle/&#34;&gt;Shackle&lt;/a&gt; package papers over the &lt;code&gt;display-buffer-alist&lt;/code&gt; oddness and presents a simplified elisp interface for specifying window rules.  If you want to corral a couple of pesky buffer types that always ruin your window arrangement and have you reaching for &lt;code&gt;winner-undo&lt;/code&gt;, this is your best bet.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Emacs distributions usually provide a simple interface for specifying these preferences.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Doom Emacs provides a convenient &lt;code&gt;set-popup-rule!&lt;/code&gt; command for this.
&lt;/small&gt;&lt;/span&gt;
If you&amp;rsquo;re using one, you&amp;rsquo;re probably covered.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;And if you&amp;rsquo;ve got a hankering for tinkering, &lt;a href=&#34;https://www.masteringemacs.org/article/demystifying-emacs-window-manager&#34;&gt;Mickey Peterson&amp;rsquo;s article&lt;/a&gt; on demystifying the window manager, this &lt;a href=&#34;https://protesilaos.com/codelog/2024-02-08-emacs-window-rules-display-buffer-alist/&#34;&gt;video by Protesilaos Stavrou&lt;/a&gt; and &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Displaying-Buffers.html&#34;&gt;the elisp manual&lt;/a&gt; are all fine resources, as alluded to in the preface.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;popper-popwin-shell-pop-and-vterm-toggle&#34;&gt;Popper, Popwin, shell-pop and vterm-toggle&lt;/h3&gt;
&lt;p&gt;While we&amp;rsquo;re aiming at the ideal of the minimal workspace uncluttered by windows, a popup manager is another helpful tool.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/emacsorphanage/popwin&#34;&gt;Popwin&lt;/a&gt; and &lt;a href=&#34;https://github.com/karthink/popper&#34;&gt;Popper&lt;/a&gt; are Emacs packages based on the observation that not all buffers are created equal.  There are (primary) buffers we spend most of our time in, and (popup) buffers we&amp;rsquo;d like to access temporarily &amp;ndash; to use as a reference, page through documentation, run shell commands, check a task or compilation status, access search results, read messages, and so on.  Using &lt;code&gt;display-buffer-alist&lt;/code&gt; or an equivalent method, you can make these buffers use smaller, auxiliary windows and not grab the cursor when they appear.  But that doesn&amp;rsquo;t solve the access problem: what we&amp;rsquo;d like is one key access to summon these popup buffers, and easy ways to dismiss their windows, cycle through or kill them.&lt;/p&gt;
&lt;p&gt;Popper provides this for all kinds of buffers you choose to (pre-)designate as popups, helping you stick to the one (or two) window paradigm, raising and dismissing these auxiliary windows as needed.  This image shows popups available in the current context as a line of tabs that can be accessed or cycled through with one key:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/popper-tab-line-demo.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Popwin is an older and more comprehensive implementation of this idea, but it bundles together quick key access and its own bespoke display-buffer configuration, which may not be what you want.  If you only want one key-access to summon and dismiss shell buffers, &lt;a href=&#34;https://github.com/kyagi/shell-pop-el&#34;&gt;shell-pop&lt;/a&gt; or &lt;a href=&#34;https://github.com/jixiuf/vterm-toggle&#34;&gt;vterm-toggle&lt;/a&gt; might be all you need instead.&lt;/p&gt;
&lt;h2 id=&#34;the-missing-pieces&#34;&gt;The Missing Pieces&lt;/h2&gt;
&lt;p&gt;We conclude with window management options that should exist&amp;hellip; but don&amp;rsquo;t.&lt;/p&gt;
&lt;h3 id=&#34;window-tree&#34;&gt;window-tree&lt;/h3&gt;
&lt;p&gt;There is a fundamental disconnect between how Emacs represents windows and how we manipulate them using the approaches discussed above.&lt;/p&gt;
&lt;p&gt;Windows in a frame in Emacs are arranged in a tree: the leaf nodes are &amp;ldquo;live&amp;rdquo; (real) windows, and the rest are &amp;ldquo;internal&amp;rdquo; (virtual) windows
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
The minibuffer is technically not part of this tree, although it can be reached by traversing it.  (See the &lt;code&gt;window-tree&lt;/code&gt; function.)
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-window-tree-illustration.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Most user-facing operations on windows, such as moving between them with &lt;code&gt;other-window&lt;/code&gt; or Windmove, ignore the tree structure and work by examining their spatial positions instead.  This often causes unexpected and unintuitive behavior when splitting or deleting windows, or imposes confusing constraints on what splits you can create.  For example, there is no way to perform these transformations:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-window-tree-deficit.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;The window that needs to be split here is neither the frame root nor a leaf window &amp;ndash; it&amp;rsquo;s some internal node in the tree.&lt;/p&gt;
&lt;p&gt;Adding commands for window-tree operations opens the door to many new possibilities.  Frame transformations like splitting, transposing, mirroring and so on are elementary operations on window-tree branches.  Multiple window selection is possible via &amp;ldquo;selecting&amp;rdquo; internal windows, and &lt;em&gt;partial&lt;/em&gt; window configurations can then be operated on, handed off to other tabs or frames, duplicated or persisted.  Tree branches can be protected from being mangled by &lt;code&gt;display-buffer&lt;/code&gt; and friends
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
This kind of all-or-nothing window behavior is currently enabled via Elisp&amp;rsquo;s atomic windows API, which is a significantly more restrictive approach.
&lt;/small&gt;&lt;/span&gt;
, and you can have sections of a frame devoted to one task, with the sibling branch tolerating flexible, looser behavior.&lt;/p&gt;
&lt;p&gt;How do we write this hypothetical wintree package?&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Elisp already provides functions to query the window tree: &lt;code&gt;window-tree&lt;/code&gt; returns the tree itself.  &lt;code&gt;frame-root-window&lt;/code&gt; returns the tree root, and &lt;code&gt;window-parent&lt;/code&gt;, &lt;code&gt;window-child&lt;/code&gt;, &lt;code&gt;window-*-sibling&lt;/code&gt; do what you&amp;rsquo;d expect.&lt;/li&gt;
&lt;li&gt;There is some support for tree traversal via &lt;code&gt;walk-window-tree&lt;/code&gt; and &lt;code&gt;walk-windows&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;There are no elementary functions for mutating the tree, except via splitting and deleting live windows the usual way.&lt;/li&gt;
&lt;li&gt;There is no concept of &amp;ldquo;selecting&amp;rdquo; an internal window, so this will have to be simulated via the UI, perhaps by &lt;a href=&#34;https://github.com/captainflasmr/selected-window-accent-mode&#34;&gt;adding a border&lt;/a&gt; inside each window in the sub-tree.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So some of the required elements are present.  The missing ingredient is a motivated Emacs user (perhaps you) stepping into &lt;code&gt;window.el&lt;/code&gt; and getting their hands dirty!&lt;/p&gt;
&lt;h3 id=&#34;the-tiling-wm-integrator&#34;&gt;The tiling-wm integrator&lt;/h3&gt;
&lt;p&gt;Emacs&amp;rsquo; window-tree model is almost exactly that of manual tiling window managers like i3 or bspwm, sans some affordances like i3&amp;rsquo;s tabbed windows.  This leads us to a natural question: why use a tiling window manager inside of another one?
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Yo dawg, I heard you like tiling&amp;hellip;
&lt;/small&gt;&lt;/span&gt;
If you use i3, bspwm or Emacs inside tmux, it&amp;rsquo;s natural to want to be able to navigate both seamlessly, with the same keybindings.  There are a couple of Emacs packages for this: Pavel Korytov&amp;rsquo;s &lt;a href=&#34;https://sqrtminusone.xyz/posts/2021-10-04-emacs-i3/&#34;&gt;i3-integration&lt;/a&gt;, and something I hacked up for &lt;a href=&#34;https://github.com/karthink/.emacs.d/blob/master/plugins/emacs-wm.el&#34;&gt;qtile&lt;/a&gt;.  But providing a cleaner and more unified interface for this from Emacs can make integrating with all window managers much easier.  Again, most elements we need are already present:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The window manager should provide some way to identify the active window class, and to move across and manipulate windows programmatically.  This can be via a shell command, socket or server-based IPC, or (on Linux) via D-Bus methods.  This covers most window managers and terminal multiplexers.&lt;/li&gt;
&lt;li&gt;On the Emacs side, we need a communication method-agnostic interface for window operations that mimics how most window managers do them, supporting a common subset of operations or (more ambitiously) their union.&lt;/li&gt;
&lt;li&gt;When switching windows in the window manager, we check if the active window is Emacs, and yield control to it if required.  Emacs then performs the window operation within or without the Emacs frame as required.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;As before, the missing ingredient is you!&lt;/p&gt;
&lt;h2 id=&#34;the-view-from-here&#34;&gt;The view from here&lt;/h2&gt;
&lt;p&gt;Believe it or not, this was the short version.  To keep the scope of this piece under check, there are several window management strategies I had to exclude, such as anything involving &lt;code&gt;tab-line-mode&lt;/code&gt;, or window types and properties like atomic, dedicated or side windows.  And we are all safer for skirting around the issue of &lt;code&gt;display-buffer&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Where does that leave us?  With about a dozen ways to switch, move, jump around, create, delete and otherwise manipulate windows and window configurations in Emacs, many ways to control window display on the fly when invoking commands, and half a dozen ways to work across windows and avoid thinking about them at all.  Once again, this collection is colored and limited by my experience with window wrangling in Emacs, and thus it&amp;rsquo;s not an exhaustive list.  If I&amp;rsquo;ve missed something simple and useful please let me know!&lt;/p&gt;
&lt;p&gt;For better or worse, window management in Emacs is not so much complicated as it is open-ended.  Emacs provides the ingredients and some instructions, and the ingredients can work as basic meals by themselves.&lt;/p&gt;
&lt;p&gt;But with a little cooking we can make something delicious.  Bon appétit.&lt;/p&gt;
&lt;hr&gt;
&lt;details class=&#34;implementation&#34; open style=&#34;font-size:0.8rem&#34;&gt;
&lt;summary&gt;Updates and Corrections&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Thanks to the following folks for corrections and suggestions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://old.reddit.com/r/planetemacs/comments/1cp4hfg/karthik_chikmagalur_the_emacs_window_management/l3kthnq/&#34;&gt;JD Smith for pointing out&lt;/a&gt; that &lt;code&gt;winner-mode&lt;/code&gt; maintains separate window configuration history per Emacs frame, so it remains viable if you use multiple frames.&lt;/li&gt;
&lt;li&gt;Grant Rosson for reminding me that &lt;code&gt;pop-global-mark&lt;/code&gt; does &lt;em&gt;not&lt;/em&gt; work across Emacs windows by default, and needs a little advice.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://old.reddit.com/r/planetemacs/comments/1cp4hfg/karthik_chikmagalur_the_emacs_window_management/l3kthnq/&#34;&gt;u/simplex5d for corrections&lt;/a&gt; to the &lt;code&gt;winum-keymap&lt;/code&gt; definition.&lt;/li&gt;
&lt;li&gt;kotatsuyaki mentions that &lt;code&gt;aw-dispatch-always&lt;/code&gt; needs to be set for &lt;code&gt;ace-window&lt;/code&gt; actions to be available when there are two or fewer windows on the screen.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
</description>
    </item><item>
      <title>For Your Reference: RefTeX in Org Mode</title>
      <link>https://karthinks.com/software/reftex-in-org-mode/</link>
      <pubDate>Fri, 16 Feb 2024 04:48:00 -0800</pubDate>
      
      <guid>https://karthinks.com/software/reftex-in-org-mode/</guid>
      <description>&lt;div class=&#34;subtitle&#34;&gt;
&lt;p&gt;TL;DR: &amp;ldquo;We have X-references at home&amp;rdquo;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Cross-references in Org mode are not as well developed as its (relatively) new citation system.  Org&amp;rsquo;s built-in linking system is fairly comprehensive and exports to all formats well enough.  But if you&amp;rsquo;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.  &lt;em&gt;Sort of&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In the past few months I received a number of questions about my usage of LaTeX-style cross-references in Org, so here&amp;rsquo;s a short explanation and, uh, reference.&lt;/p&gt;
&lt;h2 id=&#34;just-give-me-the-code&#34;&gt;Just give me the code&lt;/h2&gt;
&lt;p&gt;One half of my long-winded Emacs articles begin or end with a call to action:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;hellip;and it&amp;rsquo;s a package, and here&amp;rsquo;s a link, it&amp;rsquo;s on MELPA, try it out.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is not one of those.  There &lt;em&gt;is&lt;/em&gt; a package, and more code besides.  But this is stuff extracted from my Emacs init file, which is a cross between a palimpsest, a crime scene and a dry-erase board that don&amp;rsquo;t erase no more.  Use at your own peril, or better yet, reuse these ideas to make something coherent and plug-and-play:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/karthink/consult-reftex&#34;&gt;&lt;code&gt;consult-reftex&lt;/code&gt;&lt;/a&gt;: A better interface to RefTeX, with &lt;a href=&#34;https://github.com/minad/consult&#34;&gt;Consult&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/karthink/reftex-xref&#34;&gt;&lt;code&gt;reftex-xref&lt;/code&gt;&lt;/a&gt;: xref and eldoc support for RefTeX&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://gist.github.com/karthink/d2419098c9312e3bf2c63b052464ef5f&#34;&gt;Some configuration&lt;/a&gt; to turn on these enhancements.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Demos and explanations below.&lt;/p&gt;
&lt;h2 id=&#34;background-org-link-org-ref-and-oxr&#34;&gt;Background: &lt;code&gt;org-link&lt;/code&gt;, &lt;code&gt;org-ref&lt;/code&gt; and &lt;code&gt;oxr&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;There are other solutions &amp;ndash; actual solutions &amp;ndash; for cross-references in Org mode.  Org&amp;rsquo;s built-in linking system can be repurposed for this, and it will export to all document formats.  Bruce D&amp;rsquo;Arcus&amp;rsquo; &lt;a href=&#34;https://github.com/bdarcus/oxr&#34;&gt;&lt;code&gt;oxr&lt;/code&gt;&lt;/a&gt; is a proof of concept of a cross-referencing system built on top of Org&amp;rsquo;s links.  For LaTeX exports, there&amp;rsquo;s John Kitchin&amp;rsquo;s frighteningly full-featured &lt;a href=&#34;https://github.com/jkitchin/org-ref/&#34;&gt;&lt;code&gt;org-ref&lt;/code&gt;&lt;/a&gt;, with simple and elegant &lt;a href=&#34;https://github.com/jkitchin/org-ref/blob/master/org-ref.org#ref-links-ref-links&#34;&gt;cross-referencing syntax&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;One of these is probably what you want.&lt;/p&gt;
&lt;p&gt;One of these is probably what I would have used if I had given my slow transition from LaTeX to Org any active thought.  Instead I just continued to use RefTeX.&lt;/p&gt;
&lt;h2 id=&#34;what-s-a-reftex&#34;&gt;What&amp;rsquo;s a RefTeX?&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&#34;https://www.gnu.org/software/auctex/reftex.html&#34;&gt;RefTeX&lt;/a&gt; is an Emacs minor mode with distinct support for &lt;code&gt;\ref&lt;/code&gt;, &lt;code&gt;\label&lt;/code&gt;, &lt;code&gt;\cite&lt;/code&gt;, and &lt;code&gt;\index&lt;/code&gt; commands in (multi-file) LaTeX documents.  It is included with Emacs.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The official description undersells it.  RefTeX is extensive: it supports cross-references and citations, semi-automatic label creation, reference tracking and updates, indexes, multi-file documents, references to external documents, a dynamic table of contents and more, and provides the means to do everything that we&amp;rsquo;re about to do more clumsily below.&lt;/p&gt;
&lt;p&gt;In a happy coincidence, RefTeX works without a hitch in Org documents&amp;hellip; to a point
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
It gets dicey with multi-file Org documents.
&lt;/small&gt;&lt;/span&gt;
.  This is an oft-ignored advantage of regexp-based, structure-agnostic parsing &amp;ndash; once you iron out the many, many edge cases over a few years, it tends to work pretty much everywhere.  RefTeX&amp;rsquo;s Org mode &amp;ldquo;support&amp;rdquo; is good enough for my purposes, and having it work the same in Org and LaTeX documents is a bonus.&lt;/p&gt;
&lt;p&gt;It even integrates with &lt;a href=&#34;https://karthinks.com/software/latex-input-for-impatient-scholars/#step-2-cdlatex&#34;&gt;&lt;code&gt;cdlatex&lt;/code&gt; and &lt;code&gt;org-cdlatex&lt;/code&gt;&lt;/a&gt;, with automatic label insertion when inserting environments.  (This is not a coincidence.)&lt;/p&gt;
&lt;p&gt;There are two limitations.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Obviously, LaTeX style cross-references only work with LaTeX exports.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The other issue with RefTeX, and the main focus of this write-up, is the UI.  It&amp;rsquo;s very&amp;hellip; 90s, let&amp;rsquo;s say.  Better previewing, faster navigation, integration into the modern Emacs API, some DWIM behavior &amp;ndash; these are all achievable with a few band-aids.  The result is a patchwork, but that&amp;rsquo;s most things Emacs.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Finally, there&amp;rsquo;s one other deep connection between RefTeX, CDLaTeX and Org mode.  It&amp;rsquo;s two words.  Take your guesses, or open up &lt;code&gt;reftex.el&lt;/code&gt; and read the header!&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;sprucing-up-the-reftex-experience&#34;&gt;Sprucing up the RefTeX experience&lt;/h2&gt;
&lt;p&gt;A reassertion: RefTeX already works reasonably well in Org mode, and you can work around edge cases if you encounter them.  The write-up until now was thus mainly a PSA.  What follows is minor improvements to the UI and the general experience of Org when using RefTeX.&lt;/p&gt;
&lt;h3 id=&#34;insert-references-with-consult-reftex&#34;&gt;Insert references with &lt;code&gt;consult-reftex&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;As mentioned above, RefTeX is a kitchen sink library &amp;ndash; it provides everything you need to manage references, including a multi-step reference insertion menu.  But this process leaves a bit to be desired:&lt;/p&gt;
&lt;img src=&#34;https://karthinks.com/img/reftex-insert-reference.png&#34; style=&#34;box-shadow:0px -5px 5px #421D5D;margin-top:14px;margin-bottom:14px;border-radius:8px;&#34;&gt;
&lt;p&gt;I wrote &lt;a href=&#34;https://github.com/karthink/consult-reftex&#34;&gt;consult-reftex&lt;/a&gt; a while ago to provide a better interface for reference creation:
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
The LaTeX previews in the buffer, in &lt;code&gt;consult-reftex&lt;/code&gt;&amp;rsquo;s previews and elsewhere are from Org&amp;rsquo;s &lt;a href=&#34;https://www.youtube.com/watch?v=n-AfvuV-bYo&#34;&gt;upcoming LaTeX preview system overhaul&lt;/a&gt;.
&lt;/small&gt;&lt;/span&gt;&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/consult-reftex-insert-demo-small.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/consult-reftex-insert-demo-small.mp4&#34;&gt;[VIDEO: consult-reftex label insertion]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;Call &lt;code&gt;consult-reftex-insert-reference&lt;/code&gt; to insert a reference at point.  I&amp;rsquo;ve bound it to a snippet, so I invoke it by typing in &lt;code&gt;ref&lt;/code&gt; and pressing &lt;code&gt;TAB&lt;/code&gt; instead.&lt;/li&gt;
&lt;li&gt;This command presents a completing-read interface where you can narrow the candidates to just equations, figures, sections etc.  Candidate objects are previewed above the minibuffer.&lt;/li&gt;
&lt;li&gt;You can choose how to insert this reference (as a &lt;code&gt;\ref&lt;/code&gt;, &lt;code&gt;\eqref&lt;/code&gt;, &lt;code&gt;\cref&lt;/code&gt; etc).&lt;/li&gt;
&lt;li&gt;Repeat this a couple of times.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;I wrote it for LaTeX documents, but thanks to RefTeX&amp;rsquo;s flexibility it works all the same in Org mode.&lt;/p&gt;
&lt;h4 id=&#34;looking-up-references-consult-reftex--again&#34;&gt;Looking up references: &lt;code&gt;consult-reftex&lt;/code&gt; (again)&lt;/h4&gt;
&lt;p&gt;The preview interface for &lt;code&gt;consult-reftex&lt;/code&gt; serves a second purpose &amp;ndash; you can use it as a listing of the equations in your document (by label), and act on labels via Embark.&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/consult-reftex-lookup-demo-small.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/consult-reftex-lookup-demo-small.mp4&#34;&gt;[VIDEO: consult-reftex to look up labels]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Same usage pattern, different focus from the above&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Cycle through labeled objects (equations/sections etc) in the document&lt;/li&gt;
&lt;li&gt;Invoke &lt;a href=&#34;https://karthinks.com/software/fifteen-ways-to-use-embark/&#34;&gt;Embark&lt;/a&gt; on a candidate to access additional RefTeX actions: change the label (and all references to it), reparse the file, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;I don&amp;rsquo;t do this when writing, but it&amp;rsquo;s occasionally useful when reviewing work.&lt;/p&gt;
&lt;h3 id=&#34;fontify-dot-dot-dot&#34;&gt;Fontify&amp;hellip;&lt;/h3&gt;
&lt;p&gt;RefTeX labels in Org are plain by default,&lt;/p&gt;
&lt;img src=&#34;https://karthinks.com/img/reftex-hack-no-font-lock.png&#34; style=&#34;box-shadow:0px -5px 5px #421D5D;margin-top:14px;margin-bottom:10px;border-radius:8px;&#34;&gt;
&lt;p&gt;so a little syntax highlighting goes a long way:&lt;/p&gt;
&lt;img src=&#34;https://karthinks.com/img/reftex-hack-with-font-lock.png&#34; style=&#34;box-shadow:0px -5px 5px #421D5D;margin-top:14px;margin-bottom:10px;border-radius:8px;&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;font-lock-add-keywords&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-mode&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;((&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\\(\\(?:\\\\\\(?:label\\|ref\\|eqref\\)\\)\\){\\(.+?\\)}&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;font-lock-keyword-face&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;font-lock-constant-face&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I didn&amp;rsquo;t bother making a comprehensive regexp for font-locking here, you might want to thrown in more keywords.&lt;/p&gt;
&lt;p&gt;This is more than eye-candy: a little further below, we use the faces we specify here as anchors for jumping between references.  If you use different faces for the keywords, you&amp;rsquo;ll need to update the &lt;a href=&#34;#org-target--reftex-navigation-code&#34;&gt;navigation code below&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;dot-dot-dot-and-prettify-tex-fold-mode&#34;&gt;&amp;hellip;and Prettify: &lt;code&gt;TeX-fold-mode&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;TeX-fold-mode&lt;/code&gt;, provided with &lt;a href=&#34;https://www.gnu.org/software/auctex&#34;&gt;AucTeX&lt;/a&gt;, is useful for shortening long references by placing overlays over them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Before&lt;/strong&gt;:&lt;/p&gt;
&lt;img src=&#34;https://karthinks.com/img/TeX-fold-before.png&#34; style=&#34;box-shadow:0px -5px 5px #421D5D;margin-top:14px;margin-bottom:10px;border-radius:8px;&#34;&gt;
&lt;p&gt;&lt;strong&gt;After&lt;/strong&gt; (with the mouse over one of the references):&lt;/p&gt;
&lt;img src=&#34;https://karthinks.com/img/TeX-fold-after.png&#34; style=&#34;box-shadow:0px -5px 5px #421D5D;margin-top:14px;margin-bottom:10px;border-radius:8px;&#34;&gt;
&lt;p&gt;The effect is purely visual, moving the cursor into the overlay reveals the full reference:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/TeX-fold-enable-small.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/TeX-fold-enable-small.mp4&#34;&gt;[VIDEO TeX-fold-mode]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;This requires turning on &lt;code&gt;TeX-fold-mode&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://karthinks.com/software/latex-input-for-impatient-scholars/#the-rest-of-auctex&#34;&gt;It can fold most LaTeX constructs&lt;/a&gt;, including environments, sections, comments and even individual math symbols and operators.  We&amp;rsquo;re only interested in folding references and labels here, though, so we can specify this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;TeX-fold-type-list&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;macro&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can make this Org mode-specific with a hook if you want to fold more constructs in LaTeX documents.&lt;/p&gt;
&lt;p&gt;Optional: we can tweak the overlay styling for labels and refs as well:&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/lisp-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Reference/Label folding style: code&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; Faces&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;set-face-attribute&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;TeX-fold-folded-face&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:foreground&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:inherit&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;shadow&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; Custom folded display for labels and refs&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/TeX-fold-ref&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;text&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;m&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;string-match&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;^\\([^:]+:\\)\\(.*\\)&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;text&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#963&#34;&gt;cat&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;match-string&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;text&lt;/span&gt;) &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#963&#34;&gt;ref&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;match-string&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;text&lt;/span&gt;) &lt;span style=&#34;color:#963&#34;&gt;text&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;&amp;gt;&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;length&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ref&lt;/span&gt;) &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;13&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ref&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;substring&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ref&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;6&lt;/span&gt;) &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;...&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;substring&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ref&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-6&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;[&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;propertize&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cat&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;face&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;shadow&lt;/span&gt;) &lt;span style=&#34;color:#963&#34;&gt;ref&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;]&amp;#34;&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/TeX-fold-label&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;texts&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;cl-loop&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;for&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;text&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;in&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;texts&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#963&#34;&gt;for&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;m&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;=&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;string-match&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;^\\([^:]+:\\)\\(.*\\)&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;text&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#963&#34;&gt;for&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cat&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;=&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;match-string&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;text&lt;/span&gt;) &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#963&#34;&gt;for&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ref&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;=&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;match-string&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;text&lt;/span&gt;) &lt;span style=&#34;color:#963&#34;&gt;text&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#963&#34;&gt;collect&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;[&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;propertize&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cat&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;face&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;shadow&lt;/span&gt;) &lt;span style=&#34;color:#963&#34;&gt;ref&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;]&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#963&#34;&gt;into&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;labels&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#963&#34;&gt;finally&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;return&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;mapconcat&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;identity&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;labels&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;,&amp;#34;&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq-default&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;TeX-fold-macro-spec-list&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;((&lt;span style=&#34;color:#963&#34;&gt;my/TeX-fold-label&lt;/span&gt; (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;cite&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;my/TeX-fold-label&lt;/span&gt; (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;label&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;my/TeX-fold-ref&lt;/span&gt; (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;ref&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;pageref&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;eqref&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;footref&amp;#34;&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Lastly, you might want to turn folding on in Org buffers.  &lt;code&gt;TeX-fold&lt;/code&gt; uses the &lt;code&gt;C-c C-o&lt;/code&gt; key as a prefix, watch out for key conflicts with Org!&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-mode-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;TeX-fold-mode&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;moving-around-references-big-ol-pile-o-hacks&#34;&gt;Moving around references: big ol&amp;rsquo; pile o&amp;rsquo;hacks&lt;/h3&gt;
&lt;p&gt;This is mostly to avoid having to use the mouse &amp;ndash; Isearch or Avy aren&amp;rsquo;t very useful if the reference is folded.  That said, its main advantage is not that it moves the cursor (for editing), but that it enables other actions we might want to take immediately after, such as jumping to the definition of a label &lt;a href=&#34;#jumping-to-definition-xref-support-more-hacks&#34;&gt;with &lt;code&gt;xref&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/reftex-hack-jumping-around-small.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/reftex-hack-jumping-around-small.mp4&#34;&gt;[VIDEO: Jumping around reftex references]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;I jump to the next reference with &lt;code&gt;M-g r&lt;/code&gt;, and then jump forward and backward across references, labels and citations with &lt;code&gt;M-g r&lt;/code&gt; and &lt;code&gt;M-g R&lt;/code&gt;.  Actually, after invoking it once I jump forward and back with just &lt;code&gt;r&lt;/code&gt; and &lt;code&gt;R&lt;/code&gt;, thanks to &lt;code&gt;repeat-mode&lt;/code&gt;.  The code is below.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;We want several things to happen when we jump to a reference:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Org should open up folded/invisible text if the references is in a hidden region,&lt;/li&gt;
&lt;li&gt;Any TeX-fold overlay at the reference should be cleared,&lt;/li&gt;
&lt;li&gt;and if we jumped &lt;em&gt;from&lt;/em&gt; a reference it should be folded again by TeX-fold.&lt;/li&gt;
&lt;li&gt;If a preview is available (via Eldoc, &lt;a href=&#34;#auto-preview-reference-at-point-eldoc-support&#34;&gt;see below&lt;/a&gt;), it should be activated.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The code for this is below.  It&amp;rsquo;s not pretty.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--reftex-navigation-code&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/lisp-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; Jumping by reference: code&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/next-reference-or-label&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;_arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;p&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;prop&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;pcase-let&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          ((&lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;get-char-property-and-overlay&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;TeX-fold-type&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;TeX-fold-hide-item&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prop&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;text-property-search-forward&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;face&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;val&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;memq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;val&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;font-lock-constant-face&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;org-cite&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prop&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;progn&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;prop-match-beginning&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prop&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;derived-mode-p&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-mode&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;org-invisible-p&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#963&#34;&gt;org-fold-show-context&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;link-search&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;eldoc-mode&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;eldoc--invoke-strategy&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;pcase-let&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     ((&lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;get-char-property-and-overlay&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;TeX-fold-type&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;TeX-fold-show-item&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;message&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;No more references/labels.&amp;#34;&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/previous-reference-or-label&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;_arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;p&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;p&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;text-property-search-backward&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;face&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;val&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;memq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;val&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;font-lock-constant-face&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;org-cite&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           &lt;span style=&#34;color:#963&#34;&gt;TeX-fold-folded-face&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;p&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#007020&#34;&gt;pcase-let&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         ((&lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;get-char-property-and-overlay&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;TeX-fold-type&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;TeX-fold-hide-item&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;p&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;derived-mode-p&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-mode&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;org-invisible-p&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#963&#34;&gt;org-fold-show-context&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;link-search&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;eldoc-mode&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;eldoc--invoke-strategy&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#007020&#34;&gt;pcase-let&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         ((&lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;get-char-property-and-overlay&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;TeX-fold-type&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;TeX-fold-show-item&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;While we&amp;rsquo;re at it, we might as well make this command repeatable, so you can navigate with just &lt;code&gt;r&lt;/code&gt; and &lt;code&gt;R&lt;/code&gt; after the first jump:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-set&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;org-mode-map&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-g r&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;my/next-reference-or-label&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-set&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;org-mode-map&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-g R&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;my/previous-reference-or-label&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;defvar-keymap&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/TeX-ref-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:repeat&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;r&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;my/next-reference-or-label&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;R&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;my/previous-reference-or-label&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;jumping-to-definition-xref-support-more-hacks&#34;&gt;Jumping to definition: &lt;code&gt;xref&lt;/code&gt; support, more hacks&lt;/h3&gt;
&lt;p&gt;With the cursor at a reference, jump to the corresponding label using Emacs&amp;rsquo; standard &lt;code&gt;xref&lt;/code&gt; mechanism:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/reftex-hack-jumping-around-and-xref-small.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/reftex-hack-jumping-around-and-xref-small.mp4&#34;&gt;[VIDEO: reftex-xref]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;Jump to the next reference with &lt;code&gt;M-g r&lt;/code&gt;, as before.&lt;/li&gt;
&lt;li&gt;Jump to the corresponding label with &lt;code&gt;M-.&lt;/code&gt;, Emacs&amp;rsquo; standard keybinding for &lt;code&gt;xref-find-definitions&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Jump back with &lt;code&gt;M-,&lt;/code&gt;, Emacs&amp;rsquo; standard keybinding for &lt;code&gt;xref-go-back&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Repeat a couple of times.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Code below.  Again, not pretty.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;org-target&#34; id=&#34;org-target--reftex-xref-code-block&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;&lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/lisp-icon.png&#34; class=detail-icon&gt;&lt;/span&gt; &lt;code&gt;xref&lt;/code&gt; support for RefTeX: code&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;require&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;xref&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;require&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;reftex-ref&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;cl-defmethod&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;xref-backend-identifier-at-point&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;_backend&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;eql&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;looking-back&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\\\\\\(?:page\\|eq\\|auto\\|c\\)?ref{[-a-zA-Z0-9_*.:]*&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;line-beginning-position&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;		    (&lt;span style=&#34;color:#963&#34;&gt;reftex-this-word&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;-a-zA-Z0-9_*.:&amp;#34;&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;cl-defmethod&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;xref-backend-definitions&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;_backend&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;eql&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex&lt;/span&gt;)) &lt;span style=&#34;color:#963&#34;&gt;prompt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;unless&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-value&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-docstruct-symbol&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;reftex-parse-one&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;when-let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;docstruct&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-value&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-docstruct-symbol&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;data&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;assoc&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prompt&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;docstruct&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;label&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;nth&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;data&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;nth&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;data&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;buffer&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;find-buffer-visiting&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                          (&lt;span style=&#34;color:#963&#34;&gt;reftex-get-file-buffer-force&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;not&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-keep-temporary-buffers&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;re&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;format&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-find-label-regexp-format&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;regexp-quote&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;label&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;found&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;with-current-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;buffer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                       (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;re-search-backward&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;re&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           (&lt;span style=&#34;color:#007020&#34;&gt;progn&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point-min&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;re-search-forward&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                   (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;format&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-find-label-regexp-format2&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                           (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;regexp-quote&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;label&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                   &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;list&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;xref-make&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prompt&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;xref-make-buffer-location&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                             &lt;span style=&#34;color:#963&#34;&gt;buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;found&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;cl-defmethod&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;xref-backend-apropos&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;_backend&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;eql&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex&lt;/span&gt;)) &lt;span style=&#34;color:#963&#34;&gt;pattern&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;xref-backend-definitions&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;reftex&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pattern&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-xref&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Function to activate buffer-local backend.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;Add this function to &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`xref-backend-functions&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; to use xref to find
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;function and variable definitions in the same buffer.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;This should have a low priority among xref backends.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;reftex&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; Eldoc support via xref, because why not&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-xref--display-in-eldoc&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;callback&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Display reference label location in Eldoc.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;Call CALLBACK if possible.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;cl-intersection&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#963&#34;&gt;ensure-list&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;get-char-property&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;face&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;font-lock-keyword-face&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;font-lock-constant-face&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#963&#34;&gt;TeX-fold-unfolded-face&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;when-let*&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          ((&lt;span style=&#34;color:#963&#34;&gt;inhibit-redisplay&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;_macro&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;car&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;reftex-what-macro-safe&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;key&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;reftex-this-word&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;^{}%\n\r, \t&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;item&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;car&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;xref-backend-definitions&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;reftex&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;key&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;location&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;xref-item-location&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;item&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;pos&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;xref-buffer-location-position&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;location&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;docstring&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;with-current-buffer&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;xref-buffer-location-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;location&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pos&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#007020&#34;&gt;pcase-let&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                  ((&lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;start&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;end&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    (&lt;span style=&#34;color:#007020&#34;&gt;condition-case&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        (&lt;span style=&#34;color:#963&#34;&gt;LaTeX-find-matching-begin&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                      (&lt;span style=&#34;color:#007020&#34;&gt;:success&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                       &lt;span style=&#34;color:#888&#34;&gt;;; Found \begin{}...\end{}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cons&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                             (&lt;span style=&#34;color:#007020&#34;&gt;progn&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;forward-char&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                    (&lt;span style=&#34;color:#963&#34;&gt;LaTeX-find-matching-end&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                      (&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;error&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                       &lt;span style=&#34;color:#888&#34;&gt;;; No \begin, find \section{} or Org heading instead&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pos&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;re-search-backward&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        (&lt;span style=&#34;color:#007020&#34;&gt;pcase&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;major-mode&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                          (&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-mode&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;^*&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                          (&lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\\(&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;LaTeX-outline-regexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                     &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\\|\\`\\)&amp;#34;&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;line-beginning-position&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-2&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cons&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;line-beginning-position&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                             (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;line-end-position&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-substring-no-properties&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;start&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;end&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;if-let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;prop-and-ov&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;get-char-property-and-overlay&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    (&lt;span style=&#34;color:#963&#34;&gt;xref-buffer-location-position&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;location&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    (&lt;span style=&#34;color:#007020&#34;&gt;pcase&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;major-mode&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                      (&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-mode&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-overlay-type&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                      (&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;latex-mode&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;category&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                  (&lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;memq&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;car&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prop-and-ov&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;org-latex-overlay&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;preview-overlay&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                  (&lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cdr&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prop-and-ov&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;callback&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;propertize&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;docstring&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;display&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                          (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-get&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;preview-image&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;callback&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;docstring&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-eldoc-activate&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;eldoc-documentation-functions&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;reftex-xref--display-in-eldoc&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:local&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-xref-activate&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Activate reftex support using xref.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;xref-backend-functions&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;reftex-xref&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:local&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;provide&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;reftex-xref&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;To turn on &lt;code&gt;xref&lt;/code&gt; support for references in Org mode:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;use-package&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-xref&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:after&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;org&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;latex&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:hook&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;org-mode&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-xref-activate&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;auto-preview-reference-at-point-eldoc-support&#34;&gt;Auto-preview reference at point: &lt;code&gt;eldoc&lt;/code&gt; support&lt;/h3&gt;
&lt;p&gt;If you&amp;rsquo;re jumping to label definitions with &lt;code&gt;xref&lt;/code&gt; just to look at the corresponding equations, we can skip that step with previews of the referenced object.  With &lt;code&gt;eldoc-mode&lt;/code&gt;
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Eldoc is Emacs&amp;rsquo; standard and recommended way of showing contextual help.
&lt;/small&gt;&lt;/span&gt;
enabled:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/reftex-hack-jumping-around-and-eldoc-small.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/reftex-hack-jumping-around-and-eldoc-small.mp4&#34;&gt;[VIDEO: reftex-eldoc]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;With &lt;code&gt;eldoc-mode&lt;/code&gt; enabled, move the cursor into (or jump into) a reference.&lt;/li&gt;
&lt;li&gt;This activates a preview of the relevant label, mostly equations in this example.&lt;/li&gt;
&lt;li&gt;Works for sections too, but not figures or tables (yet).&lt;/li&gt;
&lt;li&gt;Repeat a few times.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Equations and figures can be pretty tall, so if you&amp;rsquo;re not using a dedicated Eldoc buffer (or &lt;a href=&#34;https://github.com/casouri/eldoc-box&#34;&gt;eldoc-box&lt;/a&gt;) you might want to change the height that the echo area can expand to.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;eldoc-echo-area-use-multiline-p&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#963&#34;&gt;max-mini-window-height&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.4&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To activate reference previews as an Eldoc documentation function, we use the helper function defined as part of &lt;a href=&#34;#org-target--reftex-xref-code-block&#34;&gt;reftex-xref above&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;use-package&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-xref&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:after&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;org&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;latex&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:hook&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;org-mode&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reftex-eldoc-activate&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;yep-reftex-dcr-exists&#34;&gt;Yep, &lt;code&gt;reftex-dcr&lt;/code&gt; exists&lt;/h2&gt;
&lt;p&gt;Earlier I mentioned that we would be clumsily recreating features RefTeX already includes.  Indeed, most of the above features, like jumping to label definitions and previewing the reference at point, are already provided in the &lt;code&gt;reftex-dcr&lt;/code&gt; library, included with RefTeX.  The problem is that it predates Emacs&amp;rsquo; &lt;code&gt;xref&lt;/code&gt; and &lt;code&gt;eldoc&lt;/code&gt; APIs (if not their libraries), and like most 90s Emacs packages it reinvents all the wheels.  This is painful on more than an aesthetic level &amp;ndash; I prefer to have one well-supported and convenient way for each semantic task.  The mental model is simpler, as are the required keyboard gymnastics.&lt;/p&gt;
&lt;p&gt;Thankfully, there&amp;rsquo;s enough of a separation between the data-parsing RefTeX backend and the UI that I was able to drive a wedge through and beat it into a more consistent shape.  Needless to say, this shape is not very robust.  Emacs makes it very easy to cobble together an 80% solution &amp;ndash; I spent much longer writing this little explainer than I did actually slapping together the code.  Due to a pies ≫ fingers situation, I&amp;rsquo;m not going to be able to get these hacks to a stage beyond &amp;ldquo;it works for me&amp;rdquo;.  The interest around this topic suggests that perhaps someone might be interested in developing the idea further and modernizing RefTeX, or working on a better cross-referencing system for Org mode.   Have at it!&lt;/p&gt;
</description>
    </item><item>
      <title>Different Strokes For Different Folks</title>
      <link>https://karthinks.com/software/different-strokes-for-different-folks/</link>
      <pubDate>Fri, 24 Nov 2023 15:15:00 -0800</pubDate>
      
      <guid>https://karthinks.com/software/different-strokes-for-different-folks/</guid>
      <description>&lt;div class=&#34;subtitle&#34;&gt;
&lt;p&gt;A modest defense of the rodent&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
See &lt;code&gt;context-menu-mode&lt;/code&gt;.
&lt;/small&gt;&lt;/span&gt;
and drag and drop support, which improve with each new Emacs release, are very intuitive.  The mouse provides access to basic editor functions with no learning curve, and no exhortations to work through the Emacs tutorial are necessary.  Also, feature discoverability via Emacs&amp;rsquo; menu-bar is surprisingly good.&lt;/p&gt;
&lt;p&gt;Unfortunately, I have to address the rodent in the room carefully before we can talk about mitigating the many disadvantages of mouse-first interaction, since Emacs users tend to be very opinionated about this topic.  &lt;strong&gt;Ergonomics&lt;/strong&gt;, &lt;strong&gt;speed&lt;/strong&gt;, and &lt;strong&gt;efficiency&lt;/strong&gt; are three common reasons people advocate for the keyboard against the mouse for non-graphical work.  I&amp;rsquo;m not convinced any of these arguments hold water.  The first two are research-worthy topics on their own, with many quotable precedents, and beyond my ability to argue for or against convincingly just from personal experience
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Besides, anyone who&amp;rsquo;s had bouts of RSI has made up their mind already on this topic.
&lt;/small&gt;&lt;/span&gt;
.  On the matter of speed, for instance, I am obliged to include this quote because y&amp;rsquo;all are going to send me emails linking to it otherwise:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;We’ve done a cool $50 million of R &amp;amp; D on the Apple Human Interface. We discovered, among other things, two pertinent facts:&lt;/p&gt;
&lt;p&gt;Test subjects consistently report that keyboarding is faster than mousing.&lt;/p&gt;
&lt;p&gt;The stopwatch consistently proves mousing is faster than keyboarding.&lt;/p&gt;
&lt;p&gt;&amp;ndash; &lt;a href=&#34;https://en.wikipedia.org/wiki/Bruce_Tognazzini&#34;&gt;Bruce Tognazzini&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So let&amp;rsquo;s pretend for the purpose of today&amp;rsquo;s discussion that we&amp;rsquo;re not concerned about the difference in editing speed one way or another.&lt;/p&gt;
&lt;p&gt;In the context of Emacs specifically, there are further disadvantages.  For example, mouse actions compose in limited ways (such as when dragging to form selections) and cannot build on each other like key sequences can with prefix keys and transient maps.  You can&amp;rsquo;t automate mouse usage with keyboard macros easily.&lt;/p&gt;
&lt;p&gt;But today we&amp;rsquo;re primarily going to address the third reason: efficiency.&lt;/p&gt;
&lt;p&gt;I find the arguments about efficiency, in the sense of poor expressivity or economy of motion, shortsighted at best.  Here are two facets of this argument, where &amp;ldquo;mouse&amp;rdquo; includes any kind of pointing device.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Economy&lt;/strong&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Frequent context switching between the keyboard, mouse and keyboard+mouse is wasteful and causes low amounts of constant friction.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;Expressivity&lt;/strong&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Mouse usage has a low ceiling: it makes easy tasks trivial but involved actions impossible.  Adding buttons or widgets to the screen doesn&amp;rsquo;t scale.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;economy-and-interprogram-contexts&#34;&gt;Economy and interprogram contexts&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Economy&lt;/strong&gt; first.  I actually agree with the context switching argument, to the extent that the friction of repeated switching feels progressively more annoying.  But the conclusion &amp;ndash; it&amp;rsquo;s best to avoid the mouse to avoid context switching &amp;ndash; is shortsighted because it only applies if you&amp;rsquo;re &lt;em&gt;only ever&lt;/em&gt; in Emacs and never have to use the mouse, or conversely if you&amp;rsquo;re &lt;em&gt;never&lt;/em&gt; in a text editor and always in a mouse-driven (or keyboard+mouse driven) application like a 3D modeling tool or a big commercial IDE.  Most of us are somewhere in the middle.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m as keyboard-centric as you can reasonably get: besides Emacs, I use a tiling window manager, a &lt;a href=&#34;https://qutebrowser.org/&#34;&gt;keyboard-driven web browser&lt;/a&gt; and mostly TUI applications.  Keybindings are the topic I&amp;rsquo;ve written the most about on this website &amp;ndash; an embarrassing amount of yakshaving devoted to an inane subject.  Even so, I use the mouse frequently because it&amp;rsquo;s often the best way to select text, images and links, do graphical work, and to interact with (both simple and complex) GUI software.&lt;/p&gt;
&lt;p&gt;When working on something that involves Emacs &lt;em&gt;and&lt;/em&gt; one of these mouse driven applications, having to move over to the keyboard for the Emacs bit is exactly the friction we&amp;rsquo;d like to avoid.  The other app may not be flexible, but Emacs is!  So we don&amp;rsquo;t need to switch to the Emacs-typical both-hands-at-keyboard context.  Here are a few examples of quick interprogram interaction involving Emacs that you can easily do without moving your hand off the mouse.&lt;/p&gt;
&lt;h3 id=&#34;pasting-text-from-other-applications-into-a-new-buffer&#34;&gt;Pasting text from other applications into a new buffer&lt;/h3&gt;
&lt;p&gt;Switch to a scratch buffer+window in Emacs to paste some text:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/strokes-drag-text.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/strokes-drag-text.mp4&#34;&gt;[VIDEO: Create a scratch buffer with strokes]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;I use a mouse gesture in Emacs to create a scratch buffer in Org mode &amp;ndash; courtesy of the &lt;a href=&#34;https://codeberg.org/emacs-weirdware/scratch&#34;&gt;scratch&lt;/a&gt; package &amp;ndash; then drag some text into it
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Incidentally, the text is a LaTeX environment that is rendered automatically via Org&amp;rsquo;s new LaTeX preview system.
&lt;/small&gt;&lt;/span&gt;
.  I then switch back to the previous buffer using another mouse gesture.&lt;/p&gt;
&lt;h3 id=&#34;git-clone-from-a-repository-url&#34;&gt;git-clone from a repository URL&lt;/h3&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/strokes-git-clone.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/strokes-git-clone.mp4&#34;&gt;[VIDEO: git-clone from repository URL]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;Middle click to paste a link from the clipboard.  (This is only for clarity, it&amp;rsquo;s unrelated to the actual action.)  Then use a mouse gesture to git-clone from that link to a prespecified directory.&lt;/p&gt;
&lt;h3 id=&#34;open-a-project-directory-in-dired-so-we-can-drag-and-drop-a-file&#34;&gt;open a project directory in dired so we can drag and drop a file&lt;/h3&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/strokes-project-dired.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/strokes-project-dired.mp4&#34;&gt;[VIDEO: project directory in dired]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;Use a mouse gesture to bring up a list of directories in the active project.  Pick one &amp;ndash; also using the mouse &amp;ndash; then drag an image file into dired before switching back.&lt;/p&gt;
&lt;h3 id=&#34;mpv-plus-live-video-transcript-in-emacs&#34;&gt;mpv + live video transcript in Emacs&lt;/h3&gt;
&lt;p&gt;Control mpv (a video player) by clicking around in a live transcript file in Emacs:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://i.imgur.com/DQ9cmED.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://i.imgur.com/DQ9cmED.mp4&#34;&gt;[VIDEO: live, clickable transcripts with elfeed-tube]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;No mouse gestures here &amp;ndash; the clickable transcripts and mpv connection are provided by &lt;a href=&#34;https://github.com/karthink/elfeed-tube&#34;&gt;elfeed-tube&lt;/a&gt;, which was designed to be usable with the mouse since it involves interacting with a video player.&lt;/p&gt;
&lt;p&gt;My counter-argument can be summarized: &lt;strong&gt;Use the lowest effort means of interaction in each context you work in.  Often this means driving Emacs with the mouse.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&#34;expressivity&#34;&gt;Expressivity&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;expressivity&lt;/strong&gt; counterargument: Buttons and widgets indeed don&amp;rsquo;t scale, but they bear the additional burdern of discoverability.  Mouse interactions in Emacs don&amp;rsquo;t have to be prescribed or discoverable &amp;ndash;  when they are actions &lt;em&gt;we&lt;/em&gt; set up, typically after repeatedly observing a cumbersome task that could be mouse-driven.  Point-and-click in an editor is not as expressive as full-on keyboard usage, but that&amp;rsquo;s only true in the generic sense.  The relevant question is if we can express the &lt;em&gt;specific verbs that we care about&lt;/em&gt;, and from the above demos it&amp;rsquo;s clear we can.&lt;/p&gt;
&lt;p&gt;An example: considering that using the mouse to select and resize windows is already a more natural experience than spamming &lt;code&gt;C-x o&lt;/code&gt; and friends (or your &lt;code&gt;evil-mode&lt;/code&gt; equivalents), it is possible to extend it to be a more comprehensive approach to window and buffer management:&lt;/p&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/strokes-window-handling.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/strokes-window-handling.mp4&#34;&gt;[VIDEO: strokes window handling demo]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;This demo showcases the use of mouse gestures to do the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Split the frame vertically and horizontally&lt;/li&gt;
&lt;li&gt;Delete windows&lt;/li&gt;
&lt;li&gt;Cycle through buffers in windows by left and right clicking the buffer name in the mode line.&lt;/li&gt;
&lt;li&gt;Delete other windows&lt;/li&gt;
&lt;li&gt;Swap windows to the right and left&lt;/li&gt;
&lt;li&gt;Toggle between the last two buffers shown in a window&lt;/li&gt;
&lt;li&gt;Go back to a previous window configuration (via &lt;code&gt;tab-bar-history-back&lt;/code&gt; or &lt;code&gt;winner-undo&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;how-to-mouse-around&#34;&gt;How to mouse around&lt;/h2&gt;
&lt;p&gt;This is not, strictly speaking, an article on how to use the mouse in Emacs &amp;ndash; it&amp;rsquo;s more about &lt;em&gt;why&lt;/em&gt; and &lt;em&gt;when&lt;/em&gt;.  For the how I suggest reading &lt;a href=&#34;https://amodernist.com/texts/emacs-mouse.html&#34;&gt;Philip Kaludercic&amp;rsquo;s write-up&lt;/a&gt;.  You could also try just clicking around, especially in the mode line!  However the use of gestures in Emacs rarely gets much attention, so here we go.&lt;/p&gt;
&lt;p&gt;For once, this is going to be a short description, since this is a &lt;a href=&#34;https://karthinks.com/software/more-batteries-included-with-emacs/#strokes--m-x-strokes-help&#34;&gt;batteries included&lt;/a&gt; situation.  Emacs ships with everything you need.&lt;/p&gt;
&lt;p&gt;Adding mouse gesture support to Emacs is easy with the included Strokes library
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Many thanks to David Bakhash and the Emacs maintainers for strokes.el.
&lt;/small&gt;&lt;/span&gt;
.  For each action you want to map to a gesture,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Find or (optional) write a command that does the thing.&lt;/li&gt;
&lt;li&gt;Set it to a mouse stroke (gesture) with &lt;code&gt;strokes-global-set-stroke&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;That&amp;rsquo;s it
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
&lt;code&gt;M-x strokes-help&lt;/code&gt; has more information.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;Optionally, you could change the mouse button you hold down to perform a gesture.  The default is &lt;code&gt;S-mouse-2&lt;/code&gt;, which is rather awkward.  I use a side button on my mouse (typically the &amp;ldquo;forward&amp;rdquo; button):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;keymap-global-set&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;down-mouse-9&amp;gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;strokes-do-stroke&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Also optionally, you can hide the live-display of the stroke as you draw (&lt;code&gt;strokes-use-strokes-buffer&lt;/code&gt;) &amp;ndash; I left it in for clarity in the demos.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve not had to customize anything else about the strokes library, but feel free to explore &amp;ndash; it has support for multi-glyph (complex) strokes, for instance.&lt;/p&gt;
&lt;p&gt;There are a few general mouse settings you might be interested in:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;mouse-autoselect-window&lt;/code&gt;: Set to &lt;code&gt;t&lt;/code&gt; for focus-follows-mouse behavior inside Emacs.  Typically what you&amp;rsquo;d want if you use mouse gestures.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mouse-drag-and-drop-region&lt;/code&gt;: To enable text drag-and-drop within Emacs,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mouse-drag-and-drop-region-cross-program&lt;/code&gt;: (Emacs 29+) and across programs from Emacs.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dired-mouse-drag-files&lt;/code&gt;: To drag files from dired to other programs.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;improving-strokes&#34;&gt;Improving Strokes&lt;/h2&gt;
&lt;p&gt;Mouse gestures are a decades-old concept, as many features included with Emacs are.  And the Strokes library has a list of notes and todos, as many features included with Emacs do.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;No contextual actions&lt;/strong&gt;: The use of strokes is limited, as of Emacs 29, by the lack of support for mode-specific or buffer-local strokes.  This means the same gesture cannot do different things in different contexts without writing cumbersome, bespoke dispatch commands to handle this.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Somewhat unreliable gesture matching&lt;/strong&gt;:  Drawing with the mouse or trackpad is fuzzy and imprecise.  The matching algorithm is quite rudimentary and there are mismatches when you have many strokes defined (&amp;gt; 25, let&amp;rsquo;s say), even with an increased &amp;ldquo;grid&amp;rdquo; resolution when drawing.  Fixing 1 can take the pressure off the matching algorithm, but we could also use a more sophisticated approach to matching.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No multi-touch gestures&lt;/strong&gt;: This can increases the dimensionality of the gesture space, allowing for a greater number of &amp;ldquo;basic strokes&amp;rdquo; &amp;ndash; although the OS usually captures and maps most of these for its window management.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Despite these limitations, this is a very handy tool.  I&amp;rsquo;m not sure why gestures aren&amp;rsquo;t more common &amp;ndash; we only see them on touch interfaces these days.  You can draw them anywhere on the screen, and they tolerate a fair bit of fuzz.  They avoid the problem of having to move the mouse over to a small target on screen.  Not having to fill the screen up with buttons is a win by itself.  The only significant problem appears to be that they&amp;rsquo;re not (re)discoverable, but this isn&amp;rsquo;t a problem inside Emacs: we have &lt;code&gt;strokes-describe-stroke&lt;/code&gt; (like &lt;code&gt;describe-key&lt;/code&gt;) and &lt;code&gt;strokes-list-strokes&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;it-s-not-all-or-nothing-dot-it-s-not-even-something-dot&#34;&gt;It&amp;rsquo;s not all or nothing.  It&amp;rsquo;s not even something.&lt;/h2&gt;
&lt;p&gt;Some of the &amp;ldquo;talking past each other&amp;rdquo; I mentioned in the beginning is because of assumptions we make about using the mouse in text editors.  We gravitate to one of two specious requirements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The mouse should &lt;em&gt;substitute&lt;/em&gt; for the keyboard, such as when using menu or toolbar buttons &lt;em&gt;instead&lt;/em&gt; of keybindings.&lt;/li&gt;
&lt;li&gt;The mouse should &lt;em&gt;complement&lt;/em&gt; the keyboard, so we work best with a hand each on the keyboard and mouse.  (This is the &lt;a href=&#34;http://acme.cat-v.org/&#34;&gt;Acme editor&lt;/a&gt; approach.)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Actual usage patterns are messier than either of these.  Sometimes we&amp;rsquo;re working in a mouse-heavy context, sometimes it&amp;rsquo;s two handed keyboarding, sometimes its a mix.  Often the editor is at the periphery of the task at hand, sometimes it&amp;rsquo;s dead center
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
This is true despite Emacs swallowing up my desktop applications.  Calendar, email, reading, some web browsing&amp;hellip; the list keeps growing.
&lt;/small&gt;&lt;/span&gt;
.  Any degree of flexibility on the part of the editor is welcome.  Instead of dismissing the mouse on the basis of the available design affordances, it can help to think about what we actually care to avoid &amp;ndash; frequent context switching for me, your answer will be different &amp;ndash; and how driving Emacs with the mouse helps us do that.&lt;/p&gt;
</description>
    </item><item>
      <title>Cool your heels, Emacs</title>
      <link>https://karthinks.com/software/cool-your-heels-emacs/</link>
      <pubDate>Mon, 14 Aug 2023 17:54:00 -0700</pubDate>
      
      <guid>https://karthinks.com/software/cool-your-heels-emacs/</guid>
      <description>&lt;div class=&#34;subtitle&#34;&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;: Sometimes Emacs needs a &lt;a href=&#34;https://github.com/karthink/timeout&#34;&gt;timeout&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;div class=&#34;attribution&#34;&gt;
&lt;p&gt;&amp;ndash; Gerald Sussman, paraphrasing Joel Moses&lt;/p&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;p&gt;A common problem with Emacs&amp;rsquo; giant ball of shared state: Any code can step on the feet of any other &amp;ndash; including yours.  There are conventions in place to keep this from being too much of an issue: Code included in Emacs is tested extensively for edge cases by the tireless maintainers, and third-party package authors are generally careful these days about stepping on too many toes.&lt;/p&gt;
&lt;p&gt;In practice the casualty here is not &lt;em&gt;correctness&lt;/em&gt;, it&amp;rsquo;s &lt;em&gt;performance&lt;/em&gt;.  Emacs can, as of today, only do one thing at a time.  So every &amp;ldquo;background&amp;rdquo; task must, at some point, surface to the foreground and block Emacs for a bit
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Many types of &amp;ldquo;background&amp;rdquo; processing are interruptible by signalling a &lt;code&gt;quit&lt;/code&gt; with &lt;code&gt;keyboard-quit&lt;/code&gt;, but then the task isn&amp;rsquo;t done!  This doesn&amp;rsquo;t help the situation beyond giving you control of Emacs again.
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;The resultant hitching is experienced both with commands you initiate (&amp;quot;&lt;a class=&#34;org-gls&#34; href=&#34;#gls-8&#34;&gt;push operations&lt;/a&gt;&amp;quot;, let&amp;rsquo;s say) and timers that run code without your involvement (&amp;quot;&lt;a class=&#34;org-gls&#34; href=&#34;#gls-9&#34;&gt;pull operations&lt;/a&gt;&amp;quot;).  Every hook and timer installed by packages to dazzle you with real-time updates or feedback is another fraction of a second for which Emacs is blocked.  Ideally these run when Emacs is idle and you don&amp;rsquo;t notice them.  In practice there are many cases, especially with &amp;ldquo;&lt;a class=&#34;org-gls&#34; href=&#34;#gls-8&#34;&gt;push operations&lt;/a&gt;&amp;rdquo;, that involve significant chunks of synchronous auxiliary processing.&lt;/p&gt;
&lt;p&gt;Under these limitations, a few obvious solutions present themselves.&lt;/p&gt;
&lt;h2 id=&#34;as-a-package-author-you-can&#34;&gt;As a package author, you can&lt;/h2&gt;
&lt;h3 id=&#34;use-conservative-defaults&#34;&gt;Use conservative defaults&lt;/h3&gt;
&lt;p&gt;&amp;hellip;or provide user options to selectively turn off or extend these timers.  Packages for which responsiveness is a marquee feature generally do a good job of this.&lt;/p&gt;
&lt;h3 id=&#34;account-for-as-many-contexts-as-possible&#34;&gt;Account for as many contexts as possible&lt;/h3&gt;
&lt;p&gt;&amp;hellip;when writing packages.&lt;/p&gt;
&lt;p&gt;Elisp code doesn&amp;rsquo;t always run in the context that the author intends.  A &lt;a class=&#34;org-gls&#34; href=&#34;#gls-11&#34;&gt;mode-line&lt;/a&gt; update in one window can stagger image display in another.  In-buffer completion can slow down keyboard macro execution.  The more overarching the mode, the larger the surface area for these kinds of interactions.  The list of ways in which a sprawling library like Org+plugins can slow down Emacs (and vice-versa) is long and convoluted.  Few Emacs packages can afford the foresight to be, essentially, paranoid defensive drivers that guard against this unpredictable traffic.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;These examples are not hypothetical&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class=&#34;org-gls&#34; href=&#34;#gls-11&#34;&gt;mode-line&lt;/a&gt; update affecting image display: The first example was &lt;code&gt;pdf-tools&lt;/code&gt;&amp;rsquo;s &lt;code&gt;pdf-misc-size-indication-minor-mode&lt;/code&gt; freezing Emacs when updating LaTeX preview images in an unrelated buffer/window.&lt;/li&gt;
&lt;li&gt;The second is a completion-at-point front-end like Company slowing down playback when using &lt;a href=&#34;https://github.com/corytertel/macrursors&#34;&gt;Macrursors&lt;/a&gt;, a multiple-cursors emulator that uses keyboard macros.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h2 id=&#34;as-a-user-you-can&#34;&gt;As a user, you can:&lt;/h2&gt;
&lt;h3 id=&#34;report-slowdowns&#34;&gt;Report slowdowns&lt;/h3&gt;
&lt;p&gt;&amp;hellip;so package maintainer(s) can fix them.&lt;/p&gt;
&lt;p&gt;This is easier said than done.  Binary-searching your way by toggling active modes is tedious.  Profiler output can be mysterious without a good sense for how Emacs&amp;rsquo; command loop works.  A package like &lt;a href=&#34;https://github.com/lastquestion/explain-pause-mode&#34;&gt;explain-pause-mode&lt;/a&gt; does some of this work for you, but the causes can be subtle interactions.  Generally &amp;ndash; but not always &amp;ndash; if you are at the point where you can pinpoint causes of slowdowns, you can also avoid them without much trouble.&lt;/p&gt;
&lt;h3 id=&#34;use-fewer-packages&#34;&gt;Use fewer packages&lt;/h3&gt;
&lt;p&gt;Turn down the bling. Use less mud.&lt;/p&gt;
&lt;p&gt;The saner option.  Emacs&amp;rsquo; first-class extensibility, one of its biggest strengths, is also an inherent limitation.  A significant fraction of complaints I read about Emacs being too slow are usually the result of installing packages with wild abandon.  This results in busy, full-fat hooks (&lt;code&gt;post-command-hook&lt;/code&gt;, &lt;code&gt;post-self-insert-hook&lt;/code&gt;, &lt;code&gt;window-state-change-hook&lt;/code&gt;, …)
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Among many others, like major-mode hooks.  These hooks contain functions that run after every Emacs command, after typing in text, after window changes&amp;hellip; &lt;em&gt;i.e. all the time&lt;/em&gt;.
&lt;/small&gt;&lt;/span&gt;
that bring things to a crawl before long.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;All right!  That was the preamble.  Now that we&amp;rsquo;ve exhausted the &lt;em&gt;good&lt;/em&gt; options, we&amp;rsquo;re free to ignore the less-is-more approach to code today.  It&amp;rsquo;s time to be irresponsible and fix the giant mud ball by&amp;hellip; &lt;strong&gt;adding more mud&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&#34;timeouts-and-delays&#34;&gt;Timeouts and Delays&lt;/h2&gt;
&lt;p&gt;The problem common to both &amp;ldquo;push&amp;rdquo; and &amp;ldquo;pull&amp;rdquo; slowdowns is non-critical code running more often than it should.  Our no-context, no-Chesterton&amp;rsquo;s-fence solution is to force such code into a timeout.  There are two common ways of doing this, with different use patterns, and we&amp;rsquo;re going to implement both.&lt;/p&gt;
&lt;h3 id=&#34;first-up-throttle&#34;&gt;First up: &lt;strong&gt;Throttle&lt;/strong&gt;&lt;/h3&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/throttle_description.svg&#34; width=&#34;700px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Throttled code (&lt;code&gt;foo&lt;/code&gt;) is placed in a timeout after it runs once.  Attempts to run again for the duration of the timeout (the &amp;ldquo;Throttle time&amp;rdquo; above) are ignored.  See &lt;a href=&#34;https://redd.one/blog/debounce-vs-throttle&#34;&gt;this resource&lt;/a&gt; for an interactive explanation.&lt;/p&gt;
&lt;p&gt;In the context of Emacs, throttling works well for &amp;ldquo;&lt;a class=&#34;org-gls&#34; href=&#34;#gls-9&#34;&gt;pull operations&lt;/a&gt;&amp;rdquo;, i.e. code that runs non-interactively and independent of user input
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Typically this means messing with timers, which is generally &lt;em&gt;a bad idea&lt;/em&gt;&amp;hellip; but we covered all the good solutions already, didn&amp;rsquo;t we?
&lt;/small&gt;&lt;/span&gt;
.  Throttling user commands (or their consequents) leads to state changes being completely ignored, which is rarely what we want.&lt;/p&gt;
&lt;p&gt;Of course, if packages with over-eager timers allow for customizable eagerness, then the simpler solution is to tweak the frequency directly.  Packages that implement &amp;ldquo;&lt;a class=&#34;org-gls&#34; href=&#34;#gls-9&#34;&gt;pull operations&lt;/a&gt;&amp;rdquo; are generally conscientious about this.  If something is running far more often than it should, searching for the variable(s) &lt;code&gt;&amp;lt;package-name&amp;gt;-*-delay&lt;/code&gt; or  &lt;code&gt;&amp;lt;package-name&amp;gt;-*-timer&lt;/code&gt; is a good start to fixing it.  Further, these actions typically run on &lt;a class=&#34;org-gls&#34; href=&#34;#gls-6&#34;&gt;idle timers&lt;/a&gt;, which is like a built-in debounce and unlikely to block Emacs in a perceptible way.&lt;/p&gt;
&lt;p&gt;But there are many exceptions.  What we&amp;rsquo;d like, in the absence of a provided dial for tuning this, is an elisp function or macro that can easily &amp;ndash; and generically &amp;ndash; &lt;em&gt;throttle&lt;/em&gt; any other elisp function.&lt;/p&gt;
&lt;h3 id=&#34;second-debounce&#34;&gt;Second: &lt;strong&gt;Debounce&lt;/strong&gt;&lt;/h3&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/debounce-description.svg&#34; width=&#34;700px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Debounced code (&lt;code&gt;foo&lt;/code&gt;) runs after a pre-specified delay from when it is called (the &amp;ldquo;Debounce time&amp;rdquo; above).  If the command is called again before the delay ends, it resets to its full duration.  See &lt;a href=&#34;https://redd.one/blog/debounce-vs-throttle&#34;&gt;this resource&lt;/a&gt; for an interactive explanation.&lt;/p&gt;
&lt;p&gt;In the context of Emacs, debouncing makes more sense with &amp;ldquo;&lt;a class=&#34;org-gls&#34; href=&#34;#gls-8&#34;&gt;push operations&lt;/a&gt;&amp;rdquo;.  Debounced user commands are ignored when there are too many calls in quick succession, except for the last one.  This is typically what we want in an interactive context, since the intermediate states from running each call would have been invalidated by the next call anyway.&lt;/p&gt;
&lt;p&gt;Again, we want an elisp function or macro that can easily &amp;ndash; and generically &amp;ndash; &lt;em&gt;debounce&lt;/em&gt; any other elisp function.&lt;/p&gt;
&lt;h3 id=&#34;aside-memoize&#34;&gt;Aside: &lt;strong&gt;Memoize&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;i.e.&lt;/em&gt; just caching &amp;ndash; store the results of expensive calculations and use a look-up table instead.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Emacs 29+ includes a handy &lt;code&gt;with-memoization&lt;/code&gt; macro to facilitate this for any chunk of code.
&lt;/small&gt;&lt;/span&gt;
We do a bit of caching with the throttle implementation below.  But in general this doesn&amp;rsquo;t work for our purposes because the functions we want to use this with are rarely pure &amp;ndash; they work by side-effect using (and on) Emacs&amp;rsquo; current state as a potential input.  So there&amp;rsquo;s no way to provide a generic memoization routine without knowing what the specific code in question is doing.&lt;/p&gt;
&lt;h2 id=&#34;throttle-and-debounce&#34;&gt;&lt;code&gt;throttle!&lt;/code&gt; and &lt;code&gt;debounce!&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;What we&amp;rsquo;d like: given a command or plain function &lt;code&gt;foo&lt;/code&gt;, modify it so that&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;throttle!&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;foo&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;2.0&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;throttles it to run no more than once every 2 seconds, and&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;debounce!&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;foo&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.5&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;debounces it to run with a delay of 0.5 seconds.&lt;/p&gt;
&lt;p&gt;We can also envision the safer, &amp;ldquo;non-destructive&amp;rdquo; versions
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Although our versions of &lt;code&gt;throttle!&lt;/code&gt; (etc) won&amp;rsquo;t be destructive because of Emacs&amp;rsquo; robust advice system.
&lt;/small&gt;&lt;/span&gt;
that return new functions, so we could do&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;fset&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;foo-throttled&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;foo&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;2.0&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;fset&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;foo-debounced&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;debounce&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;foo&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.5&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This turns out to actually be trickier to do well (&lt;a href=&#34;#throttle-and-debounce-non-destructive-finagling&#34;&gt;see below&lt;/a&gt;).  For the in-place versions, we can rely on Emacs&amp;rsquo; advice system to do most of the work for us.&lt;/p&gt;
&lt;p&gt;Before we implement &lt;code&gt;throttle!&lt;/code&gt; and &lt;code&gt;debounce!&lt;/code&gt;, let&amp;rsquo;s look at the kinds of thing we&amp;rsquo;d like to do with them.&lt;/p&gt;
&lt;h3 id=&#34;example-throttle-smart-mode-line-updates&#34;&gt;Example: throttle &lt;code&gt;smart-mode-line&lt;/code&gt; updates&lt;/h3&gt;
&lt;p&gt;Updating the &lt;a class=&#34;org-gls&#34; href=&#34;#gls-11&#34;&gt;mode-line&lt;/a&gt; display is one of the exceptions I mentioned in the &lt;a href=&#34;#first-up-throttle&#34;&gt;throttle description&lt;/a&gt;.  Typically the &lt;a class=&#34;org-gls&#34; href=&#34;#gls-11&#34;&gt;mode-line&lt;/a&gt; is updated along with &lt;a class=&#34;org-gls&#34; href=&#34;#gls-10&#34;&gt;redisplay&lt;/a&gt;, and Emacs is quite fast at handling all display elements that Emacs has C-level support for (typically the &lt;code&gt;%&lt;/code&gt;-prefixed &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/_0025_002dConstructs.html&#34;&gt;format specifiers&lt;/a&gt;).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;For efficiency, Emacs does not continuously recompute each window’s mode line and header line.  It does so when circumstances appear to call for it—for instance, if you change the window configuration, switch buffers, narrow or widen the buffer, scroll, or modify the buffer.&lt;/p&gt;
&lt;div class=&#34;attribution&#34;&gt;
&lt;p&gt;&amp;ndash;&lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Mode-Line-Basics.html&#34;&gt; Mode Line Basics&lt;/a&gt;, elisp manual.&lt;/p&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;ol&gt;
&lt;li&gt;The problem is that it appears to compute &lt;em&gt;every&lt;/em&gt; element on the &lt;a class=&#34;org-gls&#34; href=&#34;#gls-11&#34;&gt;mode-line&lt;/a&gt; under &lt;em&gt;any&lt;/em&gt; of these circumstances.&lt;/li&gt;
&lt;li&gt;You can evaluate arbitrary Lisp code during a &lt;a class=&#34;org-gls&#34; href=&#34;#gls-11&#34;&gt;mode-line&lt;/a&gt; update, and we sure do like to stuff the Emacs &lt;a class=&#34;org-gls&#34; href=&#34;#gls-11&#34;&gt;mode-line&lt;/a&gt; with fancy widgets in &lt;code&gt;:eval&lt;/code&gt; blocks.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The combination of these two facts is a recipe for slowdown.&lt;/p&gt;
&lt;p&gt;Case in point: the &lt;code&gt;smart-mode-line&lt;/code&gt; package uses the function &lt;code&gt;sml/generate-minor-modes&lt;/code&gt; to display active minor-modes in the &lt;a class=&#34;org-gls&#34; href=&#34;#gls-11&#34;&gt;mode-line&lt;/a&gt; with rich formatting.  Generating this string
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
A rather plain one too, despite support for rich text.
&lt;/small&gt;&lt;/span&gt;
takes up to 10% of Emacs&amp;rsquo; time during routine text-editing.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/sml-minor-mode-string-annotated.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;As the Emacs profiler illustrates:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Samples   %    Function
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;---------------------------------------------
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   1076  65% - redisplay_internal (C function)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    705  43%  + jit-lock-function
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    404  22%  - eval
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    220  13%   + and-let*
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;--&amp;gt; 166   9%   + sml/generate-minor-modes   &amp;lt;-- PRE-THROTTLE
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      4   0%     sml/generate-modified-status
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     52   3% - ...
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     52   3%    Automatic GC
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Recomputing the minor-modes string after every buffer insertion or window scroll is a waste.  We&amp;rsquo;re actually fine so long as it&amp;rsquo;s updated soon after a minor-mode is enabled or disabled.  So we throttle this function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; only allowed to run once every 4 seconds.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;throttle!&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;sml/generate-minor-modes&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;4.0&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This frees up Emacs to do other things.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Samples    %   Function
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;----------------------------------------
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   1482  66% - redisplay_internal (C function)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    733  33%  - eval
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    681  30%   + and-let*
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     17   0%     sml/generate-modified-status
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;--&amp;gt;   9   0%   + sml/generate-minor-modes   &amp;lt;-- POST-THROTTLE
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      6   0%   + format
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    700  31%  + jit-lock-function
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    117   5% - ...
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    117   5%    Automatic GC
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Throttling lets us work around, in a coarse way, our lack of control over the &lt;a class=&#34;org-gls&#34; href=&#34;#gls-11&#34;&gt;mode-line&lt;/a&gt; update logic.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Throttle vs Debounce&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;In this example, using a debounce would have worked too&amp;hellip; for the most part.  There would be scenarios where it wouldn&amp;rsquo;t work well, though, such as turning on/off a minor mode and then immediately scrolling the window or typing.  If we can tolerate slightly-out-of-date reports of Emacs&amp;rsquo; state, throttling is generally the better option.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;example-debounce-org-agenda-follow-mode&#34;&gt;Example: debounce &lt;code&gt;org-agenda-follow-mode&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;An example of an Org-mode feature that&amp;rsquo;s too eager for its own good:  when following along entries with a preview in the Org Agenda, running down the list to the next item you&amp;rsquo;re interested in causes previews to be generated for each intermediate item (first video).  Org does a fair bit of work &amp;ndash; relative to the cursor movement speed - to set up the preview display, causing Emacs to hitch.&lt;/p&gt;
&lt;div class=&#34;wide&#34;&gt;
&lt;div class=&#34;column&#34;&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/org-agenda-no-debounce.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/org-agenda-no-debounce.mp4&#34;&gt;[Video: org-agenda without a debounce]&lt;/a&gt;&lt;/video&gt;
&lt;/div&gt;
&lt;div class=&#34;column&#34;&gt;
&lt;video preload=&#34;metadata&#34; style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/org-agenda-debounce.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/org-agenda-debounce.mp4&#34;&gt;[Video: org-agenda with a debounce]&lt;/a&gt;&lt;/video&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s debounce this feature:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; run after a resettable delay of 0.3 seconds.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;debounce!&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-agenda-do-context-action&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.3&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Throwing in a debounce causes the intermediate cursor positions to be ignored (second video), making the process smoother and less visually noisy while keeping Emacs responsive.&lt;/p&gt;
&lt;p&gt;Debouncing lets us work around, in a coarse way, user input that&amp;rsquo;s coming too fast to be smoothly acted on.&lt;/p&gt;
&lt;h3 id=&#34;an-inside-out-implementation&#34;&gt;An inside-out implementation&lt;/h3&gt;
&lt;p&gt;To implement &lt;code&gt;throttle!&lt;/code&gt; and &lt;code&gt;debounce!&lt;/code&gt;, we can work our way outwards from the specification of what throttles and debounces should do.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;But before we dig in&amp;#x2026;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;This is primarily a fun elisp exercise.&lt;/p&gt;
&lt;p&gt;If you are considering throttling elisp from outside of packages as an actual solution to addressing performance issues, you should have already tried the better options listed at the start of this write-up.  We don&amp;rsquo;t play with mud balls without getting our hands dirty.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;A throttled function will:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Run when first called,&lt;/li&gt;
&lt;li&gt;and start keeping time.&lt;/li&gt;
&lt;li&gt;If called again within the timeout period,&lt;/li&gt;
&lt;li&gt;it refuses to run or returns immediately.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The core of this idea is captured in this thunk:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; FUNC is the function to be throttled, called with arguments ARGS&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; TIMEOUT is the throttle duration&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; If the timer is running&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;;; do nothing, return nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; else run and start the timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;prog1&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;run-with-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             &lt;span style=&#34;color:#888&#34;&gt;;; clear the timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#963&#34;&gt;cancel-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;where &lt;code&gt;throttle-timer&lt;/code&gt; and &lt;code&gt;timeout&lt;/code&gt; need to be persistent between calls to this function.&lt;/p&gt;
&lt;p&gt;The debounce version is built similarly.  A debounced function will:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Not run immediately, and start a timer when first called.&lt;/li&gt;
&lt;li&gt;If called again before the timer expires,&lt;/li&gt;
&lt;li&gt;the timer is reset and starts over.&lt;/li&gt;
&lt;li&gt;If the timer ends, the function finally runs.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The core of this process is captured in the following thunk:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; FUNC is the function to be throttled, called with arguments ARGS&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; DELAY is the debounce period&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; If the timer is running&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;;; Do not run the function, reset the timer instead&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;timer-set-idle-time&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; start the timer over&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;run-with-idle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#888&#34;&gt;;; Timer ran, finally run the function&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;where &lt;code&gt;debounce-timer&lt;/code&gt; and &lt;code&gt;delay&lt;/code&gt; need to be persistent between calls to this function.  We use an idle-timer when debouncing, and a regular timer for the throttle.  Using an &lt;a class=&#34;org-gls&#34; href=&#34;#gls-6&#34;&gt;idle timer&lt;/a&gt; here is technically incorrect, but the better choice since &lt;code&gt;func&lt;/code&gt; is presumably an expensive call.  The throttle timer only has to clear itself, which is cheap.&lt;/p&gt;
&lt;p&gt;Next, we need to wrap these in a function that effectively acts as the throttled/debounced &lt;code&gt;func&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;warning&#34;&gt;
&lt;p&gt;If you are trying this in Emacs, be sure to &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html&#34;&gt;turn on&lt;/a&gt; &lt;code&gt;lexical-binding&lt;/code&gt; first.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a id=&#34;code-snippet--throttled-closure&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1.0&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Run with a throttle.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;;; do nothing, return nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#888&#34;&gt;;; else run and start the timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;prog1&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;run-with-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#888&#34;&gt;;; clear the timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#963&#34;&gt;cancel-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;))))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;throttle-timer&lt;/code&gt; and &lt;code&gt;timeout&lt;/code&gt; are now defined in the enclosing environment.  Provided &lt;code&gt;lexical-binding&lt;/code&gt; is turned on, the inner lambda is a closure and these two objects will be persistent across calls to this closure.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;func&lt;/code&gt; is still undefined/free.  We place the above code into a &amp;ldquo;throttle-maker&amp;rdquo; function that &amp;ldquo;closes over&amp;rdquo; &lt;code&gt;func&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Return a throttled version of FUNC.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;It runs at most once every TIMEOUT seconds (default 1.0).&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1.0&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;prog1&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;run-with-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#963&#34;&gt;cancel-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)))))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note that this is the &amp;ldquo;non-destructive&amp;rdquo; version, it returns a new function instead of modifying &lt;code&gt;func&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;While we&amp;rsquo;re at it, we can return the previous result instead of &lt;code&gt;nil&lt;/code&gt; during the throttle duration.  This is unimportant for top-level interactive commands, but might at least help avoid type errors if this is a pure function, or if we&amp;rsquo;re monkey-patching something deep inside an elisp library.&lt;/p&gt;
&lt;p&gt;We effectively memoize the &lt;code&gt;result&lt;/code&gt; of calling &lt;code&gt;func&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Return a throttled version of FUNC.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;It runs at most once every TIMEOUT seconds (default 1.0).&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1.0&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;prog1&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;run-with-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#963&#34;&gt;cancel-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)))))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The debounce version is similar, but there&amp;rsquo;s nowhere to return the &lt;code&gt;result&lt;/code&gt; to this time.  &lt;code&gt;func&lt;/code&gt; may be called from anywhere in the code but runs (eventually, via the timer) at top-level, so it doesn&amp;rsquo;t make sense to store its return value.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
We also couldn&amp;rsquo;t if we wanted to, since the return value doesn&amp;rsquo;t exist yet.
&lt;/small&gt;&lt;/span&gt;
To satisfy the calling code, we can prespecify a constant return value when constructing the function.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s a new wrinkle as well: the throttled &lt;code&gt;func&lt;/code&gt; runs immediately or not at all.  The debounced &lt;code&gt;func&lt;/code&gt;, however, runs at a later time when the environment can be different &amp;ndash; or invalid.  So we need to capture as much of the current context as we can and restore it when &lt;code&gt;func&lt;/code&gt; runs.  Capturing the full context at call time is not possible (it could be anything)
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
As far as I know.  This might be possible in other Lisps with continuations, etc.
&lt;/small&gt;&lt;/span&gt;
, but we can set the active buffer at least.&lt;/p&gt;
&lt;p&gt;Adding a &lt;code&gt;default&lt;/code&gt; &amp;ldquo;immediate-return&amp;rdquo; value and the calling context, we get&lt;/p&gt;
&lt;p&gt;&lt;a id=&#34;code-snippet--debounced-closure&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;default&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Return a debounced version of FUNC.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;It runs with a delay of DELAY seconds (default 0.5).
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;DEFAULT is the immediate return value of the function when
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;called.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.5&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;timer-set-idle-time&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;prog1&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;default&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;run-with-idle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;with-current-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt; &lt;span style=&#34;color:#888&#34;&gt;;set buffer when running&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;current-buffer&lt;/span&gt;))))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We&amp;rsquo;re on the right track, but there are many issues with &lt;code&gt;throttle&lt;/code&gt; and &lt;code&gt;debounce&lt;/code&gt; above:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The generated closures don&amp;rsquo;t have &lt;code&gt;interactive&lt;/code&gt; forms, so they cannot be run as commands.  We can&amp;rsquo;t add interactive forms unconditionally, since we might want to throttle/debounce non-interactive functions too.&lt;/li&gt;
&lt;li&gt;The generated closures don&amp;rsquo;t have any documentation.  Assigning them to variables with &lt;code&gt;fset&lt;/code&gt; will leave them (mostly) non-introspectable.&lt;/li&gt;
&lt;li&gt;Most importantly, we wanted a &lt;code&gt;throttle!&lt;/code&gt; and &lt;code&gt;debounce!&lt;/code&gt; to corral existing errant elisp code, not generate new, quieter variants.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It turns out most of these issues can be resolved in one go, with some&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;advising-around&#34;&gt;Advising around&lt;/h3&gt;
&lt;p&gt;We have on hand our throttled and debounced versions of &lt;code&gt;func&lt;/code&gt;, albeit lacking some niceties.  To replace &lt;code&gt;func&lt;/code&gt; with these variants, we will depend on Emacs&amp;rsquo; advice system.  We&amp;rsquo;re specifically looking for a recipe that routes around &lt;code&gt;func&lt;/code&gt; while letting us call it when necessary.  The &lt;code&gt;:around&lt;/code&gt; advice combinator fits the bill:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;‘:around’&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Call &lt;code&gt;FUNCTION&lt;/code&gt; instead of the old function, but provide the old function as an extra argument to &lt;code&gt;FUNCTION&lt;/code&gt;. This is the most flexible composition. For example, it lets you call the old function with different arguments, or many times, or within a let-binding, or &lt;strong&gt;you can sometimes delegate the work to the old function and sometimes override it completely&lt;/strong&gt;. More specifically, the composition of the two functions behaves like:
&lt;code&gt;(lambda (&amp;amp;rest r) (apply FUNCTION OLDFUN r))&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;-Manual section on Advice Combinators (emphasis mine)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This time let&amp;rsquo;s work our way outside-in.  The basic idea is:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Define a function that accepts as arguments the original function (&lt;code&gt;oldfun&lt;/code&gt;) and &lt;em&gt;its&lt;/em&gt; arguments.&lt;/li&gt;
&lt;li&gt;Add this as &lt;code&gt;:around&lt;/code&gt; advice to &lt;code&gt;oldfun&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Emacs runs this function instead of &lt;code&gt;oldfun&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;!--listend--&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;newfun&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;oldfun&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; do stuff&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;predicate&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;oldfun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#888&#34;&gt;;; do something else&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;foo&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;advice-add&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;oldfun&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:around&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;newfun&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Our &lt;code&gt;newfun&lt;/code&gt; is the generated closure (&lt;a href=&#34;#code-snippet--throttled-closure&#34;&gt;throttled&lt;/a&gt; or &lt;a href=&#34;#code-snippet--debounced-closure&#34;&gt;debounced&lt;/a&gt;) from the previous section.  Here&amp;rsquo;s the same throttled closure as before, but following the above pattern instead:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1.0&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;oldfun&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Throttle this function.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;prog1&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;oldfun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;run-with-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#963&#34;&gt;cancel-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;))))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This closure, intended as &lt;code&gt;:around&lt;/code&gt; advice, accepts &lt;code&gt;oldfun&lt;/code&gt; as an argument along with &lt;code&gt;args&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This time there&amp;rsquo;s nothing to &amp;ldquo;close over&amp;rdquo; save the (customizable) &lt;code&gt;timeout&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle--advice&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1.0&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;oldfun&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Throttle this function.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;prog1&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;oldfun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;run-with-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#963&#34;&gt;cancel-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)))))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;throttle--advice&lt;/code&gt; is an &amp;ldquo;advice maker&amp;rdquo; that, when called with a timeout, returns an &amp;ldquo;advice function&amp;rdquo; that throttles the function it advises. Phew!&lt;/p&gt;
&lt;p&gt;Of course, we need to actually add this advice:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;advice-add&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;foo&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:around&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;throttle--advice&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1.0&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This advice (closure) is nameless &amp;ndash; we require a way to refer to it so that we can restore &lt;code&gt;foo&lt;/code&gt; to its un-throttled, over-eager, Emacs-blocking state.  We should also add this advice &lt;em&gt;last&lt;/em&gt;, in that any other advice placed on &lt;code&gt;foo&lt;/code&gt; should take precedence &amp;ndash; the result of throttling the function would be unpredictable otherwise.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;advice-add&lt;/code&gt; provides the machinery to do both these things:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;advice-add&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;foo&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:around&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;throttle--advice&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1.0&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;((&lt;span style=&#34;color:#963&#34;&gt;name&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;depth&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-99&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Wrapping up this action in a function (finally) gives us the &lt;code&gt;throttle!&lt;/code&gt; we are looking for:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle!&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;advice-remove&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;func&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;throttle&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;advice-add&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:around&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;throttle--advice&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;((&lt;span style=&#34;color:#963&#34;&gt;name&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                  (&lt;span style=&#34;color:#963&#34;&gt;depth&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-99&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Instead of defining an &lt;code&gt;unthrottle!&lt;/code&gt;, we make it so passing a &lt;code&gt;timeout&lt;/code&gt; of &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;throttle!&lt;/code&gt; restores the original function.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;debounce!&lt;/code&gt; works the exact same way:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; advice-maker&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce--advice&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;default&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.5&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;oldfun&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Debounce this function.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;timer-set-idle-time&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;prog1&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;default&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;run-with-idle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;with-current-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;oldfun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;current-buffer&lt;/span&gt;))))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; advice-adder or remover&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce!&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;advice-remove&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;debounce&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;advice-add&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:around&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;debounce--advice&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;((&lt;span style=&#34;color:#963&#34;&gt;name&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                  (&lt;span style=&#34;color:#963&#34;&gt;depth&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-98&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;debounce--advice&lt;/code&gt; is an &amp;ldquo;advice maker&amp;rdquo; that, when called with a delay, returns an &amp;ldquo;advice function&amp;rdquo; that debounces the function it advises.  &lt;code&gt;debounce!&lt;/code&gt; can then add or remove this advice function to its argument.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Fortuitously, the other two problems &amp;ndash; mirroring the interactive spec and adding function documentation &amp;ndash; have worked themselves out.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Advice functions that don&amp;rsquo;t have an interactive spec &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Core-Advising-Primitives.html&#34;&gt;will reuse&lt;/a&gt; that of the function they are advising.&lt;/li&gt;
&lt;li&gt;The documentation of the original function is still available, with a note about the advice at the end.  This note is the documentation of the advice function itself, &lt;em&gt;i.e.&lt;/em&gt; &amp;ldquo;Throttle this function&amp;rdquo;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;top-level-vs-nested-calls-what-can-we-timeout&#34;&gt;Top-level vs nested calls: what can we timeout?&lt;/h2&gt;
&lt;p&gt;A short digression on Emacs&amp;rsquo; command loop.&lt;/p&gt;
&lt;p&gt;Throttling or debouncing code that runs at top-level, such as user commands or timers, is simple.  Since there&amp;rsquo;s nothing for them to &amp;ldquo;return to&amp;rdquo;, introducing delays or (effectively) refusing to run code has no consequences beyond a delay in the corresponding library&amp;rsquo;s understanding of Emacs&amp;rsquo; current state.&lt;/p&gt;
&lt;p&gt;Things get tricky when we mess with &amp;ldquo;internal&amp;rdquo; code.  Often it&amp;rsquo;s not user commands themselves that need debouncing, but something heavy lurking well inside a hook that runs as a result of the command.  Our throttle example above (&lt;code&gt;sml/generate-minor-modes&lt;/code&gt;) is a &amp;ldquo;hook function&amp;rdquo; triggered by &lt;a class=&#34;org-gls&#34; href=&#34;#gls-11&#34;&gt;mode-line&lt;/a&gt; updates.  Our debounce example (&lt;code&gt;org-agenda-do-context-action&lt;/code&gt;) is a function called from deep inside the &lt;code&gt;org-agenda&lt;/code&gt; machinery when the cursor moves.  Since&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;throttled functions can return &lt;code&gt;nil&lt;/code&gt; or repeat a previous result, and&lt;/li&gt;
&lt;li&gt;debounced functions always return &lt;code&gt;nil&lt;/code&gt; immediately,&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;we require &lt;code&gt;nil&lt;/code&gt; to be (at minimum) a valid return value wherever they are called, and (better) a value that stops further processing in the moment.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Picking a different return value&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;The same is true for any other &lt;code&gt;non-nil&lt;/code&gt; value we choose to return (&lt;a href=&#34;#code-snippet--debounced-closure&#34;&gt;see implementation&lt;/a&gt;).  Reusing return values from past calls to debounced functions is not possible without setting up global variables&amp;hellip;  which is a project for another time.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Having throttled and debounced a bunch of internal functions now, I can report that this is generally true of elisp code that needs a timeout, so long as a little care is exercised in picking them.&lt;/p&gt;
&lt;h2 id=&#34;throttle-and-debounce-non-destructive-finagling&#34;&gt;&lt;code&gt;throttle&lt;/code&gt; and &lt;code&gt;debounce&lt;/code&gt;: Non-destructive finagling&lt;/h2&gt;
&lt;p&gt;So why is:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;fset&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;foo-debounced&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;debounce&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;foo&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.5&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;difficult to pull off well?&lt;/p&gt;
&lt;p&gt;We have the basic skeleton in place &lt;a href=&#34;#code-snippet--debounced-closure&#34;&gt;from before&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;default&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Return a debounced version of FUNC.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;It runs with a delay of DELAY seconds (default 0.5).
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;DEFAULT is the immediate return value of the function when
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;called.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.5&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;timer-set-idle-time&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;prog1&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;default&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;run-with-idle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;with-current-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt; &lt;span style=&#34;color:#888&#34;&gt;;set buffer when running&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;current-buffer&lt;/span&gt;))))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The problems are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Mirroring the interactive form of &lt;code&gt;func&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Documenting the unnamed closure that &lt;code&gt;debounce&lt;/code&gt; returns.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;mirroring-interactive-forms&#34;&gt;Mirroring &lt;code&gt;interactive&lt;/code&gt; forms&lt;/h4&gt;
&lt;p&gt;We can lean on the advice system again for the former, but it&amp;rsquo;s ugly.  We essentially write both versions of the function and pick one.  Here&amp;rsquo;s &lt;code&gt;throttle&lt;/code&gt;:&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Mirroring interactive forms: &lt;code&gt;throttle&lt;/code&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;default&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Return a throttled version of function FUNC.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;THROTTLE defaults to 1 second.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;throttle&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;iform&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;interactive-form&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;default&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;iform&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#888&#34;&gt;;; INTERACTIVE version&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;advice-eval-interactive-spec&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#963&#34;&gt;cadr&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;iform&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                  (&lt;span style=&#34;color:#963&#34;&gt;run-with-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   &lt;span style=&#34;color:#963&#34;&gt;throttle&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#963&#34;&gt;cancel-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#888&#34;&gt;;; NON-INTERACTIVE version&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                  (&lt;span style=&#34;color:#963&#34;&gt;run-with-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   &lt;span style=&#34;color:#963&#34;&gt;throttle&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#963&#34;&gt;cancel-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)))))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;&lt;code&gt;debounce&lt;/code&gt; is similar.&lt;/p&gt;
&lt;h4 id=&#34;inserting-function-documentation&#34;&gt;Inserting function documentation&lt;/h4&gt;
&lt;p&gt;Named symbols can have function documentation inserted directly into their &lt;code&gt;function-documentation&lt;/code&gt; &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Standard-Properties.html&#34;&gt;symbol property&lt;/a&gt;.  Documenting unnamed closures programmatically is beyond me at this point &amp;ndash; unless of course, we embrace the idea that we&amp;rsquo;re writing code that writes code&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;it-s-macrotime&#34;&gt;It&amp;rsquo;s macrotime!&lt;/h3&gt;
&lt;p&gt;At this point it would actually be easier to get Emacs to write the code for us.  This process is much more accessible (if not simpler) with a macro.  We can fetch the relevant interactive form and documentation and shove them verbatim into the closure definition:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#888&#34;&gt;;; Add the documentation from FUNC with an extra note&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;documentation&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;format&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\n\nThis function is debounced -- it runs after a delay of %.3f seconds.&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; Add the interactive form from FUNC&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;interactive-form&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; Rest of the debounce code from above&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  )
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;While we&amp;rsquo;re at it, we can even skip the &lt;code&gt;fset&lt;/code&gt; step and just define the new function &lt;code&gt;func--debounced&lt;/code&gt; directly:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;intern&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-name&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;) &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;--debounced&amp;#34;&lt;/span&gt;)) (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#888&#34;&gt;;; Add the documentation from FUNC with an extra note&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;documentation&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;format&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\n\nThis function is debounced -- it runs after a delay of %.3f seconds.&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; Add the interactive form from FUNC&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;interactive-form&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; Rest of the debounce code from above&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  )
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Adding the lexical environment (for &lt;code&gt;debounce-timer&lt;/code&gt; etc) and the rest of the macro definition, we get&lt;/p&gt;
&lt;div class=&#34;warning&#34;&gt;
&lt;p&gt;If you are trying this in Emacs, be sure to &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html&#34;&gt;turn on&lt;/a&gt; &lt;code&gt;lexical-binding&lt;/code&gt; first.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defmacro&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Return a debounced version of function FUNC.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;DELAY defaults to 0.5 seconds.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.5&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;intern&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-name&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;) &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;--debounced&amp;#34;&lt;/span&gt;)) (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#888&#34;&gt;;; Add the documentation from FUNC with an extra note&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;documentation&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;format&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\n\nThis function is debounced -- it runs after a delay of %.3f seconds.&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#888&#34;&gt;;; Add the interactive form from FUNC&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;interactive-form&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;timer-set-idle-time&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;current-buffer&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;run-with-idle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#963&#34;&gt;delay&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#963&#34;&gt;cancel-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;debounce-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#007020&#34;&gt;with-current-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;))))))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This works as we intended, only the function name should no longer be quoted. The following code&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;debounce&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;next-line&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.4&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;expands to a definition for &lt;code&gt;next-line--debounced&lt;/code&gt;, replete with the correct documentation and &lt;code&gt;interactive&lt;/code&gt; behavior
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Or we could stick to the anonymous closure version and run &lt;code&gt;(fset &#39;next-line--debounced (debounce next-line))&lt;/code&gt;
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;p&gt;For completeness, here is &lt;code&gt;throttle&lt;/code&gt; as a macro:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defmacro&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;default&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Return a throttled version of function FUNC.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;TIMEOUT defaults to 1 second.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1.0&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;default&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;intern&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-name&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;) &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;--debounced&amp;#34;&lt;/span&gt;)) (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;documentation&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;format&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\n\nThis function is throttled -- it runs at most once every %.3f seconds.&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;interactive-form&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;timerp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;result&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;func&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;run-with-timer&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               &lt;span style=&#34;color:#963&#34;&gt;timeout&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#963&#34;&gt;cancel-timer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;throttle-timer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;))))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;questions&#34;&gt;Questions&lt;/h2&gt;
&lt;p&gt;A few concerns bubbled up on this excursion, and I don&amp;rsquo;t know how to address them:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Debouncing a function a few hundred times is easy to do just by holding down a key.  &lt;del&gt;This creates and destroys many timers &amp;ndash; I don&amp;rsquo;t know if the ensuing garbage is worth worrying about, and whether it can be avoided.&lt;/del&gt;
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
This is now avoided in the code, see acknowledgments.
&lt;/small&gt;&lt;/span&gt;
Here is the &lt;code&gt;atimer&lt;/code&gt; struct that Emacs uses:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-c&#34; data-lang=&#34;c&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;struct&lt;/span&gt; atimer
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#888&#34;&gt;/* The type of this timer.  */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;enum&lt;/span&gt; atimer_type type;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#888&#34;&gt;/* Time when this timer is ripe.  */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;struct&lt;/span&gt; timespec expiration;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#888&#34;&gt;/* Interval of this timer.  */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;struct&lt;/span&gt; timespec interval;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#888&#34;&gt;/* Function to call when timer is ripe.  Interrupt input is
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;        guaranteed to not be blocked when this function is called.  */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     atimer_callback fn;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#888&#34;&gt;/* Additional user-specified data to pass to FN.  */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#339;font-weight:bold&#34;&gt;void&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;*&lt;/span&gt;client_data;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#888&#34;&gt;/* Next in list of active or free atimers.  */&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#080;font-weight:bold&#34;&gt;struct&lt;/span&gt; atimer &lt;span style=&#34;color:#333&#34;&gt;*&lt;/span&gt;next;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   };
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is&amp;hellip; about 48 bytes of memory?  &lt;del&gt;Debouncing a command 200 times &amp;ndash; not an uncommon occurrence &amp;ndash; then creates at least 10KB of garbage.  How does this compare with the regular rate of garbage creation in Emacs?&lt;/del&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;How long does it take, realistically speaking, to create and clear timers?  Some testing suggests that this is not an insignificant number when done in bulk, especially coupled with garbage collection.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Using a macro to implement the &amp;ldquo;non-destructive&amp;rdquo; versions of &lt;code&gt;throttle!&lt;/code&gt; and &lt;code&gt;debounce!&lt;/code&gt; does not pair well with our functions &amp;ndash; the call signatures are different.  Perhaps there is a way to do this with functions that isn&amp;rsquo;t janky?&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;the-timeout-library&#34;&gt;The &lt;code&gt;timeout&lt;/code&gt; library&lt;/h2&gt;
&lt;p&gt;This functionality is available as an elisp package: &lt;a href=&#34;https://github.com/karthink/timeout&#34;&gt;timeout&lt;/a&gt;.  So far it&amp;rsquo;s exactly the code developed above, and just a couple of helper functions.&lt;/p&gt;
&lt;p&gt;Writing debouncers and throttlers this way wasn&amp;rsquo;t a careful design process on my part.  In fact, I have no idea how else I could write them in elisp.  This suggests that I don&amp;rsquo;t understand the problem very well, or don&amp;rsquo;t understand elisp well, or (more likely) both.  If you have corrections, suggestions or answers for me, please get in touch.&lt;/p&gt;
&lt;p&gt;All right then &amp;ndash; that&amp;rsquo;s it for me.  Gotta debounce!&lt;/p&gt;
&lt;details class=&#34;details apinote&#34; open style=&#34;font-size:0.8rem;margin-top:18px&#34;&gt;
&lt;summary&gt;Glossary&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;a name=&#34;gls-6&#34;&gt;Idle timer&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;An idle timer is some Lisp code scheduled to run when Emacs is idle for a specified period.  What it means for Emacs to be idle is complicated: at minimum, this means no user input, no subprocess communication and no non-idle timers that need running. [2 uses]&lt;/dd&gt;
&lt;dt&gt;&lt;a name=&#34;gls-11&#34;&gt;Mode-line&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;This is the &amp;ldquo;status bar&amp;rdquo; at the bottom of Emacs windows.  There are dozens of Emacs packages that prettify the mode-line, adding widgets and status reports.  I&amp;rsquo;ve found many of these to be too aggressive in how often they update. [10 uses]&lt;/dd&gt;
&lt;dt&gt;&lt;a name=&#34;gls-8&#34;&gt;Push operations&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;Slow elisp code that runs as a direct result of user input.  Example: an html preview of a markdown buffer that updates with each keystroke.  Less exreme examples: sending data to an LSP server when some code is yanked into a buffer, or a header-line update because the cursor moved into a new function.  So named because control of Emacs is &amp;ldquo;pushed&amp;rdquo; away as a result of the input action. [3 uses]&lt;/dd&gt;
&lt;dt&gt;&lt;a name=&#34;gls-9&#34;&gt;Pull operations&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;Slow elisp code that runs independent of user input, although it might be interrupted by it.  So named because control of Emacs is &amp;ldquo;pulled&amp;rdquo; away by this code irrespective of user input.  Examples: any idle timer not tied to user input, like RefTeX&amp;rsquo;s periodic scans of the LaTeX buffer.  Of course, ultimately everything that happens in Emacs is user-driven and thus a &amp;ldquo;push operation&amp;rdquo;.  This distinction is only one of proximity to the user. [3 uses]&lt;/dd&gt;
&lt;dt&gt;&lt;a name=&#34;gls-10&#34;&gt;Redisplay&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;This is the process of redrawing the screen, or more often parts of it, in Emacs.  Considering Emacs&amp;rsquo; terminal user interface and support for every platform under the sun, displaying is a complicated affair. [1 uses]&lt;/dd&gt;
&lt;/dl&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details open style=&#34;font-size:0.8rem;margin-top:12px&#34;&gt;
&lt;summary&gt;Acknowledgments&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Joseph Turner points out that &lt;code&gt;timerp&lt;/code&gt; handles the case when its argument is &lt;code&gt;nil&lt;/code&gt;, so there is no need to check explicitly, as in &lt;code&gt;(if (and debounce-timer (timerp debounce-timer)))&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Ihor Radchenko points out that timer attributes (such as the remaining time) can be modified in place with the &lt;code&gt;timer-set-*&lt;/code&gt; functions.  This completely fixes the problem of debounce timers generating a lot of garbage.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
</description>
    </item><item>
      <title>Persistent prefix keymaps in Emacs</title>
      <link>https://karthinks.com/software/persistent-prefix-keymaps-in-emacs/</link>
      <pubDate>Sun, 05 Mar 2023 15:22:00 -0800</pubDate>
      
      <guid>https://karthinks.com/software/persistent-prefix-keymaps-in-emacs/</guid>
      <description>&lt;p&gt;Or: Further Musings on the Tedium of Long Key-Chords.  In the past I&amp;rsquo;ve covered various bespoke approaches to the problem of repeating long key sequences: &lt;a href=&#34;https://github.com/magit/transient&#34;&gt;Transient&lt;/a&gt;, &lt;a href=&#34;https://github.com/abo-abo/hydra&#34;&gt;Hydra&lt;/a&gt;, &lt;a href=&#34;https://karthinks.com/software/it-bears-repeating/&#34;&gt;repeat-mode&lt;/a&gt; (and &lt;a href=&#34;https://tildegit.org/acdw/define-repeat-map.el&#34;&gt;repeat-mode&amp;rsquo;s helpers&lt;/a&gt;) 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.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;A quick glossary&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;keymap&lt;/code&gt;: A &lt;em&gt;&amp;ldquo;keymap&amp;rdquo;&lt;/em&gt; is an Emacs data structure that maps a collection of keybindings (&lt;em&gt;i.e.&lt;/em&gt; keyboard shortcuts) to commands.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;key-chord&lt;/code&gt;: This is a sequence of keys, some or all of which can require modifier keys to be held down. Examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;C-x C-f&lt;/code&gt; (&lt;code&gt;control + x&lt;/code&gt;, followed by &lt;code&gt;control + f&lt;/code&gt;), which runs the &lt;code&gt;find-file&lt;/code&gt; command&lt;/li&gt;
&lt;li&gt;&lt;code&gt;C-c @ C-t&lt;/code&gt; (&lt;code&gt;control + c&lt;/code&gt;, &lt;code&gt;@&lt;/code&gt;, followed by &lt;code&gt;control + t&lt;/code&gt;), which runs the command &lt;code&gt;outline-hide-body&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Needless to say, these can get pretty tedious for repeated invocations, even if you avoid the modifiers by using Vim-style leader keys.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;prefix-key&lt;/code&gt;: Any &amp;ldquo;incomplete&amp;rdquo; part of a &lt;code&gt;key-chord&lt;/code&gt; that will cause Emacs to wait for further keyboard input. In the above examples, &lt;code&gt;C-x&lt;/code&gt;, &lt;code&gt;C-c&lt;/code&gt; and &lt;code&gt;C-c @&lt;/code&gt; are all prefix keys.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;&lt;code&gt;repeat-mode&lt;/code&gt;, Hydra, Hercules and Transient all enable variations of the following interaction:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You (the user) define a special keymap &amp;ndash; a set of mappings from key bindings to commands,&lt;/li&gt;
&lt;li&gt;where the bindings are short and mnemonic/ergonomic,&lt;/li&gt;
&lt;li&gt;where the commands are related at some conceptual level in your mind,&lt;/li&gt;
&lt;li&gt;which are displayed in some kind of menu or table,&lt;/li&gt;
&lt;li&gt;and can be invoked in quick succession if required without exiting this menu.  Additionally,&lt;/li&gt;
&lt;li&gt;this menu (and associated editor state) can be enabled by using a dedicated keybinding, or&lt;/li&gt;
&lt;li&gt;(&lt;code&gt;repeat-mode&lt;/code&gt; only) by calling any one of these commands the long way.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The price you pay for this convenience is that you have to create this command group and specify the menu elements manually.  This is not a tall order if you only need a few such menus, and the results can be pretty neat.  In this situation these packages solve the tedium issue almost incidentally, since easing repetition is not even their primary purpose.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/repeat-help-toggle-transient.png&#34;
         alt=&#34;Figure 1: Pictured: A Transient for assorted tasks. Not pictured: Its long and messy definition.&#34; width=&#34;700px&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 1: &lt;/span&gt;Pictured: A Transient for assorted tasks. Not pictured: Its long and messy definition.&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;As I&amp;rsquo;ve &lt;a href=&#34;https://karthinks.com/software/it-bears-repeating/&#34;&gt;written at length&lt;/a&gt; before, Emacs&amp;rsquo; built-in &lt;code&gt;repeat-mode&lt;/code&gt; straddles the divide between requiring a bespoke menu with associated elisp configuration and a minimally specified approach to repeating commands.&lt;/p&gt;
&lt;p&gt;But Emacs is full of prefix maps, and we still don&amp;rsquo;t have the ability to enter a persistent state &amp;ndash; on the fly and &lt;em&gt;without premeditation&lt;/em&gt; &amp;ndash; where an arbitrary keymap can be &amp;ldquo;activated&amp;rdquo; until we are done running or repeating commands in this map.&lt;/p&gt;
&lt;p&gt;As it turns out, a 90% solution for this is actually really straightforward, no &lt;code&gt;repeat-mode&lt;/code&gt; needed. With some inspiration from Embark:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;repeated-prefix-help-command&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;when-let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;keys&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;this-command-keys-vector&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;prefix&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;seq-take&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;keys&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;1-&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;length&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;keys&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;orig-keymap&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;key-binding&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prefix&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;accept-default&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;copy-keymap&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;orig-keymap&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;exit-func&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;set-transient-map&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;which-key-abort&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt; [&lt;span style=&#34;color:#963&#34;&gt;remap&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;keyboard-quit&lt;/span&gt;]
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; () (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;) (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;exit-func&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;which-key--create-buffer-and-show&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prefix-help-command&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;repeated-prefix-help-command&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That&amp;rsquo;s all of it.  Here&amp;rsquo;s how it works:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;When you&amp;rsquo;ve typed &lt;em&gt;any&lt;/em&gt; prefix key (say &lt;code&gt;C-c @&lt;/code&gt;) and Emacs is waiting for further input, press &lt;code&gt;C-h&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Emacs now remembers whatever you&amp;rsquo;ve already typed, activates a &amp;ldquo;repeat state&amp;rdquo;
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
or &lt;code&gt;repeat-mode&lt;/code&gt;, as it were.  This is basically modal editing with bespoke modes.
&lt;/small&gt;&lt;/span&gt;
and a &lt;code&gt;which-key&lt;/code&gt; prompt/menu with available keybindings.&lt;/li&gt;
&lt;li&gt;You can now continue to call available commands in sequence without having to re-type the annoying prefix key.&lt;/li&gt;
&lt;li&gt;This state persists until you exit it with &lt;code&gt;C-g&lt;/code&gt; (bound to &lt;code&gt;keyboard-quit&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;
&lt;details open&gt;
&lt;summary&gt;Note:&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;&lt;code&gt;which-key&lt;/code&gt; is only a visual aid here &amp;ndash; this works if you replace it with a different prompter or if you remove it from the code entirely.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Here is a demo of creating a &amp;ldquo;repeat state&amp;rdquo; on the fly, in this case for the ever annoying &lt;code&gt;outline-minor-mode&lt;/code&gt; commands on the &lt;code&gt;C-c @&lt;/code&gt; prefix. (The keypresses are shown at the top of the window.)&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/repeated-prefix-help-command.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/repeated-prefix-help-command.mp4&#34;&gt;[Repeated-prefix demo]&lt;/a&gt;&lt;/video&gt;
&lt;p&gt;In principle, &lt;code&gt;repeated-prefix-help-command&lt;/code&gt; functions similar to &lt;code&gt;repeat-mode&lt;/code&gt;, but with one difference.  The latter requires that you specify beforehand which prefix keymaps should automatically enter the &amp;ldquo;repeat state&amp;rdquo;, and define maps that group together related commands if they don&amp;rsquo;t exist already.  The above method lacks this automaticity, but is more flexible: you can enter this state at any time (and for any keymap) with an additional keypress (here &lt;code&gt;C-h&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;&lt;code&gt;repeated-prefix-help-command&lt;/code&gt; also has an advantage over &lt;code&gt;repeat-mode&lt;/code&gt;: pressing keys that are not bound in the &amp;ldquo;repeat state&amp;rdquo; will cause &lt;code&gt;repeat-mode&lt;/code&gt; to end, and you will have to start over with the full, long key sequence to enter it again.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Although this can be remedied with some monkey patching. See &lt;a href=&#34;https://github.com/karthink/repeat-help&#34;&gt;repeat-help&lt;/a&gt;.
&lt;/small&gt;&lt;/span&gt;
The keymap we activate above stays active until we call &lt;code&gt;keyboard-quit&lt;/code&gt;, so we can freely mix regular Emacs editing commands and the ones we have temporary one-key access to.&lt;/p&gt;
&lt;p&gt;We could, of course, use both approaches together.  We are approaching peak laziness, but I don&amp;rsquo;t think we&amp;rsquo;re there yet!&lt;/p&gt;
</description>
    </item><item>
      <title>A Consistent Structural Editing Interface</title>
      <link>https://karthinks.com/software/a-consistent-structural-editing-interface/</link>
      <pubDate>Sat, 04 Feb 2023 21:02:00 -0800</pubDate>
      
      <guid>https://karthinks.com/software/a-consistent-structural-editing-interface/</guid>
      <description>&lt;p&gt;Emacs 29 is getting native Tree-Sitter support, and the buzz is hard to miss.&lt;/p&gt;
&lt;p&gt;Tree-Sitter maintains and provides a concrete parse tree of the buffer that you can query, but that&amp;rsquo;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&amp;rsquo;ve had structural editing packages popping up all over the place.&lt;/p&gt;
&lt;p&gt;Lisp modes in Emacs already have pretty good support for structural editing as the syntax is particularly simple: the code is its own parse tree
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Notwithstanding some Lisp reader shenanigans
&lt;/small&gt;&lt;/span&gt;
.  But for every other language this is just the beginning.  It&amp;rsquo;s going to take some work, but tree-sitter information is rich enough that over the next year or two of collective experimentation, I expect we&amp;rsquo;re going to see new editing paradigms emerge that could be to &lt;a href=&#34;http://paredit.org/&#34;&gt;paredit&lt;/a&gt; what paredit is to naïve Lisp editing.&lt;/p&gt;
&lt;p&gt;Considering my penchant for &lt;a href=&#34;https://karthinks.com/software/avy-can-do-anything/&#34;&gt;fussing over composability&lt;/a&gt;, I thought this might be a good time to make a short note about the UIs of structural editing packages.&lt;/p&gt;
&lt;p&gt;Comparing structural editing packages usually comes down to a question of keybindings: Are they accessible?  Mnemonic?  Tedious?  Modal?  Chainable?  Indeed, this is the subject of an extended example below.  But I&amp;rsquo;m more interested in how composable structural editing packages are at a more fundamental level: Is it a megalithic suite with a rigid user-facing interface, or a bag of tools you can pick from and combine with other Emacs features?&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;
Of course, every piece of elisp has a bag-of-tools nature if you&amp;rsquo;re not averse to some monkey patching, but brittle fixes crumble over time in unpleasant ways.  Moreover, it&amp;rsquo;s not always clear which approach is better.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s an incomplete and evolving picture of structural editing in Emacs:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/simple-structural-0001.svg&#34;/&gt;
&lt;/figure&gt;

&lt;details&gt;
&lt;summary&gt;An incomplete picture:&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Dashed lines: Support is being worked on or can be added with some configuration.&lt;/p&gt;
&lt;p&gt;It follows from the thesis of this write-up that this chart is out of date as you peruse it now. But it also elides many details for reasons of readability:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Most packages offer the obvious, modeless editing interface of calling individual commands directly, for instance with a keybinding or with &lt;code&gt;M-x&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Every structural editing package in the above list that is not made for &lt;code&gt;evil-mode&lt;/code&gt; has an adapter that allows it to be used with &lt;code&gt;evil-mode&lt;/code&gt;. (&lt;code&gt;evil-paredit&lt;/code&gt;, &lt;code&gt;evil-smartparens&lt;/code&gt;, &amp;hellip;) I included &lt;a href=&#34;https://github.com/noctuid/lispyville&#34;&gt;lispyville&lt;/a&gt; as an exmaple.&lt;/li&gt;
&lt;li&gt;Also not on the list: single-purpose structure editing commands like &lt;code&gt;expand-region&lt;/code&gt; or &lt;code&gt;embrace&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Emacs&amp;rsquo; &lt;code&gt;ppss&lt;/code&gt; (parse partial s-expression) parser as used here is a catchall for parsing the old way, through a combination of regexp searching and using &lt;code&gt;syntax-ppss&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h2 id=&#34;parsers-editing-suites-and-user-interfaces&#34;&gt;Parsers, Editing Suites and User Interfaces&lt;/h2&gt;
&lt;p&gt;The &lt;span class=&#34;Green&#34;&gt;Parser&lt;/span&gt;: Emacs&amp;rsquo; homegrown &lt;code&gt;ppss&lt;/code&gt; (parse partial s-expression) parser and its regexp-scan based cousins are workhorses that are available across many major modes.  But if you&amp;rsquo;ve ever tried the &lt;code&gt;mark-defun&lt;/code&gt; or &lt;code&gt;forward-sexp&lt;/code&gt; commands in a non-Lisp buffer you&amp;rsquo;ll have noticed how inconsistent it can be.  Until now, structural editing in non-Lisp modes has had to rely on this mix of &lt;code&gt;ppss&lt;/code&gt; and bespoke regexp scans of the buffer.  The addition of tree-sitter-based parsing is going to be a massive upgrade in consistency.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;Purple&#34;&gt;Structural Editing&lt;/span&gt; packages: Along with old favorites like &lt;a href=&#34;http://paredit.org/&#34;&gt;paredit&lt;/a&gt; and &lt;a href=&#34;https://github.com/abo-abo/lispy&#34;&gt;lispy&lt;/a&gt;, we now have the fledgling entries I included in the chart: &lt;a href=&#34;https://github.com/AmaiKinono/puni&#34;&gt;puni&lt;/a&gt;, &lt;a href=&#34;https://github.com/mickeynp/combobulate&#34;&gt;combobulate&lt;/a&gt;, &lt;a href=&#34;https://github.com/haritkapadia/ts-movement&#34;&gt;ts-movement&lt;/a&gt; and so on.  Not all of these are tree-sitter based, although I expect they will all eventually support it, or be supplanted in usage by packages that do.&lt;/p&gt;
&lt;p&gt;The &lt;span class=&#34;Orange&#34;&gt;Editing Interface&lt;/span&gt;: As provided or supported by the structural editing package.  A distinction that most packages don&amp;rsquo;t (and often shouldn&amp;rsquo;t) make, but is the focus of my attention here:&lt;/p&gt;
&lt;p&gt;Packages like lispy and &lt;a href=&#34;https://github.com/drym-org/symex.el&#34;&gt;symex&lt;/a&gt; are end-to-end solutions, with a defined vision of the best way for users to interact with them.  This is expressed through both the kinds of verbs they afford, with editing actions like &lt;code&gt;convolute&lt;/code&gt;, &lt;code&gt;flow&lt;/code&gt; and &lt;code&gt;stringify&lt;/code&gt;, and how these are made available and invoked &amp;ndash; contextually based on the cursor position with lispy, and through a special editing mode with symex.  These are customizable in the sense that you can move the keybindings around, but not change the editing paradigm or interface itself. It&amp;rsquo;s our way, the highway, or defadvice away.  The advantage is that these are plug and play solutions
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Or plug, practice, practice, practice and play.
&lt;/small&gt;&lt;/span&gt;
, and very capable out of the box.  You must adapt to it, but it&amp;rsquo;s fast and intuitive afterwards.&lt;/p&gt;
&lt;p&gt;Packages like smartparens and paredit are more restrained in their preferences: They offer a set of verbs that you can bind to keys as you please, with more levers to tweak their behavior.&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;   These packages also tend to be more singular in their focus: they don&amp;rsquo;t ship with commands to view docstrings inline or interact with the elisp debugger, like lispy does.  They&amp;rsquo;re not all-encompassing editing &amp;ldquo;suites&amp;rdquo;, just participants in your editing experience.  The advantage is malleability: they can adapt to you, and you pick only what you need.  There are no nasty surprises along the way.  They can change as your editing needs do.&lt;/p&gt;
&lt;p&gt;To make my point about this difference in their design philosophies, the rest of this write-up is an extended example of the malleability gap. We try to create a uniform and consistent interface for structural editing irrespective of the package being used.&lt;/p&gt;
&lt;h2 id=&#34;example-a-lispy-lite-without-lispy&#34;&gt;Example: A lispy-lite without lispy&lt;/h2&gt;
&lt;p&gt;One of the advantages of a specialized mode for structural edits is that the keybindings become much simpler &amp;ndash; no chords needed &amp;ndash; and editing is smoother and faster.  Indeed, this is touted as the main feature of lispy:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This package reimagines Paredit - a popular method to navigate and edit LISP code in Emacs.
The killer-feature are the short bindings [&amp;hellip;]
Most of more than 100 interactive commands that lispy provides are bound to a-z and A-Z in lispy-mode.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;100 interactive commands!  In my experience you only need ten or fifteen interactive commands for most structural edits.  The others commands will be needed so rarely that you&amp;rsquo;re likely to have forgotten they exist, and the corresponding keybindings will get in the way when you mean to do something else.&lt;/p&gt;
&lt;p&gt;With Emacs&amp;rsquo; &lt;a href=&#34;https://karthinks.com/software/it-bears-repeating/&#34;&gt;repeat-mode&lt;/a&gt; and a smattering of helpers from a basic structural editing package like smartparens, we can setup up a lispy-lite no-chords keymap that is tailored to our needs.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s an example of using a (mostly) one-key interface that uses smartparens and &lt;a href=&#34;https://karthinks.com/software/it-bears-repeating/&#34;&gt;repeat-mode&lt;/a&gt;:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/lispy-lite-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/lispy-lite-demo.mp4&#34;&gt;Lispy-lite with repeat-mode demo&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;The command-log window on the right shows the keys that are pressed and the commands they activate.  Notice that once a structural editing command in the &lt;code&gt;structural-edit-map&lt;/code&gt; (see below) is called with its full keybinding &amp;ndash; typically &lt;code&gt;C-M-key&lt;/code&gt; &amp;ndash; we can continue to use single keys to move around and edit code syntactically.&lt;/p&gt;
&lt;p&gt;Regular Emacs commands like &lt;code&gt;isearch&lt;/code&gt; or character-based navigation are available at all times, and I use a few above, including &lt;code&gt;upcase-dwim&lt;/code&gt;.  Calling such a command deactivates &lt;code&gt;structural-edit-map&lt;/code&gt;, however, and I have to use a &amp;ldquo;full keybinding&amp;rdquo; again to activate it again.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;All structural editing commands of relevance are bound to single keys (like &lt;code&gt;n&lt;/code&gt; and &lt;code&gt;p&lt;/code&gt;) in a single keymap, and using any of these commands activates this transient keymap.  Until we use a non-structural editing command again, we can continue to navigate and edit structurally with the single keys.&lt;/p&gt;
&lt;p&gt;If necessary, this can be augmented with a prompter like &lt;a href=&#34;https://github.com/karthink/repeat-help&#34;&gt;repeat-help&lt;/a&gt;, giving us optional (or on-demand) &lt;a href=&#34;https://github.com/abo-abo/hydra&#34;&gt;hydra&lt;/a&gt;-like hints:
&lt;img src=&#34;https://karthinks.com/img/lispy-lite-prompter.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;h3 id=&#34;defining-a-structural-editing-keymap&#34;&gt;Defining a structural editing keymap&lt;/h3&gt;
&lt;p&gt;Here&amp;rsquo;s &lt;code&gt;structural-edit-map&lt;/code&gt; and the instruction to use this with &lt;code&gt;repeat-mode&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;repeat-mode&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defvar&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;structural-edit-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;make-sparse-keymap&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;pcase-dolist&lt;/span&gt; (&lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;k&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;f&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;((&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;u&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;backward-up-list&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;f&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;forward-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;b&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;backward-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;d&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;down-list&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;k&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;kill-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;n&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;sp-next-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;p&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;sp-previous-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;K&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;sp-kill-hybrid-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;]&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;sp-forward-slurp-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;[&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;sp-backward-slurp-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;}&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;sp-forward-barf-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;{&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;sp-backward-barf-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;C&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;sp-convolute-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;J&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;sp-join-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;S&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;sp-split-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;R&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;sp-raise-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\\&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;indent-region&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;/&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;undo&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;t&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;transpose-sexps&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;x&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;eval-defun&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;k&lt;/span&gt;) &lt;span style=&#34;color:#963&#34;&gt;f&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;map-keymap&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;repeat-map&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;structural-edit-map&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#963&#34;&gt;structural-edit-map&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To understand how this works, check out the &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/emacs/Repeating.html&#34;&gt;repeating commands&lt;/a&gt; section of the Emacs manual, or my write-up on &lt;a href=&#34;https://karthinks.com/software/it-bears-repeating/&#34;&gt;repeat-mode&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;seamless-activation&#34;&gt;Seamless activation&lt;/h3&gt;
&lt;p&gt;The other advantage of the repeat-map bindings is that the activation and deactivation of the transient keymap (&lt;code&gt;structural-edit-map&lt;/code&gt; above) requires no action on our part.  As in the demo, we can seamlessly mix regular editing commands (standard cursor navigation, inserting text, isearch) with single-key structural navigation editing commands (up/down-list, convolute-sexp, slurp/barf and so on).  You don&amp;rsquo;t have to explicitly switch modes &amp;ndash; typing any key not in this map will deactivate the transient keymap and let you get on with regular editing.&lt;/p&gt;
&lt;h3 id=&#34;only-what-we-need&#34;&gt;Only what we need&lt;/h3&gt;
&lt;p&gt;We can start small and add to &lt;code&gt;lisp-navigation-map&lt;/code&gt; incrementally.  For example, suppose we find ourselves needing a command to duplicate s-expressions.  We write a &lt;code&gt;duplicate-sexp&lt;/code&gt; command (or just find &lt;code&gt;sp-clone-sexp&lt;/code&gt; in the smartparens library) and add it to your one-key repeat-map repertoire.  Each command we add has a multiplicative effect because of&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;composable-features&#34;&gt;Composable features&lt;/h3&gt;
&lt;p&gt;Every command you add composes with everything already in our toolbelt.  Here&amp;rsquo;s an example of moving a value into a variable where the newly added &lt;code&gt;duplicate-sexp&lt;/code&gt; feeds into an &lt;a href=&#34;https://karthinks.com/software/avy-can-do-anything/&#34;&gt;Avy action&lt;/a&gt; that exchanges expressions:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/lispy-lite-refactor.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/lispy-lite-refactor.mp4&#34;&gt;Refactor with repeat-mode and Avy.&lt;/a&gt;&lt;/video&gt;
&lt;h3 id=&#34;the-cost&#34;&gt;The cost&lt;/h3&gt;
&lt;p&gt;There is, of course, a cost to pay for this convenience, and it&amp;rsquo;s the cost of all modal interaction: &lt;strong&gt;it&amp;rsquo;s the user&amp;rsquo;s responsibility to remember if the repeat-map is active&lt;/strong&gt;.  There are the usual band-aids, like an indicator in the mode-line.  But realistically it comes down to two options:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Parsimony: Populate &lt;code&gt;structural-edit-map&lt;/code&gt; with as few commands as you can get away with, thus minimizing the chance that a regular editing command (such as typing in some text) will cause a distressing series of structural edits that you didn&amp;rsquo;t intend.&lt;/li&gt;
&lt;li&gt;Maximalism: Populate &lt;code&gt;structural-edit-map&lt;/code&gt; with everything you think you might use, and explicitly deactivate the keymap with &lt;code&gt;C-g&lt;/code&gt; (&lt;code&gt;keyboard-quit&lt;/code&gt;) when you&amp;rsquo;re done with a round of structural edits.  This effectively makes the method completely modal like &lt;code&gt;evil-mode&lt;/code&gt; or symex.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Personally I prefer the first option, but the second is just as viable.&lt;/p&gt;
&lt;h2 id=&#34;minimum-viable-consistency&#34;&gt;Minimum Viable Consistency&lt;/h2&gt;
&lt;p&gt;I used smartparens features in the &lt;code&gt;structural-edit-map&lt;/code&gt; example above, but there isn&amp;rsquo;t anything special about smartparens here.  &lt;code&gt;repeat-mode&lt;/code&gt; is a generic Emacs feature.&lt;/p&gt;
&lt;p&gt;As tree-sitter support matures, more packages are created and structural editing is available across many (non-Lisp) major-modes in Emacs, we won&amp;rsquo;t have to contend with selecting one and learning and unlearning the plethora of editing interfaces that will accompany them
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Compare for instance the &lt;a href=&#34;https://github.com/drym-org/symex.el/#key-bindings&#34;&gt;symex&lt;/a&gt; and &lt;a href=&#34;http://oremacs.com/lispy/&#34;&gt;lispy keybindings&lt;/a&gt;.  &lt;em&gt;Phew!&lt;/em&gt;
&lt;/small&gt;&lt;/span&gt;
.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/structural-editing-packages-0001.svg&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Assuming that&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;they are written as simple packages and not editing &amp;ldquo;suites&amp;rdquo;, and&lt;/li&gt;
&lt;li&gt;structural editing has a reasonably consistent set of universal verbs (&lt;code&gt;up-&lt;/code&gt; / &lt;code&gt;down-tree&lt;/code&gt;, &lt;code&gt;transpose-nodes&lt;/code&gt; etc),&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;they can be conveniently folded into &lt;code&gt;structural-edit-map&lt;/code&gt;, and our interface will remain consistent across modes, structural editing packages and time!&lt;/p&gt;
&lt;p&gt;Even though lispy and symex are not intended to be used this way, there&amp;rsquo;s nothing stopping us from applying some elbow grease and appropriating the fancy verbs they provide into &lt;code&gt;structural-edit-map&lt;/code&gt;.  But the hackier the solution, the more edge cases and frustration we&amp;rsquo;ll need to contend with.&lt;/p&gt;
&lt;p&gt;More broadly, there&amp;rsquo;s room in the emerging structural editing space for both end-to-end solutions and composable pieces.  The former kind is flashier and more usable out of the box, but the latter is invaluable to users who move slower and try to minimize changes to their editing environment.  This is a plea to package authors: when you begin designing a structural editing library for Emacs, please consider which kind suits you better!&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;The &lt;a href=&#34;https://github.com/minad/consult&#34;&gt;Consult&lt;/a&gt;/&lt;a href=&#34;https://github.com/minad/vertico&#34;&gt;Vertico&lt;/a&gt;/&lt;a href=&#34;https://github.com/oantolin/embark&#34;&gt;Embark&lt;/a&gt; ecosystem is a great example of the latter.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;The package that handles everything in a rigid way is also going to be more stable, an aspect for which my appreciation grows exponentially as deadlines begin to loom.&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;&lt;code&gt;smartparens&lt;/code&gt; lets you define custom syntactic pairs, for instance.&amp;#160;&lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>Notmuch Ado About Nothing</title>
      <link>https://karthinks.com/software/notmuch-ado-about-nothing/</link>
      <pubDate>Wed, 27 Jul 2022 18:32:00 +0530</pubDate>
      
      <guid>https://karthinks.com/software/notmuch-ado-about-nothing/</guid>
      <description>&lt;p&gt;Addressing an &lt;a href=&#34;https://old.reddit.com/r/emacs/comments/w761d3/how_to_automatically_collapse_attachments_in/&#34;&gt;innocuous question&lt;/a&gt; about the Notmuch email client&amp;rsquo;s default behavior took me surprisingly deep into the bowels of the package code.  When the normal customization methods didn&amp;rsquo;t help, I realized it might be a good opportunity to live-code a solution.&lt;/p&gt;
&lt;p&gt;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 &amp;ndash;  with no specific prior knowledge.  The reality is thirty minutes of fairly myopic yakshaving:&lt;/p&gt;
&lt;iframe width=&#34;700&#34; height=&#34;371&#34; src=&#34;https://www.youtube.com/embed/UP2dFk5_ytY&#34; title=&#34;YouTube video player&#34; frameborder=&#34;0&#34; allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&#34; allowfullscreen&gt;&lt;a href=&#34;https://www.youtube.com/embed/UP2dFk5_ytY&#34;&gt;[Video]&lt;/a&gt;&lt;/iframe&gt;</description>
    </item><item>
      <title>It Bears Repeating: Emacs 28 &amp; Repeat Mode</title>
      <link>https://karthinks.com/software/it-bears-repeating/</link>
      <pubDate>Tue, 05 Jul 2022 23:17:00 +0530</pubDate>
      
      <guid>https://karthinks.com/software/it-bears-repeating/</guid>
      <description>&lt;p&gt;Are you tired of pressing &lt;code&gt;C-x o&lt;/code&gt; repeatedly to switch to the window you want in Emacs? Or &lt;code&gt;M-g n&lt;/code&gt; and &lt;code&gt;M-g p&lt;/code&gt; to cycle through compile errors or grep matches? How about navigating outline headings with (yuck) &lt;code&gt;C-c @ C-n&lt;/code&gt; and &lt;code&gt;C-c @ C-p&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;Depending on their levels of comfort with Emacs, users typically deal with them in one of three ways:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;They aren&amp;rsquo;t aware of or don&amp;rsquo;t use these commands, or use the menu to access them.&lt;/li&gt;
&lt;li&gt;They rebind the ones they need elsewhere, to an easier to press but equally idiosyncratic location. After a few such short non-prefixed keybindings they run out of room on their keyboards.&lt;/li&gt;
&lt;li&gt;They use one of the many, many available helpers written with the &lt;a href=&#34;https://github.com/abo-abo/hydra&#34;&gt;Hydra&lt;/a&gt; or &lt;a href=&#34;https://github.com/magit/transient&#34;&gt;Transient&lt;/a&gt; packages for these.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;But there&amp;rsquo;s a fourth option. Emacs 28 bundles a simple and hassle-free way to take the tedium out of these keybindings: Repeat Mode.&lt;/p&gt;
&lt;p&gt;Repeat Mode lets you call multiple commands in a keymap without repeating the prefix each time. So you can press&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;C-x o&lt;/code&gt;, &lt;code&gt;o&lt;/code&gt;, &lt;code&gt;o&lt;/code&gt;, &amp;hellip; to switch windows repeatedly. &lt;code&gt;O&lt;/code&gt; will cycle backwards.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;C-x u&lt;/code&gt;, &lt;code&gt;u&lt;/code&gt;, &lt;code&gt;u&lt;/code&gt;, &amp;hellip; to undo repeatedly,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;C-x @ C-n&lt;/code&gt;, &lt;code&gt;n&lt;/code&gt;, &lt;code&gt;p&lt;/code&gt;, &lt;code&gt;f&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;,&amp;hellip; to traverse headings,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;M-g n&lt;/code&gt;, &lt;code&gt;n&lt;/code&gt;, &lt;code&gt;p&lt;/code&gt;, &lt;code&gt;n&lt;/code&gt;,&amp;hellip; to navigate errors or grep matches, and so on.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With &lt;code&gt;repeat-mode&lt;/code&gt;  active, calling the prefix (&lt;code&gt;M-g&lt;/code&gt;) the first time &amp;ldquo;activates&amp;rdquo; the keymap, after which only the &amp;ldquo;base&amp;rdquo; key for a command (&lt;code&gt;n&lt;/code&gt; or &lt;code&gt;p&lt;/code&gt;)is needed.&lt;/p&gt;
&lt;details open&gt;
&lt;summary&gt;Naming things is hard&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;In this write-up I&amp;rsquo;ll call all but the final part of a keybinding the &amp;ldquo;prefix&amp;rdquo;, and the final key or chord the &amp;ldquo;base&amp;rdquo; key.&lt;/p&gt;
&lt;p&gt;Example: &lt;code&gt;org-next-link&lt;/code&gt;, bound to  &lt;code&gt;C-c C-x C-n&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The prefix is &lt;code&gt;C-c C-x&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The base key is &lt;code&gt;C-n&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details open&gt;
&lt;summary&gt;Repeating a single command&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;If you want to call a &lt;em&gt;single command&lt;/em&gt; repeatedly, &lt;code&gt;repeat-mode&lt;/code&gt; is not required. You can just call &lt;code&gt;M-x repeat&lt;/code&gt;, bound to &lt;code&gt;C-x z&lt;/code&gt; by default. This has been part of Emacs for ages. You can repeat invocations of the repeat command itself with just &lt;code&gt;z&lt;/code&gt;, so it&amp;rsquo;s &lt;code&gt;C-x z z z...&lt;/code&gt; to repeat the last command multiple times.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;In comparison to &lt;code&gt;M-x repeat&lt;/code&gt;, &lt;code&gt;repeat-mode&lt;/code&gt; shines when there&amp;rsquo;s a whole keymap of related commands with keys (like &lt;code&gt;n&lt;/code&gt;, &lt;code&gt;p&lt;/code&gt;, &lt;code&gt;f&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;u&lt;/code&gt; for outline navigation) under the same prefix (like &lt;code&gt;C-c @&lt;/code&gt; for &lt;code&gt;outline-minor-mode&lt;/code&gt;). In this video I switch windows, jump through Occur (grep) matches, navigate git-diff hunks
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
With &lt;code&gt;diff-hl-mode&lt;/code&gt;, which supports repeating commands out of the box.
&lt;/small&gt;&lt;/span&gt;
and call undo repeatedly with single key presses. The buffer on the right lists the keystrokes. Commands with the same prefix or repeated commands are single key presses:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;1280&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/repeat-help-full-demo-gh.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/repeat-help-full-demo-gh.mp4&#34;&gt;[VIDEO]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;After the first invocation of &lt;code&gt;other-window&lt;/code&gt; (&lt;code&gt;C-x o&lt;/code&gt;), I switch windows with &lt;code&gt;o&lt;/code&gt; (and &lt;code&gt;O&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Next I find  &lt;code&gt;occur&lt;/code&gt; -ences  of the phrase &amp;ldquo;repeat-mode&amp;rdquo; in the buffer. The &lt;code&gt;next-error&lt;/code&gt; (&lt;code&gt;M-g n&lt;/code&gt;) and &lt;code&gt;previous-error&lt;/code&gt; (&lt;code&gt;M-g p&lt;/code&gt;) commands jump through the matches. I only need to type the prefix (&lt;code&gt;M-g&lt;/code&gt;) once.&lt;/li&gt;
&lt;li&gt;I call &lt;code&gt;diff-hl-previous-hunk&lt;/code&gt; from the end of the buffer to jump to modified hunks in this version-controlled document. This is provided by the &lt;code&gt;diff-hl&lt;/code&gt; package. Again, I only type in the prefix (&lt;code&gt;C-x v&lt;/code&gt;  in my configuration) once.&lt;/li&gt;
&lt;li&gt;I mark a modified hunk with &lt;code&gt;SPC&lt;/code&gt; &amp;ndash; corresponding to the full version  &lt;code&gt;C-x v SPC&lt;/code&gt;. Then I call &lt;code&gt;undo&lt;/code&gt; a few times. As a bonus, undo in Emacs is limited to the active region.&lt;/li&gt;
&lt;li&gt;After the first invocation of the &lt;code&gt;C-x&lt;/code&gt; prefix, undo is just &lt;code&gt;u&lt;/code&gt;. This is simpler than holding down Control to press &lt;code&gt;C-/&lt;/code&gt;, the other undo binding, a bunch of times.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Repeat Mode comes with built-in support for a bunch of keymaps. There&amp;rsquo;s no learning curve, &lt;code&gt;M-x repeat-mode&lt;/code&gt; and you&amp;rsquo;re set. You&amp;rsquo;ll wonder how you lived without it.&lt;/p&gt;
&lt;h2 id=&#34;what-s-in-a-keymap&#34;&gt;What&amp;rsquo;s in a keymap&lt;/h2&gt;
&lt;p&gt;Before we dive into Repeat Mode proper, let&amp;rsquo;s address the issue of creating an easily repeatable command using Emacs&amp;rsquo; base API.&lt;/p&gt;
&lt;p&gt;A &lt;em&gt;&amp;ldquo;keymap&amp;rdquo;&lt;/em&gt; is a data structure that maps a collection of keybindings (&lt;em&gt;i.e.&lt;/em&gt; keyboard shortcuts) to commands. Let&amp;rsquo;s call each element of this map a &lt;em&gt;&amp;ldquo;binding&amp;rdquo;&lt;/em&gt;. Any number of keymaps can be &lt;em&gt;&amp;ldquo;active&amp;rdquo;&lt;/em&gt; at a time in Emacs, meaning that typing a keybinding will run some command that it&amp;rsquo;s mapped to in these keymaps. Which command runs is a question of which keymap is looked up first.&lt;/p&gt;
&lt;p&gt;For our purposes, a &lt;em&gt;&amp;ldquo;transient keymap&amp;rdquo;&lt;/em&gt; is one that&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;takes priority over all other keymaps, and&lt;/li&gt;
&lt;li&gt;disappears after a keypress unless unless you explicitly ask it to stick around.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If we want to make a  key run a command no matter what other keymaps are active, we can use a transient keymap. If we want this keymap to stick around until some arbitrary condition is met, we can do that too. Putting these ideas together lets us add a &amp;ldquo;repeat&amp;rdquo; feature to any command.&lt;/p&gt;
&lt;p&gt;For example, I &lt;a href=&#34;../dealing-with-window-clutter-in-emacs&#34;&gt;cycle through popup buffers &lt;/a&gt; in Emacs with the key &lt;code&gt;C-M-`&lt;/code&gt;, or Control, Alt and the grave key chorded together. This calls the &lt;code&gt;popper-cycle&lt;/code&gt; command. Needless to say, this isn&amp;rsquo;t very conducive to repeated invocations. So I activate a transient-keymap after each call to &lt;code&gt;popper-cycle&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;advice-add&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;popper-cycle&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:after&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/popper-cycle-repeated&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Continue to cycle popups with the grave key.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;set-transient-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;make-sparse-keymap&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;`&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;popper-cycle&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This keymap binds &lt;code&gt;popper-cycle&lt;/code&gt; to the grave key, and it stays active for exactly one keypress. Typing the grave key thus calls &lt;code&gt;popper-cycle&lt;/code&gt; again, or I can break this chain by doing anything else. (Note: This is a terrible way to do it!&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;)&lt;/p&gt;
&lt;p&gt;The logic used by Repeat Mode is quite different, but the effect is similar. In its simplest form, binding a shared set of commands to a transient map is how you could add a &amp;ldquo;repeat&amp;rdquo; functionality to the set.&lt;/p&gt;
&lt;h2 id=&#34;adding-repeat-mode-support-to-keymaps&#34;&gt;Adding &lt;code&gt;repeat-mode&lt;/code&gt; support to keymaps&lt;/h2&gt;
&lt;p&gt;Repeat Mode supports a few keymaps out of the box, including all the ones in my demo above.&lt;/p&gt;
&lt;p&gt;To add Repeat Mode support to commands in a keymap, you add a &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Symbol-Properties.html&#34;&gt;symbol property&lt;/a&gt; to each command. Here&amp;rsquo;s support for the completely unpressable &lt;code&gt;smerge-mode&lt;/code&gt; commands:
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
See below for a demo.
&lt;/small&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;map-keymap&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;_key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbolp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;repeat-map&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;smerge-basic-map&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#963&#34;&gt;smerge-basic-map&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is simple enough that we can shove it into a function that repeat-izes keymaps:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;repeatize&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Add &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`repeat-mode&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; support to a KEYMAP.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;map-keymap&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;_key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbolp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;repeat-map&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-value&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &amp;ldquo;repeat&amp;rdquo; state is shared between commands that are (i) bound in a keymap, and (ii) have the keymap  as their  &lt;code&gt;repeat-map&lt;/code&gt; symbol property. But what if the commands you want to repeat aren&amp;rsquo;t defined on top of a prefix, unlike all the above examples? Or if the commands we want to group aren&amp;rsquo;t part of a single keymap to begin with? Then this is a two step process:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Bind your commands of interest in some keymap,  to short keys if necessary.&lt;/li&gt;
&lt;li&gt;Attach the keymap name as a symbol property to all of them.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For instance, suppose you&amp;rsquo;d  like to be able to Isearch repeatedly with just &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;r&lt;/code&gt; instead of hammering &lt;code&gt;C-s&lt;/code&gt; over and over. To do this you can bind them to short keys in a keymap, and attach the keymap name to the commands&amp;rsquo; &lt;code&gt;repeat-map&lt;/code&gt; symbol properties:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defvar&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;isearch-repeat-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;make-sparse-keymap&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;s&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;isearch-repeat-forward&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;r&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;isearch-repeat-backward&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;dolist&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;isearch-repeat-forward&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;isearch-repeat-backward&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;repeat-map&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;isearch-repeat-map&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note: You&amp;rsquo;re not going to have trouble typing &amp;ldquo;s&amp;rdquo; or &amp;ldquo;r&amp;rdquo; as part of the search string, even after you&amp;rsquo;ve begun the search with  &lt;code&gt;C-s&lt;/code&gt; &amp;ndash; it&amp;rsquo;s only the repeated invocations (isearch-&lt;em&gt;repeat&lt;/em&gt;-forward)  that are shortened!&lt;/p&gt;
&lt;p&gt;This is a somewhat low-level (though simple) operation and the recipe is fairly constant. So we could package it in a macro  for ease of use&amp;hellip; but we don&amp;rsquo;t have to. There are already multiple packages that let you specify commands to be repeated along with their short keys. Here are a few:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&#34;https://tildegit.org/acdw/define-repeat-map.el&#34;&gt;define-repeat-map&lt;/a&gt; by &lt;a href=&#34;https://www.acdw.net/&#34;&gt;Case Duckworth&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/mmarshall540/repeaters&#34;&gt;repeaters&lt;/a&gt; by &lt;a href=&#34;https://github.com/mmarshall540&#34;&gt;mmarshall540&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://gitlab.com/jjzmajic/hercules.el&#34;&gt;Hercules&lt;/a&gt; by &lt;a href=&#34;https://gitlab.com/jjzmajic&#34;&gt;jjzmajic&lt;/a&gt;, an external package that bypasses the whole &lt;code&gt;repeat-mode&lt;/code&gt; system and lets you define repeat functionality for any keymap.&lt;/li&gt;
&lt;/ol&gt;
&lt;details open&gt;
&lt;summary&gt;Making repeat-maps: Emacs 29 update&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Emacs 29 introduces &lt;code&gt;defvar-keymap&lt;/code&gt;, making it easier to define keymaps with the &lt;code&gt;repeat-map&lt;/code&gt; property attached:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;defvar-keymap&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;hl-todo-repeat-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#007020&#34;&gt;:repeat&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;n&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;hl-todo-next&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;p&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;hl-todo-previous&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;o&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;hl-todo-occur&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or, for finer control over when the repeat-map is (de)activated,&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;defvar-keymap&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;hl-todo-repeat-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#007020&#34;&gt;:repeat&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;:enter&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;hl-todo-insert&lt;/span&gt;) &lt;span style=&#34;color:#007020&#34;&gt;:exit&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;hl-todo-occur&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;n&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;hl-todo-next&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;p&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;hl-todo-previous&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;o&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;hl-todo-occur&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;which specifies that using &lt;code&gt;hl-=todo-insert&lt;/code&gt; should activate the repeat-map and  &lt;code&gt;hl-todo-occur&lt;/code&gt; should deactivate it.&lt;/p&gt;
&lt;p&gt;Note that turning an existing keymap into a repeat-map or adding this behavior to individual commands still requires one of the above helpers, like &lt;code&gt;repeatize&lt;/code&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;With any of these packages you could develop the above idea into a complete modal editing environment &amp;ndash; like &lt;a href=&#34;https://github.com/emacsorphanage/god-mode&#34;&gt;God Mode&lt;/a&gt;, but with custom modes for specialized editing tasks. Even at a more basic level, you can go wild here, placing all commands into repeat maps: Why delete words with &lt;code&gt;M-d&lt;/code&gt; or &lt;code&gt;M-DEL&lt;/code&gt; five times when you can just do &lt;code&gt;M-d d d d d&lt;/code&gt;? Why cycle through the kill-ring with &lt;code&gt;M-y&lt;/code&gt;  when you can just yank and cycle with &lt;code&gt;C-y y y y...&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m not sure about taking it that far. For one, it&amp;rsquo;s simpler to use digit arguments: &lt;code&gt;M-5 M-d&lt;/code&gt; is shorter and possibly faster to type. Second, many commands that involve more than three levels of &amp;ldquo;cycling&amp;rdquo; are better served by a menu with choices, &lt;em&gt;i.e.&lt;/em&gt; a &lt;code&gt;completing-read&lt;/code&gt; interface or an &lt;a href=&#34;../avy-can-do-anything&#34;&gt;Avy selection&lt;/a&gt;. I&amp;rsquo;ve found that the returns diminish and the common issues with modality start to surface as the repeat maps become more  expansive.&lt;/p&gt;
&lt;p&gt;Repeat maps appear to be best suited for families of related commands that are usually invoked in succession and are cumbersome to invoke. Pretty much exactly what folks use Hydras or (more lately) Transients for, which brings us to&amp;hellip;&lt;/p&gt;
&lt;h2 id=&#34;repeat-mode-vs-hydra-transient-and-hercules&#34;&gt;Repeat Mode vs Hydra, Transient and Hercules&lt;/h2&gt;
&lt;p&gt;Repeat Mode has a few advantages when compared to Hydras/Transients&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt; for repeating commands:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;There&amp;rsquo;s no special definition or code to write, maintain or copy: it just works.&lt;/li&gt;
&lt;li&gt;There&amp;rsquo;s only one set of keys defined for a command: You can use the same full keybinding with or without Repeat Mode active.&lt;/li&gt;
&lt;li&gt;You can rebind both the prefix and the base keys without losing the repeat behavior.&lt;/li&gt;
&lt;li&gt;Repeat Mode has support for many prefix maps out of the box, and adding support for new maps is easy, see below.&lt;/li&gt;
&lt;li&gt;It&amp;rsquo;s built into Emacs.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The Hercules package shares many of these advantages, since it too uses existing keymaps as the basis for a repeat interface. However, Repeat Mode is more minimal in its configuration and presentation, does not depend on Which Key, and does not offer a fancy key hinting system out of the box.&lt;/p&gt;
&lt;p&gt;With all of the above alternatives, you still need to invoke the mode somehow. With &lt;code&gt;repeat-mode&lt;/code&gt; this requires pressing the unwieldy prefix key &lt;em&gt;once&lt;/em&gt;: &lt;code&gt;C-c @&lt;/code&gt; for &lt;code&gt;outline-minor-mode&lt;/code&gt;, &lt;code&gt;C-c ^&lt;/code&gt; for &lt;code&gt;smerge-mode&lt;/code&gt;, and so on. This is cause enough for rebinding them somewhere convenient, perhaps to the &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Conventions.html&#34;&gt;user-reserved&lt;/a&gt; &lt;code&gt;C-c o&lt;/code&gt; (for outline) and &lt;code&gt;C-c m&lt;/code&gt; (for merge). Or under a leader key if you use &lt;code&gt;evil-mode&lt;/code&gt;. &lt;strong&gt;Note that you have to do this with a Hydra/Transient as well.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There are disadvantages to Repeat Mode too. First, Hydras/Transients are incredibly versatile, and repeating commands isn&amp;rsquo;t even in the top three problems they solve. Using them for repeating commands is like using an elephant gun to hunt a mouse.&lt;/p&gt;
&lt;p&gt;They can be full fledged suites combining settings and bespoke commands that don&amp;rsquo;t have much in common. For example, here&amp;rsquo;s a Transient I use to toggle minor-modes in Emacs:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/repeat-help-toggle-transient.png&#34; width=&#34;700px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;And another to resize or clip a video with &lt;code&gt;ffmpeg&lt;/code&gt;:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/repeat-help-transient-2.png&#34; width=&#34;700px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Basically, Transients have &lt;em&gt;state&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In contrast, Repeat Mode only aims to save your fingers some work. You &lt;em&gt;can&lt;/em&gt; gather disparate commands under the same umbrella map for use with &lt;code&gt;repeat mode&lt;/code&gt;, but it gets out of hand rather quickly. So we will limit ourselves to the intended patterns of Repeat Mode usage in this write-up.&lt;/p&gt;
&lt;p&gt;Second, Hydras can stay alive while you press keys not in the keymap. This means you can (usually) move the cursor around to where you next want to call a Hydra command.  You can add this behavior to Repeat Mode with some creative use of &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Inheritance-and-Keymaps.html&#34;&gt;composed keymaps&lt;/a&gt;, but by default the prefix map does not stay active if you call a non-keymap command. Again, I&amp;rsquo;m going to hew to the default scope of Repeat Mode here.&lt;/p&gt;
&lt;p&gt;Finally, &lt;code&gt;repeat-mode&lt;/code&gt; prompts you with available keys in the echo area, but not what commands they&amp;rsquo;re bound to:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/repeat-help-basic-auto.png&#34; width=&#34;700px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;This is generally sufficient, but I could use a Which Key style menu for rarely used keymaps with lots of keys (like &lt;code&gt;smerge-mode&lt;/code&gt;). As it turns out, this is quite straightforward to add.&lt;/p&gt;
&lt;h2 id=&#34;adding-a-hydra-like-prompt-to-repeat-mode&#34;&gt;Adding a Hydra-like prompt to Repeat Mode&lt;/h2&gt;
&lt;p&gt;If you prefer an explicit and persistent menu of available keys/commands &amp;ndash; like a Hydra or Transient menu &amp;ndash; you can produce a menu using Which Key or an Embark prompter when calling a relevant command:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/repeat-help-which-key-auto.png&#34; width=&#34;1000px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Doing this is quite simple: we disable the built-in hint display and advise the function that sets the transient keymap after a &amp;ldquo;repeatable key&amp;rdquo; is pressed. Here&amp;rsquo;s the Which Key version:
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
This code creates a closure, so remember to &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Lexical-Binding.html&#34;&gt;enable lexical-binding&lt;/a&gt; where it&amp;rsquo;s placed.
&lt;/small&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; Disable the built-in repeat-mode hinting&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;custom-set-variables&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;repeat-echo-function&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;ignore&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; Spawn or hide a which-key popup&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;advice-add&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;repeat-post-hook&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:after&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;repeat-help--which-key-popup&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;if-let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;this-command&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;real-this-command&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                       (&lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;repeat-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                   (&lt;span style=&#34;color:#963&#34;&gt;repeat--command-property&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;repeat-map&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;run-at-time&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#963&#34;&gt;which-key--create-buffer-and-show&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-value&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;which-key--hide-popup&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Specifically, we schedule the which-key popup on the main event loop. (&lt;strong&gt;Emacs&lt;/strong&gt;: Making things happen when other things happen™.)&lt;/p&gt;
&lt;p&gt;In action, applied to the &lt;code&gt;smerge-mode&lt;/code&gt; keymap when performing a Git merge:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;1000&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/repeat-help-smerge-which-key-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/repeat-help-smerge-which-key-demo.mp4&#34;&gt;[VIDEO]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;Open a file with merge conflicts.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;smerge-previous&lt;/code&gt; (&lt;code&gt;C-c m p&lt;/code&gt; in my configuration) to go to the beginning of a hunk. This &amp;ldquo;activates&amp;rdquo; the keymap and the Which Key pop up.&lt;/li&gt;
&lt;li&gt;Jump through conflict regions with &lt;code&gt;n&lt;/code&gt; and &lt;code&gt;p&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Resolve conflicts by picking the upper (&lt;code&gt;u&lt;/code&gt;) or lower (&lt;code&gt;l&lt;/code&gt;) regions.&lt;/li&gt;
&lt;li&gt;Save the buffer. This quits the repeat map and the popup.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;The code to produce a suitable Embark indicator involves a little more book-keeping, but the idea is the same: Schedule a keymap display when a repeatable command is invoked and remove it once it&amp;rsquo;s not relevant any more.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; Disable the built-in repeat-mode hinting&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;custom-set-variables&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;repeat-echo-function&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;ignore&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;repeat-help--embark-indicate&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;if-let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;this-command&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;real-this-command&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;repeat-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                       (&lt;span style=&#34;color:#963&#34;&gt;repeat--command-property&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;repeat-map&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;run-at-time&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#007020&#34;&gt;let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;bufname&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;*Repeat Commands*&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;embark-verbose-indicator-buffer-sections&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;bindings&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;embark--verbose-indicator-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;bufname&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;embark-verbose-indicator-display-action&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;display-buffer-at-bottom&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#963&#34;&gt;window-height&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;fit-window-to-buffer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;window-parameters&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;no-other-window&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                         (&lt;span style=&#34;color:#963&#34;&gt;mode-line-format&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#963&#34;&gt;embark-verbose-indicator&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-value&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;other-window-scroll-buffer&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;get-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;bufname&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;when-let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;get-buffer-window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;*Repeat Commands*&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;visible&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;kill-buffer&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;window-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;delete-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;win&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;advice-add&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;repeat-post-hook&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:after&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;repeat-help--embark-indicate&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here&amp;rsquo;s what it produces:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/repeat-help-embark-auto.png&#34; width=&#34;1000px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;If these are too busy, you might prefer to toggle the prompter on demand. There are only a few keymaps I need hints to use, so I bind the popup key to &lt;code&gt;C-h&lt;/code&gt;. Here I jump between modified hunks in a version controlled document and examine and stage them for committing using the Embark popup/indicator as a guide. Keep an eye on the key/command description at the top of the window:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;600&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/repeat-help-embark-manual.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=https://karthinks.com/img/repeat-help-embark-manual.mp4&#34;&gt;[VIDEO]&lt;/a&gt;&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;Call &lt;code&gt;diff-hl-next-hunk&lt;/code&gt;, which I&amp;rsquo;ve bound to &lt;code&gt;C-x v n&lt;/code&gt; . This is the only time I type the prefix &lt;code&gt;C-x v&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Jump between modified hunks in the document with &lt;code&gt;n&lt;/code&gt; and &lt;code&gt;p&lt;/code&gt;, which would be &lt;code&gt;C-x v n&lt;/code&gt; and &lt;code&gt;C-x v p&lt;/code&gt; without &lt;code&gt;repeat-mode&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Bring up the Embark key description popup with &lt;code&gt;C-h&lt;/code&gt;. I toggle it a couple of times.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;diff-hl-show-hunk&lt;/code&gt; with &lt;code&gt;*&lt;/code&gt;, and stage the previous hunk with &lt;code&gt;S&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Perform an action that ends the &lt;code&gt;repeat-mode&lt;/code&gt; chain, in this case by yanking some text into the buffer.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;The key description popup does not need to be cancelled: it automatically disappears when you run any command that&amp;rsquo;s not in the keymap, such as inserting text. (This is regular  behavior for transient keymaps in Emacs.)&lt;/p&gt;
&lt;p&gt;Both indicators (Embark and Which Key) and both kinds of behavior (auto-popup or toggle on demand) are available in &lt;a href=&#34;https://github.com/karthink/repeat-help&#34;&gt;Repeat Help&lt;/a&gt;, a package I wrote to get a simplified Hydra-like prompt for repeat maps. The prompt interface is basic but generic, so any function that can list a keymap&amp;rsquo;s entries can be plugged in.&lt;/p&gt;
&lt;h2 id=&#34;command-smells&#34;&gt;Command smells&lt;/h2&gt;
&lt;p&gt;To find  other commands or keymaps that could use repeat-izing, we can look for a code smell:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Any command that has &amp;ldquo;next&amp;rdquo;, &amp;ldquo;forward&amp;rdquo;, &amp;ldquo;previous&amp;rdquo; or &amp;ldquo;backward&amp;rdquo; in the name is fair game. For reasons alluded to above, this excludes common commands like &lt;code&gt;next-line&lt;/code&gt; or &lt;code&gt;forward-word&lt;/code&gt;: jumping across text is better solved by Isearch or Avy.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
These do other useful things besides, like pushing the mark and letting you act on the region you jumped across.
&lt;/small&gt;&lt;/span&gt;
But something contextual like &lt;code&gt;org-next-link&lt;/code&gt; is fair game:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defvar&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;org-link-repeat-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;make-sparse-keymap&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;n&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-next-link&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;p&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-previous-link&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;dolist&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;org-next-link&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;org-previous-link&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;repeat-map&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-link-repeat-map&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It&amp;rsquo;s surprising that link navigation isn&amp;rsquo;t already part of &lt;a href=&#34;https://orgmode.org/manual/Speed-Keys.html&#34;&gt;Org Speed Keys&lt;/a&gt;, which is included in Org Mode.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Any predictable sequence of actions that forms a &amp;ldquo;task&amp;rdquo; is a good candidate. Smerge Mode is a good example. In its most basic usage you jump to each merge conflict, pick one of three choices and repeat. Critically, it has to be a sequence of actions carried out in (or across) an editable buffer. In &lt;code&gt;read-only-mode&lt;/code&gt; buffers like help windows or mail clients, most relevant commands are already bound to single key presses at the top level.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Any command that tweaks an analog setting will need to be repeated. Setting the text scale (&lt;code&gt;C-x C-=&lt;/code&gt; ) or  window width (&lt;code&gt;C-x {&lt;/code&gt;), for instance. Fortunately these are already handled by Repeat Mode.&lt;/p&gt;
&lt;p&gt;But other built-in libraries like Windmove, for which Hydras are usually written, can be repeat-ized instead:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defvar&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;windmove-repeat-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;make-sparse-keymap&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;left&amp;gt;&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;windmove-left&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;S-&amp;lt;left&amp;gt;&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;windmove-swap-states-left&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;right&amp;gt;&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;windmove-right&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;S-&amp;lt;right&amp;gt;&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;windmove-swap-states-right&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;up&amp;gt;&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;windmove-up&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;S-&amp;lt;up&amp;gt;&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;windmove-swap-states-up&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;down&amp;gt;&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;windmove-down&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;S-&amp;lt;down&amp;gt;&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;windmove-swap-states-down&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;map-keymap&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;_key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbolp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;put&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;repeat-map&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;windmove-repeat-map&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#963&#34;&gt;windmove-repeat-map&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now you can continue to move across or rearrange windows with the arrow keys after calling any Windmove command.&lt;/p&gt;
&lt;h2 id=&#34;dot-dot-dot-but-i-repeat-myself&#34;&gt;&amp;hellip;but I repeat myself&lt;/h2&gt;
&lt;p&gt;Keybindings are typically where modal editing paradigms have an advantage. Indeed, most repeated invocations in Vim &amp;ndash; like searching forward with &lt;code&gt;n&lt;/code&gt; , &lt;code&gt;f&lt;/code&gt; or &lt;code&gt;;&lt;/code&gt;&amp;ndash; are single key presses. But here too I had to rebind keys to switch windows (&lt;code&gt;C-w j&lt;/code&gt;  etc) to use it comfortably over a long editing session.&lt;/p&gt;
&lt;p&gt;The question remained: Why do I need to press so many keys to do the same few things? After failing to gel with the Hydra paradigm, I had been manually setting up transient keymaps (with &lt;code&gt;set-transient-map&lt;/code&gt;) to speed up consecutive calls for a bunch of commands. Placing them behind a uniform interface is a welcome addition. Repeat Mode is a small feature that solves a small problem, but with a big cumulative impact on my experience of using Emacs.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Technically there&amp;rsquo;s one more approach: Use bespoke solutions like &lt;code&gt;ace-window&lt;/code&gt; to switch windows. But in terms of a general approach it&amp;rsquo;s just these three.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;Setting a new transient keymap on each call is actually a wasteful way of producing this effect! Instead, you can set a transient keymap just once but instruct it to stay active as long as the only key pressed is grave.&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;It makes sense that the Transient package is called that, since Transients (the menus Magit uses) are &amp;ldquo;just&amp;rdquo; souped-up transient maps, the way a Komodo dragon is just a lizard. But it causes no end of confusion when talking about them. Here I refer to a regular Emacs transient map in lowercase and the Magit-style popup-menu variety in uppercase.&amp;#160;&lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>more &lt; less &lt; emacs</title>
      <link>https://karthinks.com/software/more-less-emacs/</link>
      <pubDate>Mon, 27 Jun 2022 03:25:00 +0530</pubDate>
      
      <guid>https://karthinks.com/software/more-less-emacs/</guid>
      <description>&lt;p&gt;If you use Emacs for more than editing text, there are many daily occasions to use Emacs as a pager. Here&amp;rsquo;s my list:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read-only files (with &lt;a href=&#34;../batteries-included-with-emacs/#view-mode--m-x-view-mode&#34;&gt;view-mode&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Scrolling through emails (&lt;code&gt;notmuch&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;RSS feed entries (&lt;code&gt;elfeed&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Reading ebooks (&lt;code&gt;nov.el&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Web browsing (&lt;code&gt;eww&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Man pages (&lt;code&gt;man&lt;/code&gt; or &lt;code&gt;woman&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Help buffers and Info documents&lt;/li&gt;
&lt;li&gt;Git logs (&lt;code&gt;magit&lt;/code&gt; or &lt;code&gt;vc&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;System logs, compilation and debug output&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This list was about half as long ten years ago, it keeps growing!&lt;/p&gt;
&lt;p&gt;Emacs (and associated packages) generally do a decent job of acting as a pager. In addition to the default movement commands, all these modes let you page forward with &lt;code&gt;SPC&lt;/code&gt; and backward with Backspace or &lt;code&gt;S-SPC&lt;/code&gt;, and quit the window (without killing the buffer) with &lt;code&gt;q&lt;/code&gt;. Additionally, some modes provide commands to scroll half a page up or down.&lt;/p&gt;
&lt;p&gt;And that&amp;rsquo;s where the pager-ness stops. Unlike a pager, Emacs has to read in the entire document into a buffer. This is fine for man pages, but you&amp;rsquo;re asking for trouble if the log you want to page through is a few hundred chunky Megabytes, or if the website in question is the &lt;a href=&#34;https://orgmode.org/org.html&#34;&gt;single-page Org manual&lt;/a&gt;. If your document has long lines in addition, it&amp;rsquo;s curtains for your Emacs session. But let&amp;rsquo;s put these heady issues aside for today.&lt;/p&gt;
&lt;p&gt;The thing that&amp;rsquo;s always bothered me about these modes is that the text cursor sticks around. This is generally useless and distracting &amp;ndash; I don&amp;rsquo;t need a cursor hanging around the screen when reading an ebook or a man page. Often it&amp;rsquo;s annoying &amp;ndash; I can&amp;rsquo;t page the view down by a few lines by scrolling&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;. The presence of the cursor makes the arrow keys virtually useless.&lt;/p&gt;
&lt;h2 id=&#34;prefab-construction&#34;&gt;Prefab construction&lt;/h2&gt;
&lt;p&gt;I don&amp;rsquo;t doubt that there&amp;rsquo;s a &lt;code&gt;pager-mode&lt;/code&gt; package somewhere that fixes this. But as usual, Emacs already provides us the ingredients to fix the dangling cursor problem easily:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hide the cursor&lt;/strong&gt;: The variable &lt;code&gt;cursor-type&lt;/code&gt; controls the cursor&amp;rsquo;s appearance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scroll the view instead of the cursor&lt;/strong&gt;: The appropriately named &lt;code&gt;scroll-lock-mode&lt;/code&gt; does this. It&amp;rsquo;s even bound to the ScrLk key, fulfilling the key&amp;rsquo;s original purpose.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Combining the two gives us a better pager experience in Emacs:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defvar-local&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;hide-cursor--original&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;define-minor-mode&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;hide-cursor-mode&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Hide or show the cursor.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;When the cursor is hidden &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`scroll-lock-mode&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; is enabled, so that
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;the buffer works like a pager.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:global&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:lighter&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;H&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;hide-cursor-mode&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;progn&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;scroll-lock-mode&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;setq-local&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;hide-cursor--original&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    &lt;span style=&#34;color:#963&#34;&gt;cursor-type&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;setq-local&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cursor-type&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;scroll-lock-mode&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;setq-local&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cursor-type&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;hide-cursor--original&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I bind &lt;code&gt;hide-cursor-mode&lt;/code&gt; to &lt;code&gt;F7&lt;/code&gt;, the key to toggle caret browsing in Firefox. The utility is inverted here: &lt;code&gt;hide-cursor-mode&lt;/code&gt; turns &lt;em&gt;off&lt;/em&gt; &amp;ldquo;caret browsing&amp;rdquo; in Emacs instead of turning it on, but the effect is the same.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;global-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;f7&amp;gt;&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;hide-cursor-mode&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here&amp;rsquo;s me browsing an Elfeed entry without/with &lt;code&gt;hide-cursor-mode&lt;/code&gt;. Like in &lt;strong&gt;less&lt;/strong&gt;, searching and other functions still work fine. If I want the cursor back to select a region, it&amp;rsquo;s a keypress away:&lt;/p&gt;
&lt;video style=&#34;center&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/hide-cursor-mode.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/hide-cursor-mode.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;h2 id=&#34;bonus-half-screen-scrolling&#34;&gt;Bonus: half-screen scrolling&lt;/h2&gt;
&lt;p&gt;Vim/less style half-screen scrolling is particularly useful for paging, and missing in Emacs&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;. Here&amp;rsquo;s a really basic implementation:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;scroll-up-half&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;scroll-up-command&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;floor&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;-&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;window-height&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#963&#34;&gt;next-screen-context-lines&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;scroll-down-half&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;scroll-down-command&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;floor&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;-&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;window-height&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       &lt;span style=&#34;color:#963&#34;&gt;next-screen-context-lines&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;2&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;As a bonus, these can be bound to more convenient keys than Vim/=evil-mode=&amp;rsquo;s &lt;code&gt;C-d&lt;/code&gt; and &lt;code&gt;C-u&lt;/code&gt; since most keys are available in pager-type read-only buffers.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Instead I have to call &lt;code&gt;recenter&lt;/code&gt; (&lt;code&gt;C-l&lt;/code&gt;) with a prefix argument&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;Although &lt;code&gt;view-mode&lt;/code&gt; provides this.&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>Fast Latex previews in Org-mode</title>
      <link>https://karthinks.com/software/fast-latex-previews-in-org-mode/</link>
      <pubDate>Sun, 27 Feb 2022 22:42:00 -0800</pubDate>
      
      <guid>https://karthinks.com/software/fast-latex-previews-in-org-mode/</guid>
      <description>&lt;p&gt;This is a post in my &lt;a href=&#34;https://karthinks.com/tags/latex&#34;&gt;Latex editing series&lt;/a&gt;, a quick package announcement for better Latex previews.&lt;/p&gt;
&lt;p&gt;After complaining &lt;a href=&#34;https://karthinks.com/software/scaling-latex-previews-in-emacs/&#34;&gt;the other day&lt;/a&gt; about Latex previews in org-mode being unbearably slow, I decided to take a crack at adapting Org-mode to use AucTeX&amp;rsquo;s &lt;code&gt;preview&lt;/code&gt; library, which is blazing fast in comparison:&lt;/p&gt;
&lt;div style=&#34;width:100%;height:0px;position:relative;padding-bottom:111.801%;&#34;&gt;&lt;iframe src=&#34;https://streamable.com/e/kgtjmk?loop=0&#34; frameborder=&#34;0&#34; width=&#34;100%&#34; height=&#34;100%&#34; allowfullscreen style=&#34;width:100%;height:100%;position:absolute;left:0px;top:0px;overflow:hidden;&#34;&gt;&lt;a href=&#34;https://karthinks.com/img/auctex-demo-2.mp4&#34;&gt;[Fast previews in Org]&lt;/a&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;p&gt;&lt;small&gt;&lt;a href=&#34;https://karthinks.com/img/org-auctex-demo-2.mp4&#34;&gt;Direct link to video&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;p&gt;It was both easier and more annoying than I expected it to be, but perhaps less annoying on balance than &lt;code&gt;org-latex-preview&lt;/code&gt; locking up Emacs for a good minute on every fresh invocation in medium sized documents.&lt;/p&gt;
&lt;p&gt;For now the package is &lt;a href=&#34;https://github.com/karthink/org-auctex&#34;&gt;available online&lt;/a&gt; in its fledgling state. It&amp;rsquo;s intended for use as a drop-in replacement for &lt;code&gt;org-latex-preview&lt;/code&gt;. Turn on &lt;code&gt;org-auctex-mode&lt;/code&gt; and use your keybinding for &lt;code&gt;org-latex-preview&lt;/code&gt; (or call &lt;code&gt;org-auctex-preview-dwim&lt;/code&gt;), and it should use the Auctex-based backend instead. This is very early, everything including the name of the package might change in the future.&lt;/p&gt;
&lt;p&gt;Interestingly, there&amp;rsquo;s very little Org-specific code in there. It should be trivial to extend the &lt;code&gt;preview&lt;/code&gt; library to work in Markdown and other text buffers.&lt;/p&gt;
</description>
    </item><item>
      <title>Scaling Latex previews in Emacs</title>
      <link>https://karthinks.com/software/scaling-latex-previews-in-emacs/</link>
      <pubDate>Fri, 25 Feb 2022 02:39:00 +0530</pubDate>
      
      <guid>https://karthinks.com/software/scaling-latex-previews-in-emacs/</guid>
      <description>&lt;p&gt;This is a post in my &lt;a href=&#34;https://karthinks.com/tags/latex&#34;&gt;Latex editing series&lt;/a&gt;, an awkward solution to a tiny problem.&lt;/p&gt;
&lt;h2 id=&#34;the-problem&#34;&gt;The Problem&lt;/h2&gt;
&lt;p&gt;A common issue with &lt;a href=&#34;https://karthinks.com/software/latex-input-for-impatient-scholars/#in-buffer-previews--m-x-preview-buffer&#34;&gt;Latex previews in Emacs&lt;/a&gt;: The preview images don&amp;rsquo;t scale when you rescale text in &lt;code&gt;latex-mode&lt;/code&gt; or &lt;code&gt;org-mode&lt;/code&gt;:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/org-scale-latex-demo-pre.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/org-scale-latex-demo-pre.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;&lt;small&gt;&lt;a href=&#34;https://karthinks.com/img/org-scale-latex-demo-pre.mp4&#34;&gt;Direct link to video&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;p&gt;This makes it cumbersome to work with Latex math in Emacs when dealing with different sized monitors or when presenting from Emacs with &lt;a href=&#34;https://github.com/takaxp/org-tree-slide&#34;&gt;Org Tree Slide&lt;/a&gt;, for example.&lt;/p&gt;
&lt;p&gt;A good solution would be to re-render these fragment images at a higher resolution when applying text scaling. The current version of org-mode (9.52 as of this writing) is very slow to render Latex previews and locks up Emacs for a while, this is not a workable solution.&lt;/p&gt;
&lt;p&gt;There are a couple of ways this could be improved: For Org, call an async process to render Latex fragments, or better yet, reuse AucTeX&amp;rsquo;s &lt;code&gt;preview-latex&lt;/code&gt; library for fast, near instant updates.
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Instant Org previews with preview-latex are now feasible, see the &lt;a href=&#34;https://karthinks.com/software/fast-latex-previews-in-org-mode/&#34;&gt;next post&lt;/a&gt; in this series.
&lt;/small&gt;&lt;/span&gt;
For Latex, adjust the &lt;code&gt;preview-scale&lt;/code&gt; variable and regenerate the fragments at each new text scale. These are projects for another day, or for someone more proficient.&lt;/p&gt;
&lt;h2 id=&#34;the-hack&#34;&gt;The Hack&lt;/h2&gt;
&lt;p&gt;After asking around for an alternative, I settled on writing a big ol&amp;rsquo; hack: Just zoom in on the preview images when increasing the text scale:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/org-scale-latex-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/org-scale-latex-demo.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;&lt;small&gt;&lt;a href=&#34;https://karthinks.com/img/org-scale-latex-demo.mp4&#34;&gt;Direct link to video&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;p&gt;This is fast and cheap, but the downside is that the images get blurry:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/org-scale-latex-blur.png&#34; width=&#34;700px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Using SVG fragments can mitigate this problem, at least for Org previews:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;org-preview-latex-default-process&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;dvisvgm&lt;/span&gt;) &lt;span style=&#34;color:#888&#34;&gt;;No blur when scaling&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;the-recipe&#34;&gt;The Recipe&lt;/h2&gt;
&lt;p&gt;Preview images are handled using &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Overlays.html&#34;&gt;overlays&lt;/a&gt;, so the image scaling is done by scanning for and adjusting appropriate overlay properties when changing the text scale:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/text-scale-adjust-latex-previews&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Adjust the size of latex preview fragments when changing the
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;buffer&amp;#39;s text scale.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;pcase&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;major-mode&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;latex-mode&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#007020&#34;&gt;dolist&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlays-in&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point-min&lt;/span&gt;) (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point-max&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;eq&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-get&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;category&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;preview-overlay&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;my/text-scale--resize-fragment&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-mode&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#007020&#34;&gt;dolist&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlays-in&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point-min&lt;/span&gt;) (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point-max&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;eq&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-get&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-overlay-type&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;org-latex-overlay&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;my/text-scale--resize-fragment&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/text-scale--resize-fragment&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-put&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;display&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cons&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;image&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;plist-put&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cdr&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;overlay-get&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ov&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;display&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          &lt;span style=&#34;color:#007020&#34;&gt;:scale&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1.0&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.25&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;text-scale-mode-amount&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;text-scale-mode-hook&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;my/text-scale-adjust-latex-previews&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item><item>
      <title>Dired history in Emacs</title>
      <link>https://karthinks.com/software/dired-history-in-emacs/</link>
      <pubDate>Thu, 24 Feb 2022 01:33:00 -0800</pubDate>
      
      <guid>https://karthinks.com/software/dired-history-in-emacs/</guid>
      <description>&lt;p&gt;Emacs is reasonably consistent across its major-modes in its common usage patterns and keybindings. For example, &lt;code&gt;C-M-a&lt;/code&gt; and &lt;code&gt;C-M-e&lt;/code&gt; consistently move you to the beginnings and ends of functions in various language modes, and &lt;code&gt;C-c C-z&lt;/code&gt; moves the focus to REPLs and back. In read-only modes &lt;code&gt;n&lt;/code&gt; and &lt;code&gt;p&lt;/code&gt; move the cursor up and down, and &lt;code&gt;w&lt;/code&gt; generally copies the path, address or URL of the buffer to the kill ring.&lt;/p&gt;
&lt;p&gt;One of these consistent (but less well known) keybindings is for going back and forward across nodes in a tree, arranged into a list: &lt;code&gt;l&lt;/code&gt; and &lt;code&gt;r&lt;/code&gt; traverse your history and &amp;ldquo;forward&amp;rdquo; history of visited help pages in &lt;code&gt;help-mode&lt;/code&gt;, info nodes in &lt;code&gt;Info-mode&lt;/code&gt;
&lt;span class=&#34;sidenote-number&#34;&gt;&lt;small class=&#34;sidenote&#34;&gt;
Info mode takes this further. &lt;code&gt;L&lt;/code&gt; gives you an index of your visited nodes, which is itself placed into history!
&lt;/small&gt;&lt;/span&gt;
, web pages in &lt;code&gt;eww&lt;/code&gt;, locations in &lt;code&gt;pdf-tools&lt;/code&gt; and probably others. I think of this as moving [l]eft or [r]ight across a traversal path.&lt;/p&gt;
&lt;p&gt;But there are some omissions. I frequently find myself using &lt;code&gt;l&lt;/code&gt; and &lt;code&gt;r&lt;/code&gt; in dired buffers to navigate my history of visited dired buffers, where it annoyingly does nothing. I assumed this feature would be part of one of the many, many Emacs packages that extend dired, but while there are big total makeovers (like &lt;a href=&#34;https://github.com/ralesi/ranger.el&#34;&gt;ranger.el&lt;/a&gt;) for dired that include it, there wasn&amp;rsquo;t anything simple.&lt;/p&gt;
&lt;p&gt;So I wrote a helper: &lt;a href=&#34;https://github.com/karthink/dired-hist&#34;&gt;dired-hist&lt;/a&gt;. It&amp;rsquo;s very basic (&amp;lt; 50 LOC) and will remain so, although I might add some customization options in time.&lt;/p&gt;
</description>
    </item><item>
      <title>A Tab Bar Menu in Emacs</title>
      <link>https://karthinks.com/software/a-tab-bar-menu-in-emacs/</link>
      <pubDate>Wed, 29 Dec 2021 22:53:00 +0530</pubDate>
      
      <guid>https://karthinks.com/software/a-tab-bar-menu-in-emacs/</guid>
      <description>&lt;p&gt;One of the first customizations folks make to their Emacs is to hide the menu bar. This makes some sense if you&amp;rsquo;re using a completion UI like Ivy: it&amp;rsquo;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&amp;rsquo; API, you&amp;rsquo;ll need to use a different interface (like &lt;code&gt;customize&lt;/code&gt;). The menu is thus seen as a crutch for new users to outgrow.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s a shame, though. The menu bar serves two useful purposes:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Discoverability&lt;/strong&gt;: &lt;code&gt;M-x&lt;/code&gt; and the &lt;code&gt;describe-*&lt;/code&gt; commands are good for &amp;ldquo;keyword searches&amp;rdquo;, &lt;em&gt;i.e&lt;/em&gt; finding exact names for features that you know exist, including a rough idea of what it might be called (&lt;em&gt;&amp;quot;&amp;hellip;probably ends in &lt;code&gt;-hook&lt;/code&gt;?&amp;quot;&lt;/em&gt;). But what about the unknown unkowns? Unless you chance upon features you want when looking for something else, you&amp;rsquo;re out of luck. The menu bar is a helpful guide to discover features. CUA-mode, one of the most common new user requests is front and center in the menu bar:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/tab-bar-menu-demo-1.png&#34;/&gt;
    &lt;/figure&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Organization&lt;/strong&gt;: The menu bar for any major-mode usually contains a comprehensive collection of options for that mode. Notwithstanding some recent improvements to command filtering, the &lt;code&gt;M-x&lt;/code&gt; interface throws up the entire bag of Emacs&amp;rsquo; commands at you irrespective of the context in which it&amp;rsquo;s called. The &lt;code&gt;describe-*&lt;/code&gt; commands are worse. In contrast, the menu bar changes depending on what modes you have active, and generally provides a relevant set of actions. For example, the menu bar in programming modes provides options for linting, compilation, tracing, code folding and so on.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; The menu in LaTeX or Org-mode is quite different.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;But if we&amp;rsquo;re honest, the real reason the menu bar is avoided tends to be more superficial: &lt;em&gt;it takes up space and does not compose visually with Emacs&amp;rsquo; theming.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s address this too. There are at least two non-invasive approaches to using the menu in Emacs.&lt;/p&gt;
&lt;h2 id=&#34;the-text-mode-menu&#34;&gt;The text-mode menu&lt;/h2&gt;
&lt;p&gt;There&amp;rsquo;s a text-mode menu built into Emacs. Calling &lt;code&gt;tmm-menubar&lt;/code&gt; (bound to &lt;code&gt;M-`&lt;/code&gt; by default) will allow menu-bar access from the minibuffer (or equivalent), helping with discoverability and organization as before:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/tab-bar-menu-demo-3.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://karthinks.com/img/tab-bar-menu-demo-3.mp4&#34;&gt;[TMM-MENUBAR DEMO]&lt;/a&gt;&lt;/p&gt;
&lt;/video&gt;
&lt;h2 id=&#34;the-tab-bar-menu&#34;&gt;The tab-bar menu&lt;/h2&gt;
&lt;p&gt;The second method requires Emacs 28. You can shove the menu into the tab-bar:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/tab-bar-menu-demo-2.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://karthinks.com/img/tab-bar-menu-demo-2.mp4&#34;&gt;[TAB-BAR MENU DEMO]&lt;/a&gt;&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;To do this, you add the built-in function &lt;code&gt;tab-bar-format-menu-bar&lt;/code&gt; to &lt;code&gt;tab-bar-format&lt;/code&gt;, which is the list of widgets to show in the tab bar.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;add-to-list&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;tab-bar-format&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;tab-bar-format-menu-bar&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Contrary to its name, the tab-bar can show &lt;a href=&#34;http://ruzkuku.com/texts/emacs-global.html&#34;&gt;arbitrary information&lt;/a&gt;. For example, the system time and battery information in addition to the menu and open tabs:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/tab-bar-global-demo-1.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;I use tabs (as workspaces) and the tab-bar already, so I prefer this method for accessing the menu occasionally.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Of course, this supposes that the relevant features are available in Emacs either as built-ins or through an installed package.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;I changed the menu button text to &lt;code&gt;𝞴&lt;/code&gt; from the default to further shorten it.&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>Simple folding with Hideshow</title>
      <link>https://karthinks.com/software/simple-folding-with-hideshow/</link>
      <pubDate>Mon, 20 Dec 2021 20:59:00 +0530</pubDate>
      
      <guid>https://karthinks.com/software/simple-folding-with-hideshow/</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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. Both libraries use regular expressions and only support a few languages out of the box, so tree-sitter based folding is going to be a welcome addition whenever it arrives. But that&amp;rsquo;s a story for another day. Today&amp;rsquo;s problem is the user interface, which is independent of the folding backend.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s the keymap for folding-related functions in the two modes:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Key binding&lt;/th&gt;
&lt;th&gt;Hideshow mode&lt;/th&gt;
&lt;th&gt;Key binding&lt;/th&gt;
&lt;th&gt;Outline minor mode&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-a&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;hs-show-all&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-c @ TAB&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;outline-show-children&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-c&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;hs-toggle-hiding&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-k&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;outline-show-branches&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-d&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;hs-hide-block&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-o&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;outline-hide-other&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-e&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;hs-toggle-hiding&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-q&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;outline-hide-sublevels&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-h&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;hs-hide-block&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-l&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;hs-hide-level&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-s&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;hs-show-block&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-t&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;hs-hide-all&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-c @ ESC&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Prefix Command&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-M-h&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;hs-hide-all&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-c @ C-M-s&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;hs-show-all&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;This is irritating on two levels.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The key bindings are on a difficult to use keymap.&lt;/li&gt;
&lt;li&gt;There&amp;rsquo;s no easy entry point and there are too many commands to do simple tasks.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The former is easily rectified by rebinding keys or defining a transient/hydra menu, but the latter takes more work. Designing a better interface to Outline mode&amp;rsquo;s folding functions was one of the original reasons for the creation of Org mode, which did a bang-up job: There&amp;rsquo;s no learning curve to cycling Org headings with &lt;code&gt;TAB&lt;/code&gt;. It &lt;strong&gt;just works&lt;/strong&gt; and there&amp;rsquo;s nothing to look up or remember!&lt;/p&gt;
&lt;p&gt;As of Emacs 28, Outline-mode and its minor-mode variant have acquired &lt;code&gt;outline-cycle&lt;/code&gt;, a convenient fold cycling function inspired by Org. If you&amp;rsquo;re on an older Emacs, there are packages for this: &lt;a href=&#34;https://github.com/tarsius/bicycle&#34;&gt;bicycle&lt;/a&gt; and &lt;a href=&#34;https://github.com/alphapapa/outshine&#34;&gt;outshine&lt;/a&gt;. For Hideshow mode there&amp;rsquo;s &lt;a href=&#34;https://melpa.org/#/hideshow-org&#34;&gt;hideshow-org&lt;/a&gt;, but this bugged out for me because it makes assumptions about the behavior of my already overloaded &lt;code&gt;TAB&lt;/code&gt; key.&lt;/p&gt;
&lt;p&gt;So I took a crack at making a simple Org-like one-key interface to Hideshow.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; autoplay controls loop&gt;
&lt;source src=&#34;https://karthinks.com/img/hs-cycle.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://karthinks.com/img/hs-cycle.mp4&#34;&gt;[HIDESHOW CYCLE DEMO]&lt;/a&gt;&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;(&lt;a href=&#34;https://karthinks.com/img/hs-cycle.mp4&#34;&gt;Direct link&lt;/a&gt; to demo if the embed fails to load.)&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s how it works (bind it to whatever, it&amp;rsquo;s &lt;code&gt;C-TAB&lt;/code&gt; here):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;C-TAB&lt;/code&gt; to cycle between showing unfolded, folded and showing children. (Same as Org)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;C-TAB&lt;/code&gt; with a prefix argument to show arg levels. &lt;em&gt;i.e.&lt;/em&gt; &lt;code&gt;C-3 C-TAB&lt;/code&gt; will show unfolded up to the third level.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;C-S-TAB&lt;/code&gt; to fold/unfold the whole buffer.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I find myself calling &lt;code&gt;hs-cycle&lt;/code&gt; with a numeric level as the prefix arg all the time to get a top-down overview of code at different levels of detail. Here are three views of the same function, folded and unfolded to levels 2 and 4:
&lt;img src=&#34;https://karthinks.com/img/hs-cycle-level.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s it. This combines &lt;code&gt;hs-show-all&lt;/code&gt;, &lt;code&gt;hs-hide-all&lt;/code&gt;, &lt;code&gt;hs-show-block&lt;/code&gt;, &lt;code&gt;hs-hide-block&lt;/code&gt;, &lt;code&gt;hs-toggle-hiding&lt;/code&gt; and  &lt;code&gt;hs-hide-level&lt;/code&gt; into two commands with a hopefully familiar usage pattern. It&amp;rsquo;s not much code either:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;hs-cycle&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;level&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;p&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;message-log-max&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;inhibit-message&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;level&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;pcase&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;last-command&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;hs-cycle&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;hs-hide-level&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;this-command&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;hs-cycle-children&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;hs-cycle-children&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#888&#34;&gt;;; TODO: Fix this case. `hs-show-block&amp;#39; needs to be&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#888&#34;&gt;;; called twice to open all folds of the parent&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#888&#34;&gt;;; block.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;hs-show-block&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;hs-show-block&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;this-command&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;hs-cycle-subtree&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;hs-cycle-subtree&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;hs-hide-block&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;not&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;hs-already-hidden-p&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#963&#34;&gt;hs-hide-block&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#963&#34;&gt;hs-hide-level&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;this-command&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;hs-cycle-children&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;hs-hide-level&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;level&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;this-command&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;hs-hide-level&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;hs-global-cycle&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;pcase&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;last-command&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;hs-global-cycle&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;hs-show-all&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;this-command&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;hs-global-show&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;hs-hide-all&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;details&gt;
&lt;summary&gt;Note to future self&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;This code looks like it has some redundant clauses you can refactor using &lt;code&gt;hs-already-hidden-p&lt;/code&gt;, and like you don&amp;rsquo;t need to set &lt;code&gt;last-command&lt;/code&gt; for all the clauses. Don&amp;rsquo;t try this, it breaks in subtle ways.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;</description>
    </item><item>
      <title>LaTeX Input for Impatient Scholars</title>
      <link>https://karthinks.com/software/latex-input-for-impatient-scholars/</link>
      <pubDate>Wed, 03 Nov 2021 02:54:00 +0530</pubDate>
      
      <guid>https://karthinks.com/software/latex-input-for-impatient-scholars/</guid>
      <description>&lt;p&gt;Ever since Gilles Castel documented his &lt;a href=&#34;https://castel.dev/post/lecture-notes-1/&#34;&gt;method for taking math notes in real-time in Vim&lt;/a&gt;, I&amp;rsquo;ve noticed Emacs users asking if it&amp;rsquo;s possible to replicate this level of speed and convenience typing \(\LaTeX\) in Emacs&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;. Well, it&amp;rsquo;s Emacs. Of course all of this&amp;ndash;and more&amp;ndash;is possible. I write LaTeX all day, and I&amp;rsquo;m about as fast as when writing equations on paper. Sometimes a smidge faster. In this write-up I explain how, but first here&amp;rsquo;s what I mean:&lt;/p&gt;
&lt;p&gt;Math input for the impatient:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-full-demo-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-full-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;Matrices in a hurry:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-matrix-demo-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-matrix-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;A typical statement:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-statement-demo-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-statement-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;style&gt;
.detail-icon {
float: right;
max-width: 25px;
}
.Task {
text-align: center;
background: #bb90b7;
padding-left: 2px;
padding-right: 3px;
border-radius: 4px;
color: black;
}
.tabbox {
background: #E8E9EB;
display: table;
border-radius: 6px;
padding: 6px;
}
&lt;/style&gt;
&lt;h2 id=&#34;tl-dr-just-give-me-the-code&#34;&gt;TL;DR: Just give me the code&lt;/h2&gt;
&lt;p&gt;The rest of this article outlines the components involved in LaTeX editing in Emacs and breaks down the features that are used to speed up text input specifically. &lt;strong&gt;The objective is to enable Emacs to let you type LaTeX, including math, as fast as you can type regular text or write math on paper&lt;/strong&gt;. Fast enough to take live notes, at least.&lt;/p&gt;
&lt;p&gt;You can use the TOC (to the right or below) to gain an overview of the tools involved. The demos might be helpful too.&lt;/p&gt;
&lt;p&gt;The configuration code is available as a single file &lt;a href=&#34;https://gist.github.com/karthink/7d89df35ee9b7ac0c93d0177b862dadb&#34;&gt;here&lt;/a&gt;. It will install three Emacs packages: AucTeX, CDLaTeX and YaSnippet. It does not install any YaS snippets. The snippets I use are &lt;a href=&#34;https://github.com/karthink/yasnippets/tree/master/latex-mode&#34;&gt;here&lt;/a&gt;, but I recommend writing ones that suit your needs instead.&lt;/p&gt;
&lt;p&gt;One of the features included in this code, used to rapidly input LaTeX tables or arrays, is available as a separate package here: &lt;a href=&#34;https://github.com/karthink/lazytab&#34;&gt;Lazytab&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;the-state-of-latex-editing-in-emacs&#34;&gt;The state of LaTeX editing in Emacs&lt;/h2&gt;
&lt;p&gt;This is my rough understanding of LaTeX editing in Emacs:&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://karthinks.com/img/latex_editing_overview.svg&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/latex-editing-overview.png&#34; style=&#34;max-width:110%;&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Click to embiggen. Also every block is a link to the corresponding package.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;At the core is the TeX document structure: the document tree, text and floats, the document class and style, cross-references and citations, other metadata and doc versions&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;. Surrounding it are the islands of concern when using a text editor to create this document: text input and text editing, document navigation, appearance, linting and compilation. The spokes leading into these islands are Emacs packages, libraries or library features that enable or hasten these tasks.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m not qualified to comment on most aspects of this map. Ask an Emacs user who&amp;rsquo;s written a book or two. This article is intended to be a collection of tips to speed up LaTeX editing to the point where you can take live notes, &lt;em&gt;not&lt;/em&gt; a comprehensive guide to editing LaTeX in Emacs. Thus we&amp;rsquo;re mostly looking at the &lt;span class=&#34;Task&#34;&gt;Text Input&lt;/span&gt; block, with quick dips into the Appearance and Text Editing sections. If you&amp;rsquo;re interested in the full picture I recommend starting with the AucTeX manual (&lt;code&gt;C-h i m auctex&lt;/code&gt; in Emacs). It&amp;rsquo;s quite readable, and if you have the rare gene that lets you tolerate manuals, quite pleasant too!&lt;/p&gt;
&lt;p&gt;On account of my ignorance, there are atleast a couple of big omissions in this chart. These are worth mentioning:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/astoff/digestif&#34;&gt;Digestif&lt;/a&gt;: The Language Server for LaTeX in combination with &lt;a href=&#34;https://github.com/joaotavora/eglot&#34;&gt;Eglot&lt;/a&gt; or &lt;a href=&#34;https://github.com/emacs-lsp/lsp-mode&#34;&gt;LSP&lt;/a&gt; should handle many of these tasks: cross-references, citations, linting, autocompletion etc.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/dandavison/xenops&#34;&gt;Xenops&lt;/a&gt;: Xenops is a full suite of tools built on top of the venerable AucTeX that collects the above features into a single package that you can install and use with no configuration. It also adds literate programming support.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you want faster or more convenient ways to do the other tasks, check out the links in the chart above.&lt;/p&gt;
&lt;p&gt;In a future post in this series I plan to cover the Text Editing block, which is different from Input in that it deals primarily with manipulating existing document structure without adding significantly to it. We will end up using a different set of tools from the ones I cover below.&lt;/p&gt;
&lt;h2 id=&#34;the-basic-ingredients&#34;&gt;The basic ingredients&lt;/h2&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/latex-input-block-overview.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Of this bunch, we only need a few ingredients (plus Emacs itself). We build the text input environment we need in three stages of laziness:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;AucTeX, which is the foundation for LaTeX (and ConText) editing in Emacs. It provides commands and minor-modes for all the aspects of document creation above. It provides all the ingredients we need. You could live with just AucTeX and be completely satisfied with your speed of text input and convenience of editing, as I was for many years.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;CDLaTeX, which is a collection of commands and convenience features mostly intended to reduce how much you need to type. This is one of Emacs&amp;rsquo; best kept secrets, and the secret sauce in our recipe.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;YaSnippet, which is a package for Emacs to insert text snippets, &lt;em&gt;i.e.&lt;/em&gt; templates with placeholder fields that you can fill in. Of course, we bend it into doing a lot more. This overlaps in functionality with CDLaTeX in an inconvenient way, but them&amp;rsquo;s the breaks.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s get this out of the way now: A google search for faster LaTeX input in Emacs usually leads people straight to &lt;code&gt;Yasnippet&lt;/code&gt; and the more contemporary &lt;code&gt;auto-activating-snippets&lt;/code&gt; packages. While I make some use of &lt;code&gt;Yasnippet&lt;/code&gt; in the demos above (and below), I think heavy use of expanding snippets is the &lt;strong&gt;wrong&lt;/strong&gt; approach to speed up your LaTeX editing. More on this &lt;a href=&#34;#snippets-snap-easy&#34;&gt;in a bit&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The remaining packages in the Text input block above mostly overlap in function with the above:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;tempo&lt;/code&gt;, &lt;code&gt;skeleton&lt;/code&gt; and &lt;code&gt;abbrev&lt;/code&gt; all offer some flavor of template insertion or expansion. YaSnippet and CDLaTeX handle this and do a lot more besides.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;capfs&lt;/code&gt;, or the &lt;code&gt;completion-at-point&lt;/code&gt; functionality is provided by AucTeX, but we will seldom need it because of how we enter text. If you need it to complete a keyword for whatever reason, you can call &lt;code&gt;completion-at-point&lt;/code&gt; or use one of many packages that act as frontends for it, such as &lt;code&gt;company-mode&lt;/code&gt; or &lt;code&gt;corfu&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;auto-activating-snippets&lt;/code&gt; and its add-on &lt;code&gt;LaTeX-auto-activating-snippets&lt;/code&gt;: This is a cleaner and faster implementation of the specific functionality that we use YaSnippet for. If I was to start over I would probably use these, so do check them out.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;LaTeX-math-mode&lt;/code&gt;, part of AucTeX. This is a method to insert mathematical symbols efficiently. CDLaTeX does it better though.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;So we begin with AucTeX, then add CDLaTeX and pile on YaSnippet at the end. With each addition we gain a boost in the speed of LaTeX input, but also introduce a little more jank and make the tower teeter a bit. I&amp;rsquo;ve been using the former two for decades and added YaS a few years ago, and I think I&amp;rsquo;ve worked most bugs out of the system by now. Still, &lt;em&gt;caveat emptor&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;All set? OK, let&amp;rsquo;s go.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;A note for org-mode users &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/org-mode-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Org-mode has very good support for LaTeX input out of the box, so you can use the tips in this article with minimal modifications. When necessary, I add org-mode specific details below.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h2 id=&#34;step-1-auctex&#34;&gt;Step 1: AucTeX&lt;/h2&gt;
&lt;p&gt;AucTeX does most of the work of creating a full fledged LaTeX editing environment, leaving us with the task of adding time-saving convenience features.&lt;/p&gt;
&lt;p&gt;AucTeX is generally responsible for providing completions when typing. The most general, always available options for text input are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Insert an arbitrary environment with &lt;code&gt;LaTeX-environment&lt;/code&gt; (&lt;code&gt;C-c C-e&lt;/code&gt;),&lt;/li&gt;
&lt;li&gt;or a macro with &lt;code&gt;TeX-insert-macro&lt;/code&gt; (&lt;code&gt;C-c C-m&lt;/code&gt;), which it will do so after prompting you for arguments.&lt;/li&gt;
&lt;li&gt;Insert a section header with &lt;code&gt;LaTeX-section&lt;/code&gt; (&lt;code&gt;C-c C-s&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Further below I describe much faster ways to do this, however, so treat this as a fallback option that&amp;rsquo;s always available.&lt;/p&gt;
&lt;p&gt;A couple of AucTeX&amp;rsquo;s convenience features I use that do not pertain to text input:&lt;/p&gt;
&lt;h3 id=&#34;outlines&#34;&gt;Outlines&lt;/h3&gt;
&lt;p&gt;I turn on &lt;code&gt;outline-minor-mode&lt;/code&gt; in TeX buffers so I can fold sections, jump across section headings and so on. If you use Emacs 28 or higher this enables the &lt;code&gt;outline-cycle&lt;/code&gt; command that you can use to cycle section visibility with a single key like in Org-mode. I bind it to &lt;code&gt;TAB&lt;/code&gt; like in Org-mode&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;tabbox&#34;&gt;TAB&amp;rsquo;ometer count: 2 (&lt;code&gt;outline-cycle&lt;/code&gt; and &lt;code&gt;LaTeX-indent-line&lt;/code&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Here are a couple of useful appearance-related AucTeX features that inject a bit of WYSIWYG into the document:&lt;/p&gt;
&lt;h3 id=&#34;pretty-symbols--m-x-prettify-symbols-mode&#34;&gt;Pretty symbols (&lt;code&gt;M-x prettify-symbols-mode&lt;/code&gt;)&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;prettify-symbols-mode&lt;/code&gt; in LaTeX buffers will replace math symbols with more readable unicode equivalents. This makes parsing equations much easier:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/latex-prettify-symbols-1.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;This is for display only, the underlying text does &lt;em&gt;not&lt;/em&gt; change. You can still search for the text in these symbols, for instance.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s nothing to set up, AucTeX defines these replacements for you. Just turn on &lt;code&gt;prettify-symbols-mode&lt;/code&gt;:&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Turning on &lt;code&gt;prettify-symbols&lt;/code&gt; &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/term-logo.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;LaTeX-mode-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;prettify-symbols-mode&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;Pretty symbols in org-mode &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/org-mode-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Org has its own version of &lt;code&gt;prettify-symbols-mode&lt;/code&gt;. Use &lt;code&gt;M-x org-toggle-pretty-entities&lt;/code&gt; instead. It&amp;rsquo;s bound to &lt;code&gt;C-c C-x \&lt;/code&gt; by default.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;in-buffer-previews--m-x-preview-buffer&#34;&gt;In-buffer previews (&lt;code&gt;M-x preview-buffer&lt;/code&gt;)&lt;/h3&gt;
&lt;p&gt;What&amp;rsquo;s better than replacing individual symbols with unicode characters? Replacing entire equations and figures with compiled previews:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/latex-preview-equation-1.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Moving the cursor over the equation will temporarily remove the image overlay and allow you to edit the environment:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-preview-edit-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-preview-edit-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;You can preview the environment at point, active region, section or the entire buffer, they&amp;rsquo;re all bound under the preview map (&lt;code&gt;C-c C-p&lt;/code&gt;). A common practice is to auto-preview math environments whenever you move out of one, and many packages provide this feature. Over the decades I&amp;rsquo;ve found this more jarring than convenient. I prefer to edit freely (with the pretty symbols turned on) and call &lt;code&gt;preview-section&lt;/code&gt; when I&amp;rsquo;m done.&lt;/p&gt;
&lt;p&gt;I use both appearance enhancements in the demos in this write-up.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Optional: Changing the preview image size &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/term-logo.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;One thing you may want is change the size of the preview images as displayed. Replace the number here with whatever works best for you:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;LaTeX-mode-hook&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;preview-larger-previews&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;preview-scale-function&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                  (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; () (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;1.25&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                           (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;preview-scale-from-face&lt;/span&gt;)))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;In-buffer previews in Org-mode &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/org-mode-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Org has its own version of in-buffer LaTeX previews too. Instead of &lt;code&gt;preview-region&lt;/code&gt;, you would do &lt;code&gt;M-x org-latex-preview&lt;/code&gt;. (Bound to &lt;code&gt;C-c C-x C-l&lt;/code&gt;)&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;the-rest-of-auctex&#34;&gt;The rest of AucTeX&lt;/h3&gt;
&lt;p&gt;AucTeX is comprehensive: For example, &lt;code&gt;TeX-fold-mode&lt;/code&gt; adds another way to hide some of the visual noise when looking at a document, while allowing you to step into the noisy bits seamlessly:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-tex-fold-demo-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-tex-fold-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;&lt;code&gt;TeX-error-&lt;/code&gt; and &lt;code&gt;TeX-command-&lt;/code&gt; deal with compilation and debugging, &lt;code&gt;TeX-view&lt;/code&gt; with viewing output PDFs, &lt;code&gt;TeX-master&lt;/code&gt; with multi-file documents, &lt;code&gt;TeX-documentation&lt;/code&gt; with help and so on. These are beyond the scope of this article.&lt;/p&gt;
&lt;h2 id=&#34;step-2-cdlatex&#34;&gt;Step 2: CDLaTeX&lt;/h2&gt;
&lt;p&gt;CDLaTeX provides a collection of convenience functions that speed up editing LaTeX documents.&lt;/p&gt;
&lt;p&gt;This is an understatement. A more accurate assessment would be that after a couple of days of practice, CDLaTeX lets you type in and navigate LaTeX chunks like a motorcyclist weaving through traffic.&lt;/p&gt;
&lt;p&gt;Technically AucTeX already does most of this, but in a stodgy 90s sort of way. Do you want to type &lt;code&gt;C-c C-o C-o&lt;/code&gt; after filling in every math environment? Me neither.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;CDLaTeX in org-mode &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/org-mode-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Instead of installing CDLaTeX you&amp;rsquo;d turn on &lt;code&gt;org-cdlatex-mode&lt;/code&gt;. You don&amp;rsquo;t even need to install CDLaTeX, it&amp;rsquo;s already on your system! Org-cdlatex-mode is part of Org.&lt;/p&gt;
&lt;p&gt;This is not a coincidence. CDLaTeX was written by Carsten Dominik (hence the CD), who was also the primary author of Org-mode.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;the-tabinator&#34;&gt;The TABinator&lt;/h3&gt;
&lt;p&gt;CDLaTeX&amp;rsquo;s best trick is its heavy overloading of the &lt;code&gt;TAB&lt;/code&gt; key. Pressing &lt;code&gt;TAB&lt;/code&gt; jumps you to the next &amp;ldquo;point of interest&amp;rdquo;, placing your cursor at convenient spots for text input. This is much simpler to watch than to explain. Here I navigate through a chunk of my document with a hundred presses of the &lt;code&gt;TAB&lt;/code&gt; key and nothing else:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-cdlatex-tab-demo-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-cdlatex-tab-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;The heuristic it uses for where &lt;code&gt;TAB&lt;/code&gt; should jump to next is generally pretty good, and handles delimiters and LaTeX macros adroitly:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-cdlatex-tab-demo-2.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-cdlatex-tab-demo-2.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;In this example, it jumps from outside the &lt;code&gt;\left(&lt;/code&gt; to before the integral, then to the integrand, then the variable of integration, and finally past the &lt;code&gt;\right)&lt;/code&gt;. As the manual helpfully summarizes:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When in doubt, press TAB.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;span class=&#34;tabbox&#34;&gt;TAB&amp;rsquo;ometer count: 3 (Jumping around with &lt;code&gt;cdlatex-tab&lt;/code&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;h3 id=&#34;entering-symbols&#34;&gt;Entering symbols&lt;/h3&gt;
&lt;p&gt;Typing in the grave key (&lt;code&gt;`&lt;/code&gt;) and a letter inserts symbols into the buffer, automatically adding inline math dollars if necessary:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-cdlatex-symbol-demo-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-cdlatex-symbol-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;The keys are chosen to be mnemonic:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;`&lt;/code&gt; and a-z (A-Z) insert greek letters (uppercase), so &lt;code&gt;`a&lt;/code&gt; gives &lt;code&gt;\alpha&lt;/code&gt;, &lt;code&gt;`L&lt;/code&gt; gives &lt;code&gt;\Lambda&lt;/code&gt; etc&lt;/li&gt;
&lt;li&gt;&lt;code&gt;`&lt;/code&gt; plus keys to insert arrows:
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;key&lt;/th&gt;
&lt;th&gt;grave &lt;code&gt;`&lt;/code&gt; + key&lt;/th&gt;
&lt;th&gt;two graves &lt;code&gt;` `&lt;/code&gt; + key&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\rightarrow\) or \(\leftarrow\)&lt;/td&gt;
&lt;td&gt;\(\longrightarrow\) or \(\longleftarrow\)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;]&lt;/code&gt; or &lt;code&gt;[&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\Rightarrow\) or \(\Leftarrow\)&lt;/td&gt;
&lt;td&gt;\(\Longrightarrow\) or \(\Longleftarrow\)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;^&lt;/code&gt; or &lt;code&gt;_&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\uparrow\) or \(\downarrow\)&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\Leftrightarrow\)&lt;/td&gt;
&lt;td&gt;\(\Longleftrightarrow\)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are mappings for symbols for other operations, such as on sets etc. But you don&amp;rsquo;t need to remember any of this: a menu with hints pops up if you wait for a second. There are actually three layers of symbols, with less common ones accessed via repeated presses of the grave key: &lt;code&gt;` `&amp;lt;key&amp;gt;&lt;/code&gt; and &lt;code&gt;` ` `&amp;lt;key&amp;gt;&lt;/code&gt;:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-cdlatex-symbol-demo-2.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-cdlatex-symbol-demo-2.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;I found myself typing the first layer of symbols (single &lt;code&gt;`&lt;/code&gt;) automatically after a couple of days of using CDLaTeX, and usually waiting for the hints to pop up for the less common symbols in the double &lt;code&gt;` `&lt;/code&gt; and triple grave menu.&lt;/p&gt;
&lt;p&gt;You can change or add to this list of symbols by customizing &lt;code&gt;cdlatex-math-symbol-alist&lt;/code&gt;. Lastly, if you need to type in a literal grave key in your document you can prefix it with &lt;code&gt;C-q&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Note: There is also &lt;code&gt;TeX-math-mode&lt;/code&gt;, provided by AucTeX that does something very similar.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Symbol entry in Org-mode &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/org-mode-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;&lt;code&gt;org-cdlatex&lt;/code&gt; inserts symbols in org-mode without the math delimiters. This is because it&amp;rsquo;s less visually distracting this way and Org&amp;rsquo;s LaTeX export backend automatically adds the delimiters.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;math-and-text-modifiers&#34;&gt;Math and Text modifiers&lt;/h3&gt;
&lt;p&gt;You can add modifiers to typed in text with the single quote (&lt;code&gt;&#39;&lt;/code&gt;). This includes things like hats, dots, tildes and graves and over/underlines on symbols, as well as font style changes in both math and text modes:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-cdlatex-symbol-demo-3.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;As before, typing in a quote &lt;code&gt;&#39;&lt;/code&gt; and waiting pops up a window with hints. (There are many more modifiers available here, I use only a few.)&lt;/p&gt;
&lt;p&gt;This works the other way too. You can start with the modifier and type in the symbol or text after:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-cdlatex-symbol-demo-4.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-cdlatex-symbol-demo-4.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;You can change or add to this list by customizing &lt;code&gt;cdlatex-math-modify-alist&lt;/code&gt;. To type in a literal quote you can use &lt;code&gt;&#39;&#39;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The live help feature of CDLaTeX used to be a revelation ten years ago. These days &lt;code&gt;which-key&lt;/code&gt; and other packages have brought this to all of Emacs.&lt;/p&gt;
&lt;h3 id=&#34;environments-and-math-templates&#34;&gt;Environments and Math templates&lt;/h3&gt;
&lt;p&gt;CDLaTeX defines a collections of templates that expand into environments with &lt;code&gt;TAB&lt;/code&gt;. You can then &lt;code&gt;TAB&lt;/code&gt; your way across text fields in that expansion. In text mode, for example, you can type in &lt;code&gt;equ&amp;lt;tab&amp;gt;&lt;/code&gt; to generate an equation environment or &lt;code&gt;sn&amp;lt;tab&amp;gt;&lt;/code&gt; for a section, &lt;code&gt;fg&amp;lt;tab&amp;gt;&lt;/code&gt; for a figure and &lt;code&gt;inc&amp;lt;tab&amp;gt;&lt;/code&gt; for an &lt;code&gt;\includegraphics&lt;/code&gt; macro. &lt;code&gt;env&amp;lt;tab&amp;gt;&lt;/code&gt; or &lt;code&gt;beg&amp;lt;tab&amp;gt;&lt;/code&gt; will insert any environment with prompting. Here are a few examples:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-cdlatex-templates-demo-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-cdlatex-templates-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;(Note that I used &lt;code&gt;TAB&lt;/code&gt; to both insert the template templates and navigate the document here.)&lt;/p&gt;
&lt;p&gt;There are similar shortcuts for common delimiters and macros inside math environments. For example, it modifies caret (&lt;code&gt;^&lt;/code&gt;) and underscore (&lt;code&gt;_&lt;/code&gt;) to insert &lt;code&gt;^{}&lt;/code&gt; and &lt;code&gt;_{}&lt;/code&gt;, and gracefully handles the braces. Here are more examples:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-cdlatex-templates-demo-2.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-cdlatex-templates-demo-2.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;You can, of course, add your own. I added a few environments to enter AMSMath style matrices by customizing &lt;code&gt;cdlatex-command-alist&lt;/code&gt;. (Demo of matrix/array input &lt;a href=&#34;#table-matrix-or-array-entry&#34;&gt;below&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;This is familiar, expected stuff: these appear to be snippets like those provided by other packages. But there&amp;rsquo;s one crucial difference. The text fields in a template/snippet inserter like YaSnippet lose their special meaning once the insertion is complete. CDLaTeX&amp;rsquo;s &lt;code&gt;TAB&lt;/code&gt; does &lt;em&gt;not&lt;/em&gt; use special markers in the template, but a heuristic method to jump forward instead. So you can revisit these fields (and intermediate ones) in the same order at any time. See &lt;a href=&#34;#snippets-snap-easy&#34;&gt;Snippets snap easy&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;tabbox&#34;&gt;TAB&amp;rsquo;ometer count: 4 (Expand CDLaTeX templates with &lt;code&gt;cdlatex-tab&lt;/code&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;h3 id=&#34;we-could-stop-here-and-things-would-be-good-dot&#34;&gt;We could stop here, and things would be Good.&lt;/h3&gt;
&lt;p&gt;With fast symbol, modifier and environment insertion AucTeX and CDLaTeX together offer a stable and speedy LaTeX input and editing experience. The complete customizability of these features usually puts them well ahead of an online suite (like Overleaf) or LaTeX IDE (like TeXStudio) for most editing tasks&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a href=&#34;#fn:4&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;You can skip to the section on &lt;a href=&#34;#putting-it-into-practice&#34;&gt;Putting it into practice&lt;/a&gt; now if this covers what you need.&lt;/p&gt;
&lt;p&gt;But our laziness and impatience knows no bounds. Hitting &lt;code&gt;TAB&lt;/code&gt; every other second is too much work, as is typing arcane modifiers like &lt;code&gt;&#39;^&lt;/code&gt; or &lt;code&gt;&#39;}&lt;/code&gt;. That &lt;code&gt;Shift&lt;/code&gt; key can really tire out the pinkies, especially if you type LaTeX all day. So it&amp;rsquo;s time for&amp;hellip;&lt;/p&gt;
&lt;h2 id=&#34;step-3-yasnippet-and-automatic-snippets&#34;&gt;Step 3: Yasnippet &amp;amp; automatic snippets&lt;/h2&gt;
&lt;p&gt;We use Yasnippet primarily for auto-expansion of snippets. Auto-expansion implies that there&amp;rsquo;s no need to hit &lt;code&gt;TAB&lt;/code&gt;. This is useful when trying to take notes and keep up with a speaker, for instance. In my experience this can get quite annoying if you&amp;rsquo;re not expecting it, so I use it for only a select few cases&lt;sup id=&#34;fnref:5&#34;&gt;&lt;a href=&#34;#fn:5&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;5&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;If AucTeX and CDLaTeX are the soup, think of YaSnippet as the garnish added at the end for some extra flavor.&lt;/p&gt;
&lt;p&gt;To make YaSnippet expand snippets automatically, we&amp;rsquo;re going to bend it into shape.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Auto-expansion with YaSnippet &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/term-logo.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; Function that tries to autoexpand YaSnippets&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; The double quoting is NOT a typo!&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/yas-try-expanding-auto-snippets&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;bound-and-true-p&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;yas-minor-mode&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;yas-buffer-local-condition&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;require-snippet-condition&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;auto&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;yas-expand&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; Try after every insertion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;post-self-insert-hook&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;my/yas-try-expanding-auto-snippets&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Elisp note: Adding this check to &lt;code&gt;post-self-insert-hook&lt;/code&gt; might seem crazy, but it does not cause any slowdown that I&amp;rsquo;ve noticed. Check out the &lt;a href=&#34;https://github.com/ymarco/auto-activating-snippets&#34;&gt;auto-activating-snippets&lt;/a&gt; package or &lt;code&gt;abbrev-mode&lt;/code&gt; (Emacs built-in) for a different approach if this bothers you.&lt;/p&gt;
&lt;p&gt;The next step is to declare a snippet as auto-expanding. To do this you add the &lt;code&gt;# condition:&lt;/code&gt; line to snippet definitions. For example, this is the snippet for auto-expanding left and right curly braces:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-cfg&#34; data-lang=&#34;cfg&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# key: set&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# name: set&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# condition: (and (texmathp) &amp;#39;auto)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# group: math&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;# --&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#00c&#34;&gt;\\left\\{ $0 \\right\\}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;See the YaSnippet docs for more details on writing snippets.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;Reusing LaTeX YaSnippets in org-mode &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/org-mode-icon.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;To use your LaTeX Yasnippets in Org, you can copy them to the org section of your snippets directory, or better yet, add a file named &lt;code&gt;.yas-parents&lt;/code&gt; in the org snippets folder with the contents&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;latex-mode
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This makes all the &lt;code&gt;latex-mode&lt;/code&gt; snippets available in Org as well.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;My snippets are &lt;a href=&#34;https://github.com/karthink/yasnippets/tree/master/latex-mode&#34;&gt;here&lt;/a&gt;, but these are tailored to the kind of math I use (mostly Calculus and  Linear Algebra). I straight up stole most of these &lt;a href=&#34;https://github.com/gillescastel/latex-snippets&#34;&gt;from Gilles Castel&lt;/a&gt;. There are many snippets here for historical reasons. I only use a few.&lt;/p&gt;
&lt;p&gt;Consider the auto-expanding examples below as examples to inspire you to write ones more suited to your needs.&lt;/p&gt;
&lt;h3 id=&#34;create-math-environments&#34;&gt;Create math environments&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;mk&lt;/code&gt; and &lt;code&gt;dm&lt;/code&gt; create inline and equation environments. There&amp;rsquo;s nothing special about these shortcuts, they&amp;rsquo;re easier to type than &lt;code&gt;$&lt;/code&gt;, &lt;code&gt;$$&lt;/code&gt; or &lt;code&gt;\[ \]&lt;/code&gt; and not words by themselves. (YaSnippet expands only at word boundaries, so Words like &amp;ldquo;admin&amp;rdquo; or &amp;ldquo;gymkhana&amp;rdquo; will not trigger these snippets.)&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a demo (where I also use the CDLaTeX symbols, math modifiers and templates from above):&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-yasnippet-math-demo-1.mp4&#34; type=&#34;&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-yasnippet-math-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;h3 id=&#34;faster-math-modifiers&#34;&gt;Faster math modifiers&lt;/h3&gt;
&lt;p&gt;Replace cdlatex&amp;rsquo;s &lt;code&gt;&#39;^&lt;/code&gt; → &lt;code&gt;\hat{}&lt;/code&gt; with just typing &amp;ldquo;hat&amp;rdquo; after a symbol. This way I can type how I read or hear math: &lt;code&gt;a hat&lt;/code&gt; gives me \(\hat{a}\), and so on:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-yasnippet-hat-demo-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-yasnippet-hat-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;I make a few more such automatic translations:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;I type&lt;/th&gt;
&lt;th&gt;Becomes&lt;/th&gt;
&lt;th&gt;Mnemonic&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;x sr&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(x²\)&lt;/td&gt;
&lt;td&gt;x squared&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;x cb&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(x³\)&lt;/td&gt;
&lt;td&gt;x cubed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;x td&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(x^{\{\}}\)&lt;/td&gt;
&lt;td&gt;x to the&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;x conj&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(x^{\star} \)&lt;/td&gt;
&lt;td&gt;x conjugate&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;x adj&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(x^{\dagger} \)&lt;/td&gt;
&lt;td&gt;x adjoint&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Where &lt;code&gt;x&lt;/code&gt; is any symbol or s-expression (i.e. delimited expression). Check &lt;a href=&#34;#putting-it-into-practice&#34;&gt;Putting it into practice&lt;/a&gt; to see these in action.&lt;/p&gt;
&lt;p&gt;Note that this behavior involves editing the buffer prior to the point, and is not possible with Emacs&amp;rsquo; built-in &lt;code&gt;abbrev&lt;/code&gt; library. In most other cases &lt;code&gt;abbrev-mode&lt;/code&gt; can suffice for auto-expansion.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Suppressing Yasnippet warnings &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/term-logo.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;YaSnippet complains if we use a snippet to edit the buffer directly, as we do with the above examples of wrapping symbols in &lt;code&gt;\hat{}&lt;/code&gt;, etc. This is probably bad practice, but I haven&amp;rsquo;t had an issue yet. I suppress these warnings with&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;with-eval-after-load&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;warnings&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;cl-pushnew&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;yasnippet&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;backquote-change&lt;/span&gt;) &lt;span style=&#34;color:#963&#34;&gt;warning-suppress-types&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              &lt;span style=&#34;color:#007020&#34;&gt;:test&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;equal&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;faster-frac&#34;&gt;Faster &lt;code&gt;\frac&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Make &lt;code&gt;//&lt;/code&gt; set up a &lt;code&gt;\frac&lt;/code&gt; expression:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-yasnippet-frac-demo-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-yasnippet-frac-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;h3 id=&#34;useful-simple-replacements&#34;&gt;Useful simple replacements&lt;/h3&gt;
&lt;p&gt;These are simple but useful auto-replacements for my purposes:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;I type&lt;/th&gt;
&lt;th&gt;Becomes&lt;/th&gt;
&lt;th&gt;Which is&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;neq&lt;/code&gt;, &lt;code&gt;leq&lt;/code&gt; or &lt;code&gt;geq&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\ne \), \(\le \) or \(\ge \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\ne&lt;/code&gt;, &lt;code&gt;\le&lt;/code&gt; or &lt;code&gt;\ge&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;~~&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\sim \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\sim&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-&amp;gt;&lt;/code&gt; and &lt;code&gt;=&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\( \to \) and \( \implies \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\to&lt;/code&gt; and &lt;code&gt;\implies&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;inn&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\in \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\in&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;set&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\{ \} \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\{ \}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;cc&lt;/code&gt; or &lt;code&gt;cceq&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\subset \) or \(\subseteq \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\subset&lt;/code&gt; or &lt;code&gt;\subseteq&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;EE&lt;/code&gt; or &lt;code&gt;nEE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\exists \) or \(\nexists \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\exists&lt;/code&gt; or &lt;code&gt;\nexists&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;VV&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\forall \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\forall&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;xx&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\times \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\times&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ox&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\otimes \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\otimes&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;o+&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\oplus \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\oplus&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;...&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\dots \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\dots&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;;.&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\vdots  \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\vdots&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;;/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\(\ddots \)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\ddots&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;,,&lt;/code&gt; or &lt;code&gt;;;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;\( \&amp;amp;  \) or &lt;code&gt;\\&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;field sep or linebreak&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;And so on. This functionality overlaps somewhat with cdlatex&amp;rsquo;s symbol entry (&lt;code&gt;`&lt;/code&gt;) command, and you could add these there instead. The point of these is not so much to save time as it is to preserve the flow of my thoughts when writing. I type them as I sound them out in my head (thus &lt;code&gt;leq&lt;/code&gt; instead of &lt;code&gt;\le&lt;/code&gt;, &lt;code&gt;x adj&lt;/code&gt; instead of &lt;code&gt;x^{\dag}&lt;/code&gt;) and they&amp;rsquo;re automatically changed to the correct symbols. You can catch many of these replacements in the demos at the start of this write-up.&lt;/p&gt;
&lt;h3 id=&#34;optional-conventional-snippets-with-multiple-placeholders&#34;&gt;Optional: conventional snippets with multiple placeholders&lt;/h3&gt;
&lt;p&gt;You can also add some more conventional snippets in the mix. I use these quite often for derivatives and definite integrals, for instance:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-yasnippet-ddt-demo-4.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-yasnippet-ddt-demo-4.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;In principle these can just be added to the &lt;code&gt;cdlatex-command-alist&lt;/code&gt; instead (which is much simpler to set up), but the above are relics of more experimental times that I&amp;rsquo;ve not bothered to change.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s also tempting to set up snippets for typing in arrays, matrices or vectors, whose syntax has a lot of structure. However there is a better way, see &lt;a href=&#34;#table-matrix-or-array-entry&#34;&gt;table, matrix or array entry&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;tabbox&#34;&gt;TAB&amp;rsquo;ometer count: 5 (Expand a conventional YaSnippet with &lt;code&gt;yas-expand&lt;/code&gt;.)&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&#34;snippets-snap-easy&#34;&gt;Snippets snap easy&lt;/h2&gt;
&lt;p&gt;Template or snippet based insertion is a very limited form of interaction with the document, both in time and space. The placeholder fields retain their special navigation and insertion behavior only until the snippet &amp;ldquo;exits&amp;rdquo;, and this behavior is not available anywhere else in the document.&lt;/p&gt;
&lt;p&gt;Snippets are rigid and monolithic, in that you have to bake in all the variables (such as field locations, mirrors or transformations) in the definition, and can&amp;rsquo;t modify it on the fly. They&amp;rsquo;re also brittle: things often break if you deviate from the expected behavior of &lt;code&gt;TAB&lt;/code&gt; → insert text → &lt;code&gt;TAB&lt;/code&gt; → insert text. For example, when you move the cursor away to copy something from another part of the document to a snippet field. They&amp;rsquo;re modal in a bad way: you can exit the snippet mode but there&amp;rsquo;s no resuming their state without starting over.&lt;/p&gt;
&lt;p&gt;What we would like instead is snippet-like navigation between fields, including field transformations, but at any time, anywhere in the document, and without the notion of a snippet being &amp;ldquo;active&amp;rdquo;. CDlatex&amp;rsquo;s &lt;code&gt;TAB&lt;/code&gt; goes some way towards this ideal, but its regex based jump heuristic is quite limited compared to what&amp;rsquo;s possible.&lt;/p&gt;
&lt;p&gt;I can imagine a better system through some combination of Vim/ &lt;code&gt;evil-mode&lt;/code&gt; style text-objects, a semantically aware tree-sitter based LaTeX parser and a further improved CDLaTeX style DWIM command set that&amp;rsquo;s integrated into AucTeX. That&amp;rsquo;s without bringing AI helpers into the picture. Maybe something like this already exists or is in the works for &lt;code&gt;$MODERN_EDITOR&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But there&amp;rsquo;s no need to let perfect be the enemy of good enough. A little bit of YaS to plaster over the gaps goes a long way.&lt;/p&gt;
&lt;h2 id=&#34;putting-it-into-practice&#34;&gt;Putting it into practice&lt;/h2&gt;
&lt;h3 id=&#34;environment-floats-and-math-input&#34;&gt;Environment, floats and math input&lt;/h3&gt;
&lt;p&gt;The goal is to write LaTeX (and especially math) in a way that mirrors our stream of thought, where our eyes, fingers and the cursor all glide over the clutter of the markup. The above described process isn&amp;rsquo;t quite there yet, but it&amp;rsquo;s close. In summary,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Turn on &lt;code&gt;prettify-symbols-mode&lt;/code&gt; to enhance readability.&lt;/li&gt;
&lt;li&gt;Enter symbols with grave (&lt;code&gt;`&lt;/code&gt;) and modify text or macros with the quote (&lt;code&gt;&#39;&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;TAB&lt;/code&gt; to jump forward to the next &amp;ldquo;point of interest&amp;rdquo; when typing.&lt;/li&gt;
&lt;li&gt;Insert environment and float templates with CDLaTeX&amp;rsquo;s commands or YaS snippets. &lt;code&gt;env &amp;lt;tab&amp;gt;&lt;/code&gt; for an arbitrary environment (with completion).&lt;/li&gt;
&lt;li&gt;Use YaS&amp;rsquo; auto-expanding snippets (or &lt;code&gt;abbrev-mode&lt;/code&gt; abbrevs) to type without breaking the flow. Generally useful, but especially handy for math operators.&lt;/li&gt;
&lt;li&gt;Preview your work with &lt;code&gt;preview-&lt;/code&gt; commands. &lt;code&gt;preview-at-point&lt;/code&gt; is quite handy.&lt;/li&gt;
&lt;li&gt;When everything else fails, use the slower but fully document aware AucTeX commands: &lt;code&gt;LaTeX-environment&lt;/code&gt; (&lt;code&gt;C-c C-e&lt;/code&gt;)  and &lt;code&gt;TeX-insert-macro&lt;/code&gt; (&lt;code&gt;C-c C-m&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here I type in a simple equation using many of the features we discussed above:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-full-demo-4.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-full-demo-4.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Start an equation env with &lt;code&gt;dm&lt;/code&gt; (YaS)&lt;/li&gt;
&lt;li&gt;Expand an integral snippet with &lt;code&gt;intl &amp;lt;tab&amp;gt;&lt;/code&gt; (cdlatex, but you could define a YaS for this)&lt;/li&gt;
&lt;li&gt;Tab my way through the integration limits, use &lt;code&gt;` 8&lt;/code&gt; to enter \(∞\) as the upper limit (CDLaTeX symbol)&lt;/li&gt;
&lt;li&gt;Obtain \(e^{\{\}}\) by auto-expansion of &lt;code&gt;e td&lt;/code&gt; (YaS)&lt;/li&gt;
&lt;li&gt;Obtain \(- x^2 \) as the exponent from &lt;code&gt;-x sr&lt;/code&gt; (YaS)&lt;/li&gt;
&lt;li&gt;Obtain &lt;code&gt;\mathrm{d}&lt;/code&gt; from following &lt;code&gt;d&lt;/code&gt; with &lt;code&gt;&#39;r&lt;/code&gt; (CDLaTeX math modifier)&lt;/li&gt;
&lt;li&gt;Type in &lt;code&gt;π&lt;/code&gt; on the right hand side as &lt;code&gt;`p&lt;/code&gt; (CDLaTeX symbol)&lt;/li&gt;
&lt;li&gt;Obtain \(\pi^{\{\}}\) by auto-expansion of &lt;code&gt;\pi td&lt;/code&gt; (YaS)&lt;/li&gt;
&lt;li&gt;Get \(\frac{1}{2} \) as the exponent of \(\pi \) using the auto-expansion of &lt;code&gt;1 // 2&lt;/code&gt; (YaS)&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;preview-at-point&lt;/code&gt; to preview the equation using a keybinding.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;table-matrix-or-array-entry&#34;&gt;Table, matrix or array entry&lt;/h3&gt;
&lt;p&gt;In my &lt;a href=&#34;../batteries-included-with-emacs&#34;&gt;Batteries Included&lt;/a&gt; series I briefly mentioned &lt;code&gt;orgtbl-mode&lt;/code&gt;, a built-in feature of Emacs that brings org-mode style table editing to all buffers. This is a powerful and often underutilized ability that we will use to write LaTeX.&lt;/p&gt;
&lt;p&gt;Org-mode tables are very capable. Folks go as far as maintaining spreadsheets in them, but for our purposes what matters is that you can navigate and edit the table structurally. You can move between cells with &lt;code&gt;TAB&lt;/code&gt;, move columns or cells around, delete or add new ones, transpose the table etc. Using this to input matrices or arrays in a free-form way feels very natural. The speed-up is a bonus. Here I&amp;rsquo;ve rigged my CDLaTeX snippets for typing in matrices to automatically start &lt;code&gt;orgtbl-mode&lt;/code&gt;. When I&amp;rsquo;m done I can press &lt;code&gt;C-c C-c&lt;/code&gt; and the table is converted to a LaTeX array:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-table-demo-3.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-table-demo-3.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;Here is the idea applied to a full matrix equation:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-table-demo-2.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;And here it is applied to a text table. I start by expanding the &lt;code&gt;tbl&lt;/code&gt; template in cdlatex, which I&amp;rsquo;ve set to start an org-mode table. I press &lt;code&gt;C-c C-c&lt;/code&gt; when I&amp;rsquo;m done to generate the LaTeX tabular environment:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-table-demo-4.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-table-demo-4.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;I moved the code for this out of my configuration into a standalone package, although it requires CDLaTeX to be installed. You can find &lt;a href=&#34;https://github.com/karthink/lazytab&#34;&gt;LazyTab here&lt;/a&gt;. Turning a LaTeX array or matrix back into an org-table is not yet implemented.&lt;/p&gt;
&lt;p&gt;&lt;span class=&#34;tabbox&#34;&gt;TAB&amp;rsquo;ometer count: 6 (Next field in an org table with &lt;code&gt;org-table-next-field&lt;/code&gt;.)&lt;/span&gt;&lt;/p&gt;
&lt;h3 id=&#34;cross-references-and-citations&#34;&gt;Cross-references and citations&lt;/h3&gt;
&lt;p&gt;There are many tools for Emacs to help you insert citations and cross-references without hassle, but these are mostly out of the scope of this write-up. You can check the &lt;a href=&#34;#the-state-of-latex-editing-in-emacs&#34;&gt;chart above&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;However, one aspect  that&amp;rsquo;s relevant here is the method of invoking these features. Instead of binding these command to keys (like the commonly used &lt;code&gt;C-c ]&lt;/code&gt; and &lt;code&gt;C-c )&lt;/code&gt;), you can invoke these commands using a snippet. To not break the flow, I use CDLaTeX to expand the words &lt;code&gt;ref&lt;/code&gt; and &lt;code&gt;cite&lt;/code&gt; into calls to my reference and citation handlers:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-cite-ref-demo-2.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-cite-ref-demo-2.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;h3 id=&#34;math-input-using-calc&#34;&gt;Math input using Calc&lt;/h3&gt;
&lt;p&gt;It wouldn&amp;rsquo;t be one of my rambling Emacs pieces if I didn&amp;rsquo;t mention the Emacs Calculator. What can Calc do for you here? Quite a bit, it turns out.&lt;/p&gt;
&lt;p&gt;Calc has a built in parser for handling LaTeX math. While it&amp;rsquo;s pretty basic, it can convert simple objects and equations from their &amp;ldquo;programming language&amp;rdquo; representation to LaTeX. The former is usually much simpler to input when using a keyboard. Here I call a helper function that invokes calc on a matrix and an equation:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-calc-demo-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/calc-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;An additional advantage is that Calc can do some math for you in the process. Here I invert the  above matrix in the process of displaying it as a LaTeX array.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/latex-calc-demo-2.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/latex-calc-demo-2.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;Also shown: Some Taylor expansion and integration.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;LaTeX math forms using Calc &lt;span&gt;&lt;img src=&#34;https://karthinks.com/img/term-logo.png&#34; class=detail-icon&gt;&lt;/span&gt;&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;latex-math-from-calc&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Evaluate &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`calc&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; on the contents of line at point.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;cond&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;region-active-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#007020&#34;&gt;let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;beg&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;region-beginning&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;end&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;region-end&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;string&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-substring-no-properties&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;beg&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;end&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;kill-region&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;beg&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;end&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;insert&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;calc-eval&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;string&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;calc-language&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;latex&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                        &lt;span style=&#34;color:#963&#34;&gt;calc-prefer-frac&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                        &lt;span style=&#34;color:#963&#34;&gt;calc-angle-mode&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;rad&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;l&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;thing-at-point&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;line&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;end-of-line&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;kill-line&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;             (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;insert&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;calc-eval&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;l&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                  &lt;span style=&#34;color:#963&#34;&gt;calc-language&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;latex&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                  &lt;span style=&#34;color:#963&#34;&gt;calc-prefer-frac&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                  &lt;span style=&#34;color:#963&#34;&gt;calc-angle-mode&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;rad&lt;/span&gt;)))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;LaTeX-mode-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;C-S-e&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;latex-math-from-calc&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;org-mode-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;C-S-e&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;latex-math-from-calc&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;invoking-other-parsers&#34;&gt;Invoking other parsers&lt;/h3&gt;
&lt;p&gt;Calc is an amazing piece of software, but unfortunately it falls somewhere in between a programmable calculator and a full CAS or numerical computation suite: constantly surprising in its abilities but too limited to use full time. Its built-in LaTeX syntax parser is quite rigid and in non-interactive use the built-in functions have non-standard, hard to remember names. Transpose is &lt;code&gt;trn&lt;/code&gt;, for instance.&lt;/p&gt;
&lt;p&gt;While I haven&amp;rsquo;t set it up, it&amp;rsquo;s also possible to convert programming style formulas into LaTeX strings using a similar interface as the above Calc command, but with more fully featured external program instead. Parsers to do this are available as part of Mathematica, Python (&lt;a href=&#34;https://castel.dev/post/lecture-notes-1/#sympy-and-mathematica&#34;&gt;with Sympy&lt;/a&gt;) and Julia (with Latexify.jl), for example. &lt;a href=&#34;https://github.com/dandavison/xenops&#34;&gt;Xenops&lt;/a&gt; includes support for this.&lt;/p&gt;
&lt;h2 id=&#34;keeping-tabs-on-tab&#34;&gt;Keeping tabs on &lt;code&gt;TAB&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;You may have noticed the &lt;code&gt;TAB&lt;/code&gt;&amp;lsquo;ometer climbing as we progressively overload the key with more context-sensitive functions. The simple approach is to assign different keys to &lt;code&gt;outline-cycle&lt;/code&gt;, &lt;code&gt;cdlatex-tab&lt;/code&gt;, &lt;code&gt;yas-expand&lt;/code&gt; etc, but I don&amp;rsquo;t want to stop to think what key to press next when typing LaTeX. So I configure the &lt;code&gt;TAB&lt;/code&gt; key to do everything, in this order:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;At an outline heading, like a section? Cycle the outline like in Org.&lt;/li&gt;
&lt;li&gt;Looking at text that CDLaTeX can expand? Expand it.&lt;/li&gt;
&lt;li&gt;At the end of a Yasnippet field? Jump to the next field.&lt;/li&gt;
&lt;li&gt;In a Yasnippet field? Try a CDLaTeX &lt;code&gt;TAB&lt;/code&gt; jump. If that takes us out of the field, go to the end of the field instead.&lt;/li&gt;
&lt;li&gt;At the end of text in an org-table cell? Jump to the next cell like in a regular table.&lt;/li&gt;
&lt;li&gt;In a table cell? Try a CDLaTeX &lt;code&gt;TAB&lt;/code&gt; jump. If that takes us out of the cell, go to the end of the cell instead.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This reads like a blueprint for a Rube Goldberg machine, but in practice it does exactly what you expect at any location. The code for this is included &lt;a href=&#34;https://gist.github.com/karthink/7d89df35ee9b7ac0c93d0177b862dadb&#34;&gt;in the gist&lt;/a&gt;, but there may be still be edge cases that need filing before it works in every context.&lt;/p&gt;
&lt;h2 id=&#34;some-concluding-thoughts&#34;&gt;Some concluding thoughts&lt;/h2&gt;
&lt;p&gt;This collection of tips is just what I&amp;rsquo;ve scrabbled together over the years, not an authoritative or exhaustive exploration of this area. I think of it as a 90% solution: the remaining 10% is jank that someone needs to jump into and scrub out of the system. This rabbit hole goes very deep if you dive in headfirst, so I&amp;rsquo;m quite content to hang out here for now.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve been asked what the point is of speeding up LaTeX input - after all, the bottleneck with writing is usually your speed of thought, not typing. Leaving aside the issue of transcribing handwritten notes to the screen, I&amp;rsquo;ve found that this bottleneck theory isn&amp;rsquo;t true. Instead, normally there&amp;rsquo;s a thinking phase followed by a busywork phase where you translate your thought into LaTeX. When you can type math fast enough that this busywork phase disappears (or as fast as someone can teach with a blackboard), new possibilities open up. Recording self-taught lessons in technical subjects into your hyperlinked, indexed and/or searchable digital archive becomes automatic, as you don&amp;rsquo;t have to set aside time to do it. Written communication becomes easier, as dashing off a fully formatted, easy to parse technical email or message is no extra effort. The write → review → rewrite cycle when publishing material is much faster, and you can go through more iterations and feedback. It&amp;rsquo;s one of those situations where quantity has an emergent quality.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Henceforth just LaTeX, because sheesh.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;Not included in the chart: literate programs in or as the document. This is covered essentially by PythonTeX in LaTeX files and by &lt;code&gt;org-babel&lt;/code&gt; in org-mode.&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;If you&amp;rsquo;re on Emacs 27.2 or lower there are the &lt;a href=&#34;https://github.com/alphapapa/outshine&#34;&gt;Outshine&lt;/a&gt; and &lt;a href=&#34;https://github.com/tarsius/bicycle&#34;&gt;Bicycle&lt;/a&gt; packages for one-key Org-style cycling.&amp;#160;&lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34;&gt;
&lt;p&gt;Of course, this presumes that the user is comfortable with Emacs. And the alternatives are well ahead of AucTeX in other aspects, like collaboration.&amp;#160;&lt;a href=&#34;#fnref:4&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:5&#34;&gt;
&lt;p&gt;You could also go the other way, eschew cdlatex and auto-expand all your snippets with YaS. But snippet packages have a fundamental problem, see &lt;a href=&#34;#snippets-snap-easy&#34;&gt;Snippets snap easy&lt;/a&gt;.&amp;#160;&lt;a href=&#34;#fnref:5&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>ELMO - Embark Live Mode for Emacs</title>
      <link>https://karthinks.com/software/elmo-embark-live-mode-for-emacs/</link>
      <pubDate>Wed, 27 Oct 2021 22:32:00 +0530</pubDate>
      
      <guid>https://karthinks.com/software/elmo-embark-live-mode-for-emacs/</guid>
      <description>&lt;p&gt;Do not use Elmo.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/elmo.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Just making a note here. Following the release of &lt;a href=&#34;https://protesilaos.com/emacs/mct&#34;&gt;mct.el&lt;/a&gt;, I &lt;a href=&#34;https://github.com/karthink/elmo&#34;&gt;packaged&lt;/a&gt; some similar code I had lying around to use &lt;a href=&#34;https://github.com/oantolin/embark#working-with-sets-of-possible-targets&#34;&gt;Embark live collect buffers&lt;/a&gt; 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.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/elmo-grid-list-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://karthinks.com/img/elmo-grid-list-demo.mp4&#34;&gt;[VIDEO]&lt;/a&gt;&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;&lt;strong&gt;Elmo is idiosyncratic.&lt;/strong&gt; It does not show completions until you type some characters. It debounces completion candidate updates. It shows certain categories of completions in a grid. &lt;code&gt;RET&lt;/code&gt; behaves like in Ido: it selects the top candidate or &amp;ldquo;enters&amp;rdquo; directories. On the flip side, the candidate buffer is a regular read-only buffer so you can use all your navigation commands. Regions, rectangles, registers, the whole lot. It&amp;rsquo;s also (slightly) better integrated into Embark on the whole than the others, because it &lt;em&gt;is&lt;/em&gt; some glue applied to Embark.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Elmo is slow.&lt;/strong&gt; Use Selectrum, or Vertico, or Ivy, or Icomplete instead.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; My primary reason for turning it into a minor-mode from a gaggle of hooks is that I can now turn it off.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Do not use Elmo.&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Or Helm, but that&amp;rsquo;s more of a lifestyle than a completion system.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>An Elisp Editing Tip</title>
      <link>https://karthinks.com/software/an-elisp-editing-tip/</link>
      <pubDate>Sun, 24 Oct 2021 14:00:00 +0530</pubDate>
      
      <guid>https://karthinks.com/software/an-elisp-editing-tip/</guid>
      <description>&lt;p&gt;One of the first things new Emacs users learn is the &lt;code&gt;eval-last-sexp&lt;/code&gt; (&lt;code&gt;C-x C-e&lt;/code&gt;) command and that Emacs can interpret elisp &lt;em&gt;anywhere&lt;/em&gt; it appears. Here&amp;rsquo;s a quick tip about using this command when writing elisp that you may not have discovered.&lt;/p&gt;
&lt;p&gt;If you call it with a prefix (&lt;code&gt;C-u&lt;/code&gt;) argument, it prints (or attempts to print) the result in place in the buffer. Better yet, call it with an argument of &lt;code&gt;0&lt;/code&gt; (&lt;code&gt;C-0 C-x C-e&lt;/code&gt;) to avoid truncating longer results.&lt;/p&gt;
&lt;p&gt;Variables evaluate to their values, so here it prints the current values of these variables:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/eval-last-sexp-demo-3.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://karthinks.com/img/eval-last-sexp-demo-3.mp4&#34;&gt;[VIDEO]&lt;/a&gt;&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;This is handy when writing elisp, for example if you want to tweak the current value of a variable:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/eval-last-sexp-demo-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://karthinks.com/img/eval-last-sexp-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;I replace &lt;code&gt;eval-last-sexp&lt;/code&gt; everywhere with &lt;code&gt;pp-eval-last-sexp&lt;/code&gt;, which produces a cleaner result:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;global-set-key&lt;/span&gt; [&lt;span style=&#34;color:#963&#34;&gt;remap&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;eval-last-sexp&lt;/span&gt;] &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;pp-eval-last-sexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/eval-last-sexp-demo-2.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;p&gt;&lt;a href=&#34;https://karthinks.com/img/eval-last-sexp-demo-2.mp4&#34;&gt;[VIDEO]&lt;/a&gt;&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;That is all.&lt;/p&gt;
</description>
    </item><item>
      <title>Avy can do anything</title>
      <link>https://karthinks.com/software/avy-can-do-anything/</link>
      <pubDate>Thu, 21 Oct 2021 02:32:00 -0700</pubDate>
      
      <guid>https://karthinks.com/software/avy-can-do-anything/</guid>
      <description>&lt;p&gt;&lt;em&gt;Update (2024-09-08): Read this article in Japanese at &lt;a href=&#34;https://qiita.com/ayatakesi/items/8379ec7322051bb40d67&#34;&gt;Qiita&lt;/a&gt; or at &lt;a href=&#34;https://emacs-jp.github.io/tips/avy-can-do-anything&#34;&gt;Emacs-JP&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;You&amp;rsquo;re using Avy wrong.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Too harsh? Let me rephrase: you&amp;rsquo;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&amp;rsquo;s obscured by default.&lt;/p&gt;
&lt;p&gt;Without burying the lede any further, here&amp;rsquo;s a demo that uses a single Avy command (&lt;code&gt;avy-goto-char-timer&lt;/code&gt;) to do various things in multiple buffers and windows, all without manually moving the cursor:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-all-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-all-demo.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;p&gt;Copy text, kill lines or regions, move text around, mark text, bring up help buffers, look up definitions, search google, check my spelling, the list goes on. I emphasize this again: &lt;em&gt;Avy defines dozens of jump commands, but I&amp;rsquo;m only using one.&lt;/em&gt; This post breaks this down in detail so you can create your own version of this, but more importantly tries to explain why this is a neat idea.&lt;/p&gt;
&lt;p&gt;This is the first of two parts in a series on Avy, an Emacs package for jumping around efficiently with the keyboard. Part 1 is about about supercharging built-in customization to &lt;strong&gt;do anything with Avy&lt;/strong&gt;, or some approximation thereof. Part 2 will be a more technical (elisp-y) dive into writing more complex features for your individual needs. If you are interested in the short elisp snippets in this document, they are collated into a single file &lt;a href=&#34;https://gist.github.com/karthink/af013ffd77fe09e67360f040b57b4c7b&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;style&gt;
.Filter {
text-align: center;
background: #bb90b7;
padding-left: 2px;
padding-right: 3px;
border-radius: 4px;
color: black;
}
.Select {
text-align: center;
background: #f0ad95;
padding-left: 2px;
padding-right: 3px;
border-radius: 4px;
color: black;
}
.Act {
text-align: center;
background: #a3b09a;
padding-left: 2px;
padding-right: 3px;
border-radius: 4px;
color: black;
}
&lt;/style&gt;
&lt;h2 id=&#34;adc2ee&#34;&gt;&lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt; → &lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; → &lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;We see the same pattern repeated in most interactions with Emacs whose primary purpose isn&amp;rsquo;t typing text. To perform a task, we &lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt;, &lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; and &lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt; in sequence:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt;&lt;/strong&gt;: Winnow a large pile of candidates to a smaller number, usually by typing in some text. These candidates can be anything, see below for examples.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt;&lt;/strong&gt;: Specify a candidate as the one you need, usually with visual confirmation. If you filter a list down to one candidate, it&amp;rsquo;s automatically selected.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt;&lt;/strong&gt;: Run the task with this candidate as an argument.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Want to open a file? Invoke a command, then type in text to &lt;span class=&#34;Filter&#34;&gt;filter&lt;/span&gt; a list of completions, &lt;span class=&#34;Select&#34;&gt;select&lt;/span&gt; a completion, &lt;span class=&#34;Act&#34;&gt;find-file&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;Switch buffers? Type to &lt;span class=&#34;Filter&#34;&gt;filter&lt;/span&gt;, &lt;span class=&#34;Select&#34;&gt;select&lt;/span&gt; a buffer, &lt;span class=&#34;Act&#34;&gt;switch&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Act&#34;&gt;Autocomplete&lt;/span&gt; a symbol in code? Type a few characters to &lt;span class=&#34;Filter&#34;&gt;narrow&lt;/span&gt; a pop-up list, &lt;span class=&#34;Select&#34;&gt;choose&lt;/span&gt; a candidate, confirm.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As ever, this model is a simplification. Helm, Ivy, Dired &amp;amp; co let you &lt;span class=&#34;Select&#34;&gt;select&lt;/span&gt; multiple candidates to &lt;span class=&#34;Act&#34;&gt;act&lt;/span&gt; on, for instance. We will put this qualification aside while we explore this idea.&lt;/p&gt;
&lt;p&gt;This observation leads to several interesting ideas. For one, the &lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt; → &lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; → &lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt; process is often thought of as a single operation. Decoupling the filtering, selection and action phases (in code and in our heads) frees us to consider a flock of possibilities. Here&amp;rsquo;s minibuffer interaction:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/minibuffer-interaction-paradigm.png&#34; width=&#34;800px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;The possibilities are, respectively: different completion styles (matching by regexps, flex, orderless), different selection interfaces (Icomplete, Ivy, Helm, Vertico, Selectrum and more by the day) and different action dispatchers (Embark, Helm/Ivy actions)&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;. A similar mini-Cambrian explosion has happened in the &lt;a href=&#34;https://github.com/junegunn/fzf/wiki/&#34;&gt;space of shell utilities&lt;/a&gt; since &lt;a href=&#34;https://github.com/junegunn/fzf&#34;&gt;fzf&lt;/a&gt; arrived on the scene. In Emacs the minibuffer is where we&amp;rsquo;re used to selecting things, so it&amp;rsquo;s natural to think of these examples.&lt;/p&gt;
&lt;p&gt;But this usage pattern extends to more than just minibuffer interaction. We often do things in regular buffers that involve the &lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt; → &lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; → &lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt; pattern. In fact, you can look at most interactions with Emacs (whose focus isn&amp;rsquo;t typing text) this way: when you call a goto-definition command with point&amp;ndash;the text cursor&amp;ndash;in some text, the &lt;span class=&#34;Filter&#34;&gt;filtering&lt;/span&gt; stage is skipped, the &lt;span class=&#34;Select&#34;&gt;selection&lt;/span&gt; is made for you by a function from the &lt;code&gt;thing-at-pt&lt;/code&gt; library, and a preset &lt;span class=&#34;Act&#34;&gt;action&lt;/span&gt; is called. How about a mouse interaction? &lt;span class=&#34;Filter&#34;&gt;scroll&lt;/span&gt; through a window full of icons, &lt;span class=&#34;Select&#34;&gt;move&lt;/span&gt; the mouse cursor to an icon and &lt;span class=&#34;Act&#34;&gt;click&lt;/span&gt; on it. These completely redundant examples prime us for the more interesting cases. Consider Isearch:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/isearch-interaction-paradigm.png&#34; width=&#34;800px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;When you type (after &lt;code&gt;C-s&lt;/code&gt;), you automatically &lt;span class=&#34;Filter&#34;&gt;filter&lt;/span&gt; buffer text and &lt;span class=&#34;Select&#34;&gt;select&lt;/span&gt; the nearest match. You can select each subsequent match in turn, or &lt;span class=&#34;Act&#34;&gt;jump&lt;/span&gt; to the first or last match. The &lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt; here is the process of moving the cursor to the match location, but it can be one of a few things, like running &lt;code&gt;occur&lt;/code&gt; or &lt;code&gt;query-replace&lt;/code&gt; on the search string. Many Isearch commands simultaneously filter, select and act, so we&amp;rsquo;re fitting a square peg in a round hole here&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;ve spent any time using Isearch, you can appreciate the tradeoff involved in dividing a task into these three independently configurable phases. Lumping two or all three into a single operation makes Isearch a &lt;em&gt;wicked fast&lt;/em&gt; keyboard interaction. When I use Isearch my brain is usually trying to catch up to my fingers. On the other hand, the advantage of modularity is expressive power. The three phase process is slower on the whole, but we can do a whole lot more by plugging in different pieces into each of the &lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt; , &lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; and &lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt; slots. To see this, you have only to consider how many disparate tasks the minibuffer handles, and in how many different ways!&lt;/p&gt;
&lt;p&gt;But back to Isearch: what can we do to decouple the three stages here? Not much without modifying its guts. It&amp;rsquo;s all elisp, so that&amp;rsquo;s not a tall order. For example, Protesilaos Stavrou adds many intuitive actions (such as marking candidates) to Isearch in &lt;a href=&#34;https://www.youtube.com/watch?v=y6_bmcd3nis&#34;&gt;this video&lt;/a&gt;. But it turns out we don&amp;rsquo;t need to modify Isearch, because &lt;strong&gt;Avy&lt;/strong&gt; exists, has a killer &lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt; feature, and it separates the three stages like a champ. This makes for some very intriguing possibilities.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/avy-interaction-paradigm.png&#34; width=&#34;800px&#34;/&gt;
&lt;/figure&gt;

&lt;h2 id=&#34;wait-what-s-avy&#34;&gt;Wait, what&amp;rsquo;s Avy?&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/abo-abo/avy&#34;&gt;Avy&lt;/a&gt; is authored by the prolific &lt;a href=&#34;https://oremacs.com/&#34;&gt;abo-abo&lt;/a&gt; (Oleh Krehel), who also wrote Ivy, Counsel, Ace-Window, Hydra, Swiper and many other mainstays of the Emacs package ecosystem that you&amp;rsquo;ve probably used. If you&amp;rsquo;re reading this, chances are you already know (and probably use) Avy. So here&amp;rsquo;s a very short version from the documentation:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;avy is a GNU Emacs package for jumping to visible text using a char-based decision tree.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;You can call an Avy command and type in some text. Any match for this text on the frame (or all Emacs frames if desired) becomes a selection candidate, with some hint characters overlaid on top. Here I type in &amp;ldquo;an&amp;rdquo; and all strings in the frame that match it are highlighted:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/avy-basic-demo.png&#34; width=&#34;800px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Typing in one of the hints then jumps the cursor to that location. Here I jump to this sentence from another window:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-basic-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-basic-demo.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;se&amp;rdquo;. This shows hints for all matches with &amp;ldquo;se&amp;rdquo;, including &amp;ldquo;sentence&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Type in the hint char corresponding to &amp;ldquo;sentence&amp;rdquo;, which is &lt;code&gt;g&lt;/code&gt; here.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Typical Avy usage looks something like this: Jump to a location that matches your text (across all windows), then jump back with &lt;code&gt;pop-global-mark&lt;/code&gt; (&lt;code&gt;C-x C-SPC&lt;/code&gt;). In a later section &lt;a href=&#34;#when-avy-is-too-clever&#34;&gt;I go into more detail on jumping back and forth&lt;/a&gt; with Avy. Here is a demo of this process where I jump twice with Avy and then jump back in sequence:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-jump-back-demo-2.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-jump-back-demo-2.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;demo&amp;rdquo;. There is only one candidate for this string, so Avy jumps to the other window.&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;jump&amp;rdquo;. This shows hints for all matches with &amp;ldquo;jump&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Pick one of the matches. Avy jumps again, this time to the third window.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;pop-global-mark&lt;/code&gt; (&lt;code&gt;C-x C-SPC&lt;/code&gt;) to jump back to the previous location.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;pop-global-mark&lt;/code&gt; (&lt;code&gt;C-x C-SPC&lt;/code&gt;) again to jump back to the previous location.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;At least that&amp;rsquo;s the official description. You can peruse the &lt;a href=&#34;https://github.com/abo-abo/avy/blob/master/README.md&#34;&gt;README&lt;/a&gt; for more information, but what I find mystifying is that&amp;hellip;&lt;/p&gt;
&lt;h2 id=&#34;dot-dot-dot-avy-s-documentation-leaves-out-the-best-part&#34;&gt;&amp;hellip;Avy&amp;rsquo;s documentation leaves out the best part&lt;/h2&gt;
&lt;p&gt;Avy handles filtering automatically and the selection is made through a char-based decision tree. Here&amp;rsquo;s how it fits into our three part interaction model.&lt;/p&gt;
&lt;h3 id=&#34;f868f3&#34;&gt;&lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt;,&lt;/h3&gt;
&lt;p&gt;Before you call Avy &lt;em&gt;every text character on your screen&lt;/em&gt; is a potential candidate for selection. The possibilites are all laid out for you, and there are too many of them!&lt;/p&gt;
&lt;p&gt;You filter the candidate pool with Avy similar to how you would in the minibuffer, by typing text. This reduces the size of the pool to those that match your input. Avy provides dozens of filtering styles. It can: only consider candidates above/below point, only beginnings of words, only the current window (or frame), only whitespace, only beginnings of lines, only headings in Org files, the list goes on.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Filtering commands in Avy&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;&lt;a id=&#34;table--Jump commands in Avy&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Unit: Char&lt;/th&gt;
&lt;th&gt;Unit: Word or Symbol&lt;/th&gt;
&lt;th&gt;Unit: Line or other&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;avy-goto-char-timer&lt;/td&gt;
&lt;td&gt;avy-goto-word-0&lt;/td&gt;
&lt;td&gt;avy-goto-line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;avy-goto-char&lt;/td&gt;
&lt;td&gt;avy-goto-subword-0&lt;/td&gt;
&lt;td&gt;avy-goto-end-of-line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;avy-goto-char-2&lt;/td&gt;
&lt;td&gt;avy-goto-symbol-1-above&lt;/td&gt;
&lt;td&gt;avy-goto-whitespace-end&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;avy-goto-char-in-line&lt;/td&gt;
&lt;td&gt;avy-goto-word-0-below&lt;/td&gt;
&lt;td&gt;avy-org-goto-heading-timer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;avy-goto-char-2-below&lt;/td&gt;
&lt;td&gt;avy-goto-word-1-below&lt;/td&gt;
&lt;td&gt;avy-goto-whitespace-end-above&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;avy-goto-char-2-above&lt;/td&gt;
&lt;td&gt;avy-goto-symbol-1-below&lt;/td&gt;
&lt;td&gt;avy-goto-line-above&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;avy-goto-word-1-above&lt;/td&gt;
&lt;td&gt;avy-goto-whitespace-end-below&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;avy-goto-symbol-1&lt;/td&gt;
&lt;td&gt;avy-goto-line-below&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;avy-goto-word-or-subword-1&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;avy-goto-subword-1&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;avy-goto-word-1&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;avy-goto-word-0-above&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;This is a &lt;em&gt;crazy&lt;/em&gt; list to keep track of.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Filtering in Avy is independent of the selection method (as it should be), but there is a dizzying collection of filtering methods. I assume the idea is that the user will pick a couple of commands that they need most often and commit only those to memory.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s the problem: &lt;strong&gt;We want to use our mental bandwidth for the problem we&amp;rsquo;re trying to solve with the text editor, not the editor itself&lt;/strong&gt;. Conscious decision-making is expensive and distracting. As of now we need to decide on the fly between Isearch and Avy to find and act on things. If you use a fancy search tool like Swiper, Helm-swoop or Consult-line, you now have three options. Having a bunch of Avy commands on top is a recipe for mental gridlock. To that end, we just pick the most adaptable, flexible and general-purpose Avy command (&lt;code&gt;avy-goto-char-timer&lt;/code&gt;) for everything.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;global-set-key&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-j&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-goto-char-timer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Further below &lt;a href=&#34;./#avy-plus-isearch-seek-then-jump&#34;&gt;I make the case&lt;/a&gt; that you don&amp;rsquo;t need to make even this decision, you can always use Isearch and switch to Avy as needed.&lt;/p&gt;
&lt;p&gt;To be clear, this decision cost has to be balanced against the cost of frequent busywork and chronic context switching that Avy helps avoid. There is a case to be made for adapting Avy&amp;rsquo;s flexible filtering options to our needs, and the &lt;a href=&#34;https://melpa.org/#/?q=avy&#34;&gt;number of packages&lt;/a&gt; that offer Avy-based candidate filtering (for everything from linting errors to buffer selection) attests to this. We will examine this in depth in Part II.&lt;/p&gt;
&lt;p&gt;But in this piece we are interested in a different, much less explored aspect of Avy.&lt;/p&gt;
&lt;h3 id=&#34;3008c7&#34;&gt;&lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt;,&lt;/h3&gt;
&lt;p&gt;Every selection method that Avy offers involves typing characters that map to screen locations. This is quite different from Isearch, where you call &lt;code&gt;isearch-repeat-forward&lt;/code&gt; (&lt;code&gt;C-s&lt;/code&gt;, possibly with a numerical prefix argument) or the minibuffer, where you navigate a completions buffer or list with &lt;code&gt;C-n&lt;/code&gt; and &lt;code&gt;C-p&lt;/code&gt;. Avy&amp;rsquo;s selection method is generally faster because it minimizes, by design, the length of the character sequences it uses, and we have ten fingers that can access ∼40 keys in O(1) time. The fact that we&amp;rsquo;re often looking directly where we mean to jump means we don&amp;rsquo;t need to parse an entire screen of gibberish. Unfortunately for this article, this means using Avy is much more intuitive than looking at screenshots or watching demos.&lt;/p&gt;
&lt;p&gt;This excellent design leaves us with little reason to tinker with the selection phase: it&amp;rsquo;s sufficiently modular and accommodating of different filter and act stages. You can customize &lt;code&gt;avy-style&lt;/code&gt; if you want to change the set or positions of characters used for selection. Here is an example of using simple words to select candidates:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/avy-words-style-demo.png&#34; width=&#34;800px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;We will pay more attention to the selection operation in part II as well.&lt;/p&gt;
&lt;h3 id=&#34;fc6ea2&#34;&gt;&lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt;!&lt;/h3&gt;
&lt;p&gt;This brings us to the focus of this article. The stated purpose of Avy, jumping to things, makes it sound like a (contextually) faster Isearch. But jumping is only one of many possibilities. Avy provides a &amp;ldquo;dispatch list&amp;rdquo;, a collection of actions you can perform on a candidate, and they are all treated on equal footing with the jump action. You can show these commands any time you use Avy with &lt;code&gt;?&lt;/code&gt;:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/avy-dispatch-demo.png&#34; width=&#34;800px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;This means we are free to leverage Avy&amp;rsquo;s unique filtering and selection method to &lt;em&gt;whatever action we want to carry out&lt;/em&gt; at any location on the screen. Our interaction model now ends in a block that looks something like this:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/avy-interaction-paradigm-detailed.png&#34; width=&#34;500px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Additionally, Avy also defines a few commands that run different actions, like copying text from anywhere on screen:&lt;/p&gt;
&lt;p&gt;&lt;a id=&#34;table--Action commands in Avy&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Kill&lt;/th&gt;
&lt;th&gt;Copy&lt;/th&gt;
&lt;th&gt;Move&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;avy-kill-ring-save-whole-line&lt;/td&gt;
&lt;td&gt;avy-copy-line&lt;/td&gt;
&lt;td&gt;avy-move-line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;avy-kill-ring-save-region&lt;/td&gt;
&lt;td&gt;avy-copy-region&lt;/td&gt;
&lt;td&gt;avy-move-region&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;avy-kill-region&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;avy-transpose-lines-in-region&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;avy-kill-whole-line&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;avy-org-refile-as-child&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The problem with this approach is that it doesn&amp;rsquo;t scale. Each of these commands defines a full &lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt; → &lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; → &lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt; process, and we quickly run out of headspace and keyboard room if we want any kind of versatility or coverage. They&amp;rsquo;re also not dynamic enough: you&amp;rsquo;re locked into the pipeline and cannot change your mind once you start the command.&lt;/p&gt;
&lt;p&gt;Folks love Vim&amp;rsquo;s editing model for a reason: it&amp;rsquo;s a mini-language where knowing M actions (verbs) and N cursor motions gives you M × N composite operations. This (M + N) → (M × N) ratio pays off quadratically with the effort you put into learning verbs and motions in Vim. Easymotion, which is Vim&amp;rsquo;s version of Avy&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;, has part of this composability built-in as a result. We seek to bring some of this to Avy, and (because this is Emacs) do a lot more than combining motions with verbs. We won&amp;rsquo;t need to step into Avy&amp;rsquo;s source code for this, it has all the hooks we need already.&lt;/p&gt;
&lt;h2 id=&#34;avy-actions&#34;&gt;Avy actions&lt;/h2&gt;
&lt;p&gt;The basic usage for running an arbitrary action with Avy is as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Call an Avy command. Any command will do, I stick to &lt;code&gt;avy-goto-char-timer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt;: Type in some text to shrink the candidate pool from the entire screen to a few locations.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt;: Specify the action you want to run. You can pull up the dispatch help with &lt;code&gt;?&lt;/code&gt;, although you won&amp;rsquo;t have to if you set it up right, see &lt;a href=&#34;#remembering-to-avy&#34;&gt;Remembering to Avy&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt;: Pick one of the candidates to run the action on.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here are some things I frequently do with Avy. Note that you can do this on any text in your frame, not just the active window!&lt;/p&gt;
&lt;p&gt;First, taking the annoyance out of some common editing actions with Avy. If you use Vim and Easymotion, you get the first few actions below for free:&lt;/p&gt;
&lt;details open&gt;
&lt;summary&gt;A note about these demos&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For clarity, I set Avy to desaturate the screen and to &amp;ldquo;pulse&amp;rdquo; the line during a few of these actions. These are not enabled by default. I also slowed down the operations by adding a delay to make them easier to follow. In actual usage these are instantaneous.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The keys Avy uses to dispatch actions on candidates are specified in &lt;code&gt;avy-dispatch-alist&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We will also need to ensure that these keys don&amp;rsquo;t coincide with the ones Avy uses as selection hints on screen. Consider customizing &lt;code&gt;avy-keys&lt;/code&gt; for this.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;kill-a-candidate-word-sexp-or-line&#34;&gt;Kill a candidate word, sexp or line&lt;/h3&gt;
&lt;p&gt;Killing words or s-expressions is built-in. I added an action to kill a line. In this demo I quickly squash some typos and delete a comment, then remove some code in a different window:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-kill-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-kill-demo.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;is&amp;rdquo;. This shows hints for all matches for &amp;ldquo;is&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-action-kill&lt;/code&gt; with &lt;code&gt;k&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Select one of the duplicate &amp;ldquo;is&amp;rdquo; occurrence. This deletes it.&lt;/li&gt;
&lt;li&gt;Repeat steps 1-4 to delete a redundant &amp;ldquo;and&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-Goto-Char-Timer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;key&amp;rdquo; to filter matches for &amp;ldquo;key&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-action-kill-whole-line&lt;/code&gt; with &lt;code&gt;K&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select the commented line, this removes the line.&lt;/li&gt;
&lt;li&gt;Repeat steps 1-4, this time selecting &amp;ldquo;(&amp;rdquo; in the other window and killing the function definition.&lt;/li&gt;
&lt;li&gt;Repeat steps 7-9, this time selecting &amp;ldquo;ad&amp;rdquo; in the other window and killing the &amp;ldquo;(advice-add &amp;hellip;)&amp;rdquo; line.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-action-kill-whole-line&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;kill-whole-line&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;select-window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cdr&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;ring-ref&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-ring&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setf&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?k&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-action-kill-stay&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?K&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-action-kill-whole-line&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;yank-a-candidate-word-sexp-or-line&#34;&gt;Yank a candidate word, sexp or line&lt;/h3&gt;
&lt;p&gt;Copy to the kill-ring or copy to point in your buffer. In this demo I copy some text from a man page into my file:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-copy-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-copy-demo.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;[&amp;rdquo;. This filters to all matches for &amp;ldquo;[&amp;rdquo; in the frame.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-action-yank&lt;/code&gt;, bound to &lt;code&gt;y&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select the match corresponding to &amp;ldquo;[big-cache]&amp;rdquo;. This text is copied to the buffer from the other window.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;de&amp;rdquo;. This filters to matches that include &amp;ldquo;demuxer&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-action-yank-whole-line&lt;/code&gt;, bound to &lt;code&gt;Y&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select one of the matches. The line is copied to the buffer.&lt;/li&gt;
&lt;li&gt;Fix indentation with &lt;code&gt;just-one-space&lt;/code&gt;, bound to &lt;code&gt;M-SPC&lt;/code&gt; by default.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-action-copy-whole-line&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;cl-destructuring-bind&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;start&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;end&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;bounds-of-thing-at-point&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;line&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;copy-region-as-kill&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;start&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;end&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;select-window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cdr&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;ring-ref&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-ring&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-action-yank-whole-line&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;avy-action-copy-whole-line&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;yank&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setf&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?y&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-action-yank&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?w&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-action-copy&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?W&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-action-copy-whole-line&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?Y&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-action-yank-whole-line&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note that Avy actually defines separate commands for this: &lt;code&gt;avy-copy-line&lt;/code&gt; and &lt;code&gt;avy-copy-region&lt;/code&gt; to copy lines and regions from anywhere in the frame. These are a little faster since they have the &lt;span class=&#34;Act&#34;&gt;action&lt;/span&gt; stage baked into the function call. You might be better served by these. But we want to avoid the mental burden of remembering too many top level commands, so we work in two simpler stages: call &lt;code&gt;avy-goto-char-timer&lt;/code&gt; (to &lt;span class=&#34;Filter&#34;&gt;filter&lt;/span&gt; and &lt;span class=&#34;Select&#34;&gt;select&lt;/span&gt;) and then dispatch on our selected candidate as we see fit.&lt;/p&gt;
&lt;h3 id=&#34;move-a-candidate-word-sexp-or-line&#34;&gt;Move a candidate word, sexp or line&lt;/h3&gt;
&lt;p&gt;Avy calls this &amp;ldquo;teleport&amp;rdquo;, I call it &amp;ldquo;transpose&amp;rdquo;, either way it&amp;rsquo;s bound to &lt;code&gt;t&lt;/code&gt;. In this demo I move text around the buffer&amp;hellip; without moving (much) around the buffer:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-transpose-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-transpose-demo.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Make some room, type in a space.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Filter to candidates that begin with &amp;ldquo;(&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;t&lt;/code&gt; to run &lt;code&gt;avy-action-teleport&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Select the candidate that says &amp;ldquo;(parametric forcing)&amp;rdquo;. It is moved over (transposed) to where the point is.&lt;/li&gt;
&lt;li&gt;Jump to where it says &amp;ldquo;DOWNLOADED&amp;rdquo; in the window with &lt;code&gt;avy-goto-char-timer&lt;/code&gt;. This is the only match for the input &amp;ldquo;down&amp;rdquo;, so Avy jumps there automatically. You could also just &lt;code&gt;isearch-backwards&lt;/code&gt; here.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Filter to candidates matching &amp;ldquo;the&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;T&lt;/code&gt; to run =avy-action-teleport-line~.&lt;/li&gt;
&lt;li&gt;Select a candidate line (the one just below the image). It is moved over (transposed) to where the point is.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-action-teleport-whole-line&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;avy-action-kill-whole-line&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;yank&lt;/span&gt;)) &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setf&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?t&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-action-teleport&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?T&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-action-teleport-whole-line&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;zap-to-a-candidate-position&#34;&gt;Zap to a candidate position&lt;/h3&gt;
&lt;p&gt;This is built-in and bound to &lt;code&gt;z&lt;/code&gt; by default:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-zap-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-zap-demo.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;in&amp;rdquo;. This shows hints for all matches with &amp;ldquo;in&amp;rdquo;, including &amp;ldquo;In Emacs&amp;hellip;&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;z&lt;/code&gt; to run &lt;code&gt;avy-action-zap&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select a candidate char, in this case &amp;ldquo;In Emacs&amp;hellip;&amp;rdquo;. The text between point and the candidate is killed.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;mark-a-candidate-word-or-sexp&#34;&gt;Mark a candidate word or sexp&lt;/h3&gt;
&lt;p&gt;Also built in, &lt;code&gt;m&lt;/code&gt; by default. This isn&amp;rsquo;t different from jumping to the candidate using Avy and calling &lt;code&gt;mark-sexp&lt;/code&gt;, but it &lt;em&gt;is&lt;/em&gt; more convenient:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-mark-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Type in text to filter with, in this case just &amp;ldquo;(&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;m&lt;/code&gt; to run &lt;code&gt;avy-action-mark&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select a candidate word or sexp, in this case &lt;code&gt;(&amp;quot;~/.local/share&amp;quot;)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Repeat steps 1 to 4 twice to mark other candidates: &lt;code&gt;(data_directory...&lt;/code&gt; and &lt;code&gt;RotatingFileHandler&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;mark-the-region-from-point-to-a-candidate&#34;&gt;Mark the region from point to a candidate&lt;/h3&gt;
&lt;p&gt;Avy sets the mark before it jumps, so you could use &lt;code&gt;C-x C-x&lt;/code&gt; to activate the region, but this saves you the trouble.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-mark-to-char-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Type in text to filter with, in this case &amp;ldquo;&amp;rsquo;)&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;SPC&lt;/code&gt; to run &lt;code&gt;avy-action-mark-to-char&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select a candidate char. This marks the region from point to the char and moves the point.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Type in text to filter with, in this case just a series of spaces.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;SPC&lt;/code&gt; to run &lt;code&gt;avy-action-mark-to-char&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Choose a candidate (series of spaces) that begins a line. This marks the region from point to the line.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-action-mark-to-char&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;activate-mark&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setf&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;? &lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-action-mark-to-char&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Next, some contextual actions automagicked by Avy:&lt;/p&gt;
&lt;h3 id=&#34;ispell-a-candidate-word&#34;&gt;ispell a candidate word&lt;/h3&gt;
&lt;p&gt;This is built-in, bound to &lt;code&gt;i&lt;/code&gt; by default.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-ispell.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-ispell.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt; (or any other Avy jump command)&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Filter&#34;&gt;Type in&lt;/span&gt; &amp;ldquo;can&amp;rdquo;, this highlights matches for &amp;ldquo;candidate&amp;rdquo; (and its misspellings)&lt;/li&gt;
&lt;li&gt;Press the &lt;span class=&#34;Act&#34;&gt;dispatch&lt;/span&gt; key for &lt;code&gt;avy-action-ispell&lt;/code&gt;, set to &lt;code&gt;i&lt;/code&gt; by default.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; one of the matches, in this case the misspelled &amp;ldquo;canddidate&amp;rdquo; match.&lt;/li&gt;
&lt;li&gt;This runs &lt;code&gt;ispell-word&lt;/code&gt; on the selection.&lt;/li&gt;
&lt;li&gt;Pick the correct spelling.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt; again.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Filter&#34;&gt;Type in&lt;/span&gt; &amp;ldquo;te&amp;rdquo;, this highlights the match for &amp;ldquo;teh&amp;rdquo; (among others).&lt;/li&gt;
&lt;li&gt;Press the &lt;span class=&#34;Act&#34;&gt;dispatch&lt;/span&gt; key for &lt;code&gt;avy-action-ispell&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; the candidate, in this case the &amp;ldquo;teh&amp;rdquo; match.&lt;/li&gt;
&lt;li&gt;This runs &lt;code&gt;ispell-word&lt;/code&gt; again, and &amp;ldquo;teh&amp;rdquo; can be corrected.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;You can replace &lt;code&gt;avy-action-ispell&lt;/code&gt; (built-in) with a version that automatically picks the top correction for a word, automating the process:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-action-flyspell&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;require&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;flyspell&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;flyspell-auto-correct-word&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;select-window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cdr&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;ring-ref&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-ring&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; Bind to semicolon (flyspell uses C-;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setf&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?\;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-action-flyspell&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;define-a-word&#34;&gt;Define a word&lt;/h3&gt;
&lt;p&gt;I use the dictionary package for Emacs, and I&amp;rsquo;m lazy about it:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-define.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt; (or any other Avy jump command)&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Filter&#34;&gt;Type in&lt;/span&gt; &amp;ldquo;non&amp;rdquo;, this highlights matches for &amp;ldquo;nonpareil&amp;rdquo; (among others)&lt;/li&gt;
&lt;li&gt;Press the &lt;span class=&#34;Act&#34;&gt;dispatch&lt;/span&gt; key for &lt;code&gt;avy-action-define&lt;/code&gt;, set to &lt;code&gt;=&lt;/code&gt; here&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; the candidate, in this case one of the &amp;ldquo;nonpareil&amp;rdquo; matches.&lt;/li&gt;
&lt;li&gt;This produces the buffer with the definition of &amp;ldquo;nonpareil&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;scroll-other-window&lt;/code&gt; (&lt;code&gt;C-M-v&lt;/code&gt;) to scroll the dictionary window.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt; again.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Filter&#34;&gt;Type in&lt;/span&gt; &amp;ldquo;fi&amp;rdquo;, this highlights the match for &amp;ldquo;finch&amp;rdquo; (among others). Note that this match is in another buffer, the one with the definition. We did not have to switch buffers.&lt;/li&gt;
&lt;li&gt;Press the &lt;span class=&#34;Act&#34;&gt;dispatch&lt;/span&gt; key for &lt;code&gt;avy-action-define&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; the candidate, in this case the &amp;ldquo;finch&amp;rdquo; match.&lt;/li&gt;
&lt;li&gt;This produces the buffer with the dictionary definition of &amp;ldquo;finch&amp;rdquo;.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;Replace your package manager or preferred dict package&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;package-install&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;dictionary&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;dictionary-search-dwim&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Search for definition of word at point. If region is active,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;  search for contents of region instead. If called with a prefix
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;  argument, query for word to search.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;dictionary-search&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;use-region-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;dictionary-search&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;buffer-substring-no-properties&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                              (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;region-beginning&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                              (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;region-end&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;thing-at-point&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;word&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#963&#34;&gt;dictionary-lookup-definition&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;dictionary-search-dwim&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;4&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-action-define&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;dictionary-search-dwim&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;select-window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cdr&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;ring-ref&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-ring&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setf&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?=&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;dictionary-search-dwim&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;look-up-the-documentation-for-a-symbol&#34;&gt;Look up the documentation for a symbol&lt;/h3&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-help-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Type in text to filter with, in this case &amp;ldquo;pc&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;H&lt;/code&gt; to run &lt;code&gt;avy-action-helpful&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select a candidate phrase, in this case &amp;ldquo;pcase-lambda&amp;rdquo;. This pulls up a documentation buffer for this symbol.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;scroll-other-window&lt;/code&gt; with &lt;code&gt;C-M-v&lt;/code&gt; to scroll the help buffer.&lt;/li&gt;
&lt;li&gt;call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Type in text to filter with, in this case &amp;ldquo;ma&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;H&lt;/code&gt; to run &lt;code&gt;avy-action-helpful&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select a candidate phrase, in this case &amp;ldquo;macroexp-parse-body&amp;rdquo;. Note that this is matched in the other (help) window. This pulls up the documentation for this symbol.&lt;/li&gt;
&lt;li&gt;Repeat steps 5-9 to find the documentation of another symbol, in this case &lt;code&gt;memq&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;Replace with your package manager or help library of choice&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;package-install&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;helpful&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-action-helpful&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;helpful-at-point&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;select-window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cdr&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;ring-ref&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-ring&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setf&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?H&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-action-helpful&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;google-search-for-a-word-or-sexp&#34;&gt;Google search for a word or sexp&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a href=&#34;#fn:4&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;&lt;/h3&gt;
&lt;p&gt;You&amp;rsquo;ll need an Emacs feature that can search Google for you. There &lt;a href=&#34;https://melpa.org/#/?q=web%20search&#34;&gt;are&lt;/a&gt; &lt;a href=&#34;https://melpa.org/#/?q=google%20search&#34;&gt;several&lt;/a&gt;. I use a CLI program named &lt;a href=&#34;https://github.com/Bugswriter/tuxi%20&#34;&gt;Tuxi&lt;/a&gt; for this, and it&amp;rsquo;s pretty handy:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-tuxi-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt; (or any other Avy jump command)&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Filter&#34;&gt;Type in&lt;/span&gt; &amp;ldquo;ema&amp;rdquo;, this highlights matches for &amp;ldquo;Emacs&amp;rdquo; (among others)&lt;/li&gt;
&lt;li&gt;Press the &lt;span class=&#34;Act&#34;&gt;dispatch&lt;/span&gt; key for &lt;code&gt;avy-action-tuxi&lt;/code&gt;, set to &lt;code&gt;C-=&lt;/code&gt; here&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; the candidate, in this case one of the &amp;ldquo;Emacs&amp;rdquo; matches.&lt;/li&gt;
&lt;li&gt;This produces the buffer with the Google&amp;rsquo;s description of Emacs.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt; again.&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Filter&#34;&gt;Type in&lt;/span&gt; &amp;ldquo;vi&amp;rdquo;, this highlights the match for &amp;ldquo;Vi&amp;rdquo; (among others). Note that this match is in another buffer, the one with the Google result. We did not have to switch buffers.&lt;/li&gt;
&lt;li&gt;Press the &lt;span class=&#34;Act&#34;&gt;dispatch&lt;/span&gt; key for &lt;code&gt;avy-action-tuxi&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; the candidate, in this case the &amp;ldquo;Vi&amp;rdquo; match.&lt;/li&gt;
&lt;li&gt;This produces the buffer with Google&amp;rsquo;s description of Vi.&lt;/li&gt;
&lt;li&gt;Repeat steps 6-10 but selecting the string &amp;ldquo;POSIX&amp;rdquo; instead.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Now: We could continue populating &lt;code&gt;avy-dispatch-alist&lt;/code&gt; with functions to do increasingly arcane contextual actions, but let&amp;rsquo;s take a step back. We want a list of easily callable actions on pieces of semantically classified buffer text&amp;hellip; now where have we seen &lt;a href=&#34;../fifteen-ways-to-use-embark&#34;&gt;something like this&lt;/a&gt; before?&lt;/p&gt;
&lt;h2 id=&#34;avy-plus-embark-any-action-anywhere&#34;&gt;Avy + Embark:  Any action, anywhere&lt;/h2&gt;
&lt;p&gt;Avy and Embark plug into each other like LEGO blocks. Here are a couple of examples:&lt;/p&gt;
&lt;h3 id=&#34;highlight-occurrences&#34;&gt;Highlight occurrences&lt;/h3&gt;
&lt;p&gt;In this demo I highlight some keywords in a busy LaTeX document, then visit the bibliography entry of a citation key with Avy and Embark, without ever manually moving the cursor:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-embark-demo-2.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-embark-demo-2.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt; (or any other Avy jump command)&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;flo&amp;rdquo; to filter matches that include &amp;ldquo;Floquet&amp;rdquo;&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;avy-action-embark&lt;/code&gt; with &lt;code&gt;o&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select one of the matches for &amp;ldquo;Floquet&amp;rdquo;. This runs Embark on the match.&lt;/li&gt;
&lt;li&gt;Select the &lt;code&gt;embark-toggle-highlight&lt;/code&gt; action with &lt;code&gt;H&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Repeat 1-5 to highlight &amp;ldquo;Parametric&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt; again.&lt;/li&gt;
&lt;li&gt;Type in &amp;ldquo;na&amp;rdquo; to match one of the citation keys (among others)&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;avy-action-embark&lt;/code&gt; with &lt;code&gt;o&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select the citation key match. This runs Embark on it.&lt;/li&gt;
&lt;li&gt;Choose the bibtex-action to visit the Bib file, bound to &lt;code&gt;e&lt;/code&gt; by the bibtex-actions package.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;run-a-skein-through-emacs-help-systems&#34;&gt;Run a skein through Emacs&amp;rsquo; help systems&lt;/h3&gt;
&lt;p&gt;In this demo I explore my way through a package with Avy and Embark, threading help, apropos and customization buffers, again without manually moving the cursor.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-embark-demo-1.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-embark-demo-1.mp4&#34;&gt;[VIDEO]&lt;/a&gt;.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Type in text to filter with, in this case &amp;ldquo;root&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;avy-action-embark&lt;/code&gt; with &lt;code&gt;o&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select &amp;ldquo;project-root&amp;rdquo;, one of the matches. This runs Embark on the match.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;h&lt;/code&gt;, which makes Embark run &lt;code&gt;describe-symbol&lt;/code&gt; on the match. This opens up a help buffer for the function. (Note: we bound a help command to Avy earlier, we could have used that.)&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;C-M-v&lt;/code&gt; (&lt;code&gt;scroll-other-window&lt;/code&gt;) to scroll the help buffer.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt; again.&lt;/li&gt;
&lt;li&gt;Type in text to filter with, in this case &amp;ldquo;proj&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;avy-action-embark&lt;/code&gt; with &lt;code&gt;o&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select &amp;ldquo;project-x&amp;rdquo;, which is one of the matches. This runs Embark on the match.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;embark-cycle&lt;/code&gt; to change the target from a file (named &amp;ldquo;project-x&amp;rdquo;) to a library (named &amp;ldquo;project-x&amp;rdquo;)&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;h&lt;/code&gt;, which makes Embark run &lt;code&gt;finder-commentary&lt;/code&gt; on the project-x library. This opens a buffer with some commentary.&lt;/li&gt;
&lt;li&gt;Repeat the previous steps to run Embark on &amp;ldquo;project-x&amp;rdquo; again. This time, run the &lt;code&gt;apropos-library&lt;/code&gt; action with &lt;code&gt;a&lt;/code&gt; in Embark. This opens an apropos buffer.&lt;/li&gt;
&lt;li&gt;Repeat the previous steps to run Embark again, this time on the symbol &amp;ldquo;project-x-local-identfier&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Choose the &lt;code&gt;customize-variable&lt;/code&gt; action with &lt;code&gt;u&lt;/code&gt; in Embark. This opens a customization buffer for the variable &lt;code&gt;project-x-local-identifier&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;a-division-of-responsibility&#34;&gt;A division of responsibility&lt;/h3&gt;
&lt;p&gt;We save ourselves a lot of redundancy and reuse muscle memory here. Avy provides its unique means of filtering and Embark does what it does best, run actions! The intermediate job of candidate selection is shared between Avy and Embark: Avy specifies the general location of the candidate, and Embark figures out the semantic unit at that position on which to act. The fact that the &lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt; → &lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; → &lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt; process is helpfully chunked this way by Avy makes the elisp required to integrate the two completely trivial&lt;sup id=&#34;fnref:5&#34;&gt;&lt;a href=&#34;#fn:5&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;5&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-action-embark&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;unwind-protect&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pt&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;embark-act&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;select-window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cdr&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;ring-ref&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-ring&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setf&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;avy-dispatch-alist&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-action-embark&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Note that if you don&amp;rsquo;t like the candidate that Embark picks as the unit to act on, you can call &lt;code&gt;embark-cycle&lt;/code&gt; to cycle through the other targets.&lt;/p&gt;
&lt;p&gt;All that, and we didn&amp;rsquo;t even move the point.&lt;sup id=&#34;fnref:6&#34;&gt;&lt;a href=&#34;#fn:6&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;6&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;h2 id=&#34;avy-plus-isearch-seek-then-jump&#34;&gt;Avy + Isearch: Seek, then jump&lt;/h2&gt;
&lt;p&gt;Isearch and Avy have different strengths: Avy jumps quickly to any &lt;em&gt;visible&lt;/em&gt; element in any window, Isearch to any matching candidate in this &lt;em&gt;buffer&lt;/em&gt;. Avy is faster when you want to cover some distance in a jump, Isearch when you&amp;rsquo;re moving a small distance or a very large one. Avy is useful when your eyes are already on a target, Isearch when you&amp;rsquo;re looking for one. But you don&amp;rsquo;t have you choose. You can handily combine the two by restricting Avy&amp;rsquo;s candidate pool to Isearch candidates: now you can start Isearch and finish with Avy:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;isearch-mode-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-j&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;avy-isearch&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Again, consciously deciding which of the two commands to call every time is a bad idea. It&amp;rsquo;s not a bad idea to always Isearch and switch to Avy when necessary:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-isearch-basic-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;a href=&#34;https://karthinks.com/img/avy-isearch-basic-demo.mp4&#34;&gt;[VIDEO]&lt;/a&gt;
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Start Isearch with &lt;code&gt;C-s&lt;/code&gt;. In the video I switched to &lt;code&gt;isearch-regexp&lt;/code&gt; with &lt;code&gt;M-r&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Type in a phrase to search for. In the video I typed in a regexp that ends in &amp;ldquo;-region&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Navigate Isearch matches with &lt;code&gt;C-s&lt;/code&gt;, recentering the screen with &lt;code&gt;C-l&lt;/code&gt; if necessary.&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt;. The candidate pool limits to the Isearch matches.&lt;/li&gt;
&lt;li&gt;Pick an Isearch match to jump to as before.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;At least, that&amp;rsquo;s the usual pitch.&lt;/p&gt;
&lt;p&gt;For us, however, &amp;ldquo;jump&amp;rdquo; in that description is replaced with &amp;ldquo;act&amp;rdquo;. We can &lt;em&gt;act&lt;/em&gt; on any visible Isearch candidate with one of the above actions. Kill text between two isearch matches? Copy the previous line that contains a word to the current location? Check. Essentially we &lt;span class=&#34;Filter&#34;&gt;filter&lt;/span&gt; with Isearch and &lt;span class=&#34;Select&#34;&gt;select&lt;/span&gt; and &lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt; with Avy, indirectly decoupling Filter from the other two actions in Isearch.&lt;/p&gt;
&lt;h2 id=&#34;when-avy-is-too-clever&#34;&gt;When Avy is too clever&lt;/h2&gt;
&lt;p&gt;This usage pattern has a failure mode. When there&amp;rsquo;s a single match, Avy jumps to the location and does not offer any actions. Oops.&lt;/p&gt;
&lt;p&gt;While it&amp;rsquo;s possible to force Avy to show a selection char/hint for a single match, the default DWIM behavior is usually desirable. There are two options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Filter candidates conservatively, for example by typing in a single character. Using &lt;code&gt;avy-goto-char&lt;/code&gt; or &lt;code&gt;avy-goto-char-2&lt;/code&gt; will almost always result in more than one match, preventing this problem. If you use one of the timer-based Avy commands, you can vary how much text to filter by on the fly.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Carry out the action the old-fashioned way after jumping, then jump back by popping the mark Avy sets. You can do this with the default &lt;code&gt;set-mark-command&lt;/code&gt; (&lt;code&gt;C-u C-SPC&lt;/code&gt;)&lt;sup id=&#34;fnref:7&#34;&gt;&lt;a href=&#34;#fn:7&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;7&lt;/a&gt;&lt;/sup&gt;. You can do this for most commands that cause the point to jump, including Isearch. Vim users have the jumplist, accessed with &lt;code&gt;C-o&lt;/code&gt;, and the changelist, accessed with &lt;code&gt;g;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In this demo I jump twice with Avy to edit text and then chain jump my way back to where I started:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls&gt;
&lt;source src=&#34;https://karthinks.com/img/avy-jump-back-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Call &lt;code&gt;avy-goto-char-timer&lt;/code&gt; and jump to a candidate (or end up there by accident)&lt;/li&gt;
&lt;li&gt;Make your edits (or not).&lt;/li&gt;
&lt;li&gt;Call &lt;code&gt;set-mark-command&lt;/code&gt; with a prefix arg (&lt;code&gt;C-u C-SPC&lt;/code&gt;) to jump back. You can chain these jumps.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;what-s-the-point-anyway&#34;&gt;What&amp;rsquo;s the Point, anyway&lt;/h2&gt;
&lt;p&gt;This section is for the pedants.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve been using &amp;ldquo;point&amp;rdquo; and &amp;ldquo;cursor&amp;rdquo; interchangeably in this article. Yes, I&amp;rsquo;m aware of the distinction.&lt;/p&gt;
&lt;p&gt;One of the illustrated advantages of using Avy to filter and select text to run actions on is that you can do it without moving the cursor. But as the above code snippets make clear with their &lt;code&gt;save-excursion&lt;/code&gt; blocks, we do move the point, mostly just invisibly. The point is where the &amp;ldquo;gap&amp;rdquo; in Emacs&amp;rsquo; gap-buffer data structure is located, so Emacs commands are all oriented around acting on the point, and usually more efficient when doing so.&lt;/p&gt;
&lt;p&gt;Yes: it&amp;rsquo;s much faster to run an Avy action on some text in a different window than it is to call &lt;code&gt;other-window&lt;/code&gt;, then Isearch to the text, run an action and switch back. But to me, the Point (har) is primarily a useful abstraction for writing elisp. The real advantage of Avy is in how it lets me think about the contents of the entire frame in the powerful &lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt; → &lt;span class=&#34;Select&#34;&gt;select&lt;/span&gt; → &lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt; paradigm. The fact that you can do this without the mental context switch involved in expressly navigating around the window or frame is a bonus.&lt;/p&gt;
&lt;h2 id=&#34;remembering-to-avy&#34;&gt;Remembering to Avy&lt;/h2&gt;
&lt;p&gt;In some ways, using Avy to jump around the screen is like using a mouse. You could make the case, quite successfully, that the mouse is faster here and thus preferable. This unfavorable comparison evaporates when you add your dispatch actions into the mix. Yanking a line from another window or running goto-definition on a symbol on the other edge of the screen is much faster with Avy than with the mouse selection/right-click business. And this is without taking into account the disruptive effect of frequent context switching, the reason to prefer all keyboard navigation (or all mouse, when possible) in the first place.&lt;/p&gt;
&lt;h3 id=&#34;the-smell-test&#34;&gt;The smell test&lt;/h3&gt;
&lt;p&gt;However, using Avy &lt;em&gt;actions&lt;/em&gt; is a new way of interacting with text on your screen even if you already use Avy to jump around. To remember to use Avy actions or find new ones, I look for &amp;ldquo;smells&amp;rdquo; in my day-to-day Emacs usage:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Switching windows multiple times to land my cursor on some text&lt;/li&gt;
&lt;li&gt;Isearching through more than three matches to jump to the right one&lt;/li&gt;
&lt;li&gt;Moving the point a long distance to run a lookup command&lt;/li&gt;
&lt;li&gt;Activating the mark manually (&lt;code&gt;C-SPC&lt;/code&gt;) all the time&lt;/li&gt;
&lt;li&gt;Jumping to locations to delete single words&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;buried-in-keymaps&#34;&gt;Buried in keymaps&lt;/h3&gt;
&lt;p&gt;The other sense of &amp;ldquo;remembering to Avy&amp;rdquo; is that piling a new abstraction onto simple text editing means you have to learn a new keymap. Emacs already has too many of those!&lt;/p&gt;
&lt;p&gt;This is true. But the effort is greatly mitigated by a choice of keys that is sensible &lt;em&gt;to you&lt;/em&gt;. In the above code snippets, I made choices that mimic my Emacs&amp;rsquo; keybindings (which are close to the default ones) so I don&amp;rsquo;t have to remember anything new:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Action&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Avy keybinding&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Emacs keybinding&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Emacs Default?&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Kill&lt;/td&gt;
&lt;td&gt;&lt;code&gt;k&lt;/code&gt;, &lt;code&gt;K&lt;/code&gt; (line)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-k&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Copy&lt;/td&gt;
&lt;td&gt;&lt;code&gt;w&lt;/code&gt;, &lt;code&gt;W&lt;/code&gt; (line)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;M-w&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Yank&lt;/td&gt;
&lt;td&gt;&lt;code&gt;y&lt;/code&gt;, &lt;code&gt;Y&lt;/code&gt; (line)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-y&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Transpose&lt;/td&gt;
&lt;td&gt;&lt;code&gt;t&lt;/code&gt;, &lt;code&gt;T&lt;/code&gt; (line)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-t&lt;/code&gt;, &lt;code&gt;M-t&lt;/code&gt; etc&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Zap&lt;/td&gt;
&lt;td&gt;&lt;code&gt;z&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;M-z&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Flyspell&lt;/td&gt;
&lt;td&gt;&lt;code&gt;;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mark&lt;/td&gt;
&lt;td&gt;&lt;code&gt;m&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;m&lt;/code&gt; in special buffers&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Activate region&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SPC&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-SPC&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dictionary&lt;/td&gt;
&lt;td&gt;&lt;code&gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-h =&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Google search&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-h C-=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Embark&lt;/td&gt;
&lt;td&gt;&lt;code&gt;o&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;C-o&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;You can go beyond the mnemonic and simply reuse the same keybindings you use in regular editing, trading off a slightly longer key sequence for maximally reusing your muscle memory. If you&amp;rsquo;re an Embark user, you don&amp;rsquo;t even need the above keys, just one to call &lt;code&gt;embark-act&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;the-missing-pieces&#34;&gt;The missing pieces&lt;/h2&gt;
&lt;p&gt;There are two common editing actions that still require manually moving the point elsewhere, perhaps to another window:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Searching or jumping to the contents of other windows beyond the confines of the screen. This has a simple solution:&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;Isearching in other windows&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;isearch-forward-other-window&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;prefix&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Function to isearch-forward in other-window.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;unless&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;one-window-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;next&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prefix&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-1&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;other-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;next&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;isearch-forward&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;other-window&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;next&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;isearch-backward-other-window&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;prefix&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Function to isearch-backward in other-window.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;unless&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;one-window-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#007020&#34;&gt;save-excursion&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;next&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prefix&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-1&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;other-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;next&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;isearch-backward&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              (&lt;span style=&#34;color:#963&#34;&gt;other-window&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;-&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;next&lt;/span&gt;))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;global-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;C-M-s&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;isearch-forward-other-window&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;global-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;C-M-r&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;isearch-backward-other-window&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;In keeping with &lt;code&gt;C-M-v&lt;/code&gt; to scroll the other window, you can Isearch the other window with &lt;code&gt;C-M-s&lt;/code&gt; without switching to it&lt;sup id=&#34;fnref:8&#34;&gt;&lt;a href=&#34;#fn:8&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;8&lt;/a&gt;&lt;/sup&gt;. If you&amp;rsquo;re feeling adventurous, replace &lt;code&gt;(other-window next)&lt;/code&gt; in the above functions with &lt;code&gt;(ace-window)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can call Avy from Isearch as before, to run actions on essentially any text in the other-window&amp;rsquo;s buffer.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Copying regions of text. This has an Avy-based solution: &lt;code&gt;avy-copy-region&lt;/code&gt;. I promised at the beginning, however, that you would only need to call one Avy command. For now you would do this the boring way, using Avy only to make shorter jumps or using Isearch+Avy. The more elispy solution will have to wait until part II of this series.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This post primarily concerned itself with the &lt;span class=&#34;Act&#34;&gt;Act&lt;/span&gt; part as it connects with the ideas in the the previous one about &lt;a href=&#34;../fifteen-ways-to-use-embark&#34;&gt;ways to use Embark&lt;/a&gt;. But Avy is composed of modular pieces that makes it suitable for a wide variety of &lt;span class=&#34;Filter&#34;&gt;Filter&lt;/span&gt; → &lt;span class=&#34;Select&#34;&gt;Select&lt;/span&gt; applications as well. In part II of this series, we will dig into the Avy API and see how to create unique commands.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Technically there&amp;rsquo;s also sorting the candidates, which I lump in with filtering in this breakdown.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;Isearch combines filter/search/act into a single command for efficiency. Even so, it&amp;rsquo;s a very cleverly designed library for Emacs with support for many actions. Folks who replace Isearch entirely with Swiper or similar commands are missing out.&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;Or perhaps Avy is Emacs&amp;rsquo; version of Easymotion.&amp;#160;&lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34;&gt;
&lt;p&gt;Why would you want to google an s-expression? The most common reason is when the sexp is a hyphenated phrase, like Fink-Nottle.&amp;#160;&lt;a href=&#34;#fnref:4&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:5&#34;&gt;
&lt;p&gt;Thanks to Omar Antolin for the improvement to this function.&amp;#160;&lt;a href=&#34;#fnref:5&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:6&#34;&gt;
&lt;p&gt;Technically this is false, since we use &lt;code&gt;save-excursion&lt;/code&gt; in all the avy action functions. The real accomplishment here is that I got almost 4000 words into this piece before mentioning Embark.&amp;#160;&lt;a href=&#34;#fnref:6&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:7&#34;&gt;
&lt;p&gt;If you end up in a different window you can pop the global mark instead with &lt;code&gt;pop-global-mark&lt;/code&gt; (&lt;code&gt;C-x C-SPC&lt;/code&gt;). There are also external packages for this now, like &lt;a href=&#34;https://github.com/alphapapa/dogears.el&#34;&gt;dogears&lt;/a&gt;.&amp;#160;&lt;a href=&#34;#fnref:7&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:8&#34;&gt;
&lt;p&gt;&lt;code&gt;C-M-s&lt;/code&gt; is bound to &lt;code&gt;isearch-forward-regexp&lt;/code&gt; by default. You can continue to access it with &lt;code&gt;M-r&lt;/code&gt; in the Isearch map, &lt;em&gt;i.e.&lt;/em&gt; &lt;code&gt;C-s M-r&lt;/code&gt;.&amp;#160;&lt;a href=&#34;#fnref:8&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>Declickbait Elfeed</title>
      <link>https://karthinks.com/software/declickbait-elfeed/</link>
      <pubDate>Mon, 11 Oct 2021 05:27:00 -0700</pubDate>
      
      <guid>https://karthinks.com/software/declickbait-elfeed/</guid>
      <description>&lt;p&gt;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&amp;rsquo;T BELIEVE the results!&lt;/p&gt;
&lt;p&gt;The Before (The After will SHOCK you!):
&lt;img src=&#34;https://karthinks.com/img/declickbait-before-extra.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The After:
&lt;img src=&#34;https://karthinks.com/img/declickbait-after-extra.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The Code:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;elfeed-new-entry-hook&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;elfeed-declickbait-entry&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-declickbait-entry&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;entry&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;title&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;elfeed-entry-title&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;entry&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;setf&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;elfeed-meta&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;entry&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:title&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;elfeed-title-transform&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;title&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-title-transform&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;title&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Declickbait string TITLE.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;trim&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;\\(?:\\(?:\\.\\.\\.\\|[!?]\\)+\\)&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#963&#34;&gt;arr&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;split-string&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;title&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;trim&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#963&#34;&gt;s-table&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;copy-syntax-table&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;modify-syntax-entry&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?\&amp;#39;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;w&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;s-table&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;with-syntax-table&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;s-table&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;mapconcat&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;word&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   (&lt;span style=&#34;color:#007020&#34;&gt;cond&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    ((&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;member&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;word&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;AND&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;OR&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;IF&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;ON&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;IT&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;TO&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;A&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;OF&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;VS&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;IN&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;FOR&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;WAS&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;IS&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;BE&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;downcase&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;word&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    ((&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;member&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;word&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;WE&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;DAY&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;HOW&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;WHY&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;NOW&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;OLD&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;NEW&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;MY&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;TOO&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;GOT&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;GET&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;THE&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;ONE&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;DO&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;YOU&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;capitalize&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;word&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    ((&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;&amp;gt;&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;length&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;word&lt;/span&gt;) &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;3&lt;/span&gt;) (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;capitalize&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;word&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                    (&lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;word&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 &lt;span style=&#34;color:#963&#34;&gt;arr&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; &amp;#34;&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;code&gt;elfeed-title-transform&lt;/code&gt; can be replaced with something much better, like a grammar aware title formatter (AI or otherwise), or with information extracted from the content or video description of the entry. But I&amp;rsquo;ll settle for this pareto solution for what was &lt;a href=&#34;https://youtube.com/watch?v=tF4OdtSuXMg&#34;&gt;half an hour of live coding&lt;/a&gt; in the dark:&lt;/p&gt;
&lt;iframe width=&#34;704&#34; height=&#34;396&#34; src=&#34;https://www.youtube.com/embed/tF4OdtSuXMg&#34; title=&#34;YouTube video player&#34; frameborder=&#34;0&#34; allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&#34; allowfullscreen&gt;&lt;/iframe&gt;
&lt;p&gt;Okay, the above screenshots were chosen as a joke. Here&amp;rsquo;s a more representative version of the declickbait effect:&lt;/p&gt;
&lt;p&gt;Before:
&lt;img src=&#34;https://karthinks.com/img/declickbait-before.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;After:
&lt;img src=&#34;https://karthinks.com/img/declickbait-after.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item><item>
      <title>Popup buffer management with keyboard hints</title>
      <link>https://karthinks.com/software/popper-echo-mode-for-emacs/</link>
      <pubDate>Sat, 09 Oct 2021 20:46:00 -0700</pubDate>
      
      <guid>https://karthinks.com/software/popper-echo-mode-for-emacs/</guid>
      <description>&lt;p&gt;Just updated &lt;a href=&#34;https://github.com/karthink/popper&#34;&gt;Popper for Emacs&lt;/a&gt; with hinting in the echo area:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/popper-echo-demo.svg&#34; width=&#34;900px&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;When you toggle a popup, popups for the current context are listed in the echo area along with keyboard hints (&lt;code&gt;M-1&lt;/code&gt; through &lt;code&gt;M-9&lt;/code&gt; by default) to switch to them instantly. The listing is in the order in which the popups are displayed with &lt;code&gt;popper-cycle&lt;/code&gt;.  &lt;a href=&#34;https://user-images.githubusercontent.com/8607532/135746395-dfe3b3e8-9d5a-4309-b521-9555a34bb73d.mp4&#34;&gt;Here&lt;/a&gt; is a demo of this in action.&lt;/p&gt;
&lt;p&gt;There is a dispatch feature included that is currently undocumented. When this transient keymap is active, you can kill any of the popups directly by prefixing the key for that popup with &lt;code&gt;k&lt;/code&gt;, &lt;em&gt;i.e.&lt;/em&gt; &lt;code&gt;k M-2&lt;/code&gt; to kill the second popup in line. Similarly, &lt;code&gt;^ M-2&lt;/code&gt; will raise the second popup to being a regular buffer, &lt;em&gt;i.e.&lt;/em&gt; persistent and not affected by Popper commands. As usual most of this behaviour is customizable.&lt;/p&gt;
&lt;p&gt;The echo area display can be noisy and annoying if you don&amp;rsquo;t need it, so it&amp;rsquo;s disabled by default and can be activated as the separate minor mode &lt;code&gt;popper-echo-mode&lt;/code&gt;. I added it tentatively, but I find myself using it all the time to switch popup buffers quickly.&lt;/p&gt;
</description>
    </item><item>
      <title>Jumping directories in eshell</title>
      <link>https://karthinks.com/software/jumping-directories-in-eshell/</link>
      <pubDate>Fri, 08 Oct 2021 17:33:00 -0700</pubDate>
      
      <guid>https://karthinks.com/software/jumping-directories-in-eshell/</guid>
      <description>&lt;p&gt;A quick note that I thought might be interesting to document.&lt;/p&gt;
&lt;p&gt;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&amp;rsquo;s very easy to implement a more powerful version of this by piggybacking off of &lt;a href=&#34;https://github.com/karthink/consult-dir&#34;&gt;consult-dir&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a &lt;strong&gt;z&lt;/strong&gt; command that lets you jump to any previously visited directory, as well as any bookmark, project or emacs-wide recent directory:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop&gt;
&lt;source src=&#34;https://karthinks.com/img/eshell-z.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;It&amp;rsquo;s a single function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;eshell/z&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;regexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Navigate to a previously visited directory in eshell, or to
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;any directory proferred by &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`consult-dir&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;eshell-dirs&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;delete-dups&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;mapcar&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;abbreviate-file-name&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                (&lt;span style=&#34;color:#963&#34;&gt;ring-elements&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;eshell-last-dir-ring&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;cond&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       ((&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;not&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;regexp&lt;/span&gt;) (&lt;span style=&#34;color:#007020&#34;&gt;featurep&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;consult-dir&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;consult-dir--source-eshell&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;:name&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Eshell&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                             &lt;span style=&#34;color:#007020&#34;&gt;:narrow&lt;/span&gt; &lt;span style=&#34;color:#04d;background-color:#fff0f0&#34;&gt;?e&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                             &lt;span style=&#34;color:#007020&#34;&gt;:category&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                             &lt;span style=&#34;color:#007020&#34;&gt;:face&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;consult-file&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                             &lt;span style=&#34;color:#007020&#34;&gt;:items&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;eshell-dirs&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#963&#34;&gt;consult-dir-sources&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cons&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;consult-dir--source-eshell&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                          &lt;span style=&#34;color:#963&#34;&gt;consult-dir-sources&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#963&#34;&gt;eshell/cd&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;substring-no-properties&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                      (&lt;span style=&#34;color:#963&#34;&gt;consult-dir--pick&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Switch directory: &amp;#34;&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;eshell/cd&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;regexp&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;eshell-find-previous-directory&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;regexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                            (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;completing-read&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;cd: &amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;eshell-dirs&lt;/span&gt;)))))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Plus &lt;code&gt;consult-dir&lt;/code&gt;, of course.&lt;/p&gt;
&lt;p&gt;Note that if you provide input to the command instead, &lt;em&gt;e.g.&lt;/em&gt; &lt;code&gt;z doc&lt;/code&gt;, it will jump directly to the last matching directory you visited in eshell, &lt;em&gt;i.e.&lt;/em&gt; &lt;code&gt;~/Documents/&lt;/code&gt; or something like it.&lt;/p&gt;
&lt;p&gt;The idea is simple, and it should be trivial to write something similar if you&amp;rsquo;re a Helm or Ivy user, as well as to write one for the comint mode &lt;code&gt;M-x shell&lt;/code&gt;.&lt;/p&gt;
</description>
    </item><item>
      <title>Fifteen ways to use Embark</title>
      <link>https://karthinks.com/software/fifteen-ways-to-use-embark/</link>
      <pubDate>Wed, 06 Oct 2021 05:53:00 -0700</pubDate>
      
      <guid>https://karthinks.com/software/fifteen-ways-to-use-embark/</guid>
      <description>&lt;p&gt;&lt;em&gt;Update (2024-10-02): Update for Emacs 29&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Update (2024-09-08): Read this article in Japanese at &lt;a href=&#34;https://emacs-jp.github.io/tips/fifteen-ways-to-use-embark&#34;&gt;Qiita&lt;/a&gt; or at &lt;a href=&#34;https://emacs-jp.github.io/tips/fifteen-ways-to-use-embark&#34;&gt;Emacs-JP&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;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 &amp;ldquo;Play by play&amp;rdquo; section under each demo listing the sequence of actions in the demo.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/oantolin/embark/tree/98121bacef39abaf6f6849f87a439ba2184c03e2&#34;&gt;Embark&lt;/a&gt; is a fantastic and thoughtfully designed package for Emacs that flips Emacs&amp;rsquo; action → object ordering without adding a learning curve. It&amp;rsquo;s completely changed how I use Emacs, and I&amp;rsquo;m going to show you why.&lt;/p&gt;
&lt;p&gt;By default, Emacs&amp;rsquo; action model is to specify the action (&lt;code&gt;find-file&lt;/code&gt;), then the object (the file):
&lt;a href=&#34;https://karthinks.com/img/emacs-pattern.png&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/emacs-pattern.png&#34; alt=&#34;&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This mirrors how one does things in a shell:
&lt;a href=&#34;https://karthinks.com/img/shell-pattern.png&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/shell-pattern.png&#34; alt=&#34;&#34;&gt;&lt;/a&gt;
The difference is that before you submit your shell command, you&amp;rsquo;re free to edit both the action and the object, since it&amp;rsquo;s just a line of text. In Emacs you can change the object freely, but to change the action you&amp;rsquo;d have to hit &lt;code&gt;C-g&lt;/code&gt; and call a different command.&lt;/p&gt;
&lt;p&gt;Things work the other way in a GUI program like a file manager. You select some representation of the object (usually an icon), then choose the action you would like to perform on it:
&lt;a href=&#34;https://karthinks.com/img/gui-pattern.png&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/gui-pattern.png&#34; alt=&#34;&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Either paradigm works fine, but this is Emacs, there&amp;rsquo;s no reason to choose just one! &lt;strong&gt;Embark lets you go back and forth between the two patterns.&lt;/strong&gt; So you can call &lt;code&gt;find-file&lt;/code&gt; (say) and pick a file, only to realize that you want to do something else with it, like open it in another window, or copy the file to a different directory:&lt;/p&gt;
&lt;figure&gt;&lt;a href=&#34;https://karthinks.com/img/embark-pattern.png&#34;&gt;&lt;img src=&#34;https://karthinks.com/img/embark-pattern.png&#34;/&gt;&lt;/a&gt;
&lt;/figure&gt;

&lt;p&gt;With Embark, this is a breeze.&lt;/p&gt;
&lt;h2 id=&#34;embark-act-actually-dot-dot-dot-dot-and-but-first-dot-dot-dot&#34;&gt;&lt;code&gt;embark-act&lt;/code&gt;: &lt;em&gt;Actually&amp;hellip;.&lt;/em&gt; &amp;amp; &lt;em&gt;But first&amp;hellip;&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;embark-act&lt;/code&gt; is your &amp;ldquo;&lt;strong&gt;Actually&amp;hellip;&lt;/strong&gt;&amp;rdquo; command. As in, I called &lt;code&gt;package-install&lt;/code&gt; and picked a package but &lt;em&gt;actually&lt;/em&gt; I&amp;rsquo;d like to read the package description instead!&lt;/p&gt;
&lt;p&gt;&lt;code&gt;embark-act&lt;/code&gt; is your &amp;ldquo;&lt;strong&gt;Yes, but first&amp;hellip;&lt;/strong&gt;&amp;rdquo; command as well. As in, I called &lt;code&gt;find-file&lt;/code&gt; but &lt;em&gt;first I&amp;rsquo;d like to&lt;/em&gt; copy it elsewhere to be safe, then continue to open this file!&lt;/p&gt;
&lt;p&gt;Or perhaps you want to think of it as a keyboard driven analog of a &amp;ldquo;right-click menu&amp;rdquo; in a GUI environment. That works too, but the former maps better to the idea of &amp;ldquo;late-binding&amp;rdquo; and laziness that I think of Embark as enabling.&lt;/p&gt;
&lt;p&gt;Emacs makes you specify and fix the action/verb first (&lt;code&gt;find-file&lt;/code&gt;, say), then choose the thing it acts on (the file). If you call embark-act, this is reversed. Now the object (file) is fixed, and you&amp;rsquo;re free to choose the action.&lt;/p&gt;
&lt;p&gt;I know: It sounds like I&amp;rsquo;m describing Helm actions. The difference is that Embark works &lt;em&gt;everywhere&lt;/em&gt;, across all types of &amp;ldquo;objects&amp;rdquo;, and with &lt;em&gt;every&lt;/em&gt; initial and &lt;em&gt;wait-I-changed-my-mind&lt;/em&gt; command. There is no predetermined set of alternative actions configured to work with another predetermined set of initial actions. No one (including yourself) needs to have anticipated in advance what actions go together.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; This uniform, consistent integration into Emacs makes the difference between them one of kind and not of quantity, although it takes a bit of time to see this.&lt;/p&gt;
&lt;p&gt;This means you can start a command and select a candidate in the minibuffer, then call &lt;code&gt;embark-act&lt;/code&gt; and  &lt;code&gt;M-x some-other-command&lt;/code&gt; to run that command on the candidate instead. If you are about to kill a buffer with &lt;code&gt;C-x k&lt;/code&gt; but want to switch to it instead, you can call &lt;code&gt;embark-act&lt;/code&gt; followed by &lt;code&gt;C-x b&lt;/code&gt;. You can even do this without losing the &lt;code&gt;kill-buffer&lt;/code&gt; prompt if you just want a quick peek at the buffer!&lt;/p&gt;
&lt;p&gt;The categories of objects Embark understands covers most common cases: filenames, buffers, bookmarks, URLs, text regions, variables, commands, symbols and more.&lt;/p&gt;
&lt;p&gt;When you call &lt;code&gt;embark-act&lt;/code&gt;, Embark also activates a keymap with direct access to common actions you might want to run for each category of object. This makes it unnecessary to use &lt;code&gt;M-x&lt;/code&gt; to run your &lt;em&gt;I-changed-my-mind&lt;/em&gt; action all the time, although you always have that option. You can, of course, add your own commands to this keymap as I do below.&lt;/p&gt;
&lt;p&gt;I use &lt;code&gt;embark-act&lt;/code&gt; literally hundreds of times every day. Here are a few of my common uses. A few of these are built in, others need some elisp to work, all are surprisingly useful. To be clear, this list barely scratches the surface of the sphere of possibilities with Embark.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;A recipe for reproducing these demos&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;I use Embark in conjunction with various Consult commands (&lt;code&gt;consult-grep&lt;/code&gt;, &lt;code&gt;consult-locate&lt;/code&gt;, &lt;code&gt;consult-dir&lt;/code&gt; etc) in Emacs 27.2. If you want to reproduce these demos exactly in your Emacs, you will need the following packages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;embark&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;marginalia&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;vertico&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;consult&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;embark-consult&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;orderless&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;consult-dir&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ace-window&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;0x0&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Additionally you may need to bind the relevant commands (&lt;code&gt;embark-act&lt;/code&gt;, &lt;code&gt;embark-export&lt;/code&gt;, &lt;code&gt;consult-*&lt;/code&gt;) to suitable keys.&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;open-any-buffer-by-splitting-any-window&#34;&gt;Open any buffer by splitting any window&lt;/h3&gt;
&lt;p&gt;This needs a little background. The ace-window package allows you to switch to a window based on keyboard hints. A less well known feature is that it also provides a &amp;ldquo;dispatch menu&amp;rdquo; that lets you act on windows in ways beyond simply switching to them:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/EWC4jNH.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/ace-dispatch-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;With two or more windows open, call &lt;code&gt;ace-window&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;?&lt;/code&gt; to bring up the dispatch menu.&lt;/li&gt;
&lt;li&gt;Press the dispatch key to split a window horizontally (&lt;code&gt;v&lt;/code&gt; in my video)&lt;/li&gt;
&lt;li&gt;Press the ace-window key corresponding to the buffer you want to split (&lt;code&gt;e&lt;/code&gt; in my video)&lt;/li&gt;
&lt;li&gt;Repeat steps 1 and 2&lt;/li&gt;
&lt;li&gt;Press the dispatch key to split a window vertically (&lt;code&gt;s&lt;/code&gt; in my video)&lt;/li&gt;
&lt;li&gt;Press the ace-window key corresponding to the buffer you want to split (&lt;code&gt;w&lt;/code&gt; in my video)&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;So you can kill windows, move them around, split them and more by using the dispatch keys. (Hit &lt;code&gt;?&lt;/code&gt; to bring up the dispatch menu.)&lt;/p&gt;
&lt;p&gt;Now: You can call ace-window via Embark to display a candidate anywhere, including in splits that you create using the above dispatch menu. This means any buffer/file/bookmark I open is always placed exactly where I want it to be on the screen.&lt;/p&gt;
&lt;p&gt;In the below demo, I open a bookmark (with &lt;code&gt;consult-bookmark&lt;/code&gt;), a file (with &lt;code&gt;find-file&lt;/code&gt;) and a buffer (with &lt;code&gt;consult-buffer&lt;/code&gt;) in sequence. Each time, I run &lt;code&gt;embark-act&lt;/code&gt; and select the ace-window action, which activates &lt;code&gt;ace-window&lt;/code&gt;. You can then display the buffer in any existing window by making a selection with &lt;code&gt;ace-window&lt;/code&gt;. I actually go one step further in the demo: I split one of the existing windows using &lt;code&gt;ace-window&lt;/code&gt;&amp;rsquo;s dispatch feature from above and display the relevant buffer in that split!&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/5hwqpQD.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-ace-open-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run a command that requires selecting a file, bookmark or buffer, perhaps &lt;code&gt;switch-to-buffer&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Select one and run &lt;code&gt;embark-act&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Run the &lt;code&gt;my/embark-ace-action&lt;/code&gt; with &lt;code&gt;o&lt;/code&gt; (see below)&lt;/li&gt;
&lt;li&gt;Select the window where you want the buffer to be placed, OR&lt;/li&gt;
&lt;li&gt;Split an existing window with &lt;code&gt;v&lt;/code&gt; or &lt;code&gt;b&lt;/code&gt; (see &lt;code&gt;aw-dispatch-alist&lt;/code&gt;) followed by a window selection, and display the buffer in the new split.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;Update for Emacs 29&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;p&gt;Emacs 29 provides a bunch of &amp;ldquo;window-prefix&amp;rdquo; actions: &lt;a href=&#34;https://karthinks.com/software/emacs-window-management-almanac/#the-other-window-prefix--built-in&#34;&gt;these are commands you can call to display the output of the &lt;em&gt;next&lt;/em&gt; command in specified windows&lt;/a&gt;.  For example, calling &lt;code&gt;other-tab-prefix&lt;/code&gt; and then &lt;code&gt;find-file&lt;/code&gt; will open the file you select in a new tab.  Emacs provides &lt;code&gt;same-window-prefix&lt;/code&gt;, &lt;code&gt;other-window-prefix&lt;/code&gt;, &lt;code&gt;other-tab-prefix&lt;/code&gt; and &lt;code&gt;other-frame-prefix&lt;/code&gt;.  We can &lt;a href=&#34;https://karthinks.com/software/emacs-window-management-almanac/#a-window-prefix-command-for-ace-window&#34;&gt;go one step further and define&lt;/a&gt; an &lt;code&gt;ace-window-prefix&lt;/code&gt;. Calling it will activate &lt;code&gt;ace-window&lt;/code&gt; after the &lt;em&gt;next&lt;/em&gt; command and show its result in the window you select, including possibly in splits you create using &lt;code&gt;ace-window&lt;/code&gt; actions:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;ace-window-prefix&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Use &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`ace-window&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; to display the buffer of the next command.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;The next buffer is the buffer displayed by the next command invoked
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;immediately after this command (ignoring reading from the minibuffer).
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;Creates a new window before displaying the buffer.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;When &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`switch-to-buffer-obey-display-actions&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; is non-nil,
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`switch-to-buffer&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; commands are also supported.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;display-buffer-override-next-command&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;type&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          &lt;span style=&#34;color:#963&#34;&gt;window&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;aw-select&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;propertize&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; ACE&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;face&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;mode-line-highlight&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          &lt;span style=&#34;color:#963&#34;&gt;type&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;reuse&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cons&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;type&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;     &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;[ace-window]&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;message&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Use &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`ace-window&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; to display next command buffer...&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now the interesting bit:  Instead of defining separate Embark actions for opening files, bookmarks or buffers in specified windows or splits, we can embed the window prefix actions into Embark so they can be used with any category of object.&lt;/p&gt;
&lt;p&gt;First we define a keymap with these actions:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;defvar-keymap&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/window-prefix-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:doc&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Keymap for various window-prefix maps&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#007020&#34;&gt;:suppress&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;nodigits&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;o&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;ace-window-prefix&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;0&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;ace-window-prefix&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;1&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;same-window-prefix&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;2&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;split-window-vertically&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;3&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;split-window-horizontally&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;4&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;other-window-prefix&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;5&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;other-frame-prefix&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;6&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;other-tab-prefix&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;t&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;other-tab-prefix&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;What we&amp;rsquo;d like: When running &lt;code&gt;embark-act&lt;/code&gt;, pressing any of the keys in the above keymap should run Embark&amp;rsquo;s default action &amp;ndash; i.e. the command that you originally invoked &amp;ndash; but with the right window-prefix applied.  This will supersede the below, older method of defining individual Embark commands for each kind of object.  Getting there involves hooking into Embark&amp;rsquo;s event loop, so this is a little convoluted.  Strap in!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We define a function that looks up keys in the above keymap and calls the right &lt;code&gt;-window-prefix&lt;/code&gt; command before running Embark&amp;rsquo;s default action.  This is intended as a hook function for Embark&amp;rsquo;s &lt;code&gt;embark-around-action-hooks&lt;/code&gt;, which lets you insert specific behavior around each Embark action.  This is the code we&amp;rsquo;d like Embark to &lt;em&gt;actually&lt;/em&gt; run:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; Look up the key in `my/window-prefix-map&amp;#39; and call that function first.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; Then run the default embark action.&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;cl-defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/embark--call-prefix-action&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;rest&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;run&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;type&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;allow-other-keys&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;when-let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;keymap-lookup&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     &lt;span style=&#34;color:#963&#34;&gt;my/window-prefix-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                     (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;key-description&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;this-command-keys-vector&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;run&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:action&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;embark--default-action&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;type&lt;/span&gt;) &lt;span style=&#34;color:#007020&#34;&gt;:type&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;type&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;rest&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;But this behavior is not attached to any Embark action yet.  To access this behavior from Embark, we define a dummy Embark action whose behavior will be replaced by the above function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; Dummy function, will be overridden by running `embark-around-action-hooks&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/embark-set-window&lt;/span&gt; () (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#888&#34;&gt;;; When running the dummy function, call the prefix action from above&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setf&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;my/embark-set-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-around-action-hooks&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;my/embark--call-prefix-action&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A wrinkle: to support multi-category commands like those provided by Consult (where the candidates can be a mix of bookmarks, buffers, files and others), we need to explicitly set the &amp;ldquo;default&amp;rdquo; Embark action for relevant categories:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;setf&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-default-action-overrides&lt;/span&gt;) &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;pop-to-buffer-same-window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;file&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-default-action-overrides&lt;/span&gt;) &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;find-file&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;bookmark&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-default-action-overrides&lt;/span&gt;) &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;bookmark-jump&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;alist-get&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;library&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-default-action-overrides&lt;/span&gt;) &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;find-library&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Finally, we map this dummy embark action to all the keys in &lt;code&gt;my/window-prefix-map&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;map-keymap&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;cmd&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#963&#34;&gt;keymap-set&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-general-map&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;key-description&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;make-vector&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;1&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;key&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                            &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;my/embark-set-window&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              &lt;span style=&#34;color:#963&#34;&gt;my/window-prefix-map&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The fact that all keys in &lt;code&gt;my/window-prefix-map&lt;/code&gt; are mapped to the same action is not a problem &amp;ndash; in &lt;code&gt;my/embark--call-prefix-action&lt;/code&gt; we dispatch on the key that was actually pressed.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;div class=&#34;warning&#34;&gt;
&lt;p&gt;If you&amp;rsquo;re on Emacs 29 or later, you can enable behavior like the above for all commands and categories at once, without needing to define individual actions.  The below is a more manual (and backward-compatible) approach.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;To get this to work, you&amp;rsquo;ll need to add a few ace-window functions to the Embark file actions map:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;eval-when-compile&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defmacro&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/embark-ace-action&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;fn&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;intern&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;my/embark-ace-&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-name&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;fn&lt;/span&gt;))) ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;with-demoted-errors&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;%s&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;require&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;ace-window&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;aw-dispatch-always&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;aw-switch-to-window&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;aw-select&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;call-interactively&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-function&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;,fn&lt;/span&gt;)))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-file-map&lt;/span&gt;     (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;o&amp;#34;&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;my/embark-ace-action&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;find-file&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-buffer-map&lt;/span&gt;   (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;o&amp;#34;&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;my/embark-ace-action&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;switch-to-buffer&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-bookmark-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;o&amp;#34;&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;my/embark-ace-action&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;bookmark-jump&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I also add actions to open the buffer in a vertical or horizontal split. But you probably don&amp;rsquo;t need this, since you can do this and a lot more with ace-window&amp;rsquo;s dispatch menu!&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;eval-when-compile&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defmacro&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/embark-split-action&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;fn&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;split-type&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#333&#34;&gt;`&lt;/span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;intern&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;my/embark-&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-name&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;fn&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                      &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;-&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;car&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;last&lt;/span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;split-string&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                   (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;symbol-name&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;split-type&lt;/span&gt;) &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;-&amp;#34;&lt;/span&gt;))))) ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;funcall&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;split-type&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;       (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;call-interactively&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#333&#34;&gt;,&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;fn&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-file-map&lt;/span&gt;     (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;2&amp;#34;&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;my/embark-split-action&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;find-file&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;split-window-below&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-buffer-map&lt;/span&gt;   (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;2&amp;#34;&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;my/embark-split-action&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;switch-to-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;split-window-below&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-bookmark-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;2&amp;#34;&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;my/embark-split-action&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;bookmark-jump&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;split-window-below&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-file-map&lt;/span&gt;     (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;3&amp;#34;&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;my/embark-split-action&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;find-file&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;split-window-right&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-buffer-map&lt;/span&gt;   (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;3&amp;#34;&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;my/embark-split-action&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;switch-to-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;split-window-right&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-bookmark-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;3&amp;#34;&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;my/embark-split-action&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;bookmark-jump&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;split-window-right&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h3 id=&#34;copy-a-file-to-a-remote-location-when-finding-a-file&#34;&gt;Copy a file to a remote location when finding a file&lt;/h3&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/mpArf9q.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-copy-remote-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;em&gt;any&lt;/em&gt; command that requires selecting a file, perhaps &lt;code&gt;find-file-other-window&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Select one and run &lt;code&gt;embark-act&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Run the &lt;code&gt;copy-file&lt;/code&gt; action with &lt;code&gt;c&lt;/code&gt;. Embark has a key for this but you can also &lt;code&gt;M-x copy-file&lt;/code&gt; here.&lt;/li&gt;
&lt;li&gt;Navigate to the destination path. In the video I used the &lt;a href=&#34;https://github.com/karthink/consult-dir&#34;&gt;consult-dir&lt;/a&gt; package to instantly switch the path to one of my bookmarks, a remote location.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;RET&lt;/code&gt; to copy the file. You can type in a name to copy it as.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Here&amp;rsquo;s what happened. In any file prompt, you can call &lt;code&gt;embark-act&lt;/code&gt;  and select the copy action to copy the file instead. (You could just as well call &lt;code&gt;M-x copy-file&lt;/code&gt;.) In this case I then use &lt;a href=&#34;https://github.com/karthink/consult-dir&#34;&gt;consult-dir&lt;/a&gt; to insert a bookmark that points to my server into the destination prompt, and the file is copied using Tramp.&lt;/p&gt;
&lt;p&gt;You can even do this without losing the &lt;code&gt;find-file&lt;/code&gt; prompt! Calling &lt;code&gt;embark-act&lt;/code&gt; with a prefix argument keeps the prompt alive:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/BIw0Tht.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-copy-remote-persist-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;em&gt;any&lt;/em&gt; command that requires selecting a file, perhaps &lt;code&gt;find-file-other-window&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Select one and run &lt;code&gt;embark-act&lt;/code&gt; with a prefix argument. That is, if your binding for &lt;code&gt;embark-act&lt;/code&gt; is &lt;code&gt;C-.&lt;/code&gt;, run &lt;code&gt;C-u C-.&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Run the &lt;code&gt;copy-file&lt;/code&gt; action with &lt;code&gt;c&lt;/code&gt;. Embark has a key for this but you can also &lt;code&gt;M-x copy-file&lt;/code&gt; here.&lt;/li&gt;
&lt;li&gt;Navigate to the destination path. In the video I used the &lt;a href=&#34;https://github.com/karthink/consult-dir&#34;&gt;consult-dir&lt;/a&gt; package to instantly switch the path to one of my bookmarks, a remote location.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;RET&lt;/code&gt; to copy the file. You can type in a name to copy it as.&lt;/li&gt;
&lt;li&gt;Continue to use your &lt;code&gt;find-file-other-window&lt;/code&gt; prompt as before.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;At the end I quit the &lt;code&gt;find-file&lt;/code&gt; prompt manually and check the remote directory to ensure that the file has been copied.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;insert-a-minibuffer-candidate-into-the-buffer&#34;&gt;Insert a minibuffer candidate into the buffer&lt;/h3&gt;
&lt;p&gt;Simple but very convenient:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/SrAD4Oa.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-insert-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;em&gt;any&lt;/em&gt; command that requires you to make a selection using the minibuffer. The selection can be anything, it just has to display some text.&lt;/li&gt;
&lt;li&gt;In the video I chose a distant directory with &lt;code&gt;consult-dir&lt;/code&gt; and selected a file in that directory.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;embark-act&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;i&lt;/code&gt; to insert the text of the selection into the main buffer. In the video I used &lt;code&gt;I&lt;/code&gt; instead to insert the selected file&amp;rsquo;s relative path. &lt;code&gt;I&lt;/code&gt; does different things based on the type of object you&amp;rsquo;re selecting. For example, &lt;code&gt;I&lt;/code&gt; with a buffer candidate inserts the contents of the buffer instead.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;hr&gt;
&lt;h3 id=&#34;run-a-shell-command-on-a-minibuffer-candidate-file-without-losing-your-session&#34;&gt;Run a shell command on a minibuffer candidate file without losing your session&lt;/h3&gt;
&lt;p&gt;A perfect example of &lt;em&gt;But First I need to&amp;hellip;&lt;/em&gt;:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/9Wf6mQc.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-shell-cmd-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;em&gt;any&lt;/em&gt; command that requires selecting a file, perhaps &lt;code&gt;find-file&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;I switched to a distant directory using &lt;code&gt;consult-dir&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select a file and run &lt;code&gt;embark-act&lt;/code&gt; with a prefix argument. That is, if your binding for &lt;code&gt;embark-act&lt;/code&gt; is &lt;code&gt;C-.&lt;/code&gt;, run &lt;code&gt;C-u C-.&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;&amp;amp;&lt;/code&gt; to run the &lt;code&gt;async-shell-command&lt;/code&gt; action. Embark has a key for this in its keymaps but you could run &lt;code&gt;M-x async-shell-command&lt;/code&gt; or call its default keybinding (&lt;code&gt;M-&amp;amp;&lt;/code&gt;) instead.&lt;/li&gt;
&lt;li&gt;Type in the command at the prompt. The file name is already filled in for you. I used the &lt;code&gt;file&lt;/code&gt; shell command for more info on a file.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;RET&lt;/code&gt; to run the command and return to the &lt;code&gt;find-file&lt;/code&gt; prompt.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;I called the &amp;ldquo;file&amp;rdquo; shell command for more info on the file without ending the &lt;code&gt;find-file&lt;/code&gt; prompt.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;open-a-file-as-root-without-losing-your-session&#34;&gt;Open a file as root without losing your session&lt;/h3&gt;
&lt;p&gt;Emacs&amp;rsquo; version of forgetting to add &lt;code&gt;sudo&lt;/code&gt; before the command. In the shell you can go back to the start of the prompt and type it in, or engage in the &lt;code&gt;sudo !!&lt;/code&gt; ritual. In Emacs I use an Embark action:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/ccjvizN.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-sudo-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;em&gt;any&lt;/em&gt; command that requires selecting a file. I used &lt;code&gt;consult-locate&lt;/code&gt; to locate a root-owned file on my filesystem.&lt;/li&gt;
&lt;li&gt;Select one and run &lt;code&gt;embark-act&lt;/code&gt; with a prefix argument. That is, if your binding for &lt;code&gt;embark-act&lt;/code&gt; is &lt;code&gt;C-.&lt;/code&gt;, run &lt;code&gt;C-u C-.&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Select the &lt;code&gt;sudo-find-file&lt;/code&gt; action with &lt;code&gt;S&lt;/code&gt;. Note: You&amp;rsquo;ll need to add this action to the keymap, see below. Alternatively you can run &lt;code&gt;M-x sudo-find-file&lt;/code&gt; or its global binding.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Like before, this works from any file prompt but the command I started with was &lt;code&gt;consult-locate&lt;/code&gt;. For the sudo program there is the &lt;code&gt;sudo-edit&lt;/code&gt; package, although I used a snippet from my init file that I can&amp;rsquo;t ascertain the provenance of anymore:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;sudo-find-file&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Open FILE as root.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;FOpen file as root: &amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;file-writable-p&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;user-error&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;File is user writeable, aborting sudo&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;find-file&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;file-remote-p&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                 (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;/&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;file-remote-p&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;method&lt;/span&gt;) &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;:&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         (&lt;span style=&#34;color:#963&#34;&gt;file-remote-p&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;user&lt;/span&gt;) &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;@&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;file-remote-p&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;host&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;|sudo:root@&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         (&lt;span style=&#34;color:#963&#34;&gt;file-remote-p&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;host&lt;/span&gt;) &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;:&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;file-remote-p&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;localname&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;/sudo:root@localhost:&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;file&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To use &lt;code&gt;sudo-find-file&lt;/code&gt; as an Embark action, you can run it (with &lt;code&gt;M-x&lt;/code&gt; or a global keybinding) after calling &lt;code&gt;embark-act&lt;/code&gt;, or shorten the process further by adding an entry to Embark&amp;rsquo;s file actions map:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-file-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;S&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;sudo-find-file&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h3 id=&#34;upload-a-region-of-text-to-0x0&#34;&gt;Upload a region of text to 0x0&lt;/h3&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/i06G4vT.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-0x0-region-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Select a region of text in a buffer.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;embark-act&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;U&lt;/code&gt; to choose the &lt;code&gt;0x0-dwim&lt;/code&gt; action. Note: You&amp;rsquo;ll need to add this action to the keymap, see below.&lt;/li&gt;
&lt;li&gt;The region text will be uploaded to 0x0 and URL added to the &lt;code&gt;kill-ring&lt;/code&gt;. (See message at the end of the video.)&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;I&amp;rsquo;m using the &lt;a href=&#34;https://melpa.org/#/0x0&#34;&gt;0x0&lt;/a&gt; package for the &lt;code&gt;0x0-dwim&lt;/code&gt; function. When called as an Embark action on a URL, this shortens it. When called on a file, it uploads the file. The echo area message at the end (from &lt;code&gt;0x0-dwim&lt;/code&gt;) tells me the upload URL has been copied to the kill ring. As with the other examples, you can call &lt;code&gt;0x0-dwim&lt;/code&gt; after running &lt;code&gt;embark-act&lt;/code&gt; or define a short key for it in one of Embark&amp;rsquo;s keymaps:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-region-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;U&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;0x0-dwim&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h3 id=&#34;visit-a-package-s-url-from-the-minibuffer&#34;&gt;Visit a package&amp;rsquo;s URL from the minibuffer&lt;/h3&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/b6BTODS.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-package-url-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;em&gt;any&lt;/em&gt; command that requires selecting a package, perhaps &lt;code&gt;describe-package&lt;/code&gt; (&lt;code&gt;C-h P&lt;/code&gt; by default)&lt;/li&gt;
&lt;li&gt;Select a package and run &lt;code&gt;embark-act&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;u&lt;/code&gt; to run the &lt;code&gt;embark-browse-package-url&lt;/code&gt; action.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;In this case I ran the &lt;code&gt;describe-package&lt;/code&gt; command before going &amp;ldquo;&lt;strong&gt;Actually&amp;hellip; URL please&lt;/strong&gt;&amp;rdquo;, but in this example as all the others, there&amp;rsquo;s nothing special about &lt;code&gt;describe-package&lt;/code&gt;. Any command that gives you a list of packages at the minibuffer will proffer the same set of Embark actions.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;set-a-variable-from-anywhere-it-appears-in-a-buffer&#34;&gt;Set a variable from anywhere it appears in a buffer&lt;/h3&gt;
&lt;p&gt;Super handy for quickly setting variables, especially when testing code.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/wltZaGq.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-set-var-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Move point to a variable in a buffer. (Alternatively, run a command that requires selecting a variable at the minibuffer, like &lt;code&gt;describe-variable&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;embark-act&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;=&lt;/code&gt; to run the &lt;code&gt;set-variable&lt;/code&gt; action. Embark has a key for this in its keymaps, but you could call &lt;code&gt;M-x set-variable&lt;/code&gt; instead.&lt;/li&gt;
&lt;li&gt;Set the new value of the variable.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;In this case Embark has an entry for &lt;code&gt;set-variable&lt;/code&gt; in its variables keymap (bound to &lt;code&gt;=&lt;/code&gt;), but you can just call &lt;code&gt;M-x set-variable&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;add-a-keybinding-for-a-command-name-from-anywhere-it-appears&#34;&gt;Add a keybinding for a command name from anywhere it appears&lt;/h3&gt;
&lt;p&gt;Set all the keys.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/A0hHGhi.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-set-key-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Move point to a command name in a buffer. (Alternatively, run a command that requires selecting a command at the minibuffer, like &lt;code&gt;describe-command&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;embark-act&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;g&lt;/code&gt; to run the &lt;code&gt;global-set-key&lt;/code&gt; action. Embark has a key for this in its keymaps, but you could call &lt;code&gt;M-x global-set-key&lt;/code&gt; instead.&lt;/li&gt;
&lt;li&gt;Set the new keybinding for the command.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Embark provides an action in its keymap to run &lt;code&gt;global-set-key&lt;/code&gt;, but you could just call &lt;code&gt;M-x global-set-key&lt;/code&gt; after running &lt;code&gt;embark-act&lt;/code&gt; with the point on a command name. There is also &lt;code&gt;local-set-key&lt;/code&gt; in the embark keymap.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;embark-export-i-want-a-gist-so-give-me-a-list&#34;&gt;&lt;code&gt;embark-export&lt;/code&gt;: &lt;em&gt;I want a gist, so give me a list&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;If that was everything Embark did I&amp;rsquo;d be a happy camper. But &lt;code&gt;embark-act&lt;/code&gt; isn&amp;rsquo;t even its best feature. That would be the gem of composability that is &lt;code&gt;embark-export&lt;/code&gt; (and its lesser kin &lt;code&gt;embark-collect&lt;/code&gt;). These commands create persistent collections from minibuffer candidate lists: It&amp;rsquo;s one part ivy-occur and one part glue that ties together Emacs libraries better than Emacs does. The examples illustrate why.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;export-emacs-package-candidates-to-a-package-menu&#34;&gt;Export Emacs package candidates to a package menu&lt;/h3&gt;
&lt;p&gt;Want a package-menu-mode buffer with all packages involving shells in Emacs? &lt;code&gt;embark-export&lt;/code&gt; has you covered:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/oaDGV3X.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-package-export-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;em&gt;any&lt;/em&gt; command that requires selecting a package, perhaps &lt;code&gt;describe-package&lt;/code&gt; (&lt;code&gt;C-h P&lt;/code&gt; by default)&lt;/li&gt;
&lt;li&gt;(Optional) Type in some text to filter the completions list&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;embark-export&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;The clever idea behind &lt;code&gt;embark-export&lt;/code&gt; is to reuse Emacs&amp;rsquo; built-in functionality whenever possible: the package-menu library already handles displaying packages. If you&amp;rsquo;re generating a list of packages with user-specified conditions, why reinvent the wheel?&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;collect-imenu-candidates-in-an-imenu-list&#34;&gt;Collect imenu candidates in an &amp;ldquo;imenu-list&amp;rdquo;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;embark-collect&lt;/code&gt; creates persistent collections of minibuffer completion candidates (filtered by user input) in a way that basically obsoletes every &amp;ldquo;listing&amp;rdquo; package for me. In this example I create a filtered list of &lt;code&gt;imenu&lt;/code&gt; items that sticks around and that I can use to navigate around the file:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/MJlM9cL.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-imenu-list-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;When visiting any file, run &lt;code&gt;imenu&lt;/code&gt; or a version of it (I ran &lt;code&gt;consult-imenu-all&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;(Optional) Type in some text to filter the completions list&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;embark-export&lt;/code&gt;. (This actually runs &lt;code&gt;embark-collect&lt;/code&gt; under the hood. You could run &lt;code&gt;embark-collect&lt;/code&gt; directly instead, but it&amp;rsquo;s simpler to just use one command.)&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;RET&lt;/code&gt; in the persistent collections buffer to navigate to that symbol in the file.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;I didn&amp;rsquo;t show this in the demo, but all &lt;code&gt;embark-act&lt;/code&gt; actions are available in the Collections buffer, and you can even call them directly (i.e. without calling &lt;code&gt;embark-act&lt;/code&gt; first) by turning on &lt;code&gt;embark-collect-direct-action-minor-mode&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;export-file-candidates-to-a-dired-buffer&#34;&gt;Export file candidates to a dired-buffer&lt;/h3&gt;
&lt;p&gt;Have a list of files you arrived at in a tortuous manner that you want to keep around? &lt;code&gt;dired&lt;/code&gt; was created to list files, and &lt;code&gt;embark-export&lt;/code&gt; respects this:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/6ZY08H2.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-file-export-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;em&gt;any&lt;/em&gt; command that requires selecting a file. I used &lt;code&gt;consult-fd&lt;/code&gt; to find all files matching a pattern below a directory.&lt;/li&gt;
&lt;li&gt;(Optional) Type in some text to filter the completions list. With &lt;code&gt;consult-fd&lt;/code&gt; you do this by adding a &lt;code&gt;#&lt;/code&gt; to end the string to search on and begin the string used to filter the results.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;embark-export&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;This obsoletes &lt;code&gt;find-name-dired&lt;/code&gt;, another &amp;ldquo;listing&amp;rdquo; based feature.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;export-buffer-candidates-to-ibuffer&#34;&gt;Export buffer candidates to ibuffer&lt;/h3&gt;
&lt;p&gt;You saw this coming: Any list of buffers gets exported to an &lt;code&gt;ibuffer&lt;/code&gt;.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/pmBTb6q.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-buffer-export-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run &lt;em&gt;any&lt;/em&gt; command that requires selecting a buffer. I used &lt;code&gt;consult-buffer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Type in some text to filter the completions list:
&lt;ul&gt;
&lt;li&gt;I pressed &lt;code&gt;b SPC&lt;/code&gt; to narrow the consult-buffer list to buffers, then&lt;/li&gt;
&lt;li&gt;typed in &lt;code&gt;!&lt;/code&gt; followed by &lt;code&gt;*&lt;/code&gt; to omit all buffers&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt; that begin with a &lt;code&gt;*&lt;/code&gt;, i.e. &amp;ldquo;special&amp;rdquo; buffers.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;embark-export&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;hr&gt;
&lt;h3 id=&#34;export-variable-candidates-to-a-customize-buffer&#34;&gt;Export variable candidates to a customize buffer&lt;/h3&gt;
&lt;p&gt;A list of variables is exported by &lt;code&gt;embark-export&lt;/code&gt; into a customize buffer:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/NIQBwKS.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-custom-var-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run a command that requires selecting a variable, like &lt;code&gt;describe-variable&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Type in some text to filter the completions list&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;embark-export&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;This is a great way to transition from looking up a variable to a full-fledged apropos on relevant items when you need to.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;export-grep-or-line-candidates-to-a-grep-buffer&#34;&gt;Export grep or line candidates to a grep buffer&lt;/h3&gt;
&lt;p&gt;Any &lt;code&gt;occur&lt;/code&gt;-like results (from consult-line, grep, xref etc) get exported into a &lt;code&gt;grep&lt;/code&gt; buffer.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/PjS1Yx6.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-grep-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run a command that generates a list of grep-style matches. I used &lt;code&gt;consult-ripgrep&lt;/code&gt; in the demo. Other Consult-based options are &lt;code&gt;consult-grep&lt;/code&gt;, &lt;code&gt;consult-git-grep&lt;/code&gt; and &lt;code&gt;consult-line&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Type in some text to find grep results.&lt;/li&gt;
&lt;li&gt;Not necessary: I flipped through the various files that matched with &lt;code&gt;vertico-next-group&lt;/code&gt; and &lt;code&gt;vertico-previous-group&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;embark-export&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Turn on &lt;code&gt;next-error-follow-minor-mode&lt;/code&gt; in the grep buffer with &lt;code&gt;C-c C-f&lt;/code&gt;. This jumps each match as I&amp;hellip;&lt;/li&gt;
&lt;li&gt;&amp;hellip;navigate the grep buffer with &lt;code&gt;M-n&lt;/code&gt; and &lt;code&gt;M-p&lt;/code&gt; (&lt;code&gt;compilation-next-error&lt;/code&gt; and &lt;code&gt;compilation-previous-error&lt;/code&gt;), and move to the next/previous matching file with &lt;code&gt;}&lt;/code&gt; and &lt;code&gt;{&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Note that this is a regular grep buffer, so you can use all your tricks, like wgrep to edit the grep buffer and save changes in all the files.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;bonus-use-embark-actions-like-helm&#34;&gt;BONUS: Use Embark Actions like Helm&lt;/h2&gt;
&lt;p&gt;In the above examples, the available embark actions were displayed in some window in the frame. Embark has multiple &amp;ldquo;prompters&amp;rdquo; listing the preset actions, and with a little elbow grease you can set up something similar to Helm&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop preload=&#34;metadata&#34;&gt;
&lt;source src=&#34;https://i.imgur.com/LH9uYM6.gifv&#34; type=&#34;video/mp4&#34;&gt;
&lt;source src=&#34;https://karthinks.com/img/embark-helm-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;details&gt;
&lt;summary&gt;Play by play&lt;/summary&gt;
&lt;div class=&#34;details&#34;&gt;
&lt;ol&gt;
&lt;li&gt;Run any command involving minibuffer selection, &lt;code&gt;consult-buffer&lt;/code&gt; in the video.&lt;/li&gt;
&lt;li&gt;(Optional) type in something to filter the completions list or select a buffer.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;TAB&lt;/code&gt; to switch to the list of embark actions.&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;TAB&lt;/code&gt; again to switch back to the list of candidates.&lt;/li&gt;
&lt;li&gt;Search for an action by name (in this case &amp;ldquo;kill&amp;rdquo;) to filter the list of actions&lt;/li&gt;
&lt;li&gt;Erase and search for a different action (&amp;ldquo;diff&amp;rdquo;) and choose the &lt;code&gt;diff-buffer-with-file&lt;/code&gt; action&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;RET&lt;/code&gt; to run &lt;code&gt;diff-buffer-with-file&lt;/code&gt; on the selected buffer&lt;/li&gt;
&lt;li&gt;(Optional) Navigate the diff hunks with &lt;code&gt;diff-hunk-next&lt;/code&gt; and &lt;code&gt;diff-hunk-prev&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;(Optional) Fold the diff sections with &lt;code&gt;outline-cycle&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;consult-buffer&lt;/code&gt; again and select a buffer&lt;/li&gt;
&lt;li&gt;Switch to the actions list again with &lt;code&gt;TAB&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;@&lt;/code&gt; to call an action by its keybinding instead of selecting it by name&lt;/li&gt;
&lt;li&gt;Call the embark action for killing a buffer with &lt;code&gt;k&lt;/code&gt; to kill the selected buffer.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Here I switch back and forth between the list of actions and the list of candidates (like in Helm) with &lt;code&gt;C-&amp;lt;tab&amp;gt;&lt;/code&gt;. In the actions list you can either type the action (matched with completing-read), or call the action directly by prepending its keybinding with &lt;code&gt;@&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Elbow grease:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;with-minibuffer-keymap&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;fn&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;minibuffer-with-setup-hook&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;use-local-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;make-composed-keymap&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;keymap&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;current-local-map&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;apply&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;fn&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;args&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defvar&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-completing-read-prompter-map&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;make-sparse-keymap&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;tab&amp;gt;&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;abort-recursive-edit&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#963&#34;&gt;map&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;advice-add&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;embark-completing-read-prompter&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:around&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            (&lt;span style=&#34;color:#963&#34;&gt;with-minibuffer-keymap&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-completing-read-prompter-map&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;vertico-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;tab&amp;gt;&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;embark-act-with-completing-read&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;embark-act-with-completing-read&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;embark-prompter&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;embark-completing-read-prompter&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#963&#34;&gt;embark-indicators&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;embark-minimal-indicator&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;embark-act&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Replace &lt;code&gt;vertico-map&lt;/code&gt; above with your completion system of choice&amp;rsquo;s active minibuffer keymap. The default is &lt;code&gt;minibuffer-local-completion-map&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Remember that unlike with Helm, &lt;em&gt;you&amp;rsquo;re not restricted to these actions&lt;/em&gt; when you use Embark! You can call literally any command that it makes sense to with its keybinding or with &lt;code&gt;M-x&lt;/code&gt; after running &lt;code&gt;embark-act&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;33&#34;&gt;33%&lt;/h2&gt;
&lt;p&gt;That&amp;rsquo;s fifteen useful Embark thingamajigs, and I didn&amp;rsquo;t get to mention &lt;code&gt;embark-become&lt;/code&gt;. Or &lt;code&gt;embark-prefix-help-map&lt;/code&gt;, &lt;code&gt;embark-which-key-prompter&lt;/code&gt;, or Embark&amp;rsquo;s targets and target cycling, or half a dozen more thoughtful features and niceties about Embark. Maybe next time.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ll conclude instead by mentioning the main packages I used in the above demos:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/oantolin/embark&#34;&gt;&lt;code&gt;embark&lt;/code&gt;&lt;/a&gt; by Omar Antolin Camarena, who&amp;rsquo;s been a pleasure to interact with and pester with my requests for features. To add custom actions to the embark keymaps or otherwise customize Embark, I suggest perusing the README. It&amp;rsquo;s as readable and informative as they come.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/minad/consult&#34;&gt;&lt;code&gt;consult&lt;/code&gt;&lt;/a&gt; for its various enhancements to Emacs&amp;rsquo; builtins. &lt;code&gt;consult-locate&lt;/code&gt; and &lt;code&gt;consult-find&lt;/code&gt; (actually &lt;code&gt;consult-fd&lt;/code&gt;) to find files, &lt;code&gt;consult-imenu&lt;/code&gt; for a colorful imenu with grouping and &lt;code&gt;consult-ripgrep&lt;/code&gt; to grep across a directory.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/minad/marginalia&#34;&gt;&lt;code&gt;marginalia&lt;/code&gt;&lt;/a&gt; for the annotations in the minibuffer. Co-maintained by Omar Antolin and Daniel Mendler.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/minad/vertico&#34;&gt;&lt;code&gt;vertico&lt;/code&gt;&lt;/a&gt; as the minibuffer completion interface. Consult, Vertico and Marginalia are all authored by Daniel Mendler, who I&amp;rsquo;m convinced never sleeps. I didn&amp;rsquo;t even mention Corfu.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&#34;https://github.com/oantolin/orderless&#34;&gt;&lt;code&gt;orderless&lt;/code&gt;&lt;/a&gt; completion style, also by Omar Antolin, to match pieces of text against minibuffer candidates independently. Together these five packages form the MOVEC pentagram, a composable enhancement suite that integrates Emacs&amp;rsquo; loosely bound libraries into a modern and cohesive whole.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/karthink/consult-dir&#34;&gt;&lt;code&gt;consult-dir&lt;/code&gt;&lt;/a&gt; to switch directories quickly. I used this multiple times above to navigate to distant directories when in the minibuffer prompt.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/karthink/popper&#34;&gt;&lt;code&gt;popper&lt;/code&gt;&lt;/a&gt; to make &lt;code&gt;embark-collect&lt;/code&gt;, help and other ephemeral buffers behave when they appear on screen.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/abo-abo/ace-window&#34;&gt;&lt;code&gt;ace-window&lt;/code&gt;&lt;/a&gt; by abo-abo, whose dispatch-keys idea in Ace-Window and Avy I promptly ripped off for Popper. If I understand correctly his Ivy-Occur was an early influence on what became Embark-Collect as well.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://git.sr.ht/~willvaughn/emacs-0x0&#34;&gt;&lt;code&gt;0x0&lt;/code&gt;&lt;/a&gt; by William Vaughn. I use this far more often than I thought I would.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally a quick note for Doom Emacs users: Doom ships with Embark out of the box (as of Sep 2021), you don&amp;rsquo;t need to do anything besides looking up the keys for &lt;code&gt;embark-act&lt;/code&gt; and &lt;code&gt;embark-collect&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Despite what these examples suggest, I estimate that I use less than a third of what Embark provides. Even so, in allowing me to change or chain actions at any time, it lets me pilot Emacs by the seat of my pants. A second, unforeseen benefit is that it makes commands and listings that I would never use available in a frictionless way: commands like &lt;code&gt;transpose-regions&lt;/code&gt; and &lt;code&gt;apply-macro-to-region-lines&lt;/code&gt;, or custom dired, ibuffer and package-menu listings that are interactively inaccessible otherwise&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a href=&#34;#fn:4&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;. The ability to quickly whip up such buffers makes knowhing how to use dired or ibuffer pay off several fold. In composing such features seamlessly with minibuffer interaction or with text-regions, Embark acts as a lever to amplify the power of Emacs&amp;rsquo; myriad built in commands and libraries.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Although of course, Helm and Embark both do a good job with their presets.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;To match the inverse of an input string with &lt;code&gt;!&lt;/code&gt;, I used a &lt;a href=&#34;https://github.com/oantolin/orderless#style-dispatchers&#34;&gt;feature of the orderless package&lt;/a&gt; for Emacs.&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;Yes, it&amp;rsquo;s not fully Helm-style since it still uses the minibuffer instead of a buffer to show the candidates/actions. You could use &lt;a href=&#34;https://github.com/minad/vertico#extensions&#34;&gt;vertico-buffer&lt;/a&gt; if that&amp;rsquo;s a sticking point.&amp;#160;&lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34;&gt;
&lt;p&gt;Technically custom package-menu listings are accessible. From the full package listing (&lt;code&gt;M-x list-packages&lt;/code&gt;), you can filter package names by regexp with &lt;code&gt;/ n&lt;/code&gt;.&amp;#160;&lt;a href=&#34;#fnref:4&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>A better yank-pop binding</title>
      <link>https://karthinks.com/software/a-better-yank-pop-binding/</link>
      <pubDate>Sat, 15 May 2021 20:41:00 -0700</pubDate>
      
      <guid>https://karthinks.com/software/a-better-yank-pop-binding/</guid>
      <description>&lt;p&gt;&lt;em&gt;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&amp;rsquo;re using Emacs 27.2 or older, keep reading!&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;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&amp;rsquo;re using these, check out &lt;code&gt;consult-yank-pop&lt;/code&gt; (or equivalent) instead.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A quick tweak to yanking in Emacs: Many completion systems provide a more fully featured version of &lt;code&gt;yank-pop&lt;/code&gt; to yank text from the kill-ring. Ivy/Counsel has &lt;code&gt;counsel-yank&lt;/code&gt;, Helm has &lt;code&gt;helm-show-kill-ring&lt;/code&gt; (I assume) and Consult provides &lt;code&gt;consult-yank&lt;/code&gt;. These show you items in the kill ring and let you select, with completion, which block of text you would like to yank (&lt;em&gt;i.e.&lt;/em&gt; paste) into the buffer.&lt;/p&gt;
&lt;p&gt;Here is Consult&amp;rsquo;s version, previewed in an Embark live-occur buffer:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/consult-yank.png&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;This is quite useful when you know you copied something a while ago and want it inserted in your buffer now, but it involves navigating through a menu for something that could be near-instantaneous.&lt;/p&gt;
&lt;p&gt;In comparison, Emacs&amp;rsquo; built-in &lt;code&gt;yank-pop&lt;/code&gt; command (bound to &lt;code&gt;M-y&lt;/code&gt;) simply cycles through the kill ring, pasting the next item with each invocation, provided you call it after a yank. The idea is that you hit &lt;code&gt;C-y&lt;/code&gt; first, and if this isn&amp;rsquo;t what you intended to paste you can repeatedly type &lt;code&gt;M-y&lt;/code&gt; (or call with a prefix argument) until you see what you want on the screen. This sounds circuitous, but in practice it takes than a second when I want something that&amp;rsquo;s within the top three or four positions in the kill-ring, &lt;em&gt;i.e.&lt;/em&gt; something I copied moments ago.&lt;/p&gt;
&lt;p&gt;This approach is less than optimal in two ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The intended target text to be yanked is buried deep in the kill-ring and requires several presses of &lt;code&gt;M-y&lt;/code&gt;. In this scenario &lt;code&gt;consult-yank&lt;/code&gt; &lt;em&gt;et al&lt;/em&gt; are a faster solution.&lt;/li&gt;
&lt;li&gt;You call &lt;code&gt;yank-pop&lt;/code&gt; without yanking (with &lt;code&gt;C-y&lt;/code&gt;) first. Then &lt;code&gt;yank-pop&lt;/code&gt; complains and does nothing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The shortcomings of both approaches can be fixed with a little change in the behavior of &lt;code&gt;yank-pop&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When called by itself (pressing &lt;code&gt;M-y&lt;/code&gt; without pressing &lt;code&gt;C-y&lt;/code&gt; first), call &lt;code&gt;consult-yank&lt;/code&gt; to get the kill-ring as a menu. You do this when you know the text you copied a while ago is buried somewhere in the ring.&lt;/li&gt;
&lt;li&gt;When called after yanking, run &lt;code&gt;yank-pop&lt;/code&gt; as usual. If you pressed &lt;code&gt;C-y&lt;/code&gt; first, you know the text you want is at or near the top of the kill-ring so Emacs&amp;rsquo; default behavior makes sense.&lt;/li&gt;
&lt;/ul&gt;
&lt;!--listend--&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/consult-yank-or-yank-pop&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Call &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`consult-yank&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;. If called after a yank, call &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`yank-pop&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; instead.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;*p&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;eq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;last-command&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;yank&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;yank-pop&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;consult-yank&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Replace &lt;code&gt;consult-yank&lt;/code&gt; with your completion system equivalent.&lt;/p&gt;
&lt;p&gt;Binding this to &lt;code&gt;M-y&lt;/code&gt; ensures that you don&amp;rsquo;t need to build new muscle-memory, and that yanking now works in a somewhat DWIM fashion. In addition, this has the nice effect of assigning &lt;code&gt;M-[key]&lt;/code&gt; to the advanced version of the &lt;code&gt;C-[key]&lt;/code&gt; command, an irregular but somewhat prevalent aspect of the keybindings in Emacs.&lt;/p&gt;
</description>
    </item><item>
      <title>Bridging Islands in Emacs: re-builder and query-replace-regexp</title>
      <link>https://karthinks.com/software/bridging-islands-in-emacs-1/</link>
      <pubDate>Wed, 28 Apr 2021 05:25:00 -0700</pubDate>
      
      <guid>https://karthinks.com/software/bridging-islands-in-emacs-1/</guid>
      <description>&lt;p&gt;One of the problems with Emacs, especially out of the box, is that its constituents don&amp;rsquo;t communicate with each other as comprehensively as they ought to. This is expected given the &lt;em&gt;bazaar&lt;/em&gt; nature of its development: it&amp;rsquo;s an amalgamation of elisp libraries written by different contributors over decades, few of whom were aware of many of Emacs&amp;rsquo; existing capabilities they could reuse or plug into. I covered a couple of examples of this deficiency in my series on &lt;a href=&#34;https://karthinks.com/software/batteries-included-with-emacs/&#34;&gt;Batteries included with Emacs&lt;/a&gt; (such as the &lt;code&gt;pulse&lt;/code&gt; and &lt;code&gt;view&lt;/code&gt; libraries).&lt;/p&gt;
&lt;p&gt;The experience of using most software teaches us to ignore such shortcomings and annoyances until we don&amp;rsquo;t even notice them any more. When using Emacs, however, it&amp;rsquo;s possible to glance occasionally at a lacuna between its islands that&amp;rsquo;s begging for a bridge. In stark contrast to most software, building arbitrary bridges in elisp is very easy.&lt;/p&gt;
&lt;h2 id=&#34;the-islands-re-builder-and-query-replace-regexp&#34;&gt;The Islands: &lt;code&gt;re-builder&lt;/code&gt; and &lt;code&gt;query-replace-regexp&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;One such example is a simple connection between the built in regexp-builder (&lt;code&gt;re-builder&lt;/code&gt;) library and the &lt;code&gt;*-replace-regexp&lt;/code&gt; functions. &lt;code&gt;re-builder&lt;/code&gt; lets you build a regular expression (&lt;em&gt;henceforth &amp;ldquo;regexp&amp;rdquo;&lt;/em&gt;) with interactive feedback. Text in the main buffer matching the regular expression is highlighted, which is very helpful to catch and correct errors:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/re-builder-demo.png&#34;
         alt=&#34;Figure 1: re-builder: Matches for the current regexp are highlighted in the main buffer.&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 1: &lt;/span&gt;&lt;code&gt;re-builder&lt;/code&gt;: Matches for the current regexp are highlighted in the main buffer.&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;I&amp;rsquo;m reasonably familiar with Emacs&amp;rsquo; flavor of regular expressions, idiosyncratic as it is (compared to PCRE), and thus often forget that &lt;code&gt;re-builder&lt;/code&gt; even exists. On the other hand, &lt;code&gt;query-replace-regexp&lt;/code&gt; (&lt;em&gt;henceforth&lt;/em&gt; &lt;code&gt;qrr&lt;/code&gt;), an everyday tool which does what it says on the tin, &lt;strong&gt;does not show matches&lt;/strong&gt; as you construct the expression to be replaced:&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/qrr-demo.png&#34;
         alt=&#34;Figure 2: qrr: No feedback, no highlights.&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 2: &lt;/span&gt;&lt;code&gt;qrr&lt;/code&gt;: No feedback, no highlights.&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Building regexps and replacing constructed regexps: &lt;strong&gt;these two commands do complementary things and deserve to work together&lt;/strong&gt;. As things stand now, you&amp;rsquo;d have to&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Open &lt;code&gt;re-builder&lt;/code&gt; and construct your regexp.&lt;/li&gt;
&lt;li&gt;Copy it to the kill ring (&lt;code&gt;C-c C-w&lt;/code&gt; by default).&lt;/li&gt;
&lt;li&gt;Quit &lt;code&gt;re-builder&lt;/code&gt; (&lt;code&gt;C-c C-q&lt;/code&gt; by default).&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;query-replace-regexp&lt;/code&gt; (&lt;code&gt;C-M-%&lt;/code&gt; by default).&lt;/li&gt;
&lt;li&gt;Paste the kill (&lt;code&gt;C-y&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Fix newlines and backslashes (if using the &amp;ldquo;read&amp;rdquo; interface to &lt;code&gt;re-builder&lt;/code&gt;, more on this below)&lt;/li&gt;
&lt;li&gt;Type in the replacement string and press &lt;code&gt;RET&lt;/code&gt; to begin the replacements.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Connecting commands through the kill-ring (or clipboard) should be the last resort, not a go-to strategy!&lt;/p&gt;
&lt;h2 id=&#34;a--bridged-functions&#34;&gt;(A)bridged functions&lt;/h2&gt;
&lt;p&gt;Here they are working in concert:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; autoplay controls loop&gt;
&lt;source src=&#34;https://karthinks.com/img/re-builder-integration-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;The idea is this: &lt;code&gt;re-builder&lt;/code&gt; and &lt;code&gt;qrr&lt;/code&gt; are now effectively the same command. Bring up &lt;code&gt;re-builder&lt;/code&gt; using a keybinding (preferably your keybinding for the latter) and build your regexp interactively. Press &lt;code&gt;RET&lt;/code&gt; and &lt;code&gt;re-builder&lt;/code&gt; exits, with its contents as the input to the replacement command.&lt;/p&gt;
&lt;p&gt;This is exactly as many keystrokes as running &lt;code&gt;qrr&lt;/code&gt; or &lt;code&gt;re-builder&lt;/code&gt; for their individual purposes, but now you can use both fully, go from the latter to the former, and you have to remember one fewer command or keybinding!&lt;/p&gt;
&lt;h2 id=&#34;a-combinatorial-expansion-rx-input-to-query-replace-regexp&#34;&gt;A Combinatorial Expansion: &lt;code&gt;rx&lt;/code&gt; input to &lt;code&gt;query-replace-regexp&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;re-builder&lt;/code&gt; has many more advantages than just interactive feedback, and now they all carry over to &lt;code&gt;qrr&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You construct the regexp in a regular buffer, giving you access to the full suite of Emacs command for editing, including your own editing customizations.&lt;/li&gt;
&lt;li&gt;You can navigate between matches interactively (like with &lt;code&gt;isearch&lt;/code&gt;), and thus choose where in the buffer the replacement should begin. This even doubles as a replacement for &lt;code&gt;isearch-forward-regexp&lt;/code&gt; and &lt;code&gt;isearch-backward-regexp&lt;/code&gt;, although these can be configured to preview matches and &lt;code&gt;re-builder&lt;/code&gt; is less crucial.&lt;/li&gt;
&lt;li&gt;You can switch between different modes of regex entry, including the &lt;a href=&#34;https://www.gnu.org/software/emacs/manual/html_node/elisp/Rx-Notation.html&#34;&gt;powerful &lt;code&gt;rx&lt;/code&gt; forms&lt;/a&gt; that &lt;code&gt;qrr&lt;/code&gt; does not allow:&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/rx-demo.png&#34;
         alt=&#34;Figure 3: Regexp specification through a much easier to parse Lisp form.&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;&lt;span class=&#34;figure-number&#34;&gt;Figure 3: &lt;/span&gt;Regexp specification through a much easier to parse Lisp form.&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Pressing &amp;ldquo;RET&amp;rdquo; will run the replacement on the appropriate condensed version of this string:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; autoplay controls loop&gt;
&lt;source src=&#34;https://karthinks.com/img/rx-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;To switch &lt;code&gt;re-builder&lt;/code&gt; to &lt;code&gt;rx&lt;/code&gt; mode, invoke &lt;code&gt;reb-change-syntax&lt;/code&gt; (bound to &lt;code&gt;C-c C-i&lt;/code&gt; by default). This is persistent, you only need to do it once. Note that this is a regular lisp buffer, so you have access to all your lisp editing tools: smartparens/lispy, autocomplete etc.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;re-builder&lt;/code&gt; actually has a third &amp;ldquo;read&amp;rdquo; interface, where you quote regexps like you would in a string in Lisp code. This is useful to test regexps that you plan to place in code.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Thus we now have a route that threads more islands that were originally disjoint: &lt;code&gt;rx&lt;/code&gt;, your Lisp editing suite, &lt;code&gt;re-builder&lt;/code&gt; and &lt;code&gt;qrr&lt;/code&gt;. This is perhaps the lesson here:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Connecting existing libraries in Emacs leads not to a linear growth in its features, but to a combinatorial expansion of its capabilities. This can be significantly more bang for your buck than writing things from scratch, and it will help minimize your cognitive load as the things you already know work in more contexts.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h2 id=&#34;the-actual-bridge&#34;&gt;The Actual Bridge&lt;/h2&gt;
&lt;p&gt;Finally here&amp;rsquo;s the elisp forming a bridge between the two commands instead:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#007020&#34;&gt;defvar&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/re-builder-positions&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Store point and region bounds before calling re-builder&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;advice-add&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;re-builder&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#007020&#34;&gt;:before&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/re-builder-save-state&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Save into &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`my/re-builder-positions&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; the point and region
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;  positions before calling &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`re-builder&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                            (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/re-builder-positions&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;cons&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                        (&lt;span style=&#34;color:#007020&#34;&gt;when&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;region-active-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                          (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;list&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;region-beginning&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                                (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;region-end&lt;/span&gt;)))))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reb-replace-regexp&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delimited&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Run &lt;/span&gt;&lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;`query-replace-regexp&amp;#39;&lt;/span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt; with the contents of re-builder. With
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;  non-nil optional argument DELIMITED, only replace matches
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;  surrounded by word boundaries.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;reb-update-regexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;let*&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;re&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;reb-target-value&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;reb-regexp&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;replacement&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;query-replace-read-to&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         &lt;span style=&#34;color:#963&#34;&gt;re&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;concat&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Query replace&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                 (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;current-prefix-arg&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                     (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;eq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;current-prefix-arg&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;-&lt;/span&gt;) &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; backward&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; word&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                   &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                 &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; regexp&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                 (&lt;span style=&#34;color:#007020&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;with-selected-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reb-target-window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                                       (&lt;span style=&#34;color:#963&#34;&gt;region-active-p&lt;/span&gt;)) &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34; in region&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;pnt&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;car&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/re-builder-positions&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;beg&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;cadr&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/re-builder-positions&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;color:#963&#34;&gt;end&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;caddr&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/re-builder-positions&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;with-selected-window&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reb-target-window&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;goto-char&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pnt&lt;/span&gt;) &lt;span style=&#34;color:#888&#34;&gt;; replace with (goto-char (match-beginning 0)) if you want&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        &lt;span style=&#34;color:#888&#34;&gt;; to control where in the buffer the replacement starts&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        &lt;span style=&#34;color:#888&#34;&gt;; with re-builder&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;my/re-builder-positions&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;reb-quit&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;query-replace-regexp&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;re&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;replacement&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;delimited&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;beg&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;end&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Additionally, I bind this new replace-regexp function (&lt;code&gt;reb-replace-regexp&lt;/code&gt;) to &lt;code&gt;RET&lt;/code&gt; in the &lt;code&gt;re-builder&lt;/code&gt; buffer, and replace &lt;code&gt;qrr&lt;/code&gt; entirely with just &lt;code&gt;re-builder&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reb-mode-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;RET&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;reb-replace-regexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;reb-lisp-mode-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;RET&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;reb-replace-regexp&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;global-set-key&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;C-M-%&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;re-builder&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Very briefly, the code works as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Save the region and point positions into &lt;code&gt;my/re-builder-positions&lt;/code&gt; before invoking &lt;code&gt;re-builder&lt;/code&gt;, since these are lost. This is done by advising the function.&lt;/li&gt;
&lt;li&gt;When you press &lt;code&gt;RET&lt;/code&gt;, quit &lt;code&gt;re-builder&lt;/code&gt; and call &lt;code&gt;qrr&lt;/code&gt; with the built regexp, saved point and region information.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Lastly, if you want to insert a newline in the regexp-builder buffer you can now use &lt;code&gt;C-q C-j&lt;/code&gt;. Entering literal newlines in a regexp definition is rare enough that dedicating &lt;code&gt;RET&lt;/code&gt; to the much more useful &lt;code&gt;qrr&lt;/code&gt; is a no-brainer.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Yes, &lt;a href=&#34;https://github.com/benma/visual-regexp.el&#34;&gt;visual-regexp&lt;/a&gt; exists. But piling on another thousand lines of code here would be like bringing in a mountain of dirt to create a new self-contained island when the existing ones are lacking but a few connecting strings, and have the opportunity to form a denser network of interactions.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>Popper-mode: dealing with window clutter in Emacs</title>
      <link>https://karthinks.com/software/dealing-with-window-clutter-in-emacs/</link>
      <pubDate>Mon, 15 Mar 2021 16:46:00 -0700</pubDate>
      
      <guid>https://karthinks.com/software/dealing-with-window-clutter-in-emacs/</guid>
      <description>&lt;p&gt;Wrote a thing to handle the annoying window flood in Emacs:&lt;/p&gt;
&lt;iframe width=&#34;560&#34; height=&#34;315&#34; src=&#34;https://www.youtube.com/embed/E-xUNlZi3rI&#34; frameborder=&#34;0&#34; allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&#34; allowfullscreen&gt;&lt;/iframe&gt;
&lt;p&gt;Popper-mode was brewing for years as part of my config, I decided to bind it into reasonable shape and submit to MELPA.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/karthink/popper&#34;&gt;Code&lt;/a&gt;, &lt;a href=&#34;https://melpa.org/#/popper&#34;&gt;MELPA&lt;/a&gt;, &lt;a href=&#34;https://www.youtube.com/watch?v=E-xUNlZi3rI&#34;&gt;Extended demo&lt;/a&gt;, &lt;a href=&#34;https://old.reddit.com/r/emacs/comments/m5ibyh/popperel%5Fsummon%5Fand%5Fdismiss%5Fbuffers%5Fas%5Fpopups/&#34;&gt;Reddit thread&lt;/a&gt;&lt;/p&gt;
</description>
    </item><item>
      <title>Persistent project switching in Emacs</title>
      <link>https://karthinks.com/software/persistent-project-switching-in-emacs/</link>
      <pubDate>Mon, 01 Feb 2021 19:11:00 -0800</pubDate>
      
      <guid>https://karthinks.com/software/persistent-project-switching-in-emacs/</guid>
      <description>&lt;p&gt;Just a short note for today, as the super-fast-latex post is still cooking:&lt;/p&gt;
&lt;p&gt;Emacs provides a few mechanisms to manage buffer/window state as a group. There&amp;rsquo;s &lt;code&gt;current-window-configuration&lt;/code&gt; (and its register variants) and &lt;code&gt;desktop-save&lt;/code&gt;, and you can act on groups of buffers by every predicate imaginable in &lt;code&gt;ibuffer&lt;/code&gt;. But the window configurations vaporize when you shut down Emacs, and they don&amp;rsquo;t handle unopened file buffers. &lt;code&gt;desktop-read&lt;/code&gt; is an all-or-nothing affair. Somehow there&amp;rsquo;s no clear way to bookmark and switch to (across Emacs sessions) a collection of files, buffers and windows together as a unit&amp;hellip; or project.&lt;/p&gt;
&lt;p&gt;Spinning up a new Emacs session (it happens) or switching between projects (using &lt;code&gt;project.el&lt;/code&gt;) always annoyed me since I&amp;rsquo;d have to reopen or redisplay the project files I was working on last, then recreate my preferred window configuration and so on. This is especially so since all the ingredients to seamlessly switch projects are present in the Emacs API but haven&amp;rsquo;t been put together.&lt;/p&gt;
&lt;p&gt;Between &lt;code&gt;burly&lt;/code&gt;, &lt;code&gt;bufler&lt;/code&gt;, &lt;code&gt;persp-mode&lt;/code&gt;, &lt;code&gt;projectile&lt;/code&gt; and various tab libraries I&amp;rsquo;m sure this hole is covered, but I&amp;rsquo;m happy with &lt;code&gt;project.el&lt;/code&gt; and wanted something much simpler, so &lt;a href=&#34;https://github.com/karthink/project-x&#34;&gt;I whipped something up&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;project-x&lt;/code&gt; saves my project state (open files, buffers and window configuration) and restores them across Emacs sessions.&lt;/p&gt;
&lt;h2 id=&#34;resuming-project-states&#34;&gt;Resuming project states&lt;/h2&gt;
&lt;p&gt;Resume a saved project state in a fresh Emacs process:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop&gt;
&lt;source src=&#34;https://karthinks.com/img/project-switching-new-emacs.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;In addition to the window configuration, project files saved by &lt;code&gt;project-x&lt;/code&gt; are restored (as highlighted in &lt;code&gt;ibuffer&lt;/code&gt; here.)&lt;/p&gt;
&lt;h2 id=&#34;enhanced-project-switching&#34;&gt;Enhanced project switching&lt;/h2&gt;
&lt;p&gt;When I switch projects I switch window configurations too, opening files if needed:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop&gt;
&lt;source src=&#34;https://karthinks.com/img/project-switching.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;Normally this kind of customization would just live in &lt;code&gt;init.el&lt;/code&gt;, but I decided to package it in case someone&amp;rsquo;s looking for a similar feature. At just a few defuns and a couple of hook functions, it really is much simpler than full fledged workspace management packages for Emacs. It works perfectly within a session, but it only restores files and directory windows across sessions (no shells, help buffers, etc). It&amp;rsquo;ll do for now.&lt;/p&gt;
&lt;p&gt;I also threw in a project backend to recognize non-version controlled projects through the presence of a &amp;ldquo;.project&amp;rdquo; file in the path. I might take it out to make the library do-one-thing-well, or I might add more &lt;code&gt;project.el&lt;/code&gt; enhancements to it instead. The struggle is eternal.&lt;/p&gt;
</description>
    </item><item>
      <title>More batteries included with emacs</title>
      <link>https://karthinks.com/software/more-batteries-included-with-emacs/</link>
      <pubDate>Fri, 11 Dec 2020 19:17:00 -0800</pubDate>
      
      <guid>https://karthinks.com/software/more-batteries-included-with-emacs/</guid>
      <description>&lt;p&gt;Continuing from &lt;a href=&#34;https://karthinks.com/software/batteries-included-with-emacs/&#34;&gt;last time&lt;/a&gt;, here are a dozen more tricks Emacs has up its
sleeve that it&amp;rsquo;s shy about telling you. We continue to chip away at Emacs&#39;
discoverability problem, one demo at a time.&lt;/p&gt;
&lt;p&gt;Same rules as before:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;No packages, &lt;strong&gt;stock Emacs only&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;No steep learning curves. &lt;strong&gt;Learn each feature in under five minutes or bust&lt;/strong&gt;. (Up from two minutes last time.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;No gimmicks&lt;/strong&gt;. No doctor, tetris, snake, dunnet&amp;hellip;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Just the deltas&lt;/strong&gt;. No commonly mentioned packages like flymake, doc-view,
outline-minor-mode, gnus or eww. Nothing that Emacs brings up automatically or
a nonspecific Google search gets you.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Assume a modern Emacs, 26.3+.&lt;/p&gt;
&lt;p&gt;Also, if you&amp;rsquo;re new to Emacs:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Emacs jargon&lt;/th&gt;
&lt;th&gt;Modern parlance&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;M-x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Alt + x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ctrl + x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Frame&lt;/td&gt;
&lt;td&gt;Emacs window&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Window&lt;/td&gt;
&lt;td&gt;split/pane&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Buffer&lt;/td&gt;
&lt;td&gt;Contiguous chunk of text/data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Point&lt;/td&gt;
&lt;td&gt;Cursor position in buffer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Active Region&lt;/td&gt;
&lt;td&gt;Text selection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Region&lt;/td&gt;
&lt;td&gt;Text selection (not highlighted)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Face&lt;/td&gt;
&lt;td&gt;Font, color and display properties&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;(Sorry.)&lt;/p&gt;
&lt;p&gt;Okay? Let&amp;rsquo;s go:&lt;/p&gt;
&lt;h2 id=&#34;strokes--m-x-strokes-help&#34;&gt;Strokes (&lt;code&gt;M-x strokes-help&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Control Emacs with mouse gestures:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; autoplay controls loop&gt;
 &lt;source src=&#34;https://karthinks.com/img/strokes-mode-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;Why are you using Emacs with a mouse, you ask.&lt;/p&gt;
&lt;p&gt;In this demo I used gestures to handle window management:
&lt;img src=&#34;https://karthinks.com/img/strokes-list.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;This is because I lack imagination. Consider: You can bind &lt;em&gt;any&lt;/em&gt; gesture to &lt;em&gt;any&lt;/em&gt; Emacs command.&lt;/p&gt;
&lt;p&gt;The real utility of this feature is when you find yourself going back and forth between different interaction paradigms, like a web browser and Emacs, requiring frequent context switching between full keyboard and keyboard/mouse based interaction.&lt;/p&gt;
&lt;p&gt;Want to &lt;code&gt;org-capture&lt;/code&gt; or &lt;code&gt;org-roam-insert&lt;/code&gt; something from your browser? Want to quickly recompile a TeX document while you&amp;rsquo;re busy mousing through the corresponding PDF? Need to tweak some markup in your document while you work on graphics in Inkscape? &lt;a href=&#34;http://xenodium.com/emacs-clone-git-repo-from-clipboard/&#34;&gt;Clone a repository you found online&lt;/a&gt;?  &lt;code&gt;strokes-mode&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The second use case for Strokes is to control Emacs during reading-centric activities, like email or RSS. Star or delete messages, pause or skip music tracks (with some elisp around &lt;code&gt;playerctl&lt;/code&gt;), navigate info nodes, or cycle through Elfeed searches.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;M-x strokes-help&lt;/code&gt; will get you started. As with most things Emacs, there&amp;rsquo;s more to the library than meets the eye, like support for multi-part strokes you can use to edit documents in Chinese. The buffer showing the gesture being traced is for demo purposes only, you can customize &lt;code&gt;strokes-use-strokes-buffer&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;global-set-key&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;&amp;lt;down-mouse-3&amp;gt;&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;strokes-do-stroke&lt;/span&gt;) &lt;span style=&#34;color:#888&#34;&gt;; Draw strokes with RMB&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;strokes-use-strokes-buffer&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;) &lt;span style=&#34;color:#888&#34;&gt;; Don&amp;#39;t draw strokes to the screen&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h2 id=&#34;minibuffer-completion-styles--c-h-v-completion-styles&#34;&gt;Minibuffer completion styles (&lt;code&gt;C-h v completion-styles&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;The default minibuffer experience is annoying enough to send anyone into the
arms of &lt;code&gt;ido&lt;/code&gt;, &lt;code&gt;ivy&lt;/code&gt; or &lt;code&gt;helm&lt;/code&gt;. But Emacs does a lot better in the
tab-completions department than it lets on. The minibuffer can match by
substrings, regexps, initials and even (as of Emacs 27+) fuzzily, and it can do
all of them at once if you don&amp;rsquo;t mind a giant pile of matches.&lt;/p&gt;
&lt;p&gt;You can do worse than&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;completion-styles&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;initials&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;partial-completion&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;flex&lt;/span&gt;)) &lt;span style=&#34;color:#888&#34;&gt;; &amp;gt; Emacs 27.1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;completion-cycle-threshold&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;10&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now &lt;code&gt;M-x ohba&lt;/code&gt; tab-expands to &lt;code&gt;org-hide-block-all&lt;/code&gt;, &lt;code&gt;M-x qrr&lt;/code&gt; to
&lt;code&gt;query-replace-regexp&lt;/code&gt; and so on, allowing you to tab-cycle between up to ten
completions. Use tab to match file names fuzzily and expand short paths
(&lt;code&gt;~/.l/sh/g&lt;/code&gt;) to long ones (&lt;code&gt;~/.local/share/git&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Stretching the five minute rule a bit: You probably want different matching
rules for different categories, though. Flex matching on extended commands
(&lt;code&gt;M-x&lt;/code&gt;) can dump hundreds of irrelevant matches on short input, for instance.
You can customize &lt;code&gt;completion-category-overrides&lt;/code&gt; to set the matching style by
the category being completed.&lt;/p&gt;
&lt;p&gt;Finally, note that completion styles dictate how a candidate pool is found.
Incremental completion systems like &lt;code&gt;ido&lt;/code&gt; specify how found candidates are
displayed and chosen. These are orthogonal functions, so any set of completion
styles should work with any completion system. Unfortunately this isn&amp;rsquo;t the
case, because &lt;code&gt;ivy&lt;/code&gt; and &lt;code&gt;helm&lt;/code&gt; are off doing their own thing. Emacs&amp;rsquo; built in
completion styles do work with &lt;code&gt;icomplete&lt;/code&gt;, &lt;code&gt;ido&lt;/code&gt; and possibly &lt;code&gt;selectrum&lt;/code&gt;
though.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;fake-ido--m-x-fido-mode&#34;&gt;Fake Ido ( &lt;code&gt;M-x fido-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Improves the other half of the default minibuffer experience: interacting with
selection candidates. Navigating to, from and inside the default completions
buffer takes too many key presses. &lt;code&gt;fido-mode&lt;/code&gt; brings &lt;code&gt;ido&lt;/code&gt; like selection to
every command in Emacs that uses &lt;code&gt;completing-read&lt;/code&gt;, which is most of them.&lt;/p&gt;
&lt;p&gt;Of course, &lt;code&gt;ido&lt;/code&gt; is also built in, but you know all about it. It also takes some
effort to get ido to work with every command. &lt;code&gt;fido-mode&lt;/code&gt; is set-and-forget, but
it&amp;rsquo;s Emacs 27+ only.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;easier-rectangle-editing--m-x-cua-selection-mode&#34;&gt;Easier rectangle editing (&lt;code&gt;M-x cua-selection-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; autoplay controls loop&gt;
 &lt;source src=&#34;https://karthinks.com/img/cua-selection-mode-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;The default rectangle commands in Emacs (&lt;code&gt;C-x r&lt;/code&gt; map) leave a little to be
desired in terms of interactivity. Emacs has fully featured rectangle editing,
but it&amp;rsquo;s presented in an odd sort of way, as a subfeature of Common User Access.
It&amp;rsquo;s pretty nifty:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; autoplay controls loop&gt;
 &lt;source src=&#34;https://karthinks.com/img/cua-selection-mode-demo-2.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;Start or clear a rectangle selection with &lt;code&gt;C-&amp;lt;return&amp;gt;&lt;/code&gt;. Cycle through rectangle
corners with &lt;code&gt;&amp;lt;return&amp;gt;&lt;/code&gt;. Yes, you&amp;rsquo;ll need to rebind it if you use Org or ESS.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s a very handy feature, but note that &lt;code&gt;cua-selection-mode&lt;/code&gt; does &lt;em&gt;not&lt;/em&gt; mesh
well with undo. If you use &lt;code&gt;undo-tree&lt;/code&gt;, it can lock up trying to undo a
&lt;code&gt;cua-selection&lt;/code&gt; edit.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;speedbar--m-x-speedbar&#34;&gt;speedbar (&lt;code&gt;M-x speedbar&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;A file explorer and much, much more in Emacs. If you need the Neotree or
dired-sidebar package to do anything in Emacs, check out speedbar.&lt;/p&gt;
&lt;p&gt;Speedbar pops up a side frame that looks like a file browser, which it is. But
it also integrates with &lt;code&gt;imenu&lt;/code&gt; to show you headings/tags inside files, and with
&lt;code&gt;vc&lt;/code&gt; to show you the status of your files:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/speedbar-tags-demo.png&#34;
         alt=&#34;Figure 1: Speedbar showing tags and VC status&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;Figure 1: Speedbar showing tags and VC status&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/speedbar-org-demo.png&#34;
         alt=&#34;Figure 2: Speedbar showing headings in an org file&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;Figure 2: Speedbar showing headings in an org file&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;From inside speedbar you can act on files with (frustratingly, &lt;em&gt;almost&lt;/em&gt;
dired-like) keybindings. Most regular commands run from speedbar will be run in
the associated buffer.&lt;/p&gt;
&lt;p&gt;It tracks the active buffer to show you appropriate hierarchical information.
Here I moved point into &lt;code&gt;info&lt;/code&gt; and &lt;code&gt;latex-mode&lt;/code&gt; buffers:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://karthinks.com/img/speedbar-info-demo.png&#34; alt=&#34;&#34;&gt;
&lt;img src=&#34;https://karthinks.com/img/speedbar-latex-demo.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Perhaps you&amp;rsquo;d like a list of your buffers instead. Switch between buffer and
file view with &lt;code&gt;b&lt;/code&gt; / &lt;code&gt;f&lt;/code&gt;. (You can expand a buffer entry for tag/headings.)&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/speedbar-buffers-demo.png&#34;/&gt;
&lt;/figure&gt;

&lt;hr&gt;
&lt;h2 id=&#34;orgtbl-minor-mode--m-x-orgtbl-mode&#34;&gt;Orgtbl minor mode (&lt;code&gt;M-x orgtbl-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Org-mode is its own thing, a full fledged notetaking, publishing,
literate-programming, task tracking application with a growing ecosystem that&amp;rsquo;s
parallel to Emacs&amp;rsquo;.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;But it does provide a handy tool that&amp;rsquo;s useful in any mode: Making tables. If
you&amp;rsquo;re one of the dozen Emacs users who haven&amp;rsquo;t hopped on the Org train, this
one&amp;rsquo;s for you.&lt;/p&gt;
&lt;p&gt;With &lt;code&gt;orgtbl-mode&lt;/code&gt;, you can make tables by starting a line with the pipe
character and hitting tab to make a field&amp;ndash;like you would in &lt;code&gt;org-mode&lt;/code&gt;&amp;ndash;but
&lt;strong&gt;without getting in the way of your major mode&lt;/strong&gt;. You can just leave it on and
get on with your work.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; autoplay controls loop&gt;
 &lt;source src=&#34;https://karthinks.com/img/orgtbl-mode-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;Here I table some parameters in matlab-mode as a comment, but even more lazily
than prescribed above by calling &lt;code&gt;orgtbl-create-or-convert-from-region&lt;/code&gt;
(&lt;code&gt;C-c |&lt;/code&gt;) on some data.&lt;/p&gt;
&lt;p&gt;With some work, you can export the table in place to html or LaTeX, but setting
this up would break the five minute rule. You can also use the table as a
spreadsheet, which is beyond me.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;regexp-builder--m-x-re-builder&#34;&gt;Regexp builder (&lt;code&gt;M-x re-builder&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;&lt;img src=&#34;https://karthinks.com/img/re-builder-demo.png&#34; alt=&#34;&#34;&gt;
Emacs&amp;rsquo; regular expressions syntax can be idiosyncratic if you&amp;rsquo;re used to &lt;a href=&#34;https://www.pcre.org/&#34;&gt;PCRE&lt;/a&gt;. Are unescaped parens matched literally or do they act as capture groups? Does + need to be escaped to match multiple occurrences of a character? How do I match whitespace again?&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;I can never remember. For regularly confused users like me there is &lt;code&gt;re-builder&lt;/code&gt;. Build your regular expressions interactively, one character at a time. Save it to the kill ring for later use. This is a godsend when testing regexes for non-interactive use, like when writing elisp helpers.&lt;/p&gt;
&lt;p&gt;A cleaner approach to regular expressions in Emacs, as most package maintainers will tell you, is to use the &lt;code&gt;rx&lt;/code&gt; library instead. &lt;code&gt;rx&lt;/code&gt; translates regular expressions in sexp form to a regexp string:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;rx&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;and&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;(&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;use-package&amp;#34;&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;require&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;space&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         (&lt;span style=&#34;color:#963&#34;&gt;group&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;syntax&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;symbol&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(\(?:\(?:requir\|use-packag\)e\)[[:space:]]+\(\s_\)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;hr&gt;
&lt;h2 id=&#34;future-history--m-n-in-prompts&#34;&gt;Future history (&lt;code&gt;M-n&lt;/code&gt; in prompts)&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;M-p&lt;/code&gt; and &lt;code&gt;M-n&lt;/code&gt; cycle through history items in minibuffer prompts. So what happens when you press &lt;code&gt;M-n&lt;/code&gt; when you&amp;rsquo;re at a blank prompt?&lt;/p&gt;
&lt;p&gt;Emacs tries to Do What You Mean. If the cursor is over a file name, for instance, &lt;code&gt;M-n&lt;/code&gt; at the find-file prompt inserts the file path at point into the minibuffer. From the manual:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The “future history” for file names includes several possible alternatives you may find useful, such as the file name or the URL at point in the current buffer. The defaults put into the “future history” in this case are controlled by the functions mentioned in the value of the option file-name-at-point-functions.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Like the DWIM behavior of Emacs commands on regions, many utilities account for &lt;code&gt;future-history&lt;/code&gt;. You can usually drag whatever relevant object point is at into the minibuffer prompt with &lt;code&gt;M-n&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;transpose-regions--m-x-transpose-region&#34;&gt;Transpose regions (&lt;code&gt;M-x transpose-region&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Lurking in the bevy of transposition commands in Emacs is &lt;code&gt;transpose-region&lt;/code&gt;,
which does what it says on the tin&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; autoplay controls loop&gt;
 &lt;source src=&#34;https://karthinks.com/img/transpose-regions-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;Exchange any two non-overlapping regions in a buffer. You&amp;rsquo;ll need to assign a
keybinding though.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;global-set-key&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;C-x C-M-t&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;transpose-regions&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Also of note: &lt;code&gt;transpose-paragraphs&lt;/code&gt;, which sounds like a text-mode utility but
works pretty well on adjacent blocks of code.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;view-mode-again--m-x-view-mode&#34;&gt;View mode, again (&lt;code&gt;M-x view-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;View-mode got an airing &lt;a href=&#34;https://karthinks.com/software/batteries-included-with-emacs/#view-mode--m-x-view-mode&#34;&gt;the last time around&lt;/a&gt; but I like it so much I will repeat
myself. &lt;strong&gt;Turn Emacs into a pager.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;By default, pressing &lt;code&gt;v&lt;/code&gt; in dired will open a file in view-mode. You can dismiss
the window and buffer with &lt;code&gt;q&lt;/code&gt;, so regular buffers can essentially function as
info or help buffers do with &lt;code&gt;View&lt;/code&gt;. You can scroll or isearch without pressing
any modifier keys, and all advanced navigation commands (like xref) are still
available, so this is the perfect way to explore a code repository.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;newsticker--m-x-newsticker-treeview&#34;&gt;Newsticker  (&lt;code&gt;M-x newsticker-treeview&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;AKA I&amp;rsquo;m not brave enough to use GNUS!
&lt;img src=&#34;https://karthinks.com/img/newsticker-demo.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Yes, Emacs has a traditionally styled RSS reader built in. You can organize
feeds by folders, peruse with one button, the usual. This is the only feature in
this list I no longer use, because Elfeed&amp;rsquo;s design syncs with my brain much
better. That said, Newsticker is excellent for following high volume feeds like
subreddits since it doesn&amp;rsquo;t maintain a database:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;You can mark [an item] as “old” when you have read it or – if you want to keep
it – you can mark it as “immortal”. You can do that manually and you can define
filters which do that automatically, see below. When a headline has vanished
from the feed it is automatically marked as “obsolete” unless it has the status
“immortal”. “Obsolete” headlines get removed automatically after a certain time.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Another advantage over GNUS is that it needs very little configuration&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a href=&#34;#fn:4&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;. I used
it for a while and never read the info page. &lt;code&gt;newsticker-add-url&lt;/code&gt; to add a
source (atom/RSS feed), &lt;code&gt;newsticker-treeview&lt;/code&gt; to browse.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;semantic-and-semantic-decorators--m-x-semantic-decoration-mode&#34;&gt;Semantic and Semantic decorators (&lt;code&gt;M-x semantic-decoration-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Get Emacs to decorate your python code:
&lt;img src=&#34;https://karthinks.com/img/semantic-decorators-demo.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Doing this is like pointing a firehose at a matchstick: Semantic is &lt;a href=&#34;http://alexott.net/en/writings/emacs-devenv/EmacsCedet.html#sec5&#34;&gt;part of
CEDET&lt;/a&gt;, a large collection of (mostly) built-in tools to try to turn Emacs into a
full-fledged IDE. It&amp;hellip; doesn&amp;rsquo;t work great on a code base of serious size or
import, but it&amp;rsquo;s good at analyzing exploratory code/small utilities.&lt;/p&gt;
&lt;p&gt;CEDET is written as plumbing, and unless you&amp;rsquo;re writing a package you probably
shouldn&amp;rsquo;t need to do anything beyond turning on/off minor modes to use it.&lt;/p&gt;
&lt;p&gt;Ultimately Semantic is inadequate on account of the XY problem. LSP handles
everything it&amp;rsquo;s supposed to do and does it better, but Semantic is
built-in and there if you just want some code-awareness in your Emacs.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;next-time&#34;&gt;Next Time&lt;/h2&gt;
&lt;p&gt;This was my attempt at covering built-in features of Emacs I use regularly that
I don&amp;rsquo;t see being talked about much. There are many more, like &lt;code&gt;project&lt;/code&gt;,
&lt;code&gt;flymake&lt;/code&gt; and &lt;code&gt;outline-minor-mode&lt;/code&gt; that have received a surge of
interest in recent times&lt;sup id=&#34;fnref:5&#34;&gt;&lt;a href=&#34;#fn:5&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;5&lt;/a&gt;&lt;/sup&gt;. There are also features I know
of that aren&amp;rsquo;t talked about much, like &lt;code&gt;ede-mode&lt;/code&gt;, &lt;code&gt;2C-two-columns&lt;/code&gt;, &lt;code&gt;skeleton&lt;/code&gt;
and &lt;code&gt;tempo&lt;/code&gt;. I don&amp;rsquo;t bring these up since I don&amp;rsquo;t have any experience with them.&lt;/p&gt;
&lt;p&gt;So this concludes my list.&lt;/p&gt;
&lt;p&gt;Something entirely different next time: Typing equations in Emacs faster than you
can write on paper.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;I hear the next major version will make you pancakes.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;Matched literally, no and &amp;ldquo;\s-&amp;rdquo; respectively.&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;Vim users might be familiar with the popular &lt;code&gt;exchange&lt;/code&gt; (&lt;code&gt;evil-exchange&lt;/code&gt;) plugin that exchanges regions of text.&amp;#160;&lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34;&gt;
&lt;p&gt;Which doesn&amp;rsquo;t mean it&amp;rsquo;s not there. Let&amp;rsquo;s say I resisted the urge to customize Newsticker because I didn&amp;rsquo;t want to waste time while I was busy wasting time.&amp;#160;&lt;a href=&#34;#fnref:4&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:5&#34;&gt;
&lt;p&gt;Interest from developers and from users. Don&amp;rsquo;t you love that the distinction is fuzzy in Emacs land?&amp;#160;&lt;a href=&#34;#fnref:5&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>Batteries included with Emacs</title>
      <link>https://karthinks.com/software/batteries-included-with-emacs/</link>
      <pubDate>Tue, 17 Nov 2020 20:50:00 -0800</pubDate>
      
      <guid>https://karthinks.com/software/batteries-included-with-emacs/</guid>
      <description>&lt;p&gt;Emacs has a reputation for being borderline unusable out of the box, of being
bloated but somehow surprisingly bare.&lt;/p&gt;
&lt;p&gt;This is largely a discoverability problem&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;. The solution
the Internet has settled on seems to be &amp;ldquo;Emacs distributions&amp;rdquo; 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&amp;rsquo;s not for me, this does work
great &lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;, and many of these packages will probably make
their way into the default Emacs experience in due time.&lt;/p&gt;
&lt;p&gt;But while modern features like built-in LSP support, faster syntax highlighting
(through tree-sitter) and ligature support are still being debated in the
development mailing list, the long running, slow moving train of Emacs has
picked up many interesting passengers.&lt;/p&gt;
&lt;p&gt;Emacs as shipped does a lot more than meets the eye, and external package
functionality often partially replicates built in behavior.&lt;/p&gt;
&lt;p&gt;Here is a list of useful features in emacs I use regularly that I don&amp;rsquo;t see
mentioned or recommended often online. Guidelines I used to populate this list:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No packages, &lt;strong&gt;stock Emacs only&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;No steep learning curves. &lt;strong&gt;Learn each feature in under two minutes or bust&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No gimmicks&lt;/strong&gt;. No doctor, tetris, snake, dunnet, zone or butterfly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Just the deltas&lt;/strong&gt;. No commonly mentioned packages like flymake, doc-view,
outline-minor-mode or eww/w3m. Nothing that Emacs brings up automatically or a
nonspecific Google search gets you.&lt;/li&gt;
&lt;li&gt;Assume a modern Emacs, 26.3+.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The list is written in the language of Emacs&amp;rsquo; conventions. If you&amp;rsquo;re new to
Emacs, here&amp;rsquo;s some extra cognitive load for you:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Emacs jargon&lt;/th&gt;
&lt;th&gt;Modern parlance&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;M-x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Alt + x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;C-x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ctrl + x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Frame&lt;/td&gt;
&lt;td&gt;Emacs window&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Window&lt;/td&gt;
&lt;td&gt;split/pane&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Buffer&lt;/td&gt;
&lt;td&gt;Contiguous chunk of text/data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Point&lt;/td&gt;
&lt;td&gt;Cursor position in a buffer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Active Region&lt;/td&gt;
&lt;td&gt;Text selection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Region&lt;/td&gt;
&lt;td&gt;Text selection (not highlighted)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Face&lt;/td&gt;
&lt;td&gt;Font, color and display properties&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;OK? Let&amp;rsquo;s go.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;artist-mode--m-x-artist-mode&#34;&gt;Artist mode (&lt;code&gt;M-x artist-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Turn Emacs into an Ascii art based paint program. Draw (poly-)lines, rectangles
and ellipses. Fill or spray.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop&gt;
 &lt;source src=&#34;https://karthinks.com/img/artist-mode-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;I&amp;rsquo;m not much of an (ascii) artist, but I do use &lt;code&gt;artist-mode&lt;/code&gt; to draw boxes when
writing documentation or READMEs.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;pulse--pulse-dot-el&#34;&gt;Pulse (&lt;code&gt;pulse.el&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;The included pulse library provides functions to flash a region of text. The
most useful general application is to flash the line the cursor is on as a
navigational aid or accessibility feature.&lt;/p&gt;
&lt;video style=&#34;center&#34; width=&#34;700&#34; controls loop&gt;
 &lt;source src=&#34;https://karthinks.com/img/pulse-demo.mp4&#34; type=&#34;video/mp4&#34;&gt;
 Your browser does not support the video tag.
&lt;/video&gt;
&lt;p&gt;As is the annoying case with many things Emacs though, it provides all the
ingredients and lights the flame but leaves the cooking to you. Here&amp;rsquo;s a simple
recipe:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pulse-line&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;rest&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;_&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Pulse the current line.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;pulse-momentary-highlight-one-line&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;point&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;dolist&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;command&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#963&#34;&gt;scroll-up-command&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;scroll-down-command&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                   &lt;span style=&#34;color:#963&#34;&gt;recenter-top-bottom&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;other-window&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;advice-add&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;command&lt;/span&gt; &lt;span style=&#34;color:#007020&#34;&gt;:after&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;pulse-line&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Modify as needed. There&amp;rsquo;s more than one external package
(&lt;a href=&#34;https://github.com/Malabarba/beacon&#34;&gt;beacon&lt;/a&gt;) that does this and more, but
&lt;code&gt;pulse&lt;/code&gt; is just fine.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;undo-in-region--c&#34;&gt;Undo in region (&lt;code&gt;C-/&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Limit your undoing to the active region:&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/undo-in-region-demo.gif&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;There&amp;rsquo;s nothing to set up or run here. This is the default behavior of undo in
Emacs.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;follow-mode--m-x-follow-mode&#34;&gt;Follow mode (&lt;code&gt;M-x follow-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Most monitors are much wider than they are tall. Most text files are much longer
than they are wide. That&amp;rsquo;s a problem.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;follow-mode&lt;/code&gt; shows a contiguous buffer paginated across multiple windows. The
cursor flows from one window to the next.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/follow-mode-demo.gif&#34;/&gt;
&lt;/figure&gt;

&lt;hr&gt;
&lt;h2 id=&#34;selective-display--c-x&#34;&gt;Selective display (&lt;code&gt;C-x $&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;If you code with rigid indentation, you can get a quick overview of your
document with &lt;code&gt;set-selective-display&lt;/code&gt;. No mucking around with folding,
&lt;code&gt;outline-&lt;/code&gt; or &lt;code&gt;hs-minor-mode&lt;/code&gt; regexps.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/set-selective-display-demo.gif&#34;/&gt;
&lt;/figure&gt;

&lt;p&gt;Call the command with the prefix argument set to the column to hide. Call
without a prefix argument to disable.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;pretty-symbols--m-x-prettify-symbols-mode&#34;&gt;Pretty symbols (&lt;code&gt;M-x prettify-symbols-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;This one&amp;rsquo;s mainly for LaTeX users. Display unicode versions of math operators,
greek symbols and more. &lt;code&gt;M-x prettify-symbols-mode&lt;/code&gt; in a TeX buffer.&lt;/p&gt;
&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/prettify-symbols-test.png&#34;
         alt=&#34;Figure 1: Before and after enabling prettify-symbols-mode&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;Figure 1: Before and after enabling &lt;code&gt;prettify-symbols-mode&lt;/code&gt;&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;The equivalent in &lt;code&gt;org-mode&lt;/code&gt; is &lt;code&gt;M-x org-toggle-pretty-entities&lt;/code&gt;. Other major
modes will have to define the replacements explicitly to get this behavior.
Example with Python:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;add-hook&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;python-mode-hook&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;   (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;mapc&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;pair&lt;/span&gt;) (&lt;span style=&#34;color:#007020&#34;&gt;push&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;pair&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;prettify-symbols-alist&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;         &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;(&lt;span style=&#34;color:#888&#34;&gt;;; Syntax&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;def&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;      &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x2131&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;not&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;      &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x2757&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;in&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;       &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x2208&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;not in&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;   &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x2209&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;return&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;   &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x27fc&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;yield&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;    &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x27fb&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;for&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;      &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x2200&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#888&#34;&gt;;; Base Types&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;int&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;      &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x2124&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;float&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;    &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x211d&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;str&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;      &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x1d54a&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;True&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;     &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x1d54b&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;False&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;    &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x1d53d&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           &lt;span style=&#34;color:#888&#34;&gt;;; Mypy&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Dict&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;     &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x1d507&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;List&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;     &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x2112&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Tuple&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;    &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x2a02&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Set&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;      &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x2126&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Iterable&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x1d50a&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Any&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;      &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x2754&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;           (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Union&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt;    &lt;span style=&#34;color:#058;font-weight:bold&#34;&gt;#x22c3&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/prettify-symbols-python-before.png&#34;/&gt;
&lt;/figure&gt;

&lt;figure&gt;&lt;img src=&#34;https://karthinks.com/img/prettify-symbols-python-after.png&#34;
         alt=&#34;Figure 2: A python-mode buffer before and after enabling prettify-symbols-mode&#34;/&gt;&lt;figcaption&gt;
            &lt;p&gt;Figure 2: A &lt;code&gt;python-mode&lt;/code&gt; buffer before and after enabling &lt;code&gt;prettify-symbols-mode&lt;/code&gt;&lt;/p&gt;
        &lt;/figcaption&gt;
&lt;/figure&gt;

&lt;hr&gt;
&lt;h2 id=&#34;view-mode--m-x-view-mode&#34;&gt;View mode (&lt;code&gt;M-x view-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Provide pager-like keybindings. Makes navigating read-only buffers a breeze.
Move down and up with &lt;code&gt;SPC&lt;/code&gt; and &lt;code&gt;delete&lt;/code&gt; (backspace) or &lt;code&gt;S-SPC&lt;/code&gt;, half a page
down and up with &lt;code&gt;d&lt;/code&gt; and &lt;code&gt;u&lt;/code&gt;, and isearch with &lt;code&gt;s&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is my preferred way to read code or documents as I can avoid chorded
commands. Note that &lt;code&gt;evil-mode&lt;/code&gt; doesn&amp;rsquo;t help here either, since paging is bound
to &lt;code&gt;C-u/d/f/b&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;del&gt;To that end I just hook this into &lt;code&gt;read-only-mode&lt;/code&gt;.&lt;/del&gt; Prolific emacser &lt;a href=&#34;https://old.reddit.com/r/emacs/comments/jwhr6g/batteries%5Fincluded%5Fwith%5Femacs/gct12vp/&#34;&gt;Omar
Antolin Camarena&lt;/a&gt; points out a built-in way to use &lt;code&gt;view-mode&lt;/code&gt; in all read-only
buffers, including ones you set read-only with &lt;code&gt;C-x C-q&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;view-read-only&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;t&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is my favorite feature of the bunch, considering how much time I spend in
Emacs reading things.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;cycle-spacing--m-spc&#34;&gt;Cycle-spacing (&lt;code&gt;M-SPC&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;cycle-spacing&lt;/code&gt; command is more versatile than it appears. By default, it
cycles between deleting all whitespace around cursor but one, deleting all
whitespace and restoring whitespace. But with a negative argument, it deletes
all blank lines around the cursor. (Calling it with a negative argument is fast:
Hold down Meta and hit minus and space in sequence.)&lt;/p&gt;
&lt;p&gt;Put together, it&amp;rsquo;s doing the job of (almost) three older commands:
&lt;code&gt;just-one-space&lt;/code&gt;, &lt;code&gt;delete-horizontal-space&lt;/code&gt; and
&lt;code&gt;delete-blank-lines&lt;/code&gt;!&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt; This opens up the
bindings &lt;code&gt;C-x C-o&lt;/code&gt; and &lt;code&gt;M-\&lt;/code&gt; for more useful functions.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;indirect-buffers--m-x-make-indirect-buffer&#34;&gt;Indirect buffers (&lt;code&gt;M-x make-indirect-buffer&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;One buffer. Two windows. Two states.&lt;/p&gt;
&lt;p&gt;This one&amp;rsquo;s for outline/org users. Do you want to see an overview of your
document &lt;em&gt;and&lt;/em&gt; the section you&amp;rsquo;re working on? &lt;code&gt;M-x make-indirect-buffer&lt;/code&gt; or &lt;code&gt;M-x clone-indirect-buffer&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Here I clone an org buffer and narrow the original to get a makeshift TOC:
&lt;img src=&#34;https://karthinks.com/img/indirect-buffer-demo.gif&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;At this point we&amp;rsquo;re a few lines of elisp away from writing a &lt;code&gt;toc-minor-mode&lt;/code&gt;
for org files!&lt;/p&gt;
&lt;p&gt;But the possibilities are much larger, because as the manual puts it:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The text of the indirect buffer is always identical to the text of its base
buffer; changes made by editing either one are visible immediately in the other.
But in all other respects, the indirect buffer and its base buffer are
completely separate. They can have different names, different values of point,
different narrowing, different markers, different major modes, and different
local variables.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h2 id=&#34;html-fontify--m-x-htmlfontify-buffer&#34;&gt;Html-fontify (&lt;code&gt;M-x htmlfontify-buffer&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;Reproduce the look of your emacs buffer as a html file with CSS. This is either
extremely useful or useless to you!&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://karthinks.com/share/htmlfontify-demo.html&#34;&gt;Here&lt;/a&gt; is the html-fontified version of the
source file of this write-up.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;dwim-commands--upcase-downcase-and-more&#34;&gt;DWIM commands (upcase, downcase  and more&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a href=&#34;#fn:4&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;)&lt;/h2&gt;
&lt;p&gt;Modern versions of Emacs provide Do-What-I-Mean versions of various editing
commands: They act on the region when the region is active, and on an
appropriate semantic unit otherwise. Replace &lt;code&gt;upcase-word&lt;/code&gt; and &lt;code&gt;downcase-word&lt;/code&gt;
with &lt;code&gt;upcase-dwim&lt;/code&gt; and &lt;code&gt;downcase-dwim&lt;/code&gt; respectively, and you can safely eject
the bindings for &lt;code&gt;upcase-region&lt;/code&gt; and &lt;code&gt;downcase-region&lt;/code&gt;.&lt;sup id=&#34;fnref:5&#34;&gt;&lt;a href=&#34;#fn:5&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;5&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;global-set-key&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-u&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;upcase-dwim&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;global-set-key&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-l&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;downcase-dwim&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#963&#34;&gt;global-set-key&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-c&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;capitalize-dwim&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;DWIM is standard behavior for emacs commands even when it doesn&amp;rsquo;t say that in
the name. &lt;code&gt;count-words&lt;/code&gt;, &lt;code&gt;query-replace&lt;/code&gt;, the list goes on. Check to see if your
frequently used commands DWYM.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;unit-conversion-in-calc--m-x-calc&#34;&gt;Unit conversion in calc (&lt;code&gt;M-x calc&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;It&amp;rsquo;s &lt;code&gt;u c&lt;/code&gt;. And &lt;code&gt;&#39;&lt;/code&gt; (quote) for algebraic entry: &lt;img src=&#34;https://karthinks.com/img/calc-units-demo.gif&#34; alt=&#34;&#34;&gt;
&lt;code&gt;calc&lt;/code&gt; does a lot more with units. You can simplify, define new unit conversions
and more. Hit &lt;code&gt;u ?&lt;/code&gt; to see your options.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;symbolic-computation-in-calc--m-x-calc&#34;&gt;Symbolic computation in calc (&lt;code&gt;M-x calc&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;re skirting the &amp;ldquo;&lt;strong&gt;learn each feature in under two minutes or bust&lt;/strong&gt;&amp;rdquo; rule with
this one, as it deserves its own write-up, or a perusal of the manual. The
general interaction paradigm is simple, though.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s find a Taylor expansion of the integral of the error function:
&lt;img src=&#34;https://karthinks.com/img/calc-symbolic-demo.gif&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Access algebraic routines (root finding, symbolic manipulation) in calc under
the &lt;code&gt;a&lt;/code&gt; prefix. Indefinite integration is &lt;code&gt;a i&lt;/code&gt;, differentiation is &lt;code&gt;a d&lt;/code&gt;,
solving algebraic equations is &lt;code&gt;a S&lt;/code&gt; and so on. (Hit &lt;code&gt;a ?&lt;/code&gt;)&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;scroll-lock-mode--scrollock&#34;&gt;Scroll lock mode (&lt;code&gt;scrollock&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;What it says on the tin. Move the buffer instead of the cursor when navigating.
Just press the scroll lock key or &lt;code&gt;M-x scroll-lock-mode&lt;/code&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;tabs--m-x-tab-bar-mode&#34;&gt;Tabs (&lt;code&gt;M-x tab-bar-mode&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;These are mentioned often, but rarely recommended. Most Emacs users find the
idea of tabs in Emacs to be redundant, but will happily recommend window
configuration registers, which provide similar functionality.&lt;/p&gt;
&lt;p&gt;Tabs work great to separate projects, or work and email buffers. In principle
this is equivalent to popping up a new frame and letting the window manager
handle the separation, but on stacking window managers I find tabs to be much
preferable.&lt;/p&gt;
&lt;p&gt;Since there&amp;rsquo;s never one way to do something in Emacs, a secondary
&lt;code&gt;tab-line-mode&lt;/code&gt; is available that adds tabs to each window instead of frame.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;next-time&#34;&gt;Next time:&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;icomplete&lt;/code&gt; and &lt;code&gt;fido&lt;/code&gt;: Incremental completion systems&lt;/li&gt;
&lt;li&gt;&lt;code&gt;completion-styles&lt;/code&gt;: Supercharge completion in the minibuffer&lt;/li&gt;
&lt;li&gt;&lt;code&gt;re-builder&lt;/code&gt; and &lt;code&gt;rx&lt;/code&gt;: Visual regular expressions&lt;/li&gt;
&lt;li&gt;&lt;code&gt;orgtbl-mode&lt;/code&gt;: Easy table formatting everywhere&lt;/li&gt;
&lt;li&gt;&lt;code&gt;strokes-mode&lt;/code&gt;: Control emacs with mouse gestures&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;hellip; and more.&lt;/p&gt;
&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;Coupled with some antiquated defaults. I&amp;rsquo;m not holding my breath here.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;And no wonder, a staggering amount of work has gone into Doom/Spacemacs etc. Tens of thousands of man hours.&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;Not quite, since &lt;code&gt;delete-blank-lines&lt;/code&gt; will leave one newline untouched.&amp;#160;&lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34;&gt;
&lt;p&gt;There is of course also &lt;code&gt;capitalize-dwim&lt;/code&gt;. Many thanks to Zachary Kanfer, the author of all three DWIM commands, for reminding me of its existence!&amp;#160;&lt;a href=&#34;#fnref:4&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:5&#34;&gt;
&lt;p&gt;Unless you like working with inactive regions. In which case you&amp;rsquo;re probably an Emacs greybeard and you don&amp;rsquo;t need this write-up!&amp;#160;&lt;a href=&#34;#fnref:5&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>Lazy Elfeed</title>
      <link>https://karthinks.com/software/lazy-elfeed/</link>
      <pubDate>Fri, 22 May 2020 03:20:00 +0530</pubDate>
      
      <guid>https://karthinks.com/software/lazy-elfeed/</guid>
      <description>&lt;p&gt;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 present you with fresh results. The third is organizing by tags instead of folders. Web services like Gmail use some of these concepts (and probably pioneered them too), but the difference between web-based readers and Emacs in speed, customizability, general hackability and use is night and day.&lt;/p&gt;
&lt;p&gt;Elfeed&amp;rsquo;s default interface has all the right pieces, but I found it needed just a &lt;em&gt;little tweaking&lt;/em&gt; to fit what I expect from a feed reader.&lt;/p&gt;
&lt;h2 id=&#34;display-the-feed-list-and-current-entry-in-a-split-pane-setup&#34;&gt;Display the feed list and current entry in a split pane setup &lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;:&lt;/h2&gt;
&lt;p&gt;Elfeed has two kinds of views: The &lt;code&gt;search&lt;/code&gt; view which shows feed entries matching a search query, and the &lt;code&gt;show&lt;/code&gt; view to read a specific entry. By default only one of these is active at a time, but a more useful split-pane setup is a few tweaks away:&lt;/p&gt;
&lt;video width=&#34;700&#34; style=&#34;display:block; margin: 0 auto;&#34; autoplay controls loop&gt;
&lt;source src=&#34;https://karthinks.com/img/elfeed-split-pane-small.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;p&gt;Your browser does not support the video tag.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;Stay in the search view and preview entries.&lt;/p&gt;
&lt;p&gt;There are only two pieces to this. The first is to specify the function we want Elfeed to use to display the buffer with the current entry. In this case write our own &lt;code&gt;elfeed-display-buffer&lt;/code&gt; to set the height.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-show-entry-switch&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;elfeed-display-buffer&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-display-buffer&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;act&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;pop-to-buffer&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;buf&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#963&#34;&gt;set-window-text-height&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;get-buffer-window&lt;/span&gt;) (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;round&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#60e;font-weight:bold&#34;&gt;0.7&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;frame-height&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A different but less self-contained way would be to set it to use the built in &lt;code&gt;pop-to-buffer&lt;/code&gt; but add an entry to &lt;code&gt;display-buffer-alist&lt;/code&gt; as an instruction on what to do with elfeed entry buffers.&lt;/p&gt;
&lt;p&gt;The second is to set up a keybinding to advance to the next or previous feed in the search window, with a little  elbow grease. &lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#888&#34;&gt;;; -*- lexical-binding: t -*-&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-search-show-entry-pre&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;lines&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Returns a function to scroll forward or back in the Elfeed
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;  search results, displaying entries without switching to them.&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;times&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;p&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;forward-line&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;*&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;times&lt;/span&gt; (&lt;span style=&#34;color:#007020&#34;&gt;or&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;lines&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;0&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;recenter&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;call-interactively&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;elfeed-search-show-entry&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;select-window&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;previous-window&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#007020&#34;&gt;unless&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-search-remain-on-entry&lt;/span&gt; (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;forward-line&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-1&lt;/span&gt;))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-search-mode-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;n&amp;#34;&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;elfeed-search-show-entry-pre&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;+1&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-search-mode-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;p&amp;#34;&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;elfeed-search-show-entry-pre&lt;/span&gt; &lt;span style=&#34;color:#00d;font-weight:bold&#34;&gt;-1&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-search-mode-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;M-RET&amp;#34;&lt;/span&gt;) (&lt;span style=&#34;color:#963&#34;&gt;elfeed-search-show-entry-pre&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;navigate-the-entire-database-with-the-space-bar&#34;&gt;Navigate the entire database with the space bar&lt;/h2&gt;
&lt;p&gt;Alternatively, you might prefer to stay in the &amp;ldquo;show&amp;rdquo; window and just go through each entry by content instead of header. You can use the space bar to scroll the view or move to the next entry as appropriate.&lt;/p&gt;
&lt;video width=&#34;700&#34; style=&#34;display:block; margin: 0 auto;&#34; autoplay controls loop&gt;
&lt;source src=&#34;https://karthinks.com/img/elfeed-space-nav-small.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;p&gt;Your browser does not support the video tag.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;Go forward (scroll or next entry) with &lt;code&gt;SPC&lt;/code&gt;, back with &lt;code&gt;S-SPC&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Google Reader had one button navigation, and it is a level of laziness I have aspired to since.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-scroll-up-command&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Scroll up or go to next feed item in Elfeed&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;^P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;scroll-error-top-bottom&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;condition-case-unless-debug&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;scroll-up-command&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;error&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;elfeed-show-next&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-scroll-down-command&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Scroll up or go to next feed item in Elfeed&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;^P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;scroll-error-top-bottom&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;condition-case-unless-debug&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;color:#963&#34;&gt;scroll-down-command&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;arg&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#f00;font-weight:bold&#34;&gt;error&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;elfeed-show-prev&lt;/span&gt;)))))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-show-mode-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;SPC&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;elfeed-scroll-up-command&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-show-mode-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;S-SPC&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;elfeed-scroll-down-command&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;easier-tagging&#34;&gt;Easier tagging&lt;/h2&gt;
&lt;p&gt;By default you can tag an entry from the search results by typing &amp;ldquo;&lt;code&gt;+&lt;/code&gt;&amp;rdquo; followed by the tag name. This is too much work for a central organizational feature, so a little helper sorts things out.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-tag-selection-as&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;mytag&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Returns a function that tags an elfeed entry or selection as
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;background-color:#fff0f0&#34;&gt;MYTAG&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#007020&#34;&gt;lambda&lt;/span&gt; ()
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;Toggle a tag on an Elfeed search selection&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      (&lt;span style=&#34;color:#963&#34;&gt;elfeed-search-toggle-all&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;mytag&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Tag with a single letter keybind:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-search-mode-map&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;l&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;elfeed-tag-selection-as&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;readlater&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-search-mode-map&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;d&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;elfeed-tag-selection-as&lt;/span&gt; &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;junk&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;open-feeds-in-emacs&#34;&gt;Open feeds in Emacs&lt;/h2&gt;
&lt;p&gt;Elfeed will open links to feeds in your default browser with &amp;ldquo;&lt;code&gt;b&lt;/code&gt;&amp;rdquo;. But for text heavy posts or to look up something specific I often want to open them in place in Emacs:&lt;/p&gt;
&lt;video style=&#34;center&#34; style=&#34;center&#34; width=&#34;700&#34; autoplay controls loop&gt;
&lt;source src=&#34;https://karthinks.com/img/elfeed-open-eww-small.mp4&#34; type=&#34;video/mp4&#34;&gt;
&lt;p&gt;Your browser does not support the video tag.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;Quick-preview links in &lt;code&gt;eww&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Instead of writing a function to do this from scratch, we set &lt;code&gt;eww&lt;/code&gt; (Emacs&amp;rsquo; built in web browser) as the default in a short-lived &lt;code&gt;let&lt;/code&gt; binding and let the usual &lt;code&gt;browse-url&lt;/code&gt; functions handle the rest:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-show-eww-open&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;use-generic-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;open with eww&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;browse-url-browser-function&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;eww-browse-url&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;elfeed-show-visit&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;use-generic-p&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-search-eww-open&lt;/span&gt; (&lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;use-generic-p&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;open with eww&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;interactive&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;P&amp;#34;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#007020&#34;&gt;let&lt;/span&gt; ((&lt;span style=&#34;color:#963&#34;&gt;browse-url-browser-function&lt;/span&gt; &lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;#&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#963&#34;&gt;eww-browse-url&lt;/span&gt;))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    (&lt;span style=&#34;color:#963&#34;&gt;elfeed-search-browse-url&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;use-generic-p&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-show-mode-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;B&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;efleed-show-eww-open&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;define-key&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;elfeed-search-mode-map&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;kbd&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;B&amp;#34;&lt;/span&gt;) &lt;span style=&#34;color:#a60;background-color:#fff0f0&#34;&gt;&amp;#39;efleed-search-eww-open&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We can take this idea further. The following snippet will ensure that Emacs (and thus Elfeed) defaults to opening Youtube links in &lt;code&gt;mpv&lt;/code&gt; (or the video player of your choice), cutting the browser out of the loop entirely. &lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-emacs-lisp&#34; data-lang=&#34;emacs-lisp&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;setq&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;browse-url-browser-function&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;      &lt;span style=&#34;color:#333&#34;&gt;&amp;#39;&lt;/span&gt;((&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;https:\\/\\/www\\.youtu\\.*be.&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;browse-url-mpv&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        (&lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;.&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#333&#34;&gt;.&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;browse-url-generic&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#007020&#34;&gt;defun&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;browse-url-mpv&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;url&lt;/span&gt; &lt;span style=&#34;color:#038;font-weight:bold&#34;&gt;&amp;amp;optional&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;single&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  (&lt;span style=&#34;color:#06b;font-weight:bold&#34;&gt;start-process&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;mpv&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#036;font-weight:bold&#34;&gt;nil&lt;/span&gt; &lt;span style=&#34;background-color:#fff0f0&#34;&gt;&amp;#34;mpv&amp;#34;&lt;/span&gt; (&lt;span style=&#34;color:#963&#34;&gt;shell-quote-argument&lt;/span&gt; &lt;span style=&#34;color:#963&#34;&gt;url&lt;/span&gt;)))
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34;&gt;
&lt;p&gt;There is &lt;a href=&#34;https://github.com/algernon/elfeed-goodies&#34;&gt;Elfeed Goodies&lt;/a&gt;, a package on github that provides a split pane setup to Elfeed. But it&amp;rsquo;s rather large for what it does, has a dependency I don&amp;rsquo;t need (&lt;code&gt;popwin.el&lt;/code&gt;) for a single function and provides much else that I have no use for.&amp;#160;&lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34;&gt;
&lt;p&gt;A previous version of this write-up used macros instead of closures for the helpers. This simpler solution was suggested by &lt;a href=&#34;https://old.reddit.com/r/emacs/comments/goh2nw/lazy_elfeed/frgbn1h/&#34;&gt;&lt;code&gt;/u/nv-elisp&lt;/code&gt; on Reddit&lt;/a&gt;.&amp;#160;&lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;
&lt;p&gt;&lt;code&gt;mpv&lt;/code&gt; requires &lt;a href=&#34;https://github.com/ytdl-org/youtube-dl&#34;&gt;Youtube-dl&lt;/a&gt; to play youtube videos.&amp;#160;&lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
</description>
    </item><item>
      <title>About</title>
      <link>https://karthinks.com/about/</link>
      <pubDate>Wed, 02 Oct 2019 10:28:38 -0700</pubDate>
      
      <guid>https://karthinks.com/about/</guid>
      <description>&lt;p&gt;Hi, I&amp;rsquo;m Karthik.  I collect notes here &amp;ndash; ostensibly about everything, but realistically mostly Emacs.&lt;/p&gt;
&lt;p&gt;Things I&amp;rsquo;m interested in:&lt;/p&gt;
</description>
    </item><item>
      <title>The Orphaning of Ideas</title>
      <link>https://karthinks.com/blog/the-orphaning-of-ideas/</link>
      <pubDate>Wed, 15 May 2019 21:53:33 -0700</pubDate>
      
      <guid>https://karthinks.com/blog/the-orphaning-of-ideas/</guid>
      <description>&lt;p&gt;Or “A very short investigation of the mental dynamics of feeling suddenly stupid”.&lt;/p&gt;
&lt;p&gt;Every week I have a couple of experiences that play out as follows:&lt;/p&gt;
&lt;p&gt;Involved and intricate discussion on non-trivial subject, usually but not always mathematical and/or abstract in nature,
involving an attempt to make a deduction about the same,
resulting in a sudden and complete blanking of the mind,
the contents of which are replaced by an image of reflective self-awareness at losing the plot.
Having lived through this a few hundred times, I’m beginning to understand in greater resolution what is happening during the “blanking” stage. It’s not really that all relevant concepts pack up and vacate the imagination. For the most part, they’re around. The strongest “chunks”, clusters of densely interconnected atoms of understanding, they continue to persist as chunks too. What disappear under mental overload are the thinly formed (i.e. new) bridges connecting these islands, leaving in their wake local pockets of orphaned and completely inapplicable concepts.&lt;/p&gt;
&lt;p&gt;This realization is helpful in that it tells me where I should be exerting my efforts: Not on learning new ideas, but on creating as many independent routes between new and old ones as I can. In a field like mathematics that deals with generalities, for example, this means spending less time on definitions or theorems and more on applying them to as many other mathematical constructs as I can, hopefully proving something I already know to be true in a new way.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;For long-lasting learning, pieces of knowledge should support each other through their connections. For when we remember a fact or use an idea, we activate connected facts and ideas and solidify them in our minds. Our knowledge lives best in infinite, self-supporting clusters. But if we learn facts and ideas in isolation, we make dots without bonds…So, for long-lasting learning and understanding, make bonds; connect each new fact and idea to what you already know. Use your reasoning tools to weave a richly connected, durable tapestry of knowledge.&lt;/p&gt;
&lt;p&gt;-The Art of Insight in Science and Engineering&lt;/p&gt;
&lt;/blockquote&gt;
</description>
    </item><item>
      <title>Bodies</title>
      <link>https://karthinks.com/blog/bodies/</link>
      <pubDate>Sun, 07 Apr 2019 21:29:44 -0700</pubDate>
      
      <guid>https://karthinks.com/blog/bodies/</guid>
      <description>&lt;p&gt;I’ve dabbled in mindfulness meditation before, but the past three months have been the first uninterrupted period of sustained practice. While it would be an exaggeration to say I’ve even scratched the surface of the practice, I have learnt a couple of interesting things about the nature of experience. The first is how unbelievably skittish and capricious the mind is: we are all mostly age four, most of the time. Our minds are not on board with whatever veneer of maturity or sophistication we project. The second is how much the mind likes narratives, and repeating narratives. They form unbidden and play on repeat until they are supplanted by a new story. I knew this in the abstract, but watching it happen live is a revelation. Then there is some stuff that I suspect is only true for me: how much of my mental chatter is verbal instead of imagery, for example. But by far the most interesting realization I’ve had is learning how much of our thinking is in our bodies.&lt;/p&gt;
&lt;p&gt;This is easiest to see with negative emotions, as you might recognize if you’ve ever caught yourself clenching your fist or tightening your shoulders at a thought. We tend to think of this as a physical consequence of a mental state. But it’s tough for me to make as much of a case for the physical-mental dichotomy as I would have three months ago. Focusing on the sensation of anxiety itself, for instance, clarifies that the emotion is primarily a pattern of energy that is felt mostly around my throat with varying degrees of constriction and radiating heat. Regret is all in the chest.&lt;/p&gt;
&lt;p&gt;Some of this, like a gut feeling, is captured in language as phrases. Others are visual metaphors, like feeling crushed, or the floor dropping out from under you when you’re shocked. But a lot isn’t, and maybe that’s because they aren’t universal experiences.&lt;/p&gt;
&lt;p&gt;The feeling of craving stimulation, the feeling you might get when you really want to check your phone but deny yourself, I feel it in the stomach in a way that is remarkably close to, but not exactly, like hunger. Sleepiness is of course in the eyelids, but surprisingly also in the breath. Fear is everywhere, in the joints and the fingers and the back of the neck.&lt;/p&gt;
</description>
    </item>
  </channel>
</rss>
