1
Fork 0

replace textutils with inlined function

This commit is contained in:
Jan-Erik Rediger 2024-11-19 12:00:06 +01:00
parent 52d03a066e
commit 54189d10dd

View file

@ -1,9 +1,42 @@
#!/usr/bin/env wish #!/usr/bin/env wish
package require textutil
set active_transform 0 set active_transform 0
# Remove empty items at the beginning and the end of a list.
proc ltrim {list} {
set first [lsearch -not -exact $list {}]
set last [lsearch -not -exact [lreverse $list] {}]
return [
if {$first == -1} {
list
} else {
lrange $list $first end-$last
}
]
}
# Trim indentation in multiline quoted text.
proc undent {msg {whitespaceChars " "}} {
set msgLines [split $msg "\n"]
set maxLength [string length $msg]
set regExp [subst -nocommands {([$whitespaceChars]*)[^$whitespaceChars]}]
set indent [
tcl::mathfunc::min {*}[
lmap x $msgLines {
if {[regexp $regExp $x match whitespace]} {
string length $whitespace
} else {
lindex $maxLength
}
}
]
]
join [ltrim [lmap x $msgLines {string range $x $indent end}]] "\n"
}
proc oneline {text} { proc oneline {text} {
return [regsub -all \n+ $text " "] return [regsub -all \n+ $text " "]
} }
@ -20,7 +53,7 @@ proc wordcount {text} {
} }
proc dedent {text} { proc dedent {text} {
return [textutil::undent $text] return [undent $text]
} }
proc markdown_quote {text} { proc markdown_quote {text} {