help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Lexical vs. dynamic: small examples?


From: Drew Adams
Subject: Re: Lexical vs. dynamic: small examples?
Date: Sun, 9 Jan 2022 17:40:33 +0000

> >> FWIW, I just wrote a tiny library, `dyna-show.el', that
> >> defines minor mode `dyna-show-mode', which highlights
> >> occurrences of "special" (aka dynamically
> >> scoped) variables.
> >>
> >> It just uses `special-variable-p', which is limited.
> >>
> >> From the attachment, you can see another limitation:
> >> occurrences of a function, e.g. `font-lock-mode', that has
> >> the same name as a dynamic variable are also highlighted.
> >
> > Thanks, it is very helpful for cosmetics of the code.
> 
> But here it also has a functional value. Or to be even more
> precise, the functional value is also what is appealing, since
> I think it started in that end.

tl;dr:
1. It can be useful.  2. It's not foolproof.
___

I guess you're referring to this (from the
`dyna-show.el' Commentary)?

 [I]f a function has the same name as a dynamic
 variable, then its occurrences are also
 highlighted, as if they were occurrences of
 the variable.

For example `font-lock-mode' is a variable as
well as a function.  Both kinds of occurrences
of that symbol are highlighted the same.

Whether this is considered a feature or a
limitation, the reason is that it requires no
analysis of the code (which would anyway be
problematic and limited) to determine how each
occurrence is used.  

The Commentary calls it out as a limitation.
And the sentence above comes right after this
additional caveat:

 The simple built-in test `special-variable-p'
 is used.  That test is not 100% reliable.  It
 doesn't respect vacuous `defvar' sexps, which
 declare a variable to be special in a given
 context, without assigning a value to the
 variable.  Instead, it uses `defvar',`defconst',
 and `defcustom' sexps with a value arg present.

<<attachment: winmail.dat>>


reply via email to

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