<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Elsa Gonsiorowski</title>
        <description>My Personal Website</description>
        <link>http://gonsie.com/</link>
        <atom:link href="http://gonsie.com/blorg/feeds/elisp.xml" rel="self" type="application/rss+xml"/>
        <pubDate>Tue, 19 May 2026 17:45:38 +0000</pubDate>
        <lastBuildDate>Tue, 19 May 2026 17:45:38 +0000</lastBuildDate>
        <generator>Jekyll v3.10.0</generator>
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
            <item>
                <title>Org Export Hooks</title>
                <author>gonsie@me.com (Elsa Gonsiorowski)</author>
                <description>&lt;p&gt;In my quest for a simplified, org-based publishing scheme, I would like to add some information to a file when I export it.
Namely, I would like to add some metadata within the file, something like:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;    &lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;property:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;exported:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;2018-01-30&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Let’s see if I can prototype this functionality through Org-mode!&lt;/p&gt;

&lt;h2 id=&quot;hooks-and-useful-functions&quot;&gt;Hooks and Useful Functions&lt;/h2&gt;

&lt;p&gt;I can think of some functions and/or variables I will need:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/34397046/org-export-hook-does-not-trigger#34397363&quot;&gt;StackOverflow: org-export-preprocess-final-hook&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.howtobuildsoftware.com/index.php/how-do/c0Og/datetime-emacs-org-mode-org-mode-timestamp-format-when-exported&quot;&gt;Org mode timestamp format&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Interesting functions from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-h f org-insert-TAB&lt;/code&gt;:
    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-insert-comment&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-insert-time-stamp&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;end-of-buffer&lt;/code&gt; which references &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(goto-char (point-max))&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s put them together into an elisp snippet.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;add-hook&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&apos;org-export-preprocess-final-hook&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;save-excursion&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;goto-char&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;point-max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;insert&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\n#+property: exported: &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-insert-time-stamp&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;current-time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;insert&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\n&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;I think that does the thing that I want.
Ideally the property would go near (but not at) the top of my document, but that seems overly hard for the moment.
Notice that executing the block puts the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#+property&lt;/code&gt; at the end of the document.
That is the behavior we want, BUT it should not be happening when executing the block rather it should happen on export.
Also, this function will keep inserting more text, rather than update an existing property.&lt;/p&gt;

&lt;p&gt;That seems like a rather hacky way to set properties.
There must be something included with org.
Let’s try the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-set-property&lt;/code&gt; function.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;save-excursion&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;goto-char&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;point-min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-set-property&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;exported:&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;format-time-string&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;car&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;org-time-stamp-formats&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;current-time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))))&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Gross.
Without going to the beginning of the file, it just adds a property drawer to the current subtree.
Going to the beginning of the file just inserts the timestamp with the error: “Before first headline in position 1”.&lt;/p&gt;

&lt;h2 id=&quot;stackexchange-to-the-rescue&quot;&gt;StackExchange to the Rescue&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://emacs.stackexchange.com/questions/21459/programmatically-read-and-set-buffer-wide-org-mode-property&quot;&gt;This StackExchange Question&lt;/a&gt; leads me in the direction of the powerful &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-element-parse-buffer&lt;/code&gt;.
Actually, there is one solution which includes a rather elegant set of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-global-prop&lt;/code&gt; functions that I want to properly package up and attribute&lt;sup&gt;&lt;a id=&quot;fnr.1&quot; class=&quot;footref&quot; href=&quot;#fn.1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;.
Let’s try them out:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-global-prop-set&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;exported:&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;format-time-string&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;car&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;org-time-stamp-formats&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;current-time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;That function works!
What about as a hook?&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;add-hook&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&apos;org-export-before-parsing-hook&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-global-prop-set&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;exported:&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;format-time-string&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;car&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;org-time-stamp-formats&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;current-time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))))&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Ugh, hooks are dead.
Reading through &lt;a href=&quot;https://orgmode.org/worg/doc.html#hooks&quot;&gt;the official org documenatation&lt;/a&gt;, it seems like each hook operates on a copy of the current buffer, not what I want.&lt;/p&gt;

&lt;h2 id=&quot;hooking-on-to-something&quot;&gt;Hooking on to Something&lt;/h2&gt;

