0

If you click on a file: link to a document that does not exist, org-mode will create this file for you.

How can I get this behavior to work with a org-capture template, so that files created in this way include the following header:

#+TITLE: {filename token}
#+AUTHOR: Me
#+DATE: {date token}
#+STARTUP: showall latexpreview inlineimages

%? <- Place pointer here {token}
1

I am not sure how to use the org-capture framework, but something like this is close to what you ask for above. The idea is to use a hook function to check if your file exists and if not insert the content you want in it. You might want to add additional checks that it is an org file.

(defun special-follow ()
  (let ((current-element (org-element-context))
    path)
    (when (and (eq 'link (car current-element))
           (string= "file" (org-element-property :type current-element)))
      (setq path (org-element-property :path current-element))
      (when (not (file-exists-p path))
    (with-temp-file path
      (insert (format "#+TITLE: %s
#+AUTHOR: Me
#+DATE: %s
#+STARTUP: showall latexpreview inlineimages

" path (current-time-string))))))))

(add-hook 'org-open-at-point-functions 'special-follow)

It would be interesting to see a capture solution too.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.