Using Embark and qrencode to show a QR code for the Org Mode link at point

Posted: - Modified: | emacs, org

[2024-01-12 Fri]: Added some code to display the QR code on the right side.

John Kitchin includes little QR codes in his videos. I thought that was a neat touch that makes it easier for people to jump to a link while they're watching. I'd like to make it easier to show QR codes too. The following code lets me show a QR code for the Org link at point. Since many of my links use custom Org link types that aren't that useful for people to scan, the code reuses the link resolution code from https://sachachua.com/dotemacs#web-link so that I can get the regular https: link.

(defun my-org-link-qr (url)
  "Display a QR code for URL in a buffer."
  (let ((buf (save-window-excursion (qrencode--encode-to-buffer (my-org-stored-link-as-url url)))))
    (display-buffer-in-side-window buf '((side . right)))))

(use-package qrencode
  :config
  (with-eval-after-load 'embark
    (define-key embark-org-link-map (kbd "q") #'my-org-link-qr)))
qr-code.svg
Figure 1: Screenshot of QR code for the link at point
View org source for this post
This is part of my Emacs configuration.
You can comment with Disqus or you can e-mail me at sacha@sachachua.com.