&lt;p&gt;That’s fine, I can hack in another way.
Let’s just rebind the keys that do the exporting to a new function which will do the export property update.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;    &lt;span class=&quot;c1&quot;&gt;;; add exported: property with date to org files when exporting&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;defun&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;my/org-export-dispatch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;&quot;updateds the exported: property before opening the dispatch&quot;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-global-prop-set&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;exported:&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;format-time-string&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;car&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;org-time-stamp-formats&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;current-time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-export-dispatch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;add-hook&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&apos;org&lt;/span&gt;
              &lt;span class=&quot;o&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;local-set-key&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;kbd&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;C-c C-e&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&apos;my/org-export-dispatch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Not perfect (the spaces/newlines after the property are globbed) but good enough for now.
Someday I’ll have to work on integrating this functionality into the publishing process (rather than this hack), but hey, it works.&lt;/p&gt;

&lt;h1 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h1&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id=&quot;fn.1&quot; href=&quot;#fnr.1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; I found the author, Tobias Zawada, and put the &lt;a href=&quot;https://github.com/gonsie/org-global-prop.el&quot;&gt;code on GitHub&lt;/a&gt;.&lt;/p&gt;
</description>
                <pubDate>Thu, 22 Mar 2018 00:00:00 +0000</pubDate>
                <link>http://gonsie.com/blorg/ox-hook.html</link>
                <guid isPermaLink="true">http://gonsie.com/blorg/ox-hook.html</guid>
                
                <category>org</category>
                
                <category>emacs</category>
                
                <category>elisp</category>
                
                
            </item>
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
            <item>
                <title>Part 2: Counting Words</title>
                <author>gonsie@me.com (Elsa Gonsiorowski)</author>
                <description>&lt;p&gt;&lt;em&gt;This post is part of a series.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;/blorg/part1-org-for-dev-elisp.html&quot;&gt;Part 1: Using Org to Develop E-lisp Snippets&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;(You are here) Part 2: Counting Words&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#org71ee782&quot;&gt;Exploring Existing Functionality&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#org02a74e3&quot;&gt;Marking and Counting&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#org6527a27&quot;&gt;Jaunting&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#org98fd9b5&quot;&gt;Count All the Things!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I often use an separate (Org) file to develop written content, especially when I am filling out an application that has essay questions.
The answers often have a word-count or character-count limit.
Let’s use Emacs and Org to count words!&lt;/p&gt;

&lt;p&gt;&lt;a id=&quot;org71ee782&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;exploring-existing-functionality&quot;&gt;Exploring Existing Functionality&lt;/h2&gt;

&lt;p&gt;First, I use builtin documentation (and tab completion) to compile some useful functions.
Actually, I flailed a lot and bugged my friend who knows a bunch about Emacs and Org.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;count-words&lt;/code&gt; function is obviously a good place to start.
The documentation indicates that functions works on either a region or buffer and that it acts differently if called from lisp (rather than interactively).
I don’t know anything about regions, but the Emacs Lisp documentation for “The Region” mentions two more useful functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;region-beginning&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;region-end&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Looking through all the Org functions, two stick out: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-mark-subtree&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-babel-mark-block&lt;/code&gt;.
These functions create a region on a specified chunk of Org content.&lt;/p&gt;

&lt;p&gt;Finally, I’ll need to go to the Org location to mark the region.
There are a few functions that look good for that: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-goto&lt;/code&gt; (though that seems to be very interactive) and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-id-goto&lt;/code&gt;.
Also, I come across &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-babel-goto-named-src-block&lt;/code&gt;.
I already know how to name a source block.
For the other go-tos, making an Org ID is easy enough: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-id-get-create&lt;/code&gt;.
(Note, although &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-id-new&lt;/code&gt; looks promising, I eventually learn that it doesn’t do what I want).&lt;/p&gt;

&lt;p&gt;&lt;a id=&quot;org02a74e3&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;marking-and-counting&quot;&gt;Marking and Counting&lt;/h2&gt;

