On 15/03/2022 02:43, Ignacio Casso wrote:
I've also investigated the issue a little bit further and wrote and
email with my conclusions about the same time Max wrote his. I comment
inline about a few of your thoughts:

For `defcustom' autoload generates no more than

     (defvar org-capture-templates nil "...")

It seems, behavior depends on whether `org-capture-templates' has the :set
attribute.

Not really, all defcustoms have a :set attribute, be it passed
explicitly as a parameter or the default value, set-default. This issue
happens with all autoload functions that use a custom variable: if they
are called inside a let form binding that variable and the feature was
not loaded yet, the let-binding will have no effect.

To avoid misunderstanding. I was testing with Emacs-26.3 (Ubuntu-20.04 focal LTS system package) and did not explicitly set lexical binding cookie in an .el file. However defcustom autoloading was assumed.

;; simulate effect of ;;;###autoload
(defvar org-capture-templates nil)

(defun print-org-capture-templates ()
  (message "print-org-capture-templates")
  (pp org-capture-templates)
  (message "-----"))
(let ((org-capture-templates
       '(("d" "default" entry
          (file "/tmp/capture-test.org")
          "* %?"))))
  (print-org-capture-templates)
  (require 'org-capture)
  (print-org-capture-templates))

Second call of print-org-capture templates prints nil with original definition of `org-capture-templates' but it prints locally let-bound value if I comment out the :set attribute.

I am not disputing any observation from your thorough study
mid:paxpr06mb7760a3031924ba897fd082e4c6...@paxpr06mb7760.eurprd06.prod.outlook.com
(it seems message delivery took several hours, so I noticed it after I sent my message).

Maybe it is reasonable to expect that let-binding should work with autoloading. I believe that loading of a file should be performed inside top-level scope, so it should ignore let-bound values. It is fragile when let-binding may affect global value of defcustom. However following call of just loaded function should be performed with regular stack of dynamic scopes. I am unsure if such behavior is feasible with elisp implementation.


Reply via email to