Created
June 25, 2024 02:01
-
-
Save dmgerman/40e8785c37c1043dab452f87332fd548 to your computer and use it in GitHub Desktop.
Extract Fields from org-roam template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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