emacs-devel
[Top][All Lists]
Advanced

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

Re: Adding use-package to ELPA


From: Philip Kaludercic
Subject: Re: Adding use-package to ELPA
Date: Mon, 07 Mar 2022 19:24:39 +0000

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

>> I'll just throw in a request of mine: make it so `flymake-mode` gets
>> usable feedback when used in an init file.
>
> To make it more concrete.
> Currently if your init file contains just:
>
>     ;;; -*- lexical-binding: t -*-
>     (setq smtpmail-smtp-service 587)
>
> and you enable `flymake-mode`, it will complain:
>
>     assignment to free variable ‘smtpmail-smtp-service’
>
> There's no much we can do about it in general.
> With Setup/Leaf/use-package, OTOH, the user would presumably write
> something like:
>
>     ;;; -*- lexical-binding: t -*-
>     (setup smtpmail
>       (setq smtpmail-smtp-service 587))

> which does provide the link between `smtpmail-smtp-service` and the
> `smtpmail.el` file necessary for Emacs to be able in theory to discover
> that `smtpmail-smtp-service` is not just some unknown free variable.
>
> Currently, the above snippet using Setup still gives the same
> warning, tho.

True, because the above examples just expands to

      (setq smtpmail-smtp-service 587)

I'd usually recommend to use a local macro to avoid these issues,
because something like

      (setup smtpmail
        (:option smtpmail-smtp-service 587))

would expand to a `customize-set-variable'-like code, where
`smtpmail-smtp-service' would appear as a quoted symbol.

> So `setup.el` could maybe do something like:
>
>     (defmacro setup (pkg &rest args)
>       (when (we-are-byte-compiling-p)
>         (require (byte-run-strip-symbol-positions pkg)))
>       ...)

What is the point of using byte-run-strip-symbol-positions here?  I just
tried something like this, but it doesn't seem to work.

> so as to silence the warning.
>
>
>         Stefan
>

"John Wiegley" <johnw@gnu.org> writes:

>>>>>> "SM" == Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>>> I'll just throw in a request of mine: make it so `flymake-mode` gets usable
>>> feedback when used in an init file.
>
> SM> To make it more concrete.
> SM> Currently if your init file contains just:
>
> SM>     ;;; -*- lexical-binding: t -*-
> SM>     (setq smtpmail-smtp-service 587)
>
> SM> and you enable `flymake-mode`, it will complain:
>
> SM>     assignment to free variable ‘smtpmail-smtp-service’
>
> Ah, I understand what you mean now.
>
> In use-package, this is exactly what the `:defines` keyword was created for,
> so that you can indicate to the byte-compiler which variables will be defined
> when the module is loaded.

I guess the issue here is that you would have to mention every variable
twice, declaring it with :defines before using it, while it could
actually be inferred, as Stefan points out.

> This special handling is done in `use-package-normalize-keywords`, so one
> could advise that function to intercept the list yielded by :defines and do
> what's necessary to satisfy flymake. That is, if :defines itself isn't already
> enough.

AFAIK flymake just reports the issues generated by the byte-compiler, so
if that is fixed, flymake shouldn't complain either.

-- 
        Philip Kaludercic



reply via email to

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