[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#65475: 29.1; package-selected-packages variable is not updated when
From: |
Philip Kaludercic |
Subject: |
bug#65475: 29.1; package-selected-packages variable is not updated when the last package is deleted |
Date: |
Sat, 26 Aug 2023 07:30:37 +0000 |
Eli Zaretskii <eliz@gnu.org> writes:
>> Date: Wed, 23 Aug 2023 18:02:14 +0600
>> From: Andrey Samsonov <samsonov.box@gmail.com>
>>
>> Steps to reproduce:
>>
>> 1. Start 'emacs -Q --init-directory <DIR>', where <DIR> is directory
>> with only zero-sized 'init.el' file
>> 2. M-x package-install RET mines RET
>> 3. M-x package-install RET chess RET
>> 4. C-h v package-selected-packages RET: Its value is (chess mines)
>> 5. M-x package-delete RET mines RET
>> 6. C-h v package-selected-packages RET: Its value is (chess)
>> 7. M-x package-delete RET chess RET
>>
>> Actual behavior:
>>
>> 8. C-h v package-selected-packages RET: Its value is (chess)
>>
>> Expected behavior:
>>
>> 8. C-h v package-selected-packages RET: Its value is nil
>
> Philip, Stefan: any comments?
The issue here is that `package--save-selected-packages' only updates
the value of `package-selected-packages', if the new value is non-nil,
presumably because the VALUE argument is optional, and it should be
possible to invoke the function without any new value, just wishing to
save the current one to disk (in fact this behaviour is required for the
`after-init-hook'-trick to work).
But if 'chess is removed from '(chess), the value is nil, hence nothing
happens.
One could imagine allowing a special value like 'empty to resolve the
issue:
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index e1172d69bf0..6d0ad274795 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -1982,8 +1982,11 @@ package--find-non-dependencies
(defun package--save-selected-packages (&optional value)
"Set and save `package-selected-packages' to VALUE."
- (when value
- (setq package-selected-packages value))
+ (cond
+ ((eq value 'empty)
+ (setq package-selected-packages nil))
+ ((not (null package-selected-packages))
+ (setq package-selected-packages value)))
(if after-init-time
(customize-save-variable 'package-selected-packages
package-selected-packages)
(add-hook 'after-init-hook #'package--save-selected-packages)))
@@ -2527,7 +2530,7 @@ package-delete
;; Don't deselect if this is an older version of an
;; upgraded package.
(package--newest-p pkg-desc))
- (package--save-selected-packages (remove name
package-selected-packages)))
+ (package--save-selected-packages (or (remove name
package-selected-packages) 'empty)))
(cond ((not (string-prefix-p (file-name-as-directory
(expand-file-name package-user-dir))
(expand-file-name dir)))
--
Philip Kaludercic