diff options
Diffstat (limited to 'lib/editor/autocompletion.tcl')
-rw-r--r--[-rwxr-xr-x] | lib/editor/autocompletion.tcl | 135 |
1 files changed, 100 insertions, 35 deletions
diff --git a/lib/editor/autocompletion.tcl b/lib/editor/autocompletion.tcl index a5c9234..04dca79 100755..100644 --- a/lib/editor/autocompletion.tcl +++ b/lib/editor/autocompletion.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,20 +21,64 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _AUTOCOMPLETION_TCL ] } { +set _AUTOCOMPLETION_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Implements autocompletion related procedures # This file should be loaded into class Editor in file "editor.tcl" # -------------------------------------------------------------------------- - -## Refresh list of avaliable SFR's and SFB's on the target uC +common invoke_com_win_in_p 0 ;# Bool: invoke_completion_popup_window in progress +common completion_win_opened 0 ;# Bool: Editor popup-based completion window opended + +## Array: Strings available for autocompletion + # Index 0 - Labels in assembly + # Index 1 - Constants/variables + # Index 2 - C variables + # Index 3 - Macros + # Index 4 - SFR's + # Index 5 - Expression symbols + # Index 6 - Doxygen tags + # Index 7 - C Functions +private variable autocompletion_list +private variable completion_win_str_i 1.0 ;# TextIndex: String to complete - start index +private variable completion_win_end_i 1.0 ;# TextIndex: String to complete - end index +private variable completion_win_mode 0 ;# Int: Completion window mode +private variable comp_win_loading_in_p 0 ;# Bool: Completion window list loading is in progress +private variable comp_win_loading_max 1 ;# Int: Maximum for progressbar in the completion window +private variable macl_invocations 0 ;# Int: Number of invocations of "manage_autocompletion_list" +private variable doxytag_fg {#000000} ;# Color: Highlight color for doxygen tag +private variable indirect_fg {#000000} ;# Color: Highlight color for indirect address +private variable symbol_fg {#000000} ;# Color: Highlight color for asm. symbol +private variable sfr_fg {#000000} ;# Color: Highlight color for SFR +private variable label_fg {#000000} ;# Color: Highlight color for asm. label +private variable macro_fg {#000000} ;# Color: Highlight color for asm. macro +private variable const_fg {#000000} ;# Color: Highlight color for asm. const +private variable dir_fg {#000000} ;# Color: Highlight color for asm. directive +private variable cs_fg {#000000} ;# Color: Highlight color for constrol sequence +private variable ins_fg {#000000} ;# Color: Highlight color for instruction +private variable doxytag_font ${::Editor::defaultFont} ;# Font: Font for doxygen tag +private variable indirect_font ${::Editor::defaultFont} ;# Font: Font for indirect address +private variable symbol_font ${::Editor::defaultFont} ;# Font: Font for asm. symbol +private variable sfr_font ${::Editor::defaultFont} ;# Font: Font for SFR +private variable label_font ${::Editor::defaultFont} ;# Font: Font for asm. label +private variable macro_font ${::Editor::defaultFont} ;# Font: Font for asm. macro +private variable const_font ${::Editor::defaultFont} ;# Font: Font for asm. const +private variable dir_font ${::Editor::defaultFont} ;# Font: Font for asm. directive +private variable cs_font ${::Editor::defaultFont} ;# Font: Font for constrol sequence +private variable ins_font ${::Editor::defaultFont} ;# Font: Font for instruction + + +## Refresh list of available SFR's and SFB's on the target uC # @return void -public method refresh_avaliable_SFR {} { - set autocompletion_list(4) [lsort -ascii [$parentObject cget -avaliable_SFR]] +public method refresh_available_SFR {} { + set autocompletion_list(4) [lsort -ascii [$parentObject cget -available_SFR]] } - ## Clear list of words for autocompletion window # @return void public method clear_autocompletion_list {} { @@ -49,14 +93,21 @@ public method clear_autocompletion_list {} { #+ autocompletion list up to date # @parm TextIndex start_index - Start # @parm TextIndex end_index - End + # @parm Bool do_spellcheck - Perform spell check # @return void -public method detete_text_in_editor {start_index end_index} { +public method detete_text_in_editor {start_index end_index {do_spellcheck 1}} { autocompletion_maybe_important_change $start_index $end_index + if {$do_spellcheck} { + spellcheck_change_detected_pre + } $editor delete $start_index $end_index + if {$do_spellcheck} { + spellcheck_change_detected_post + } } ## Inform autocompletion mechanism about possibly deleted symbol - # @parm TextIndex start_index - Begining on area to to analyze + # @parm TextIndex start_index - Beginning on area to to analyze # @parm TextIndex end_index - End on area to to analyze # @return void public method autocompletion_maybe_important_change {start_index end_index} { @@ -97,7 +148,7 @@ public method autocompletion_maybe_important_change {start_index end_index} { set idx [lsearch -ascii -exact $autocompletion_list($index) $string] if {$idx != -1} { $parentObject rightPanel_adjust_symbol_list \ - all $string $index 0 + all $string $index 0 $this set autocompletion_list($index) \ [lreplace $autocompletion_list($index) $idx $idx] @@ -135,24 +186,33 @@ private method autocompletion_c_syntax_analyze {line_number} { set end 0 set string {} - # Find part which consist of alfanumeric characters - if {![regexp -start $start -- {\w+} $line string]} { - return + # Find part which consist of alphanumeric characters + while {1} { + if {![regexp -start $start -- {\w+} $line string]} { + return + } + + incr start + set end [expr {$start + [string length $string]}] + + if {[string is digit [string index $string 0]]} { + incr start [string length $string] + } else { + break + } } - set start [string first $string $line $start] - set end [expr {$start + [string length $string]}] # Mark the word if {[regexp -start $end -- {\s*\(} $line]} { $editor tag add c_lang_func $line_number.$start $line_number.$end - } { + } else { $editor tag add c_lang_var $line_number.$start $line_number.$end } } } ## Inform autocompletion mechanism about possibly newly defined symbol - # @parm Int line_number - Line number + # @parm Int line_number - Line number # @return void public method manage_autocompletion_list {line_number} { # Detect new symbol @@ -184,7 +244,7 @@ public method manage_autocompletion_list {line_number} { || [lsearch -ascii -exact ${::CsyntaxHighlight::keywords} $string] != -1 } then { - return + continue } } @@ -196,9 +256,9 @@ public method manage_autocompletion_list {line_number} { # Append to the autocompletion list if {[lsearch -ascii -exact $autocompletion_list($index) $string] == -1} { lappend autocompletion_list($index) $string - $parentObject rightPanel_adjust_symbol_list \ - $line_number $string $index 1 + $line_number $string $index 1 $this + $parentObject rightPanel_sm_select $line_number } } } @@ -220,7 +280,7 @@ public method manage_autocompletion_list {line_number} { # 2 - C functions # 3 - Indirect values # 4 - Doxygen tags - # @parm String str - Incomplite instruction or directive + # @parm String str - Incomplete instruction or directive # @parm Int x - Relative X position of the popup window (relative to editor) # @parm Int y - Relative Y position of the popup window (relative to editor) # @return void @@ -281,13 +341,14 @@ private method invoke_completion_popup_window {mode start_idx end_idx} { # Create lisbox and scrollbar set frame [frame $win.frame] - set listbox [ListBox $frame.listbox \ - -relief flat -bd 0 -selectfill 1 \ - -selectbackground {#AAAAFF} \ - -bg white -cursor left_ptr \ + set listbox [ListBox $frame.listbox \ + -relief flat -bd 0 -selectfill 0 \ + -selectbackground {#AAAAFF} \ + -bg white -cursor left_ptr \ -yscrollcommand "$frame.scrollbar set" \ - -selectmode single -width 0 -height 0 \ - -highlightthickness 0 -padx 2 \ + -selectmode single -width 0 -height 0 \ + -highlightthickness 0 -padx 2 \ + -font $defaultFont_bold \ ] set completion_listbox $listbox pack $listbox -side left -fill both -expand 1 @@ -316,7 +377,7 @@ private method invoke_completion_popup_window {mode start_idx end_idx} { set listbox ".completion_win.frame.listbox" $listbox selection clear $listbox delete [$listbox items] - update idle + update idletasks if {$loading || $comp_win_loading_in_p} { if {!($comp_win_loading_max > 1)} { @@ -456,7 +517,7 @@ private method invoke_completion_popup_window {mode start_idx end_idx} { } # Control sequences - } { + } else { foreach command ${::ASMsyntaxHighlight::all_controls__with_dolar} { set shortcmd [string range $command 0 $end] if {$shortcmd == $str} { @@ -615,10 +676,10 @@ public method close_completion_popup_window {} { #+ state of this object # @return void proc close_completion_popup_window_NOW {} { - if {$invoke_com_win_in_p} {return} - set invoke_com_win_in_p 1 + if {${::Editor::invoke_com_win_in_p}} {return} + set ::Editor::invoke_com_win_in_p 1 - if {$completion_win_opened} { + if {${::Editor::completion_win_opened}} { catch { grab release .completion_win } @@ -627,8 +688,8 @@ proc close_completion_popup_window_NOW {} { } } - set completion_win_opened 0 - set invoke_com_win_in_p 0 + set ::Editor::completion_win_opened 0 + set ::Editor::invoke_com_win_in_p 0 } ## Auxiliary method for method "Key" @@ -788,7 +849,7 @@ private method aux_Key_autocompletion_5 {wordstart wordend} { ## Determinate color for instructions, directives, etc. # @return void private method refresh_highlighting_for_autocompletion {} { - foreach key ${::ASMsyntaxHighlight::hightlight_tags} { + foreach key ${::ASMsyntaxHighlight::highlight_tags} { if {[lindex $key 0] == {tag_instruction}} { set ins_fg [lindex $key 1] set ins_font [$editor tag cget tag_instruction -font] @@ -828,7 +889,7 @@ private method refresh_highlighting_for_autocompletion {} { } if {$prog_language == 1} { - foreach key ${::CsyntaxHighlight::hightlight_tags} { + foreach key ${::CsyntaxHighlight::highlight_tags} { if {[lindex $key 0] == {tag_c_dox_tag}} { set doxytag_fg [lindex $key 1] set doxytag_font [$editor tag cget tag_c_dox_tag -font] @@ -836,3 +897,7 @@ private method refresh_highlighting_for_autocompletion {} { } } } + +# >>> File inclusion guard +} +# <<< File inclusion guard |