emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [BUG] org-capture autoload bug? [9.5.2 (9.5.2-gfbff08 @ /home/ignaci


From: Max Nikulin
Subject: Re: [BUG] org-capture autoload bug? [9.5.2 (9.5.2-gfbff08 @ /home/ignacio/.emacs.d/elpa/org-9.5.2/)]
Date: Fri, 11 Mar 2022 17:07:03 +0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0

On 11/03/2022 01:00, Ignacio Casso wrote:
Max Nikulin writes:

On 10/03/2022 19:53, Ignacio Casso wrote:
For example, if we call this:
    (let ((org-capture-templates
           '(("d" "default" entry
              (file+headline org-default-notes-file "Tasks")
              "* %?"))))
      (org-capture nil "d")))
It produces the error:
    (error "No capture template referred to by \"d\" keys")

Ignacio, could you, please, try the following?

     (custom-set-variables
      '(org-capture-templates
        '(("d" "default" entry
           (file "/tmp/capture-test.org")
           "* %?"))))
     (org-capture nil "d")


That works, of course, but it's not suitable to my use case. The example
I have provided has been reduced from a larger function I wrote that
relies on org-capture functionality to create new entries in an org
file, using a template specific for that function which is not relevant
for any other Elisp code calling org-capture. Thus the function binds
locally and temporarily org-capture-templates, as I've seen other Elisp
code snippets do. If org-capture is already loaded it works just fine,
and I would expect it to work too when it is not and the function
triggers the autoload, but it doesn't.

Ignacio, I think, you can add (require 'org-capture) inside your function just before `let' and it would work almost as lazy loading. I am unsure if org-capture is the best approach in your case. Have you considered yasnippet or Org specific functions to transform and to generate content? Even changing arguments of the `org-capture' function or introducing another function that has explicit argument with a template might be better then marking the template list variable for autoloading.

I have no particular opinion concerning adding autoload cookie to `org-capture-templates'. Emacs has enough number of them, but Org has no such custom variables. Arguments why autoload should be avoided:

info "(elisp) When to Autoload" https://www.gnu.org/software/emacs/manual/html_node/elisp/When-to-Autoload.html
Don’t autoload a user option just so that a user can set it.

The following thread related to Emacs core and linked from https://emacs.stackexchange.com/questions/32859/autoloading-defcustoms-good-practice-or-not :

Glenn Morris. Re: master f995fbd: * lisp/server.el (server-name): Add autoload cookie. (Bug#23576) Thu, 19 May 2016 12:44:49 -0400
https://lists.gnu.org/archive/html/emacs-devel/2016-05/msg00415.html

Org-specific thread:
Achim Gratz. missing autoload cookies for defcustom? Sun, 09 Oct 2011 17:20:16 +0200 https://list.orgmode.org/87lisub39r.fsf@Rainer.invalid/T/#u

c.buhtz, I am sorry, despite `org-capture-templates' has the :set attribute, this is not a really convincing example why `custom-set-variables' should be used. The setter was added to ensure compatibility with older template format and this example works with `setq' as well.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]