<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <atom:link href="http://kitchingroup.cheme.cmu.edu/blog/feed/index.xml" rel="self" type="application/rss+xml" />
    <title>The Kitchin Research Group</title>
    <link>https://kitchingroup.cheme.cmu.edu/blog</link>
    <description>Chemical Engineering at Carnegie Mellon University</description>
    <pubDate>Sat, 01 Nov 2025 13:47:46 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    
    <item>
      <title>Using prefix args in ivy actions</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2016/06/14/Using-prefix-args-in-ivy-actions</link>
      <pubDate>Tue, 14 Jun 2016 11:03:46 EDT</pubDate>
      <category><![CDATA[ivy]]></category>
      <category><![CDATA[emacs]]></category>
      <guid isPermaLink="false">llUH4oZhmfyX6P9Gq4ewBjNC8q4=</guid>
      <description>Using prefix args in ivy actions</description>
      <content:encoded><![CDATA[


&lt;div id="table-of-contents"&gt;
&lt;h2&gt;Table of Contents&lt;/h2&gt;
&lt;div id="text-table-of-contents"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#orgheadline1"&gt;1. Bare bones setup&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
There is a &lt;a href="https://github.com/abo-abo/swiper/commit/e54aa1850077d22e8007edef86d4bb751c3b7794"&gt;brand new feature&lt;/a&gt; in ivy which allows you to pass prefix args to the action functions. This change has made it into MELPA by now, so you can try it out. Check out this &lt;a href="#orgheadline1"&gt;1&lt;/a&gt; for an emacs -Q setup that I used for this post. This installs ivy and org-ref with some minimal setup.
&lt;/p&gt;

&lt;p&gt;
The video for this post can be found here: &lt;a href="https://www.youtube.com/watch?v=Y8HHLAE_-yA"&gt;https://www.youtube.com/watch?v=Y8HHLAE_-yA&lt;/a&gt; 
&lt;/p&gt;

&lt;p&gt;
In this post I will show how to use this new feature to create an ivy selection function that inserts a citation from a bibtex file, and with a prefix arg lets you choose the type of citation to insert.
&lt;/p&gt;

&lt;p&gt;
&lt;a href="https://melpa.org/#/org-ref"&gt;org-ref&lt;/a&gt; provides a function that generates candidates for selection. Each candidate is a list where the car of the list is a display string, and the cdr is an a-list of properties. I have a lot of entries in here, so it is important to have a convenient selection tool.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; org-ref-bibtex-files '(&lt;span style="color: #008000;"&gt;"references.bib"&lt;/span&gt;))
(length (orhc-bibtex-candidates))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Here is an example of the first entry in my bibliography. We will need to extract the key from that. 
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(elt (orhc-bibtex-candidates) 0)
&lt;/pre&gt;
&lt;/div&gt;



&lt;p&gt;
Here is the key from that entry.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(cdr (assoc &lt;span style="color: #008000;"&gt;"=key="&lt;/span&gt; (elt (orhc-bibtex-candidates) 0)))
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;
By default we will insert that as &lt;a class='org-ref-reference' href="#kitchin-2015-examp"&gt;kitchin-2015-examp&lt;/a&gt; but there are other types of citations we might use too like &lt;a class='org-ref-reference' href="#kitchin-2015-examp"&gt;kitchin-2015-examp&lt;/a&gt;. org-ref provides a list of citation types we could insert. Here they are. This somewhat complicated code just wraps the string so it fits in the blog post nicely.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;with-temp-buffer&lt;/span&gt; 
  (insert (format &lt;span style="color: #008000;"&gt;"%s"&lt;/span&gt; org-ref-cite-types))
  (fill-region (point-min) (point-max))
  (buffer-string))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
So, we are now prepared to make a simple ivy function to query our bibliography that has a default action to insert a standard citation, but we can use a prefix to change the citation type. The prefix arg is stored in the global variable ivy-current-prefix-arg which can be checked inside the action function. We can check for it in the action function and do something different if a prefix arg is used. Here is the function.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;cite&lt;/span&gt; ()
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (ivy-read &lt;span style="color: #008000;"&gt;"select: "&lt;/span&gt; (orhc-bibtex-candidates)
            &lt;span style="color: #006FE0;"&gt;:action&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (entry) 
                      (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((key (cdr (assoc &lt;span style="color: #008000;"&gt;"=key="&lt;/span&gt; entry)))
                            (type (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; ivy-current-prefix-arg
                                      (ivy-read &lt;span style="color: #008000;"&gt;"type: "&lt;/span&gt; org-ref-cite-types)
                                    &lt;span style="color: #008000;"&gt;"cite"&lt;/span&gt;)))
                        (&lt;span style="color: #0000FF;"&gt;with-ivy-window&lt;/span&gt;
                          (insert (format &lt;span style="color: #008000;"&gt;"%s:%s"&lt;/span&gt; type key)))))))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
