unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Andrey Samsonov <samsonov.box@gmail.com>,
	Eli Zaretskii <eliz@gnu.org>, Eshel Yaron <me@eshelyaron.com>,
	Stefan Kangas <stefankangas@gmail.com>,
	65475@debbugs.gnu.org
Subject: bug#65475: 29.1; package-selected-packages variable is not updated when the last package is deleted
Date: Wed, 13 Sep 2023 10:01:15 +0000	[thread overview]
Message-ID: <8734ziv1ck.fsf@posteo.net> (raw)
In-Reply-To: <jwvjzsx77ol.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sun, 10 Sep 2023 22:42:38 -0400")

[-- Attachment #1: Type: text/plain, Size: 550 bytes --]

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

>> +    (let ((package-alist                 ;see bug#65475
>>             (let ((pkgs (assq name package-alist)))
> [...]
>> +             (set-default-toplevel-value 'package-alist package-alist)
> [...]
>
> Eww!!
>
> If we really can't find a better option, we need to add a bunch of
> comments explaining why we ended up with such a hack.

It seems that it is only necessary to bind `package-alist' during the
invocation of `package--used-elsewhere-p', so this is a more
conservative proposal:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Handle-edge-case-when-deleting-the-last-package.patch --]
[-- Type: text/x-diff, Size: 2538 bytes --]

From a8959f1b245540a2d0d158621dedf244ac133849 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Wed, 13 Sep 2023 11:58:22 +0200
Subject: [PATCH] ; Handle edge-case when deleting the last package

* lisp/emacs-lisp/package.el (package-delete): Rebind 'package-alist'
while calling 'package--used-elsewhere-p'.  (bug#65475)
---
 lisp/emacs-lisp/package.el | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 3a019905960..02691ff7aa5 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2521,8 +2521,12 @@ package-delete
                                            nil t)))
        (list (cdr (assoc package-name package-table))
              current-prefix-arg nil))))
-  (let ((dir (package-desc-dir pkg-desc))
-        (name (package-desc-name pkg-desc))
+  (let* ((dir (package-desc-dir pkg-desc))
+         (name (package-desc-name pkg-desc))
+         (new-package-alist (let ((pkgs (assq name package-alist)))
+                              (if (null (remove pkg-desc (cdr pkgs)))
+                                  (remq pkgs package-alist)
+                                package-alist)))
         pkg-used-elsewhere-by)
     ;; If the user is trying to delete this package, they definitely
     ;; don't want it marked as selected, so we remove it from
@@ -2541,7 +2545,8 @@ package-delete
                   (package-desc-full-name pkg-desc)))
           ((and (null force)
                 (setq pkg-used-elsewhere-by
-                      (package--used-elsewhere-p pkg-desc)))
+                      (let ((package-alist new-package-alist))
+                        (package--used-elsewhere-p pkg-desc)))) ;See bug#65475
            ;; Don't delete packages used as dependency elsewhere.
            (error "Package `%s' is used by `%s' as dependency, not deleting"
                   (package-desc-full-name pkg-desc)
@@ -2562,10 +2567,7 @@ package-delete
                (when (file-exists-p file)
                  (delete-file file))))
            ;; Update package-alist.
-           (let ((pkgs (assq name package-alist)))
-             (delete pkg-desc pkgs)
-             (unless (cdr pkgs)
-               (setq package-alist (delq pkgs package-alist))))
+           (setq package-alist new-package-alist)
            (package--quickstart-maybe-refresh)
            (message "Package `%s' deleted."
                     (package-desc-full-name pkg-desc))))))
-- 
2.39.2


  reply	other threads:[~2023-09-13 10:01 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-23 12:02 bug#65475: 29.1; package-selected-packages variable is not updated when the last package is deleted Andrey Samsonov
2023-08-26  7:16 ` Eli Zaretskii
2023-08-26  7:30   ` Philip Kaludercic
2023-08-26 11:57     ` Stefan Kangas
2023-08-26 12:02       ` Philip Kaludercic
2023-08-26 12:07         ` Stefan Kangas
2023-09-02 16:28       ` Stefan Kangas
2023-09-04  3:24         ` Andrey Samsonov
2023-09-04  7:35           ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-05 17:10             ` Philip Kaludercic
2023-09-05 17:39               ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-05 22:03                 ` Stefan Kangas
2023-09-10 11:57                   ` Philip Kaludercic
2023-09-11  2:42                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-13 10:01                       ` Philip Kaludercic [this message]
2023-09-13 14:35                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-13 14:41                         ` Stefan Kangas
2023-09-14 13:09                           ` Philip Kaludercic
2023-09-14 14:27                             ` Stefan Kangas
2023-09-15  7:41                               ` Philip Kaludercic
2023-09-21 16:31                                 ` Philip Kaludercic

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=8734ziv1ck.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=65475@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=me@eshelyaron.com \
    --cc=monnier@iro.umontreal.ca \
    --cc=samsonov.box@gmail.com \
    --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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).