all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Defvar not called at top level
@ 2021-11-23 13:28 Arthur Miller
  2021-11-23 13:58 ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Arthur Miller @ 2021-11-23 13:28 UTC (permalink / raw)
  To: emacs-devel


Just a question: why is it important to call defvar from top level?

I would like to have some code that generates some other code, amongs that to
declare few global symbols with auto generated docs as well.

If I call those from a defun/macro normally I get that warning that defvar is
not called at top level; so I guess it is for some reason a bad practice? So if
I generate some code that will be called at some later time that uses defvar I
guess it would be equally bad practice.

I just wonder, why is it demanded to call defvar as top level form?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Defvar not called at top level
  2021-11-23 13:28 Defvar not called at top level Arthur Miller
@ 2021-11-23 13:58 ` Stefan Monnier
  2021-11-24 10:47   ` Arthur Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2021-11-23 13:58 UTC (permalink / raw)
  To: Arthur Miller; +Cc: emacs-devel

Arthur Miller [2021-11-23 14:28:04] wrote:
> Just a question: why is it important to call defvar from top level?
> I would like to have some code that generates some other code, amongs that to
> declare few global symbols with auto generated docs as well.

Presumably you can do this with

    (defmacro FOO (..) ... `(defvar ...) ...)

    (FOO ...)

> If I call those from a defun/macro normally I get that warning that defvar is
> not called at top level;

Can you show the actual warning?


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Defvar not called at top level
  2021-11-23 13:58 ` Stefan Monnier
@ 2021-11-24 10:47   ` Arthur Miller
  2021-11-24 13:38     ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Arthur Miller @ 2021-11-24 10:47 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Arthur Miller [2021-11-23 14:28:04] wrote:
>> Just a question: why is it important to call defvar from top level?
>> I would like to have some code that generates some other code, amongs that to
>> declare few global symbols with auto generated docs as well.
>
> Presumably you can do this with
>
>     (defmacro FOO (..) ... `(defvar ...) ...)
>
>     (FOO ...)
>
>> If I call those from a defun/macro normally I get that warning that defvar is
>> not called at top level;
>
> Can you show the actual warning?


Thank you for the answer; it seems like I can't :).

I am sorry, I had too many things in my head and confused things. It was not
"defvar" it was "defvar-local". I appologize.

This one:

(defun byte-compile-make-variable-buffer-local (form)
  (if (and (eq (car-safe (car-safe (cdr-safe form))) 'quote)
           (byte-compile-warning-enabled-p 'make-local))
      (byte-compile-warn
       "`make-variable-buffer-local' not called at toplevel"))
  (byte-compile-normal-call form))

I copy-pasted a bunch of defvar-local statements somewhere into a
defun to save some typing; and I got that warning, so I have put them back. By
the way after second thought I think I understand why it could be bad thing, but
I am not sure: if a form would be evaluated in a non-buffer context?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Defvar not called at top level
  2021-11-24 10:47   ` Arthur Miller
@ 2021-11-24 13:38     ` Stefan Monnier
  2021-11-25  3:04       ` Arthur Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2021-11-24 13:38 UTC (permalink / raw)
  To: Arthur Miller; +Cc: emacs-devel

Arthur Miller [2021-11-24 11:47:16] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Arthur Miller [2021-11-23 14:28:04] wrote:
>>> Just a question: why is it important to call defvar from top level?
>>> I would like to have some code that generates some other code, amongs that to
>>> declare few global symbols with auto generated docs as well.
>>
>> Presumably you can do this with
>>
>>     (defmacro FOO (..) ... `(defvar ...) ...)
>>
>>     (FOO ...)
>>
>>> If I call those from a defun/macro normally I get that warning that defvar is
>>> not called at top level;
>>
>> Can you show the actual warning?
>
>
> Thank you for the answer; it seems like I can't :).
>
> I am sorry, I had too many things in my head and confused things. It was not
> "defvar" it was "defvar-local". I appologize.

So the warning was not about `defvar` but about `make-variable-buffer-local`.
The reason for this warning is to catch the widespread confusion between
`make-variable-buffer-local` and `make-local-variable`.


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Defvar not called at top level
  2021-11-24 13:38     ` Stefan Monnier
@ 2021-11-25  3:04       ` Arthur Miller
  0 siblings, 0 replies; 5+ messages in thread
From: Arthur Miller @ 2021-11-25  3:04 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Arthur Miller [2021-11-24 11:47:16] wrote:
>> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> Arthur Miller [2021-11-23 14:28:04] wrote:
>>>> Just a question: why is it important to call defvar from top level?
>>>> I would like to have some code that generates some other code, amongs that to
>>>> declare few global symbols with auto generated docs as well.
>>>
>>> Presumably you can do this with
>>>
>>>     (defmacro FOO (..) ... `(defvar ...) ...)
>>>
>>>     (FOO ...)
>>>
>>>> If I call those from a defun/macro normally I get that warning that defvar is
>>>> not called at top level;
>>>
>>> Can you show the actual warning?
>>
>>
>> Thank you for the answer; it seems like I can't :).
>>
>> I am sorry, I had too many things in my head and confused things. It was not
>> "defvar" it was "defvar-local". I appologize.
>
> So the warning was not about `defvar` but about `make-variable-buffer-local`.

Yes. Caused by defvar-locals I pasted in.

> The reason for this warning is to catch the widespread confusion between
> `make-variable-buffer-local` and `make-local-variable`.

Aha. I thought it was more like it's easy to create a binding in wrong buffer.

Anyway, thanks.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-11-25  3:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-23 13:28 Defvar not called at top level Arthur Miller
2021-11-23 13:58 ` Stefan Monnier
2021-11-24 10:47   ` Arthur Miller
2021-11-24 13:38     ` Stefan Monnier
2021-11-25  3:04       ` Arthur Miller

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.