plexus / chemacs2

Emacs version switcher, improved
779 stars 47 forks source link

Allow chemacs-profiles from chemacs-profile to be globally available? #43

Closed zardoz03 closed 2 years ago

zardoz03 commented 2 years ago

Note: I'm sending this patch as an issue only because I do not want to accidentally send a broken/odd PR to upstream, as I have other edits locally I don't want to commit. I apologize in advance for being awkward in this manner.

@@ -102,19 +101,20 @@
           (env-profile-value env-profile-value)
           (t chemacs-default-profile-name))))

+(defvar chemacs-profiles
+  (with-temp-buffer
+    (insert-file-contents chemacs-profiles-path)
+    (goto-char (point-min))
+    (condition-case err
+        (read (current-buffer))
+      (error
+       (error "Failed to parse %s: %s" chemacs-profiles-path (error-message-string err))))))
+
 (defvar chemacs-profile
   (if (and chemacs--with-profile-value
            (listp chemacs--with-profile-value))
       chemacs--with-profile-value
-    (let ((profiles
-           (with-temp-buffer
-             (insert-file-contents chemacs-profiles-path)
-             (goto-char (point-min))
-             (condition-case err
-                 (read (current-buffer))
-               (error
-                (error "Failed to parse %s: %s" chemacs-profiles-path (error-message-string err)))))))
-      (cdr (assoc chemacs-profile-name profiles)))))
+      (cdr (assoc chemacs-profile-name chemacs-profiles))))

 (unless chemacs-profile
   (error "No profile `%s' in %s" chemacs-profile-name chemacs-profiles-path))

Primarily the motivation for this is allowing for the user to program with the data that is read in here at EMACS' boot. For example one could (albeit naively) use completing-read to provide arguments to restart-emacs (per issue #40) in order to change a chemacs install, without having to re-read from the chemacs-profiles-path.

(defun restart-emacs-with-other-profile (&optional profile)
   (interactive)
   (if (or (null profile) (called-interactively-p 'any))
       (restart-emacs (list "--with-profile" (completing-read "chemacs install to reboot into: "
                                                              (mapcar #'car chemacs-profiles)
                                                              nil t)))
     (and (stringp profile)
          (memq profile chemacs-profiles)
          (restart-emacs (list "--with-profile" profile)))))
plexus commented 2 years ago

I'm sorry but you're putting an extra burden here on maintainers who are already stretched thin. The change looks fine, but please submit a PR if you want it to make it in. Do a fresh git clone in a temporary location if you are concerned about committing other changes, or use git add -p to selectively stage and commit hunks.

Thanks.