I’m hoping this is an easy question: I want to create a small function that I can run with a key binding that creates a node and inserts a template automatically (so, bypassing any question about which template to use). I just want to go straight to start typing in a new node. I’m hoping to prompt for a title and then start typing. It’s for quickly filing a link, primarily. The template will take the url from the clipboard and insert it into the template. Which function would I start with?
I’m guessing the entry point would be org-roam-capture, but with all of the parameters filled out and only one template provided. Has anyone does this and could show me an example?
Actually, I think I found it (mostly copied from another thread):
(defun eds/strip-invalid-chars (title)
"Strip characters that don't work in filenames or github branches"
(replace-regexp-in-string "[\\?\\>\\<\\|\\:\\&]" "" title))
(defun eds/process-title (title)
"Downcase and hyphenate a title case string. Remove characters
that don't work in a filename."
(eds/strip-invalid-chars (mapconcat 'identity (split-string (downcase title)) "-")))
(defun eds/create-new-note-from-clipboard-link (title)
"Create a new note file in `org-roam-directory' and insert a link."
(interactive "sTitle: ")
(let* ((time-string (format-time-string "%Y%m%dT%H%M%S"))
(clipboard-content (or (gui-get-selection 'CLIPBOARD) "Clipboard is empty."))
(extension "org")
(slug (eds/process-title title))
(file-base-name (concat time-string "-" slug "." extension))
(org-roam-directory (eds/get-org-directory))
(file-name (expand-file-name file-base-name org-roam-directory))
(title-line (format "#+title: %s\n" title))
(startup-line "#+startup: content\n")
(link-line (format "* [[%s][%s]]\n" clipboard-content title)))
(find-file file-name)
;; In the new buffer
(insert (concat title-line startup-line link-line))
(beginning-of-buffer)
(org-id-get-create)
(end-of-buffer)
(save-buffer)
(org-roam-db-sync)))
you can in the future look into org-roam-protocol which can be used to interact with the outside-emacs world - for example creating a node from the link in a webpage and so on. Might be useful to your usecase.
All you need to do is create a file in the org-roam directory (or children) with at least one node (either the file ID or a header with an ID) and it will be automatically added to the org-roam database.
That, however, does no “run” the template.
if you want to actually run the template as if you provided the key, see the code of the function:
org-roam-dailies–capture
it calls org-roam-capture as it was called interactively