To get the default action, we run M-x cite, enter our query, select an entry and press return. To get an alternate cite type, we run M-x cite, enter the query, select an entry, then type  C-u return, which will prompt you for an alternate citation type, then insert your choice and the citation. Here are some examples.
&lt;a class='org-ref-reference' href="#kitchin-2015-examp"&gt;kitchin-2015-examp&lt;/a&gt;  &lt;a class='org-ref-reference' href="#kitchin-2015-examp"&gt;kitchin-2015-examp&lt;/a&gt; &lt;a class='org-ref-reference' href="#kitchin-2015-examp"&gt;kitchin-2015-examp&lt;/a&gt;
&lt;/p&gt;



&lt;p&gt;
In summary, these aren't functions you would want to use; they don't handle a lot of the nuances of multiple citations. They are just to illustrate in a pretty simple way how easy it is to use a prefix arg in an ivy action function now! 
&lt;/p&gt;

&lt;div id="outline-container-orgheadline1" class="outline-2"&gt;
&lt;h2 id="orgheadline1"&gt;&lt;span class="section-number-2"&gt;1&lt;/span&gt; Bare bones setup&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;
&lt;p&gt;
This will setup the bare bones emacs that I used for this post.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; package-user-dir (expand-file-name &lt;span style="color: #008000;"&gt;"sandbox"&lt;/span&gt;))

