Ticket #27242: port.tcl-completion.patch
File port.tcl-completion.patch, 3.2 KB (added by outis, 14 years ago) |
---|
-
port.
old new 3825 3825 \ 3826 3826 quit [list action_exit [ACTION_ARGS_NONE]] \ 3827 3827 exit [list action_exit [ACTION_ARGS_NONE]] \ 3828 3828 ] 3829 3829 3830 # Expand "action". 3831 # Returns an action proc, or a list of matching action procs, or the action passed in 3832 proc find_action { action } { 3833 global action_array 3834 3835 if { ! [info exists action_array($action)] } { 3836 set guess [guess_action $action] 3837 if { [info exists action_array($guess)] } { 3838 return $guess 3839 } 3840 return $guess 3841 } 3842 3843 return $action 3844 } 3845 3846 # Expand action 3847 # If there's more than one match, return the next possibility 3830 3848 proc find_action_proc { action } { 3831 3849 global action_array 3832 3850 3833 3851 set action_proc "" 3834 3852 if { [info exists action_array($action)] } { 3835 3853 set action_proc [lindex $action_array($action) 0] 3854 } else { 3855 set action [complete_action $action] 3856 if { [info exists action_array($action)] } { 3857 set action_proc [lindex $action_array($action) 0] 3858 } 3859 } 3860 3861 return $action_proc 3862 } 3863 3864 proc get_action_proc { action } { 3865 global action_array 3866 3867 set action_proc "" 3868 if { [info exists action_array($action)] } { 3869 set action_proc [lindex $action_array($action) 0] 3836 3870 } 3837 3871 3838 3872 return $action_proc 3839 3873 } 3840 3874 … … 4112 4146 # Reset global_options from base before each action, as we munge it just below... 4113 4147 array unset global_options 4114 4148 array set global_options $global_options_base 4115 4149 4116 4150 # Find an action to execute 4117 set action_proc [find_action_proc $action] 4118 if { $action_proc == "" } { 4119 puts "Unrecognized action \"$action\"" 4151 #set action_proc [find_action_proc $action] 4152 set actions [find_action $action] 4153 if {[llength $actions] == 1} { 4154 set action [lindex $actions 0] 4155 set action_proc [get_action_proc $action] 4156 } else { 4157 if {[llength $actions] > 1} { 4158 puts "Ambiguous action \"$action\": could be any of {$actions}." 4159 } else { 4160 puts "Unrecognized action \"$action\"" 4161 } 4120 4162 set action_status 1 4121 4163 break 4122 4164 } 4123 4165 4124 4166 # Parse options that will be unique to this action … … 4204 4246 4205 4247 return $word 4206 4248 } 4207 4249 4208 4250 4251 # return text action beginning with $text 4209 4252 proc complete_action { text state } { 4210 4253 global action_array 4211 4254 global complete_choices complete_position 4212 4255 4213 4256 if {$state == 0} { … … 4219 4262 incr complete_position 4220 4263 4221 4264 return $word 4222 4265 } 4223 4266 4267 # return all actions beginning with $text 4268 proc guess_action { text } { 4269 global action_array 4270 4271 return [array names action_array "[string tolower $text]*"] 4272 4273 if { [llength $complete_choices ] == 1 } { 4274 return [lindex $complete_choices 0] 4275 } 4276 4277 return {} 4278 } 4224 4279 4225 4280 proc attempt_completion { text word start end } { 4226 4281 # If the word starts with '~', or contains '.' or '/', then use the build-in 4227 4282 # completion to complete the word 4228 4283 if { [regexp {^~|[/.]} $word] } {