Subject: Re: bug#57752: 28.1.91; emacsclient-mail.desktop doesn't work for me

From: Jim Porter <[email-masked]>
Date: Fri, 16 Sep 2022 12:33:05 -0700

On 9/16/2022 11:26 AM, Gregory Heytings wrote:
>> That would allow both of the following in .desktop files:
>>
>> emacsclient --function my-function-taking-one-url %u
>> emacsclient --function my-function-taking-many-urls %U
>>
> 
> Sure, and how would you use it say in shell scripts, in which these 
> %u/%U/%f/%F constructs do not exist?

That depends on the script. However, as an example, maybe you want a 
'browse' alias that you can use from the shell (or a shell script) like 
this:

   browse https://gnu.org https://fsf.org

You might define that alias one of these ways (assuming 'eww-browse-url' 
were enhanced to use 'command-line-args-left' like 'message-mailto'):

   alias browse='firefox'
   alias browse='emacs -f eww-browse-url'
   alias browse='emacsclient --funcall eww-browse-url'

>> '--setq' has the disadvantage that you'd need some way to prepend 
>> *each* URL/filename with it in the %U/%F cases.
>>
> 
> What about --setq args "(list %U)"?

That wouldn't work, since .desktop files forbid %-expansions inside 
quotes[1]. Even working around that, the expansion would look something 
like this:

   (list mailto:[email-masked] ...)

Since want each argument to be a string (and wrapping quotes around each 
element won't work for the same reason I previously mentioned), we'd 
probably want a different syntax than the above. I wouldn't expect that 
syntax to make a list of strings.

>> Adding '--function' to emacsclient also has the advantage that it's 
>> already available for emacs,
>>
> 
> No, emacs only has --funcall: call Emacs Lisp function FUNC with no 
> arguments.

Sorry, yes. I meant --funcall.

This would likely necessitate some changes to how emacsclient talks to 
the main emacs process though, since I believe positional arguments to 
emacsclient are currently always treated as file names to visit. For 
"emacsclient --funcall" to work like "emacs --funcall", emacsclient 
would have to let the main emacs process process at least some of the 
arguments in the same manner as command-line arguments to "emacs" (i.e. 
allow reading them via '(pop command-line-args-left)' or something similar).

(I also have an alternate strategy for addressing the original bug, 
which I'll describe in a separate message so that this subthread doesn't 
get too unwieldy.)

[1] 
https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s07.html