(&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; package-archives
      '((&lt;span style="color: #008000;"&gt;"melpa"&lt;/span&gt; . &lt;span style="color: #008000;"&gt;"http://melpa.org/packages/"&lt;/span&gt;)))

(&lt;span style="color: #0000FF;"&gt;require&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;package&lt;/span&gt;)

&lt;span style="color: #8D8D84;"&gt;;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;Code:&lt;/span&gt;

(package-initialize)

(&lt;span style="color: #0000FF;"&gt;unless&lt;/span&gt; (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(&lt;span style="color: #0000FF;"&gt;eval-when-compile&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;require&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;use-package&lt;/span&gt;))

(&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; use-package-always-ensure t)

(&lt;span style="color: #0000FF;"&gt;use-package&lt;/span&gt; &lt;span style="color: #D0372D;"&gt;ivy&lt;/span&gt;)

(&lt;span style="color: #0000FF;"&gt;use-package&lt;/span&gt; &lt;span style="color: #D0372D;"&gt;org-ref&lt;/span&gt;
 &lt;span style="color: #006FE0;"&gt;:init&lt;/span&gt; 
 (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; org-ref-default-bibliography '(&lt;span style="color: #008000;"&gt;"~/Dropbox/bibliography/references.bib"&lt;/span&gt;))
 &lt;span style="color: #006FE0;"&gt;:config&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;require&lt;/span&gt; '&lt;span style="color: #D0372D;"&gt;org-ref-helm-cite&lt;/span&gt;))

(global-visual-line-mode 1)
(&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; org-confirm-babel-evaluate nil)
(load-theme 'leuven)
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2016 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;
&lt;p&gt;&lt;a href="/org/2016/06/14/Using-prefix-args-in-ivy-actions.org"&gt;org-mode source&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Org-mode version = 8.3.4&lt;/p&gt;]]></content:encoded>
    </item>
    <item>
      <title>Dynamic sorting with ivy</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2016/06/13/Dynamic-sorting-with-ivy</link>
      <pubDate>Mon, 13 Jun 2016 15:51:19 EDT</pubDate>
      <category><![CDATA[ivy]]></category>
      <category><![CDATA[emacs]]></category>
      <guid isPermaLink="false">hLJ9e4x3ygVWdrOY6ZX81mTFbQg=</guid>
      <description>Dynamic sorting with ivy</description>
      <content:encoded><![CDATA[


&lt;p&gt;
I have been exploring ivy a lot these days as a general purpose completion backend. One need I have is dynamic resorting of candidates. I illustrate how to achieve that here. A big thanks to Oleh Krehel (author of ivy) for a lot help today getting this working!
&lt;/p&gt;

&lt;p&gt;
You may want to check out the video: &lt;a href="https://www.youtube.com/watch?v=nFKfM3MOAd0"&gt;https://www.youtube.com/watch?v=nFKfM3MOAd0&lt;/a&gt; 
&lt;/p&gt;

&lt;p&gt;
First, a typical ivy-read example. Below I have a set of contact data for some people, and have setup an ivy-read command that inserts the email in the current buffer by default, and a second action for the phone. What is missing that I would like to do is dynamically reorder the candidates, including sorting all the candidates, swapping candidates up and down to fine tune the order, and then finally applying an action to all the candidates.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;ct&lt;/span&gt; ()
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (ivy-read &lt;span style="color: #008000;"&gt;"contact: "&lt;/span&gt; '((&lt;span style="color: #008000;"&gt;"Kno Body"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"kb@true.you"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"555-1212"&lt;/span&gt;)
                          (&lt;span style="color: #008000;"&gt;"A. Person"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"ap@some.come"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"867-5304"&lt;/span&gt;)
                          (&lt;span style="color: #008000;"&gt;"G. Willikers"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"gw@not.me"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"555-5555"&lt;/span&gt;))
            &lt;span style="color: #006FE0;"&gt;:action&lt;/span&gt; '(1
                      (&lt;span style="color: #008000;"&gt;"o"&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (x)
                             (&lt;span style="color: #0000FF;"&gt;with-ivy-window&lt;/span&gt;
                               (insert
                                (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (not (looking-back &lt;span style="color: #008000;"&gt;" "&lt;/span&gt;)) &lt;span style="color: #008000;"&gt;", "&lt;/span&gt; &lt;span style="color: #008000;"&gt;""&lt;/span&gt;)
                                (elt x 0))))
                       &lt;span style="color: #008000;"&gt;"insert email"&lt;/span&gt;)
                      (&lt;span style="color: #008000;"&gt;"p"&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (x)
                             (&lt;span style="color: #0000FF;"&gt;with-ivy-window&lt;/span&gt;
                               (insert
                                (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (not (looking-back &lt;span style="color: #008000;"&gt;" "&lt;/span&gt;)) &lt;span style="color: #008000;"&gt;", "&lt;/span&gt; &lt;span style="color: #008000;"&gt;""&lt;/span&gt;)
                                (elt x 1))))
                       &lt;span style="color: #008000;"&gt;"insert phone"&lt;/span&gt;))))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
