From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.devel Subject: Re: Default emacs init file location confusion Date: Tue, 14 Jan 2020 15:00:13 +0100 Message-ID: References: <87tv56bjop.fsf@gmail.com> <539DBEA2-E758-4CB0-B886-F908CF0525B6@gnu.org> <83pnfuaqj3.fsf@gnu.org> <83imllc3iq.fsf@gnu.org> <87eew9q4rt.fsf@windriver.com> <83tv538d0q.fsf@gnu.org> <7f532a3b-a812-3088-936c-e15a35b58654@cs.ucla.edu> <834kwz72o5.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="182551"; mail-complaints-to="usenet@blaine.gmane.org" Cc: eggert@cs.ucla.edu, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jan 14 15:01:50 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1irMlR-000l2L-6g for ged-emacs-devel@m.gmane-mx.org; Tue, 14 Jan 2020 15:01:49 +0100 Original-Received: from localhost ([::1]:40356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irMlP-0003Pk-Bi for ged-emacs-devel@m.gmane-mx.org; Tue, 14 Jan 2020 09:01:47 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52887) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irMjz-00025z-IX for emacs-devel@gnu.org; Tue, 14 Jan 2020 09:00:21 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irMjx-0001Yw-AJ for emacs-devel@gnu.org; Tue, 14 Jan 2020 09:00:19 -0500 Original-Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:34971) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irMjx-0001Yj-3C; Tue, 14 Jan 2020 09:00:17 -0500 Original-Received: by mail-wm1-x333.google.com with SMTP id p17so13873495wmb.0; Tue, 14 Jan 2020 06:00:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :mime-version:content-transfer-encoding; bh=jLh3nmsSAs9LnjCDkipdc97qMsnY0QqHRv2elvM7Nac=; b=lhzPXarGhd0u54hfv2xUNgJew6Ml0ETIr59pcLJh49Ybu5yI//j4/T40G7PN3DBbLZ R6O78tDdDVG2XVHeGKe0nRX5kdYiVOExafk3NPoD/wqvwfz3F3ShhdUKCNPnYdVZ/W6F nSpcHsl1K13k2sY//Asuw3aON4jOAcahASAU80XN2eqa1oXtBCjGnzJ3gcOBSJA4osm3 qUI0Xhy8jaPAlMkZKdQTlhqMVYyc2FrPNqq0PHdz/Akoqd5kiY2CLzClaBFGFTOT5kXr p6JZVJEDadrkVcHiJqt4NW8oltS1EG01TcG3bRKNCVZHaZ27BsJN/g05SzFDuUPcoyVB KHHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:mime-version:content-transfer-encoding; bh=jLh3nmsSAs9LnjCDkipdc97qMsnY0QqHRv2elvM7Nac=; b=j7Y0gl1g1l77wApF9HWztnHoWiqBceIFfgtQGcfl3kx6iiAhNQOh5z/i84QVso9zTe MqIk5sUwn3++sBRP4C4+q83BkkFiWftShXH9JpEaSXNeBDK7wd/ZETlibvFO1uwqW93t Dfhb5b0OLwP8P6zue082Rn5l7y5buoXXu0HZxhM7I8XFfJsWNlnFkxXT2ivCO1hrvfGg WiILDdaHCKvSJItlxs+KdBUV1e/lA0iE/9LZ3YLxhFG4deA4OfydhKMGrBfI8aewkRRx hu5wRudSWjt3DP8p7Nvv482dLUi+WJtRaghCTfHx5i5R2xFTc823bvyISQ475A7l+z46 ac1g== X-Gm-Message-State: APjAAAVAoO5hcc2f6XerLiEsbIKdMNo420/dxxvZXi42JcQ6G0KdHM+V uai7+ajZ2gbBdUTWC1dhd5yJ9csd X-Google-Smtp-Source: APXvYqxsvd7GqAEsD52B95a3zuTyg9RyV8MLOExbc37o1DaAXcZkXWT0WthDJjwAJRBZCI64EVtypQ== X-Received: by 2002:a7b:c4cc:: with SMTP id g12mr27803984wmk.68.1579010414969; Tue, 14 Jan 2020 06:00:14 -0800 (PST) Original-Received: from rpluim-mac ([149.5.228.1]) by smtp.gmail.com with ESMTPSA id u7sm18688508wmj.3.2020.01.14.06.00.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 06:00:14 -0800 (PST) In-Reply-To: (Robert Pluim's message of "Mon, 13 Jan 2020 17:39:19 +0100") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::333 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:244242 Archived-At: >>>>> On Mon, 13 Jan 2020 17:39:19 +0100, Robert Pluim s= aid: >>>>> On Mon, 13 Jan 2020 18:15:54 +0200, Eli Zaretskii said: Eli> Btw, the "+++" before the NEWS entry means we have this documented= in Eli> the manuals, but I wonder whether the current text there is in sync Eli> with the code change we are about to install. Robert> No, it is definitely not aligned. Robert> Robert So here=CA=BCs what I have so far. diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index 1958a86b92..55c3141a71 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi @@ -2655,26 +2655,34 @@ Find Init =20 Emacs normally finds your init file in a location under your home directory. @xref{Init File}. By default this location is -@file{~/.config/emacs/init.el} where @file{~/} stands for your home direct= ory. +@file{~/.emacs.d/init.el} where @file{~/} stands for your home directory. This default can be overridden as described below. =20 - If @env{XDG_CONFIG_HOME} is set in your environment, its -value replaces @file{~/.config} in the name of the default -init file. - - If the default init file's parent directory does not exist but the -directory @file{~/.emacs.d} does exist, Emacs looks for your init file +Emacs looks for your init file using the filenames @file{~/.emacs.el}, @file{~/.emacs}, or @file{~/.emacs.d/init.el}; you can choose to use any one of these names. (Note that only the locations directly in your home directory -have a leading dot in the location's basename.) Although this is -backward-compatible with older Emacs versions, modern POSIX platforms -prefer putting your initialization files under @file{~/.config} so -that troubleshooting a problem that might be due to a bad init file, -or archiving a collection of init files, can be done by renaming that -directory. To help older Emacs versions find configuration files in -their current default locations, you can execute the following -Emacs Lisp code: +have a leading dot in the location's basename.) + +Emacs can also look in an XDG-compatible location for @file{init.el}, +the default is the directory @file{~/.config/emacs}. This can be +overriden by setting @env{XDG_CONFIG_HOME} in your environment, its +value replaces @file{~/.config} in the name of the default XDG init +file. However @file{~/.emacs.d} and @file{~/.emacs} are always +preferred if they exist, which means that you must delete or rename +them in order to use the XDG location. + +Note also that if neither the XDG location nor @file{~/.emacs.d} +exist, then Emacs will create @file{~/.emacs.d} (and therefore use it +during subsequent invocations). + +Although this is backward-compatible with older Emacs versions, modern +POSIX platforms prefer putting your initialization files under +@file{~/.config} so that troubleshooting a problem that might be due +to a bad init file, or archiving a collection of init files, can be +done by renaming that directory. To help older Emacs versions find +configuration files in their current default locations, you can +execute the following Emacs Lisp code: =20 @example (make-symbolic-link ".config/emacs" "~/.emacs.d") @@ -2694,7 +2702,7 @@ Find Init name in the system's data base of users. =20 For brevity the rest of the Emacs documentation generally uses just -the current default location @file{~/.config/emacs/init.el} for the +the current default location @file{~/.emacs.d/init.el} for the init file. @c LocalWords: backtab =20 @@ -2740,7 +2748,7 @@ Early Init File @xref{Init File}. However, it is sometimes desirable to have customizations that take effect during Emacs startup earlier than = the normal init file is processed. Such customizations can be put in the early -init file, @file{~/.config/emacs.d/early-init.el} or @file{~/.emacs.d/earl= y-init.el}. This file is loaded before the +init file, @file{~/.config/emacs/early-init.el} or @file{~/.emacs.d/early-= init.el}. This file is loaded before the package system and GUI is initialized, so in it you can customize variables that affect frame appearance as well as the package initialization process, such as @code{package-enable-at-startup}, @code{package-load-list}, and diff --git a/etc/NEWS b/etc/NEWS index cea5d500c7..0837bd2336 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -154,25 +154,24 @@ support. * Startup Changes in Emacs 27.1 =20 +++ -** Emacs now uses the XDG convention for init files. -For example, it looks for init.el in "~/.config/emacs/init.el", and -similarly for other init files. - -The 'XDG_CONFIG_HOME' environment variable (which defaults to "~/.config") -specifies the parent directory of these and other configuration files, -and will override their traditional locations (the home directory, -"~/.emacs.d", etc.). - -Emacs will still look for init files in their traditional locations if -"$XDG_CONFIG_HOME/emacs" does not exist, but "~/.emacs.d" or -"~/.emacs" does exist, so invoking Emacs with XDG_CONFIG_HOME=3D'/nowhere' -might be useful if your new-location init files are scrambled, or if -you want to force Emacs to ignore files under 'XDG_CONFIG_HOME' for -some other reason. - -If neither "$XDG_CONFIG_HOME/emacs" nor "~/.emacs.d" exist, Emacs will -now default to "$XDG_CONFIG_HOME/emacs", and will create that directory -and set 'user-emacs-directory' to point to it. +** Emacs can now use the XDG convention for init files. +The 'XDG_CONFIG_HOME' environment variable (which defaults to +"~/.config") specifies the XDG configuration parent directory. Emacs +checks for "init.el" and other configuration files inside the "emacs" +subdirectory of 'XDG_CONFIG_HOME', i.e. "$XDG_CONFIG_HOME/emacs/init.el" + +Emacs will still initially look for init files in their traditional +locations if "~/.emacs.d" or "~/.emacs" exist, even if +"$XDG_CONFIG_HOME/emacs" also exists. This means that you must delete +or rename any existing "~/.emacs.d" and "~/.emacs" to enable use of +the XDG directory. + +If "~/.emacs.d" does not exist, and Emacs has decided to use it +(i.e. "$XDG_CONFIG_HOME/emacs" does not exist), Emacs will create it. +Emacs will never create "$XDG_CONFIG_HOME/emacs". + +Whichever directory Emacs decides to use, it will set +'user-emacs-directory' to point to it. =20 +++ ** Emacs can now be configured using an early init file. diff --git a/lisp/startup.el b/lisp/startup.el index 2a85c004da..1f545c6692 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -497,28 +497,28 @@ startup--xdg-config-default (defvar startup--xdg-config-home-emacs) =20 ;; Return the name of the init file directory for Emacs, assuming -;; XDG-DIR is the XDG location and USER-NAME is the user name. -;; If USER-NAME is nil or "", use the current user. -;; Prefer the XDG location unless it does does not exist and the -;; .emacs.d location does exist. +;; XDG-DIR is the XDG location and USER-NAME is the user name. If +;; USER-NAME is nil or "", use the current user. Prefer the XDG +;; location only if the .emacs.d location does not exist. (defun startup--xdg-or-homedot (xdg-dir user-name) - (if (file-exists-p xdg-dir) - xdg-dir - (let ((emacs-d-dir (concat "~" user-name - (if (eq system-type 'ms-dos) - "/_emacs.d/" - "/.emacs.d/")))) - (if (or (file-exists-p emacs-d-dir) - (if (eq system-type 'windows-nt) - (if (file-directory-p (concat "~" user-name)) - (directory-files (concat "~" user-name) nil - "\\`[._]emacs\\(\\.elc?\\)?\\'")) - (file-exists-p (concat "~" init-file-user - (if (eq system-type 'ms-dos) - "/_emacs" - "/.emacs"))))) - emacs-d-dir - xdg-dir)))) + (let ((emacs-d-dir (concat "~" user-name + (if (eq system-type 'ms-dos) + "/_emacs.d/" + "/.emacs.d/")))) + (cond + ((or (file-exists-p emacs-d-dir) + (if (eq system-type 'windows-nt) + (if (file-directory-p (concat "~" user-name)) + (directory-files (concat "~" user-name) nil + "\\`[._]emacs\\(\\.elc?\\)?\\'")) + (file-exists-p (concat "~" init-file-user + (if (eq system-type 'ms-dos) + "/_emacs" + "/.emacs"))))) + emacs-d-dir) + ((file-exists-p xdg-dir) + xdg-dir) + (t emacs-d-dir)))) =20 (defun normal-top-level () "Emacs calls this function when it first starts up.