Subject: Re: bug#65902: 29.0.92; emacsclient-mail.desktop fails due to complicated escaping

From: Jim Porter <[email-masked]>
Date: Thu, 14 Sep 2023 12:16:17 -0700

On 9/14/2023 6:36 AM, Eli Zaretskii wrote:
>> From: [email-masked]
>> Date: Thu, 14 Sep 2023 11:03:44 +0000 (UTC)
>> Cc: Jim Porter <[email-masked]>, [email-masked],
>> 	[email-masked]
>>
>> The issue is not really with the desktop file.  It's a generic problem:
> 
> No, it isn't.  If it were, we'd have heard about it much sooner, and
> not because of the desktop files.

This actually *has* come up before, but in Org. "org-protocol.el" tries 
to solves a similar use case (use emacsclient to open an "org-protocol:" 
URL, which calls some Org-mode function). The code for this integration 
is quite complex though, and relies on advising 'server-visit-files' 
(see the code around 'org--protocol-detect-protocol-server' in 
lisp/org/org-protocol.el).

Overall, the Org solution works, though it's hacky, and hooks into 
things a bit too late, so Org has to do extra work to clean up the 
arguments it receives. For example, on MS-Windows[1], instead of seeing 
the original "org-protocol:/..." string that gets passed to emacsclient, 
Org sees something like "c:/WINDOWS/system32/org-protocol:/...". Org 
works around this problem, but it would be nice if there were a way to 
hook into things earlier before the input arguments had been munged.

There have been a few reports/complaints about how this works on the Org 
list in the past, too.

I'm not married to any particular implementation for this problem, but 
given how this has come up for multiple cases (admittedly both for 
handling URLs of some form), I think there's value in considering a 
common way to handle this that's more straightforward than shell 
scripting or org-protocol's advice hacks.

[1] This is also an example of how the problem isn't *just* with desktop 
files, since MS-Windows doesn't use those; instead, you have to set some 
registry keys. Otherwise, the problems are pretty similar to desktop 
files though.