Skip to content

Instantly share code, notes, and snippets.

@dmgerman
Created June 25, 2024 02:01
Show Gist options
  • Save dmgerman/40e8785c37c1043dab452f87332fd548 to your computer and use it in GitHub Desktop.
Save dmgerman/40e8785c37c1043dab452f87332fd548 to your computer and use it in GitHub Desktop.
Extract Fields from org-roam template
(defun org-roam-template-extract-fields (template)
"return a list with the names of the fields used
in the given template"
(let (
(result '())
(pos 0)
)
(while (string-match "\\${\\([^}]+\\)}" template pos)
;; position should be saved first, since
;; we use another string match inside
;; and it is not reentrant
(setq pos (match-end 0))
(setq result (cons
;; concat current field
;; up to :
(let (
(st (match-string 1 template))
)
(substring st 0 (string-match ":" st))
)
result))
)
(reverse result)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment