all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: thievol@posteo.net,  emacs-devel@gnu.org
Subject: Proposal for 'package-isolate' command
Date: Tue, 15 Aug 2023 19:52:32 +0000	[thread overview]
Message-ID: <87r0o4jd6n.fsf_-_@posteo.net> (raw)
In-Reply-To: <83y1ic8790.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 15 Aug 2023 21:56:11 +0300")

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

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Philip Kaludercic <philipk@posteo.net>
>> 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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-command-to-start-Emacs-with-specific-packages.patch --]
[-- Type: text/x-diff, Size: 3999 bytes --]

From 47dde2be5732ec9dfa153813649e385e0227751e Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
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)))
+
 \f
 ;;;; Package description buffer.
 
-- 
2.39.2


  reply	other threads:[~2023-08-15 19:52 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07  7:57 Changes to make in elpa-packages file for nongnu elpa Thierry Volpiatto
2023-08-07 13:30 ` Philip Kaludercic
2023-08-07 18:19   ` Thierry Volpiatto
2023-08-07 20:33     ` Philip Kaludercic
2023-08-08  4:33       ` Thierry Volpiatto
2023-08-08  5:52         ` Philip Kaludercic
2023-08-08  6:17           ` Thierry Volpiatto
2023-08-15 16:55           ` Philip Kaludercic
2023-08-15 17:34             ` Eshel Yaron
2023-08-15 19:39               ` Proposal for 'package-isolate' command Philip Kaludercic
2023-08-17 10:53                 ` Adam Porter
2023-08-15 18:56             ` Changes to make in elpa-packages file for nongnu elpa Eli Zaretskii
2023-08-15 19:52               ` Philip Kaludercic [this message]
2023-08-16 11:25                 ` Proposal for 'package-isolate' command Eli Zaretskii
2023-08-16 18:48                   ` Philip Kaludercic
2023-08-16  6:51             ` Changes to make in elpa-packages file for nongnu elpa Thierry Volpiatto
2023-08-16 10:10               ` Philip Kaludercic
2023-08-16 10:14                 ` Thierry Volpiatto
2023-08-16 11:03                   ` Philip Kaludercic
2023-08-16 11:55                     ` Thierry Volpiatto
2023-08-16 18:34                       ` Proposal for 'package-isolate' command Philip Kaludercic
2023-08-16 18:49                         ` Stefan Kangas
2023-08-16 19:00                           ` Philip Kaludercic
2023-08-17  5:30                         ` Thierry Volpiatto
2023-08-17  8:34                           ` Philip Kaludercic
2023-08-17  9:07                             ` Eshel Yaron
2023-08-17 14:19                               ` Philip Kaludercic
2023-08-17 13:32                             ` Thierry Volpiatto
2023-08-17 14:04                               ` Philip Kaludercic
2023-08-17 14:15                                 ` Thierry Volpiatto
2023-08-17 13:56                             ` Thierry Volpiatto
2023-08-17 14:18                               ` Philip Kaludercic
2023-08-17 14:28                               ` Thierry Volpiatto
2023-08-17 18:17                                 ` Philip Kaludercic
2023-08-18  4:57                                   ` Thierry Volpiatto
2023-08-18  5:44                                     ` Eli Zaretskii
2023-08-18  7:49                                     ` Philip Kaludercic
2023-08-18 12:43                                       ` Thierry Volpiatto
2023-08-18 18:34                                       ` Adding package and package-vc to ELPA Philip Kaludercic
2023-08-19 10:26                                         ` Thierry Volpiatto
2023-08-20  6:40                             ` Proposal for 'package-isolate' command Thierry Volpiatto
2023-08-20  7:51                               ` Philip Kaludercic
2023-08-20 16:06                               ` Thierry Volpiatto
2023-08-20 18:41                                 ` Philip Kaludercic
2023-08-20 19:15                                   ` Thierry Volpiatto
2023-08-20 20:24                                     ` Thierry Volpiatto
2023-08-20 20:28                                     ` Philip Kaludercic
2023-08-16 14:10                 ` Changes to make in elpa-packages file for nongnu elpa Eli Zaretskii
2023-08-16 18:52                   ` Philip Kaludercic
2023-08-08  6:01       ` Thierry Volpiatto
2023-08-08  6:34       ` Michael Albinus
2023-08-08 16:37         ` Philip Kaludercic
2023-08-08 16:41           ` Michael Albinus
2023-08-09  7:06             ` Philip Kaludercic
2023-08-09 11:53               ` Eli Zaretskii
2023-08-09 14:53                 ` Philip Kaludercic
2023-08-09 14:55                   ` Eli Zaretskii
2023-08-09 15:24                     ` Philip Kaludercic
2023-08-09 16:23                       ` Eli Zaretskii
2023-08-09  3:47   ` Richard Stallman

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

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

  git send-email \
    --in-reply-to=87r0o4jd6n.fsf_-_@posteo.net \
    --to=philipk@posteo.net \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=thievol@posteo.net \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.