From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id kF9qLduFgGIvJQAAbAwnHQ (envelope-from ) for ; Sun, 15 May 2022 06:47:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id 4PliLNuFgGLmMAEAG6o9tA (envelope-from ) for ; Sun, 15 May 2022 06:47:23 +0200 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 23FE22B45A for ; Sun, 15 May 2022 06:47:23 +0200 (CEST) Received: from localhost ([::1]:47092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nq6A5-00029d-Uc for larch@yhetil.org; Sun, 15 May 2022 00:47:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nq69n-00028K-Kr for guix-patches@gnu.org; Sun, 15 May 2022 00:47:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:53967) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nq69n-0003b3-Bu for guix-patches@gnu.org; Sun, 15 May 2022 00:47:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nq69n-0002tP-B6 for guix-patches@gnu.org; Sun, 15 May 2022 00:47:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55424] [PATCH 004/602] utils: Add a 'delete-expression' procedure. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 15 May 2022 04:47:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55424 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55424@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 55424-submit@debbugs.gnu.org id=B55424.165259001711061 (code B ref 55424); Sun, 15 May 2022 04:47:03 +0000 Received: (at 55424) by debbugs.gnu.org; 15 May 2022 04:46:57 +0000 Received: from localhost ([127.0.0.1]:47857 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nq69g-0002sK-Vz for submit@debbugs.gnu.org; Sun, 15 May 2022 00:46:57 -0400 Received: from mail-qt1-f173.google.com ([209.85.160.173]:38524) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nq69f-0002re-0D for 55424@debbugs.gnu.org; Sun, 15 May 2022 00:46:55 -0400 Received: by mail-qt1-f173.google.com with SMTP id fu47so10075973qtb.5 for <55424@debbugs.gnu.org>; Sat, 14 May 2022 21:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0hSHUoXvsA3T1Phj1BQ2SDD7VKjgWbirW4feNufPc28=; b=XHL/Ynkeks9iEc1DB+vip/NjU3tYOX5naBUHwHr0bR977/9VyIEOsn7daFevjEri2b nQ3JU6dEDCH9R0P3FY0ptNwFe3Kfgz8dd/qpyUfRIxqre/y3ukgwUGUB6LEotWJkh+0Y bYxoT8wjzqyW3W9qHvJkeQRCJ3x0HFxHHBGwOWq72lRbS2IeSuo25pxv+QhG2MwfWwUG fvpgBABjPd1PNgZ+7yc3EfW6Apz4pj/c0xIlVoYa/UyEuLzUlpclfd7clN8sUnbTlOQE +CAftXeeT7NzFHJdiLjSMrjibe1MOTWi3mwR7+ffCmg4WYuSkYzMuBEAPldasKmkRg3T SOiw== 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:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0hSHUoXvsA3T1Phj1BQ2SDD7VKjgWbirW4feNufPc28=; b=oclg5St/tOHXYJzqihYiMWgNzfjBcKuk3Nk3pHFuPI+6W0b9Q1AGSvnvXvuaOCTc6a Y/ogHjgL9KFVSzaT1kaYGEa95eAbyc2/5I7fE5s5FDFgozgw7KaBw4ggNOYgMBdAPe+I l5XfzRBMk6DvGMWQxoz0MY4DC+LeY+z2VZ1YxZv+b+k1tMzhmC2uARqA0w/xtsgSgdSj vmwgY7Tj9o64Kf6nXC9x6eCWNheXl44gZ6S3B/CQblqH5lw2A+FdH+dfHBgV0r1j4TY1 YSHqzm32vDp/V6TyM2b3qh41AUfBuGoW5v3BNeL1Pu6+nJ3AS34/s2GIGqgXGrQAnXlS Vv3w== X-Gm-Message-State: AOAM530Ra8XtPQOikPWQ8vAYqmyNsFCivQvfxQbURMNFsAnnQi8zqvuN XWYFUONMbnZEiAspOQASzsmNGF6XULI8LQ== X-Google-Smtp-Source: ABdhPJww/Q2Ac4xWtzoH57XWgfTfl1mTZx8jeLZHCGwWw6IqiqN4HkIXp/zi+XY/QuhlYnumXicQpg== X-Received: by 2002:a05:622a:42:b0:2f3:dbbf:4508 with SMTP id y2-20020a05622a004200b002f3dbbf4508mr10966479qtw.206.1652590009303; Sat, 14 May 2022 21:46:49 -0700 (PDT) Received: from localhost.localdomain (dsl-149-239.b2b2c.ca. [66.158.149.239]) by smtp.gmail.com with ESMTPSA id 2-20020ac82082000000b002f39b99f672sm4287690qtd.12.2022.05.14.21.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 May 2022 21:46:49 -0700 (PDT) From: Maxim Cournoyer Date: Sun, 15 May 2022 00:36:31 -0400 Message-Id: <20220515044629.6843-4-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220515044629.6843-1-maxim.cournoyer@gmail.com> References: <20220515044629.6843-1-maxim.cournoyer@gmail.com> 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: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1652590043; h=from:from:sender:sender: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=5jMkTsdFIf1yLKqUDKp1SfH+qjf5U9HKEbw+QBXze6c=; b=mqEyrn9xcCO049F+lOhwEawrNZechzn+Ay9U3KX0OBPmKLNxB1H8UBUm8jnI8BdsP34Cj4 XVFBUK1EMWRG0OrHm0j/g5kjioHMqJ125EOfOI009ViiS8pbtnD/iGzG/qLREIDHYxiYcg B4xMnSwUGhsNPgxXkpfwUjwiqBewAupIMaf40nZ7jIiPtDttf/Z0w7ozDu7Ex3Bukt2FJN XXIgWlQnXZdT6wYPfWniSF9D4E1FdtDoLaQ7PkDSTyUPNwWEIm0Acs45ME1O3BXPlSWpmy uDi2EHIUukyaHzhZWmZRvXHo440Gjt/VHo8bYoAAhMTESPQ88hgDkkGo96XmwA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1652590043; a=rsa-sha256; cv=none; b=HWwpLTeNkfOvYJrblOI9BbHay2tOZlfEtJVvmITbylT9qAVrUdXoMrF1P15n48OLhGvJAA pSavjY2GCJCtWYtuQJvdQRX9/BS+auXnr0pON7KBY4JC2Lx35bXHgifkDgaNf5tg//W1yt SWuZ7qMSrKFqp0gY8jQD4cUE7itSO0syQHYXDF859QUV7+6asGYA3uqLJD6dTjuspnWhnF Tbed66QVFF+OBcI+thaqvYSHPh0KQphcbGhAMbuVytOZk21Ltrnt53ivHrkGpl+/oWpdYH hqpVLXLypH2/L7ErOBKnEqgcXzsB4zsQpll+udmmyPbkJ3z7wux2yErN4Qh2HQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b="XHL/Ynke"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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" X-Migadu-Spam-Score: 5.67 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b="XHL/Ynke"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); 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" X-Migadu-Queue-Id: 23FE22B45A X-Spam-Score: 5.67 X-Migadu-Scanner: scn0.migadu.com X-TUID: MiAaMiWBPv53 * guix/utils.scm: Fix copyright lines and order imports. (edit-expression): Fix typo in doc. Add a new 'include-trailing-newline?' keyword argument. Update doc. (delete-expression): New procedure. --- guix/utils.scm | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/guix/utils.scm b/guix/utils.scm index 44c46cb4a9..e169624ee6 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -8,12 +8,11 @@ ;;; Copyright © 2017 Mathieu Othacehe ;;; Copyright © 2018, 2020 Marius Bakke ;;; Copyright © 2020, 2021 Efraim Flashner -;;; Copyright © 2020 Maxim Cournoyer +;;; Copyright © 2020, 2021, 2022 Maxim Cournoyer ;;; Copyright © 2021 Simon Tournier ;;; Copyright © 2021 Chris Marusich ;;; Copyright © 2021 Maxime Devos ;;; Copyright © 2018 Steve Sprang -;;; Copyright © 2021 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -38,7 +37,6 @@ (define-module (guix utils) #:use-module (srfi srfi-26) #:use-module (srfi srfi-39) #:use-module (srfi srfi-71) - #:use-module (ice-9 ftw) #:use-module (rnrs io ports) ;need 'port-position' etc. #:use-module ((rnrs bytevectors) #:select (bytevector-u8-set!)) #:use-module (guix memoization) @@ -49,10 +47,11 @@ (define-module (guix utils) #:use-module ((guix combinators) #:select (fold2)) #:use-module (guix diagnostics) ;, &error-location, etc. #:use-module (ice-9 format) - #:use-module (ice-9 regex) - #:use-module (ice-9 match) - #:use-module (ice-9 format) + #:use-module (ice-9 ftw) #:use-module ((ice-9 iconv) #:prefix iconv:) + #:use-module (ice-9 match) + #:use-module (ice-9 regex) + #:use-module (ice-9 rdelim) #:use-module (ice-9 vlist) #:autoload (zlib) (make-zlib-input-port make-zlib-output-port) #:use-module (system foreign) @@ -133,6 +132,7 @@ (define-module (guix utils) readlink* go-to-location edit-expression + delete-expression filtered-port decompressed-port @@ -433,11 +433,13 @@ (define (move-source-location-map! source target line) (hash-set! %source-location-map target-key `(,@target-stamp ,source-map))))))) -(define* (edit-expression source-properties proc #:key (encoding "UTF-8")) +(define* (edit-expression source-properties proc #:key (encoding "UTF-8") + include-trailing-newline?) "Edit the expression specified by SOURCE-PROPERTIES using PROC, which should be a procedure that takes the original expression in string and returns a new -one. ENCODING will be used to interpret all port I/O, it default to UTF-8. -This procedure returns #t on success." +one. ENCODING will be used to interpret all port I/O, it defaults to UTF-8. +This procedure returns #t on success. When INCLUDE-TRAILING-NEWLINE? is true, +the trailing line is included in the edited expression." (define file (assq-ref source-properties 'filename)) (define line (assq-ref source-properties 'line)) (define column (assq-ref source-properties 'column)) @@ -446,10 +448,14 @@ (define column (assq-ref source-properties 'column)) (call-with-input-file file (lambda (in) (let* ( ;; The start byte position of the expression. - (start (begin (go-to-location in (+ 1 line) (+ 1 column)) + (start (begin (go-to-location + in (+ 1 line) (+ 1 column)) (ftell in))) ;; The end byte position of the expression. - (end (begin (read in) (ftell in)))) + (end (begin (read in) + (when include-trailing-newline? + (read-line in)) + (ftell in)))) (seek in 0 SEEK_SET) ; read from the beginning of the file. (let* ((pre-bv (get-bytevector-n in start)) ;; The expression in string form. @@ -478,6 +484,10 @@ (define column (assq-ref source-properties 'column)) (move-source-location-map! (stat in) (stat file) (+ 1 line)))))))))) +(define (delete-expression source-properties) + "Delete the expression specified by SOURCE-PROPERTIES." + (edit-expression source-properties (const "") #:include-trailing-newline? #t)) + ;;; ;;; Keyword arguments. -- 2.36.0