From patchwork Fri Feb 9 19:25:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Herman Rimm X-Patchwork-Id: 59969 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3819D27BBEB; Fri, 9 Feb 2024 19:27:47 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 5DC3027BBE2 for ; Fri, 9 Feb 2024 19:27:46 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYWWU-0002Wg-1V; Fri, 09 Feb 2024 14:26:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rYWWS-0002V8-8k for guix-patches@gnu.org; Fri, 09 Feb 2024 14:26:52 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rYWWS-0000ij-03; Fri, 09 Feb 2024 14:26:52 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rYWWd-0001bL-3A; Fri, 09 Feb 2024 14:27:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68935] [PATCH v2 3/6] utils: Add insert-expression procedure. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Fri, 09 Feb 2024 19:27:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68935 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68935@debbugs.gnu.org Cc: ludo@gnu.org, Herman Rimm , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 68935-submit@debbugs.gnu.org id=B68935.17075068076068 (code B ref 68935); Fri, 09 Feb 2024 19:27:03 +0000 Received: (at 68935) by debbugs.gnu.org; 9 Feb 2024 19:26:47 +0000 Received: from localhost ([127.0.0.1]:60232 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rYWWM-0001Zl-Pt for submit@debbugs.gnu.org; Fri, 09 Feb 2024 14:26:47 -0500 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117]:51759 helo=email.rimm.ee) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rYWWH-0001YI-Fs for 68935@debbugs.gnu.org; Fri, 09 Feb 2024 14:26:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1707506773; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bo58dJWIAT1XdgL+H8EMd72drBrY1EfYAOnRR/lhCuU=; b=pinwblhG0M0VHFJFL2PWPK88ZiZ8pxd5FE+SNgQUHj8L5WuIcQ4/isv57x11bCVAYZxK1s cGWJ66MoOIuSwDQQxhuJoIURoDeAmxKLSqCZOtGCWIATGY6MGBeIrhQJDUsROfSoMAjbQS dc3r0SmQ5fWhm16yYEefP2lpNZIZAz59XdL+JVN+vMMMInhZWAsFwKo66rHym6/eSwmPY/ FmebuPiTNtomIdshVnnalvzGuIlBfsIiOk0q76ZRyHXS1XZj5EmOt6sjhHNKffFpdq+cYx 916fTy3412vpgLoEBQapzm7N4U/zwj+64Odk4doHftK5dx/lvyhSak8/U3mTUA== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id 1eb830c3 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Fri, 9 Feb 2024 19:26:13 +0000 (UTC) Date: Fri, 9 Feb 2024 20:25:15 +0100 Message-ID: <69ff85b93e8a7f9095412429c213a2e10e9b0e6d.1707505804.git.herman@rimm.ee> X-Mailer: git-send-email 2.41.0 In-Reply-To: <3c0da641938e96a9f0c491abb74b30c75634df9a.1707505804.git.herman@rimm.ee> References: <3c0da641938e96a9f0c491abb74b30c75634df9a.1707505804.git.herman@rimm.ee> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Herman Rimm X-ACL-Warn: , Herman Rimm via Guix-patches X-Patchwork-Original-From: Herman Rimm via Guix-patches via From: Herman Rimm Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/utils.scm (define-module): Use (guix read-print) and export (insert-expression). (insert-expression): Add procedure. * tests/utils.scm ("insert-expression"): Add test. Change-Id: I971a43a78aa6ecaaef33c1a7a0db4b287eb85036 --- guix/utils.scm | 11 +++++++++++ tests/utils.scm | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/guix/utils.scm b/guix/utils.scm index e4e9d922e7..8f0bc2399e 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -20,6 +20,7 @@ ;;; Copyright © 2023 Janneke Nieuwenhuizen ;;; Copyright © 2023 Zheng Junjie <873216071@qq.com> ;;; Copyright © 2023 Foundation Devices, Inc. +;;; Copyright © 2024 Herman Rimm ;;; ;;; This file is part of GNU Guix. ;;; @@ -38,6 +39,7 @@ (define-module (guix utils) #:use-module (guix config) + #:use-module (guix read-print) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) @@ -145,6 +147,7 @@ (define-module (guix utils) go-to-location edit-expression delete-expression + insert-expression filtered-port decompressed-port @@ -502,6 +505,14 @@ (define (delete-expression source-properties) "Delete the expression specified by SOURCE-PROPERTIES." (edit-expression source-properties (const "") #:include-trailing-newline? #t)) +(define (insert-expression source-properties expr) + "Insert EXPR before the top-level expression specified by +SOURCE-PROPERTIES." + (let* ((expr (object->string* expr 0)) + (insert (lambda (str) + (string-append expr "\n\n" str)))) + (edit-expression source-properties insert))) + ;;; ;;; Keyword arguments. diff --git a/tests/utils.scm b/tests/utils.scm index 5664165c85..cd54112846 100644 --- a/tests/utils.scm +++ b/tests/utils.scm @@ -5,6 +5,7 @@ ;;; Copyright © 2021 Simon Tournier ;;; Copyright © 2021 Maxime Devos ;;; Copyright © 2023 Foundation Devices, Inc. +;;; Copyright © 2024 Herman Rimm ;;; ;;; This file is part of GNU Guix. ;;; @@ -274,6 +275,19 @@ (define (test-compression/decompression method run?) string-reverse) (call-with-input-file temp-file get-string-all))) +(test-equal "insert-expression" + "(define-public package-1\n 'package)\n +(define-public package-2\n 'package)\n" + (begin + (call-with-output-file temp-file + (lambda (port) + (display "(define-public package-2\n 'package)\n" port))) + (insert-expression `((filename . ,temp-file) + (line . 0) + (column . 0)) + `(define-public package-1 'package)) + (call-with-input-file temp-file get-string-all))) + (test-equal "string-distance" '(0 1 1 5 5) (list