<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <id>https://dawranliou.com/atom.xml</id>
  <title>Daw-Ran Liou's website</title>
  <updated>2024-03-01T00:00:00Z</updated>
  <link href="https://dawranliou.com/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="https://dawranliou.com"/>
  <author>
    <name>Daw-Ran Liou</name>
  </author>
  <entry xml:lang="en">
    <id>https://dawranliou.com/blog/the-biggest-positive-for-emacs</id>
    <author>
      <name>Daw-Ran Liou</name>
    </author>
    <title>The Biggest Positive for Emacs</title>
    <updated>2021-03-18T00:00:00Z</updated>
    <published>2021-03-18T00:00:00Z</published>
    <link href="https://dawranliou.com/blog/the-biggest-positive-for-emacs" type="text/html"/>
    <content type="html">&lt;p&gt;I came across &lt;a href="https://youtu.be/LKegZI9vWUU"&gt;the interview with Henrik Lissner&lt;/a&gt;, the creator of Doom Emacs, and it really resonated with me about the biggest positive for Emacs (starting at &lt;a href="https://youtu.be/LKegZI9vWUU?t=2917"&gt;48:37&lt;/a&gt;):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The biggest positive for Emacs, hands down (that addresses all its negatives) is self-documenting, which primarily means documentation is a first-class citizen in ELisp. You can easily look it up any variable, function, macro, face, whatever, even something that’s not defined in ELisp but defined in the C code you can look it up. […]&lt;/p&gt;
&lt;p&gt;If you use Emacs you’re living in a REPL: you have direct, unfeathered access to its guts. And if you want to know anything about the current state of Emacs, you can just ask it directly. That’s something I don’t think any other editors can do quite at that level.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Living inside the REPL (or working inside a running program) is such a powerful technique in programming. That’s also one of the reasons drove me towards Emacs after learning Clojure, even though the two LISPs have very different ideals or philosophies.&lt;/p&gt;
</content>
  </entry>
  <entry xml:lang="en">
    <id>https://dawranliou.com/blog/rewriting-my-emacs-config</id>
    <author>
      <name>Daw-Ran Liou</name>
    </author>
    <title>Rewriting My Emacs Config</title>
    <updated>2020-11-06T00:00:00Z</updated>
    <published>2020-11-06T00:00:00Z</published>
    <link href="https://dawranliou.com/blog/rewriting-my-emacs-config" type="text/html"/>
    <content type="html">&lt;p&gt;Since the last post, I had switched over to &lt;a href="https://github.com/hlissner/doom-emacs"&gt;Doom Emacs&lt;/a&gt; for a while and then, hopefully, have switched back to my hand-crafted emacs config for the last time. I wanted to try Doom for some reasons:&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;I didn’t like the startup time of my previous handcrafted emacs config,&lt;/li&gt;
&lt;li&gt;I found painful to look at my emacs config, and&lt;/li&gt;
&lt;li&gt;I wanted to learn more from this very successful community-driven project.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Even prior to switching over to Doom, I took a lot of inspirations from it to enhance my config. One main frustration of using Spacemacs was its think layers of abstracts. I didn’t find such frustration with Doom. Doom is very well documented and stays true to its mantras:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Close to metal.&lt;/strong&gt; There’s less between you and vanilla Emacs by design. That’s less to grok and less to work around when you tinker. Internals ought to be written as if reading them were part of Doom’s UX, and it is!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Trying various modules, it’s fun exploring various pre-configured packages without the hustle to configure them pre-maturely. As an example, I like the &lt;a href="https://github.com/hlissner/doom-emacs/tree/develop/modules/lang/org"&gt;&lt;code&gt;org&lt;/code&gt; module&lt;/a&gt; just work out of the box with various of plugins.&lt;/p&gt;
&lt;p&gt;However, eventually I grew tired of looking at all the keybindings that I wasn’t using. All the keybindings and functionalities that I wasn’t using, or didn’t spark joy in me, made me sad. For every single unused keybinding, it is an extra mental burden in my workflow. If I get rid of all the unnecessary keybindings I could improve the efficiencies on the ones I use most often, because I no longer need the long nested key strokes anymore.&lt;/p&gt;
&lt;p&gt;Also, I found the &lt;a href="https://www.youtube.com/channel/UCAiiOTio8Yu69c3XnR7nQBQ"&gt;System Crafters&lt;/a&gt; YouTube serious &lt;a href="https://www.youtube.com/playlist?list=PLEoMzSkcN8oPH1au7H6B7bBJ4ZO7BXjSZ"&gt;Emacs From Scratch&lt;/a&gt;. It really was a godsend to me to help me start writing my Emacs config again. &lt;a href="https://github.com/dawranliou/emacs.d"&gt;My current Emacs Config&lt;/a&gt; drew a lot of inspirations from it and from the author’s, David Wilson’s, &lt;a href="https://github.com/daviwil/dotfiles/blob/master/Emacs.org"&gt;own config&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;So far, I really like that I have total control over my emacs configuration, and the start time wasn’t too terrible either.&lt;/p&gt;
&lt;p&gt;Links: - &lt;a href="https://github.com/hlissner/doom-emacs"&gt;Doom Emacs&lt;/a&gt; - &lt;a href="https://www.youtube.com/playlist?list=PLEoMzSkcN8oPH1au7H6B7bBJ4ZO7BXjSZ"&gt;Emacs From Scratch&lt;/a&gt; - &lt;a href="https://github.com/dawranliou/emacs.d"&gt;My current Emacs Config&lt;/a&gt; - &lt;a href="https://github.com/dawranliou/emacs.d/blob/master/themes/sketch-white-theme.el"&gt;My current Emacs theme&lt;/a&gt;&lt;/p&gt;
</content>
  </entry>
  <entry xml:lang="en">
    <id>https://dawranliou.com/blog/advise-eglot-to-support-clojure-monorepo-setup</id>
    <author>
      <name>Daw-Ran Liou</name>
    </author>
    <title>Advise Eglot to Support Clojure Monorepo Setup</title>
    <updated>2022-03-28T00:00:00Z</updated>
    <published>2022-02-27T00:00:00Z</published>
    <link href="https://dawranliou.com/blog/advise-eglot-to-support-clojure-monorepo-setup" type="text/html"/>
    <content type="html">&lt;h2 id="updates-2022-03-28-a-better-solution"&gt;&lt;em&gt;Updates 2022-03-28: A Better Solution&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;Since I published the original solution, I've found certain things were not working as I claimed. There's a better solution, which is mentioned shortly in this section, without hacking Emacs lisp code. Because my intent to write this article is less about giving you the solution but more about demonstrating a way to tweak Emacs' package to fit your own desires, I decided to keep its original content alive, with the hope that it would still be insightful to some of you.&lt;/p&gt;
&lt;p&gt;Here's the updated solution! Since &lt;a href="https://github.com/clojure-lsp/clojure-lsp/issues/752"&gt;clojure-lsp issue #752&lt;/a&gt;, &lt;code class="verbatim"&gt;clojure-lsp&lt;/code&gt; uses the classpath to discover the source code to analyze. The trick is to merge all the classpaths from the monorepo's sub-projects. Conveniently, &lt;code class="verbatim"&gt;lein-monolith&lt;/code&gt; provides a way to &lt;a href="https://github.com/amperity/lein-monolith#merged-source-profile"&gt;Merge Source Profile&lt;/a&gt;. Therefore we can invoke the command &lt;code class="verbatim"&gt;lein monolith with-all classpath&lt;/code&gt; instead. Your &lt;code class="verbatim"&gt;clojure-lsp&lt;/code&gt; configuration file that goes to &lt;code class="verbatim"&gt;&amp;lt;monorepo-root&amp;gt;/.lsp/config.edn&lt;/code&gt; should look like this:&lt;/p&gt;
&lt;pre class="clojure"&gt;&lt;code&gt;{:project-specs [{:project-path &amp;quot;project.clj&amp;quot;
                  :classpath-cmd [&amp;quot;lein&amp;quot; &amp;quot;monolith&amp;quot; &amp;quot;with-all&amp;quot; &amp;quot;classpath&amp;quot;]}]}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that if you have a large monorepo, you might need to bump the &lt;code class="verbatim"&gt;eglot-connect-timeout&lt;/code&gt; to a larger number to let &lt;code class="verbatim"&gt;clojure-lsp&lt;/code&gt; finish analyzing all the source code. I set my &lt;code class="verbatim"&gt;eglot-connect-timeout&lt;/code&gt; to &lt;code class="verbatim"&gt;600&lt;/code&gt; currently.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;em&gt;The following is the original content.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id="abstract"&gt;Abstract&lt;/h2&gt;
