From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs 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 Message-ID: <875yq6qwf2.fsf@gnus.org> References: <87ppom45ge.wl%arne_bab@web.de> <87k1bf6us6.fsf@mouse.gnus.org> <878srv2gl6.fsf@mouse.gnus.org> <85ftm2lcxl.fsf@gmail.com> <871rxmuimx.fsf@mouse.gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26774"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Glenn Morris , Arne Babenhauserheide , 16242@debbugs.gnu.org, Andrea Corallo To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 26 17:58:20 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nClch-0006jx-9x for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 26 Jan 2022 17:58:19 +0100 Original-Received: from localhost ([::1]:51674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nClcf-0006Qa-VF for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 26 Jan 2022 11:58:17 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:33226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nClPr-0000JI-0o for bug-gnu-emacs@gnu.org; Wed, 26 Jan 2022 11:45:19 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60378) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nClPp-0005Ml-Vk for bug-gnu-emacs@gnu.org; Wed, 26 Jan 2022 11:45:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nClPp-0002sC-Sl for bug-gnu-emacs@gnu.org; Wed, 26 Jan 2022 11:45:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 26 Jan 2022 16:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16242 X-GNU-PR-Package: emacs Original-Received: via spool by 16242-submit@debbugs.gnu.org id=B16242.164321547510969 (code B ref 16242); Wed, 26 Jan 2022 16:45:01 +0000 Original-Received: (at 16242) by debbugs.gnu.org; 26 Jan 2022 16:44:35 +0000 Original-Received: from localhost ([127.0.0.1]:53278 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nClPK-0002qj-L5 for submit@debbugs.gnu.org; Wed, 26 Jan 2022 11:44:35 -0500 Original-Received: from quimby.gnus.org ([95.216.78.240]:49654) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nClPI-0002qV-CS for 16242@debbugs.gnu.org; Wed, 26 Jan 2022 11:44:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=7dYQWvwb6x+RH/ImjXR1dr5tbav3cjJnabYuTr2lydk=; b=sbq8jPKMRQNXXdC7NdbWGDVmTT deouGqK8Pnvk/3TvBDIQuYuH3GyghODLi4WtsdpOlGgurMefaTDvQuqYMP7wB+e+I7UegYJKPAfun OEstNTBK9KbneVR+gxRu9Urw0BfmjNMi0tdMZQNFeM8kLBw7G4Ba6TIc5Yvc0zSD0oT8=; Original-Received: from [84.212.220.105] (helo=giant) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nClP8-0003mI-Ht; Wed, 26 Jan 2022 17:44:21 +0100 X-Now-Playing: Phew's _Phew_: "Closed" In-Reply-To: <871rxmuimx.fsf@mouse.gnus.org> (Lars Ingebrigtsen's message of "Thu, 15 Aug 2019 16:13:42 -0700") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:225285 Archived-At: Lars Ingebrigtsen 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