So, first a set of functions to manipulate the candidates. We create a swap function, two functions to move candidates up and down, and two functions that sort the whole list of candidates in ascending and descending order. In each case, we just update the ivy collection with the new modified collection, we save the currently selected candidate, and then reset the state to update the candidates.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;swap&lt;/span&gt; (i j lst)
  &lt;span style="color: #036A07;"&gt;"Swap index I and J in the list LST."&lt;/span&gt; 
  (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((tempi (nth i lst)))
    (&lt;span style="color: #0000FF;"&gt;setf&lt;/span&gt; (nth i lst) (nth j lst))
    (&lt;span style="color: #0000FF;"&gt;setf&lt;/span&gt; (nth j lst) tempi))
  lst)

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;ivy-move-up&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Move ivy candidate up."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (&lt;span style="color: #0000FF;"&gt;setf&lt;/span&gt; (ivy-state-collection ivy-last)
        (swap ivy--index (1- ivy--index) (ivy-state-collection ivy-last)))
  (&lt;span style="color: #0000FF;"&gt;setf&lt;/span&gt; (ivy-state-preselect ivy-last) ivy--current)
  (ivy--reset-state ivy-last))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;ivy-move-down&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Move ivy candidate down."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (&lt;span style="color: #0000FF;"&gt;setf&lt;/span&gt; (ivy-state-collection ivy-last)
        (swap ivy--index (1+ ivy--index) (ivy-state-collection ivy-last)))
  (&lt;span style="color: #0000FF;"&gt;setf&lt;/span&gt; (ivy-state-preselect ivy-last) ivy--current)
  (ivy--reset-state ivy-last))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;ivy-a-z&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Sort ivy candidates from a-z."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (&lt;span style="color: #0000FF;"&gt;setf&lt;/span&gt; (ivy-state-collection ivy-last)
        (cl-sort (ivy-state-collection ivy-last)
                 (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (listp (car (ivy-state-collection ivy-last)))
                     (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (a b)
                       (string-lessp (car a) (car b)))
                   (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (a b)
                     (string-lessp a b)))))
  (&lt;span style="color: #0000FF;"&gt;setf&lt;/span&gt; (ivy-state-preselect ivy-last) ivy--current)
  (ivy--reset-state ivy-last))

(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;ivy-z-a&lt;/span&gt; ()
  &lt;span style="color: #036A07;"&gt;"Sort ivy candidates from z-a."&lt;/span&gt;
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (&lt;span style="color: #0000FF;"&gt;setf&lt;/span&gt; (ivy-state-collection ivy-last)
        (cl-sort (ivy-state-collection ivy-last)
                 (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (listp (car (ivy-state-collection ivy-last)))
                     (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (a b)
                       (string-greaterp (car a) (car b)))
                   (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (a b)
                     (string-greaterp a b)))))
  (&lt;span style="color: #0000FF;"&gt;setf&lt;/span&gt; (ivy-state-preselect ivy-last) ivy--current)
  (ivy--reset-state ivy-last))
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;
Now, we make a keymap to bind these commands so they are convenient to use. I will use C-arrows for swapping, and M-arrows for sorting the whole list. I also add M-&amp;lt;return&amp;gt; which allows me to use a numeric prefix to apply an action to all the candidates. M-&amp;lt;return&amp;gt; applies the default action. M-1 M-&amp;lt;return&amp;gt; applies the first action, M-2 M-&amp;lt;return&amp;gt; the second action, etc&amp;#x2026;
&lt;/p&gt;

