summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorHerman Rimm <herman@rimm.ee>2024-02-20 21:45:12 +0100
committerLudovic Courtès <ludo@gnu.org>2024-02-23 19:02:16 +0100
commit50e514c1bc674b1c36344407c8c4b418d17759c5 (patch)
tree7e5ed98db478efa5492f672e8a2a8b68254b8568 /guix
parentbabd39e84389c544e8dab44be8ddec57e52709c9 (diff)
utils: Add find-definition-insertion-location procedure.
* guix/utils.scm (find-definition-insertion-location): Add and export procedure. * tests/utils.scm ("find-definition-insertion-location"): Add test. Change-Id: Ie17e1b4a94790f58518ce121411a38d357f49feb Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'guix')
-rw-r--r--guix/utils.scm19
1 files changed, 19 insertions, 0 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index 94b4d753d0..29ad09d9f7 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -148,6 +148,7 @@
edit-expression
delete-expression
insert-expression
+ find-definition-insertion-location
filtered-port
decompressed-port
@@ -513,6 +514,24 @@ SOURCE-PROPERTIES."
(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.