&lt;p&gt;I need to create an Org section for each answer that I want to word count.
I can either use a header/node/subtree or a source block (of text).
In the first case, I’ll add a unique ID to the header (by invoking the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-id-get-create&lt;/code&gt;) so I can use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-id-goto&lt;/code&gt;.
In the source block case, I can simply give it a name.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;&lt;span class=&quot;nv&quot;&gt;**&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;Describe&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;Blah&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;words&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;:PROPERTIES:&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;:ID:&lt;/span&gt;       &lt;span class=&quot;nv&quot;&gt;460D55A4-7C61-485C-8778-075406BAE8A4&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;:END:&lt;/span&gt;

&lt;span class=&quot;nv&quot;&gt;My&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;answer&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;that&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;blah.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NAME:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;question1&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BEGIN_SRC&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;text&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;Blah&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;blah&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;blah.&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;END_SRC&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The snippet for counting words in a subtree looks something like:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NAME:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;subtree-method&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BEGIN_SRC&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;elisp&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-id-goto&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;460D55A4-7C61-485C-8778-075406BAE8A4&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-mark-subtree&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;count-words&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;region-beginning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;region-end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;;; note that this snippet does not work&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;END_SRC&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Unfortunately, the first snippet doesn’t work.
Instead, it shows the error “Wrong type argument: markerp nil”.&lt;/p&gt;

&lt;p&gt;Let’s try the source block way:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NAME:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;src-block-method&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BEGIN_SRC&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;elisp&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-babel-goto-named-src-block&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;question1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-babel-mark-block&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;count-words&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;region-beginning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;region-end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;END_SRC&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Huzzah! This one works.
Strangely, the result appears below the question block, not where I would expect it (below the code snippet).&lt;/p&gt;

&lt;p&gt;&lt;a id=&quot;org6527a27&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;jaunting&quot;&gt;Jaunting&lt;/h2&gt;

&lt;p&gt;My friend (who actually reads books) shows me an awesome Emacs lisp function&lt;sup&gt;&lt;a id=&quot;fnr.6&quot; class=&quot;footref&quot; href=&quot;#fn.6&quot;&gt;6&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;save-excursion&lt;/code&gt;: Save point, and current buffer; execute BODY; restore those things.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Turns out, this function is all over a bunch of e-lisp code.
Let’s try it!
First, the subtree version of counting words:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NAME:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;subtree-method&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BEGIN_SRC&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;elisp&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;save-excursion&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-id-goto&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;460D55A4-7C61-485C-8778-075406BAE8A4&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-mark-subtree&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;count-words&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;region-beginning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;region-end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;END_SRC&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Low and behold! It suddenly works.
Plus, the results appear below the current code block.
Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;save-excursion&lt;/code&gt; also fixes the source block method, making the results block appear near it.&lt;/p&gt;

&lt;p&gt;One remaining issue with the subtree method is that it counts the Org properties drawer in the word count.&lt;/p&gt;

&lt;p&gt;&lt;a id=&quot;org98fd9b5&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;count-all-the-things&quot;&gt;Count All the Things!&lt;/h2&gt;

&lt;p&gt;Finally, our word counting snippet should work on a bunch of subtrees or blocks.
Let’s pass some input to the snippets.
Also, we should pretty print the results.
Finally, I’ve included the code to count the characters as well.
The source block method ends up looking like:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NAME:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;questions&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;question1&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;question2&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;question3&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BEGIN_SRC&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;elisp&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;blks=questions&lt;/span&gt;  &lt;span class=&quot;ss&quot;&gt;:results&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;output&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;save-excursion&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;blks&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;setq&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;car&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;car&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;blks&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;setq&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;blks&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cdr&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;blks&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-babel-goto-named-src-block&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-babel-mark-block&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;princ&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;princ&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\t&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;princ&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;count-words&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;region-beginning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;region-end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;princ&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot; words\t&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;princ&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;region-end&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;region-beginning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;princ&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot; chars\n&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;END_SRC&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;RESULTS:&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;question1&lt;/span&gt;	&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;words&lt;/span&gt;	&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;chars&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;question2&lt;/span&gt;	&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;words&lt;/span&gt;	&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;chars&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;question3&lt;/span&gt;	&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;words&lt;/span&gt;	&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;chars&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The same can be done for the subtree method, but with IDs as the input.&lt;/p&gt;

