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 10:21:56 -0700

On 9/16/2022 9:42 AM, Gregory Heytings wrote:
>>> And why is the above easier / better than
>>>
>>> emacsclient --eval '(progn (fun1 arg1 arg2) (fun2 arg3))'
>>
>> Because, with this, you have to correctly format the arguments with 
>> appropriate quoting into a lisp program, rather than just passing them 
>> straight in.  If the arguments are input from something else, this is 
>> harder than it appears.  Bad quoting is a common source of bugs 
>> (things like SQL injection, for example).
>>
> 
> If that's the intended use case, IMO instead of adding two --function 
> and --function-arg arguments it would be much clearer to add a --setq 
> parameter:
> 
> emacsclient --setq arg1 ... --setq arg2 ... --setq arg3 ... --eval 
> '(progn (fun1 arg1 arg2) (fun2 arg3))'

I'm not convinced that '--function-arg' is necessary, but I do think 
that adding '--function' to emacsclient would be the best solution of 
the ones presented so far. 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

(Likewise for %f/%F, which expands to one/many file names.) '--setq' has 
the disadvantage that you'd need some way to prepend *each* URL/filename 
with it in the %U/%F cases.

The functions above would need to be able to consume command-line 
arguments (like 'message-mailto' does), but that's not a big deal. We 
could even add an 'apply-from-command-line' function that adapts any 
existing function to do this:

   emacsclient --function apply-from-command-line func arg1 arg2

'apply-from-command-line' could look at the arity of 'func' and consume 
the appropriate number of command-line arguments.

Adding '--function' to emacsclient also has the advantage that it's 
already available for emacs, so it's not really an all-new feature so 
much as it is just adding a new place you can use it from. The semantics 
of '--function' are already set, and should work just fine for the cases 
described in this bug.