7

emacsorg-modeでキャプチャするための動的ファイル名を作成するorg-captureテンプレートを作成したいと思います。

ファイルの名前を次の形式にします:(format-time-string"%Y-%m-%d") "-"(名前の入力を求める)"。txt"

例:2012-08-10-MyNewFile.txt

この回答に基づいて、日付を含めるファイルの名前を動的に作成する方法を知っています。

`(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")))

これにより、ファイル2012-08-10.txtを作成し、最初の行に*TODOを挿入できます。

ファイル名を入力するためのプロンプトを追加するにはどうすればよいですか?

4

2 に答える 2

13

その場でファイル名を生成するには、を使用する必要があり(read-string ...)ます。capture-report-data-file

(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")))

これにより、キャプチャ時にファイル名の入力を求められ、キャプチャバッファが作成されます。

于 2012-08-10T13:59:28.007 に答える
2

以下のテンプレートと関数を使用して、新しいファイルを作成します。

  (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")))
于 2018-12-12T07:57:47.793 に答える