From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id uIcHLEg5AWIJfAAAgWs5BA (envelope-from ) for ; Mon, 07 Feb 2022 16:22:48 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id AEeoJEg5AWJYSQAAG6o9tA (envelope-from ) for ; Mon, 07 Feb 2022 16:22:48 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4E34714432 for ; Mon, 7 Feb 2022 16:22:48 +0100 (CET) Received: from localhost ([::1]:42098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH5qo-0004hW-HG for larch@yhetil.org; Mon, 07 Feb 2022 10:22:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH5SG-0000Ev-BI for emacs-orgmode@gnu.org; Mon, 07 Feb 2022 09:57:25 -0500 Received: from ciao.gmane.io ([116.202.254.214]:55554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH5SE-0003cZ-Br for emacs-orgmode@gnu.org; Mon, 07 Feb 2022 09:57:24 -0500 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1nH5S8-00019Y-2f for emacs-orgmode@gnu.org; Mon, 07 Feb 2022 15:57:16 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Max Nikulin Subject: Re: Lazy load of org-protocol Date: Mon, 7 Feb 2022 21:57:09 +0700 Message-ID: References: <9b140f0a-c75e-cf00-0f83-67e5a660935c@gmail.com> <62519b3f-d1fa-4497-e32f-2a0960c4d1fe@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-US In-Reply-To: <62519b3f-d1fa-4497-e32f-2a0960c4d1fe@gmail.com> Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 28 X-Spam_score: 2.8 X-Spam_bar: ++ X-Spam_report: (2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NICE_REPLY_A=-0.001, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1644247368; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dnXMDWTRsNn+m2t0BvMWUSZFq4VzpTtojE/cbeaEumM=; b=NZIAy2eGMH/fx5lq3ze1aULDRSNwBjSAIUk7sr4yrVRtQYYqIVqkFIQSY9Ga9B+KASS1qG 8xfJ4UFGRr4P8kr8tgJtIB7Hw5UV+nBLEb1W600dcDiqQG3ji1zFFxuZZMAS+NQ7Lv2XnK 1aMAy98m1epL5bCJ/rwPFyqR2YQgPAFTdwiE/NlZ+/9u8CWpHeIhJVSFJPPVeH1unBSkS1 zpK0UVP2vQEN9gTI0GsbRxfA61SOUjW5/n45eqGJfIC3J0tMYFUHwukoUv53Qc0p6v0In0 5mF73djq9lABasrWN6hpNCFb5Fol+VNQHZgp+lOR4YYznBrS18oNZmLit29rhw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644247368; a=rsa-sha256; cv=none; b=YCEre683PpoJUQSJBixtWljkPh9gVMEGLDrjhXheG1OIKPDkcjXw6VGyfhThjLsP5mo4bN x4iWDAmgoJdiO0myauXAfRIpbg/Je7BTNHL24SghhB68VPDjSmz7CA3nvBa3SWdAWvt1Np FG+D2RUR4ZFCufe023NFA70Myx6Qv/AKHvogiHjmY0rWh40spv8ovZy8gD8a8u3hNnSr3h 3WQNOBK5N1QwDn24z9A1oCyRUqgKY3wZyCq5aFhXTqLx+a9r7CH0QvfeKBQvNN0ivZrfY/ sej1wBEICs1hQ1JW4w+sLe8TygzpBZPM5FUeWTFltnceCvQvNB2AlMcXSK6DJg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.03 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 4E34714432 X-Spam-Score: -3.03 X-Migadu-Scanner: scn0.migadu.com X-TUID: UDIV2jjlQ36o On 06/02/2022 09:40, Tianshu Wang wrote: > > (defadvice server-execute (before enable-org-protocol activate) > (unless (featurep 'org-protocol) (require 'org-protocol))) Thank you, such approach, unlike mine example, does not have code duplication. On the other hand it loads org-protocol on any remote command, not only for "files" representing org-protocol URIs. Maybe defadvice in org-protocol.el should be changed by newer advice-add with a function containing body of the old advice. On 07/02/2022 02:40, Jim Porter wrote: > On 2/6/2022 8:42 AM, Max Nikulin wrote: >> On 06/02/2022 01:27, Jim Porter wrote: > >> I think, the solution is to add -arg command to emacs server protocol >> that pushes its argument to a list and extend -exec command that would >> make such list available as argv or as `command-line-args-left' for >> evaluated expression. Of course, emacsclient option parser should be >> modified as well to support --arg option >>       emacsclient --eval '(func)' --arg 1 2 3 >>       emacsclient --eval '(func)' --arg -- 1 2 3 >> and maybe even for multiple eval+arg pairs >>       emacsclient --eval '(f1)' --arg 'a1' --eval '(f2)' --arg 'a2' 'a3' > > I think something like this could work, so long as the arguments can be > forwarded correctly in the alternate editor case. If I understand how > emacsclient handles --eval, I think that might work, but it would still > require writing Lisp functions that know how to handle argv or > `command-line-args-left'. I'm also not totally sure how safe/sensible > that is when the arguments aren't from the invocation of emacs itself, > but from emacsclient (and thus, the args could be updated multiple times > throughout a session). It probably wouldn't actually break anything, but > it does seem a bit surprising to me... Of course, I mean let-bind of `argv' and `command-line-args-left' just for processing of the passed expression, not setq that would change them globally. > Maybe another option would be to add an --apply argument that really > *does* consume the other command-line args and turns them into a > properly-quoted function call. Roughly speaking, it would turn this: > >   emacs --apply func foo bar baz > > into this: > >   (apply #'func '(foo bar baz)) You have almost managed to sell this idea to me. However even --apply is just sugar for emacsclient --eval "(apply #'func command-line-args-left)" --arg 1 2 So it is --apply option that may require to write a dedicated function if --arg is not implemented. Another limitation of --apply is that the function must accept string arguments only, no lists or even integers or boolean. > This would work effectively like how I momentarily thought --funcall > works. Then you could say: > >   emacsclient --apply org-protocol-capture %u >   # or ... >   emacs --apply org-protocol-capture %u Just because of there were a couple of recent threads related to calling conventions for subprotocol handlers, it is better to provide a bit more "real" example emacsclient --eval '(org-protocol-check-filename-for-protocol (pop command-line-args-left) nil nil)' --args %u