From cb6e52b3cd1bb6ff23a5c89b9838169ea216cf9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20F=C3=A9votte?= Date: Fri, 13 Mar 2015 15:01:02 +0100 Subject: [PATCH] Add a `--user-emacs-directory' command-line option This sets `user-emacs-directory' and looks for `init.el' in it. Fixes: bug#15539 --- doc/emacs/cmdargs.texi | 10 +++++++++- lisp/startup.el | 16 +++++++++++++--- lisp/subr.el | 4 ++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/doc/emacs/cmdargs.texi b/doc/emacs/cmdargs.texi index 42c8e33..be83aaa 100644 --- a/doc/emacs/cmdargs.texi +++ b/doc/emacs/cmdargs.texi @@ -349,7 +349,15 @@ Do not reload any saved desktop. @xref{Saving Emacs Sessions}. @opindex --user @cindex load init file of another user Load @var{user}'s initialization file instead of your -own@footnote{This option has no effect on MS-Windows.}. +own@footnote{This option has no effect on MS-Windows, nor when +@samp{--user-emacs-directory} is used}. + +@item --user-emacs-directory=@var{dir} +@opindex --user-emacs-directory +Look for the initialization file in @var{dir}, instead of the default +@file{~/.emacs.d/}; @pxref{Init File}. @var{dir} will also be used as +the default directory where user-specific configuration data will be +stored; @xref{Standard File Names,,, elisp}. @item --debug-init @opindex --debug-init diff --git a/lisp/startup.el b/lisp/startup.el index 999e53e..6f25c65 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -877,7 +877,7 @@ please check its value") (while (and (not done) args) (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--debug-init") ("--user") ("--iconic") ("--icon-type") ("--quick") - ("--no-blinking-cursor") ("--basic-display"))) + ("--no-blinking-cursor") ("--basic-display") ("--user-emacs-directory"))) (argi (pop args)) (orig-argi argi) argval) @@ -924,6 +924,10 @@ please check its value") (push '(visibility . icon) initial-frame-alist)) ((member argi '("-nbc" "-no-blinking-cursor")) (setq no-blinking-cursor t)) + ((equal argi "-user-emacs-directory") + (setq user-emacs-directory (file-name-as-directory (or argval (pop args))) + user-emacs-directory--set t + argval nil)) ;; Push the popped arg back on the list of arguments. (t (push argi args) @@ -1102,7 +1106,11 @@ please check its value") ;; This tells `load' to store the file name found ;; into user-init-file. (setq user-init-file t) - (load user-init-file-1 t t) + + ;; Don't try to read `~/.emacs' if the user provided a + ;; custom `user-emacs-directory' in the command-line. + (unless user-emacs-directory--set + (load user-init-file-1 t t)) (when (eq user-init-file t) ;; If we did not find ~/.emacs, try @@ -1111,7 +1119,9 @@ please check its value") (expand-file-name "init" (file-name-as-directory - (concat "~" init-file-user "/.emacs.d"))))) + (if user-emacs-directory--set + user-emacs-directory + (concat "~" init-file-user "/.emacs.d")))))) (load otherfile t t) ;; If we did not find the user's init file, diff --git a/lisp/subr.el b/lisp/subr.el index deadca6..c5c81b7 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2545,6 +2545,10 @@ mode.") Various programs in Emacs store information in this directory. Note that this should end with a directory separator. See also `locate-user-emacs-file'.") + +(defvar user-emacs-directory--set nil + "Non-nil if the user provided a custom value for `user-emacs-directory'. +This can be done via the `--user-emacs-directory' command-line switch.") ;;;; Misc. useful functions. -- 1.7.2.5