From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: Better way to require with shorthands/renamed symbols Date: Mon, 27 Sep 2021 13:24:41 +0100 Message-ID: <8735pqryt2.fsf@gmail.com> References: <20210927003203.15806.29864@vcs0.savannah.gnu.org> <20210927003205.EF26620A5E@vcs0.savannah.gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22449"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Adam Porter , emacs-devel@gnu.org To: Stefan Kangas Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Sep 27 14:26:47 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mUpiZ-0005gp-0u for ged-emacs-devel@m.gmane-mx.org; Mon, 27 Sep 2021 14:26:47 +0200 Original-Received: from localhost ([::1]:57376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUpiX-00052b-P3 for ged-emacs-devel@m.gmane-mx.org; Mon, 27 Sep 2021 08:26:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33020) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUpgb-0003mo-Ki for emacs-devel@gnu.org; Mon, 27 Sep 2021 08:24:45 -0400 Original-Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:40903) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mUpgZ-0008Aq-PB for emacs-devel@gnu.org; Mon, 27 Sep 2021 08:24:45 -0400 Original-Received: by mail-wr1-x42e.google.com with SMTP id s21so11592716wra.7 for ; Mon, 27 Sep 2021 05:24:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=hnDPCcaewmYzA+vCyXEgVmwg/8/WbW4IXJseC/LFBlM=; b=bbiNC7EZpHXJZ2GIosJvc3AU82XukAiLdlrXcSnLbRHIRtsW1C/nVogo02Q4BJM9+a KRConBMUvxjCbipfchdFNfgkWMl72w+wwjwr7ttZBbFdDr19Ely0+WhR0dKDbA9AfqOa G3VttR6gWY6qCvS18vebdZkxPXJxQRnQ4HqC7brpvzH1c4BYnvcw7OLFgz2WbnFZCXoQ F+fOfgvjWJ9q7CiY1d+3xrkQrZsJqkUPpjWTQBzsDZzEQphCP0xiXWfFZKxB8y6Ftc+J sU7SnbNt3beS1Zk8BspLdjxr66J+daEwxF54z7lokpI4NONRCSnm2SfCdqVK8746geRe 4YUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=hnDPCcaewmYzA+vCyXEgVmwg/8/WbW4IXJseC/LFBlM=; b=6vVCptrHDiJOmCjHOL0Utw7AFg86kdko3ndjD6TCrDt3hfPuSFW+kngA0POFVA1nEi 1DHloKR2QvLbV7bGnHw9Lynxs4upQvZO6hECkBHhZPPAvDYIfzVDaB+1/SOFYZkPNt/u 3LgqKDBD7cN/zW5LV9gASTF7OR91ixAqUaYU+VGF1rS41GMFkmyOOlCqh3yrcTQkx2m5 iP0pW88+qRmFoe/Ivi1CrKthbazrko50oUeDyDbbXYdrw9tHjhFqztBWrTz7WHVtbt6C Wdx+G2h0uqA6mdFcrPMoUH/fK6uZ1FT1VkPexASTq1xBmm5BdmzRI455iZZD+0AX/sh5 Cbzw== X-Gm-Message-State: AOAM530ZHVgZWjikgkwXb1pGh5jl1ye6DlMRmYrYM0EIQ0Y2s1iNhwnh 32SUHfWr5eWsFaOY8j3wWxU= X-Google-Smtp-Source: ABdhPJy0+Bj5x25BvRUCnZTDDvfCW9sSiDyIucRhqebbgD4TaFAJ6su1U16yXQEHH6HA/CSUFUxSuw== X-Received: by 2002:a5d:46cb:: with SMTP id g11mr28278254wrs.60.1632745481991; Mon, 27 Sep 2021 05:24:41 -0700 (PDT) Original-Received: from krug ([62.48.174.238]) by smtp.gmail.com with ESMTPSA id q10sm16160751wmq.12.2021.09.27.05.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 05:24:41 -0700 (PDT) In-Reply-To: (Stefan Kangas's message of "Mon, 27 Sep 2021 04:10:49 -0700") Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=joaotavora@gmail.com; helo=mail-wr1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:275577 Archived-At: Stefan Kangas writes: > joaotavora@gmail.com (Jo=C3=A3o T=C3=A1vora) writes: > >> +(defun t-reverse-lines (s) (string-join (reverse (sns-lines s)) "\n") >> + >> +;; Local Variables: >> +;; elisp-shorthands: (("t-" . "my-tricks-") >> +;; ("sns-" . "some-nice-string-utils-")) >> +;; End: > > This is really nice and straight-forward, thanks! > > I see one problem here. It basically splits the require up in two: > I need to look both at the start and at the end of the file to > understand what is going on. > > In the previous discussion, Adam Porter suggested this:[1] > > (shorthand-require 'magnar-string :with "^s-" :as "magnar-string-") > > I like that proposal a lot, but it's a bit too verbose for my taste. > It also seems to flip the :as and :with from what I would expect (in > Python, "import x as y" means that x is available "as" y in this file). > > In my ideal world, we should be able to just say simply: > > (require 'magnar-string :as "s-") > I wrote before that something like is reasonable and sounds useful. But I was rash in that assessment. Or rather, it must be very clearly thought out. One should understand (or perhaps, as a programmer, one _must_ understand) that the Shorthands feature works at the Lisp reader level. It's tricky to think about the execution of that manifestation of the 'require' special and what it does at the Shorthands level. You're probably thinking of putting it on the top of your file, which is the most common case, but far from the only use. What if it happens at non-top level, in an IF form? What if it happen sat top level but in the middle of the file? It would amount to setting variables that influence the reader during the read process. Of course, that is exactly what Common Lisp's IN-PACKAGE does. But that comes with other challenges, prominent among which teaching tools like xref, ElDoc, describe-function and completions what the "current" shorthands are. You see, those tools are always finding symbols in the current buffer and they also need to know the value of 'elisp-shorthands' (soon to be renamed 'read-shorthands', hopefully). We'd need to update 'elisp-shorthands' whenever point moves perhaps? Or just-in-time before an 'intern-soft' is called. That is how SLY and SLIME do it. Maybe. At any rate, this is more work. Perhaps, when we arrive at that that point, we decide to put the effort and implement IN-PACKAGE, since it's so well understood (...but is it? Not by some, I fear, maybe that'll change). For now, I'd just like people to experiment with Shorthands. As Stefan Monnier once wrote (here?), implementing namespace systems isn't hard in itself (it wasn't here). It's making the tooling around it consistent. The latter was only possible with the Shorthands feature because of the relative dumbness of its approach. Jo=C3=A3o