From debbugs-submit-bounces@debbugs.gnu.org Sun Feb 13 06:20:58 2022 Received: (at submit) by debbugs.gnu.org; 13 Feb 2022 11:20:58 +0000 Received: from localhost ([127.0.0.1]:36692 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nJCw6-0005Ai-HU for submit@debbugs.gnu.org; Sun, 13 Feb 2022 06:20:58 -0500 Received: from lists.gnu.org ([209.51.188.17]:60728) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nJCw4-0005AZ-G7 for submit@debbugs.gnu.org; Sun, 13 Feb 2022 06:20:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJCw4-0007OA-BU for bug-gnu-emacs@gnu.org; Sun, 13 Feb 2022 06:20:56 -0500 Received: from [2a00:1450:4864:20::632] (port=45907 helo=mail-ej1-x632.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nJCw2-0004oq-Nh for bug-gnu-emacs@gnu.org; Sun, 13 Feb 2022 06:20:55 -0500 Received: by mail-ej1-x632.google.com with SMTP id lw4so1043329ejb.12 for ; Sun, 13 Feb 2022 03:20:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:user-agent:mime-version; bh=JwyyEUhE0ksCkMwNlFaMb/ew+Ao7uiWjwSwfoml/aRw=; b=Vtzjs7jdiQWhWvfaYhwiqriReb2vLp4fFOEr5ahUz/wOVqKum6Pma8SaRblkhyB++x qcMy0tkUi7/G470WInxv1ARpH3Nfguf8uEjP/NigQmQ8kCtYD7YreRNbIyTo6U+D3i46 HjHGpQv2y1UzeDDW1KYEp2VidVxvLVPA0JHBoPtPLhUTIS74mOJrNef4NnRLcbFzveON SQOjNn7QaeV9XISDiGn0x8jvEPIWw2ek2iASt0l37iYZJbrBEdqo10hust68eoD3nMhn Uho0eH8JwFwSLX2k35inMiV5MQppDSgTX6Hudy3FYJZLudirIXbauXoJVcqptMHJclHr JWnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version; bh=JwyyEUhE0ksCkMwNlFaMb/ew+Ao7uiWjwSwfoml/aRw=; b=WousP14jNkfJneasT8EKAdoSV79qUIXwkwBmzkasqHTW/6xjyVS3zUMRmcapcquaEY 4D5Pc81Mv9aTIFF9sKerljBXnPXd2NDA3rlHTTLNqtzLKDvL5NuNmcJ9o2PajJWNi48t 7uA9xLw33HJcylqeYsNB1gYcBj41jG9D7joH4WUdDQz0sdxWxZZIQI9oSrE8mQ6RK0Mh 7etbZrVXQzw7P5FX1O8FZ82O3udKxNrNusMd+cP8ytbt7eCIlmsWf3qjUqcQbxoSL1aH BERHGRVHw7GdN2ptuEEVMSd+sgaLeEfM8LXaogGBE2+Z+6ublXl9wL7xwbX7nP5iQC3P O/ow== X-Gm-Message-State: AOAM530LQB46Sl79EexDYvffY+tqJV0V/igCEL1VRuPRUMIJwP2Lerb9 vy/IVSsAa4egjhqTwJ+hOBjuYwLPWZ0= X-Google-Smtp-Source: ABdhPJxTOaupt8fbiZo6GHhHjNgyoHtiHfKtk9u47LO39SmxqQa755N50Sq9Vt54TDboTThGrAy9og== X-Received: by 2002:a17:906:64ca:: with SMTP id p10mr4050278ejn.366.1644751252303; Sun, 13 Feb 2022 03:20:52 -0800 (PST) Received: from ars3 ([2a02:8109:8ac0:56d0::758e]) by smtp.gmail.com with ESMTPSA id dc8sm7044216ejb.213.2022.02.13.03.20.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 03:20:51 -0800 (PST) From: Augusto Stoffel To: bug-gnu-emacs@gnu.org Subject: 28.0.91; Issue when calling 'package-install' during init Date: Sun, 13 Feb 2022 12:20:48 +0100 Message-ID: <87ee47108f.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.91 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::632 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=arstoffel@gmail.com; helo=mail-ej1-x632.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) In the recent bug#53885, it was mentioned that the user may have good reasons to call ``` (unless (package-installed-p 'some-package) (package-install 'some-package)) ``` in their init file. This works but has one glitch: when 'package-install' is called during init time, 'package-selected-packages' is not updated accordingly (unless it didn't have a saved custom value yet). As an example, consider the following .emacs file: ``` (package-install 'eglot) (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(package-selected-packages '(corfu devdocs))) ``` After starting Emacs, Eglot is installed but 'package-selected-packages' still has value '(corfu devdocs)'. The least intrusive solution to this issue, in terms of number of changed lines to packages.el, would be to add a :set parameter to 'package-selected-packages'. Namely, something equivalent to the following: ``` (require 'package) (put 'package-selected-packages 'custom-set (lambda (_ val) (setq-default package-selected-packages (append (unless after-init-time (seq-difference package-selected-packages val)) val)))) (package-install 'eglot) (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(package-selected-packages '(corfu devdocs))) ``` After starting a fresh Emacs with this as init file, one gets the expected value for 'package-selected-packages', namely '(eglot corfu devdocs)'. Does that approach look reasonable? Then I can prepare a patch. By the way: I think the following function should be included in package.el, to allow writing an init file that automatically bootstraps Emacs to a usable state when copied to a new machine. ``` (defun package-ensure-installed (&rest packages) "Make sure PACKAGES are installed." (dolist (pkg packages) (unless (package-installed-p pkg) ;; Possibly call `package-refresh-contents' here (package-install pkg)))) ```