&lt;p&gt;
This specific implementation assumes your candidates have a cdr.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; ivy-sort-keymap
      (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((map (make-sparse-keymap)))
        (define-key map (kbd &lt;span style="color: #008000;"&gt;"C-&amp;lt;up&amp;gt;"&lt;/span&gt;) 'ivy-move-up)
        (define-key map (kbd &lt;span style="color: #008000;"&gt;"C-&amp;lt;down&amp;gt;"&lt;/span&gt;) 'ivy-move-down)

        &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;sort all keys&lt;/span&gt;
        (define-key map (kbd &lt;span style="color: #008000;"&gt;"M-&amp;lt;up&amp;gt;"&lt;/span&gt;) 'ivy-a-z)
        (define-key map (kbd &lt;span style="color: #008000;"&gt;"M-&amp;lt;down&amp;gt;"&lt;/span&gt;) 'ivy-z-a)

        &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;map over all all entries with nth action&lt;/span&gt;
        (define-key map (kbd &lt;span style="color: #008000;"&gt;"M-&amp;lt;return&amp;gt;"&lt;/span&gt;)
          (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (arg)
            &lt;span style="color: #036A07;"&gt;"Apply the numeric prefix ARGth action to every candidate."&lt;/span&gt;
            (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt; &lt;span style="color: #008000;"&gt;"P"&lt;/span&gt;)
            &lt;span style="color: #8D8D84;"&gt;;; &lt;/span&gt;&lt;span style="color: #8D8D84; font-style: italic;"&gt;with no arg use default action&lt;/span&gt;
            (&lt;span style="color: #0000FF;"&gt;unless&lt;/span&gt; arg (&lt;span style="color: #0000FF;"&gt;setq&lt;/span&gt; arg (car (ivy-state-action ivy-last))))
            (ivy-beginning-of-buffer)
            (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((func (elt (elt (ivy-state-action ivy-last) arg) 1)))
              (&lt;span style="color: #0000FF;"&gt;loop&lt;/span&gt; for i from 0 to (- ivy--length 1)
                    do 
                    (funcall func
                             (&lt;span style="color: #0000FF;"&gt;let&lt;/span&gt; ((cand (elt
                                          (ivy-state-collection ivy-last)
                                          ivy--index)))
                               (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (listp cand)
                                   (cdr cand)
                                 cand)))
                    (ivy-next-line)))
            (ivy-exit-with-action
             (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (x) nil))))
        map))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Ok, now we modify our ivy-read function to use the keymap.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(&lt;span style="color: #0000FF;"&gt;defun&lt;/span&gt; &lt;span style="color: #006699;"&gt;ctn&lt;/span&gt; ()
  (&lt;span style="color: #0000FF;"&gt;interactive&lt;/span&gt;)
  (ivy-read &lt;span style="color: #008000;"&gt;"contact: "&lt;/span&gt; '((&lt;span style="color: #008000;"&gt;"Kno Body"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"kb@true.you"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"555-1212"&lt;/span&gt;)
                          (&lt;span style="color: #008000;"&gt;"A. Person"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"ap@some.come"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"867-5304"&lt;/span&gt;)
                          (&lt;span style="color: #008000;"&gt;"G. Willikers"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"gw@not.me"&lt;/span&gt; &lt;span style="color: #008000;"&gt;"555-5555"&lt;/span&gt;))
            &lt;span style="color: #006FE0;"&gt;:keymap&lt;/span&gt; ivy-sort-keymap
            &lt;span style="color: #006FE0;"&gt;:action&lt;/span&gt; '(1
                      (&lt;span style="color: #008000;"&gt;"o"&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (x)
                             (&lt;span style="color: #0000FF;"&gt;with-ivy-window&lt;/span&gt;
                               (insert
                                (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (not (looking-back &lt;span style="color: #008000;"&gt;" "&lt;/span&gt;)) &lt;span style="color: #008000;"&gt;", "&lt;/span&gt; &lt;span style="color: #008000;"&gt;""&lt;/span&gt;)
                                (elt x 0))))
                       &lt;span style="color: #008000;"&gt;"insert email"&lt;/span&gt;)
                      (&lt;span style="color: #008000;"&gt;"p"&lt;/span&gt; (&lt;span style="color: #0000FF;"&gt;lambda&lt;/span&gt; (x)
                             (&lt;span style="color: #0000FF;"&gt;with-ivy-window&lt;/span&gt;
                               (insert
                                (&lt;span style="color: #0000FF;"&gt;if&lt;/span&gt; (not (looking-back &lt;span style="color: #008000;"&gt;" "&lt;/span&gt;)) &lt;span style="color: #008000;"&gt;", "&lt;/span&gt; &lt;span style="color: #008000;"&gt;""&lt;/span&gt;)
                                (elt x 1))))
                       &lt;span style="color: #008000;"&gt;"insert phone"&lt;/span&gt;))))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
kb@true.you, gw@not.me, ap@some.come, 555-1212, 555-5555, 867-5304
&lt;/p&gt;
&lt;p&gt;Copyright (C) 2016 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;
&lt;p&gt;&lt;a href="/org/2016/06/13/Dynamic-sorting-with-ivy.org"&gt;org-mode source&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Org-mode version = 8.3.4&lt;/p&gt;]]></content:encoded>
    </item>
  </channel>
</rss>
