Subject: Re: bug#58506: Use ".dir-locals.eld" and ".dir-locals-2.eld" when they exist

From: Lars Ingebrigtsen <[email-masked]>
Date: Sun, 16 Oct 2022 10:39:40 +0200

Philip Kaludercic <[email-masked]> writes:

> There is unsafep, but that is too strict for what we want.  E.g.
>
>   (unsafep '(setq tab-width 3)) ;; => (global-variable tab-width)
>
> even though we would want this to work.  I've attached an incomplete
> sketch of how this could look like

Cool; looks very promising.

>> We already mark functions as being side-effect-free, so it seems like
>> code like
>>
>> (if (cl-oddp (% (random) 2))
>>     (setq ...))
>>
>> would be "safe" together with the safep markup for assignments we
>> already have.  We could make a safe restricted language subset for use
>> both here and in similar circumstances.
>
> That is a good point, but I think more tagging should be done.  Ideally
> this would read as regular elisp (which is kind of ironic considering
> that we are discussing an .eld file),

Yes, so perhaps we should come up with a new extension for this "new
language", i.e., "safe Lisp".  Err...  ".dir-locals.els"?

> so it would be nice if
> mode-specific modifications could be done by just writing
>
> (when (derived-mode-p 'c-mode)
>   (setq tab-width 8))
>
> or something like that.

Yes, our side-effect-free tagging isn't very complete at present -- 
probably because it's not used that much (in a visible way).  I mean,
the byte compiler uses the data to warn, for instance.  But this would
give people an impetus to do further tagging.  It looks like
`derived-mode-p' is side-effect-free, for instance.

>>> No, what I had in mind was not to trigger warnings but either to
>>> highlight unused variables or provide a command that would check it for
>>> you.
>>
>> Oh, right.  That's another good idea.  😀
>
> One idea would be to use Flymake.

That's possible, but I think it should be possible to just use font
locking, too.