Subject: Re: bug#646: emacsclient with no args to behave like -a

From: Jim Porter <[email-masked]>
Date: Fri, 27 Aug 2021 10:18:07 -0700

On 8/27/2021 7:50 AM, Lars Ingebrigtsen wrote:
> Jim Porter <[email-masked]> writes:
> 
>> "First, I recommend using the W32 package. W32 has hacked the
>> emacsclient in several useful ways. It will start Emacs if it isn't
>> already running, it will call "raise-frame" on the Emacs window when
>> started, and it permits starting emacsclient without a filename. "[1]
> 
> I think that's how emacsclient works these days -- if you set
> ALTERNATE_EDITOR to the empty string.  (It starts a new daemon Emacs and
> then connects to it.)

I tested this on Emacs 28.0.50, and a filename is still required. 
Otherwise emacsclient errors out as before.

[As an aside: the main difference that I see is that with 
ALTERNATE_EDITOR=emacs, `emacsclient file.txt' opens emacs directly (so 
there's no emacsclient process hanging around, only emacs). With 
ALTERNATE_EDITOR as the empty string, `emacsclient file.txt' starts a 
daemon Emacs (so there are emacsclient and `emacs --daemon' processes 
running).]

That said, you can call `emacsclient -c' to create a new Emacs frame. 
That works if you wanted to make a desktop shortcut to do something 
similar to the Emacs+EmacsW32 patched version of emacsclient, but that 
means it'll always open a new frame, even if you pass it some files. 
That's not necessarily the behavior people want.

No-args support in emacsclient could be nice for scripting or for things 
like the etc/emacsclient.desktop shortcut. Currently that uses a 
conditional to decide what to call based on whether it was passed any 
files (reformatted here for clarity):

   if [ -n "$*" ]; then
     exec emacsclient --alternate-editor= --display="$DISPLAY" "$@";
   else
     exec emacsclient --alternate-editor= --create-frame;
   fi

Fixing this issue could simplify that to something like: `emacsclient 
--alternate-editor= %F'. However, since emacsclient.desktop handles this 
already (albeit with a somewhat complex incantation), maybe that's enough.