emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 8eaf04de83: Add new switch --init-directory


From: Lars Ingebrigtsen
Subject: master 8eaf04de83: Add new switch --init-directory
Date: Thu, 27 Jan 2022 17:38:42 -0500 (EST)

branch: master
commit 8eaf04de83fd967c2ab69a4c1dfe44a6a10aa912
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new switch --init-directory
    
    * doc/emacs/cmdargs.texi (Initial Options): Mention it.
    * lisp/startup.el (normal-top-level): Move the eln init to after
    we've processed the command line arguments.
    (command-line): Interpret the --init-directory switch.
    
    * src/emacs.c (standard_args): Add.
---
 doc/emacs/cmdargs.texi |  4 +++
 doc/lispref/os.texi    |  3 ++
 etc/NEWS               |  3 ++
 lisp/startup.el        | 78 +++++++++++++++++++++++++++++---------------------
 src/emacs.c            |  1 +
 5 files changed, 57 insertions(+), 32 deletions(-)

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 @@ option does this too, but other options like @samp{-q} do 
not.
 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 @@ Do not load the @file{site-start} library.
 @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/etc/NEWS b/etc/NEWS
index abef1019ac..d1eaf08036 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -79,6 +79,9 @@ as was already the case for all the non-preloaded files.
 
 * Startup Changes in Emacs 29.1
 
++++
+** Emacs now support setting 'user-emacs-directory' via --init-directory.
+
 +++
 ** Emacs now has a '--fingerprint' option.
 This will output a string identifying the current Emacs build.
diff --git a/lisp/startup.el b/lisp/startup.el
index 856d600e38..f4216f7c4c 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -558,26 +558,6 @@ It is the default value of the variable `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
@@ -664,16 +644,6 @@ It is the default value of the variable `top-level'."
                (set pathsym (mapcar (lambda (dir)
                                       (decode-coding-string dir coding t))
                                     path)))))
-        (when (featurep 'native-compile)
-          (let ((npath (symbol-value 'native-comp-eln-load-path)))
-            (set 'native-comp-eln-load-path
-                 (mapcar (lambda (dir)
-                           ;; Call expand-file-name to remove all the
-                           ;; pesky ".." from the directyory names in
-                           ;; native-comp-eln-load-path.
-                           (expand-file-name
-                            (decode-coding-string dir coding t)))
-                         npath))))
        (dolist (filesym '(data-directory doc-directory exec-directory
                                          installation-directory
                                          invocation-directory invocation-name
@@ -789,6 +759,45 @@ It is the default value of the variable `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)))
+      (when locale-coding-system
+        (let ((coding (if (eq system-type 'windows-nt)
+                         ;; MS-Windows build converts all file names to
+                         ;; UTF-8 during startup.
+                         'utf-8
+                       locale-coding-system))
+              (npath (symbol-value 'native-comp-eln-load-path)))
+          (set 'native-comp-eln-load-path
+               (mapcar (lambda (dir)
+                         ;; Call expand-file-name to remove all the
+                         ;; pesky ".." from the directyory names in
+                         ;; native-comp-eln-load-path.
+                         (expand-file-name
+                          (decode-coding-string dir coding t)))
+                       npath)))))
+
     ;; 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
@@ -1153,7 +1162,8 @@ please check its value")
                          ("--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)
@@ -1193,6 +1203,9 @@ please check its value")
          (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))
@@ -1269,7 +1282,8 @@ please check its value")
                (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 @@ static const struct standard_args standard_args[] =
   { "-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 },



reply via email to

[Prev in Thread] Current Thread [Next in Thread]