0

Recently my org-mode config broke. And i started using ` and , to get it to work again. But now i have the issue that a function call (dl/capture-report-date-file) gets evaluated once and curries the time value (which is the time, and should be dynamic) for all future captures. I'd like it to get evaluated each time I capture, and have a different date each time. I am not an elisp dev.

(with-eval-after-load "org"
  (setq org-capture-templates
        `(("c" "manual-headline" entry
           (file ,(dl/capture-report-date-file
                   (concat org-directory "/notes")))
           "* SOON %?     \n:PROPERTIES:\n:CREATED: %U\n:SOURCE: %a\n:END:\n\n%i\n"))))
  • I use this for my time-stamp <%<%Y-%m-%d %a 08:30>> inside the org-capture-templates. It uses the standard format options and could use the current time instead of 08:30 if you prefer. See the doc-string of the variable format-time-string for formatting options. – lawlist Apr 18 '18 at 13:54
1

According to (info "(org) Template elements"), when setting capture target, instead of supplying a filename, you can also use a function:

(function function-finding-location)

Most general way: write your own function which both visits the file and moves point to the right location.

You can take a look at the following as an example, it picks a filename base on the current time.

(setq org-capture-templates
      '(("c" "manual-headline" entry
         (function
          (lambda ()
            (let ((filename (format-time-string "/tmp/%Y-%m-%d-%H:%M.org")))
              (set-buffer (find-file-noselect filename))
              (goto-char (point-max)))))
         "* SOON %? %U")))

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.