proc resolveMacros {string} {
set serial [file tail $::globals(serialDir)]
if {$serial eq ""} {set serial "Undefined"}
set part [file tail $::globals(partDir)]
if {$part eq ""} {set part "Undefined"}
set time [clock seconds]
set mapString [list]
# --- build up a string map of all possible substitutions
set macroList [dbMem eval {select macro from macro}]
set sortedList [lsortby {string length} -int -decreasing $macroList]
foreach macro $sortedList {
if {$macro eq "%part"} {
lappend mapString $macro $part
} elseif {$macro eq "%serial"} {
lappend mapString $macro $serial
} else {
set val [clock format $time -format $macro]
lappend mapString $macro $val
}
}
# --- return the substituted result
return [string map $mapString $string]
}
Below is an image of how I'd like it to fold in TextEd (the screenshot is from another editor).
I've played with your suggested folding rules. They're definitely on the right track, though they suffer from something I noticed while playing with the "\in" item last night.
That is, since the folding stops just *above* the line with a matching or less indent, the closing brace of a proc never becomes part of the fold. So, a fully folded proc is always 2 lines: the proc line itself and the closing brace as a second line.
I'd really like a proc to fold to just a single line. Any thoughts on how I might make that happen?
Rickard Johansson wrote:Not without adding some kind of fold option.
To make it work is it safe to:
1. Always ignore { ... } on the same line?
2. Or assume the last { on the same line (or first on the next) is the beginning of a fold?
I *think* either of those sound OK. In my original screenshot above, take a look at line 9285. I'd prefer that line to not be (independently) folded as it's complete in just 1 line anyway. Would both of the above suggestions work OK with that line?
So, within a procedure's argument list, *optional* arguments with default values can be defined by enclosing them in braces. Option #2 still sounds perfectly valid. Option #1 might be also, depending on implementation (since the above braces are nested).