Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

emacs

org-mode

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

I want that the name of the file takes the following form: (format-time-string "%Y-%m-%d") "-" (prompt for a name) ".txt"

Example : 2012-08-10-MyNewFile.txt

Based on this answer, I know how to dynamically create the name the file to include the 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 file 2012-08-10.txt and to insert * TODO at the first line

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

like image 858
sam Avatar asked Aug 10 '12 13:08

sam


People also ask

How do you make a table in Org mode?

The easiest way to create a table is to directly type the "|" character at the beginning of a line, or after any amount of white space. This will put you in the first field of an atomic table. Once you've finished editing this cell, you can jump to the next one by pressing TAB .

What is org capture?

org-capture is a way to take notes in Emacs in an unobstructive way. It allows you to open a buffer to enter a note and it'll store it in the correct place based on the type of note you've selected. I must say that I took the term note from it's documentation, but I think that it's a very loose definition of the word.

Does vim have Org mode?

vim is a minimal Org mode and Outline mode plugin for Vim providing only syntax highlighting and folding. This plugin aims to replicate Vim's existing Markdown editing experience on Org mode (and Outline mode) files, rather than trying to be a full featured Org mode plugin—that is what Emacs is for.

What does Org mode do?

Org mode is routinely used to build and manage complex workflows. It does this using an elegantly simple syntax that scales from basic markup to full LaTeX typesetting and from plain text notes to literate programs. Everything you need to get started is demonstrated in the example.


2 Answers

You'll have to use (read-string ...) in capture-report-data-file to generate the filename on the fly.

(defun capture-report-date-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 prompt on capture for the file name, and then open the capture buffer will be created.

like image 143
Jonathan Leech-Pepin Avatar answered Oct 08 '22 04:10

Jonathan Leech-Pepin


I use below template & function to create 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")))
like image 36
psachin Avatar answered Oct 08 '22 06:10

psachin