From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id eDZpJLN8xmUGXwEA62LTzQ:P1 (envelope-from ) for ; Fri, 09 Feb 2024 20:27:47 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id eDZpJLN8xmUGXwEA62LTzQ (envelope-from ) for ; Fri, 09 Feb 2024 20:27:47 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=pinwblhG; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1707506867; h=from:from:sender:sender:reply-to: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:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=bo58dJWIAT1XdgL+H8EMd72drBrY1EfYAOnRR/lhCuU=; b=epRlP0NREd40SFZ9BY5q+eFV+IV8yD18poIxCNO44KZcaLoTDHeRu63TRHaAtafFfiNr1b YHHm1pNePNVLXaGOFxGpalzwcE83RpFOuKtY/IevC9ZiGUDwYHwn/jPPrXOXCyLyADFdn2 l/bW8tUPmY1uhLU/nIbrW2qYWHhEZuC1A15nt5BFMmjMbAI8ok/AEm3Wny+Y4gG6S3r09k 5WIr38cp8FXw/yZVgAWgP/NHWsPCLxCs/s/uaEWZR8zC1K3vR5brMdLrX1K8YY+m+J6OHT InHNRbvY+MA7/En52SkJxLKROqtZck0mVJpc1oUVq5TTM6osNf43yPjAnloFWg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=pinwblhG; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1707506867; a=rsa-sha256; cv=none; b=LzF0qU14F/DVn4xDMXmKTMs3JjuPNnWvYBRaQh3q2n7B4eLaTwHeiUrTc3i/OrFVg2hv3a uWXZ62HIp1rlt+gRubSn4Pr6gsNJWIuzsySA+YhpkqM+NJldodw1NLos4T6+VxHaEwJVyk N3mC5JNUOeqyx6PDyhJfUIPO9aj7jxi6FynGqV0UZc5jff7lYzLhC+TrgnHwQVMwaCnPCb LY+ek0AxEPyyQFFmYlDGHx8TlRj0CAepAOgddKpY2aSWCNZjUGr1iuY75O0zuOcqRY29js TgBK1qe8yYvsbCcVGHBWm9fdgCPfxoLTpi9YQM3S8J5E/fJeNNtOj+AQhGvi6w== 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 4C6763F836 for ; Fri, 9 Feb 2024 20:27:46 +0100 (CET) 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 From: Herman Rimm via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -5.67 X-Migadu-Queue-Id: 4C6763F836 X-Spam-Score: -5.67 X-Migadu-Scanner: mx11.migadu.com X-TUID: RbRYuRRmqpXh * 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 -- 2.41.0