Notes from a Machinist

I'm late to the party. Again.

Implicit Buttons Are Cool

2022-12-11

I recently learned about hyperbole and its support for ‘implicit buttons’ and it helps me solve something in emacs. In my work as a machinist, I track a lot of things using org roam, including parts, which have part numbers that follow a specific syntax. They look something like: A123BC456D.

Often enough I want to create a separate org roam entry for a part, but I don’t necessarily want to go looking for places where the part number appears to create links to that entry. Hyperbole’s implicit buttons work well for this, letting me hit meta-enter on any part number (in org roam or not) and jumping to the correct entry if it exists or letting me create it if it does not already exist.

Here is the config:

(use-package hyperbole
  :ensure t

  :init
  (defconst part_no-re "[A-Z][0-9]\\{2,3\\}[A-Z]\\{2\\}[0-9]\\{3\\}[A-Z]")

  :config
  (require 'thingatpt)
  (defun open-partno (partno)
    (require 'org-roam)
    (org-roam-node-find nil partno))

  (defib partno ()
    "Make a part number open/create the associated org roam buffer."

    (let ((part-no (when (thing-at-point-looking-at part_no-re)
                     (buffer-substring (match-beginning 0) (match-end 0)))))
      (when part-no
        (hact 'open-partno part-no)))))

My elisp is weak, so I’m sure the above configuration could be more elegant, but it does work.

The video is here. If you have trouble playing the video on that page, click through the ‘Toobnix’ link near the bottom.

Discussion here