From bd11460542bfd5f662d6c0850159ed76222a8d63 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Fri, 7 Jan 2011 15:28:57 +0100 Subject: [PATCH] Make file and path accessible in capture templates * lisp/org-capture.el (org-capture-templates): Add %f and %F escapes (org-capture): Add more information to capture property list (org-capture-fill-template): Handle %f and %F escapes --- doc/org.texi | 2 ++ lisp/org-capture.el | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 43fc13aa1..e83909d4c 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -6409,6 +6409,8 @@ dynamic insertion of content: %^L @r{Like @code{%^C}, but insert as link.} %k @r{title of the currently clocked task} %K @r{link to the currently clocked task} +%f @r{file visited by current buffer when org-capture was called} +%F @r{like @code{%f}, but include full path} %^g @r{prompt for tags, with completion on tags in target file.} %^G @r{prompt for tags, with completion all tags in all agenda files.} %^@{@var{prop}@}p @r{Prompt the user for a value for property @var{prop}} diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 85747eed6..a28c3b881 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -215,6 +215,8 @@ Furthermore, the following %-escapes will be replaced with content: %^L like %^C, but insert as link %k title of currently clocked task %K link to currently clocked task + %f file visited by current buffer when org-capture was called + %F like @code{%f}, but include full path %^g prompt for tags, with completion on tags in target file %^G prompt for tags, with completion on all tags in all agenda files %^{prop}p prompt the user for a value for property `prop' @@ -415,7 +417,13 @@ bypassed." (t (org-capture-set-plist entry) (org-capture-get-template) - (org-capture-put :original-buffer orig-buf :annotation annotation + (org-capture-put :original-buffer orig-buf + :original-file (buffer-file-name orig-buf) + :original-file-nondirectory + (and (buffer-file-name orig-buf) + (file-name-nondirectory + (buffer-file-name orig-buf))) + :annotation annotation :initial initial) (org-capture-put :default-time (or org-overriding-default-time @@ -1164,6 +1172,8 @@ The template may still contain \"%?\" for cursor positioning." (org-make-link-string (buffer-file-name (marker-buffer org-clock-marker)) org-clock-heading))) + (v-f (or (org-capture-get :original-file-nondirectory) "")) + (v-F (or (org-capture-get :original-file) "")) v-I (org-startup-folded nil) (org-inhibit-startup t) @@ -1213,7 +1223,7 @@ The template may still contain \"%?\" for cursor positioning." ;; Simple %-escapes (goto-char (point-min)) - (while (re-search-forward "%\\([tTuUaiAcxkKI]\\)" nil t) + (while (re-search-forward "%\\([tTuUaiAcxkKInfF]\\)" nil t) (unless (org-capture-escaped-%) (when (and initial (equal (match-string 0) "%i")) (save-match-data