* Byte compiling and semi-free variables
@ 2008-12-28 15:39 Lennart Borgman
2008-12-28 15:48 ` Juanma Barranquero
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Lennart Borgman @ 2008-12-28 15:39 UTC (permalink / raw)
To: Emacs Devel
If you order definitions top-down in your elisp source files, like this
;;;; Interactive defuns:
(defun my-fun ()
(interactive)
(setq my-internal-var 1) )
;;;; Internal variables
(defvar my-internal-var nil)
and byte-compile the files you get warnings like
my-lib.el:118:14:Warning: reference to free variable `my-internal-var'
Is there any way to avoid that warning?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Byte compiling and semi-free variables
2008-12-28 15:39 Byte compiling and semi-free variables Lennart Borgman
@ 2008-12-28 15:48 ` Juanma Barranquero
2008-12-28 15:50 ` Lennart Borgman
2008-12-28 17:26 ` Stephen J. Turnbull
2008-12-28 22:21 ` Miles Bader
2 siblings, 1 reply; 6+ messages in thread
From: Juanma Barranquero @ 2008-12-28 15:48 UTC (permalink / raw)
To: Lennart Borgman; +Cc: Emacs Devel
On Sun, Dec 28, 2008 at 16:39, Lennart Borgman
<lennart.borgman@gmail.com> wrote:
> Is there any way to avoid that warning?
You could use `with-no-warnings' (which is ugly):
(defun my-fun ()
(interactive)
(with-no-warnings
(setq my-internal-var 1)))
or add a local variable:
;;; Local Variables:
;;; byte-compile-warnings: (not free-vars)
;;; End:
which is uglier and affects every non-declared variable in the file.
Or you could just not order the definitions top-down.
Juanma
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Byte compiling and semi-free variables
2008-12-28 15:48 ` Juanma Barranquero
@ 2008-12-28 15:50 ` Lennart Borgman
0 siblings, 0 replies; 6+ messages in thread
From: Lennart Borgman @ 2008-12-28 15:50 UTC (permalink / raw)
To: Juanma Barranquero; +Cc: Emacs Devel
On Sun, Dec 28, 2008 at 4:48 PM, Juanma Barranquero <lekktu@gmail.com> wrote:
> On Sun, Dec 28, 2008 at 16:39, Lennart Borgman
> <lennart.borgman@gmail.com> wrote:
>
>> Is there any way to avoid that warning?
>
> You could use `with-no-warnings' (which is ugly):
>
> (defun my-fun ()
> (interactive)
> (with-no-warnings
> (setq my-internal-var 1)))
>
> or add a local variable:
>
> ;;; Local Variables:
> ;;; byte-compile-warnings: (not free-vars)
> ;;; End:
>
> which is uglier and affects every non-declared variable in the file.
>
> Or you could just not order the definitions top-down.
Which is also rather ugly ... ;-)
Thanks.
> Juanma
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Byte compiling and semi-free variables
2008-12-28 15:39 Byte compiling and semi-free variables Lennart Borgman
2008-12-28 15:48 ` Juanma Barranquero
@ 2008-12-28 17:26 ` Stephen J. Turnbull
2008-12-28 22:21 ` Miles Bader
2 siblings, 0 replies; 6+ messages in thread
From: Stephen J. Turnbull @ 2008-12-28 17:26 UTC (permalink / raw)
To: Lennart Borgman; +Cc: Emacs Devel
Lennart Borgman writes:
> If you order definitions top-down in your elisp source files, like this
>
> ;;;; Interactive defuns:
>
> (defun my-fun ()
> (interactive)
> (setq my-internal-var 1) )
>
> ;;;; Internal variables
> (defvar my-internal-var nil)
But that's not top-down. `my-internal-variable' is global, ie, it has
the same scope as `my-fun'.
If `my-internal-variable' is not intended to be global, ie, it is only
accessed in `my-fun', then you could try
(defun my-fun ()
(interactive)
;; The elisp static local wannabe idiom
(eval-when-compile (defvar my-internal-var))
(setq my-internal-var 1))
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Byte compiling and semi-free variables
2008-12-28 15:39 Byte compiling and semi-free variables Lennart Borgman
2008-12-28 15:48 ` Juanma Barranquero
2008-12-28 17:26 ` Stephen J. Turnbull
@ 2008-12-28 22:21 ` Miles Bader
2008-12-28 23:19 ` Lennart Borgman
2 siblings, 1 reply; 6+ messages in thread
From: Miles Bader @ 2008-12-28 22:21 UTC (permalink / raw)
To: Lennart Borgman; +Cc: Emacs Devel
"Lennart Borgman" <lennart.borgman@gmail.com> writes:
> my-lib.el:118:14:Warning: reference to free variable `my-internal-var'
>
> Is there any way to avoid that warning?
Don't order your source files that way. Instead, order them the usual
way, with declaration preceding use.
-Miles
--
Corporation, n. An ingenious device for obtaining individual profit without
individual responsibility.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Byte compiling and semi-free variables
2008-12-28 22:21 ` Miles Bader
@ 2008-12-28 23:19 ` Lennart Borgman
0 siblings, 0 replies; 6+ messages in thread
From: Lennart Borgman @ 2008-12-28 23:19 UTC (permalink / raw)
To: Miles Bader; +Cc: Emacs Devel
On Sun, Dec 28, 2008 at 11:21 PM, Miles Bader <miles@gnu.org> wrote:
> "Lennart Borgman" <lennart.borgman@gmail.com> writes:
>> my-lib.el:118:14:Warning: reference to free variable `my-internal-var'
>>
>> Is there any way to avoid that warning?
>
> Don't order your source files that way. Instead, order them the usual
> way, with declaration preceding use.
Ok, thanks all for the suggestions. I give up ... ;-)
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-12-28 23:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-28 15:39 Byte compiling and semi-free variables Lennart Borgman
2008-12-28 15:48 ` Juanma Barranquero
2008-12-28 15:50 ` Lennart Borgman
2008-12-28 17:26 ` Stephen J. Turnbull
2008-12-28 22:21 ` Miles Bader
2008-12-28 23:19 ` Lennart Borgman
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.