emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 44f15b6 2/2: emacsclient: adjust to new config file


From: Paul Eggert
Subject: [Emacs-diffs] master 44f15b6 2/2: emacsclient: adjust to new config file location
Date: Fri, 30 Aug 2019 03:24:52 -0400 (EDT)

branch: master
commit 44f15b63dbe9a45921573197e08c8aaaed08412a
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    emacsclient: adjust to new config file location
    
    * lib-src/emacsclient.c (open_config): New arg XDG, to respect
    XDG_CONFIG_HOME, consistently with Emacs proper.  Caller changed.
    Use XDG convention if available, falling back on the old names
    if not.
---
 lib-src/emacsclient.c | 47 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 15 deletions(-)

diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index ba2721e..e9469f7 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -914,22 +914,38 @@ initialize_sockets (void)
 #endif /* WINDOWSNT */
 
 
-/* If the home directory is HOME, return the configuration file with
-   basename CONFIG_FILE.  Fail if there is no home directory or if the
-   configuration file could not be opened.  */
+/* If the home directory is HOME, and XDG_CONFIG_HOME's value is XDG,
+   return the configuration file with basename CONFIG_FILE.  Fail if
+   the configuration file could not be opened.  */
 
 static FILE *
-open_config (char const *home, char const *config_file)
+open_config (char const *home, char const *xdg, char const *config_file)
 {
-  if (!home)
-    return NULL;
-  ptrdiff_t homelen = strlen (home);
-  static char const emacs_d_server[] = "/.emacs.d/server/";
-  ptrdiff_t suffixsize = sizeof emacs_d_server + strlen (config_file);
-  char *configname = xmalloc (homelen + suffixsize);
-  strcpy (stpcpy (stpcpy (configname, home), emacs_d_server), config_file);
-
-  FILE *config = fopen (configname, "rb");
+  ptrdiff_t xdgsubdirsize = xdg ? strlen (xdg) + sizeof "/emacs/server/" : 0;
+  ptrdiff_t homesuffixsizemax = max (sizeof "/.config/emacs/server/",
+                                    sizeof "/.emacs.d/server/");
+  ptrdiff_t homesubdirsizemax = home ? strlen (home) + homesuffixsizemax : 0;
+  char *configname = xmalloc (max (xdgsubdirsize, homesubdirsizemax)
+                             + strlen (config_file));
+  FILE *config;
+  if (xdg || home)
+    {
+      strcpy ((xdg
+              ? stpcpy (stpcpy (configname, xdg), "/emacs/server/")
+              : stpcpy (stpcpy (configname, home), "/.config/emacs/server/")),
+             config_file);
+      config = fopen (configname, "rb");
+    }
+  else
+    config = NULL;
+
+  if (! config && home)
+    {
+      strcpy (stpcpy (stpcpy (configname, home), "/.emacs.d/server/"),
+             config_file);
+      config = fopen (configname, "rb");
+    }
+
   free (configname);
   return config;
 }
@@ -949,10 +965,11 @@ get_server_config (const char *config_file, struct 
sockaddr_in *server,
     config = fopen (config_file, "rb");
   else
     {
-      config = open_config (egetenv ("HOME"), config_file);
+      char const *xdg = egetenv ("XDG_CONFIG_HOME");
+      config = open_config (egetenv ("HOME"), xdg, config_file);
 #ifdef WINDOWSNT
       if (!config)
-       config = open_config (egetenv ("APPDATA"), config_file);
+       config = open_config (egetenv ("APPDATA"), xdg, config_file);
 #endif
     }
 



reply via email to

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