Subject: Re: bug#41719: 28.0.50; [FR] emacsclient should provide '--name' option as emacs

From: Vladimir Lomov <[email-masked]>
Date: Sat, 6 Jun 2020 00:53:38 +0800

Hello,
** Basil L. Contovounesios <[email-masked]> [2020-06-05 12:14:11 +0100]:

> Vladimir Lomov <[email-masked]> writes:

>> The 'emacs' allows to set the so-called 'instance' when run in X window
>> system using '--name' option. The same time the 'emacsclient' doesn't
>> have such option and if 'emacs' is run in daemon mode ('emacs
>> --daemon=...') it is impossible (?) to change the 'instance' of emacs
>> window (frame in Emacs terminology) created by 'emacsclient'.
>>
>> I tried to use '-F' option of 'emacsclient' but I didn't get desire
>> result, WM_CLASS isn't changed, only WM_ICON_NAME. It is possible that I
>> do things wrong,
>>
>>   $ emacsclient -s /run/user/1000/emacs-default -F '((name . "default") (title . "USER@HOST"))'
>>
>> but this topic is covered by manual (Emacs, 21.11 "Frame Parameters" and
>> Emacs Lisp 29.4.3 "Window Frame Parameters") very unclear.
>>
>> Even if it is possible to change the 'instance' of Emacs window created
>> by 'emacsclient' using the '-F' option it would be nice to have more
>> simple way to achieve this. On the other hand, if Emacs is run in daemon
>> mode it is the purpose of emacsclient to (allow to) set the 'instance'
>> and 'title' of created window.

> Sorry if I misunderstood,

Yes, seems so.

> but are you looking for emacsclient's --socket-name=NAME argument?

From emacsclient(1)

-s, --socket-name=FILENAME
        use socket named FILENAME for communication.  This can also be
        specified via the EMACS_SOCKET_NAME environment variable.

> This can be the same NAME passed as the --daemon=NAME argument to emacs.

From emacs(1)

--daemon[=name], --bg-daemon[=name]
        Start Emacs as a daemon, enabling the Emacs server and disconnecting
        from the terminal. You can then use the emacsclient (see
        emacsclient(1)) command to connect to the server (with optional name).

So if I use

>>   $ emacsclient -s /run/user/1000/emacs-default -F '((name . "default") (title . "USER@HOST"))'

then I use socket it means I use '--daemon' for emacs. Indeed I use socket
activation provided by systemd.

From emacs(1)

--name=name
        Specify the name which should be assigned to the initial Emacs window.
        This controls looking up X resources as well as the window title.

-T name, --title=name
        Specify the title for the initial X window.

When Emacs is run by just running 'emacs' and querying X properties

$ xprop | grep 'WM_CLASS\|WM_NAME\|WM_ICON_NAME'

one gets

WM_CLASS(STRING) = "emacs", "Emacs"
WM_ICON_NAME(STRING) = "[email-masked]"
_NET_WM_ICON_NAME(UTF8_STRING) = "[email-masked]"
WM_NAME(STRING) = "[email-masked]"
_NET_WM_NAME(UTF8_STRING) = "[email-masked]"

While running Emacs by

$ emacs --name default --title USER@HOST

one gets

WM_CLASS(STRING) = "default", "Emacs"
WM_ICON_NAME(STRING) = "default"
_NET_WM_ICON_NAME(UTF8_STRING) = "USER@HOST"
WM_NAME(STRING) = "USER@HOST"
_NET_WM_NAME(UTF8_STRING) = "USER@HOST"

In other words, emacs has option to set instance name (first string of
WM_CLASS value) and set window title. On the other hand emacsclient doesn't
have such option so it is (seem) impossible to set 'instance'. I wonder why it
doesn't have such options.

I read Emacs and Emacs Lisp manuals about frame parameters but don't get if it
is possible to set instance (and possibly name) using frame parameters. I
tried to use -F option but don't get desired result.

---
Vladimir Lomov

-- 
Natural laws have no pity.