&lt;h2 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h2&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id=&quot;fn.6&quot; href=&quot;#fnr.6&quot;&gt;6&lt;/a&gt;&lt;/sup&gt; Documentation for &lt;a href=&quot;https://www.gnu.org/software/emacs/manual/html_node/eintr/save_002dexcursion.html#save_002dexcursion&quot;&gt;Emacs Lisp save-excursion&lt;/a&gt;&lt;/p&gt;
</description>
                <pubDate>Wed, 10 Jan 2018 00:00:00 +0000</pubDate>
                <link>http://gonsie.com/blorg/part2-counting-words.html</link>
                <guid isPermaLink="true">http://gonsie.com/blorg/part2-counting-words.html</guid>
                
                <category>emacs</category>
                
                <category>elisp</category>
                
                <category>org</category>
                
                
            </item>
        
        
        
            <item>
                <title>Part 1: Using Org to Develop Elisp</title>
                <author>gonsie@me.com (Elsa Gonsiorowski)</author>
                <description>&lt;p&gt;&lt;em&gt;This post is part of a series.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;(You are here) Part 1: Using Org to Develop E-lisp snippets&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/blorg/part2-counting-words.html&quot;&gt;Part 2: Counting Words&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#org408d605&quot;&gt;Useful Commands&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#orgf8927c2&quot;&gt;The Power of Introspection&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#org6ddd2d2&quot;&gt;Starting with Org Blocks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One of the powers of Org mode is the ability to run blocks of code and collect the output.
This allows you to capture code, context for writing the code (as actual text), and results in a single document.
This blog-post will describe how I’ve started to learn Emacs lisp using org and Emacs itself.&lt;/p&gt;

&lt;p&gt;&lt;a id=&quot;org408d605&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;useful-commands&quot;&gt;Useful Commands&lt;/h2&gt;

&lt;p&gt;In Emacs, there are many ways to trigger the same actions.
I find that memorizing chords is terribly difficult (if I have any memorized its through muscle memory rather than my brain knowing what I’m typing).
Here is a short table of commands I’ve needed to get at the documentation builtin to Emacs.
Usually I run these via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;M-x FUNCTION&lt;/code&gt;, which allows me to get at tab-completion if I don’t remember the exact name.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Chord&lt;/th&gt;
      &lt;th&gt;Function&lt;/th&gt;
      &lt;th&gt;Out Come&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-h f FUNCTION&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;describe-function&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;show doc page for function&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-k F FUNCTION&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Info-goto-emacs-command-node&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;show manual page for function&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-h k KEY&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;describe-key&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;show doc page for a chord&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-h K KEY&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Info-goto-emacs-key-command-node&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;show manual page for chord&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-h C-f&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;view-emacs-FAQ&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;show GNU Emacs FAQ&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-h i&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;info&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Bring up info documentation browser to the last info page you were looking at&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-h i m elisp RET&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Shortcut to ELisp documentation&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-h i d&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
      &lt;td&gt;Top level info directory&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-c C-c&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-ctrl-c-ctrl-c&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Great function name. Does a bunch of things, namely running the source code block&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-c &apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org-edit-special&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Edit block/table in a separate buffer popup&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Helpful web pages:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://orgmode.org/org.html#Editing-source-code&quot;&gt;Orgmode Source Code Editing&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://orgmode.org/org.html#Easy-templates&quot;&gt;Org Easy Templates&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://orgmode.org/org.html#Specific-header-arguments&quot;&gt;Org Source Block Header Arguments&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.gnu.org/software/emacs/manual/html_node/eintr/index.html#Top&quot;&gt;GNU Manual on Lisp in Emacs&lt;/a&gt; and the page on &lt;a href=&quot;https://www.gnu.org/software/emacs/manual/html_node/eintr/save_002dexcursion.html#save_002dexcursion&quot;&gt;save-excursion&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a id=&quot;orgf8927c2&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;the-power-of-introspection&quot;&gt;The Power of Introspection&lt;/h2&gt;

