all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Noam Postavsky <npostavs@gmail.com>
Cc: Glenn Morris <rgm@gnu.org>,
	Arne Babenhauserheide <arne_bab@web.de>,
	16242@debbugs.gnu.org, Andrea Corallo <akrl@sdf.org>
Subject: bug#16242: 24.3; wish: set init directory (.emacs.d) by commandline flag for easy custom environments
Date: Wed, 26 Jan 2022 17:44:17 +0100	[thread overview]
Message-ID: <875yq6qwf2.fsf@gnus.org> (raw)
In-Reply-To: <871rxmuimx.fsf@mouse.gnus.org> (Lars Ingebrigtsen's message of "Thu, 15 Aug 2019 16:13:42 -0700")

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Ah, I see.  So I think the XDG patch should go in first, and then adding
> --init-dir should be pretty trivial.

Below is a stab at this, and it seems to work fine -- except that after
starting Emacs with --init-directory /tmp/, the async nativecomp never
fires.   I poked at it for half an hour, but was unable to determine
why.

Andrea, do you see something obvious here that would disable nativecomp
if user-emacs-directory isn't the default?

diff --git a/doc/emacs/cmdargs.texi b/doc/emacs/cmdargs.texi
index 5c444fc648..da9947ece3 100644
--- a/doc/emacs/cmdargs.texi
+++ b/doc/emacs/cmdargs.texi
@@ -329,6 +329,10 @@ Initial Options
 Do not include the @file{site-lisp} directories in @code{load-path}
 (@pxref{Init File}).  The @samp{-Q} option does this too.
 
+@item --init-directory
+@opindex --init-directory
+Specify the directory to use when looking for the Emacs init file.
+
 @item --no-splash
 @opindex --no-splash
 @cindex splash screen
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 3750abc4e8..25a2b9e2e4 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -363,6 +363,9 @@ Startup Summary
 @itemx -Q
 Equivalent to @samp{-q --no-site-file --no-splash}.
 @c and --no-site-lisp, but let's not mention that here.
+
+@item --init-directory
+Specify the directory to use when finding the Emacs init file.
 @end table
 
 
diff --git a/lisp/startup.el b/lisp/startup.el
index d90e7a7d26..41749848a4 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -550,26 +550,6 @@ normal-top-level
     (setq user-emacs-directory
 	  (startup--xdg-or-homedot startup--xdg-config-home-emacs nil))
 
-    (when (featurep 'native-compile)
-      ;; Form `native-comp-eln-load-path'.
-      (let ((path-env (getenv "EMACSNATIVELOADPATH")))
-        (when path-env
-          (dolist (path (split-string path-env path-separator))
-            (unless (string= "" path)
-              (push path native-comp-eln-load-path)))))
-      (push (expand-file-name "eln-cache/" user-emacs-directory)
-            native-comp-eln-load-path)
-      ;; When $HOME is set to '/nonexistent' means we are running the
-      ;; testsuite, add a temporary folder in front to produce there
-      ;; new compilations.
-      (when (and (equal (getenv "HOME") "/nonexistent")
-                 ;; We may be running in a chroot environment where we
-                 ;; can't write anything.
-                 (file-writable-p (expand-file-name
-                                   (or temporary-file-directory ""))))
-        (let ((tmp-dir (make-temp-file "emacs-testsuite-" t)))
-          (add-hook 'kill-emacs-hook (lambda () (delete-directory tmp-dir t)))
-          (push tmp-dir native-comp-eln-load-path))))
     ;; Look in each dir in load-path for a subdirs.el file.  If we
     ;; find one, load it, which will add the appropriate subdirs of
     ;; that dir into load-path.  This needs to be done before setting
@@ -781,6 +761,30 @@ normal-top-level
 	    (font-menu-add-default))
 	(unless inhibit-startup-hooks
 	  (run-hooks 'window-setup-hook))))
+
+    ;; Do this after `command-line', since it may alter
+    ;; `user-emacs-directory'.
+    (when (featurep 'native-compile)
+      ;; Form `native-comp-eln-load-path'.
+      (let ((path-env (getenv "EMACSNATIVELOADPATH")))
+        (when path-env
+          (dolist (path (split-string path-env path-separator))
+            (unless (string= "" path)
+              (push path native-comp-eln-load-path)))))
+      (push (expand-file-name "eln-cache/" user-emacs-directory)
+            native-comp-eln-load-path)
+      ;; When $HOME is set to '/nonexistent' means we are running the
+      ;; testsuite, add a temporary folder in front to produce there
+      ;; new compilations.
+      (when (and (equal (getenv "HOME") "/nonexistent")
+                 ;; We may be running in a chroot environment where we
+                 ;; can't write anything.
+                 (file-writable-p (expand-file-name
+                                   (or temporary-file-directory ""))))
+        (let ((tmp-dir (make-temp-file "emacs-testsuite-" t)))
+          (add-hook 'kill-emacs-hook (lambda () (delete-directory tmp-dir t)))
+          (push tmp-dir native-comp-eln-load-path))))
+
     ;; Subprocesses of Emacs do not have direct access to the terminal, so
     ;; unless told otherwise they should only assume a dumb terminal.
     ;; We are careful to do it late (after term-setup-hook), although the
@@ -1145,7 +1149,8 @@ command-line
                          ("--no-x-resources") ("--debug-init")
                          ("--user") ("--iconic") ("--icon-type") ("--quick")
 			 ("--no-blinking-cursor") ("--basic-display")
-                         ("--dump-file") ("--temacs") ("--seccomp")))
+                         ("--dump-file") ("--temacs") ("--seccomp")
+                         ("--init-directory")))
              (argi (pop args))
              (orig-argi argi)
              argval)
