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 8MxCCuCQ1mEHkAAAgWs5BA (envelope-from ) for ; Thu, 06 Jan 2022 07:49:04 +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 OIbMBuCQ1mFOBgEAauVa8A (envelope-from ) for ; Thu, 06 Jan 2022 07:49:04 +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 94CEA10186 for ; Thu, 6 Jan 2022 07:49:03 +0100 (CET) Received: from localhost ([::1]:44968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5Ma6-0000cG-Hm for larch@yhetil.org; Thu, 06 Jan 2022 01:49:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40986) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5MV5-0000NZ-P7 for guix-devel@gnu.org; Thu, 06 Jan 2022 01:43:56 -0500 Received: from [2a00:1450:4864:20::344] (port=46904 helo=mail-wm1-x344.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n5MV3-0002mT-U9 for guix-devel@gnu.org; Thu, 06 Jan 2022 01:43:51 -0500 Received: by mail-wm1-x344.google.com with SMTP id d198-20020a1c1dcf000000b0034569cdd2a2so644672wmd.5 for ; Wed, 05 Jan 2022 22:43:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=rBYMovi20focZs0RbCoUlR2C5Zi8fZZSD9+L5HhFqUs=; b=my31OvUjQR0NaIOiHHUvJkfKuzjKeuuWNnoS9VLVj2dVD7KHVGnYwlgCAAcYC8ZMaP +Viykuusjw5m/QmbeMH6pQBbOt69aEuHuxUKmGmxzQ5lxg/3vNx3h8PrgV4qI3vsWjjG k8k1azAXpyMp0/ISUBj8e9HfyfV8UMQvKi7drGk6/LhjyhuFiUVtTZnT/QnFSG+ZxyC8 25eloakWNLL3a0mVD2HlPC2g9hbTrn2TmNANCiP6I+QWvrbfz9ovyBaGKYfV8OKCvJqf K0hmAVzo4zFEX//mroU0elcPeeIKaepZiyKEwca/hmhYsZLC7nBWQk2GZOJTR0ltImy+ MDJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=rBYMovi20focZs0RbCoUlR2C5Zi8fZZSD9+L5HhFqUs=; b=ZN7K5w+H1cs6nOi5n3YY4xeRec2QSHxHyo+1FWkVAfidHAIHcspL6wiluxDyXSxwhS tfYJ3eYt9e6oH2ONPSYtEcKGZ2TennGnyiNomOqSuWysCEO2RPl7fdu/IScqrAJvOCs6 7/M3U0/b+NG3MGa41GP16vpcUEnhOkSBA0sZcsXRnRK4ZIqc8eL/RG1dalaVglhZkrNC rcy8zZU4yRFVQKyTRJzEkAEP4jJT4RhLBqNYT9dcfzvLkHc7oltxra4iRDzeyhWfOruw B1aWrEsOVfZzwzWhGOF262dY7FHhZv+ybW22lgv0+XuShBZu2YBH/UaeyQJOJDwU0DOI FgTA== X-Gm-Message-State: AOAM530Ap7g5fsWAa/XbNFXb4cGlyU06FrI1TqgKC1xlGS9JD9u8J5ZH f+i+8z4Wgc5btWna4p1ugfU= X-Google-Smtp-Source: ABdhPJzdF7HDXszpVJzup8AMUUbBYAE5aigtkdBcm1V/QEKLLkyqhAx5ZcAXofFERgRHmJrt0fsQbQ== X-Received: by 2002:a05:600c:3797:: with SMTP id o23mr5733909wmr.178.1641451428271; Wed, 05 Jan 2022 22:43:48 -0800 (PST) Received: from nijino.fritz.box (85-127-52-93.dsl.dynamic.surfer.at. [85.127.52.93]) by smtp.gmail.com with ESMTPSA id c9sm904545wml.12.2022.01.05.22.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jan 2022 22:43:47 -0800 (PST) Message-ID: <91c6c25534e422d893a3dd219633a2e7ff3f1a68.camel@gmail.com> Subject: Re: RFC: new syntax for inline patches From: Liliana Marie Prikler To: Jelle Licht , Ricardo Wurmus , guix-devel@gnu.org Date: Thu, 06 Jan 2022 07:43:46 +0100 In-Reply-To: <861r1lacdd.fsf@fsfe.org> References: <87ee5ne7z5.fsf@elephly.net> <9781ffb5ec81b2d7c58dd171239510e27eef3c79.camel@gmail.com> <861r1lacdd.fsf@fsfe.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::344 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::344; envelope-from=liliana.prikler@gmail.com; helo=mail-wm1-x344.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, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" 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=1641451743; 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=rBYMovi20focZs0RbCoUlR2C5Zi8fZZSD9+L5HhFqUs=; b=PWwqQug3xwksGhr5qPoAXLc/k7s7dpNNeMyVPb1kgwYTAyWgur3xaGRU1qHzzHmByqNBO5 d1cFH/A+X9e85s/2MkapuIW8M3bxWhl/U2EGZytNUi4r/CDE1zZGVsY9L6gt8kMD69ydxt LTI1vBFq6OCL7ShOy9JMli3Lf9awpZ9Owgg020kk0TRCRMDTXG3OT6wv2ILwiXTob8QI37 KAPCK2GwPK2Mvc2hLKXjAN4xoHAKlf4ZmIifFR1yBxPXl+Elsj1z56EhyVu0xrbpYpZkEn wvKcj1SWjR3Zi7uZFnoYoYc/0FGA1pGZwYwb4NZJmNqLdfKl0ytZQi4/TOPgyg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641451743; a=rsa-sha256; cv=none; b=HbJoIuBn6mGtu0s1yfQy79rv2Mmf5BE9oDznMww/35GkS0AXI8hbNEOPpf/hPPt21cXZtG 9J3HyHhn0Pk4BHKUxHTGUlL+KfrWNABlFivEndRlXsheudK5vOJzMFjg3v4RdTBlM5hr3S KegBZf4aHtP8xv3SMAksemqVRXS4D+bNrZkIH95ZhotRRjrzmhxAKpSR3xeH4NCcLDblmm /pQ18L2vVs8x1mL+eOoGvxA53jfRfsS2mR4Usp1cNGBemfVBYYCCGNqMpV3xazuUmG4+qu O0naRdt3EZxxiSnHDQeV4nB5ZZp2y3EX7uQAN/av7Kea5xPYdHxCPpnWokBXUg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=my31OvUj; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -4.30 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=my31OvUj; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 94CEA10186 X-Spam-Score: -4.30 X-Migadu-Scanner: scn1.migadu.com X-TUID: 1Dw1RRIU0hQt Hi, Am Donnerstag, dem 06.01.2022 um 02:20 +0100 schrieb Jelle Licht: > > > > > > > Here’s a colour sample for the new bikeshed: > > > > > >   (arguments > > >     (list > > >       #:patches > > >       #~(patch "the-file" > > >          ((line 10) > > >           (+ "I ONLY WANTED TO ADD THIS LINE")) > > >          ((line 3010) > > >           (- "maybe that’s better") > > >           (+ (string-append #$guix " is better")) > > >           (+ "but what do you think?"))))) > > Now this thing is again just as brittle as the patch it encodes and > > if I know something about context-less patches then it's that > > they're super not trustworthy. > > What do you mean here, with 'brittle' and 'trustworthy'? Is it the > fact that line numbers are hardcoded, compared to the substitute* > approach? What Ricardo is writing here as a colour sample is a context-less diff and if you've ever worked with those, then you'll know they apply exactly without context. So that line 10 is stuck there, it doesn't move with regards to whatever entity is interesting at line 10. The second hunk is better in that it needs a line to match and replace, but it throws an error if it doesn't find that at line 3010, even if it'd exist and 3020 or 2048. Now with substitute*s, you also need to account for wrong regexps, both matching too many and too few lines (including the notorious 0, that has sparked many a religious debate whether substitute* is safe actually), so you might call that an even tradeoff. However, substitute is still more flexible in what it does than the proposed patch objects. Particularly, even if we added context, which would trade away some of the nice look of it, we now have to go into and manually regenerate our broken patches rather than using existing merge tools with our plain old file patches. > > However, have you considered that something similar has been lying > > around in our codebase all this time and 99% of the packages ignore > > it because it's so obscure and well hidden?  Why yes, of course I'm > > talking about emacs-batch-edit-file. > > > > Now of course there are some problems when it comes to invoking > > Emacs inside Guix build.  For one, not every package has emacs- > > minimal available at build time and honestly, that's a shame.  Even > > then, you'd have to dance around and add emacs-utils to enable it.  > > And after that? You code Emacs Lisp in the middle of Guile code!  > > Now certainly, this UI can be improved. > > > Particularly, I'd propose a set of monadic functions that operate > > on a buffer in much the same way Emacs does.  Now we wouldn't need > > to implement all of Emacs in that way (though we certainly could if > > given enough time). > > > > Basic primitives would be the following to name a few: search- > > forward, re-search-forward, goto-char, forward-line, point-min, > > insert, beginning-of-line, end-of-line, delete-region, point.  Of > > course we could rename them to be more guily, but that's a minor > > concern imo. Notice how I omitted find-file and save-buffer, > > because that should be taken care of by the monad. > > I'd prefer something that is declarative in the sense that the 'how' > is abstracted away, with a focus on the 'what'; both Ricardo's > proposal and emacs-batch-edit-file do this, and to a much lesser > extent the current substitute* mess. 'Navigation primitives' as you > propose here are perhaps abstract in the technical sense of the > phrase, but still indicate to me a focus on the 'how' instead of the > 'what'. I don't think you understood me correctly there. The monadic procedures I propose would implement a subset of Emacs' buffer operations – we can bikeshed about what set of Emacs, so that the set lets you focus on the 'how' instead of the 'what' – only inside Scheme and inside some well-known (guix build) module. Consider the translation of e.g.  (emacs-batch-edit-file "foo.org" '(progn (goto-char (point-max)) (insert "More content.") (basic-save-buffer))) to (with-buffer "foo.org" (goto-char (point-max)) (insert "More content.")) which would roughly equate to (run-with-buffer (open-buffer "foo.org") (lambda (buffer-monad) (return [something magical going on here]))) where run-with-buffer would do an atomic file replacement which temporarily creates a buffer monad for the translation from in to out. > Another nice property of keeping these concerns separated is that it > should be easy (or at least possible) to later reimplement > e.g. Ricardo's proposal on top of such monadic primitives.  Doing it > the other way around seems much less fun, if even feasible at all :- > ). I haven't heard about diff being Turing-complete while Emacs demonstrably is, so buffer monads would be somewhere in between. > > WDYT, should we pursue that?  Or should we just add an Emacs to our > > native inputs?  :P > > At the risk of escalating this perhaps-not-totally-serious proposal, > I wrote some snippets that should allow one to write elisp in > g-expressions using guile's built-in elisp reader + some hacks to > serialize guile's internal representation of parsed elisp to valid > elisp again. I don't think we would need to use G-expressions here, because we would have to quote or quasi-quote the batch-edit-file expression anyway and if we do the latter, we can insert store references using the usual set of primitives that you'd expect inside a build phase, e.g. search- input-file. However, that's still a cool thing. Cheers