Using template files in dailies capture templates

Hi, all—just getting my feet wet with org-roam. Thanks for creating something so wonderful.

I’m having trouble setting up org-roam-dailies-capture-templates, specifically when using template files. I like template files, because I modify my templates incrementally over time and find it easier to jump directly to a file defining the template than wade through my entire emacs config before finding the template.

So, I naturally tried defining a dailies capture template using a template file, e.g.:

  (setq org-roam-dailies-directory "daily/"
        org-roam-dailies-capture-templates
        '(
          ("d" "default" entry #'org-roam-capture--get-point
           (file "~/org/templates/awesome-template.org")
           :file-name "daily/%<%Y-%m-%d>"
           :head "#+title: %<%Y-%m-%d>\n\n")))

Here’s what I found:

  • org-roam-dailies-capture-today has no problem with the template defined above
  • org-roam-dailies-today throws an error: Wrong type argument: characterp, file
  • org-roam-dailies-find-today throws the same error

I don’t have these problems with either org-capture-templates or org-roam-capture-templates.

Can someone help me understand what’s going on? Thanks!

Could you run M-x toggle-debug-on-error to produce a stacktrace, this may help see where the error is coming from.

Sure!

After M-x toggle-debug-on-error, and using the settings from my original post, I called org-roam-dailies-today. I had already created a daily file for today and had a few headings there.

Emacs spit out the following backtrace (This was dispatched through helm-M-x, so I’ve only included the part after org-roam-dailies-find-today is called)

  concat("#+title: %<%Y-%m-%d>\n\n" (file "~/sync/josh/org/templates/daily-preview.org"))
  (let* ((name-templ (or (org-roam-capture--get :file-name) (user-error "Template needs to specify `:file-name'"))) (new-id (s-trim (org-roam-capture--fill-template name-templ))) (file-path (org-roam--file-path-from-id new-id)) (roam-head (or (org-roam-capture--get :head) "")) (org-template (org-capture-get :template)) (roam-template (concat roam-head org-template))) (if (or (file-exists-p file-path) (cl-some #'(lambda (buffer) (string= (buffer-file-name buffer) file-path)) (buffer-list))) nil (make-directory (file-name-directory file-path) t) (org-roam-capture--put :orig-no-save (org-capture-get :no-save) :new-file t) (if (eq org-roam-capture--context 'dailies) (progn (let ((wconfig (current-window-configuration))) (unwind-protect (progn (find-file file-path) (insert ...) (set-buffer-modified-p nil)) (set-window-configuration wconfig))) (org-capture-put :template org-template)) (org-capture-put :template roam-template :type 'plain)) (org-capture-put :no-save t)) file-path)
  org-roam-capture--new-file()
  (cond ((eq org-roam-capture--context 'capture) (or (cdr (assoc 'file org-roam-capture--info)) (org-roam-capture--new-file))) ((eq org-roam-capture--context 'title) (org-roam-capture--new-file)) ((eq org-roam-capture--context 'dailies) (org-capture-put :default-time (cdr (assoc 'time org-roam-capture--info))) (org-roam-capture--new-file)) ((eq org-roam-capture--context 'ref) (let ((completions (org-roam--get-ref-path-completions)) (ref (cdr (assoc 'ref org-roam-capture--info)))) (let* ((pl (and t (cdr ...)))) (if pl (plist-get pl :path) (org-roam-capture--new-file))))) (t (error "Invalid org-roam-capture-context")))
  (let* ((file-path (cond ((eq org-roam-capture--context 'capture) (or (cdr (assoc ... org-roam-capture--info)) (org-roam-capture--new-file))) ((eq org-roam-capture--context 'title) (org-roam-capture--new-file)) ((eq org-roam-capture--context 'dailies) (org-capture-put :default-time (cdr (assoc ... org-roam-capture--info))) (org-roam-capture--new-file)) ((eq org-roam-capture--context 'ref) (let ((completions ...) (ref ...)) (let* (...) (if pl ... ...)))) (t (error "Invalid org-roam-capture-context"))))) (org-capture-put :template (org-roam-capture--fill-template (org-capture-get :template))) (org-roam-capture--put :file-path file-path :finalize (or (org-capture-get :finalize) (org-roam-capture--get :finalize))) (while org-roam-capture-additional-template-props (let ((prop (car-safe (prog1 org-roam-capture-additional-template-props (setq org-roam-capture-additional-template-props ...)))) (val (car-safe (prog1 org-roam-capture-additional-template-props (setq org-roam-capture-additional-template-props ...))))) (org-roam-capture--put prop val))) (set-buffer (org-capture-target-buffer file-path)) (widen) (let* ((olp (and t (org-roam-capture--get :olp)))) (if olp (condition-case err (let* ((marker (and t ...))) (if marker (progn (goto-char marker) (set-marker marker nil)) nil)) (error (if (org-roam-capture--get :new-file) (progn (kill-buffer))) (signal (car err) (cdr err)))) (goto-char (point-max)))))
  org-roam-capture--get-point()
  org-capture-set-target-location()
  org-capture-goto-target("d")
  org-capture((4) "d")
  (if (or one-template-p (eq org-roam-capture-function 'org-capture)) (org-capture goto keys) (funcall-interactively org-roam-capture-function))
  (let* ((org-capture-templates (mapcar #'org-roam-capture--convert-template org-roam-capture-templates)) (one-template-p (= (length org-capture-templates) 1)) org-capture-templates-contexts (org-capture-link-is-already-stored t)) (if one-template-p (progn (setq keys (car (car org-capture-templates))))) (if (or one-template-p (eq org-roam-capture-function 'org-capture)) (org-capture goto keys) (funcall-interactively org-roam-capture-function)))
  org-roam-capture--capture((4))
  (let ((org-roam-capture-templates (let ((it org-roam-dailies-capture-templates)) (if goto (list (car it)) it))) (org-roam-capture--info (list (cons 'time time))) (org-roam-capture--context 'dailies)) (org-roam-capture--capture (if goto (progn '(4)))))
  org-roam-dailies--capture((24531 50014 608564 0) t)
  org-roam-dailies-capture-today(t)
  org-roam-dailies-find-today()

I’m not familiar with the inner logic of org-capture or org-roam, so any pointers would be appreciated!