&lt;p&gt;The advice system and dynamic scoping are two powerful facilities in Emacs. In this article, I'll show you how to use them to tweak Emacs' behaviors and facts to workaround the &lt;code class="verbatim"&gt;eglot&lt;/code&gt; package while setting up &lt;code class="verbatim"&gt;clojure-lsp&lt;/code&gt; for a monorepo.&lt;/p&gt;
&lt;h2 id="background"&gt;Background&lt;/h2&gt;
&lt;p&gt;In Emacs, there are two popular LSP clients: &lt;a href="https://emacs-lsp.github.io/lsp-mode/"&gt;&lt;code class="verbatim"&gt;lsp-mode&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://github.com/joaotavora/eglot"&gt;&lt;code class="verbatim"&gt;eglot&lt;/code&gt;&lt;/a&gt;. Although &lt;a href="https://github.com/joaotavora/eglot#historical-differences-to-lsp-modeel"&gt;historically, there were more noticeable differences between the two packages&lt;/a&gt; in terms of their usage and their UI, these days, I'm pretty happy with both of them. I can achieve pretty minimal UI in &lt;code class="verbatim"&gt;lsp-mode&lt;/code&gt; (as &lt;code class="verbatim"&gt;eglot&lt;/code&gt; always is &#128578;) by tweaking several custom settings, and both work well with built-in packages, which I've grown accustomed to over the years.&lt;/p&gt;
&lt;p&gt;Over the past few years of using Emacs, I started to prefer the class of packages that work very closely with the Emacs' built-in facilities instead of inventing their isolated world&lt;a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"&gt;&lt;sup&gt;1&lt;/sup&gt;&lt;/a&gt;. Such packages provide a narrow focus that enhances a specific part of Emacs. I love this class of packages because I can simply reject a dependency if it's not essential to my workflow. Therefore, I decided to hop back from &lt;code class="verbatim"&gt;lsp-mode&lt;/code&gt; to &lt;code class="verbatim"&gt;eglot&lt;/code&gt; for its simplicity.&lt;/p&gt;
&lt;p&gt;Because of &lt;code class="verbatim"&gt;clojure-lsp&lt;/code&gt;'s limitation on discovering source code (&lt;a href="https://github.com/clojure-lsp/clojure-lsp/issues/191"&gt;issue #191&lt;/a&gt; and &lt;a href="https://github.com/clojure-lsp/clojure-lsp/issues/551"&gt;issue #551&lt;/a&gt;) with the &lt;a href="https://github.com/amperity/lein-monolith"&gt;&lt;code class="verbatim"&gt;lein-monolith&lt;/code&gt;&lt;/a&gt; setup and my needs at work, I didn't change the &lt;code class="verbatim"&gt;:project-paths&lt;/code&gt; setting as others did (e.g., &lt;a href="https://github.com/clojure-lsp/clojure-lsp/issues/191#issuecomment-918373230"&gt;this comment&lt;/a&gt; and &lt;a href="https://gist.github.com/bendlas/4a2a98b1cbe1d1efa8a7ef6850934e13"&gt;this gist&lt;/a&gt;). Instead, I run a different &lt;code class="verbatim"&gt;clojure-lsp&lt;/code&gt; server session for each sub-project. In &lt;code class="verbatim"&gt;lsp-mode&lt;/code&gt;, this can be done by customizing the project root the first time launching the &lt;code class="verbatim"&gt;clojure-lsp&lt;/code&gt;. Next, I'll show you the issue I faced using &lt;code class="verbatim"&gt;eglot&lt;/code&gt; and how to teach it (or &lt;em&gt;advise&lt;/em&gt; it &#128521;) to work around it.&lt;/p&gt;
&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;When &lt;code class="verbatim"&gt;eglot&lt;/code&gt; starts the &lt;code class="verbatim"&gt;clojure-lsp&lt;/code&gt; server, it infers&lt;a href="#fn2" class="footnote-ref" id="fnref2" role="doc-noteref"&gt;&lt;sup&gt;2&lt;/sup&gt;&lt;/a&gt; the project root by utilizing the &lt;code class="verbatim"&gt;project.el&lt;/code&gt; built-in package. Out of the box, Emacs consider the project root to be the current version-controlled root directory. If you are using &lt;code class="verbatim"&gt;git&lt;/code&gt;, the project root is the parent folder of the &lt;code class="verbatim"&gt;.git/&lt;/code&gt; folder. While this inference is correct most of the time, I want this to be different for my monorepo project at work, which has the directory structure like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;root/
  |--- .git/
  |--- projects.clj
  |--- project-a/
  |      |--- projects.clj
  |      |--- src/
  |--- project-b/
  |      |--- projects.clj
  |      |--- src/
  .
  .
  .
  |--- project-n
         |--- projects.clj
         |--- src/
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code class="verbatim"&gt;root/&lt;/code&gt; is the root of our monorepo, which uses the &lt;code class="verbatim"&gt;projects.clj&lt;/code&gt; file and &lt;code class="verbatim"&gt;lein-monolith&lt;/code&gt; to tie all of its sub-projects together. All sub-projects are version-controlled together under &lt;code class="verbatim"&gt;root/&lt;/code&gt;. The &lt;code class="verbatim"&gt;root/&lt;/code&gt; project itself does not contain any source code, whereas the sub-projects do.&lt;/p&gt;
&lt;p&gt;With this setup, editing any source file in any sub-project will connect to the &lt;code class="verbatim"&gt;clojure-lsp&lt;/code&gt; server session at &lt;code class="verbatim"&gt;root&lt;/code&gt; by default. The question is: how to tweak &lt;code class="verbatim"&gt;eglot&lt;/code&gt; to use the sub-project root as the &lt;code class="verbatim"&gt;clojure-lsp&lt;/code&gt; server session?&lt;/p&gt;
&lt;h2 id="solution"&gt;Solution&lt;/h2&gt;
&lt;p&gt;I came up with this solution that ensures the &lt;code class="verbatim"&gt;eglot-ensure&lt;/code&gt; function will try to locate the &lt;code class="verbatim"&gt;clojure-project-dir&lt;/code&gt; as the project root when launching an LSP session. If &lt;code class="verbatim"&gt;clojure-project-dir&lt;/code&gt; isn't found, it falls back to using the version-control root to launch the LSP server.&lt;/p&gt;
&lt;pre class="clojure"&gt;&lt;code&gt;;; My personal settings that you might not require
;;(add-hook &amp;#39;clojure-mode-hook &amp;#39;eglot-ensure)
;;(custom-set-variables &amp;#39;(eglot-connect-timeout 300))

(defun project-try-clojure-project (dir)
  &amp;quot;Try to locate a Clojure project.&amp;quot;
  (when-let ((found (clojure-project-dir)))
    (cons &amp;#39;transient found)))

(defun find-clojure-project-advice (orig-fun &amp;amp;rest args)
  &amp;quot;Fix project-root for the clojure monorepo setup.&amp;quot;
  (let ((project-find-functions
         (cons &amp;#39;project-try-clojure-project project-find-functions)))
    (apply orig-fun args)))

(advice-add &amp;#39;eglot-ensure :around #&amp;#39;find-clojure-project-advice)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But how does this work?&lt;/p&gt;
&lt;h2 id="teaching-emacs-new-tricks-by-giving-it-dynamic-advices"&gt;Teaching Emacs new tricks by giving it dynamic advices&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Aspect-oriented_programming"&gt;Aspect-Oriented Programming&lt;/a&gt; page on Wikipedia:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by &lt;strong&gt;adding additional behavior to existing code (an advice) without modifying the code itself&lt;/strong&gt;, instead separately specifying which code is modified via a "pointcut" specification, such as "log all function calls when the function's name begins with 'set'".&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I only learned the concept of AOP because of Emacs. It fits surprisingly well for a plug-in system in programs like Emacs. The users of Emacs are empowered to enrich their experience with third-party packages and are empowered to hack the behaviors (functions) of any package from afar through &lt;a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html"&gt;the advice system&lt;/a&gt; without touching the source code of those packages.&lt;/p&gt;
&lt;p&gt;Not only are the behaviors hackable, but the facts (variables) are also modifiable thanks to &lt;a href="https://www.emacswiki.org/emacs/DynamicScoping"&gt;Dynamic Scoping&lt;/a&gt;. Dynamic Scoping gives the Emacs users the power to change variable bindings with a dynamic extend.&lt;/p&gt;
&lt;pre class="clojure"&gt;&lt;code&gt;(defun project-try-clojure-project (dir)
  &amp;quot;Try to locate a Clojure project.&amp;quot;
  (when-let ((found (clojure-project-dir)))
    (cons &amp;#39;transient found)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we define a backend for the &lt;code class="verbatim"&gt;project-find-functions&lt;/code&gt;. If a &lt;code class="verbatim"&gt;clojure-project-dir&lt;/code&gt; is found, &lt;code class="verbatim"&gt;project-try-clojure-project&lt;/code&gt; returns the tuple &lt;code class="verbatim"&gt;(transient . &amp;lt;PROJECT DIR PATH STRING&amp;gt;)&lt;/code&gt;, otherwise &lt;code class="verbatim"&gt;nil&lt;/code&gt;. This function's signature will satisfy as an element in the &lt;code class="verbatim"&gt;project-find-functions&lt;/code&gt;. However, we don't want to change the behavior across the board. We want to limit the scope of the modified &lt;code class="verbatim"&gt;project-find-functions&lt;/code&gt; variable. So we use a let-binding to change the dynamic scope:&lt;/p&gt;
&lt;pre class="clojure"&gt;&lt;code&gt;(defun find-clojure-project-advice (orig-fun &amp;amp;rest args)
  &amp;quot;Fix project-root for the clojure monorepo setup.&amp;quot;
  (let ((project-find-functions
         (cons &amp;#39;project-try-clojure-project project-find-functions)))
    (apply orig-fun args)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code class="verbatim"&gt;find-clojure-project-advice&lt;/code&gt; function binds the &lt;code class="verbatim"&gt;project-find-functions&lt;/code&gt; variable with the &lt;code class="verbatim"&gt;project-try-clojure-project&lt;/code&gt; function as the first element in the list. This binding only exists to the extent of this function call. Therefore, invoking &lt;code class="verbatim"&gt;project-current&lt;/code&gt; function under other contexts will not be affected.&lt;/p&gt;
&lt;pre class="clojure"&gt;&lt;code&gt;(advice-add &amp;#39;eglot-ensure :around #&amp;#39;find-clojure-project-advice)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Lastly, we use the &lt;code class="verbatim"&gt;add-advice&lt;/code&gt; to advise the &lt;code class="verbatim"&gt;eglot-ensure&lt;/code&gt; function to invoke the &lt;code class="verbatim"&gt;find-clojure-project-advice&lt;/code&gt;. The &lt;code class="verbatim"&gt;:around&lt;/code&gt; keyword denotes that we want to compose the advising function (&lt;code class="verbatim"&gt;find-clojure-project-advice&lt;/code&gt;) around the advised function (&lt;code class="verbatim"&gt;eglot-ensure&lt;/code&gt;) so the let-binding can enter the dynamic scope of &lt;code class="verbatim"&gt;eglot-ensure&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="conclusion"&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;To recap, this article:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Provides an alternative way of setting up &lt;code class="verbatim"&gt;clojure-lsp&lt;/code&gt; with the &lt;code class="verbatim"&gt;eglot&lt;/code&gt; LSP client when working with a monorepo,&lt;/li&gt;
&lt;li&gt;Demonstrates how to use Aspect-Oriented Programming and Dynamic Scoping in Emacs.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Without modifying any source code of Emacs or its packages, we can change the behavior (the &lt;code class="verbatim"&gt;eglot-ensure&lt;/code&gt; function) and the fact (the &lt;code class="verbatim"&gt;project-find-functions&lt;/code&gt; variable) to satisfy a specific use case while keeping other parts of Emacs intact. I think this is a great example to showcase why Emacs is so powerful and valuable to its users.&lt;/p&gt;
&lt;h2 id="footnotes"&gt;Footnotes&lt;/h2&gt;
&lt;section class="footnotes" role="doc-endnotes"&gt;
&lt;hr /&gt;
&lt;ol&gt;
&lt;li id="fn1" role="doc-endnote"&gt;&lt;p&gt;This philosophy plays well with my favorite programming language, Clojure. The community has learned to work together by creating single-purpose libraries that strongly prefer to use Clojure data as the universal language.&lt;a href="#fnref1" class="footnote-back" role="doc-backlink"&gt;↩︎&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li id="fn2" role="doc-endnote"&gt;&lt;p&gt;&lt;code class="verbatim"&gt;eglot--guess-contact&lt;/code&gt; is the internal function that makes this inference.&lt;a href="#fnref2" class="footnote-back" role="doc-backlink"&gt;↩︎&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content>
  </entry>
  <entry xml:lang="en">
    <id>https://dawranliou.com/blog/compiling-emacs-from-source</id>
    <author>
      <name>Daw-Ran Liou</name>
    </author>
    <title>Compiling Emacs from Source on MacOS Big Sur</title>
    <updated>2021-11-09T00:00:00Z</updated>
    <published>2021-11-09T00:00:00Z</published>
    <link href="https://dawranliou.com/blog/compiling-emacs-from-source" type="text/html"/>
    <content type="html">&lt;p&gt;Recently I started to compile the Emacs master branch from source for daily use instead of using one of the popular formulas on Homebrew.&lt;a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"&gt;&lt;sup&gt;1&lt;/sup&gt;&lt;/a&gt; It’s pretty cool to try the latest features like the native compilation and the native emoji before the stable releases. Also it’s quite a satisfying experience to be able to compile Emacs from source. It took me several tries to get it right but I think I documented everything. Here are the steps:&lt;/p&gt;
&lt;h2 id="install-dependencies"&gt;Install dependencies&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;libxml2&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Optional for native compilation
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;gcc&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;libgccjit&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="sh"&gt;&lt;code&gt;brew install libxml2 gcc libgccjit&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Follow the post-installation instruction from &lt;code&gt;libxml2&lt;/code&gt; to fix the path and environment variables.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;If you need to have libxml2 first in your PATH, run:
  echo &amp;#39;export PATH=&amp;quot;/usr/local/opt/libxml2/bin:$PATH&amp;quot;&amp;#39; &amp;gt;&amp;gt; ~/.zshrc

For compilers to find libxml2 you may need to set:
  export LDFLAGS=&amp;quot;-L/usr/local/opt/libxml2/lib&amp;quot;
  export CPPFLAGS=&amp;quot;-I/usr/local/opt/libxml2/include&amp;quot;

For pkg-config to find libxml2 you may need to set:
  export PKG_CONFIG_PATH=&amp;quot;/usr/local/opt/libxml2/lib/pkgconfig&amp;quot;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="compile"&gt;Compile&lt;/h2&gt;
&lt;p&gt;I configured my Emacs with the following options. I’m not exactly sure what each meant but this combination seems to work on my machine:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;--with-cairo&lt;/code&gt; - enable Cairo drawing&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--with-imagemagick&lt;/code&gt; - enable ImageMagick support&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--with-xwidgets&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--with-native-compilation&lt;/code&gt; - enable native compilation&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="sh"&gt;&lt;code&gt;./autogen.sh
./configure --with-cairo --with-imagemagick --with-xwidgets --with-native-compilation
# Build MacOS App bundle, `install` doesn’t actually install anything.
make clean install&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The Emacs.app App bundle should now be in the &lt;code&gt;nextstep/&lt;/code&gt; directory. Simply copy it to the &lt;code&gt;/Applications&lt;/code&gt; folder to use it.&lt;/p&gt;
&lt;h2 id="references"&gt;References&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stuff-things.net/2020/12/28/building-emacs-27-dot-1-on-macos-big-sur/"&gt;Building Emacs 27.1 on macOS Big Sur&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.freesteph.info/blog/compiling-emacs.html"&gt;Compiling Emacs in the absence of a configurable brew version&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="footnotes"&gt;Footnotes&lt;/h2&gt;
&lt;section class="footnotes" role="doc-endnotes"&gt;
&lt;hr /&gt;
&lt;ol&gt;
&lt;li id="fn1" role="doc-endnote"&gt;&lt;p&gt;Probably the popular options are: &lt;a href="https://bitbucket.org/mituharu/emacs-mac/src/master/"&gt;&lt;code&gt;emacs-mac&lt;/code&gt;&lt;/a&gt;, &lt;a href="https://github.com/d12frosted/homebrew-emacs-plus"&gt;&lt;code&gt;emacs-plus&lt;/code&gt;&lt;/a&gt;, and &lt;a href="https://github.com/daviderestivo/homebrew-emacs-head"&gt;&lt;code&gt;emacs-head&lt;/code&gt;&lt;/a&gt;. I was mostly using &lt;code&gt;emacs-mac&lt;/code&gt; in the past.&lt;a href="#fnref1" class="footnote-back" role="doc-backlink"&gt;↩︎&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content>
  </entry>
  <entry xml:lang="en">
    <id>https://dawranliou.com/blog/rethink-syntax-highlighting</id>
    <author>
      <name>Daw-Ran Liou</name>
    </author>
    <title>Rethink Syntax Highlighting</title>
    <updated>2020-11-06T00:00:00Z</updated>
    <published>2020-11-06T00:00:00Z</published>
    <link href="https://dawranliou.com/blog/rethink-syntax-highlighting" type="text/html"/>
    <content type="html">&lt;p&gt;&lt;em&gt;Update 2021-02-28: My color themes are now &lt;a href="https://github.com/dawranliou/sketch-themes"&gt;released&lt;/a&gt;! Check it out!&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="/images/sketch-theme-white.png" alt="My light editor theme" /&gt; &lt;em&gt;A screenshot of my current editor theme - sketch-white&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I’m a minimalist when it comes to how I like to highlight my code - my code editor is usually almost monochromatic, just black, white, three shades of gray, and an accent color like orange. If those colors sounds a lot to you, I have to assume you either are an extreme minimalist in code highlighting or you’ve never give code highlighting a second thought and just use whatever the theme creators throws at you. If you are the latter, this post is for you.&lt;/p&gt;
&lt;p&gt;&lt;img src="/images/sketch-theme-black.png" alt="My dark editor theme" /&gt; &lt;em&gt;A screenshot of my alternative editor theme - sketch-black&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;We live in a world of distractions. Everything is constantly trying to grab your attentions, your text messages, phone notifications, emails, social medias, ads, also your friends and families. It is because: your attentions are, indeed, valuable. We too often got distracted, not because we are bad at focusing, (maybe some of us are), but more importantly, the world around us is constantly demanding our attentions. When everything’s in focus, nothing actually is. When everything are signals, every one becomes a noise.&lt;/p&gt;
&lt;p&gt;Same as your code syntax highlighting. When every single text is highlighted with different colors, they are all just distractions and noises. Take a look at the &lt;a href="https://github.com/tonsky/vscode-theme-alabaster#motivation"&gt;Alabaster theme&lt;/a&gt; by &lt;a href="https://tonsky.me/"&gt;tonsky&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://raw.githubusercontent.com/tonsky/vscode-theme-alabaster/master/screenshot.png" alt="Alabaster theme screenshot" /&gt; &lt;em&gt;A screenshot of alabaster theme&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I like how the motivations describes:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Most color themes highlight everything they can, ending up looking like a fireworks show. Instead, Alabaster uses minimal highlighting; it defines just four classes: * Strings * All statically known constants (numbers, symbols, keywords, boolean values) * Comments * Global definitions&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This makes a lot of sense to me. The reason that we even need syntax highlighting to begin with is because we, the programmers rather than the machines, need to parse the text differently when we read it. For example, we don’t even need to parse the comments when reading code. Strings are in a sense very similar to code comments. Strings are usually for the end users, not the programmers. When I saw a string in code, I usually just skim through it and make a mental note that “there’s a string here.”&lt;/p&gt;
&lt;p&gt;Personally I don’t like to highlight numbers, symbols, and keywords in code because those to me are just parts of the code. I don’t want them to stand out too much because I still need to read them. I don’t need additional visual aids to help me understand they are different from the rest of the code. There used to be a time that I embolden the keywords and highlight the global definitions, but now I’ve made a conscious decision that leaving keywords unstyled works better for me. I do have global definitions embolden because I like them to stand out a little more.&lt;/p&gt;
&lt;p&gt;How I like to highlight my code aligns with how I think about code. Your mileage might vary. But remember this: less is more. The less colors you use will have greater impacts. Have some thoughts about your syntax highlighting. How do they help you in your work flow? Do you really need all the colors to help you program? It’s pretty easy to customize color themes and syntax highlighting for pretty much all the major code editors. Try building your own color theme if necessary.&lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;
</content>
  </entry>
  <entry xml:lang="en">
    <id>https://dawranliou.com/blog/structural-editing-in-vanilla-emacs</id>
    <author>
      <name>Daw-Ran Liou</name>
    </author>
    <title>Structural editing in vanilla Emacs</title>
    <updated>2021-10-23T00:00:00Z</updated>
    <published>2021-10-23T00:00:00Z</published>
    <link href="https://dawranliou.com/blog/structural-editing-in-vanilla-emacs" type="text/html"/>
    <content type="html">&lt;h2 id="strict-structural-editing"&gt;Strict structural editing&lt;/h2&gt;
&lt;p&gt;&lt;a href="/blog/back-to-paredit"&gt;Last time&lt;/a&gt; I switched from the &lt;a href="https://github.com/abo-abo/lispy"&gt;lispy&lt;/a&gt;/&lt;a href="https://github.com/noctuid/lispyville"&gt;lispyville&lt;/a&gt; combo for structural editing s-expressions to &lt;a href="https://www.emacswiki.org/emacs/ParEdit"&gt;paredit&lt;/a&gt; for its simplicity. However, I started to realize that I kept unbinding commands from the &lt;code&gt;paredit-mode-map&lt;/code&gt; such as &lt;code&gt;C-d&lt;/code&gt;, &lt;code&gt;C-k&lt;/code&gt; because they were unnecessarily restraining. Quote from this &lt;a href="https://www.reddit.com/r/emacs/comments/l7khmk/what_key_binding_scheme_do_you_use_to_handle/gl9fcqs?utm_source=share&amp;amp;utm_medium=web2x&amp;amp;context=3"&gt;reddit thread&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I tend to think that all of the slurping, burping, gurgling, snorting, and barfing, which devotees consider handy, are just contrivances to try to make a virtue out of necessity. From the moment that you’ve automatically, prematurely introduced a closing paren, you naturally find a need to try to find a way to work around it. If you don’t box yourself in, in the first place, then there’s no such need.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I still do premature paren closing with &lt;code&gt;electric-pair-mode&lt;/code&gt; in my current setup. However, this thread really got me thinking. &lt;em&gt;“Do I really want to have balanced parenthesis at all times, at all costs?”&lt;/em&gt; To answer the question, I ask myself: a) What problems does it solves, and b) What are the costs?&lt;/p&gt;
&lt;p&gt;To me, the main cost is the freedom of expressing experimental code as I laid out in the &lt;a href="back-to-paredit"&gt;Back to paredit&lt;/a&gt; post.&lt;/p&gt;
&lt;p&gt;I think the main problem it solves is to &lt;strong&gt;“Avoid uncompilable source files by accident.”&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;However, I don’t care much about this problem nowadays since I don’t often edit the source code line-by-line or character-by-character and unbalanced parens are rarely an issue. Whenever I do accidentally introduce unbalanced parens, I can usually quickly spot the error and fix it&lt;a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"&gt;&lt;sup&gt;1&lt;/sup&gt;&lt;/a&gt;. It isn’t very hard once I learn to navigate and edit S-exps, which I’ll show in the next section.&lt;/p&gt;
&lt;p&gt;From there, it’s a simple decision to ditch paredit and the strict structural editing rules it imposes and revise my workflow with vanilla Emacs commands.&lt;a href="#fn2" class="footnote-ref" id="fnref2" role="doc-noteref"&gt;&lt;sup&gt;2&lt;/sup&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="s-expression-workflow-in-vanilla-emacs"&gt;S-expression workflow in vanilla Emacs&lt;/h2&gt;
&lt;p&gt;For the code examples in the following sections, I’ll be using &lt;code&gt;&amp;lt;!&amp;gt;&lt;/code&gt; as the &lt;em&gt;point&lt;/em&gt;, also known as the &lt;em&gt;cursor&lt;/em&gt; or the &lt;em&gt;caret&lt;/em&gt;, and &lt;code&gt;&amp;lt;@&amp;gt;&lt;/code&gt; as the &lt;em&gt;mark&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id="navigate-s-exp"&gt;Navigate S-exp&lt;/h3&gt;
&lt;p&gt;Here are the ones I use most often: - &lt;code&gt;C-M-d&lt;/code&gt; - Go down the S-exp tree - &lt;code&gt;C-M-u&lt;/code&gt; - Go up the S-exp tree - &lt;code&gt;C-M-f&lt;/code&gt; - Go forward to the next S-exp at the same level - &lt;code&gt;C-M-b&lt;/code&gt; - Go backward to the previous S-exp at the same level - &lt;code&gt;C-M-a&lt;/code&gt; - Go to the start of the top-level S-exp (or the previous top-level S-exp) - &lt;code&gt;C-M-e&lt;/code&gt; - Go to the end of the top-level S-exp (or the next top-level S-exp)&lt;/p&gt;
&lt;p&gt;I don’t use these that often because they kinda overlap with &lt;code&gt;C-M-(f|b)&lt;/code&gt; in a way: - &lt;code&gt;C-M-n&lt;/code&gt; - Go to the next S-exp - &lt;code&gt;C-M-p&lt;/code&gt; - Go to the previous S-exp&lt;/p&gt;
&lt;p&gt;I often use the navigation commands to quickly put the point at the beginning of the S-exp or the end of the S-exp. This is quite important because the next few operations require the point to be at the right spot.&lt;/p&gt;
&lt;p&gt;Example (point is &lt;code&gt;&amp;lt;!&amp;gt;&lt;/code&gt;, mark is &lt;code&gt;&amp;lt;|&amp;gt;&lt;/code&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ (+ 1 2&amp;lt;!&amp;gt;) 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After hitting &lt;code&gt;C-M-u&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ &amp;lt;!&amp;gt;(+ 1 2) 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="mark-s-exp"&gt;Mark S-exp&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;C-M-&amp;lt;SPC&amp;gt;&lt;/code&gt; - &lt;code&gt;mark-sexp&lt;/code&gt; (Mark the S-exp after the point)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ &amp;lt;!&amp;gt;(+ 1 2) 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Hit &lt;code&gt;C-M-&amp;lt;SPC&amp;gt;&lt;/code&gt; the first time will mark the first S-exp following the point, i.e. &lt;code&gt;(+ 1 2)&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ &amp;lt;!&amp;gt;(+ 1 2)&amp;lt;@&amp;gt; 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Hit &lt;code&gt;C-M-&amp;lt;SPC&amp;gt;&lt;/code&gt; the second time will mark the next two S-exps, i.e. &lt;code&gt;(+ 1 2) 3&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ &amp;lt;!&amp;gt;(+ 1 2) 3&amp;lt;@&amp;gt; 4)&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="kill-s-exp"&gt;Kill S-exp&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;C-M-k&lt;/code&gt; - Kill S-exp after the point&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When I’m working on lispy languages, I rarely use &lt;code&gt;C-k&lt;/code&gt; to kill stuff. I use line-based navigation commands + the S-exp navigation commands to locate the opening paren than do &lt;code&gt;C-M-k&lt;/code&gt;. I found this method more precise than using &lt;code&gt;C-k&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ &amp;lt;!&amp;gt;(+ 1 2) 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After hitting &lt;code&gt;C-M-k&lt;/code&gt;,&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ &amp;lt;!&amp;gt; 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="drag-s-exp"&gt;Drag S-exp&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;C-M-t&lt;/code&gt; - Drag downward&lt;/li&gt;
&lt;li&gt;&lt;code&gt;C-M-- C-M-t&lt;/code&gt; - Drag upward&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Dragging downward is almost equivalent to transposing. The only difference is that transposing requires the point to be after the S-exp to be dragged downward.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ (+ 1 2)&amp;lt;!&amp;gt; 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After hitting &lt;code&gt;C-M-t&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ 3 (+ 1 2)&amp;lt;!&amp;gt; 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the case of dragging upward, I usually kill the S-exp and then yank it to the position I want. Alternatively, using the negative argument with transposing does it too.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ 3 (+ 1 2)&amp;lt;!&amp;gt; 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After hitting &lt;code&gt;C-M-- C-M-t&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ (+ 1 2)&amp;lt;!&amp;gt; 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="wrap-s-exp"&gt;Wrap S-exp&lt;/h3&gt;
&lt;p&gt;This requires the &lt;code&gt;electric-pair-mode&lt;/code&gt;. To do wrapping, I’ll place the point at the beginning of the S-exp(s) that I want to wrap, press &lt;code&gt;C-M-&amp;lt;SPC&amp;gt;&lt;/code&gt; to mark the following few S-exp(s), and then hit the opening paren &lt;code&gt;(&lt;/code&gt; (or &lt;code&gt;"&lt;/code&gt;, &lt;code&gt;[&lt;/code&gt;, &lt;code&gt;{&lt;/code&gt;) to wrap the S-exp.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ &amp;lt;!&amp;gt;(+ 1 2) 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Mark the next two S-exp by hitting &lt;code&gt;C-M-&amp;lt;SPC&amp;gt;&lt;/code&gt; twice&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ &amp;lt;!&amp;gt;(+ 1 2) 3&amp;lt;@&amp;gt; 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Hit &lt;code&gt;"&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ &amp;quot;&amp;lt;!&amp;gt;(+ 1 2) 3&amp;quot; 4)&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="raise-s-exp"&gt;Raise S-exp&lt;/h3&gt;
&lt;p&gt;By default, Emacs doesn’t bind the &lt;code&gt;raise-sexp&lt;/code&gt; to any keys. In my current setup, I bind this to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;C-M-r&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ &amp;lt;!&amp;gt;(+ 1 2) 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After hitting &lt;code&gt;C-M-r&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ 1 2)&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="splice-s-exp"&gt;Splice S-exp&lt;/h3&gt;
&lt;p&gt;Splicing is really a special case of raising S-exp - basically, it “raises” all the sibling S-exps. So my workflow is to use &lt;code&gt;C-M-&amp;lt;SPC&amp;gt;&lt;/code&gt; to select all the siblings and then hit &lt;code&gt;C-M-r&lt;/code&gt; to raise all of them.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ &amp;lt;!&amp;gt;(+ 1 2) 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Mark the next three S-exp with three &lt;code&gt;C-M-&amp;lt;SPC&amp;gt;&lt;/code&gt;s.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ &amp;lt;!&amp;gt;(+ 1 2) 3 4&amp;lt;@&amp;gt;)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Hit &lt;code&gt;C-M-r&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;!&amp;gt;(+ 1 2) 3 4&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id="slurp-barf"&gt;Slurp &amp;amp; barf&lt;/h3&gt;
&lt;p&gt;There are no equivalent commands out-of-the-box. However, I don’t miss those commands much. In the case of slurping, I can just remove the closing paren, forward one S-exp, and then insert the closing paren back:&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ (+ 1 2)&amp;lt;!&amp;gt; 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;DEL&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ (+ 1 2&amp;lt;!&amp;gt; 3 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;C-M-f&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ (+ 1 2 3&amp;lt;!&amp;gt; 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Insert &lt;code&gt;)&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(+ (+ 1 2 3)&amp;lt;!&amp;gt; 4)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Alternatively, kill the next S-exp and yank it before the closing paren.&lt;a href="#fn3" class="footnote-ref" id="fnref3" role="doc-noteref"&gt;&lt;sup&gt;3&lt;/sup&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="conclusion"&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I think the more I work on lispy languages, the better I become at working with S-exps. Previously, I had to rely on the external packages’ safety nets to edit the source code safely. Nowadays, I think I’m dangerous enough that I feel more productive without those safety nets. &#128520;&lt;/p&gt;
&lt;p&gt;I think my experiment so far has been a success. I’ve been using the revised workflows for my day-to-day work for a while, and vanilla Emacs is all I need to be productive at navigating and editing lispy code.&lt;a href="#fn4" class="footnote-ref" id="fnref4" role="doc-noteref"&gt;&lt;sup&gt;4&lt;/sup&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="footnotes"&gt;Footnotes&lt;/h2&gt;
&lt;section class="footnotes" role="doc-endnotes"&gt;
&lt;hr /&gt;
&lt;ol&gt;
&lt;li id="fn1" role="doc-endnote"&gt;&lt;p&gt;With the help of &lt;code&gt;M-x check-parens&lt;/code&gt; and &lt;code&gt;show-paren-mode&lt;/code&gt;.&lt;a href="#fnref1" class="footnote-back" role="doc-backlink"&gt;↩︎&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li id="fn2" role="doc-endnote"&gt;&lt;p&gt;I also came across the blog &lt;a href="https://andreyorst.gitlab.io/posts/2021-09-30-why-is-paredit-is-so-un-emacsy/"&gt;Why is Paredit is so un-Emacsy?&lt;/a&gt; after the switch. It’s a nice read! It kinda reassured me of my decision.&lt;a href="#fnref2" class="footnote-back" role="doc-backlink"&gt;↩︎&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li id="fn3" role="doc-endnote"&gt;&lt;p&gt;I might be able to write a function to automate slurping and barfing in the future. Stay tuned!&lt;a href="#fnref3" class="footnote-back" role="doc-backlink"&gt;↩︎&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li id="fn4" role="doc-endnote"&gt;&lt;p&gt;I also ditched evil-mode and learned code editing the Emacs way. That’s a story for another time.&lt;a href="#fnref4" class="footnote-back" role="doc-backlink"&gt;↩︎&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content>
  </entry>
  <entry xml:lang="en">
    <id>https://dawranliou.com/blog/back-to-paredit</id>
    <author>
      <name>Daw-Ran Liou</name>
    </author>
    <title>Back to paredit</title>
    <updated>2021-08-14T00:00:00Z</updated>
    <published>2021-08-14T00:00:00Z</published>
    <link href="https://dawranliou.com/blog/back-to-paredit" type="text/html"/>
    <content type="html">&lt;h2 id="to-simplify-my-s-exp-workflow"&gt;To simplify my s-exp workflow&lt;/h2&gt;
&lt;p&gt;I had been using &lt;a href="https://github.com/abo-abo/lispy"&gt;lispy&lt;/a&gt; and &lt;a href="https://github.com/noctuid/lispyville"&gt;lispyville&lt;/a&gt; for &lt;a href="/blog/my-emacs-clojure-dev-env-overview.md#lispy-lispyville-general-lisp-s-expression-editing"&gt;general s-expression editing and navigation&lt;/a&gt; previously. My setup works pretty well, but I often found the packages are a bit of a feature bloat. Plus, I don’t use most of the transitive dependencies (ace-window, counsel, ivy, swiper, hydra). Over time, I started to realize what I like or want and what I don’t care about for my workflow. I decided to switch to a lighter package to help me to build the workflow. So here we are, back to the good old &lt;a href="https://www.emacswiki.org/emacs/ParEdit"&gt;paredit&lt;/a&gt;, again, for its simplicity.&lt;/p&gt;
&lt;p&gt;Here’s a list of features I &lt;em&gt;actually&lt;/em&gt; want to use:&lt;/p&gt;
&lt;ol type="1"&gt;
&lt;li&gt;S-exp navigation&lt;/li&gt;
&lt;li&gt;Killing s-exp&lt;/li&gt;
&lt;li&gt;Closing parentheses automatically&lt;/li&gt;
&lt;li&gt;Slurping and barfing s-exp&lt;/li&gt;
&lt;li&gt;Wrapping and unwrapping (or splicing) s-exp&lt;/li&gt;
&lt;li&gt;Dragging (or transposing) s-exp&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Surprisingly, vanilla Emacs already supports half of the list! By default, &lt;code&gt;C-M-(f|b|u|d|n|p)&lt;/code&gt; bounds to the s-exp navigation commands; &lt;code&gt;C-M-k&lt;/code&gt; kills s-exp; &lt;code&gt;C-M-t&lt;/code&gt; transposes s-exp that acts sort of like dragging s-exps. So I only need paredit to fill in the rest of the list.&lt;/p&gt;
&lt;h2 id="to-not-handle-parentheses"&gt;To not-handle parentheses&lt;/h2&gt;
&lt;p&gt;I recently came across this &lt;a href="https://www.reddit.com/r/emacs/comments/l7khmk/what_key_binding_scheme_do_you_use_to_handle/gl9fcqs?utm_source=share&amp;amp;utm_medium=web2x&amp;amp;context=3"&gt;reddit thread&lt;/a&gt;, which gave me a new perspective about handling parentheses for lispy languages. Actually, it’s about how &lt;strong&gt;not&lt;/strong&gt; handling parentheses. The constraint of keeping parentheses balanced all the time is surprisingly unnecessary and restrictive. Without this constraint, I started finding myself enjoying a lot more freedom in my REPL workflow. For example, when I have the Clojure code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(-&amp;gt; data
    transform-1
    transform-2
    transform-3
    transform-4)

(let [a 1
      b 1
      c (+ a b)
      d (+ b c)
      e (+ c d)]
  ;; some more computation
  )&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To inspect the transformation, I can temporarily insert unbalanced closing parentheses and code and then evaluate the code by putting the point at &lt;code&gt;-!-&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(-&amp;gt; data
    transform-1
    transform-2)-!-  ; eval this s-exp
    transform-3
    transform-4)

(let [a 1
      b 1
      c (+ a b)] c)-!-  ; eval this s-exp
      d (+ b c)
      e (+ c d)]
  ;; some more computation
  )&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once I got the results, removing the temporary code is all it takes to have perfectly balanced parentheses again.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This is more or less the same as using &lt;code&gt;cider-eval-sexp-up-to-point&lt;/code&gt;, but I don’t want to memorize too many lesser-used keybindings. Plus, I prefer workflows that are more generic to other lispy languages.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;To do this, I unbound a couple of commands from the &lt;code&gt;paredit-mode-map&lt;/code&gt;, such as &lt;code&gt;C-d&lt;/code&gt; and &lt;code&gt;DEL&lt;/code&gt;. &lt;code&gt;C-k&lt;/code&gt; is sometimes useful to delete code in bulk, so I still keep it bind to the &lt;code&gt;paredit-kill&lt;/code&gt; command.&lt;/p&gt;
&lt;p&gt;However, unlike what the reddit thread mentioned, I still find automatically inserting paren pairs helpful. This is probably because I work a lot in Clojure, which considers square brackets &lt;code&gt;[]&lt;/code&gt; and curly braces &lt;code&gt;{}&lt;/code&gt; as valid s-exp as well as parentheses &lt;code&gt;()&lt;/code&gt;, so there are multiple ways to close an s-exp. Also, it’s one less keystroke to type &#128539;.&lt;/p&gt;
&lt;!--  LocalWords:  paredit lispy lispyville swiper exps
 --&gt;
</content>
  </entry>
  <entry xml:lang="en">
    <id>https://dawranliou.com/blog/my-emacs-clojure-dev-env-overview</id>
    <author>
      <name>Daw-Ran Liou</name>
    </author>
    <title>My Emacs Clojure Development Environment Overview</title>
    <updated>2020-11-12T00:00:00Z</updated>
    <published>2020-11-12T00:00:00Z</published>
    <link href="https://dawranliou.com/blog/my-emacs-clojure-dev-env-overview" type="text/html"/>
    <content type="html">&lt;h1 id="preface"&gt;Preface&lt;/h1&gt;
&lt;p&gt;To me, Emacs isn’t a text editor but rather an extremely flexible development environment that allows anyone to optimize their workflow. I used to be a Vim user and did everything inside the terminal: Vim for code editing, bash commands for running/testing code, and git cli for all other git operations. I wasn’t in any sense a Vim superuser. However, I felt pretty comfortable to do most of my day-to-day work inside the terminal.&lt;/p&gt;
&lt;p&gt;For the past two years, I got into the Clojure programming community and made a very audacious move to learn Emacs at the same time. To me, learning Emacs was just as hard, if not harder, as learning Clojure itself. However, learning either subjects has paid off far more than I had expected. In this post, I will share an overview of my current development environment setup and explain my rationale of some of the key bindings that I use.&lt;/p&gt;
&lt;h1 id="magit---git-porcelain"&gt;Magit - git porcelain&lt;/h1&gt;
&lt;p&gt;&lt;a href="https://magit.vc/"&gt;Magit&lt;/a&gt; is one of the most powerful powerful packages available on Emacs. It is also the package that made me rethink my entire workflow. If you don’t known, Magit is a git porcelain that makes all the fancy git operations within Emacs. I used to enjoy doing all git operations inside terminal. I rarely do it lately because of how great Magit is. If I were to stop using Emacs for writing code, I’d definitely continue using Magit until I find another comparable tool.&lt;/p&gt;
&lt;p&gt;I bind &lt;code&gt;magit-status&lt;/code&gt; to &lt;code&gt;command+g&lt;/code&gt; (also &lt;code&gt;&amp;lt;SPC&amp;gt; g g&lt;/code&gt; because of old habit using Doom Emacs.)&lt;/p&gt;
&lt;h1 id="cider---advanced-clojure-integrated-environment"&gt;Cider - advanced Clojure integrated environment&lt;/h1&gt;
&lt;p&gt;I use &lt;a href="https://cider.mx/"&gt;Cider&lt;/a&gt; to manage the nrepl sessions and to evaluate code. I used to rely on Cider for more things like looking up code definition but lately I’ve been experimenting that with &lt;code&gt;clojure-lsp&lt;/code&gt; which I’ll describe in the next section.&lt;/p&gt;
&lt;p&gt;I bind the Cider keys under a local leader key &lt;code&gt;&amp;lt;,&amp;gt;&lt;/code&gt;, which is only available in the clojure(script)-mode. This is a habit I developed during the time using Spacemacs and Doom Emacs though their keymaps are slightly different. Currently I only use it to evaluate code in three levels - to evaluate buffer, evaluate top-level vars, and evaluate s-expression. They are currently bound to &lt;code&gt;&amp;lt;,&amp;gt; e b&lt;/code&gt;, &lt;code&gt;&amp;lt;,&amp;gt; e f&lt;/code&gt;, and &lt;code&gt;&amp;lt;,&amp;gt; e e&lt;/code&gt;, which I’ll probably simplify by removing the middle &lt;code&gt;e&lt;/code&gt; later.&lt;/p&gt;
&lt;h1 id="lsp---code-jumping"&gt;LSP - code jumping&lt;/h1&gt;
&lt;p&gt;LSP is the text editor-agnostic protocol for IDE-like operations. It separates the concerns of those IDE-like capabilities and the actual implementation. For example, the LSP defines the capability of &lt;code&gt;textDocument/definition&lt;/code&gt; and the &lt;a href="https://github.com/snoe/clojure-lsp"&gt;clojure-lsp&lt;/a&gt; implements how to find the definition of a particular Clojure symbol. In Emacs, AFAIK there are two packages to support LSP interactions, &lt;a href="https://emacs-lsp.github.io/lsp-mode/"&gt;lsp-mode&lt;/a&gt; and &lt;a href="https://github.com/joaotavora/eglot"&gt;eglot&lt;/a&gt;. I’ve tried both in the past but I’m sticking with &lt;code&gt;lsp-mode&lt;/code&gt; at the moment.&lt;/p&gt;
&lt;p&gt;I bind &lt;code&gt;command+l&lt;/code&gt; to the lsp-keymap-prefix while I’m still learning it. So far I only need two functions: &lt;code&gt;lsp-find-definition&lt;/code&gt; and &lt;code&gt;lsp-find-references&lt;/code&gt; which are bound to &lt;code&gt;command+l g g&lt;/code&gt; and &lt;code&gt;command+l g r&lt;/code&gt; respectively. I’ll definitely re-bind those keys for easier access.&lt;/p&gt;
&lt;h1 id="lispy-lispyville---general-lisp-s-expression-editing"&gt;Lispy + Lispyville - general lisp s-expression editing&lt;/h1&gt;
&lt;p&gt;I use &lt;a href="https://github.com/abo-abo/lispy"&gt;Lispy&lt;/a&gt; and &lt;a href="https://github.com/noctuid/lispyville"&gt;Lispyville&lt;/a&gt; for most of the e-expression editing in Clojure mode instead of using smartparens or paredit or parinfer. I like the safe evil operations that are remapped by Lispyville so I don’t need to worry about unbalanced parens. However, I don’t use a lot of the keys other than slurping, barfing, and dragging s-expressions.&lt;/p&gt;
&lt;h1 id="dired---file-management"&gt;Dired - file management&lt;/h1&gt;
&lt;p&gt;I bind dired to &lt;code&gt;&amp;lt;SPC&amp;gt; d&lt;/code&gt; with just two key strokes for easier access. Dired mode was a powerful package that I overlooked for so long. It finally came into my radar thanks to the amazing &lt;a href="https://youtu.be/PMWwM8QJAtU"&gt;video&lt;/a&gt; by &lt;a href="https://twitter.com/daviwil"&gt;David Wilson&lt;/a&gt;. Dired was truly a missing piece in my workflow centered around Emacs. Having the ability to browse the filesystem naturally inside the Emacs buffer was absolutely a joy.&lt;/p&gt;
&lt;h1 id="eshell---direct-shell-access"&gt;Eshell - direct shell access&lt;/h1&gt;
&lt;p&gt;This is bound to &lt;code&gt;&amp;lt;SPC&amp;gt; e&lt;/code&gt; also for easier access. With all the packages above, there are rarely things I need to do directly in shell. For those things that has to be done inside shell, I usually do it in Eshell. However, there are times I do need something closer to the native terminal app on OSX, something I can start a long running process and bury it in the background. In these cases I’ll launch vterm instead. However, for some those off tasks like compiling code or start a docker container in the background, I prefer Eshell.&lt;/p&gt;
&lt;p&gt;Links: - &lt;a href="https://github.com/dawranliou/emacs.d"&gt;My current Emacs Config&lt;/a&gt; - &lt;a href="https://magit.vc/"&gt;Magit&lt;/a&gt; - &lt;a href="https://cider.mx/"&gt;Cider&lt;/a&gt; - &lt;a href="https://github.com/snoe/clojure-lsp"&gt;clojure-lsp&lt;/a&gt; - &lt;a href="https://emacs-lsp.github.io/lsp-mode/"&gt;lsp-mode&lt;/a&gt; - &lt;a href="https://github.com/joaotavora/eglot"&gt;eglot&lt;/a&gt; - &lt;a href="https://github.com/abo-abo/lispy"&gt;Lispy&lt;/a&gt; - &lt;a href="https://github.com/noctuid/lispyville"&gt;Lispyville&lt;/a&gt; - &lt;a href="https://twitter.com/daviwil"&gt;David Wilson&lt;/a&gt; - &lt;a href="https://www.youtube.com/c/SystemCrafters/videos"&gt;System Crafters&lt;/a&gt;&lt;/p&gt;
</content>
  </entry>
  <entry xml:lang="en">
    <id>https://dawranliou.com/blog/learning-clojure-and-emacs</id>
    <author>
      <name>Daw-Ran Liou</name>
    </author>
    <title>My personal experience to learn Clojure and Emacs together</title>
    <updated>2021-07-19T00:00:00Z</updated>
    <published>2021-07-19T00:00:00Z</published>
    <link href="https://dawranliou.com/blog/learning-clojure-and-emacs" type="text/html"/>
    <content type="html">&lt;p&gt;I recently made a bit lengthy response in the Clojureverse discussion on the topic &lt;a href="https://clojureverse.org/t/gnu-emacs-cider-vs-vs-code-calva/7829"&gt;“GNU Emacs + Cider vs VS Code + Calva”&lt;/a&gt;. To summarize:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I recommend learning Emacs.&lt;/li&gt;
&lt;li&gt;I recommend learning Emacs and Clojure at the same time. It’s going to be very challenging and fun and rewarding.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Quote:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Hi, I just want to provide another data point here. I started learning Clojure using my own free time back in 2018Q3 while having a full-time software engineering job in Java + Python. I picked up Emacs (Spacemacs at the time) around 2018Q4 for no particular reason other than I always gravitate toward ancient technologies. There’s just something about the aesthetics that I love about old technologies. I watched a few Clojure talks using Emacs on YouTube at the time and thought Emacs was pretty cool, and thought I wanted to be like those Clojure Emacs people. I was fairly fluent in Vim keybindings before that, so Spacemacs made the transition a bit easier.&lt;/p&gt;
&lt;p&gt;There were lots of challenges to overcome to learn Clojure and Emacs at the same time. And oh boy, that was a lot of fun! I think both learning Clojure and learning Emacs are very rewarding experiences to me. The more time I spent on it, the more knowledge I gained, the more powerful I felt. I really think Clojure and Emacs are the two best things ever happen to my developer career so far.&lt;/p&gt;
&lt;p&gt;I’d say that I got pretty fluent in Clojure by 2019Q4 when I got my first and current Clojure full-time position but was still a beginner Emacs. Today, I feel pretty comfortable rocking my own Emacs configuration without using any off-the-shelve Emacs distribution. I can read and write ELisp code (but not so fluently) and know a couple of tricks to debug/troubleshoot issues with 3rd party packages.&lt;/p&gt;
&lt;p&gt;One benefit I found from learning Clojure and Emacs(Lisp) at the same time is that many of the concepts are transferable to one another. For example, the REPL driven development I love doing in Clojure is right there for you in Emacs, a highly moldable and inspectable Lisp machine like your Clojure REPL. Also, I couldn’t grasp the idea of dynamic vars in Clojure until I learned it from Emacs Lisp.&lt;/p&gt;
&lt;p&gt;I know that the general sentiment towards Emacs is that it is too hard, and I get that. But I mean, what’s fun in learning it if it’s just easy? After using Emacs as my daily driver for almost 3 years, I am still having fun learning bits and bits about Emacs.&lt;/p&gt;
&lt;/blockquote&gt;
</content>
  </entry>
  <entry xml:lang="en">
    <id>https://dawranliou.com/blog/xref-with-eglot-and-project</id>
    <author>
      <name>Daw-Ran Liou</name>
    </author>
    <title>Don't kill my xref buffers</title>
    <updated>2023-02-12T00:00:00Z</updated>
    <published>2023-02-12T00:00:00Z</published>
    <link href="https://dawranliou.com/blog/xref-with-eglot-and-project" type="text/html"/>
    <content type="html">&lt;p&gt;I like buffers.&lt;/p&gt;
&lt;p&gt;When I first started using Emacs, I used to feel paranoid about keeping too many buffers. Nowadays, I don't even notice the hundreds or thousands of buffers buried in Emacs.&lt;/p&gt;
&lt;p&gt;I like &lt;code class="verbatim"&gt;xref&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The built-in package, &lt;code class="verbatim"&gt;xref&lt;/code&gt;, is an essential part of my workflow at Kira Systems (now acquired by Litera). We use a monorepo setup for our flagship Machine Learning contract analysis SaaS product written in Clojure and Go. It's crucial for my day-to-day work to be able to do project-wide searches for references. I use the &lt;code&gt;project-find-regexp&lt;/code&gt; (a command from the built-in package, &lt;code class="verbatim"&gt;project.el&lt;/code&gt;, bound to &lt;code class="verbatim"&gt;C-x p g&lt;/code&gt;) to find matches for references in both Clojure and Go code. If I'm only interested in the Clojure source code, I can use &lt;code&gt;xref-find-references&lt;/code&gt; (bound to &lt;code class="verbatim"&gt;M-?&lt;/code&gt;) to find all references with &lt;code class="verbatim"&gt;eglot&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;There's one problem. &lt;code class="verbatim"&gt;xref&lt;/code&gt; doesn't like buffers.&lt;/p&gt;
&lt;p&gt;Or every time the commands invokes &lt;code class="verbatim"&gt;xref&lt;/code&gt;, they reuse the &lt;code class="verbatim"&gt;*xref*&lt;/code&gt; buffer and effectively destroyed the results of the previous reference search.&lt;/p&gt;
&lt;p&gt;Of course, this is Emacs. We can configure it ourselves. All it requires is a little gentle advice:&lt;/p&gt;
&lt;pre class="commonlisp" data-org-language="emacs-lisp"&gt;&lt;code&gt;(with-eval-after-load &amp;#39;project
  (defun project-find-regexp-with-unique-buffer (orig-fun &amp;amp;rest args)
    &amp;quot;An advice function that gives project-find-regexp a unique buffer name&amp;quot;
    (require &amp;#39;xref)
    (let ((xref-buffer-name (format &amp;quot;%s %s&amp;quot; xref-buffer-name (car args))))
      (apply orig-fun args)))

  (advice-add &amp;#39;project-find-regexp :around
              #&amp;#39;project-find-regexp-with-unique-buffer))
&lt;/code&gt;&lt;/pre&gt;
&lt;pre class="commonlisp" data-org-language="emacs-lisp"&gt;&lt;code&gt;(with-eval-after-load &amp;#39;eglot
  (defun xref-find-references-with-eglot (orig-fun &amp;amp;rest args)
    &amp;quot;An advice function that gives xref-find-definitions a unique
buffer name when eglot is enabled.&amp;quot;
    (if (bound-and-true-p eglot--managed-mode)
        (let ((xref-buffer-name (format &amp;quot;%s %s&amp;quot;
                                        xref-buffer-name
                                        (symbol-at-point))))
          (apply orig-fun args))
      (apply orig-fun args)))

  (advice-add &amp;#39;xref-find-references :around
              #&amp;#39;xref-find-references-with-eglot))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By leveraging Emacs's advice-function facility and dynamic scoping, the Elisp code above customize the existing &lt;code&gt;project-find-regexp&lt;/code&gt; and &lt;code&gt;xref-find-references&lt;/code&gt; to use a more descriptive buffer name for each invocation. The result is that I get to keep multiple &lt;code class="verbatim"&gt;xref&lt;/code&gt; reference buffers till I finish using those.&lt;/p&gt;
&lt;p&gt;The configurability of Emacs is often brought up as the top reason to use Emacs. Yes, it took some time to traverse the source code of &lt;code class="verbatim"&gt;eglot.el&lt;/code&gt;, &lt;code class="verbatim"&gt;package.el&lt;/code&gt;, and &lt;code class="verbatim"&gt;xref.el&lt;/code&gt;. Still, the customization described in this article can be done without a deep knowledge of the Emacs source code or individual packages.&lt;/p&gt;
&lt;p&gt;To me, this article is a perfect example of how Emacs adapts to the user's workflows instead of forcing the user to adapt to the editor's (or package authors') ideology. I hope this short article inspires you to start customizing your Emacs experience. Cheers! :)&lt;/p&gt;
</content>
  </entry>
  <entry xml:lang="en">
    <id>https://dawranliou.com/blog/from-vim-to-emacs</id>
    <author>
      <name>Daw-Ran Liou</name>
    </author>
    <title>From Vim to Emacs</title>
    <updated>2020-04-06T00:00:00Z</updated>
    <published>2020-04-06T00:00:00Z</published>
    <link href="https://dawranliou.com/blog/from-vim-to-emacs" type="text/html"/>
    <content type="html">&lt;p&gt;I was a Vim user a couple years back. I totally loved (and still love) the philosophy of Vim as well as the &lt;code&gt;hjkl&lt;/code&gt; navigation. In contrast, Emacs didn’t make any sense to me. &lt;code&gt;C-v&lt;/code&gt; for page down and &lt;code&gt;M-v&lt;/code&gt; for page up? Does that even make any sense to anyone?&lt;/p&gt;
&lt;p&gt;Yet here I am, after all those years, writing this article on my Emacs with all the keybinding craziness. I must confess, I enjoy Emacs quite a lot. However, the transition wasn’t easy for me. Here’s my journey so far.&lt;/p&gt;
&lt;!-- more --&gt;
&lt;h2 id="the-start-of-the-cycle"&gt;The start of the cycle&lt;/h2&gt;
&lt;p&gt;&lt;img src="//imgs.xkcd.com/comics/lisp_cycles.png" title="I've just received word that the Emperor has dissolved the MIT computer science program permanently." alt="Lisp Cycles"&gt;&lt;/p&gt;
&lt;p&gt;In the mid 2018 I started teaching myself Clojure, a dialect of the Lisp family. I fell in love with the language but the thing that amazed me the most, was how the Clojure community do all the amazing presentations using Emacs. “Well,” I told myself, “maybe it’s time to finally see the other side of the Vim vs Emacs Editor War.”&lt;/p&gt;
&lt;p&gt;I learned the basics from the &lt;a href="https://www.braveclojure.com/basic-emacs/"&gt;Clojure for the Brave and True&lt;/a&gt; website, It turned out that learning Clojure and Emacs at the same time was too audacious for me at the time. Clojure itself alone already has a pretty steep learning curve. And then there was Emacs… I took a more strategic route and focus on Clojure solely for a while (using both VSCode and IntelliJ.) It was fine at the time (because I didn’t know what I was missing.)&lt;/p&gt;
&lt;p&gt;Only knowing the foundamentals of Clojure, I started working on opensource projects to gain more real world experiences. It was then I was introduced to Spacemacs.&lt;/p&gt;
&lt;h2 id="into-the-space"&gt;Into the Space&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://www.spacemacs.org/"&gt;Spacemacs&lt;/a&gt;, on the website:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Spacemacs is a new way to experience Emacs – a sophisticated and polished set-up focused on ergonomics, mnemonics and consistency.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;To me, the main selling point was the exceptional out-of-box configuration. The layer system makes adding packages almost no-brainers. And plus, I didn’t need to give up my Vim keybindings! Spacemacs truely made me start liking Emacs and wanted to explore more aspects of Emacs.&lt;/p&gt;
&lt;p&gt;After learning a few basics, I was able to get pretty productive using Spacemacs and started understanding the superpower of Clojure, the REPL + Editor integration workflow. The “mnemonics” aspect of Spacemacs also made discovering and memorizing the useful functionalities so much easier.&lt;/p&gt;
&lt;p&gt;I also made a switch to the &lt;code&gt;develop&lt;/code&gt; branch of Spacemacs at the time because of a lot of the features and customizations can only be done there. I was learning quite a bit from both the official documentation and from &lt;a href="https://practicalli.github.io/spacemacs/"&gt;Practicalli’s spacemacs tutorial.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Then, it was the late 2019’s that I started my first professional job as a Clojure/Script developer. During the first week at work I saw my collegue’s minimalistic Emacs &lt;code&gt;init.el&lt;/code&gt; file that also uses evil-mode (which is the configuration that gives you the access to all the Vim keybindings.) I was pretty amazed by it.&lt;/p&gt;
&lt;p&gt;Using Clojure and Spacemacs day in and day out, I wasn’t completely satisfied with the fact that I can only understand Emacs through the lense of Spacemacs. And so, just last week, I started diving into Emacs.&lt;/p&gt;
&lt;h2 id="embracing-the-evil"&gt;Embracing the Evil&lt;/h2&gt;
&lt;p&gt;Aaron Bieber has a great talk on &lt;a href="https://youtu.be/JWD1Fpdd4Pc"&gt;“Evil Mode: Or, How I Learned to Stop Worrying and Love Emacs”&lt;/a&gt;. He helped me to set the right mindset from the start. I don’t really want to ditch all the keybindings, just yet. I also watched a lot of &lt;a href="https://cestlaz.github.io/stories/emacs/"&gt;Mike Zamansky’s Emacs tutorials&lt;/a&gt;. It felt like an achievable goal to recreate the Spacemacs experiences myself.&lt;/p&gt;
&lt;p&gt;Actually, someone has already done it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://youtu.be/6INMXmsCCC8"&gt;Suyash Bire talked about Spin Your Own Spacemacs-lite&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://sam217pa.github.io/2016/09/02/how-to-build-your-own-spacemacs"&gt;Bacterial Finches wrote about How to build your own spacemacs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;And here’s a repo for &lt;a href="https://github.com/balaramadurai/.emacs.d"&gt;Spacemacs-Lite&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Those resources are awesome. They gave me so much hope that I knew my goal of making my own mini Spacemacs was an achievable project.&lt;/p&gt;
&lt;p&gt;I really learned a lot in this stage. One of the most important lessons I learned is:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Emacs is a self-documenting editor&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Instead of needing to go to Google to search for answers, Emacs has all those things built-in for you. Just like Clojure, I was given the tool I need to solve my problems. Learning a few commands and I was very well-suited to troubleshoot my editor. This is very powerful.&lt;/p&gt;
&lt;p&gt;So far I’ve got most of the things I want working. You can check out the code &lt;a href="https://github.com/dawranliou/emacs.d/blob/master/init.el"&gt;here&lt;/a&gt;. Currently it’s about 500 LOC and I wrote every line of the code. I feel very good about it. If something isn’t working right, I know where to fix it (most of the time.)&lt;/p&gt;
&lt;h2 id="to-infinity-and-beyond"&gt;To infinity and beyond&lt;/h2&gt;
&lt;p&gt;Emacs is truely an amazing piece of software that I had so much fun with. The reason it pushed me away in the first place was its out-of-box configuration. It required me to have opinions on almost every aspect of the editor on day one, and this intimidated me.&lt;/p&gt;
&lt;p&gt;Spacesmacs was a godsend for me when I needed it the most. Till today, the way of Spacesmacs influences a lot of my opinion toward my Emacs configurations. I’m not giving up the things I like about Spacesmacs.&lt;/p&gt;
&lt;p&gt;However, will I ever ditch Evil mode and embrace the holly form of Emacs? Maybe.&lt;/p&gt;
</content>
  </entry>
  <entry xml:lang="en">
    <id>https://dawranliou.com/blog/on-learning-emacs</id>
    <author>
      <name>Daw-Ran Liou</name>
    </author>
    <title>On Learning Emacs</title>
    <updated>2020-11-13T00:00:00Z</updated>
    <published>2020-11-13T00:00:00Z</published>
    <link href="https://dawranliou.com/blog/on-learning-emacs" type="text/html"/>
    <content type="html">&lt;figure&gt;
&lt;img src="/images/emacs_learning_curves.png" alt="Classical learning curves for some common editors" /&gt;&lt;figcaption aria-hidden="true"&gt;Classical learning curves for some common editors&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;em&gt;Classical learning curves for some common editors&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I once came across a Tweet telling people how to use Emacs like this: step 1, download Emacs; step 2, spend the next 10 years configuring it. At first, this seems pretty silly, yet, there are some truths in it. I, for one, didn’t spend 10 years before becoming comfortable using Emacs as my daily driving horse in software development. However, I could very well imagine that after 10 years I’d still be tinkering my Emacs config with a sense of satisfaction.&lt;/p&gt;
&lt;p&gt;In retrospect, I found it amusing that both of my two favorite tools in software development, i.e. Clojure and Emacs, don’t seem to care much about the friendliness for newcomers. Yes, the community is very welcoming. However, the tools themselves are pretty demanding for the newcomers. Clojure required a huge leap of faith to unlearn most of my previous OOP experiences, whereas Emacs required me to design my own text editor from scratch and to have some understanding of the ELisp programming language. Neither of them promise newcomers to “hit the ground running” or “learn it over the weekend”.&lt;/p&gt;
&lt;p&gt;In my observation, the whole software industry puts too much spotlight on “the latest and the greatest” things. FOMO, the fear of missing out, has fueled a culture of desiring speed. The easiness of learning has become an advertising term for many of the software tools such as libraries and languages. However, &lt;strong&gt;the effectiveness of a tool would eventually outweigh the difficulty to learn it in the long run&lt;/strong&gt;. If I saved myself 15 minutes for using Emacs every day at work, I already saved myself 65 hours last year. That is almost three extra days an year. Even if I initially had spent a full week do nothing but learning Emacs, I would still start seeing the payoffs in the third year, as well as the rest of my life. The math isn’t really important here. To be honest with you, I don’t think I merely saved 15 minutes a day for using Emacs. The important thing is this - the ROI of learning a new tool is a long game. The longer you stick with it, the less significant the initial investment is. What’s more important is the capability of the tool itself.&lt;/p&gt;
&lt;p&gt;That brings me to the next key point: &lt;strong&gt;Emacs isn’t just a text editor.&lt;/strong&gt; Some people think Emacs as their operating system. I like to think &lt;strong&gt;Emacs as an integrated development environment&lt;/strong&gt;. Modern software development usually involves multiple tools: text editor, compiler, interpreter, repl, test runner, version control system, database client, or the browser. Every project is different and there is no one single IDE will meet all needs. We reach different tools for different purposes and inevitably are forced to make context switches. Context switches break our development flow. It’s draining for me to constantly reaching for a different tool with different key bindings or requires me to use the mouse. I really would prefer to stay inside one tool with the same universal key bindings all the time.&lt;/p&gt;
&lt;p&gt;When I started off learning Emacs, I tried to find the best and most conventional way to set it up. I was also feeling wrong for using the Vim key bindings rather than the default Emacs key bindings. This idea seems silly to me now for &lt;strong&gt;there should be no one true way of using Emacs&lt;/strong&gt;. Every one is using Emacs differently, with different background, under different context. I use a different keyboard than most people I know. I have a &lt;a href="https://ergodox-ez.com/pages/planck"&gt;Planck&lt;/a&gt; keyboard that only has 50 keys. A lot of the special characters I cannot type without a modifier key already. I couldn’t afford to hit a key chord that requires hitting multiple modifier keys plus a special character. Something like &lt;code&gt;C-M-$&lt;/code&gt; would be pretty humanly impossible to press with one hand. I’m glad Emacs is flexible enough to fit my needs.&lt;/p&gt;
&lt;p&gt;To recap, here’s my key points: 1. The effectiveness of a tool would eventually outweigh the difficulty to learn it in the long run. 1. Emacs is an integrated development environment rather than a text editor. 1. There’s no one true way of using Emacs.&lt;/p&gt;
</content>
  </entry>
</feed>
