From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id uKzoAlbwA2IsWgEAgWs5BA (envelope-from ) for ; Wed, 09 Feb 2022 17:48:22 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 6DMNO1XwA2L2egAAauVa8A (envelope-from ) for ; Wed, 09 Feb 2022 17:48:21 +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 80A30323A4 for ; Wed, 9 Feb 2022 17:48:21 +0100 (CET) Received: from localhost ([::1]:40568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHq8i-00044c-6C for larch@yhetil.org; Wed, 09 Feb 2022 11:48:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHq7K-00042A-88 for emacs-orgmode@gnu.org; Wed, 09 Feb 2022 11:46:54 -0500 Received: from ciao.gmane.io ([116.202.254.214]:34418) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHq7E-0001VO-J2 for emacs-orgmode@gnu.org; Wed, 09 Feb 2022 11:46:53 -0500 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1nHq70-0004Cm-5u for emacs-orgmode@gnu.org; Wed, 09 Feb 2022 17:46:34 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Max Nikulin Subject: Re: Lazy load of org-protocol Date: Wed, 9 Feb 2022 23:46:26 +0700 Message-ID: References: <9b140f0a-c75e-cf00-0f83-67e5a660935c@gmail.com> <62519b3f-d1fa-4497-e32f-2a0960c4d1fe@gmail.com> <450a25ba-e1f5-16db-c953-92fef0bfdc1a@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------Hy46iQb8tO0UOITDzUgEJx1F" 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: <450a25ba-e1f5-16db-c953-92fef0bfdc1a@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.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.248, 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=1644425301; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=brJBRbaFqnnOQLisRCTCak1WuV14aGlZ1tgUubrMA9Q=; b=Rn59s1XLs1S4oZ1HGBOpqcrn9Ugktcmr1MVmBIEewJtRhSU//X8S9jHlZ68kq4dAOXabYx iGniEUGWh7KuRGc4pQsdZ//D0G+cQaocs/xzUYw6B2cmnc1tA6E9NUKRX9a/9f2EHRhjUW UJtCfq+bpFalHQheZC2nin2siUuBincqwRzPCYPKDTok2OtSWdBs6E/+uNuWMw+O8cJPv8 V34rVZshaGu7S9rlsvzdaObTchb0rAMxya++eLWEy4rEzqrkRUIbGOU0ggi1ysN6JIqWIs +Um5fslDBx0tjj2k8ax9tmTd8vD58RNKhtG5V6H9dEvXjucMmcgTlxoHzJABBQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644425301; a=rsa-sha256; cv=none; b=YgL70YZfUHYwHCQpS9s/3TFivLo78ZtwPRH/PwMG0ZDDhpMKDglHrKLgo90SOWdcBFxZJP 6qutjFiWTAYazm1UpD7Os+iUQfGX7Tl+VnPQDbSn6bXiz0WdQmzEj6Iy5cB19BhymM0tC5 fjNhMKN1Si5dtqOEpze8w1ZNWWHRJQtMcSxyMH2XjKfb9tUA1z89IX7mcFUgx91bJEsBX9 vDf3xsM+MnUjy6NOBTCaeu2r9gymwkKHl9vKL9MgXUQGTGum+DadDBoM8lH7N1zqimCDRp 2rQDVr1aJ6Nu3pNLuNG2yAgTiSuIGpOgAyU7GPHvau/rZbPxygaqxMnSdK5yyw== 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: -1.43 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: 80A30323A4 X-Spam-Score: -1.43 X-Migadu-Scanner: scn1.migadu.com X-TUID: dOT11BGE+rFK This is a multi-part message in MIME format. --------------Hy46iQb8tO0UOITDzUgEJx1F Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 08/02/2022 17:44, Tianshu Wang wrote: > Max Nikulin writes: > >> 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. > > Yes, I replaced the original code with advice-add (not fully tested). Sorry, I was not clear enough. I meant a patch similar to the attached one. It is not tested for greedy subprotocols. It allows to check arguments to decide if it is necessary to load org-protocol: (defun org-protocol-lazy-load (args) (if (or (featurep 'org-protocol) (not (delq nil (mapcar (lambda (loc) ;; loc: (file-name . (line . column)) (string-match-p "\\(?:^\\|[/\\\\]\\)org-protocol:" (car loc))) (car args))))) args (require 'org-protocol) (org-protocol-detect-protocol-server args))) (server-start) (advice-add 'server-visit-files :filter-args #'org-protocol-lazy-load) On 08/02/2022 02:06, Jim Porter wrote: > On 2/7/2022 6:57 AM, Max Nikulin wrote: >>> 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. > > Yeah, `--arg' does have greater flexibility in that regard, but it comes > at the cost of verbosity and some slight behavioral differences with the > equivalent in the main emacs executable. For emacs itself, any elements > of `command-line-args-left' that aren't consumed by a function will get > opened as files, but I don't think that would be the case with > emacsclient. Does this difference matter? Probably not. However, > avoiding `command-line-args-left' just feels intuitively "cleaner" to > me. Still, I think `--arg' should work and be backwards-compatible, so I > don't mind it, even if I prefer the simplicity of `--apply'. It is not a problem to implement --apply in addition to --arg. It may just mean --eval '(apply-from-command-line-args-left)' emacs --batch -l apply-from-command-line-args-left.el \ --eval '(apply-from-command-line-args-left)' \ message 'test %S, %S' Hello 'World!' (defun apply-from-command-line-args-left () (let* ((name (car command-line-args-left)) (func (symbol-function (intern name)))) (if func (apply func (cdr command-line-args-left)) (error (format "Symbol's function definition is void: %s" name))))) OK, I forgot to set the variable to nil. > On a related note, there is still an issue with `--eval' in some cases. > It fails to work with emacsclient when invoking an alternate editor: > >   emacsclient --alternate-editor emacs --eval '(message "hi")' > > If Emacs isn't already running, that will open a new buffer named > '(message "hi")'. I think that's just a bug in how emacsclient handles > `--eval', though fixing it would make org-protocol links work more > reliably (if they used `--eval' as proposed, that is). emacsclient --alternate-editor '' --eval '(message "hi")' But it makes it harder to use it during debugging when -Q -L ~/src/org-mode/lisp options are required. --------------Hy46iQb8tO0UOITDzUgEJx1F Content-Type: text/x-patch; charset=UTF-8; name="0001-org-protocol.el-New-style-advice.patch" Content-Disposition: attachment; filename="0001-org-protocol.el-New-style-advice.patch" Content-Transfer-Encoding: base64 RnJvbSA4YTRmOGRiMjM5ZDAwNDUxM2JlMzUyNDllZDcxZTIyMjM4MWIwMTYyIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBNYXggTmlrdWxpbiA8bWFuaWt1bGluQGdtYWlsLmNv bT4KRGF0ZTogV2VkLCA5IEZlYiAyMDIyIDIzOjI1OjI4ICswNzAwClN1YmplY3Q6IFtQQVRD SF0gb3JnLXByb3RvY29sLmVs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cHJvdG9jb2wnLiIKLSAgKGxldCAoKGZsaXN0IChpZiBvcmctcHJv dG9jb2wtcmV2ZXJzZS1saXN0LW9mLWZpbGVzCi0gICAgICAgICAgICAgICAgICAgKHJldmVy c2UgIChhZC1nZXQtYXJnIDApKQotICAgICAgICAgICAgICAgICAoYWQtZ2V0LWFyZyAwKSkp Ci0gICAgICAgIChjbGllbnQgKGFkLWdldC1hcmcgMSkpKQorICAobGV0KiAoKGZpbGVzIChu dGggMCBhcmdzKSkKKyAgICAgICAgIChjbGllbnQgKG50aCAxIGFyZ3MpKQorICAgICAgICAg KGZsaXN0IChpZiBvcmctcHJvdG9jb2wtcmV2ZXJzZS1saXN0LW9mLWZpbGVzCisgICAgICAg ICAgICAgICAgICAgIChyZXZlcnNlIGZpbGVzKQorICAgICAgICAgICAgICAgICAgZmlsZXMp KSkKICAgICAoY2F0Y2ggJ2dyZWVkeQogICAgICAgKGRvbGlzdCAodmFyIGZsaXN0KQogCTs7 IGBcJyB0byBgLycgb24gd2luZG93cy4gIEZJWE1FOiBjb3VsZCB0aGlzIGJlIGRvbmUgYW55 IGJldHRlcj8KICAgICAgICAgKGxldCAoKGZuYW1lICAoZXhwYW5kLWZpbGUtbmFtZSAoY2Fy IHZhcikpKSkKICAgICAgICAgICAoc2V0cSBmbmFtZSAob3JnLXByb3RvY29sLWNoZWNrLWZp bGVuYW1lLWZvci1wcm90b2NvbAotCQkgICAgICAgZm5hbWUgKG1lbWJlciB2YXIgZmxpc3Qp ICBjbGllbnQpKQorCQkgICAgICAgZm5hbWUgKG1lbWJlciB2YXIgZmxpc3QpIGNsaWVudCkp CiAgICAgICAgICAgKGlmIChlcSBmbmFtZSB0KSA7OyBncmVlZHk/IFdlIG5lZWQgdGhlIHQg cmV0dXJuIHZhbHVlLgogICAgICAgICAgICAgICAocHJvZ24KLSAgICAgICAgICAgICAgICAo YWQtc2V0LWFyZyAwIG5pbCkKKyAgICAgICAgICAgICAgICAoc2V0Y2FyIGFyZ3MgbmlsKQog ICAgICAgICAgICAgICAgICh0aHJvdyAnZ3JlZWR5IHQpKQogICAgICAgICAgICAgKGlmIChz dHJpbmdwIGZuYW1lKSA7OyBwcm9iYWJseSBmaWxlbmFtZQogICAgICAgICAgICAgICAgIChz ZXRjYXIgdmFyIGZuYW1lKQotICAgICAgICAgICAgICAoYWQtc2V0LWFyZyAwIChkZWxxIHZh ciAoYWQtZ2V0LWFyZyAwKSkpKSkpKSkpKQorICAgICAgICAgICAgICAoc2V0Y2FyIGFyZ3Mg KGRlbHEgdmFyIGZpbGVzKSkpKSkpKSkKKyAgYXJncykKKworKGFkdmljZS1hZGQgJ3NlcnZl ci12aXNpdC1maWxlcyA6ZmlsdGVyLWFyZ3MgIydvcmctcHJvdG9jb2wtZGV0ZWN0LXByb3Rv Y29sLXNlcnZlcikKIAogOzs7IE9yZyBzcGVjaWZpYyBmdW5jdGlvbnM6CiAKLS0gCjIuMjUu MQoK --------------Hy46iQb8tO0UOITDzUgEJx1F--