Subject: Re: bug#2061: 23.0.60; Add preference to force load of Elisp files when they are newer than corresponding byte-compiled file

From: Brent Goodrick <[email-masked]>
Date: Mon, 2 Feb 2009 08:07:02 -0800

I won't pursue this any further.  You all have given me some useful
workarounds that I will explore further.

Thanks
Brent

On 1/27/09, Juanma Barranquero <[email-masked]> wrote:
> On Tue, Jan 27, 2009 at 16:54, Brent Goodrick <[email-masked]> wrote:
>
>> The problem relates to when and how to notify the user that the stale
>> .elc file is the one being loaded.  During development, I just
>> `eval-buffer' repeatedly on a .el file, always unaware that there is a
>> stale .elc file lying in wait to confuse me the next time I reload the
>> entire Emacs process/session.
>
> If you're going to modify/test the package with eval-buffer, you
> should make sure there's no .elc sitting around.
>
>> At init time, I only get a warning,
>> among a ton of other benign warnings and messages, and that one
>> critical warning is therefore not seen (of course, it is impractical
>> to ask the user to read all of those messages).
>
> As you know, that's trivially fixed:
>
> (add-hook 'emacs-startup-hook
>           (lambda ()
>             (with-current-buffer (get-buffer "*Messages*")
>               (goto-char (point-min))
>               (while (re-search-forward "[Ss]ource file .*? newer" nil t)
>                 (warn "%s" (buffer-substring (line-beginning-position)
>                                              (line-end-position)))))))
>
>
>> Add the following logic to the C `load' function:
>>
>>  Before loading either the .el or .elc file, test for the condition
>>  where the .el file is newer than the .elc file. If it is, then do
>>  the following:
>>
>>    See if the `load-hook-stale-byte-compile-handlers' hook variable
>>    is set to non-nil. When it is non-nil, run the hook variable with
>>    `run-hook-with-args-until-success'. Each function the user has
>>    added to that hook variable would do any logic s/he wishes,
>>    including in my case to popup a minibuffer prompt asking what to
>>    do. When the hook function thus called returns a 'prefer-el-file
>>    symbol, `load' then loads the .el file and ignores the .elc
>>    file. Likewise, when the hook function returns the
>>    'prefer-elc-file symbol, then load the .elc file but give no
>>    warning message and ignore the .el file. When nil is returned from
>>    the `run-hook-with-args-until-success' function, just load the
>>    .elc file and produce the stale file warning message as is done
>>    today (i.e., preserve existing behavior).
>
> That would work, but it is IMHO too much (interface, not code)
> complexity for little gain. In most cases, having a .elc older than
> its corresponding .el is a bug (or, let's call it, a temporary
> situation), so getting a warning to remind the user about fixing it
> seems much more economical.
>
> That said, sometimes I would've liked to have a hook that runs when a
> file is loaded; or the ability to defadvice Fload (you can, except
> that Fload is also called from C code, for example for autoloads).
>
>> I have tried doing that, but found it unworkable in practice, as
>> byte-compiling upon each save ended up chewing up too much time during
>> development (the byte-compile-upon-every-save penalty). Consider that
>> I save frequently. :)
>
> I didn't mean to byte-compile on saving, I meant to byte-compile on
> eval-buffer (or whatever method you use to test your code).
>
>> But that is a hack, so I am now trying to get the root problem
>> addressed in the C code where it exists.
>
> I agree that greater control over the loading process could sometimes
> be useful; but I don't think this is a compelling use case.
>
>     Juanma
>