emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Skip Collins <skip.collins@gmail.com>
Cc: emacs-org list <emacs-orgmode@gnu.org>
Subject: [PATCH] Re: [BUG] folding error during capture
Date: Mon, 02 May 2022 08:17:20 +0800	[thread overview]
Message-ID: <87mtg0vldb.fsf@localhost> (raw)
In-Reply-To: <CABUh-776V-_+_JAZwcKQm9ATcs0WUV9SmGwjooGFbt=CtwQj8g@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 981 bytes --]

Skip Collins <skip.collins@gmail.com> writes:

> Recently, I get an error message when invoking custom capture
> templates like this one:
> ("n" "Note" entry
>       (file "~/Documents/org/beorg/capture.org")
>       "* %^{note} :note: %(org-set-property \"Created\"
> (org-time-stamp-inactive '(16)))" :immediate-finish t)
> ...
> But the pre-populated *Capture* window contains an error message:
> *  :note: %![Error: (error Calling ‘org-fold-core-region’ with missing SPEC)]

Thanks for the report!
This is quite a hacky capture template...
What you are seeing happens because template expansion happens in
fundamental-mode and org-set-property does not work anymore outside

I'd say that setting org-mode during template expansion is reasonable.

The fix is attached.

I do not push the fix just yet. If anyone think that enabling org-mode
during template expansion is undesired, please let me know.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-capture-Expand-sexps-in-template-with-Org-mode-b.patch --]
[-- Type: text/x-patch, Size: 2387 bytes --]

From 797dfd0c82c68696d8534a9b3103d0b3c622bee6 Mon Sep 17 00:00:00 2001
Message-Id: <797dfd0c82c68696d8534a9b3103d0b3c622bee6.1651450441.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Mon, 2 May 2022 08:11:28 +0800
Subject: [PATCH] org-capture: Expand sexps in template with Org mode being

* lisp/org-capture.el (org-capture-fill-template): Enable `org-mode'
in the temporary template expansion buffer.  Update docstring
(org-capture-templates): Clarify that %(sexp) expansion happens in a
temporary Org mode buffer.

Fixes https://orgmode.org/list/CABUh-776V-_+_JAZwcKQm9ATcs0WUV9SmGwjooGFbt=CtwQj8g@mail.gmail.com
 lisp/org-capture.el | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 068e3eda2..9b17fa978 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -309,6 +309,8 @@ (defcustom org-capture-templates nil
               introduced with %[pathname] are expanded this way.
               Since this happens after expanding non-interactive
               %-escapes, those can be used to fill the expression.
+              The evaluation happens with Org mode set as major mode
+              in a temporary buffer.
   %<...>      The result of `format-time-string' on the ... format
   %t          Time stamp, date only.  The time stamp is the current
@@ -1572,7 +1574,9 @@ (defun org-capture-fill-template (&optional template initial annotation)
   "Fill a TEMPLATE and return the filled template as a string.
 The template may still contain \"%?\" for cursor positioning.
 INITIAL content and/or ANNOTATION may be specified, but will be overridden
-by their respective `org-store-link-plist' properties if present."
+by their respective `org-store-link-plist' properties if present.
+Expansion occurs in a temporary Org mode buffer."
   (let* ((template (or template (org-capture-get :template)))
 	 (buffer (org-capture-get :buffer))
 	 (file (buffer-file-name (or (buffer-base-buffer buffer) buffer)))
@@ -1645,6 +1649,7 @@ (defun org-capture-fill-template (&optional template initial annotation)
       (setq buffer-file-name nil)
       (setq mark-active nil)
       (insert template)
+      (org-mode)
       (goto-char (point-min))
       ;; %[] insert contents of a file.

  reply	other threads:[~2022-05-02  0:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-01 20:51 [BUG] folding error during capture Skip Collins
2022-05-02  0:17 ` Ihor Radchenko [this message]
2022-05-02  1:36   ` [PATCH] " Skip Collins
2022-05-02  2:05     ` Ihor Radchenko
2022-06-09  8:16   ` Ihor Radchenko

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:

  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=87mtg0vldb.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=skip.collins@gmail.com \


* 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


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).