Browse Source

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
Carsten Dominik 10 years ago
parent
commit
bd11460542
2 changed files with 14 additions and 2 deletions
  1. 2 0
      doc/org.texi
  2. 12 2
      lisp/org-capture.el

+ 2 - 0
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}}

+ 12 - 2
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