From: "François Févotte" <francois.fevotte@ensta.org>
To: 15539@debbugs.gnu.org
Subject: bug#15539: Setting user-emacs-directory at command line invocation
Date: Fri, 13 Mar 2015 16:01:55 +0100 [thread overview]
Message-ID: <CAADsv966ew8NseGyaEZgJ8c1birphdgF9TXp5YNdZzOkjV7GVA@mail.gmail.com> (raw)
In-Reply-To: <87wqlqiayq.fsf@carifio.org>
[-- Attachment #1.1: Type: text/plain, Size: 978 bytes --]
Hello,
attached is a patch which tries to implement the desired feature. It should
apply cleanly atop master (b91eafe31a524b391d5cec079cf8f36c2f9d5f30)
With this patch, emacs accepts a new command line argument:
--user-emacs-directory=DIR
which has two effects:
1. it sets the `user-emacs-directory' variable to DIR (instead of the
default "~/.emacs.d")
2. it looks for the init file in DIR/init.el (and only there: ~/.emacs & co
are bypassed)
This doesn't impact anything else in emacs' startup sequence.
Implementationwise, I'm not very proud of having to define a new global
variable, but I fail to see how to do otherwise, except maybe wrapping the
whole `command-line' function in a let form to use a local binding.
Please do not hesitate to criticize or ask me for any modification which
would be desirable. This is the first patch I propose to emacs; I don't
expect to have it right on the first try.
Thanks in advance,
François
[-- Attachment #1.2: Type: text/html, Size: 1174 bytes --]
[-- Attachment #2: 0001-Add-a-user-emacs-directory-command-line-option.patch --]
[-- Type: text/x-patch, Size: 3807 bytes --]
From cb6e52b3cd1bb6ff23a5c89b9838169ea216cf9b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20F=C3=A9votte?= <fevotte@gmail.com>
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.")
\f
;;;; Misc. useful functions.
--
1.7.2.5
next prev parent reply other threads:[~2015-03-13 15:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-06 17:08 bug#15539: 24.3; setting user-emacs-directory at command line invocation Mike Carifio
2015-03-13 15:01 ` François Févotte [this message]
2015-03-16 0:36 ` bug#15539: Setting " Glenn Morris
2015-03-16 7:28 ` François Févotte
2015-03-17 10:08 ` François Févotte
2016-02-15 10:31 ` bug#15539: [PATCH] Setting user-emacs-directory Alexis
2016-02-15 14:15 ` Eli Zaretskii
2016-02-24 4:03 ` Lars Ingebrigtsen
2016-02-24 17:15 ` Eli Zaretskii
2016-02-25 5:48 ` Lars Ingebrigtsen
2016-11-03 22:32 ` bug#15539: comment Max
2016-11-04 7:28 ` Eli Zaretskii
2016-11-04 12:42 ` Evgeny Roubinchtein
2016-11-04 12:55 ` Noam Postavsky
2016-11-04 13:59 ` Eli Zaretskii
2016-12-14 18:43 ` Glenn Morris
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAADsv966ew8NseGyaEZgJ8c1birphdgF9TXp5YNdZzOkjV7GVA@mail.gmail.com \
--to=francois.fevotte@ensta.org \
--cc=15539@debbugs.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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).