1
2
3
4
5
6
7
8
9
10
|
1
2
3
4
5
6
7
8
9
10
|
-
+
|
#!/usr/local/bin/tclsh
# FILE: "/home/joze/src/tclreadline/tclreadlineSetup.tcl.in"
# LAST MODIFICATION: "Sat Aug 21 00:19:39 1999 (joze)"
# LAST MODIFICATION: "Sun Aug 22 22:30:43 1999 (joze)"
# (C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org>
# $Id$
# ---
#
# tclreadline -- gnu readline for tcl
# Copyright (C) 1999 Johannes Zellner
#
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
return -code error "invalid command name \"$name\""
}
namespace eval tclreadline:: {
namespace export Setup Glob Loop InitCmds InitTclCmds InitTkCmds Print
}
# get the longest common completion
# e.g. str == {tcl_version tclreadline_version tclreadline_library}
# --> [tclreadline::GetCommon ${str}] == "tcl"
proc ::tclreadline::Setup {} {
#
proc tclreadline::GetCommon {str} {
set match0 [lindex ${str} 0]
set len0 [string length $match0]
set no_matches [llength ${str}]
set part ""
for {set i 0} {$i < $len0} {incr i} {
set char [string index $match0 $i]
for {set j 1} {$j < $no_matches} {incr j} {
if {$char != [string index [lindex ${str} $j] $i]} {
break
}
}
if {$j < $no_matches} {
break
} else {
append part $char
}
}
return ${part}
}
proc tclreadline::vars_cmds_completer {part start end line} {
if {{$} == [string index $part 0]} {
# variable completion. Check first, if the
# variable starts with a plain `$' or should
# be enclosed in braces.
#
if {"\{" == [string index $part 1]} {
set var [string range $part 2 end]
set left "\$\{"
set right "\}"
} else {
set left "\$"
set right ""
set var [string range $part 1 end]
}
# check if $var is an array name, which
# already has already a "(" somewhere inside.
#
if {[regexp {([^(]*)\((.*)} $var all array name]} {
set matches [uplevel array names ${array} ${name}*]
if {1 == [llength $matches]} { ; # unique match
return "\$${array}(${matches})"
} elseif {"" != ${matches}} {
return \
"\$${array}([tclreadline::GetCommon ${matches}] ${matches}"
} else {
return ""; # nothing to complete
}
}
set matches [uplevel info vars "${var}*"]
if {1 == [llength $matches]} { ; # unique match
# check if this unique match is an
# array name, (whith no "(" yet).
#
if {[uplevel array exists $matches]} {
return "\$${matches}( [uplevel array names $matches]"
} else {
return [join [list $left $matches $right] ""]
}
} elseif {"" != $matches} { ; # more than one matches
return "${left}[tclreadline::GetCommon ${matches}] ${matches}"
} else {
return ""; # nothing to complete
}
} elseif {{[} == [string index $part 0]} {
set cmd [string range $part 1 end]
set matches [info commands "${cmd}*"]
if {1 == [llength $matches]} { ; # unique match
return [join [list "\[" $matches] ""]
} elseif {"" != $matches} {
return "${part} ${matches}"
} else {
return ""; # nothing to complete
}
} else {
return ""
}
return "NOTREACHED (this is probably an error)"
}
proc ::tclreadline::Setup {} {
uplevel #0 {
if {[info commands ::tclreadline::readline] == ""} {
::tclreadline::Init
}
tclreadline::readline customcompleter tclreadline::vars_cmds_completer
if {[catch {set a [::tclreadline::prompt1]}] \
&& [info nameofexecutable] != ""} {
namespace eval ::tclreadline {
variable prompt_string
set base [file tail [info nameofexecutable]]
|