From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id SKdaLgBMYGZjvQAAe85BDQ:P1 (envelope-from ) for ; Wed, 05 Jun 2024 13:29:05 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id SKdaLgBMYGZjvQAAe85BDQ (envelope-from ) for ; Wed, 05 Jun 2024 13:29:04 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=nXFfEKQF; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1717586944; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=rz3OaDkZQeHLHqLcQpfD7hAu9/GtygmmrLw7DCmAlHI=; b=JNLpxqnPTyMk8v8o8ROpkIdMlKlnMgHaThFUlKpBBNpquaPlZ1fL7CPelDev84ByizVmuW rtawQ7lSVBXY/BaL4ovyW1nV+S5YI80t3TWKV7izR68aypxYP7CXMYxrRkvMFT6D+jTTMH SKspxyl21Evu6bzeo6GE70KUaHokT4hRppCOUHRVVS7RMAzxtuMeELdeo2uf2gBN7MIfV6 H2ie1VYaSJJ7Ir8M6Bi8C9quP2k2j+1eXaZVLjH5d0BzfLVVSS0KXdrJzcUUlESW5VnQ0g dVFeM8Uyh+zCprYbwvBi+3ro/jhkhU0SpQUDytReorbRw/OStQIEUpCTL98GAA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=nXFfEKQF; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1717586944; a=rsa-sha256; cv=none; b=ZzTQ3rln4wpcyxySjJUPaQ+pB/HT9gpwsBk2pRTwkVsEX/YGuW874F1wASRubHOnpPEcm6 WNuDlp+fN/wv7TeTrUJJX18HNU4t2S9dXixL9a5Sssso20hzFiMjiankZtQBrRMA6KexT2 Mz39qTSOPanX+c3Gjo9gVvWilnIRHrJnUYyScwHMfH+oBZm4sNus89HYVX3U7rutcdHwFw d4ASsgNRrKDTlQtuBWDi7GQy/g6TZj5QoxXMQbGnwZPkL3Eq5XBcw4wxlZA/NT5dwqS+HT neiE4ubPqP3OkNS9XNFm2P9yMWM99rLEUOhMKngd7vNHq7CxPdw43VTp3YTnfg== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1D06B1401C for ; Wed, 5 Jun 2024 13:29:03 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEonn-0006nb-04; Wed, 05 Jun 2024 07:27:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEonl-0006eB-59 for emacs-orgmode@gnu.org; Wed, 05 Jun 2024 07:27:33 -0400 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEoni-0003Qr-Ba for emacs-orgmode@gnu.org; Wed, 05 Jun 2024 07:27:32 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 04ADB240104 for ; Wed, 5 Jun 2024 13:27:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1717586848; bh=Ww54zolWSegj0kkPnflslIuZnoQNDvnDPxF3NAfOljE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=nXFfEKQFrqz97EM+4LtBLIegyLmqBmVlNuVSIHYX4PF+CwxNf15WagO+9BZfxziUX EsJ499fWWGYO5zTM3KyvHQDPNF56RJYGqKsK8kN7rL19FMBkb9pFGymaC2e/9AD8gB ocqezJ7Nx+2QMKbejReP/tk2kTYyl4O+JjjuZdVhJXXTXHeYiB2aVyFmjYKPy50EmJ c52NcF2S1xyKdU6GROv3/YOfkZOuQLf1kG9N2wTFwxaOQRW/khymBsQkj6wvPvvXDG m7cUOYs2Kga6aI1xmeMZstvUefYvCHul47eqgH+AWZsaEVuDFVLtEzPfuY9KCTP7Hy aEtfgSIPuFFNQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4VvQDH4DBVz6tmv; Wed, 5 Jun 2024 13:27:27 +0200 (CEST) From: Ihor Radchenko To: Bruno Cardoso Cc: emacs-orgmode@gnu.org Subject: Re: [BUG] org-capture: %\N template expansion In-Reply-To: <87le40puvb.fsf@gmail.com> References: <87o78xz697.fsf@gmail.com> <87msogye59.fsf@localhost> <87le40puvb.fsf@gmail.com> Date: Wed, 05 Jun 2024 11:29:10 +0000 Message-ID: <87ikyn7hmh.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -9.56 X-Spam-Score: -9.56 X-Migadu-Queue-Id: 1D06B1401C X-Migadu-Scanner: mx13.migadu.com X-TUID: PcokCzrYjk4s --=-=-= Content-Type: text/plain Bruno Cardoso writes: >> We may also make %^{prompt}X expansions to work with %\N, but it can >> break the existing templates that are tuned to the current behaviour. > > I see. Would it make sense to have another placeholder for '%^{prompt}X'? See the attached tentative patch. I introduced a new placeholder - %\*N. It refers to _all_ the prompts, unlike %\N. If you have better ideas about syntax, please share. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-capture-templates-New-placeholder-to-refer-to-pr.patch >From 276f7755e0337631eb9a202a8275fcbe7f1cdfe8 Mon Sep 17 00:00:00 2001 Message-ID: <276f7755e0337631eb9a202a8275fcbe7f1cdfe8.1717586846.git.yantar92@posteo.net> From: Ihor Radchenko Date: Wed, 5 Jun 2024 13:24:43 +0200 Subject: [PATCH] org-capture-templates: New placeholder to refer to %^{prompt}X answers * lisp/org-capture.el (org-capture-fill-template): Support new placeholder %\*N to insert answers to all prompts - %^{prompt} and %^{prompt}X. (org-capture-templates): * etc/ORG-NEWS (New =%\*N= placeholder in ~org-capture-templates~): * doc/org-manual.org (Template expansion): Document the new placeholder. Link: https://orgmode.org/list/87le40puvb.fsf@gmail.com --- doc/org-manual.org | 8 ++++++-- etc/ORG-NEWS | 5 +++++ lisp/org-capture.el | 50 ++++++++++++++++++++++++++++++++------------- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 170eea506..fd842acca 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -8338,8 +8338,12 @@ **** Template expansion - =%\N= :: - Insert the text entered at the {{{var(N)}}}th =%^{PROMPT}=, where - {{{var(N)}}} is a number, starting from 1. + Insert the text entered at the {{{var(N)}}}th =%^{PROMPT}= (but not + =%^{PROMPT}X=), where {{{var(N)}}} is a number, starting from 1. + +- =%\*N= :: + + Same as =%\N=, but include all the prompts. - =%?= :: diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 4b0b77ca8..52c6cb7b2 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -29,6 +29,11 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org. # adding new customizations, or changing the interpretation of the # existing customizations. +*** New =%\*N= placeholder in ~org-capture-templates~ + +The new placeholder is like =%\N=, gives access not only to the +=%^{prompt}= values, but also to =%^{prompt}X= values. + *** The default value of ~org-babel-latex-process-alist~ is no longer taken from ~org-preview-latex-process-alist~ The default value used to be pulled from =dvipng= process type from diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 34f9363e2..1dbe422d1 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -376,8 +376,10 @@ (defcustom org-capture-templates nil prompt/completions. Default value and completions as in %^{prompt|default|...}X are allowed. %? After completing the template, position cursor here. - %\\1 ... %\\N Insert the text entered at the nth %^{prompt}, where N - is a number, starting from 1. + %\\1 ... %\\N Insert the text entered at the nth %^{prompt} (but not + %^{prompt}X), where N is a number, starting from 1. + %\\*1...%\\*N Same as \\N, but for all the prompts, including + %^{prompt} and %^{prompt}X. Apart from these general escapes, you can access information specific to the link type that is created. For example, calling `org-capture' in emails @@ -1783,7 +1785,9 @@ (defun org-capture-fill-template (&optional template initial annotation) ;; completion in interactive prompts. (let ((org-inhibit-startup t)) (org-mode)) (org-clone-local-variables buffer "\\`org-") - (let (strings) ; Stores interactive answers. + (let (strings ; Stores interactive answers. + strings-all ; ... include %^{prompt}X answers + ) (save-excursion (let ((regexp "%\\^\\(?:{\\([^}]*\\)}\\)?\\([CgGLptTuU]\\)?")) (while (re-search-forward regexp nil t) @@ -1818,6 +1822,7 @@ (defun org-capture-fill-template (&optional template initial annotation) 'org-tags-history)) ":"))) (when (org-string-nw-p ins) + (push (concat ":" ins ":") strings-all) (unless (eq (char-before) ?:) (insert ":")) (insert ins) (unless (eq (char-after) ?:) (insert ":")) @@ -1827,13 +1832,18 @@ (defun org-capture-fill-template (&optional template initial annotation) (lambda (s) (org-insert-link 0 s))))) (pcase org-capture--clipboards (`nil nil) - (`(,value) (funcall insert-fun value)) + (`(,value) + (funcall insert-fun value) + (push value strings-all)) (`(,first-value . ,_) (funcall insert-fun - (read-string "Clipboard/kill value: " - first-value - 'org-capture--clipboards - first-value))) + (let ((val + (read-string "Clipboard/kill value: " + first-value + 'org-capture--clipboards + first-value))) + (push val strings-all) + val))) (_ (error "Invalid `org-capture--clipboards' value: %S" org-capture--clipboards))))) ("p" @@ -1865,17 +1875,20 @@ (defun org-capture-fill-template (&optional template initial annotation) (if l (point-marker) (point-min-marker))))))) (value - (org-read-property-value prompt pom default))) - (org-set-property prompt value))) + (org-read-property-value prompt pom default))) + (org-set-property prompt value) + (push value strings-all))) ((or "t" "T" "u" "U") ;; These are the date/time related ones. (let* ((upcase? (equal (upcase key) key)) (org-end-time-was-given nil) (time (org-read-date upcase? t nil prompt))) - (org-insert-timestamp - time (or org-time-was-given upcase?) - (member key '("u" "U")) - nil nil (list org-end-time-was-given)))) + (push + (org-insert-timestamp + time (or org-time-was-given upcase?) + (member key '("u" "U")) + nil nil (list org-end-time-was-given)) + strings-all))) (`nil ;; Load history list for current prompt. (setq org-capture--prompt-history @@ -1885,6 +1898,7 @@ (defun org-capture-fill-template (&optional template initial annotation) completions nil nil nil 'org-capture--prompt-history default) strings) + (push (car strings) strings-all) (insert (car strings)) ;; Save updated history list for current prompt. (puthash prompt org-capture--prompt-history @@ -1899,6 +1913,14 @@ (defun org-capture-fill-template (&optional template initial annotation) (unless (org-capture-escaped-%) (replace-match (nth (1- (string-to-number (match-string 1))) strings) + nil t)))) + ;; Replace %*n escapes with nth %^{...} string. + (setq strings-all (nreverse strings-all)) + (save-excursion + (while (re-search-forward "%\\\\\\(\\*\\([1-9][0-9]*\\)\\)" nil t) + (unless (org-capture-escaped-%) + (replace-match + (nth (1- (string-to-number (match-string 2))) strings-all) nil t))))) ;; Make sure there are no empty lines before the text, and that ;; it ends with a newline character or it is empty. -- 2.45.1 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--