From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.devel Subject: Proposal for 'package-isolate' command Date: Tue, 15 Aug 2023 19:52:32 +0000 Message-ID: <87r0o4jd6n.fsf_-_@posteo.net> References: <87r0oftgye.fsf@posteo.net> <87350vt1wz.fsf@posteo.net> <871qgen1ln.fsf@posteo.net> <87edke4mou.fsf@posteo.net> <87wmy6kuan.fsf@posteo.net> <87wmy6w070.fsf@posteo.net> <87zg2sjleg.fsf@posteo.net> <83y1ic8790.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27496"; mail-complaints-to="usenet@ciao.gmane.io" Cc: thievol@posteo.net, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Aug 15 21:53:31 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qW06d-0006ts-7H for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Aug 2023 21:53:31 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qW05v-0003yT-FN; Tue, 15 Aug 2023 15:52:47 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qW05s-0003y6-Tx for emacs-devel@gnu.org; Tue, 15 Aug 2023 15:52:44 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qW05p-0000DC-Qu for emacs-devel@gnu.org; Tue, 15 Aug 2023 15:52:44 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id B760D240101 for ; Tue, 15 Aug 2023 21:52:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1692129159; bh=jv4BOTWiSKaPk7/mATQbmcKIonYYdXfnHJ3gVIqINiM=; h=From:To:Cc:Subject:Autocrypt:Date:Message-ID:MIME-Version:From; b=qmJP8qKpkQyF56qeS55l98QOSwn5KaKlsomG2YyN722ohchTshIBR0S6xp8ihie1Z Ejw0iwNXGI8FocC4ly6U9QjxRpWKauUIpsGdfzHK3JlirWlTkqQHhC+rplBaJkiWhS 3qwzyDToz9lF9yb/8bTWyinYW3E/4CLMNjh8LwHaPb+ebzYqNfirryLyKzhEmZfAU5 BxpcF0BC7bz23GnZL1c2GewRuaDOMvr7sVv6NTl2Z1OpZSMCw5Mfop+rt0nePVIFcA SqMKRhtU8vJQ9TBhU2tu6YR2gQupnr67ba8zeAvPXNQL7f8TTvmULXoGap5kjuhgm0 lq2A50RC4BwlQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RQMPK1cFqz6tw9; Tue, 15 Aug 2023 21:52:36 +0200 (CEST) In-Reply-To: <83y1ic8790.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 15 Aug 2023 21:56:11 +0300") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:308773 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Philip Kaludercic >> Cc: emacs-devel@gnu.org >> Date: Tue, 15 Aug 2023 16:55:03 +0000 >> >> +*** New command to start Emacs only with specific packages >> +The command 'package-isolate' is equivalent to starting Emacs with the >> +-Q flag and loading specific packages (and their dependencies) >> +manually. > > Seems strange to me to have a command to start another Emacs. Why not > implement this as a command-line option instead? That would be > consistent with the several options we already have, like -q, -Q, -D, > which already contrl what happens at startup. Mainly because this wouldn't support a completing-read interface, that simplifies prompting the user for a set of packages. But perhaps the bulk of this command could be implemented as a CLI option, that this command could wrap? >> + (let* ((real (package-desc-dir package)) >> + (link (expand-file-name (file-name-nondirectory real) elpa))) >> + (make-symbolic-link real link t) > > Using symbolic links makes the program less portable, so it is best to > avoid them. The reason I used them here, instead of just adding the directories under ~/.config/emacs/elpa/ is that startup.el issues a warning along the lines of Your `load-path' seems to contain your `user-emacs-directory' ... My previous patch actually included the code that suppresses all warnings during initialisation, so I've removed this hack. >> + (apply #'start-process (concat "*" name "*") nil >> + (append (list (or (emacs-executable) "emacs") > > I don't think it's a good idea to invoke just "emacs", it could be a > completely different version of Emacs. > >> +DEFUN ("emacs-executable", Femacs_executable, Semacs_executable, 0, 0, "", >> + doc: /* Return a string with the file name of the Emacs executable. >> +If this is not known, nil will be returned instead. */) >> + (void) > > I don't understand why you need this primitive. What's wrong with the > usual paradigm we use everywhere else: > > (expand-file-name invocation-name invocation-directory) Because I failed to remember it. This also appears to not have the risk of returning nil, as my proposed command could have. I've applies these and related changes below: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-command-to-start-Emacs-with-specific-packages.patch >From 47dde2be5732ec9dfa153813649e385e0227751e Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Tue, 15 Aug 2023 18:39:14 +0200 Subject: [PATCH] Add command to start Emacs with specific packages * lisp/emacs-lisp/package.el (package-isolate): Add command. * etc/NEWS: Announce it. --- etc/NEWS | 6 +++++ lisp/emacs-lisp/package.el | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 57f04609679..c374695a571 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -505,6 +505,12 @@ project, that you can quickly select using 'project-switch-project' When non-nil, package specifications with side-effects for building software will be used when building a package. +--- +*** New command to start Emacs only with specific packages +The command 'package-isolate' is equivalent to starting Emacs with the +-Q flag and loading specific packages (and their dependencies) +manually. + ** Flymake +++ diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index b3062d2608b..838b2823466 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -2625,6 +2625,53 @@ package-autoremove removable)) (message "Nothing to autoremove"))))) +(defun package-isolate (packages) + "Start an uncustomised Emacs and only load a set of PACKAGES." + (interactive + (cl-loop for p in (cl-loop for p in (package--alist) append (cdr p)) + unless (package-built-in-p p) + collect (cons (package-desc-full-name p) p) into table + finally return + (list (cl-loop for c in (completing-read-multiple + "Isolate packages: " table + nil t) + collect (alist-get c table nil nil #'string=))))) + (cl-assert (cl-every #'package-desc-p packages)) + (let* ((name (concat "package-isolate-" (mapconcat #'package-desc-full-name + packages ","))) + (tmp-init (make-temp-file name t)) + (elpa (expand-file-name "elpa" tmp-init)) + args) + (make-directory elpa) + (dolist (package packages) + ;; We need to recursively expand all the dependencies of the + ;; requested packages and all of them to `load-path'. + (dolist (package (named-let loop ((pkg-desc package)) + (let (deps) + (dolist (req (package-desc-reqs pkg-desc)) + (setq deps (nconc + (catch 'found + (dolist (p (apply #'append (mapcar #'cdr (package--alist)))) + (when (and (string= (car req) (package-desc-name p)) + (version-list-<= (cadr req) (package-desc-version p))) + (throw 'found (loop p))))) + deps))) + (cons pkg-desc deps)))) + (push (format "--directory=%s" (package-desc-dir package)) args) + (let* ((load-suffixes '(".el" ".elc")) + (autoload (locate-library (package--autoloads-file-name package)))) + (push (format "--load=%s" autoload) args)))) + (apply #'start-process (concat "*" name "*") nil + (append (list (expand-file-name invocation-name invocation-directory) + "--quick" "--debug-init" + (format "--eval=%S" + '(progn + (require 'warnings) + (add-to-list 'warning-suppress-log-types 'initialization))) + "--init-directory" tmp-init) + args)) + (message "Started Emacs with the init directory: %s" tmp-init))) + ;;;; Package description buffer. -- 2.39.2 --=-=-=--