summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2014-02-23 11:20:27 +0000
committerNick White <git@njw.me.uk>2014-02-23 11:20:27 +0000
commit770b68f921e3ed28b34db8ca306682e3142114af (patch)
tree9801a6f5ed44c2afb260f31592ce65b00edc8b30
parentd663260fd331d9aae4b9a5fe669f1d1d12e4cbc2 (diff)
downloadtkread-770b68f921e3ed28b34db8ca306682e3142114af.tar.bz2
tkread-770b68f921e3ed28b34db8ca306682e3142114af.zip
Add prefix headings
-rwxr-xr-xtkread37
1 files changed, 37 insertions, 0 deletions
diff --git a/tkread b/tkread
index 4a712b8..bbd14c8 100755
--- a/tkread
+++ b/tkread
@@ -36,6 +36,7 @@ set inverted 0
set drag 0
set tagnum 0
set underlinenum 0
+set prefixnum 0
set domarkdown 0
set surroundfmt { \
@@ -49,6 +50,15 @@ set underlinefmt { \
{"-" "3" "italic"} \
}
+set prefixfmt { \
+ {"# " "6" ""} \
+ {"## " "3" "italic"} \
+ {"### " "1" "italic"} \
+ {"#### " "0" "italic"} \
+ {"##### " "0" "italic"} \
+ {"###### " "0" "italic"} \
+}
+
if { $::argc > 0 && [lindex $::argv 0] == "-h" } {
puts "Usage: $usage"
exit
@@ -77,10 +87,12 @@ proc indexmovechar {str moveby} {
proc markup {widget} {
global surroundfmt
global underlinefmt
+ global prefixfmt
global fontfamily
global fontsize
global tagnum
global underlinenum
+ global prefixnum
# process surrounds (bold, italic, and some headers)
# This uses marks before tags, as they handle deletions fine, so
@@ -173,6 +185,24 @@ proc markup {widget} {
$widget tag configure underline_$underlinenum -font "{$fontfamily} [expr $fontsize + $fmtsizemod] $fmtstring"
incr underlinenum
}
+
+ foreach fmt $prefixfmt {
+ set searchchar [lindex $fmt 0]
+ set fmtsizemod [lindex $fmt 1]
+ set fmtstring [lindex $fmt 2]
+
+ set cur [$widget search -regexp "^$searchchar" 0.0 end]
+ while {$cur != ""} {
+ set dotindex [string first . $cur]
+ set linenum [string range $cur 0 [expr $dotindex - 1]]
+ $widget tag add prefix_$prefixnum $linenum.0 $linenum.end
+ $widget delete $linenum.0 $linenum.[string length $searchchar]
+
+ set cur [$widget search -regexp "^$searchchar" [expr $linenum + 1].0 end]
+ }
+ $widget tag configure prefix_$prefixnum -font "{$fontfamily} [expr $fontsize + $fmtsizemod] $fmtstring"
+ incr prefixnum
+ }
}
proc changeFontSize {change} {
@@ -182,6 +212,8 @@ proc changeFontSize {change} {
global tagnum
global underlinefmt
global underlinenum
+ global prefixfmt
+ global prefixnum
set newsize [expr $fontsize $change]
if {$newsize > 0} {
set fontsize $newsize
@@ -196,6 +228,11 @@ proc changeFontSize {change} {
set fmtsizemod [lindex [lindex $underlinefmt $x] 1]
.t tag configure underline_$x -font "{$fontfamily} [expr $fontsize + $fmtsizemod] $fmtstring"
}
+ for {set x 0} {$x < $prefixnum} {incr x} {
+ set fmtstring [lindex [lindex $prefixfmt $x] 2]
+ set fmtsizemod [lindex [lindex $prefixfmt $x] 1]
+ .t tag configure prefix_$x -font "{$fontfamily} [expr $fontsize + $fmtsizemod] $fmtstring"
+ }
}
}