From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id KD4oA+EP1WWMggAAqHPOHw:P1 (envelope-from ) for ; Tue, 20 Feb 2024 21:47:29 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id KD4oA+EP1WWMggAAqHPOHw (envelope-from ) for ; Tue, 20 Feb 2024 21:47:29 +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=CE3PQc8B; 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=1708462049; 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-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=fAvUAhms6sQA11IT0Mp3NqbYqy3+2zH2eBuSBomYrpQ=; b=dcn5XfA/wPgWXaKtvVHCNwJOuz+t9pG6h6crpSWKTGOzTprbQ/F9iLYeSVGfeibSf8UrdM vY2xnHnYQUict7itXqRa9+1AgY61oX4ZsViTFVwVhcEM6IpvAHD2ilQXO3FxL4jK93Ntlz n3pzgN8c3tsltcgvtqfLCkDWF9Ah0RYRq8GUUSdIEHTF48yyEs10/U2mtjTZvQfvXU4T+l pcWPX1VfZ4SHihlTu1mSRM9wsXrZKFMMhDNAhxU52nXqqOoUejTsZCjdMYqRrSPbFBLMJJ NOHXDwMMexFq4EjJXZiCsKbSWi85kvtGlw32Ldaty4NtbSbWGlqBaPBM87gSdQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=CE3PQc8B; 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=1708462049; a=rsa-sha256; cv=none; b=YdHAKGlsXdlGwWNt86/JOynSQU1tJ+NjK5gNfORd2eyZnDHaGw1bYGOlXDYK6LLOy2bDRW dX3Fk/+I0cCTuTth3zoT1ObLNLdTXGr0D4f8KEkoXO82ifRLV2ZH/5YOD3z3TYxWEDs/sS wy8jvCeEHx8FRNKPPPI3BLXn2jVNzMDvp/MMdz0CP7WllOmFWwvWhZD+pOHKR5iqSA4z1a 8PA0c1k5OoPLFqBihRuOM58QbJjJ68N2fWAwobCl71NY3vLxn/dNQGfhhZsvzcEKOX1wBS tQrQsxbF4KH9CqETio+7MXyM6WjqG680hSoWB29UYIVKNMyYpfOgSwlo15Nk0A== 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 E99C8247B0 for ; Tue, 20 Feb 2024 21:47:28 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcX0v-00056k-5q; Tue, 20 Feb 2024 15:46:53 -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 1rcX0m-00054i-LF for guix-patches@gnu.org; Tue, 20 Feb 2024 15:46:44 -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 1rcX0m-0004GN-Cz; Tue, 20 Feb 2024 15:46:44 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rcX16-0004HC-2d; Tue, 20 Feb 2024 15:47:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68935] [PATCH v3 4/7] utils: Add find-definition-insertion-location 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: Tue, 20 Feb 2024 20:47:04 +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.170846197916326 (code B ref 68935); Tue, 20 Feb 2024 20:47:04 +0000 Received: (at 68935) by debbugs.gnu.org; 20 Feb 2024 20:46:19 +0000 Received: from localhost ([127.0.0.1]:46813 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcX0N-0004FB-7z for submit@debbugs.gnu.org; Tue, 20 Feb 2024 15:46:19 -0500 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117]:52067 helo=email.rimm.ee) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcX0J-0004Du-WF for 68935@debbugs.gnu.org; Tue, 20 Feb 2024 15:46:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1708461943; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fAvUAhms6sQA11IT0Mp3NqbYqy3+2zH2eBuSBomYrpQ=; b=CE3PQc8BEs0dZrCzBY4y+LHfQU7eQn7J1v+2vIXtydjbPpLrjHb7PIH8qrOvgZcsITzN+w RGWoEw56wBX9RjBtlpKVc2bxFvBIruGnjfUPabA9V1F1A6FVLRiTO1ks//ZiVdtcZ6FjYB PHkCuutlO7PonJmwQiIvD1+rSPrUPmttXn0K+8zotczr/81WRv00+8vdalZWgV1Ig9uDu2 eF4y3gLT77WCg9M/QSpeK2jda5DNXj3YnzamMLaJSnc7+oBSj8STPgYPYdhOb1WLNdu+n+ jA09745NsvUGDtFdqm4xk7sOVSsloiJlZw1JEtXglbR0jXxB4FbkcboqpBe+vQ== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id 69319bb1 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Tue, 20 Feb 2024 20:45:43 +0000 (UTC) Date: Tue, 20 Feb 2024 21:45:12 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -4.98 X-Spam-Score: -4.98 X-Migadu-Queue-Id: E99C8247B0 X-TUID: AGVDC7cBXejy * guix/utils.scm (find-definition-insertion-location): Add and export procedure. * tests/utils.scm ("find-definition-insertion-location"): Add test. Change-Id: Ie17e1b4a94790f58518ce121411a38d357f49feb --- guix/utils.scm | 19 +++++++++++++++++++ tests/utils.scm | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/guix/utils.scm b/guix/utils.scm index 8f0bc2399e..82a78e2dfb 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -148,6 +148,7 @@ (define-module (guix utils) edit-expression delete-expression insert-expression + find-definition-insertion-location filtered-port decompressed-port @@ -513,6 +514,24 @@ (define (insert-expression source-properties expr) (string-append expr "\n\n" str)))) (edit-expression source-properties insert))) +(define (find-definition-insertion-location file term) + "Search in FILE for a top-level public definition whose defined term +alphabetically succeeds TERM. Return the location if found, or #f +otherwise." + (let ((search-term (symbol->string term))) + (call-with-input-file file + (lambda (port) + (do ((syntax (read-syntax port) + (read-syntax port))) + ((match (syntax->datum syntax) + (('define-public current-term _ ...) + (string> (symbol->string current-term) + search-term)) + ((? eof-object?) #t) + (_ #f)) + (and (not (eof-object? syntax)) + (syntax-source syntax)))))))) + ;;; ;;; Keyword arguments. diff --git a/tests/utils.scm b/tests/utils.scm index cd54112846..52f3b58ede 100644 --- a/tests/utils.scm +++ b/tests/utils.scm @@ -288,6 +288,20 @@ (define-public package-2\n 'package)\n" `(define-public package-1 'package)) (call-with-input-file temp-file get-string-all))) +(test-equal "find-definition-insertion-location" + (list `((filename . ,temp-file) (line . 0) (column . 0)) + `((filename . ,temp-file) (line . 5) (column . 0)) + #f) + (begin + (call-with-output-file temp-file + (lambda (port) + (display "(define-public package-1\n 'foo)\n\n" port) + (display "(define foo 'bar)\n\n" port) + (display "(define-public package-2\n 'baz)\n" port))) + (map (lambda (term) + (find-definition-insertion-location temp-file term)) + (list 'package 'package-1 'package-2)))) + (test-equal "string-distance" '(0 1 1 5 5) (list -- 2.41.0