Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Handle any number of digits in line numbers. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
345d8aea883cd90f841b6d44746f9308 |
User & Date: | peter 2007-11-27 18:05:18.000 |
Context
2007-12-05
| ||
16:28 | Try if anything from the command line is a kit. check-in: baf7d8ac97 user: peter tags: trunk | |
2007-11-27
| ||
18:05 | Handle any number of digits in line numbers. check-in: 345d8aea88 user: peter tags: trunk | |
18:04 | Include .git in default excluded directories. check-in: 668194b3e0 user: peter tags: trunk | |
Changes
Changes to src/print.tcl.
︙ | ︙ | |||
23 24 25 26 27 28 29 | #---------------------------------------------------------------------- # Helpers, replace with sugar macros or mathops if available in 8.5 proc + {a b} { expr {$a + $b} } proc - {a b} { expr {$a - $b} } # Format a line number for printing | | | | | > > | > | | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #---------------------------------------------------------------------- # Helpers, replace with sugar macros or mathops if available in 8.5 proc + {a b} { expr {$a + $b} } proc - {a b} { expr {$a - $b} } # Format a line number for printing # It will always be maxlen chars wide. proc FormatLineno {lineno maxlen} { if {[string is integer -strict $lineno]} { set res [format "%d: " $lineno] } else { # Non-numerical linenumbers might turn up in some cases set res $lineno if {[string length $res] > $maxlen} { set res [string range $res 0 [expr {$maxlen - 1}]] } } if {[string length $res] < $maxlen} { set res [format "%*s" $maxlen $res] } return $res } # Process the line numbers from the line number widget into a list # of "linestarters" proc ProcessLineno {w maxlen} { set tdump [$w dump -tag -text 1.0 end] set tag "" set line "" set lines {} foreach {key value index} $tdump { if {$key eq "tagon"} { if {$value eq "change" || [string match "new*" $value]} { |
︙ | ︙ | |||
62 63 64 65 66 67 68 | # Collect until end of line if {[string index $value end] eq "\n"} { # Clean everything but the line number set line [string trim [string trim $line] :] if {$line eq ""} { lappend lines {} } else { | > | | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | # Collect until end of line if {[string index $value end] eq "\n"} { # Clean everything but the line number set line [string trim [string trim $line] :] if {$line eq ""} { lappend lines {} } else { set formatline [FormatLineno $line $maxlen] lappend lines [list $formatline $tag] } set line "" } } } return $lines } |
︙ | ︙ | |||
112 113 114 115 116 117 118 119 120 121 122 123 124 125 | puts stderr "Bad tag in FormatLine: '$tag'" } append result "\0bggray\{$gray\}$text\0bggray\{1.0\}" } } return $result } # Main print function proc PrintDiffs {top {quiet 0} {pdfprint 0}} { busyCursor $top update idletasks set tmpFile [file nativename ~/eskil.enscript] | > > > > > > > > > | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | puts stderr "Bad tag in FormatLine: '$tag'" } append result "\0bggray\{$gray\}$text\0bggray\{1.0\}" } } return $result } # Find the lastnumber in a text widget proc FindLastNumber {w} { set index [$w search -backwards -regexp {\d} end] set line [$w get "$index linestart" "$index lineend"] #puts "X '$line' '$index'" regexp {\d+} $line number return $number } # Main print function proc PrintDiffs {top {quiet 0} {pdfprint 0}} { busyCursor $top update idletasks set tmpFile [file nativename ~/eskil.enscript] |
︙ | ︙ | |||
139 140 141 142 143 144 145 | } else { set wraplength 85 set linesPerPage 66 } set tdump1 [$::widgets($top,wDiff1) dump -tag -text 1.0 end] set tdump2 [$::widgets($top,wDiff2) dump -tag -text 1.0 end] | > > > > > > > > > | | > > | 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | } else { set wraplength 85 set linesPerPage 66 } set tdump1 [$::widgets($top,wDiff1) dump -tag -text 1.0 end] set tdump2 [$::widgets($top,wDiff2) dump -tag -text 1.0 end] # Figure out how many chars are needed for line numbers set len1 [string length [FindLastNumber $::widgets($top,wLine1)]] set len2 [string length [FindLastNumber $::widgets($top,wLine2)]] # Find maximum value (at least 3) set maxlen [lindex [lsort -integer [list 3 $len1 $len2]] end] # Add space for a colon and space incr maxlen 2 set lineNo1 [ProcessLineno $::widgets($top,wLine1) $maxlen] set lineNo2 [ProcessLineno $::widgets($top,wLine2) $maxlen] set linepad [string repeat " " $maxlen] # Loop over left and right displays, collecting lines from each. # Line numbers and text are put together and lines are wrapped if needed. foreach tdump [list $tdump1 $tdump2] \ lineName {lines1 lines2} wrapName {wrap1 wrap2} \ lineNo [list $lineNo1 $lineNo2] { |
︙ | ︙ | |||
180 181 182 183 184 185 186 | set len [string length $value] while {$chars + $len > $wraplength} { set wrap [expr {$wraplength - $chars}] set val1 [string range $value 0 [expr {$wrap - 1}]] set value [string range $value $wrap end] # The newline has its own element to simplify finding # it later. | | | | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | set len [string length $value] while {$chars + $len > $wraplength} { set wrap [expr {$wraplength - $chars}] set val1 [string range $value 0 [expr {$wrap - 1}]] set value [string range $value $wrap end] # The newline has its own element to simplify finding # it later. lappend line $val1 $tag "\n" {} $linepad {} set chars $maxlen incr wrapc set len [string length $value] } lappend line $value $tag incr chars $len } tagon { |
︙ | ︙ | |||
240 241 242 243 244 245 246 | for {set t $w1} {$t < $w2} {incr t} { lappend wraplines1 {} } } } if {$pdfprint} { | | | 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | for {set t $w1} {$t < $w2} {incr t} { lappend wraplines1 {} } } } if {$pdfprint} { PdfPrint $top $wraplength $maxlen $wraplines1 $wraplines2 } else { # Write all lines to a file, taking one page at a time from each # side. set ch [open $tmpFile "w"] fconfigure $ch -encoding binary |
︙ | ︙ | |||
328 329 330 331 332 333 334 | [lrange $enscriptCmd end-2 end]'" \ -font "Courier 8" pack .dp.b -side bottom pack .dp.l -side "top" } } | | | | 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | [lrange $enscriptCmd end-2 end]'" \ -font "Courier 8" pack .dp.b -side bottom pack .dp.l -side "top" } } proc PdfPrint {top cpl cpln wraplines1 wraplines2} { if {$::diff($top,printFile) != ""} { set pdfFile $::diff($top,printFile) } else { set pdfFile ~/eskil.pdf } if {![regexp {^(.*)( \(.*?\))$} $::diff($top,leftLabel) -> lfile lrest]} { set lfile $::diff($top,leftLabel) set lrest "" } set lfile [file tail $lfile]$lrest if {![regexp {^(.*)( \(.*?\))$} $::diff($top,rightLabel) -> rfile rrest]} { set rfile $::diff($top,rightLabel) set rrest "" } set rfile [file tail $rfile]$rrest set pdf [eskilprint %AUTO% -file $pdfFile -cpl $cpl -cpln $cpln \ -headleft $lfile -headright $rfile -headsize 10] set linesPerPage [$pdf getNLines] $pdf setTag change "0.8 0.4 0.4" $pdf setTag new1 "0.4 0.8 0.4" $pdf setTag new2 "0.4 0.4 0.8" set len1 [llength $wraplines1] |
︙ | ︙ |