beetlebug▾
/

ztcl::code insert

Puts lines before a line of a file.

ztcl::code insert FILE LINE TEXT

Description

Puts TEXT, as whole lines, before line LINE. LINE end adds TEXT after the last line.

Returns

FILE:A-B +ADDED -0.

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 insert b.txt end three
b.txt:4 +1 -0

Errors

% ztcl::code insert b.txt 9 x
bad line 9: b.txt has 4 lines
-errorcode ZTCL CODE RANGE

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