EmacsConf backstage: jumping to and working with talks using Embark

| emacs, emacsconf

In the course of organizing and running EmacsConf, I often need to jump to or act on specific talks. I have a function that jumps to the talk heading so that I can look up additional information or add notes.

output-2023-09-10-14:04:30.gif
Figure 1: Jumping to a talk

emacsconf-go-to-talk: Jump to the talk heading matching SEARCH.
(defun emacsconf-go-to-talk (search)
  "Jump to the talk heading matching SEARCH."
  (interactive (list (emacsconf-complete-talk)))
  (find-file emacsconf-org-file)
  (widen)
  (cond
   ((plist-get search :slug)
    (goto-char (org-find-property "SLUG" (plist-get search :slug))))
   ((emacsconf-get-slug-from-string search)
    (goto-char (org-find-property "SLUG" (emacsconf-get-slug-from-string search))))
   (t
    (goto-char
     (catch 'found
       (org-map-entries
        (lambda ()
          (when (string-match search
                              (cons
                               (concat (org-entry-get (point) "SLUG") " - "
                                       (org-entry-get (point) "ITEM") " - "
                                       (org-entry-get (point) "NAME") " - "
                                       (org-entry-get (point) "EMAIL"))
                               (point)))
            (throw 'found (point))))
        "SLUG={.}")))))
  (org-reveal))

Most of the work is done in a completion function that makes it easy to specify a talk using the slug (talk ID), title, or speaker names.

emacsconf-complete-talk: Offer talks for completion.
(defun emacsconf-complete-talk (&optional info)
  "Offer talks for completion.
If INFO is specified, limit it to that list."
  (let ((choices
         (if (and (null info) emacsconf-complete-talk-cache)
             emacsconf-complete-talk-cache
           (mapcar (lambda (o)
                     (string-join
                      (delq nil
                            (mapcar (lambda (f) (plist-get o f))
                                    '(:slug :title :speakers :irc)))
                      " - "))
                   (or info (emacsconf-get-talk-info))))))
    (completing-read
     "Talk: " 
     (lambda (string predicate action)
       (if (eq action 'metadata)
           '(metadata (category . emacsconf))
         (complete-with-action action choices string predicate))))))

In addition to jumping to the Org heading for a talk, there are a bunch of other things I might want to do. Embark lets me add a bunch of shortcuts for working with a talk. I could open the caption file, edit the talk's wiki page, change a talk's property, e-mail the speaker, or more. Here's the Embark-related code from emacsconf.el:

Embark-related code
;;; Embark
(defun emacsconf-embark-finder ()
  "Identify when we're on a talk subtree."
  (when (and (derived-mode-p 'org-mode)
             (org-entry-get-with-inheritance "SLUG"))
    (cons 'emacsconf (org-entry-get-with-inheritance "SLUG"))))

(defun emacsconf-insert-talk-title (search)
  "Insert the talk title matching SEARCH."
  (interactive (list (emacsconf-complete-talk)))
  (insert (plist-get (emacsconf-search-talk-info search) :title)))

(with-eval-after-load 'embark
  (add-to-list 'embark-target-finders 'emacsconf-embark-finder)
  (defvar-keymap embark-emacsconf-actions
    :doc "Keymap for emacsconf-related things"
    "a" #'emacsconf-announce
    "c" #'emacsconf-find-captions-from-slug
    "d" #'emacsconf-find-caption-directives-from-slug
    "p" #'emacsconf-set-property-from-slug
    "w" #'emacsconf-edit-wiki-page
    "s" #'emacsconf-set-start-time-for-slug
    "W" #'emacsconf-browse-wiki-page
    "u" #'emacsconf-update-talk
    "t" #'emacsconf-insert-talk-title
    "m" #'emacsconf-mail-speaker-from-slug
    "n" #'emacsconf-notmuch-search-mail-from-entry
    "f" #'org-forward-heading-same-level
    "b" #'org-backward-heading-same-level
    "RET" #'emacsconf-go-to-talk)
  (add-to-list 'embark-keymap-alist '(emacsconf . embark-emacsconf-actions)))

;;; Status updates

For example, I sometimes need to open the wiki page for a talk in order to update the talk description.

emacsconf-edit-wiki-page: Open the wiki page for the talk matching SEARCH.
;;; Embark
(defun emacsconf-embark-finder ()
  "Identify when we're on a talk subtree."
  (when (and (derived-mode-p 'org-mode)
             (org-entry-get-with-inheritance "SLUG"))
    (cons 'emacsconf (org-entry-get-with-inheritance "SLUG"))))

Embark can also act on completion candidates, so I can call any of those actions from my C-c e t shortcut for emacsconf-go-to-talk. This is specified by the (metadata (category . emacsconf)) in emacsconf-complete-talk and the (add-to-list 'embark-keymap-alist '(emacsconf . embark-emacsconf-actions)) in my Embark configuration.

C-. is the embark-act shortcut in my configuration. When I need to remember what the shortcuts are, I can use C-h (embark-keymap-help) to list the keyboard shortcuts or select the command with completion.

output-2023-09-10-20:45:31.gif
Figure 2: Embark help for Emacsconf talks

The code above and related functions are in emacsconf.el or other files in the emacsconf-el repository.

You can comment with Disqus or you can e-mail me at sacha@sachachua.com.