beetlebug▾
/

ztcl::code edit

Makes several changes in one file, all of them or none.

ztcl::code edit FILE {OLD NEW ?OLD NEW ...?}

Description

Each OLD must be at one place of the file before the changes, as in replace, and two OLD texts must not overlap. One bad OLD stops all changes. -all changes each place of each OLD.

Returns

A line FILE:A-B +ADDED -REMOVED for each change, in the order of the file.

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 edit a.zig {"const std" "const s" "return p.x;" "return p.x * 2;"}
a.zig:1 +1 -1
a.zig:7 +1 -1

Errors

% ztcl::code edit a.zig {"fn len" x "len(p" y}
two old texts overlap at line 6 of a.zig
-errorcode ZTCL CODE OVERLAP

% ztcl::code edit a.zig {x}
edit FILE {OLD NEW ?OLD NEW ...?}
-errorcode ZTCL CODE USAGE

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