&lt;p&gt;I do not learn through text books.
Often, I find that they have all this extra narrative, when all I really want is the equation or detailed function documentation.
This does make it somewhat difficult for me to learn new programming languages as I’m not going to sit down a read a book.
This is where an IDE can really help.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;In psychology, the process of introspection relies exclusively on observation of one’s mental state.
Introspection is closely related to human self-reflection and is contrasted with external observation&lt;sup&gt;&lt;a id=&quot;fnr.1&quot; class=&quot;footref&quot; href=&quot;#fn.1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In programming, introspection is the ability to look at the code itself, as a program is running.
Emacs allows this (in a sense) through the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;describe-function&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;describe-key&lt;/code&gt; functions.
Users can view both documentation and even the source code itself&lt;sup&gt;&lt;a id=&quot;fnr.2&quot; class=&quot;footref&quot; href=&quot;#fn.2&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;.
Using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;describe-function&lt;/code&gt; function, along with tab completion, you can guess at functions that may exists and start to build e-lisp snippets.&lt;/p&gt;

&lt;p&gt;Built-in documentation isn’t technically introspection, but it is nice.
To bring up the “Emacs Lisp” manual, type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-h i m elisp RET&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Despite my dislike of narrative, I now present a basic walk-through for getting started with Org mode code blocks.&lt;/p&gt;

&lt;p&gt;&lt;a id=&quot;org6ddd2d2&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;starting-with-org-blocks&quot;&gt;Starting with Org Blocks&lt;/h2&gt;

&lt;p&gt;Now that we know how to bring up documentation without leaving Emacs, lets code!
I’m sure we could create a new elisp file / project, but who has time?
I would rather do my day job and learn a little new elisp when the opportunity arises.
This means I’m already working on something while writing in Org-mode.&lt;/p&gt;

&lt;h3 id=&quot;basics-running-and-results&quot;&gt;Basics: Running and Results&lt;/h3&gt;

&lt;p&gt;Org source blocks contain snippets of code that can be executed.
First, make sure executing e-lisp code through Org babel in enabled (usually in your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init.el&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.emacs&lt;/code&gt; file):&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;org-babel-do-load-languages&lt;/span&gt;
  &lt;span class=&quot;ss&quot;&gt;&apos;org-babel-load-languages&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;emacs-lisp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Let’s start with a very basic Emacs lisp snippet.
