beetlebug▾
/

ztcl::code lines

Replaces a range of lines of a file.

ztcl::code lines FILE A B TEXT ?-expect T?

Description

Replaces lines A to B with TEXT, as whole lines: a TEXT with no line end at its end gets one. An empty TEXT removes the lines. B is A - 1 to put TEXT before line A. With -expect T, the lines must have the text T, or the error EXPECT gives the lines.

Returns

FILE:A-B +ADDED -REMOVED.

Examples

Each example of this page runs after package require ztcl::code # A folder with three files, outside a git tree. set dir /tmp/ztcl-ref-code-[pid] file delete -force $dir file mkdir $dir cd $dir proc put {path text} { set ch [open $path w] puts -nonewline $ch $text close $ch } put a.zig "const std = @import(\"std\");\n\npub const Point = struct {\n x: i32,\n\n pub fn len(p: Point) i32 {\n return p.x;\n }\n};\n" put b.txt "one\ntwo\ntwo\n" put c.md "# Title\n\n## Part\n\ntext\n" # The tests use no model. set ::ztcl::code::backend {http ""} set ::ztcl::code::llm_url http://127.0.0.1:9/v1/chat/completions .

% ztcl::code lines b.txt 2 3 "2\n3\n4"
b.txt:2-4 +3 -2

% ztcl::code lines b.txt 1 1 ""
b.txt:1 -1

Errors

% ztcl::code lines b.txt 5 6 x
bad range 5-6: b.txt has 3 lines
-errorcode ZTCL CODE RANGE

% ztcl::code lines b.txt 1 1 x -expect zero
lines 1-1 of b.txt do not have the text of -expect:
1	2
-errorcode ZTCL CODE EXPECT

Facts

Capability
file. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.2