Org-Mode - How to create a new file with org-capture?

I want to create an org-capture template that creates a dynamic filename for capture in org-mode emacs.

I want the file name to have the following form: (format-time-string "% Y-% m-% d") "-" (prompt for the name) ".txt"

Example: 2012-08-10-MyNewFile.txt

Based on this answer, I know how to dynamically create a file name to include a date:

`(defun capture-report-date-file (path) (expand-file-name (concat path (format-time-string "%Y-%m-%d") ".txt"))) '(("t" "todo" entry (file (capture-report-date-file "~/path/path/name")) "* TODO"))) 

This allows me to create a 2012-08-10.txt file and insert * TODO in the first line

How can I add a prompt to complete the file name?

+6
source share
2 answers

You will need to use (read-string ...) in capture-report-data-file to generate the file name on the fly.

 (defun capture-report-data-file (path) (let ((name (read-string "Name: "))) (expand-file-name (format "%s-%s.txt" (format-time-string "%Y-%m-%d") name) path))) '(("t" "todo" entry (file (capture-report-date-file "~/path/path/name")) "* TODO"))) 

This will cause a capture for the file name, and then the capture buffer will open.

+10
source

I use the template and function below to create a new file.

  (defun psachin/create-notes-file () "Create an org file in ~/notes/." (interactive) (let ((name (read-string "Filename: "))) (expand-file-name (format "%s.org" name) "~/notes/"))) (setq org-capture-templates '(("n" "Notes" entry (file psachin/create-notes-file) "* TITLE%?\n %U"))) 
0
source

Source: https://habr.com/ru/post/922583/


All Articles