Typing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;s TAB&lt;/code&gt; will automatically create a source code block (this is called a template&lt;sup&gt;&lt;a id=&quot;fnr.3&quot; class=&quot;footref&quot; href=&quot;#fn.3&quot;&gt;3&lt;/a&gt;&lt;/sup&gt;).&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NAME:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;calc&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BEGIN_SRC&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;elisp&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;END_SRC&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Placing the cursor within the block at hitting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-c C-c&lt;/code&gt; triggers the run (type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;y&lt;/code&gt; to allow the snippet to run on your computer).
The results appear in the document.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;RESULTS:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;calc&lt;/span&gt;
        &lt;span class=&quot;err&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;8&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;string-manipulations&quot;&gt;String Manipulations&lt;/h3&gt;

&lt;p&gt;Elisp isn’t my go-to calculator, but it is a handy way to run simple calculations.
Let’s get more complicated with some quick text parsing.
Here I create 2 lists of items, then print all the permutations through an Org block.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-elisp&quot; data-lang=&quot;elisp&quot;&gt;&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NAME:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;letters&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;A&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;B&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;C&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NAME:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;numbers&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NAME:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;str-permute&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BEGIN_SRC&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;elisp&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;s1=letters&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;s2=numbers&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:results&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;output&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;s1&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;setq&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;car&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;s1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;setq&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;s1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cdr&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;s1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;setq&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;tmp&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;s2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;tmp&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;setq&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;car&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;setq&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;tmp&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cdr&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;princ&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;car&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;princ&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;car&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;princ&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\n&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;END_SRC&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;#+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;RESULTS:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;str-permute&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;A1&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;A2&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;B1&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;B2&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;C1&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;C2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;A few notes about this example:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;To edit the e-lisp code in an “Emacs-Lisp” mode buffer, move the cursor in to the source block and type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-c &apos;&lt;/code&gt;.
This ensures proper indentation and other major mode niceness.
Note that this can work for any major mode&lt;sup&gt;&lt;a id=&quot;fnr.4&quot; class=&quot;footref&quot; href=&quot;#fn.4&quot;&gt;4&lt;/a&gt;&lt;/sup&gt;, including text.&lt;/li&gt;
  &lt;li&gt;Notice the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:results output&lt;/code&gt; header argument on the code block&lt;sup&gt;&lt;a id=&quot;fnr.5&quot; class=&quot;footref&quot; href=&quot;#fn.5&quot;&gt;5&lt;/a&gt;&lt;/sup&gt;.
There are a bunch of arguments, but the results one always messes me up.
In this case, I want to print the output as the snippet executes, not the return value of the snippet.&lt;/li&gt;
  &lt;li&gt;Do not forget to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cdr&lt;/code&gt; your while loop variable.
Should you forget, use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C-g&lt;/code&gt; to kill the execution.&lt;/li&gt;
  &lt;li&gt;Emacs print functions are weird and the documentation is obtuse… I just use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;princ&lt;/code&gt;.
Unfortunately there is no easy to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;princ&lt;/code&gt; many items in a single, variable argument command (and I don’t want figure out how to build strings).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h2&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id=&quot;fn.1&quot; href=&quot;#fnr.1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; &lt;a href=&quot;https://en.wikipedia.org/wiki/Introspection&quot;&gt;Introspection&lt;/a&gt;. &lt;em&gt;Wikipedia, The Free Encyclopedia&lt;/em&gt;. Accessed Jan. 4, 2018.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id=&quot;fn.2&quot; href=&quot;#fnr.2&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; Okay, this isn’t technically programmatic introspection, more like “built-in documentation.”
On the other hand, Emacs is somewhat unique in how users can interact with the documentation and the underlying code.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id=&quot;fn.3&quot; href=&quot;#fnr.3&quot;&gt;3&lt;/a&gt;&lt;/sup&gt; Documentation for &lt;a href=&quot;https://orgmode.org/org.html#Easy-templates&quot;&gt;Org Easy Templates&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id=&quot;fn.4&quot; href=&quot;#fnr.4&quot;&gt;4&lt;/a&gt;&lt;/sup&gt; Documentation for &lt;a href=&quot;https://orgmode.org/org.html#Editing-source-code&quot;&gt;Org source blocks&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;&lt;a id=&quot;fn.5&quot; href=&quot;#fnr.5&quot;&gt;5&lt;/a&gt;&lt;/sup&gt; Documentation for &lt;a href=&quot;https://orgmode.org/org.html#Specific-header-arguments&quot;&gt;Org source block header arguments&lt;/a&gt;&lt;/p&gt;
</description>
                <pubDate>Wed, 10 Jan 2018 00:00:00 +0000</pubDate>
                <link>http://gonsie.com/blorg/part1-org-for-dev-elisp.html</link>
                <guid isPermaLink="true">http://gonsie.com/blorg/part1-org-for-dev-elisp.html</guid>
                
                <category>emacs</category>
                
                <category>elisp</category>
                
                <category>org</category>
                
                
            </item>
        
        
        
            <item>
                <title>Part 0: Word Count Goals</title>
                <author>gonsie@me.com (Elsa Gonsiorowski)</author>
                <description>&lt;h2 id=&quot;an-excursion-into-e-lisp-and-org&quot;&gt;An Excursion into E-Lisp and Org&lt;/h2&gt;

&lt;p&gt;I have had some recent success with learning Emacs lisp through Org-mode.
I’ve decided to write about for others looking to get started with elisp.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;/blorg/part1-org-for-dev-elisp.html&quot;&gt;Part 1: Using Org to Develop E-lisp Snippets&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/blorg/part2-counting-words.html&quot;&gt;Part 2: Counting Words&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I plan to eventually write a third post describing the process of publishing a package.&lt;/p&gt;
</description>
                <pubDate>Wed, 10 Jan 2018 00:00:00 +0000</pubDate>
                <link>http://gonsie.com/blorg/part0-word-count.html</link>
                <guid isPermaLink="true">http://gonsie.com/blorg/part0-word-count.html</guid>
                
                <category>emacs</category>
                
                <category>elisp</category>
                
                <category>org</category>
                
                
            </item>
        
        
        
        
        
        
        
        
    </channel>
</rss>
