Skip to content

Commit

Permalink
made syntax highlighting update properly
Browse files Browse the repository at this point in the history
  • Loading branch information
totalspectrum committed May 2, 2020
1 parent 2c6113d commit adf5683
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/ctext/ctext.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -1045,9 +1045,11 @@ proc ctext::highlight {win start end {afterTriggered 0}} {
set wordEnd [$twin index "$res + $length chars"]
if { $mi != -1 } {
set wordStart [$twin index "$res + $mi chars"]
$twin tag add $tagClass $wordStart $wordEnd
$twin tag configure $tagClass -foreground $color
} else {
set wordStart $res
}
$twin tag add $tagClass $wordStart $wordEnd
$twin tag configure $tagClass -foreground $color
set si $wordEnd

incr numTimesLooped
Expand Down
27 changes: 21 additions & 6 deletions src/gui.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,8 @@ proc doClickOnError { w coord } {
# set up syntax highlighting for a given ctext widget
#

set color(comments) cyan
set color(keywords) DarkBlue
set color(comments) grey
set color(keywords) SlateBlue
set color(brackets) green
set color(braces) lawngreen
set color(parens) darkgreen
Expand All @@ -940,6 +940,10 @@ set color(hyperlink) blue
proc setHighlightingForFile {w fname} {
global config
set ext [file extension $fname]
ctext::clearHighlightClasses $w
foreach t [$w tag names] {
$w tag delete $t
}
if { $config(syntaxhighlight) } {
set check1 [lsearch -exact {".c" ".cpp" ".cc" ".h" ".hpp"} $ext]
#puts "fname=$fname ext=$ext check1 = $check1"
Expand Down Expand Up @@ -976,7 +980,7 @@ proc setSyntaxHighlightingC {win} {
global color

ctext::addHighlightClassForSpecialChars $win brackets $color(brackets) {[]}
ctext::addHighlightClassForSpecialChars $win braces $color(braces) {{}}
ctext::addHighlightClassForSpecialChars $win braces $color(keywords) {{}}
ctext::addHighlightClassForSpecialChars $win parentheses $color(parens) {()}
ctext::addHighlightClassForSpecialChars $win quotes $color(strings) "\"\'"
ctext::addHighlightClass $win control $color(keywords) [list namespace while for if else do switch case __asm __pasm typedef]
Expand All @@ -988,8 +992,8 @@ proc setSyntaxHighlightingC {win} {
#define #undef #if #ifdef #ifndef #endif #elseif #include #import #exclude]

ctext::addHighlightClassForSpecialChars $win math $color(operators) {+=*-/&^%!|<>}
#ctext::addHighlightClassForRegexp $win eolcomment $color(comments) {\/\/[^\n\r]*}
ctext::addHighlightClassForRegexp $win eolcomment $color(comments) {(?://\ )([^\r\n]+)}
ctext::addHighlightClassForRegexp $win eolcomment $color(comments) {//[^\n\r]*}
#ctext::addHighlightClassForRegexp $win eolcomment $color(comments) {(?://\ )([^\r\n]+)}
#ctext::enableComments $win
}

Expand Down Expand Up @@ -1283,6 +1287,17 @@ proc doShowLinenumbers {} {
}
}

proc resetHighlight {} {
global config
global filenames
set tablist [.p.nb tabs]
foreach w $tablist {
set fname [getWindowFile $w]
setHighlightingForFile $w.txt $fname
$w.txt highlight 1.0 end
}
}

proc doneAppearance {} {
global config

Expand Down Expand Up @@ -1320,7 +1335,7 @@ proc doEditorOptions {} {
label .editopts.font.lb -text " Text font " -font $config(font)
ttk::button .editopts.font.change -text " Change... " -command doSelectFont
checkbutton .editopts.font.linenums -text "Show Linenumbers" -variable config(showlinenumbers) -command doShowLinenumbers
checkbutton .editopts.font.syntax -text "Syntax Highlighting" -variable config(syntaxhighlight)
checkbutton .editopts.font.syntax -text "Syntax Highlighting" -variable config(syntaxhighlight) -command resetHighlight
checkbutton .editopts.font.autoreload -text "Auto Reload Files if changed externally" -variable config(autoreload)
checkbutton .editopts.font.savewindows -text "Save session on exit" -variable config(savesession)
ttk::button .editopts.end.ok -text " OK " -command doneAppearance
Expand Down
2 changes: 1 addition & 1 deletion src/version.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ set spin2gui_version_major 4
set spin2gui_version_minor 1
set spin2gui_version_rev 8

set spin2gui_beta "-beta"


set spin2gui_beta ""


set spin2gui_version "$spin2gui_version_major.$spin2gui_version_minor.$spin2gui_version_rev$spin2gui_beta"

0 comments on commit adf5683

Please sign in to comment.