From: Toby Cubitt <tsc25@cantab.net>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Allow %<num> escapes to capture templates, expanded to text entered in <num>'th prompt
Date: Mon, 23 Apr 2012 00:47:59 +0200 [thread overview]
Message-ID: <20120422224759.GA11176@c3po.home> (raw)
[-- Attachment #1: Type: text/plain, Size: 665 bytes --]
Currently, capture templates provide no way of prompting for some text,
then inserting that text into multiple places in the template.
This patch allow you to do this, by adding %<n> escapes to the template
syntax (where <n> is a digit, 0 to 9), which expand to the text entered
for the nth prompt in the template (as specified in the template using
the usual %^{prompt} syntax).
Useful for populating a subtree with an entire sequence of related TODOs,
capturing a multi-step task.
Toby
--
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain
email: tsc25@cantab.net
web: www.dr-qubit.org
[-- Attachment #2: 0001-Capture-Add-num-escapes-to-org-capture-templates.patch --]
[-- Type: text/x-patch, Size: 2663 bytes --]
From 0e917539324fdc32cd0878b0819cb28b79f30f01 Mon Sep 17 00:00:00 2001
From: "Toby S. Cubitt" <tsc25@cantab.net>
Date: Sat, 28 Jan 2012 17:04:05 +0100
Subject: [PATCH] Capture: Add %<num> escapes to org capture templates
* lisp/org-capture.el (org-capture-fill-template): Expand %<num>
escape sequences into text entered for <num>'th %^{PROMPT} escape.
---
lisp/org-capture.el | 24 ++++++++++++++++++------
1 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index f0afc70..2daca72 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -248,6 +248,8 @@ be replaced with content and expanded in this order:
A default value and a completion table ca be specified like this:
%^{prompt|default|completion2|completion3|...}.
%? After completing the template, position cursor here.
+ %<n> Insert the text entered for at the nth %^{prompt}, where <n>
+ represents a digit, 0 to 9.
Apart from these general escapes, you can access information specific to the
link type that is created. For example, calling `org-capture' in emails
@@ -1326,7 +1328,7 @@ The template may still contain \"%?\" for cursor positioning."
(org-startup-folded nil)
(org-inhibit-startup t)
org-time-was-given org-end-time-was-given x
- prompt completions char time pos default histvar)
+ prompt completions char time pos default histvar strings)
(setq org-store-link-plist
(plist-put org-store-link-plist :annotation v-a)
@@ -1468,11 +1470,21 @@ The template may still contain \"%?\" for cursor positioning."
nil nil (list org-end-time-was-given)))
(t
(let (org-completion-use-ido)
- (insert (org-completing-read-no-i
- (concat (if prompt prompt "Enter string")
- (if default (concat " [" default "]"))
- ": ")
- completions nil nil nil histvar default)))))))
+ (push (org-completing-read-no-i
+ (concat (if prompt prompt "Enter string")
+ (if default (concat " [" default "]"))
+ ": ")
+ completions nil nil nil histvar default)
+ strings)
+ (insert (car strings)))))))
+ ;; Replace %n escapes with nth %^{...} string
+ (setq strings (nreverse strings))
+ (goto-char (point-min))
+ (while (re-search-forward "%\\([1-9]\\)+" nil t)
+ (unless (org-capture-escaped-%)
+ (replace-match
+ (nth (1- (string-to-number (match-string 1))) strings)
+ nil t)))
;; Make sure there are no empty lines before the text, and that
;; it ends with a newline character
(goto-char (point-min))
--
1.7.8.5
next reply other threads:[~2012-04-22 22:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-22 22:47 Toby Cubitt [this message]
2012-04-23 12:54 ` [PATCH] Allow %<num> escapes to capture templates, expanded to text entered in <num>'th prompt Bastien
2012-04-23 15:08 ` Toby Cubitt
2012-04-23 15:12 ` Bastien
2012-04-23 15:29 ` Toby Cubitt
2012-04-23 15:34 ` Bastien
2012-04-24 9:57 ` Bastien
2012-04-24 11:05 ` Toby Cubitt
2012-04-24 12:51 ` Bastien
2012-04-24 13:37 ` Toby Cubitt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120422224759.GA11176@c3po.home \
--to=tsc25@cantab.net \
--cc=emacs-orgmode@gnu.org \
--cc=toby-dated-1336344506.0e3262@dr-qubit.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).