@@ -1185,6 +1190,9 @@ command-line
 	  (push '(vertical-scroll-bars . nil) initial-frame-alist))
 	 ((member argi '("-q" "-no-init-file"))
 	  (setq init-file-user nil))
+	 ((member argi '("-init-directory"))
+	  (setq user-emacs-directory (or argval (pop args))
+                argval nil))
 	 ((member argi '("-u" "-user"))
 	  (setq init-file-user (or argval (pop args))
 		argval nil))
@@ -1261,7 +1269,8 @@ command-line
 		(and (eq xdg-dir user-emacs-directory)
 		     (not (eq xdg-dir startup--xdg-config-default))))
 	    user-emacs-directory
-	  ;; The name is not obvious, so access more directories to calculate it.
+	  ;; The name is not obvious, so access more directories
+	  ;; to calculate it.
 	  (setq xdg-dir (concat "~" init-file-user "/.config/emacs/"))
 	  (startup--xdg-or-homedot xdg-dir init-file-user)))
 
diff --git a/src/emacs.c b/src/emacs.c
index f6e2c01ee7..2014e97fbf 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -2472,6 +2472,7 @@ main (int argc, char **argv)
   { "-quick", 0, 55, 0 },
   { "-q", "--no-init-file", 50, 0 },
   { "-no-init-file", 0, 50, 0 },
+  { "-init-directory", "--init-directory", 30, 1 },
   { "-no-x-resources", "--no-x-resources", 40, 0 },
   { "-no-site-file", "--no-site-file", 40, 0 },
   { "-u", "--user", 30, 1 },


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





  reply	other threads:[~2022-01-26 16:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-24 15:46 bug#16242: 24.3; wish: set init directory (.emacs.d) by commandline flag for easy custom environments Arne Babenhauserheide
2019-08-15  2:12 ` Lars Ingebrigtsen
2019-08-15  4:18   ` Glenn Morris
2019-08-15  4:33     ` Lars Ingebrigtsen
2019-08-15 14:29       ` Noam Postavsky
2019-08-15 23:13         ` Lars Ingebrigtsen
2022-01-26 16:44           ` Lars Ingebrigtsen [this message]
2022-01-27 10:20             ` Andrea Corallo
2022-01-27 15:58               ` Lars Ingebrigtsen
2022-01-27 22:36                 ` Lars Ingebrigtsen
2022-01-27 23:30                   ` Glenn Morris
2019-08-15 14:44       ` Eli Zaretskii

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=875yq6qwf2.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=16242@debbugs.gnu.org \
    --cc=akrl@sdf.org \
    --cc=arne_bab@web.de \
    --cc=npostavs@gmail.com \
    --cc=rgm@gnu.org \
    /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.