From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 6BEBN+PB/mE+OgEAgWs5BA (envelope-from ) for ; Sat, 05 Feb 2022 19:28:51 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id AI7UM+PB/mEGCQAAauVa8A (envelope-from ) for ; Sat, 05 Feb 2022 19:28:51 +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 8DC572CA63 for ; Sat, 5 Feb 2022 19:28:51 +0100 (CET) Received: from localhost ([::1]:52070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGPnm-0004PX-M6 for larch@yhetil.org; Sat, 05 Feb 2022 13:28:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGPmW-0004PL-Ih for emacs-orgmode@gnu.org; Sat, 05 Feb 2022 13:27:32 -0500 Received: from [2607:f8b0:4864:20::102b] (port=52003 helo=mail-pj1-x102b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nGPmU-0004v6-FH for emacs-orgmode@gnu.org; Sat, 05 Feb 2022 13:27:32 -0500 Received: by mail-pj1-x102b.google.com with SMTP id y9so1225810pjf.1 for ; Sat, 05 Feb 2022 10:27:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=reK7lze0cbBWvyL1QgahPuSbIk/4Sg+iY3L8TLiUn9c=; b=fPf107nvrcFGu2tPkKNVX7ww/dEuUcM1r0BSKrmbb2/Hdb9Fn/2h9X5Jx0SZNpOa/c 2k8CnszJ0eJolbuNNgw4JCBZWySavRTn39GvjhX79pq0ic3tBZIEJNbXdBjuwgUDOL1o VIiMt9gXLMTconZVxsFsRi0gl37LlryzDJnlUZVVi315f5KiCP8700JHaRawwxNT5Rql ABFNh5a7ji5uA7nMxw7YzI96YvMMQjoYJXwL9M19L8WIYhrZ1OYz2vQ/mymawgSZ14np xdRfCChS3ZCH+N5+L0JGHkinQkMnkXvYfx5OSHg9hZmiz/qeIIvlMbB/ZdMPura3cJZ9 WOgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=reK7lze0cbBWvyL1QgahPuSbIk/4Sg+iY3L8TLiUn9c=; b=TvcX6YpQpywy2OO5CTBqz94klBxveCA/fBWl/IthEFEpfWXqS/9Ba9Jck9B1+J4FDB INrkX2Ps1Kmu76Bm7FF04lofa3X1IbU4jH0BjdATfVmMRN7UVDiMsXxUxDHde2OH4/m9 4L7KxDLtnTN7WGWhrRRpEFpCP77DtKyfLkM971eWqLbcifFm/81w+HlQxFL7+vs2MA0m miv77fH/jDMsVUhmUgL7MrkZLaf8oFZZxv4qZ18X5/yr8WaUGp9h6Re988JyCequHhor ngh0EK89PKUlJTXDMJZkUTxLOdYan4KkizIWVjcUou6eHnHPbZ8fEvVTNw/E5fgIsopX J3Pg== X-Gm-Message-State: AOAM531iviFZxE4YFw7gggmJPKPCG+r+8eb7ELcS1DZUbJxlfK3XgCoB gPtnXhtVZWuMCU7DM5N3jNVmbJG6TWAbIQ== X-Google-Smtp-Source: ABdhPJyRttBLIWnthOIvjmeeInG0DSXwK/SDbia65/UAO6l2IOxPy0HZ9FQv5oR0ipaWiSkoWspaOw== X-Received: by 2002:a17:903:32c3:: with SMTP id i3mr9042110plr.136.1644085648831; Sat, 05 Feb 2022 10:27:28 -0800 (PST) Received: from [192.168.1.2] (cpe-76-168-148-233.socal.res.rr.com. [76.168.148.233]) by smtp.googlemail.com with ESMTPSA id q8sm7196259pfl.143.2022.02.05.10.27.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 05 Feb 2022 10:27:28 -0800 (PST) Subject: Re: Lazy load of org-protocol To: Max Nikulin , emacs-orgmode@gnu.org References: From: Jim Porter Message-ID: <9b140f0a-c75e-cf00-0f83-67e5a660935c@gmail.com> Date: Sat, 5 Feb 2022 10:27:27 -0800 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::102b (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=jporterbugs@gmail.com; helo=mail-pj1-x102b.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, 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=1644085731; 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:dkim-signature; bh=reK7lze0cbBWvyL1QgahPuSbIk/4Sg+iY3L8TLiUn9c=; b=I3dTVvkyyk+SGDaksklBocIyo/24SORb+wpprHcz9hQzHJzG3+iSg0GgqRqzZ+MVxONMiT gmcaWYMxXNWP+3xBQ6XEZRfyi22GnUUgnlNvkjp9qRwtBMzX55OY7aSif5ex1VpbgqePFD m3h8A9EHGeBEn/Kbqm3jPE3zTvxPOueqjGqX0N+UqFVH3KNwV6nsub/orKQLuaPOcfN3JJ yMsVAaw7Qn+JBsIivgMxDiR9Xrelyj9x539o3W1LGwNmG+iJCEK954Rxl2eru7xE+twRPN iTfrbQ/3Z0xIA8L0Ag4UN2+5DBlIUb2EXiW6fsgwTtmhu0YkiUXtTApRMozCnQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644085731; a=rsa-sha256; cv=none; b=Kp9fBOwUqbIy4AXGMA362qzn1MSMMF2fnDaaqdqc1o5atLY4uXR6IHTM5SnI8sLIoYxrax 9DBS666+pIZiogQ7Y0DFUtsUXd7Ehly+sHeXAmj3E8/vkT/nc8LB7SGDIQ8Cj0indeEbTf NoWdpPwFWHiKBiuxlioXZ6g8TC1KewcrRcqLxOzNnt+xKMRGkDOfHt37xle5H2Ef3fRRof G0ZJe5mVqc9IXdHOLdluruYPyySFcfpp58uXepXF7ikN9NgXOHOM2fRKHaxEAsMYtHxIJH e75QmQW1VPfswOcTIzQUH9sqDdfH0rdDyB55mKGoCeNeuFGuGJk+loLx/7Dz/g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fPf107nv; dmarc=pass (policy=none) header.from=gmail.com; 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: -4.33 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fPf107nv; dmarc=pass (policy=none) header.from=gmail.com; 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: 8DC572CA63 X-Spam-Score: -4.33 X-Migadu-Scanner: scn1.migadu.com X-TUID: sxM3fbNZScyc On 2/5/2022 3:54 AM, Max Nikulin wrote: > I would prefer to avoid >    (require 'org-protocol) > in emacs init file and to postpone loading till invocation of > emacsclient with org-protocol URI. > > The problem is a hack in org-protocol. URIs are actually treated as > (relative) file names and magic is achieved in an advice for > `server-visit-files' function. So the advice must be installed in advance. > > My first idea was to avoid such magic and to create autoload function > org-protocol-from-argv with body similar to that advice. If it were > possible to get arguments from `command-line-args-left' then invocation > would look like > >    emacsclient --eval '(org-protocol-from-argv)' > 'org-protocol:/store-link?url=u1&title=t1' > > Unfortunately it is against design of emacs server protocol. If --eval > option is given than everything other is considered as independent > expressions. At the lower level there is no way to transfer `argv` as a > list from client to server process. I've thought a bit about how to improve this too. One further issue with the current implementation is that when emacsclient invokes the alternate editor (usually to start the "main" emacs instance), org-protocol: links no longer work correctly. That's because only the emacsclient itself (through `server-visit-files') knows what to do with them. I think the problem really starts in emacsclient's command line handling. You can see this in other situations too. For example, Emacs can be configured as your system's mailto: URL handler. (The file etc/emacsclient-mail.desktop in the Emacs repo does this.) The command to use for a new Emacs instance is simple: emacs -f message-mailto %u However, doing this for emacsclient is harder: emacsclient --alternate-editor= --create-frame --eval "(message-mailto \\"%u\\")" There's no problem with "--alternate-editor=" and "--create-frame", but the fact that emacsclient requires evaling the function call that way is: if %u holds a string with quotation marks, this will break, and worse, could even result in arbitrary code being executed. (In practice, this is probably rare, since URLs are generally URL-encoded, and so don't have literal quotes in them.) As a result, I think a good first step might be to add support for "--funcall" to emacsclient, just like the regular emacs binary. (The "-f" shorthand won't work though, since emacsclient already uses that for "--server-file"). This would simplify the `message-mailto' case above and would also allow org-protocol to do something similar: emacsclient --funcall org-protocol-capture %u Then, so long as `org-protocol-capture' has an autoload, this would Just Work, and org-protocol.el would be lazily loaded. Hopefully, this could also be forwarded onto the alternate editor so that when the user open an org-protocol: URL when Emacs is closed, it still handles the URL correctly. That said, in the short term, you could try out something like: emacsclient --eval "(org-protocol-capture \\"%u\\")" Of course, that has the quoting issues I mentioned above, but it could be helpful for developing a proof of concept. - Jim