<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Programming on Manuel Herrmann</title>
    <link>https://blog.0x17.de/tags/programming/</link>
    <description>Recent content in Programming on Manuel Herrmann</description>
    <image>
      <title>Manuel Herrmann</title>
      <url>https://blog.0x17.de/images/mh.jpg</url>
      <link>https://blog.0x17.de/images/mh.jpg</link>
    </image>
    <generator>Hugo -- 0.131.0</generator>
    <language>en</language>
    <lastBuildDate>Sat, 29 Mar 2025 00:00:00 +0100</lastBuildDate>
    <atom:link href="https://blog.0x17.de/tags/programming/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Getting Started with Emacs Lisp: Core Concepts Explained</title>
      <link>https://blog.0x17.de/post/emacs-list-introduction/</link>
      <pubDate>Sat, 29 Mar 2025 00:00:00 +0100</pubDate>
      <guid>https://blog.0x17.de/post/emacs-list-introduction/</guid>
      <description>Emacs Lisp (often abbreviated as Elisp) is the programming language that powers the extensibility of the Emacs text editor. It&amp;rsquo;s a dialect of Lisp that has been adapted specifically for text editing tasks. While it might look unusual at first glance, understanding a few key concepts opens up a world of possibilities for customizing your Emacs experience.
In this article, we&amp;rsquo;ll explore some of the fundamental concepts in Emacs Lisp that often confuse newcomers.</description>
      <content:encoded><![CDATA[<p>Emacs Lisp (often abbreviated as Elisp) is the programming language that powers the extensibility of the Emacs text editor. It&rsquo;s a dialect of Lisp that has been adapted specifically for text editing tasks. While it might look unusual at first glance, understanding a few key concepts opens up a world of possibilities for customizing your Emacs experience.</p>
<p><img alt="elisp" loading="lazy" src="/post/emacs-list-introduction/elisp.png"></p>
<p>In this article, we&rsquo;ll explore some of the fundamental concepts in Emacs Lisp that often confuse newcomers.</p>
<h2 id="variables-global-vs-local-scope">Variables: Global vs Local Scope</h2>
<p>Elisp provides several ways to define variables, each with different scoping behaviors.</p>
<h3 id="setq-global-variables"><code>setq</code>: Global Variables</h3>
<p>The <code>setq</code> function is used to define and set global variables:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span>(setq my-variable <span style="color:#e6db74">&#34;Hello, world!&#34;</span>)
</span></span></code></pre></div><p>These variables are accessible from anywhere in your Emacs session once defined. They&rsquo;re ideal for configuration settings or values that need to persist.</p>
<h3 id="let-and-let-local-variables"><code>let</code> and <code>let*</code>: Local Variables</h3>
<p>For variables with limited scope, Elisp provides <code>let</code> and <code>let*</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span><span style="color:#75715e">;; Using let for local binding</span>
</span></span><span style="display:flex;"><span>(let ((x <span style="color:#ae81ff">5</span>)
</span></span><span style="display:flex;"><span>      (y <span style="color:#ae81ff">10</span>))
</span></span><span style="display:flex;"><span>  (<span style="color:#a6e22e">message</span> <span style="color:#e6db74">&#34;Sum: %d&#34;</span> (<span style="color:#a6e22e">+</span> x y)))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">;; x and y are not accessible here</span>
</span></span></code></pre></div><p>The difference between <code>let</code> and <code>let*</code> is significant:</p>
<ul>
<li><code>let</code> evaluates all variable expressions before binding</li>
<li><code>let*</code> evaluates in sequence, allowing later variables to reference earlier ones</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span><span style="color:#75715e">;; This won&#39;t work with let</span>
</span></span><span style="display:flex;"><span>(let ((x <span style="color:#ae81ff">5</span>)
</span></span><span style="display:flex;"><span>      (y (<span style="color:#a6e22e">+</span> x <span style="color:#ae81ff">2</span>)))  <span style="color:#75715e">; Error: x is not yet bound when this is evaluated</span>
</span></span><span style="display:flex;"><span>  (<span style="color:#a6e22e">message</span> <span style="color:#e6db74">&#34;y: %d&#34;</span> y))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">;; This works with let*</span>
</span></span><span style="display:flex;"><span>(let* ((x <span style="color:#ae81ff">5</span>)
</span></span><span style="display:flex;"><span>       (y (<span style="color:#a6e22e">+</span> x <span style="color:#ae81ff">2</span>)))  <span style="color:#75715e">; Works because x is already bound</span>
</span></span><span style="display:flex;"><span>  (<span style="color:#a6e22e">message</span> <span style="color:#e6db74">&#34;y: %d&#34;</span> y))  <span style="color:#75715e">; Output: &#34;y: 7&#34;</span>
</span></span></code></pre></div><h2 id="understanding-quote-">Understanding Quote (<code>'</code>)</h2>
<p>One of the most distinctive features of Lisp is the quote character (<code>'</code>). It prevents evaluation of an expression, instead treating it as data.</p>
<h3 id="quoting-variables">Quoting Variables</h3>
<p>When you place a quote in front of a symbol:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span><span style="color:#e6db74">&#39;my-symbol</span>
</span></span></code></pre></div><p>You&rsquo;re telling Elisp, &ldquo;Don&rsquo;t evaluate this symbol, just give me the symbol itself.&rdquo; This is similar to references in other programming languages.</p>
<p>Without the quote, Elisp would try to look up the value of the variable <code>my-symbol</code>.</p>
<h3 id="list-syntax--vs-list--and-cons-">List Syntax: <code>'(...)</code> vs <code>(list ...)</code> and <code>(cons ...)</code></h3>
<p>Lists are fundamental data structures in Lisp. There are several ways to create them:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span><span style="color:#75715e">;; These are equivalent:</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&#39;</span>(a b c)
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">list</span> <span style="color:#e6db74">&#39;a</span> <span style="color:#e6db74">&#39;b</span> <span style="color:#e6db74">&#39;c</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">;; These are also equivalent:</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&#39;</span>(a <span style="color:#f92672">.</span> b)
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">cons</span> <span style="color:#e6db74">&#39;a</span> <span style="color:#e6db74">&#39;b</span>)
</span></span></code></pre></div><p>The quoted form <code>'(...)</code> is concise but has a limitation: everything inside is automatically quoted. This means you can&rsquo;t mix evaluated and non-evaluated expressions.</p>
<p>When to use each:</p>
<ul>
<li>Use <code>'(...)</code> for literal lists that don&rsquo;t need evaluation</li>
<li>Use <code>(list ...)</code> when you need to mix literals and evaluated expressions:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span>(setq name <span style="color:#e6db74">&#34;John&#34;</span>)
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">list</span> <span style="color:#e6db74">&#39;person</span> name <span style="color:#e6db74">&#39;age</span> <span style="color:#ae81ff">30</span>)  <span style="color:#75715e">; =&gt; (person &#34;John&#34; age 30)</span>
</span></span></code></pre></div><h2 id="understanding-cons-cells-car-and-cdr">Understanding Cons Cells: CAR and CDR</h2>
<p>At the heart of Lisp&rsquo;s data structures is the &ldquo;cons cell&rdquo; - a simple pair of values. Each cons cell has two parts, traditionally accessed with the functions <code>car</code> and <code>cdr</code> (pronounced &ldquo;could-er&rdquo;):</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span>(setq my-pair (<span style="color:#a6e22e">cons</span> <span style="color:#e6db74">&#39;a</span> <span style="color:#e6db74">&#39;b</span>))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">car</span> my-pair)  <span style="color:#75715e">; =&gt; a</span>
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">cdr</span> my-pair)  <span style="color:#75715e">; =&gt; b</span>
</span></span></code></pre></div><p>These peculiarly named functions are historical artifacts from the original Lisp implementation on IBM machines:</p>
<ul>
<li><code>car</code>: Contents of the Address part of Register</li>
<li><code>cdr</code>: Contents of the Decrement part of Register</li>
</ul>
<p>In modern terms, think of them as:</p>
<ul>
<li><code>car</code>: head (first element)</li>
<li><code>cdr</code>: tail (rest of the list)</li>
</ul>
<p>Lists in Lisp are actually chains of cons cells that always terminate with <code>nil</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span><span style="color:#75715e">;; This list:</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&#39;</span>(<span style="color:#ae81ff">1</span> <span style="color:#ae81ff">2</span> <span style="color:#ae81ff">3</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">;; Is actually structured as:</span>
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">cons</span> <span style="color:#ae81ff">1</span> (<span style="color:#a6e22e">cons</span> <span style="color:#ae81ff">2</span> (<span style="color:#a6e22e">cons</span> <span style="color:#ae81ff">3</span> <span style="color:#66d9ef">nil</span>)))
</span></span></code></pre></div><p>Visualized as pairs:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-fallback" data-lang="fallback"><span style="display:flex;"><span>(1 . (2 . (3 . nil)))
</span></span></code></pre></div><p>This implicit <code>nil</code> at the end is crucial - it&rsquo;s what defines a &ldquo;proper list&rdquo; in Lisp. Without this nil termination, you would have a different data structure. The presence of this nil terminator is what allows functions like <code>length</code> to work properly and what lets Lisp know where a list ends.</p>
<p>You can extract elements from lists using these functions:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span>(setq numbers <span style="color:#f92672">&#39;</span>(<span style="color:#ae81ff">1</span> <span style="color:#ae81ff">2</span> <span style="color:#ae81ff">3</span> <span style="color:#ae81ff">4</span>))
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">car</span> numbers)       <span style="color:#75715e">; =&gt; 1</span>
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">cdr</span> numbers)       <span style="color:#75715e">; =&gt; (2 3 4)</span>
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">car</span> (<span style="color:#a6e22e">cdr</span> numbers)) <span style="color:#75715e">; =&gt; 2</span>
</span></span></code></pre></div><p>Elisp provides convenient shorthand functions like <code>cadr</code> (car of cdr) for common combinations:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span>(cadr numbers)      <span style="color:#75715e">; =&gt; 2 (same as (car (cdr numbers)))</span>
</span></span><span style="display:flex;"><span>(caddr numbers)     <span style="color:#75715e">; =&gt; 3 (car of cdr of cdr)</span>
</span></span></code></pre></div><h2 id="the-dot-syntax-in-pairs">The Dot Syntax in Pairs</h2>
<p>In Emacs Lisp, you might encounter constructs with dot notation like:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span>(add-to-list <span style="color:#e6db74">&#39;auto-mode-alist</span> <span style="color:#f92672">&#39;</span>(<span style="color:#e6db74">&#34;\\.md\\&#39;&#34;</span> <span style="color:#f92672">.</span> markdown-mode))
</span></span></code></pre></div><p>This dot notation represents a &ldquo;cons cell&rdquo; or pair. In this example, we&rsquo;re creating a pair where the car is <code>&quot;\\.md\\'&quot;</code> and the cdr is <code>markdown-mode</code>.</p>
<p>The following expressions are equivalent:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span><span style="color:#f92672">&#39;</span>(<span style="color:#e6db74">&#34;\\.md\\&#39;&#34;</span> <span style="color:#f92672">.</span> markdown-mode)
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">cons</span> <span style="color:#e6db74">&#34;\\.md\\&#39;&#34;</span> <span style="color:#e6db74">&#39;markdown-mode</span>)
</span></span></code></pre></div><p>The dot creates a direct pair between two values. This syntax is commonly used in alists (like <code>auto-mode-alist</code>), mode hooks, and other paired data structures in Emacs.</p>
<p>When you see a dot in the middle of a list, it means &ldquo;the rest of this list is the cdr of this cons cell&rdquo; rather than continuing the list structure with an implicit nil at the end.</p>
<p>To understand the difference clearly:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span><span style="color:#75715e">;; A list with two elements (has an implicit nil at the end)</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&#39;</span>(<span style="color:#ae81ff">1</span> <span style="color:#ae81ff">2</span>)  <span style="color:#75715e">; =&gt; equivalent to (cons 1 (cons 2 nil))</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">;; A single cons cell (a pair) - NOT a proper list</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&#39;</span>(<span style="color:#ae81ff">1</span> <span style="color:#f92672">.</span> <span style="color:#ae81ff">2</span>)  <span style="color:#75715e">; =&gt; equivalent to (cons 1 2)</span>
</span></span></code></pre></div><p>The difference is significant:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span>(<span style="color:#a6e22e">length</span> <span style="color:#f92672">&#39;</span>(<span style="color:#ae81ff">1</span> <span style="color:#ae81ff">2</span>))     <span style="color:#75715e">; =&gt; 2</span>
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">length</span> <span style="color:#f92672">&#39;</span>(<span style="color:#ae81ff">1</span> <span style="color:#f92672">.</span> <span style="color:#ae81ff">2</span>))   <span style="color:#75715e">; =&gt; Error: Wrong type argument: listp, (1 . 2)</span>
</span></span></code></pre></div><p>This distinction is fundamental to understanding how Lisp data structures work.</p>
<h2 id="function-quoting--vs-">Function Quoting: <code>#'</code> vs <code>'</code></h2>
<p>In Elisp, you&rsquo;ll see both <code>'function-name</code> and <code>#'function-name</code> when referring to functions. The difference is important:</p>
<ul>
<li><code>'function-name</code> simply quotes the symbol</li>
<li><code>#'function-name</code> is shorthand for <code>(function function-name)</code>, which specifically tells Elisp that the symbol represents a function</li>
</ul>
<p>When should you use <code>#'</code>? Best practice is to use it whenever you&rsquo;re referring to a function as a function, especially with higher-order functions:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span><span style="color:#75715e">;; Good practice</span>
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">mapcar</span> <span style="color:#a6e22e">#&#39;1+</span> <span style="color:#f92672">&#39;</span>(<span style="color:#ae81ff">1</span> <span style="color:#ae81ff">2</span> <span style="color:#ae81ff">3</span>))  <span style="color:#75715e">; =&gt; (2 3 4)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">;; Works but less explicit</span>
</span></span><span style="display:flex;"><span>(<span style="color:#a6e22e">mapcar</span> <span style="color:#e6db74">&#39;1+</span> <span style="color:#f92672">&#39;</span>(<span style="color:#ae81ff">1</span> <span style="color:#ae81ff">2</span> <span style="color:#ae81ff">3</span>))
</span></span></code></pre></div><p>Using <code>#'</code> helps the byte-compiler optimize your code and makes your intent clearer to other programmers.</p>
<h2 id="association-lists-alists">Association Lists (alists)</h2>
<p>Association lists (alists) are lists of key-value pairs used for simple lookups:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span>(setq my-alist <span style="color:#f92672">&#39;</span>((name <span style="color:#f92672">.</span> <span style="color:#e6db74">&#34;John&#34;</span>)
</span></span><span style="display:flex;"><span>                 (age <span style="color:#f92672">.</span> <span style="color:#ae81ff">30</span>)
</span></span><span style="display:flex;"><span>                 (city <span style="color:#f92672">.</span> <span style="color:#e6db74">&#34;Boston&#34;</span>)))
</span></span></code></pre></div><p>You can access values using functions like <code>assoc</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span>(<span style="color:#a6e22e">cdr</span> (<span style="color:#a6e22e">assoc</span> <span style="color:#e6db74">&#39;age</span> my-alist))  <span style="color:#75715e">; =&gt; 30</span>
</span></span></code></pre></div><p>Alists are frequently used in Emacs for configuration options, especially when the list is relatively small and frequently modified. They&rsquo;re simple but not as efficient for large datasets.</p>
<h2 id="property-lists-plists">Property Lists (plists)</h2>
<p>Property lists are another key-value structure in Elisp, but with a different syntax:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span>(setq my-plist <span style="color:#f92672">&#39;</span>(:name <span style="color:#e6db74">&#34;John&#34;</span> :age <span style="color:#ae81ff">30</span> :city <span style="color:#e6db74">&#34;Boston&#34;</span>))
</span></span></code></pre></div><p>Notice how the keys are prefixed with colons. These are called keywords, similar to Ruby&rsquo;s symbols. You can access values using <code>plist-get</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-elisp" data-lang="elisp"><span style="display:flex;"><span>(<span style="color:#a6e22e">plist-get</span> my-plist :age)  <span style="color:#75715e">; =&gt; 30</span>
</span></span></code></pre></div><p>Other languages with similar concepts include:</p>
<ul>
<li>Ruby with its symbols (<code>:symbol</code>)</li>
<li>Clojure with keywords (<code>:keyword</code>)</li>
<li>Elixir with atoms (<code>:atom</code>)</li>
</ul>
<p>Plists are often used for function arguments that have default values or are optional.</p>
<h2 id="summary">Summary</h2>
<p>Understanding these fundamental Emacs Lisp concepts will help you:</p>
<ol>
<li>Write more effective Elisp code</li>
<li>Understand existing Emacs configurations</li>
<li>Create your own Emacs extensions</li>
</ol>
<p><img alt="summary" loading="lazy" src="/post/emacs-list-introduction/summary.png"></p>
<p>Emacs Lisp&rsquo;s power comes from its simplicity and consistency. Once you grasp these basic concepts, you&rsquo;ll find that the language follows logical patterns that make learning advanced features much easier.</p>
<p>Happy hacking!</p>
]]></content:encoded>
    </item>
    <item>
      <title>The Essential Emacs Hotkeys Every User Should Know</title>
      <link>https://blog.0x17.de/post/essential-emacs-hotkeys/</link>
      <pubDate>Fri, 28 Mar 2025 20:00:00 +0100</pubDate>
      <guid>https://blog.0x17.de/post/essential-emacs-hotkeys/</guid>
      <description>For over four decades, Emacs has stood as a pillar in the text editing world, beloved by programmers, writers, and power users alike. What makes Emacs particularly powerful is its extensive keyboard shortcut system that allows users to perform complex operations without ever touching the mouse.
Emacs comes with an excellent built-in tutorial that can be accessed with C-h t (Control-h followed by t). I highly recommend all new users complete this tutorial to get comfortable with Emacs&amp;rsquo; fundamentals.</description>
      <content:encoded><![CDATA[<p>For over four decades, Emacs has stood as a pillar in the text editing world, beloved by programmers, writers, and power users alike. What makes Emacs particularly powerful is its extensive keyboard shortcut system that allows users to perform complex operations without ever touching the mouse.</p>
<p>Emacs comes with an excellent built-in tutorial that can be accessed with <code>C-h t</code> (Control-h followed by t). I highly recommend all new users complete this tutorial to get comfortable with Emacs&rsquo; fundamentals. That said, the tutorial is comprehensive and takes time to complete.</p>
<p><img alt="hotkeys" loading="lazy" src="/post/essential-emacs-hotkeys/hotkeys.png"></p>
<p>This guide serves as a TL;DR and quick reference of the most essential hotkeys you should memorize. Consider it a short recap of what&rsquo;s worth knowing by heart to be immediately productive in Emacs, whether you&rsquo;re new to the editor or just need a refresher.</p>
<h2 id="understanding-emacs-notation">Understanding Emacs Notation</h2>
<p>Before diving into the hotkeys themselves, let&rsquo;s decode how to read Emacs key notation:</p>
<ul>
<li><strong>C-</strong> represents the Control key. For example, <code>C-a</code> means &ldquo;hold Control and press a&rdquo;.</li>
<li><strong>M-</strong> represents the Meta key, which on modern keyboards is typically the Alt key. So <code>M-f</code> means &ldquo;hold Alt and press f&rdquo;.</li>
<li><strong>C-x</strong> followed by another key represents a two-key sequence. Press Control and x together, release, then press the next key.</li>
<li><strong>M-x</strong> similarly starts a command sequence where you type the command name after pressing Alt and x.</li>
</ul>
<p>Multiple modifier keys can be combined. For example, <code>C-M-f</code> means holding both Control and Alt while pressing f.</p>
<p>With this foundation, let&rsquo;s explore the essential hotkeys that will dramatically improve your Emacs efficiency.</p>
<h2 id="essential-emacs-hotkeys-by-category">Essential Emacs Hotkeys by Category</h2>
<h3 id="text-navigation">Text Navigation</h3>
<p>Efficient text navigation is the foundation of productive editing. These shortcuts let you move through your document with precision:</p>
<table>
<thead>
<tr>
<th>Hotkey</th>
<th>Action Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>C-a</code></td>
<td>Move to beginning of line</td>
</tr>
<tr>
<td><code>C-e</code></td>
<td>Move to end of line</td>
</tr>
<tr>
<td><code>C-f</code></td>
<td>Move forward one character</td>
</tr>
<tr>
<td><code>C-b</code></td>
<td>Move backward one character</td>
</tr>
<tr>
<td><code>M-f</code></td>
<td>Move forward one word</td>
</tr>
<tr>
<td><code>M-b</code></td>
<td>Move backward one word</td>
</tr>
<tr>
<td><code>C-n</code></td>
<td>Move to next line</td>
</tr>
<tr>
<td><code>C-p</code></td>
<td>Move to previous line</td>
</tr>
<tr>
<td><code>C-v</code></td>
<td>Page down</td>
</tr>
<tr>
<td><code>M-v</code></td>
<td>Page up</td>
</tr>
<tr>
<td><code>M-&lt;</code></td>
<td>Move to beginning of buffer</td>
</tr>
<tr>
<td><code>M-&gt;</code></td>
<td>Move to end of buffer</td>
</tr>
<tr>
<td><code>C-l</code></td>
<td>Recenter buffer around cursor</td>
</tr>
</tbody>
</table>
<p>The navigation keys follow a pattern: <code>f</code> for forward, <code>b</code> for backward, <code>p</code> for previous, and <code>n</code> for next. Once you internalize these patterns, they become second nature.</p>
<h3 id="text-editing">Text Editing</h3>
<p>These shortcuts handle the core editing operations that you&rsquo;ll use hundreds of times daily:</p>
<table>
<thead>
<tr>
<th>Hotkey</th>
<th>Action Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>C-d</code></td>
<td>Delete character at point</td>
</tr>
<tr>
<td><code>M-&lt;backspace&gt;</code></td>
<td>Delete word backward</td>
</tr>
<tr>
<td><code>M-d</code></td>
<td>Delete word forward</td>
</tr>
<tr>
<td><code>C-k</code></td>
<td>Kill (cut) from cursor to end of line</td>
</tr>
<tr>
<td><code>C-w</code></td>
<td>Kill (cut) selected region</td>
</tr>
<tr>
<td><code>M-w</code></td>
<td>Copy selected region</td>
</tr>
<tr>
<td><code>C-y</code></td>
<td>Yank (paste) most recently killed text</td>
</tr>
<tr>
<td><code>M-y</code></td>
<td>Cycle through kill ring after yanking</td>
</tr>
<tr>
<td><code>C-/</code> or <code>C-_</code></td>
<td>Undo</td>
</tr>
</tbody>
</table>
<p>A unique aspect of Emacs is its &ldquo;kill ring&rdquo; - a clipboard system that remembers multiple deleted items. After using <code>C-y</code> to paste the most recent item, you can press <code>M-y</code> repeatedly to cycle through previously killed text.</p>
<h3 id="region-and-selection">Region and Selection</h3>
<p>Working with selections in Emacs involves understanding the concept of the &ldquo;mark&rdquo; and &ldquo;point&rdquo;:</p>
<table>
<thead>
<tr>
<th>Hotkey</th>
<th>Action Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>C-space</code></td>
<td>Set mark (start selection)</td>
</tr>
<tr>
<td><code>C-x C-x</code></td>
<td>Exchange point and mark (swap selection endpoints)</td>
</tr>
<tr>
<td><code>C-x h</code></td>
<td>Select entire buffer</td>
</tr>
</tbody>
</table>
<p>The mark is where a selection begins, and the point is your cursor position. Together they define the &ldquo;region&rdquo; - Emacs&rsquo; term for a selection.</p>
<h3 id="file-operations">File Operations</h3>
<p>These commands handle file management tasks:</p>
<table>
<thead>
<tr>
<th>Hotkey</th>
<th>Action Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>C-x C-f</code></td>
<td>Find (open) file</td>
</tr>
<tr>
<td><code>C-x C-s</code></td>
<td>Save current buffer</td>
</tr>
<tr>
<td><code>C-x s</code></td>
<td>Save all buffers</td>
</tr>
<tr>
<td><code>C-x C-c</code></td>
<td>Exit Emacs</td>
</tr>
<tr>
<td><code>C-x d</code></td>
<td>Open directory (dired)</td>
</tr>
</tbody>
</table>
<p>The <code>C-x C-f</code> command is particularly powerful as it allows you to create new files by entering paths that don&rsquo;t exist yet.</p>
<h3 id="buffer-management">Buffer Management</h3>
<p>In Emacs, a buffer is essentially an open file or space for editing:</p>
<table>
<thead>
<tr>
<th>Hotkey</th>
<th>Action Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>C-x b</code></td>
<td>Switch buffer</td>
</tr>
<tr>
<td><code>C-x k</code></td>
<td>Kill (close) buffer</td>
</tr>
</tbody>
</table>
<p>Efficient buffer navigation is crucial when working with multiple files.</p>
<h3 id="window-management">Window Management</h3>
<p>Emacs allows for sophisticated window layouts:</p>
<table>
<thead>
<tr>
<th>Hotkey</th>
<th>Action Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>C-x 2</code></td>
<td>Split window horizontally (one above the other)</td>
</tr>
<tr>
<td><code>C-x 3</code></td>
<td>Split window vertically (side by side)</td>
</tr>
<tr>
<td><code>C-x o</code></td>
<td>Switch to other window</td>
</tr>
<tr>
<td><code>C-x 0</code></td>
<td>Close current window</td>
</tr>
<tr>
<td><code>C-x 1</code></td>
<td>Close all windows except current</td>
</tr>
<tr>
<td><code>C-x 5 2</code></td>
<td>Create new frame (GUI window)</td>
</tr>
</tbody>
</table>
<p>The ability to split the editor into multiple windows, each showing different buffers, is one of Emacs&rsquo; most powerful features.</p>
<h3 id="search-and-replace">Search and Replace</h3>
<p>Finding and replacing text efficiently is essential for editing:</p>
<table>
<thead>
<tr>
<th>Hotkey</th>
<th>Action Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>C-s</code></td>
<td>Incremental search forward</td>
</tr>
<tr>
<td><code>C-r</code></td>
<td>Incremental search backward</td>
</tr>
<tr>
<td><code>M-%</code></td>
<td>Query replace</td>
</tr>
</tbody>
</table>
<p>Emacs&rsquo; incremental search updates as you type, making it quick to locate specific text.</p>
<h3 id="help-system">Help System</h3>
<p>When you inevitably need guidance, Emacs has built-in help:</p>
<table>
<thead>
<tr>
<th>Hotkey</th>
<th>Action Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>C-h f</code></td>
<td>Describe function</td>
</tr>
<tr>
<td><code>C-h k</code></td>
<td>Describe key</td>
</tr>
<tr>
<td><code>C-h t</code></td>
<td>Start tutorial</td>
</tr>
</tbody>
</table>
<p>The self-documenting nature of Emacs means help is always just a few keystrokes away.</p>
<h3 id="macros">Macros</h3>
<p>Macros are powerful tools for automating repetitive tasks:</p>
<table>
<thead>
<tr>
<th>Hotkey</th>
<th>Action Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>F3</code></td>
<td>Start recording a keyboard macro</td>
</tr>
<tr>
<td><code>F4</code></td>
<td>Stop recording or execute the most recent keyboard macro</td>
</tr>
</tbody>
</table>
<p>To use macros: press F3, perform the sequence of actions you want to repeat, press F4 to finish recording, then press F4 again each time you want to replay those exact keystrokes. This is incredibly useful for mass operations on text.</p>
<h3 id="command-execution">Command Execution</h3>
<p>Finally, the gateway to thousands of Emacs commands:</p>
<table>
<thead>
<tr>
<th>Hotkey</th>
<th>Action Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>M-x</code></td>
<td>Execute command by name</td>
</tr>
</tbody>
</table>
<p>This shortcut unlocks Emacs&rsquo; full potential, giving you access to any command by name.</p>
<h2 id="building-your-muscle-memory">Building Your Muscle Memory</h2>
<p>Learning these hotkeys will take time, but the productivity payoff is immense. Start by mastering the navigation and basic editing commands, then gradually incorporate the others. Consider printing this list and keeping it near your workspace until the keystrokes become automatic.</p>
<p>Remember that Emacs is highly customizable - once you&rsquo;re comfortable with these basics, you can create your own keybindings for commands you use frequently.</p>
<h2 id="conclusion">Conclusion</h2>
<p>The beauty of Emacs lies in how it becomes an extension of your thinking process once you&rsquo;ve internalized these commands. Text manipulation becomes effortless, allowing you to focus on your actual work rather than the mechanics of editing.</p>
<p><img alt="emacs-mind" loading="lazy" src="/post/essential-emacs-hotkeys/emacs-mind.png"></p>
<p>While this guide covers the essential hotkeys, it barely scratches the surface of what Emacs can do. As you grow more comfortable with these basics, explore specialized modes for your particular work, whether that&rsquo;s programming in specific languages, writing prose, managing projects, or organizing your life.</p>
<p>What began as a seemingly steep learning curve will transform into a powerful skillset that follows you throughout your computing life. Happy editing!</p>
]]></content:encoded>
    </item>
    <item>
      <title>The Rust Programming Language and the Advent of Code 2018</title>
      <link>https://blog.0x17.de/post/rust-and-adventofcode2018/</link>
      <pubDate>Fri, 07 Dec 2018 02:56:41 +0100</pubDate>
      <guid>https://blog.0x17.de/post/rust-and-adventofcode2018/</guid>
      <description>&lt;p&gt;I recently got reminded about &lt;a href=&#34;https://adventofcode.com/&#34;&gt;AdventOfCode2018&lt;/a&gt;. Be sure to check it out before end of december. Till now i did the challenges in rust, perl, bash - no specific language - just depending on the time i have. If you have plenty of time, the challenges from the last years are still available.&lt;/p&gt;
&lt;p&gt;Additionally i was looking a little into the programming language
rust.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>I recently got reminded about <a href="https://adventofcode.com/">AdventOfCode2018</a>. Be sure to check it out before end of december. Till now i did the challenges in rust, perl, bash - no specific language - just depending on the time i have. If you have plenty of time, the challenges from the last years are still available.</p>
<p>Additionally i was looking a little into the programming language
rust.</p>
<p>The rust package manager <a href="https://doc.rust-lang.org/cargo/">cargo</a> feels well designed. Also the language solves quite common issues in programming which makes classic inheritance unnecessary. The <a href="https://doc.rust-lang.org/book/index.html">tutorial</a> is easy to read and understand but in advanced topics you can see that things still change. The verbose annotation of object lifetime of references was reduced in recent releases and things that should not compile now finally do without issues. The basic data types quite bring everything you need out of the box, except some language features like <a href="https://doc.rust-lang.org/std/vec/struct.Vec.html#method.drain_filter">drain_filter</a>, quite similar to <a href="https://en.cppreference.com/w/cpp/algorithm/remove">std::remove_if</a>, are only available as unstable features. Therefore I would not recommend using the language in production, but i can already see its potential in the future. Memory related problems are reduced to ownership problems. It must be clear who is allowed to borrow a variable (keeping a reference) for later writing or read only operations. You can not have two writable references, nor have references that outlive the instance. This might cause a lot of confusion and iterations of code if you try to write code in your usual style. The ownership problem looks even worse when trying to communicate between threads. When a thread stops can be decided at runtime, either it is joined or it could be detached and even outlive the main thread. Therefore the classic thread&rsquo;s lifetime is considered <code>'static</code>. Solutions, for having threads with a defined lifetime existed: like <a href="https://doc.rust-lang.org/1.0.0/std/thread/fn.scoped.html">std:&#x1f9f5;:scoped</a>, but it had <a href="https://github.com/rust-lang/rust/issues/24292">unforseen issues</a>, related to accessing freed memory. To solve the issue, the library <a href="https://github.com/crossbeam-rs/crossbeam">crossbeam</a> provides a different approach to threads with a clearly defined lifetime. Still sharing objects as readable between threads is a challenge. One solution to the object being shared across threads could be by using <code>std::sync::Arc&lt;std::sync::Mutex&lt;Foo&gt;&gt;</code>. An <a href="https://doc.rust-lang.org/std/sync/struct.Arc.html">Arc</a> is for atomically accessing things from different threads, while the <a href="https://doc.rust-lang.org/std/sync/struct.Mutex.html">mutex</a> is required to clearly define who is writing the memory. Otherwise for <a href="https://doc.rust-lang.org/std/net/struct.TcpStream.html">TcpStreams</a> the handles can simply be cloned (see <a href="https://doc.rust-lang.org/std/net/struct.TcpStream.html#method.try_clone">try_clone</a>) without being in need of using a mutex object.</p>
<p>After reading this article you sure feel the complexity of that quite new programming language rust. But even if the language might not be ready for production, I recommend having at least a first look through the entire <a href="https://doc.rust-lang.org/book/index.html">tutorial</a> or even to learn it. The concepts might be different, but if you do you will be prepared for the future that is likely to come.</p>]]></content:encoded>
    </item>
    <item>
      <title>Hand written letters from 1941 and neural networks</title>
      <link>https://blog.0x17.de/post/letter-cnn/</link>
      <pubDate>Sat, 20 May 2017 17:12:05 +0200</pubDate>
      <guid>https://blog.0x17.de/post/letter-cnn/</guid>
      <description>&lt;p&gt;As another side project i am currently trying to convert a letter into
computer readable text just from a scanned image.&lt;/p&gt;
&lt;p&gt;&lt;img loading=&#34;lazy&#34; src=&#34;https://www.0x17.de/proj/cnn_letter.png&#34;&gt;&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>As another side project i am currently trying to convert a letter into
computer readable text just from a scanned image.</p>
<p><img loading="lazy" src="https://www.0x17.de/proj/cnn_letter.png"></p>
<p>The original images which will be preprocessed and passed to a
convolutional neural network are scanned A4 letters with a resolution
of about 2550x3500 pixels at 300dpi.</p>
<p>At first some letters will be manually converted into text for
labeling, which is required for the training process. A self written
tool is used to assign a position to each character in the
transcription. This process can be seen in the screenshot above. The
tool was written with OpenCV and allows a preview of the next two
words, highlights the current letter which is to be labeled and shows
some bounding box with hints for the later cropping process. (If you
want the source just write me some message but i also plan to release
the project after some results)</p>
<p>After each letter has some assigned position, the image still needs to
be preprocessed/enhanced as the color of the font is quite close to
the background color. This step can be done automatically in the
future. For each labeled character a 32x32px sub image will be
cropped and additionally for each of those images small pixel
translations, scaling and sinus wave transformations will be applied
to generate a lot more training data for the learning process.</p>
<p>For the CNN i planned to use Tensorflow as it has been proven to be
quite flexible for this task.</p>
<p>I will present the network configuration and further results in the next blog posts :)</p>
<p>Current letter counts after labeling two letters:</p>
<pre>
     16 ,
      2 !
     24 .
      2 0
      4 1
      3 2
      1 3
      2 4
      1 9
     71 a
      3 ä
     22 b
     54 c
     33 d
    162 e
     17 f
     26 g
     76 h
     81 i
      5 j
     13 k
     41 l
     22 m
    100 n
     26 o
      2 ö
      5 p
     65 r
     48 s
      4 ß
     57 t
     22 u
      4 ü
      1 Ü
      7 v
     31 w
     13 z
</pre>]]></content:encoded>
    </item>
    <item>
      <title>The official Harpoon page went online</title>
      <link>https://blog.0x17.de/post/harpoon-page-online/</link>
      <pubDate>Mon, 16 Jan 2017 00:55:55 +0100</pubDate>
      <guid>https://blog.0x17.de/post/harpoon-page-online/</guid>
      <description>&lt;p&gt;The official Harpoon website is now online and available at &lt;a href=&#34;https://harpoon.0x17.de/&#34;&gt;https://harpoon.0x17.de/&lt;/a&gt;.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>The official Harpoon website is now online and available at <a href="https://harpoon.0x17.de/">https://harpoon.0x17.de/</a>.</p>
<p>You can follow the project on the blog, github or via rss with the following urls:</p>
<ul>
<li>Blog: <a href="https://harpoon.0x17.de/blog/">https://harpoon.0x17.de/blog/</a></li>
<li>RSS: <a href="https://harpoon.0x17.de/blog/index.xml">https://harpoon.0x17.de/blog/index.xml</a></li>
<li>GitHub Harpoon: <a href="https://github.com/HarpoonOrg/Harpoon">https://github.com/HarpoonOrg/Harpoon</a></li>
<li>GitHub HarpoonClient: <a href="https://github.com/HarpoonOrg/HarpoonClient">https://github.com/HarpoonOrg/HarpoonClient</a></li>
</ul>
<p>Have fun reading! :)</p>]]></content:encoded>
    </item>
    <item>
      <title>Harpoon: Current State</title>
      <link>https://blog.0x17.de/post/harpoon-current-state/</link>
      <pubDate>Mon, 17 Oct 2016 15:39:30 +0200</pubDate>
      <guid>https://blog.0x17.de/post/harpoon-current-state/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://github.com/0x17de/Harpoon/&#34;&gt;Harpoon&lt;/a&gt; is a flexible chat client for common protocols - written in C++ - and will stay online when you aren&amp;rsquo;t. You will get push notifications for private messages when you are on the run.&lt;/p&gt;
&lt;p&gt;Here are some screenshots of the current state:&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p><a href="https://github.com/0x17de/Harpoon/">Harpoon</a> is a flexible chat client for common protocols - written in C++ - and will stay online when you aren&rsquo;t. You will get push notifications for private messages when you are on the run.</p>
<p>Here are some screenshots of the current state:</p>
<p><img loading="lazy" src="https://www.0x17.de/proj/harpoonClient6.png">
<img loading="lazy" src="https://www.0x17.de/proj/harpoonClientQt3.png"></p>
<p>Those screenshots need a little description, so here you go:</p>
<p>Harpoon consists of a server program and three different clients: Web/Desktop/Mobile.</p>
<p>In the first screenshot you can see the browser interface (topleft), whereas in the second screenshot you can see the desktop client.</p>
<p>The project is still work in progress as some essential parts are missing. Those are showing the backlog, user login and yet server configuration. In the next few updates those topics will be adressed and i will keep you up to date.</p>
<p>If you have questions you can find me on IRC. Just click the following link: <a href="https://webchat.freenode.net/?channels=harpoon">freenode.net channel #harpoon</a>.</p>
<p>Follow me on <a href="https://www.twitter.com/0x17de">twitter</a>, watch the project on <a href="https://github.com/0x17de/Harpoon/">github</a>, read my <a href="/index.xml">RSS</a> or join #harpoon on freenode.net to receieve status updates. :)</p>]]></content:encoded>
    </item>
  </channel>
</rss>
