all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: Gnus using lexical-binding
Date: Sat, 30 Jan 2021 10:24:05 -0500	[thread overview]
Message-ID: <jwvbld6qxye.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CADwFkmk-VGiF1Ess_NSL3DBRJiVqr3mNzOSfrS9dtY6LAOHPSg@mail.gmail.com> (Stefan Kangas's message of "Sat, 30 Jan 2021 05:43:13 -0800")

>> Btw, I think we could benefit from a detailed guide for how to convert
>> a package to lexical-binding, enumerating the steps to take, tools and
>> Emacs commands to use, possible problems and how to solve them, etc.
>> Somewhere in admin/notes/, perhaps?
>
> What about `(elisp) Converting to Lexical Binding'?
>
> Should we perhaps just expand that?  I'm sure third-party package
> developers could also benefit from any details we would like to add.

In terms of tools and commands, this section indeed describes what
I use.

I'm not sure how much further we want to go with that.
The main other tool I use is my intuition and various heuristics:

For the "unused var" warning, I can usually guess based on the name
whether it should have a `defvar` or not: variables whose name has
a "package prefix" should almost always have a `defvar` while those who
have a short name should almost always use lexical scoping.
Adding more `defvar`s than needed is largely harmless during conversion
(it's arguably harmful in the long run, but that can be addresses
later), so the main risk is for those variables with a non-prefixed name
where we normally presume they can use lexical scoping but which may
nevertheless require dynamic scoping.  Furthermore, some of those cases
can occur without triggering any warning from the byte-compiler because
the var is not locally unused.

This can happen typically with code like

    (let ((foo X)
          (bar Y))
      ...
      (eval config-var)
      ...)

where `config-var` is defined to hold an ELisp form which has access to
variables `foo` and `bar`.  If you're the package author or are a heavy
user of the package there's a chance you know about it and can take it into
account when performing the conversion, but otherwise it can be tricky
to figure it out.

The only way I know is to search for uses of `eval`, `symbol-value`,
`intern`, and `set` (this list is sadly not exhaustive, e.g. some uses
may occur via `run-hooks`) to try and find code that relies on access to
variables via dynamic scoping and then examine each one to try and see
which variables it may refer to, which is sometimes documented in
comments or docstrings.

This last part is tedious and rarely necessary, so I do it lazily,
i.e. when something indicates that it's probably necessary (e.g. because
of a regression found during testing, or because of some odd patterns in
the "unused variables" warnings, e.g. when the same set of unused
variable names appear a few times, tho sometimes these patterns are due
to copy&paste as well).


        Stefan




  parent reply	other threads:[~2021-01-30 15:24 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-29 23:11 Gnus using lexical-binding Stefan Monnier
2021-01-30  6:34 ` Lars Ingebrigtsen
2021-01-30  8:35 ` Eli Zaretskii
2021-01-30 13:43   ` Stefan Kangas
2021-01-30 13:52     ` Eli Zaretskii
2021-01-30 14:08       ` Eli Zaretskii
2021-01-30 15:24     ` Stefan Monnier [this message]
2021-01-30 15:07 ` Basil L. Contovounesios
2021-01-30 17:40   ` Stefan Monnier
2021-02-08 19:10     ` Ted Zlatanov
2021-02-09  0:10       ` Stefan Monnier
2021-02-10 10:24         ` Ted Zlatanov
2021-02-10 13:53           ` Stefan Monnier
2021-02-10 19:05           ` Lars Ingebrigtsen
2021-01-30 16:10 ` Andy Moreton
2021-01-30 17:35   ` Stefan Monnier
2021-01-30 18:00     ` Andy Moreton
2021-01-30 18:53       ` Stefan Monnier
2021-01-30 23:23         ` Andy Moreton
2021-01-31  0:06           ` Stefan Monnier
2021-01-31  0:46             ` Andy Moreton
2021-01-31 13:34             ` Basil L. Contovounesios
2021-02-02 18:17             ` Eric Abrahamsen
2021-02-02 19:40               ` Stefan Monnier
2021-02-02 20:31                 ` Eric Abrahamsen
2021-01-31  9:13 ` David Engster
2021-01-31 22:43   ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvbld6qxye.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=stefankangas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.