Немного почистил. Добавлен поиск переменных по питоньим исходникам (lexer)

master
svkalinin 2022-12-15 11:59:05 +03:00
parent 6f85de472a
commit d215c1ca25
3 changed files with 62 additions and 56 deletions

View File

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

View File

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

View File

@ -30,6 +30,7 @@ dict set lexers SH procRegexpCommand {regexp -nocase -all -- {^\s*?(function |)\
dict set lexers PY commentSymbol {#} dict set lexers PY commentSymbol {#}
dict set lexers PY procFindString {(def )\s*?PROCNAME} 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 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 # Ruby