Subject: Re: bug#45098: 28.0.50; gnu-elpa: if user says `no' to install package, it aborts the previous function invoked

From: Stefan Monnier <[email-masked]>
Date: Mon, 07 Dec 2020 15:33:07 -0500

>> I am using M-x sql-postgres and when invoked with gnu-elpa package
>> installed it asks me to install sql-indent, but I say no and on saying
>> no it aborts my action and I cannot even reach to sql-postgres
>> mode. To reach it I have to invoke M-x sql-postgres second time
>
> I can confirm this problem.  I had a peek at gnu-elpa, but decoding the
> control flow was beyond what I could do in 30 seconds.  Stefan?

I think there are 2 problems:

1 - when the user says "no" to installing `sql-indent`, `gnu-elpa`
    doesn't try to remember this fact, so it will happily ask the user
    again and again.

2 - when the user says "no" to installing `sql-indent`, `gnu-elpa`
    doesn't "keep going" but instead it "aborts" (i.e. by signaling an
    error).

Problem (1) should be reasonably easy to fix by removing the
corresponding autoload and storing the list of unwanted packages
somewhere for future Emacs sessions (and also changing the question from
"yes/no" to "yes/notnow/never").

Problem (2) is largely unsolvable on `gnu-elpa`s side.
Basically, the code in `sql-indent-enable` in sql.el does:

    (when (fboundp 'sqlind-minor-mode)
      (sqlind-minor-mode (if sql-use-indent-support +1 -1)))

With `gnu-elpa` installed, `sqlind-minor-mode` is defined (as an
autoloaded function), so we call it which in turns loads `gnu-elpa.el`,
but from there we can't "uncall" the function.  We could signal
a different error than "Abort", and then change the call so it just
ignores such errors, or we could have a special hack in `gnu-elpa` for
`sqlind-minor-mode` such that when the user decides not to
install the package we install a dummy version of the function which
does nothing (and then undefines the function), but I'm not sure it's
worth the trouble.

        Stefan