Compare commits

...

5 Commits

Author SHA1 Message Date
svkalinin 3bf3b80e38 Добавил раскраски в ruby 2022-12-16 10:11:07 +03:00
svkalinin a1248f6941 Добавлена возможность многострочных комментариев, если это поддерживается языком (html, go, ruby).
Добавлен параметр для включения данной фунциональности в меню и в конфиге.
2022-12-16 09:33:01 +03:00
svkalinin 777eaa01e5 В Ruby lexer добавлен поиск переменных коде. 2022-12-15 12:18:18 +03:00
svkalinin 2043a03c0b Новая сборка 2022-12-15 12:12:00 +03:00
svkalinin d215c1ca25 Немного почистил. Добавлен поиск переменных по питоньим исходникам (lexer) 2022-12-15 11:59:05 +03:00
8 changed files with 114 additions and 67 deletions

View File

@ -60,6 +60,7 @@ lineNumberShow=true
tabSize=4
procedureHelper=false
variableHelper=true
multilineComments=true
\[UserSession\]
opened=
editedFiles=

View File

@ -20,30 +20,55 @@ namespace eval Editor {
# Comment one string or selected string
proc Comment {txt fileType} {
global lexers
global lexers cfgVariables
set selIndex [$txt tag ranges sel]
set pos [$txt index insert]
set lineNum [lindex [split $pos "."] 0]
set PosNum [lindex [split $pos "."] 1]
# set posNum [lindex [split $pos "."] 1]
set useMultiLine false
if [dict exists $lexers $fileType commentSymbol] {
set symbol [dict get $lexers $fileType commentSymbol]
} else {
set symbol "#"
}
puts "Select : $selIndex"
if {[dict exists $lexers $fileType commentMultilineSymbolBegin] == 1 && $cfgVariables(multilineComments) eq "true"} {
set symbolBegin [dict get $lexers $fileType commentMultilineSymbolBegin]
} else {
set symbolBegin ""
}
if {[dict exists $lexers $fileType commentMultilineSymbolEnd] == 1 && $cfgVariables(multilineComments) eq "true"} {
set symbolEnd [dict get $lexers $fileType commentMultilineSymbolEnd]
} else {
set symbolEnd ""
}
# puts "Select : $selIndex"
if {$selIndex != ""} {
set lineBegin [lindex [split [lindex $selIndex 0] "."] 0]
set lineEnd [lindex [split [lindex $selIndex 1] "."] 0]
# Если выделенно больше одной строки то включаем многострочный комментарий
if {$lineBegin < $lineEnd} {
set useMultiLine true
}
set posBegin [lindex [split [lindex $selIndex 1] "."] 0]
set posEnd [lindex [split [lindex $selIndex 1] "."] 1]
if {$lineEnd == $lineNum && $posEnd == 0} {
set lineEnd [expr $lineEnd - 1]
}
for {set i $lineBegin} {$i <=$lineEnd} {incr i} {
#$txt insert $i.0 "# "
regexp -nocase -indices -- {^(\s*)(.*?)} [$txt get $i.0 $i.end] match v1 v2
$txt insert $i.[lindex [split $v2] 0] "$symbol "
if {$symbolEnd ne ""} {
$txt insert $lineEnd.end "\n$symbolEnd"
set lineEnd [expr $lineEnd + 2]
}
if {$symbolBegin ne ""} {
$txt insert $lineBegin.0 "$symbolBegin\n"
}
if {$symbolBegin eq "" && $symbolEnd eq ""} {
for {set i $lineBegin} {$i <= $lineEnd} {incr i} {
#$txt insert $i.0 "# "
regexp -nocase -indices -- {^(\s*)(.*?)} [$txt get $i.0 $i.end] match v1 v2
$txt insert $i.[lindex [split $v2] 0] "$symbol "
}
}
$txt tag add comments $lineBegin.0 $lineEnd.end
$txt tag raise comments
@ -101,7 +126,7 @@ namespace eval Editor {
}
proc GetComment {fileType str} {
global lexers
puts [dict get $lexers $fileType commentSymbol]
# puts [dict get $lexers $fileType commentSymbol]
if {[dict exists $lexers $fileType commentSymbol] == 0} {
return
}
@ -114,22 +139,23 @@ namespace eval Editor {
}
}
proc GetComment:TCL {str} {
if {[regexp -nocase -indices -- {(^| )(#\s)(.+)} $str match v1 v2 v3]} {
return [list [lindex [split $v2] 0] [lindex [split $v3] 0]]
} else {
return 0
}
}
proc GetComment:GO {str} {
# puts ">>>>>>>$str"
if {[regexp -nocase -indices -- {(^| |\t)(//\s)(.+)} $str match v1 v2 v3]} {
# puts ">>>> $match $v1 $v2 $v3"
return [list [lindex [split $v2] 0] [lindex [split $v3] 0]]
} else {
return 0
}
}
# proc GetComment:TCL {str} {
# if {[regexp -nocase -indices -- {(^| )(#\s)(.+)} $str match v1 v2 v3]} {
# return [list [lindex [split $v2] 0] [lindex [split $v3] 0]]
# } else {
# return 0
# }
# }
# proc GetComment:GO {str} {
# # puts ">>>>>>>$str"
# if {[regexp -nocase -indices -- {(^| |\t)(//\s)(.+)} $str match v1 v2 v3]} {
# # puts ">>>> $match $v1 $v2 $v3"
# return [list [lindex [split $v2] 0] [lindex [split $v3] 0]]
# } else {
# return 0
# }
# }
proc GetComment:Unknown {str} {
if {[regexp -nocase -indices -- {(^| )(#\s)(.+)} $str match v1 v2 v3]} {
return [list [lindex [split $v2] 0] [lindex [split $v3] 0]]
@ -338,19 +364,12 @@ namespace eval Editor {
proc SelectionHighlight {txt} {
variable selectionText
$txt tag remove lightSelected 1.0 end
set selBegin [lindex [$txt tag ranges sel] 0]
set selEnd [lindex [$txt tag ranges sel] 1]
if {$selBegin ne "" && $selEnd ne ""} {
set selectionText [$txt get $selBegin $selEnd]
# set selBeginRow [lindex [split $selBegin "."] 1]
# set selEndRow [lindex [split $selEnd "."] 1]
# puts "$selBegin, $selBeginRow; $selEnd, $selEndRow"
# set symNumbers [expr $selEndRow - $selBeginRow]
set symNumbers [expr [lindex [split $selEnd "."] 1] - [lindex [split $selBegin "."] 1]]
# puts "Selection $selectionText"
if [string match "-*" $selectionText] {
set selectionText "\$selectionText"
}
@ -359,7 +378,6 @@ namespace eval Editor {
set selFindLine [lindex [split $ind "."] 0]
set selFindRow [lindex [split $ind "."] 1]
set endInd "$selFindLine.[expr $selFindRow + $symNumbers]"
# puts "$ind; $symNumbers; $selFindLine, $selFindRow; $endInd "
$txt tag add lightSelected $ind $endInd
}
}
@ -369,6 +387,7 @@ namespace eval Editor {
set win .varhelper
# if { [winfo exists $win] == 0 } { return }
set ind [$win.lBox curselection]
puts ">>>>>>>>>>>> VarHelperBind <<<<<<<<<<<<<<<<"
switch -- $K {
Prior {
@ -413,27 +432,22 @@ namespace eval Editor {
}
} ;# proc auto_completition_key
proc VarHelperEscape {w} {
puts "VarHelperEscape"
bindtags $w.t [list [winfo parent $w.t] $w.t Text sysAfter all]
puts ">>>>>>>>>>>> VarHelperEscape <<<<<<<<<<<<<<<<"
# bindtags $w [list [winfo parent $w] $w Text sysAfter all]
bindtags $w [list [winfo toplevel $w] $w Ctext sysAfter all]
catch { destroy .varhelper }
puts [bindtags $w]
puts [bind $w]
puts [bindtags $w.t]
puts [bind $w.t]
}
proc VarHelper {x y w word wordType} {
global editors lexers variables
variable txt
variable win
# set txt $w.frmText.t
# блокировка открытия диалога если запущен другой
if [winfo exists .findVariables] {
return
}
set txt $w
set win .varhelper
# set win .varhelper
puts "$x $y $w $word $wordType"
set fileType [dict get $editors $txt fileType]
@ -502,20 +516,38 @@ namespace eval Editor {
}
}
# unset item
# puts $findedVars
bindtags $txt [list VarHelperBind [winfo toplevel $txt] $txt Ctext sysAfter all]
# bindtags $txt [list VarHelperBind [winfo toplevel $txt] $txt Ctext sysAfter all]
# bindtags $txt.t [list VarHelperBind [winfo parent $txt.t] $txt.t Text sysAfter all]
bind VarHelperBind <Escape> "Editor::VarHelperEscape $txt; break"
# bindtags $txt.t {[list [winfo parent $txt.t] $txt.t Text sysAfter all]};
# bindtags $txt {[list [winfo toplevel $txt] $txt Ctext sysAfter all]};
# catch { destroy .varhelper }"
bind VarHelperBind <Key> {Editor::VarHelperKey $Editor::txt %K %A; break}
if { [winfo exists $win] } { destroy $win }
# bind VarHelperBind <Escape> "Editor::VarHelperEscape $txt.t; break"
# # bindtags $txt.t {[list [winfo parent $txt.t] $txt.t Text sysAfter all]};
# # bindtags $txt {[list [winfo toplevel $txt] $txt Ctext sysAfter all]};
# # catch { destroy .varhelper }"
# bind VarHelperBind <Key> {Editor::VarHelperKey %W %K %A; break}
#
if {$findedVars eq ""} {
return
}
# puts $findedVars
VarHelperDialog $x $y $w $word $findedVars
}
proc VarHelperDialog {x y w word findedVars} {
global editors lexers variables
variable txt
variable win
# puts ">>>>>>>>>>>>>$x $y $w $word $findedVars"
# set txt $w.frmText.t
# блокировка открытия диалога если запущен другой
# if [winfo exists .findVariables] {
# return
# }
# if { [winfo exists $win] } { destroy $win }
set txt $w
set win .varhelper
# if {$findedVars eq ""} {
# return
# }
toplevel $win
wm transient $win .
wm overrideredirect $win 1
@ -542,15 +574,13 @@ namespace eval Editor {
focus -force $Editor::txt.t
break
}
# bind $win.lBox <Return> {
# set findString [dict get $lexers [dict get $editors $Editor::txt fileType] procFindString]
# set values [.varhelper.lBox get [.varhelper.lBox curselection]]
# regsub -all {PROCNAME} $findString $values str
# Editor::FindFunction $Editor::txt "$str"
# destroy .varhelper.lBox
# # focus $Editor::txt.t
# break
# }
bind VarHelperBind <Control-Return> {
$Editor::txt delete "insert - 1 chars wordstart" "insert wordend - 1 chars"
$Editor::txt insert "insert" [.varhelper.lBox get [.varhelper.lBox curselection]]
# eval [bind VarHelperBind <Escape>]
Editor::VarHelperEscape $Editor::txt
break
}
# Определям расстояние до края экрана (основного окна) и если
# оно меньше размера окна со списком то сдвигаем его вверх
@ -735,6 +765,7 @@ namespace eval Editor {
# set txt $w.frmText.t
bind $txt <KeyRelease> "catch {Editor::ReleaseKey %K $txt $fileType}"
bind $txt <KeyPress> "Editor::PressKey %K $txt"
bind $txt <Control-eacute> Quit
bind $txt <Control-igrave> "Editor::SelectionPaste $txt"
bind $txt <Control-v> "Editor::SelectionPaste $txt"
bind $txt <Control-l> "SearchVariable $txt; break"

View File

@ -26,7 +26,6 @@ bind . <Control-Q> Quit
bind . <Control-eacute> Quit
bind . <Insert> Add
bind . <Delete> Del
bind . <Control-Return> Edit
bind . <F1> ShowHelpDialog
bind . <Control-n> Editor::New
bind . <Control-N> Editor::New

View File

@ -17,6 +17,7 @@ namespace eval Highlight {} {
ctext::addHighlightClassForSpecialChars $txt qoute #b84a0c {"'`}
ctext::addHighlightClassForRegexp $txt colors #68ceff {(#)(\w)+?(\s|$)}
ctext::addHighlightClassForRegexp $txt comments #666666 {(^|;)\s*(#)[^\n\r]*}
ctext::addHighlightClass $txt bool #3e803b {nil false true}
}
proc Default {txt} {
@ -54,6 +55,7 @@ namespace eval Highlight {} {
ctext::addHighlightClassForSpecialChars $txt brackets green {[]{}()}
ctext::addHighlightClassForRegexp $txt paths lightblue {\.[a-zA-Z0-9\_\-]+}
ctext::addHighlightClassForRegexp $txt comments #666666 {(#|//)[^\n\r]*}
ctext::addHighlightClass $txt bool #3e803b {nil false true}
ctext::addHighlightClassForSpecialChars $txt qoute #b84a0c {"'`}
}
@ -111,13 +113,15 @@ namespace eval Highlight {} {
proc RB {txt} {
ctext::addHighlightClassForRegexp $txt qoute #b84a0c {("|'|`).*?("|'|`)}
ctext::addHighlightClassForRegexp $txt flags orange {\s-[a-zA-Z]+}
ctext::addHighlightClass $txt stackControl #19a2a6 {def end class if else for while case when require module begin rescue self return include}
ctext::addHighlightClass $txt stackControl #19a2a6 {def end class if else for while case when require module begin rescue self return include unless raise private new do synchronize}
ctext::addHighlightClassForRegexp $txt vars #4471ca {(\$|\*|\&)[\.a-zA-Z0-9\_\-\[\]]+}
ctext::addHighlightClassForSpecialChars $txt brackets green {[]{}()}
ctext::addHighlightClassForRegexp $txt paths lightblue {\.[a-zA-Z0-9\_\-]+}
ctext::addHighlightClassForRegexp $txt comments #666666 {(#|//)[^\n\r]*}
ctext::addHighlightClassForRegexp $txt namespaces #4f64ff {::}
ctext::addHighlightClassForRegexp $txt dog #0082ff {(@)[\.a-zA-Z0-9\_\-]+}
ctext::addHighlightClass $txt bool #7e5fb3 {nil false true}
}
proc MD {txt} {

View File

@ -15,6 +15,8 @@ dict set lexers TCL commands [info commands]
#--------------------------------------------------
# Go lang
dict set lexers GO commentSymbol {//}
dict set lexers GO commentMultilineSymbolBegin {/*}
dict set lexers GO commentMultilineSymbolEnd {*/}
dict set lexers GO procFindString {func.*?PROCNAME}
dict set lexers GO procRegexpCommand {regexp -nocase -all -- {\s*?func\s*?(\(\w+\s*?\**?\w+\)|)\s*?(\w+)\((.*?)\)\s+?([a-zA-Z0-9\{\}\[\]\(\)-_.]*?|)\s*?\{} $line match linkName procName params returns}
dict set lexers GO varRegexpCommand {regexp -nocase -all -line -- {^\s*?var\s+([a-zA-Z0-9\-_$]+)\s+(.+?)(\s*$)} $line match varName varType lineEnd}
@ -30,14 +32,17 @@ dict set lexers SH procRegexpCommand {regexp -nocase -all -- {^\s*?(function |)\
dict set lexers PY commentSymbol {#}
dict set lexers PY procFindString {(def )\s*?PROCNAME}
dict set lexers PY procRegexpCommand {regexp -nocase -all -- {^\s*?(def)\s*?(.*?)\((.*?)\):} $line match keyWord procName params}
dict set lexers PY varRegexpCommand {regexp -nocase -all -line -- {^\s*?(\w+)\s*=\s*(.+)($)} $line match varName varValue lineEnd}
#--------------------------------------------------
# Ruby
dict set lexers RB commentSymbol {#}
dict set lexers RB commentMultilineSymbolBegin {=begin}
dict set lexers RB commentMultilineSymbolEnd {end=}
dict set lexers RB tabSize 2
dict set lexers RB procFindString {(def |class )\s*?PROCNAME}
dict set lexers RB procRegexpCommand {regexp -nocase -all -- {^\s*?(def|class)\s([a-zA-Z0-9\-_:\?]+?)($|\s|\(.+?\))} $line match keyWord procName params}
dict set lexers RB varRegexpCommand {regexp -nocase -all -line -- {^\s*?(\w+)\s*=\s*(.+)($)} $line match varName varValue lineEnd}
#--------------------------------------------------
# YAML (ansible)
dict set lexers YML commentSymbol {#}
@ -74,14 +79,18 @@ dict set lexers INI procRegexpCommand {regexp -nocase -all -- {^\s*?(\[)(.+?)(\]
# -------------------------------------------------
# HTML
dict set lexers HTML commentSymbol {<\!--}
dict set lexers HTML commentSymbol {<!--}
dict set lexers HTML commentMultilineSymbolBegin {<!--}
dict set lexers HTML commentMultilineSymbolEnd {-->}
dict set lexers HTML tabSize 4
dict set lexers HTML procFindString {<h[0-9]>(<.+>|)PROCNAME(</.+>|)</h[0-9]>}
dict set lexers HTML procRegexpCommand {regexp -nocase -all -- {<h[0-9]>(<.+>|)(.+?)(</.+>|)</h[0-9]>} $line match v1 procName v2}
# -------------------------------------------------
# HTM
dict set lexers HTM commentSymbol {<\!--}
dict set lexers HTM commentSymbol {<!--}
dict set lexers HTM commentMultilineSymbolBegin {<!--}
dict set lexers HTM commentMultilineSymbolEnd {-->}
dict set lexers HTM tabSize 4
dict set lexers HTM procFindString {<h[0-9]>(<.+>|)PROCNAME(</.+>|)</h[0-9]>}
dict set lexers HTM procRegexpCommand {regexp -nocase -all -- {<h[0-9]>(<.+>|)(.+?)(</.+>|)</h[0-9]>} $line match v1 procName v2}

View File

@ -118,6 +118,8 @@ proc GetViewMenu {m} {
-variable cfgVariables(procedureHelper) -onvalue true -offvalue false
# -command "ViewHelper procedureHelper"
$m add checkbutton -label [::msgcat::mc "Multiline comments"] \
-variable cfgVariables(multilineComments) -onvalue true -offvalue false
}
proc GetHelpMenu {m} {

View File

@ -124,6 +124,7 @@
::msgcat::mcset ru "Matches" "Совпадений"
::msgcat::mcset ru "Modules" "Модули"
::msgcat::mcset ru "Modifying the Registry..." "Внесение изменений в реестр"
::msgcat::mcset ru "Multiline comments" "Многострочные комментарии"
::msgcat::mcset ru "Must be one file select!" "Вы должны выбрать только один файл"
::msgcat::mcset ru "Must be one or two file select!" "Вы должны выбрать один или два файла"
::msgcat::mcset ru "Network" "Сеть"

View File

@ -10,7 +10,7 @@ exec wish "$0" -- "$@"
######################################################
# Version: 2.0.0
# Release: alpha
# Build: 09122022154416
# Build: 16122022101023
######################################################
# определим текущую версию, релиз и т.д.