Am 2024-10-10 13:39, schrieb Eli Zaretskii:

Date: Thu, 10 Oct 2024 08:56:43 +0200
From:  Jonas Großekathöfer via "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>

I want emacsclientw.exe to start up an emacs daemon with a custom --init-directory in case no server is
running. For that case, I think, I need to explicitly set the value for the "--alternate-editor"-flag to something
like:

-a "%UserProfile%\bin\emacs-29.3\bin\runemacs.exe --init-directory
%APPDATA%\Dotfiles\emacs\.emacs.d\"

Can you explain why you need a custom --init-directory in that case?
 
 
Quality of life improvement: I have my configs online in a git-repo. I manage the dotfiles on my Linux machine with stow. On my Windows machine I want Emacs to follow that structure. As such I want to link to the config via --init-directory, so that I can place the Dotfiles-Folder where ever I want. However, I can't place the Dotfiles folder so, that the ".emacs.d/"-folder ends up under the parent "~/" as well.
 
I already tried a route via tangling to different targets for Linux and Windows. But that introduced other problems... so I decided to follow this route. Seems the most straightforward to me actually. For the start I decided to place it under "~/" on Windows as well. As such I ended up with that specific location. But AFAICT my problem is location agnostic.
 
I am open to suggestions if I am missing the super obvious solution here. (:
 

However, doing so results in the following error: "file name or argument required". This is also true when
specifing a relative path (i.e. AppData\Dotfiles\emacs\.emacs.d\).

After some more trials with single and/or double qoutes (details see below), I got the impression that this
behavior is unlikely intentional. And I am somewhat confident, that more then one oy my many attempts
should've been successful. (Note that I raised this issue first here:
https://emacs.stackexchange.com/a/82355/30098)

For completeness, the full comand ("Target") I am trying to run is:

%UserProfile%\bin\emacs-29.3\bin\emacsclientw.exe -a '%UserProfile%\bin\emacs-29.3\bin\runemacs.exe -
-init-directory "AppData\Dotfiles\emacs\.emacs.d\"' -n -c --server-file
%APPDATA%\Dotfiles\emacs\.emacs.d\server\server

that command starts in

%UserProfile%

ATM, I have as a work around a shortcut to emacscleintw.exe without an -a flag. Before using it, I once have
to run:

%UserProfile%\bin\emacs-29.3\bin\runemacs.exe --daemon ----init-directory
%APPDATA%\Dotfiles\emacs\.emacs.d\

Obviously, I would rather have to have it all in one place.

And here are the Details, regarding the use of quotes with or without relative path for --init-directory:

For the several options using quotes, I got the following problems, depending on whether I put single or
double quoutes for the whole argument or just the path:

Double quotes around the argmument and single quotes for the path, using the full path:

-a "%UserProfile%\bin\emacs-29.3\bin\runemacs.exe --init-directory
'%APPDATA%\Dotfiles\emacs\.emacs.d\'"

--> Warning: "Warning (initialization): Unable to create `user-emacs-directory'
(c:/Users/gross20/'C:/Users/gross20/AppData/Roaming/Dotfiles/emacs/.emacs.d/'/)."

Single quotes around the argmument and double quotes for the path, using the full path:

-a '%UserProfile%\bin\emacs-29.3\bin\runemacs.exe --init-directory
"%APPDATA%\Dotfiles\emacs\.emacs.d\"'

--> Error: Try --help for more information

Double quotes around the argmument and single quotes for the path, using a relative path:

-a "%UserProfile%\bin\emacs-29.3\bin\runemacs.exe --init-directory
'AppData\Roaming\Dotfiles\emacs\.emacs.d\'"

--> Strarts without errors or warning, but the user-emacs-directory is
"c:/Users/XXX/'AppData/Roaming/Dotfiles/emacs/.emacs.d/'/" (Note the single quote in the folder name for
AppData)

Single quotes around the argmument and single quotes for the path, using a relative path:

-a '%UserProfile%\bin\emacs-29.3\bin\runemacs.exe --init-directory "AppData\Dotfiles\emacs\.emacs.d\"'

--> Error: Try --help for more information

Don't use single quotes, they are not supported by Windows.

But I admit I don't understand why you needed nested quotes at all.
What happens if you use double quotes around the entire argument of
the -a option?
 
Do you mean like how in the first example I gave?
 
-a "%UserProfile%\bin\emacs-29.3\bin\runemacs.exe --init-directory %AppData%\Dotfiles\emacs\.emacs.d\"
 
That one gives "file name or Argument required. Try --help"
 
Best
Jonas