Diff
Not logged in

Differences From Artifact [1c598840ba]:

To Artifact [e0fb9f8efc]:


1
2
3


4
5
6
7
8
9
10
1


2
3
4
5
6
7
8
9
10

-
-
+
+







# -*- tclsh -*-
# FILE: "/disk01/home/joze/src/tclreadline/tclreadlineCompleter.tcl"
# LAST MODIFICATION: "Fri Sep 17 18:41:10 1999 (joze)"
# FILE: "/home/joze/src/tclreadline/tclreadlineCompleter.tcl"
# LAST MODIFICATION: "Sat Sep 18 04:27:54 1999 (joze)"
# (C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org>
# $Id$
# ---
#
# tclreadline -- gnu readline for tcl
# Copyright (C) 1999  Johannes Zellner
#
85
86
87
88
89
90
91
92


93
94
95


96
97
98
99
100
101
102
85
86
87
88
89
90
91

92
93
94


95
96
97
98
99
100
101
102
103







-
+
+

-
-
+
+







		}
		if {!$trace} {
			return 0
		}
		if {![winfo exists .tclreadline_trace.text]} {
			toplevel .tclreadline_trace
			text .tclreadline_trace.text \
			-yscrollcommand { tclreadline::TraceReconf }
				-yscrollcommand { tclreadline::TraceReconf } \
				-wrap none
			scrollbar .tclreadline_trace.scroll \
			-orient vertical \
			-command { .tclreadline_trace.text yview }
				-orient vertical \
				-command { .tclreadline_trace.text yview }
			pack .tclreadline_trace.text -side left -expand yes -fill both
			pack .tclreadline_trace.scroll -side right -expand yes -fill y
		} else {
			raise .tclreadline_trace
		}
		return 1
	}
304
305
306
307
308
309
310




311
312
313
























































































314
315
316
317
318
319
320
321






322
323


324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350






























































































































































351








352

353
354
355
356
357
358
359
305
306
307
308
309
310
311
312
313
314
315
316


317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406






407
408
409
410
411
412


413
414



























415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581

582
583
584
585
586
587
588
589







+
+
+
+

-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
-
+







	}
	return [string trim $result]
}

#**
# invoke cmd with a (hopefully) invalid string and
# parse the error message to get an option list.
# The strings are carefully chosen to match the
# results produced by known tcl routines. It's a
# pity, that not all object commands generate
# standard error messages!
#
# @param cmd
# @return list of options for cmd
# @param   cmd
# @return  list of options for cmd
# @date    Sep-14-1999
#
proc TrySubCmds {text cmd} {

	set trystring ----
	set bla 0

	# try the command with and w/o trystring.
	# Some commands, e.g.
	#     .canvas bind
	# return an error if invoked w/o arguments
	# but not, if invoked with arguments. Breaking
	# the loop is eventually done at the end ...
	#
	for {set str ${trystring}} {1} {set str ""} {

		set code [catch {set result [eval ${cmd} ${str}]} msg]
		set result ""

		if {$code} {
			set tcmd [string trim ${cmd}]
			# puts stderr msg=$msg
			# XXX see
			#         tclIndexObj.c
			#         tkImgPhoto.c
			# XXX
			if {[regexp \
				{(bad|ambiguous|unrecognized) .*"----": *must *be( .*$)} \
				${msg} all junk raw]
			} {
				regsub -all -- , ${raw} { } raw
				set len [llength ${raw}]
				set len_2 [expr ${len} - 2]
				for {set i 0} {${i} < ${len}} {incr i} {
					set word [lindex ${raw} ${i}]
					if {"or" != ${word} && ${i} != ${len_2}} {
						lappend result ${word}
					}
				}
				if {[string length ${result}] && \
					-1 == [string first ${trystring} ${result}]
				} {
					return [TryFromList ${text} ${result}]
				}

			} elseif {[regexp \
				"wrong # args: should be \"?${tcmd}\[^ \t\]*\(.*\[^\"\]\)" \
				${msg} all hint]

			} {

				# XXX see tclIndexObj.c XXX
				if {-1 == [string first ${trystring} ${hint}]} {
					return [DisplayHints [list <[string trim $hint]>]]
				}
			} else {
				# check, if it's a blt error msg ...
				#
				set msglst [split ${msg} \n]
				foreach line ${msglst} {
					if {[regexp "${tcmd}\[ \t\]\+\(\[^ \t\]*\)\[^:\]*$" \
						${line} all sub]
					} {
						lappend result [list ${sub}]
					}
				}
				if {[string length ${result}] && \
					-1 == [string first ${trystring} ${result}]
				} {
					return [TryFromList ${text} ${result}]
				}
			}
		}
		if {"" == ${str}} {
			break
		}
	}
	return ""
}

#**
# try to get options for commands which
# allow `configure' (cget).
# @param command.
# @param optionsT where the table will be stored.
# @return number of options
# @date Sep-14-1999
#
proc TrySubCmds {cmd} {
	set trystring ____
	set result ""
	if [catch {set result [eval ${cmd} ${trystring}]} msg] {
		set tcmd [string trim ${cmd}]
		# puts stderr msg=$msg
proc OptionTable {cmd optionsT} {
	upvar $optionsT options
	# first we build an option table.
	# We always use `configure' here,
	# because cget will not return the
	# option table.
		if {[regexp {(bad|ambiguous) .*"____": *must *be( .*$)} ${msg} \
			all junk raw]
	#
	if {[catch [list set option_table [eval ${cmd} configure]] msg]} {
		} {; # XXX see tclIndexObj.c XXX
			regsub -all -- , ${raw} { } raw
			set len [llength ${raw}]
			set len_2 [expr ${len} - 2]
			for {set i 0} {${i} < ${len}} {incr i} {
				set word [lindex ${raw} ${i}]
				if {"or" != ${word} && ${i} != ${len_2}} {
					lappend result ${word}
				}

			}
		} elseif {[regexp "wrong # args: should be \"${tcmd}\(.*\)\"" \
			${msg} all hint]
		} {; # XXX see tclIndexObj.c XXX
			set result [string trim $hint]
		} else {
			# check, if it's a blt error msg ...
			#
			set msglst [split ${msg} \n]
			foreach line ${msglst} {
				if {[regexp "${tcmd}\[ \t\]\+\(\[^ \t\]*\)\[^:\]*$" \
					${line} all sub]
				} {
					lappend result [list ${sub}]
				}
			}
		}
		return 0
	}
	foreach optline ${option_table} {
		if {5 != [llength ${optline}]} continue else {
			lappend options(switches) [lindex ${optline} 0]
			lappend options(value)    [lindex ${optline} 4]
		}
	}
	return [llength ${option_table}]
}

#**
# try to complete a `cmd configure|cget ..' from the command's options.
# @param   text start line cmd, standard tclreadlineCompleter arguments.
# @return  a tclreadline completer formatted string.
# @date    Sep-14-1999
#
proc CompleteFromOptions {text start line} {

	# check if either `configure' or `cget' is present.
	#
	set lst [ProperList ${line}]
	foreach keyword {configure cget} {
		set idx [lsearch ${lst} ${keyword}]
		if {-1 != ${idx}} {
			break
		}
	}
	if {-1 == ${idx}} {
		return
	}

	if {[regexp {(cget|configure)$} ${line}]} {
		# we are at the end of (configure|cget)
		# but there's no space yet.
		#
		return ${text}
	}

	# separate the command, but exclude (cget|configure)
	# because cget won't return the option table. Instead
	# OptionTable always uses `configure' to get the
	# option table.
	#
	set cmd [lrange ${lst} 0 [expr ${idx} - 1]]

	TraceText $cmd
	if {0 < [OptionTable ${cmd} options]} {

		set prev [PreviousWord ${start} ${line}]
		if {-1 != [set found [lsearch -exact $options(switches) ${prev}]]} {

			# complete only if the user has not
			# already entered something here.
			#
			if {![llength ${text}]} {
				# use this double list to quote option
				# values which have to be quoted.
				#
				return [list [list [lindex $options(value) ${found}]]]
			}

		} else {
			return [CompleteFromList ${text} \
			[RemoveUsedOptions ${line} $options(switches)]]
		}
	}
	return ""
}

proc ObjectClassCompleter {text start end line pos} {
	set cmd [Lindex ${line} 0]
	if {"." == [string index ${line} 0]} {
		# it's a widget. Try to get it's class name.
		#
		if {![catch [list set class [winfo class [Lindex ${line} 0]]]]} {
			if {[string length [info proc ${class}Obj]]} {
				return [${class}Obj ${text} ${start} ${end} ${line} ${pos}]
			}
		}
	}
	if {![catch [list image type ${cmd}]]} {
		return [ImageObj ${text} ${start} ${end} ${line} ${pos}]
	}
}

proc CompleteFromOptionsOrSubCmds {text start end line pos} {
	set from_opts [CompleteFromOptions ${text} ${start} ${line}]
	if {[string length ${from_opts}]} {
		return ${from_opts}
	} else {
		# puts stderr \n\n[lrange [ProperList ${line}] 0 [expr $pos - 1]]\n
		return [TrySubCmds ${text} \
		[lrange [ProperList ${line}] 0 [expr $pos - 1]]]
	}
	return ""
}

#**
# TODO: shit. make this better!
# @param  text, a std completer argument (current word).
# @param  fullpart, the full text of the current position.
# @param  lst, the list to complete from.
# @param  pre, leading `quote'.
# @param  sep, word separator.
# @param  post, trailing `quote'.
# @return a formatted completer string.
# @date   Sep-15-1999
#
proc CompleteListFromList {text fullpart lst pre sep post} {

	# puts stderr ""
	# puts stderr text=|$text|
	# puts stderr lst=|$lst|
	# puts stderr pre=|$pre|
	# puts stderr sep=|$sep|
	# puts stderr post=|$post|

	if {![string length ${fullpart}]} {

		# nothing typed so far. Insert a $pre
		# and inhibit further completion.
		#
		return [list ${pre} {}]

	} elseif {[regexp ${post} ${text}]} {

		# finalize, append the post and a space.
		#
		set diff \
		[expr [CountChar ${fullpart} ${pre}] - [CountChar ${fullpart} ${post}]]
		for {set i 0} {${i} < ${diff}} {incr i} {
			append text ${post}
		}
		append text " "
		return ${text}

	} elseif {![regexp -- ^\(.*\[${pre}${sep}\]\)\(\[^${pre}${sep}\]*\)$ \
		${text} all left right]
	} {
		set left {}
		set right ${text}
	}

	# TraceVar left
	# TraceVar right

	# puts stderr \nleft=|$left|
	# puts stderr \nright=|$right|
	set exact_matches [MatchesFromList ${right} ${lst}]
	# TODO this is awkward. Think of making it better!
	#
	if {1 == [llength ${exact_matches}] && -1 != [lsearch ${lst} ${right}]
	} {
		#set completion [CompleteFromList ${right} [list ${sep} ${post}] 1]
		return [list ${left}${right}${sep} {}]
	} else {
		set completion [CompleteFromList ${right} ${lst} 1]
	}
	# puts stderr \ncompletion=|$completion|
	if {![string length [lindex $completion 0]]} {
		return [concat [list ${left}] [lrange $completion 1 end]]
	} elseif {[string length ${left}]} {
		return [list ${left}]${completion}
	} else {
		return ${completion}
	}
	return ${result}
	return ""
}

proc FirstNonOption {line} {
	set expr_pos 1
	foreach word [lrange ${line} 1 end] {; # 0 is the command itself
		if {"-" != [string index ${word} 0]} {
			break
373
374
375
376
377
378
379
















380
381
382
383
384
385
386
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	}
	set new ""
	foreach word ${opts} {
		if {-1 == [string first ${word} ${line}]} {
			lappend new ${word}
		}
	}

	# check if the last word in the line is an options
	# and if this word is at the very end of the line,
	# that means no space after.
	# If this is so, the word is stuffed into the result,
	# so that it can be completed -- probably with a space.
	#
	set last [Lindex ${line} end]
	if {[expr [string last ${last} ${line}] + [string length ${last}]] == \
		[string length ${line}]
	} {
		if {-1 != [lsearch ${opts} ${last}]} {
			lappend new ${last}
		}
	}

	return [string trim ${new}]
}

proc Alert {} {
	puts -nonewline \a
	flush stdout
}
989
990
991
992
993
994
995





996
997
998
999
1000
1001
1002
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253







+
+
+
+
+







		set new_start [lindex $sub 0]
		set new_end [expr $end - ($start - $new_start)]
		set new_line [lindex $sub 1]
		# puts stderr "(SplitLine) $new_start $new_end $new_line"
		return [ScriptCompleter $part $new_start $new_end $new_line]

	} elseif {0 == [set pos [PartPosition part start end line]]} {

		# XXX
		#     note that line will be [string trimleft'ed]
		#     after PartPosition.
		# XXX

		# puts stderr "(PartPosition) $part $start $end $line"
		set all [CommandCompletion ${part}]
		# puts stderr "(ScriptCompleter) all=$all"
		#puts \nmatches=$matches\n
		# return [Format $all $part]
		return [TryFromList $part $all]
1073
1074
1075
1076
1077
1078
1079

1080
1081
1082
1083
1084
1085
1086
1087
1088
1089



1090
1091




1092
1093
1094


1095
1096
1097
1098
1099
1100
1101






1102
1103
1104
1105
1106
1107
1108
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344


1345
1346
1347
1348
1349
1350

1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372







+










+
+
+
-
-
+
+
+
+


-
+
+







+
+
+
+
+
+







					# returned an empty string. Fall thru and try
					# further fallback completers.
					#
				} else {
					# return also empty strings, if
					# they're from a specific completer.
					#
					TraceText script_result=|${script_result}|
					return ${script_result}
				}
			}
			# set namespc ""; # no qualifiers for tclreadline_complete_unknown
		}

		# as we've reached here no valid specific completer
		# was found. Check, if it's a proc and return the
		# arguments.
		#
		if {![string length ${namespc}]} {
			set namespc ::
		}
		if {[string length [uplevel [info level] info proc $alias]]} {
			set args [uplevel [info level] info args $alias]
		if {[string length [uplevel [info level] \
			namespace eval ${namespc} [list ::info proc $alias]]]} {
			set args [uplevel [info level] \
			namespace eval ${namespc} [list info args $alias]]
			set arg [lindex $args [expr $pos - 1]]
			if {"" != $arg && "args" != $arg} {
				if {[uplevel [info level] info default $alias $arg junk]} {
				if {[uplevel [info level] namespace eval \
					${namespc} [list info default $alias $arg junk]]} {
					return [DisplayHints ?$arg?]
				} else {
					return [DisplayHints <$arg>]
				}
			}
		}

		# check if the command is an object of known class.
		# 
		set res [ObjectClassCompleter $part $start $end $line $pos]
		if {[string length ${res}]} {
			return ${res}
		}

		# Ok, also no proc. Try to do the same as for widgets now:
		# try to complete from the option table if the subcommand
		# is `configure' or `cget' otherwise try to get further
		# subcommands.
		#
		return [CompleteFromOptionsOrSubCmds $part $start $end $line $pos]
2727
2728
2729
2730
2731
2732
2733
2734

2735
2736
2737
2738
2739
2740
2741
2991
2992
2993
2994
2995
2996
2997

2998
2999
3000
3001
3002
3003
3004
3005







-
+







}

proc complete(set) {text start end line pos mod} {
	switch -- $pos {
		1 { return [VarCompletion ${text}] }
		2 {
			if {$text == "" || $text == "\"" || $text == "\{"} {
				set line [QuoteQuotes $line]
				# set line [QuoteQuotes $line]
				if {[catch [list set value [list [uplevel [info level] \
					set [Lindex $line 1]]]] msg]
				} {
					return ""
				} else {
					return [Quote $value ${text}]
				}
2997
2998
2999
3000
3001
3002
3003
3004


3005
3006
3007
3008
3009
3010
3011
3261
3262
3263
3264
3265
3266
3267

3268
3269
3270
3271
3272
3273
3274
3275
3276







-
+
+







# tclreadline and import some commands.
#
namespace eval tclreadline {
	catch {
		namespace import \
		::tclreadline::DisplayHints \
		::tclreadline::CompleteFromList \
		::tclreadline::Lindex
		::tclreadline::Lindex \
		::tclreadline::CompleteBoolean
	}
}

proc tclreadline::complete(readline) {text start end line pos mod} {
	set cmd [Lindex $line 1]
	switch -- $pos {
		1 { return [CompleteFromList ${text} {
3200
3201
3202
3203
3204
3205
3206
3207

3208
3209
3210
3211
3212
3213
3214
3465
3466
3467
3468
3469
3470
3471

3472
3473
3474
3475
3476
3477
3478
3479







-
+







	regsub {^([^\.])} ${pattern} {\.\1} pattern
	if {![string length ${pattern}]} {
		set pattern .
	}
	if {[winfo exists ${pattern}]} {
		return [concat ${pattern} [winfo children ${pattern}]]
	} else {
		regsub {.[^.]*$} $pattern {} pattern
		regsub {.[^.]*$} $pattern {.} pattern
		if {[winfo exists ${pattern}]} {
			return [concat ${pattern} [winfo children ${pattern}]]
		} else {
			return ""
		}
	}
}
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334


3335

3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3494
3495
3496
3497
3498
3499
3500





























































































3501
3502
3503
3504


3505
3506

3507
3508
3509
3510
3511
3512
3513
3514
3515
3516








































































3517
3518
3519
3520
3521
3522
3523







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
-
+
+
-
+









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







		if {-1 == [lsearch $toplevels $toplevel]} {
			lappend toplevels $toplevel
		}
	}
	return $toplevels
}

#**
# try to get options for commands which
# allow `configure' (cget).
# @param command.
# @param optionsT where the table will be stored.
# @return number of options
# @date Sep-14-1999
#
proc OptionTable {cmd optionsT} {
	upvar $optionsT options
	# first we build an option table.
	# We always use `configure' here,
	# because cget will not return the
	# option table.
	#
	if {[catch [list set option_table [eval ${cmd} configure]] msg]} {
		return 0
	}
	foreach optline ${option_table} {
		if {5 != [llength ${optline}]} continue else {
			lappend options(switches) [lindex ${optline} 0]
			lappend options(value)    [lindex ${optline} 4]
		}
	}
	return [llength ${option_table}]
}

#**
# try to complete a `cmd configure|cget ..' from the command's options.
# @param text start line cmd, standard tclreadlineCompleter arguments.
# @return a tclreadline completer formatted string.
# @date Sep-14-1999
#
proc CompleteFromOptions {text start line} {

	# check if either `configure' or `cget' is present.
	#
	set lst [ProperList ${line}]
	foreach keyword {configure cget} {
		set idx [lsearch ${lst} ${keyword}]
		if {-1 != ${idx}} {
			break
		}
	}
	if {-1 == ${idx}} {
		return
	}

	# separate the command, but exclude (cget|configure)
	# because cget won't return the option table. Instead
	# OptionTable always uses `configure' to get the
	# option table.
	#
	set cmd [lrange ${lst} 0 [expr ${idx} - 1]]

	TraceText $cmd
	if {0 < [OptionTable ${cmd} options]} {

		set prev [PreviousWord ${start} ${line}]
		if {-1 != [set found [lsearch -exact $options(switches) ${prev}]]} {

			# complete only if the user has not
			# already entered something here.
			#
			if {![llength ${text}]} {
				# use this double list to quote option
				# values which have to be quoted.
				#
				return [list [list [lindex $options(value) ${found}]]]
			}

		} else {
			return [CompleteFromList ${text} \
			[RemoveUsedOptions ${line} $options(switches)]]
		}
	}
	return ""
}

proc CompleteFromOptionsOrSubCmds {text start end line pos} {
	set from_opts [CompleteFromOptions ${text} ${start} ${line}]
	if {[string length ${from_opts}]} {
		return ${from_opts}
	} else {
		# puts stderr \n\n[lrange [ProperList ${line}] 0 [expr $pos - 1]]\n
		set cmds [TrySubCmds [lrange [ProperList ${line}] 0 [expr $pos - 1]]]
		if {[llength ${cmds}]} {
			return [TryFromList ${text} ${cmds}]
		}
	}
	return ""
}

# TODO
# write a dispatcher here, which gets the widget class name
# and calls specific completers.
#
proc complete(WIDGET_COMMAND) {text start end line pos mod} {
	return [CompleteFromOptionsOrSubCmds ${text} ${start} ${end} ${line} ${pos}]
# proc complete(WIDGET_COMMAND) {text start end line pos mod} {
# 	return [CompleteFromOptionsOrSubCmds ${text} ${start} ${end} ${line} ${pos}]
}
# }

proc EventuallyInsertLeadingDot {text fallback} {
	if {![string length ${text}]} {
		return [list . {}]
	} else {
		return [DisplayHints $fallback]
	}
}

#**
# TODO: shit. make this better!
# @param  text, a std completer argument (current word).
# @param  fullpart, the full text of the current position.
# @param  lst, the list to complete from.
# @param  pre, leading `quote'.
# @param  sep, word separator.
# @param  post, trailing `quote'.
# @return a formatted completer string.
# @date   Sep-15-1999
#
proc CompleteListFromList {text fullpart lst pre sep post} {

	# puts stderr ""
	# puts stderr text=|$text|
	# puts stderr lst=|$lst|
	# puts stderr pre=|$pre|
	# puts stderr sep=|$sep|
	# puts stderr post=|$post|

	if {![string length ${fullpart}]} {

		# nothing typed so far. Insert a $pre
		# and inhibit further completion.
		#
		return [list ${pre} {}]

	} elseif {[regexp ${post} ${text}]} {

		# finalize, append the post and a space.
		#
		set diff \
		[expr [CountChar ${fullpart} ${pre}] - [CountChar ${fullpart} ${post}]]
		for {set i 0} {${i} < ${diff}} {incr i} {
			append text ${post}
		}
		append text " "
		return ${text}

	} elseif {![regexp -- ^\(.*\[${pre}${sep}\]\)\(\[^${pre}${sep}\]*\)$ \
		${text} all left right]
	} {
		set left {}
		set right ${text}
	}

	# TraceVar left
	# TraceVar right

	# puts stderr \nleft=|$left|
	# puts stderr \nright=|$right|
	set exact_matches [MatchesFromList ${right} ${lst}]
	# TODO this is awkward. Think of making it better!
	#
	if {1 == [llength ${exact_matches}] && -1 != [lsearch ${lst} ${right}]
	} {
		#set completion [CompleteFromList ${right} [list ${sep} ${post}] 1]
		return [list ${left}${right}${sep} {}]
	} else {
		set completion [CompleteFromList ${right} ${lst} 1]
	}
	# puts stderr \ncompletion=|$completion|
	if {![string length [lindex $completion 0]]} {
		return [concat [list ${left}] [lrange $completion 1 end]]
	} elseif {[string length ${left}]} {
		return [list ${left}]${completion}
	} else {
		return ${completion}
	}
	return ""
}

#**
# SpecificSwitchCompleter
# ---
# @param    text   -- the word to complete.
# @param    start  -- the char index of text's start in line
# @param    line   -- the line gathered so far.
# @param    switch -- the switch to complete for.
3437
3438
3439
3440
3441
3442
3443


3444


3445
3446
3447
3448
3449
3450
3451
3537
3538
3539
3540
3541
3542
3543
3544
3545

3546
3547
3548
3549
3550
3551
3552
3553
3554







+
+
-
+
+







			# ${start} ${end} ${line} ${pos} ${mod}]
		}
		-relief {
			return [CompleteFromList ${text} {
				raised sunken flat ridge solid groove
			}]
		}
		default {
			set prev [PreviousWord ${start} ${line}]
		default { return [DisplayHints <[String range ${prev} 1 end]>] }
			return [DisplayHints <[String range ${prev} 1 end]>]
		}
	}
}

#**
# CompleteWidgetConfigurations
# ---
# @param    text  -- the word to complete.
3476
3477
3478
3479
3480
3481
3482


















3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508

3509
3510
3511
3512
3513
3514
3515
3516

3517
3518
3519

3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531



3532
3533

3534
3535
3536
3537
3538
3539
3540
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622







3623








3624

3625

3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642

3643
3644
3645
3646
3647
3648
3649
3650







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



















-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-

-
+












+
+
+

-
+







		2 {
			if {"-displayof" == [PreviousWord ${start} ${line}]} {
				return [CompleteFromList ${text} [ToplevelWindows]]
			}
		}
	}
}

proc CompleteSequence {text fulltext} {
	set modifiers {
		Alt Control Shift Lock Double Triple
		B1 B2 B3 B4 B5 Button1 Button2 Button3 Button4 Button5
		M M1 M2 M3 M4 M5        
		Meta Mod1 Mod2 Mod3 Mod4 Mod5
	}
	set events {
		Activate Button ButtonPress ButtonRelease
		Circulate Colormap Configure Deactivate Destroy
		Enter Expose FocusIn FocusOut Gravity
		Key KeyPress KeyRelease Leave Map Motion
		MouseWheel Property Reparent Unmap Visibility
	}
	set sequence [concat ${modifiers} ${events}]
	return [CompleteListFromList ${text} ${fulltext} ${sequence} < - >]
}

proc complete(bind) {text start end line pos mod} {
	switch -- ${pos} {
		1 {
			set widgets [WidgetChildren ${text}]
			set toplevels [ToplevelWindows]
			if {[catch {set toplevelClass [winfo class .]}]} {
				set toplevelClass ""
			}
			set rest {
				Button Canvas Checkbutton Entry Frame Label
				Listbox Menu Menubutton Message Radiobutton
				Scale Scrollbar Text
				all
			}
			return [CompleteFromList ${text} \
			[concat ${toplevels} ${widgets} ${toplevelClass} $rest]]
		}
		2 {
			set modifiers {
				Alt Control Shift Lock Double Triple
				B1 B2 B3 B4 B5 Button1 Button2 Button3 Button4 Button5
				M M1 M2 M3 M4 M5        
				Meta Mod1 Mod2 Mod3 Mod4 Mod5
			}
			set events {
			set fulltext [Lindex $line 2]
				Activate Button ButtonPress ButtonRelease
				Circulate Colormap Configure Deactivate Destroy
				Enter Expose FocusIn FocusOut Gravity
				Key KeyPress KeyRelease Leave Map Motion
				MouseWheel Property Reparent Unmap Visibility
			}
			set sequence [concat ${modifiers} ${events}]
			return [CompleteListFromList ${text} \
			return [CompleteSequence ${text} ${fulltext}]
			[Lindex $line 2] ${sequence} < - >]
		}
		3 {
		default {
			# return [DisplayHints {<script> <+script>}]
			return [BraceOrCommand ${text} \
			${start} ${end} ${line} ${pos} ${mod}]
		}
	}
	return ""
}

proc complete(bindtags) {text start end line pos mod} {
	switch -- ${pos} {
		1 { return [CompleteFromList ${text} [WidgetChildren ${text}]] }
		2 {
			# set current_tags \
			# [RemoveUsedOptions ${line} [bindtags [Lindex ${line} 1]]]
			set current_tags [bindtags [Lindex ${line} 1]]
			return [CompleteListFromList ${text} [Lindex ${line} 2] \
			[bindtags [Lindex ${line} 1]] \{ { } \}]
			$current_tags \{ { } \}]
		}
	}
	return ""
}

proc complete(button) {text start end line pos mod} {
	switch -- ${pos} {
3588
3589
3590
3591
3592
3593
3594

















































3595
3596
3597
3598
3599
3600
3601
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







				-onvalue -selectcolor -selectimage -state -variable
				-width
			}]
		}
	}
	return ""
}

proc complete(clipboard) {text start end line pos mod} {
	switch -- ${pos} {
		1 { return [CompleteFromList ${text} {append clear}] }
		default {
			set sub [Lindex ${line} 1]
			set prev [PreviousWord ${start} ${line}]
			switch -- ${sub} {
				append {
					switch -- ${prev} {
						-displayof {
							return [CompleteFromList ${text} [ToplevelWindows]]
						}
						-format { return [DisplayHints <format>] }
						-type { return [DisplayHints <type>] }
						default {
							set opts [RemoveUsedOptions ${line} {
								-displayof -format -type --
							} {--}]
							if {![string length ${opts}]} {
								return [DisplayHints <data>]
							} else {
								return [CompleteFromList ${text} ${opts}]
							}
						}
					}
				}
				clear {
					switch -- ${prev} {
						-displayof {
							return [CompleteFromList ${text} [ToplevelWindows]]
						}
						default {
							return [CompleteFromList ${text} \
							[RemoveUsedOptions ${line} {
								-displayof
							}]]
						}
					}
				}
			}
		}
	}
}

proc complete(destroy) {text start end line pos mod} {
	set remaining [RemoveUsedOptions ${line} [WidgetChildren ${text}]]
	return [CompleteFromList ${text} ${remaining}]
}

proc complete(entry) {text start end line pos mod} {
	switch -- ${pos} {
		1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
		default {
			return [CompleteWidgetConfigurations ${text} ${start} ${line} {
				-background -borderwidth -cursor -exportselection
3620
3621
3622
3623
3624
3625
3626




























































































3627
3628
3629
3630
3631
3632
3633
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







				-highlightthickness -relief -takefocus -background
				-class -colormap -container -height -visual -width
			}]
		}
	}
	return ""
}

proc complete(image) {text start end line pos mod} {
set sub [Lindex ${line} 1]
	switch -- ${pos} {
		1 { return [TrySubCmds ${text} image] }
		2 {
			switch -- ${sub} {
				create { return [CompleteFromList ${text} [image types]] }
				delete -
				height -
				type -
				width { return [CompleteFromList ${text} [image names]] }
				names {}
				types {}
			}
		}
		3 {
			switch -- ${sub} {
				create {
					set type [Lindex ${line} 2]
					switch -- ${type} {
						bitmap {
							return [CompleteFromList ${text} {
								?name? -background -data -file
								-foreground -maskdata -maskfile
							}]
						}
						photo {
							return [CompleteFromList ${text} {
								?name? -data -format -file -gamma
								-height -palette -width
							}]
						}
						default {}
					}
				}
				delete { return [CompleteFromList ${text} [image names]] }
				default {}
			}
		}
		default {
			switch -- ${sub} {
				create {
					set type [Lindex ${line} 2]
					set prev [PreviousWord ${start} ${line}]
					# puts stderr prev=$prev
					switch -- ${type} {
						bitmap {
							switch -- ${prev} {
								-background -
								-foreground { return [DisplayHints <color>] }
								-data -
								-maskdata { return [DisplayHints <string>] }
								-file -
								-maskfile { return "" }
								default {
									return [CompleteFromList ${text} \
									[RemoveUsedOptions ${line} {
										-background -data -file
										-foreground -maskdata -maskfile
									}]]
								}
							}
						}
						photo {
							switch -- ${prev} {
								-data { return [DisplayHints <string>] }
								-file { return "" }
								-format { return [DisplayHints <format-name>] }
								-gamma { return [DisplayHints <value>] }
								-height -
								-width { return [DisplayHints <number>] }
								-palette {
									return [DisplayHints <palette-spec>]
								}
								default {
									return [CompleteFromList ${text} \
									[RemoveUsedOptions ${line} {
										-data -format -file -gamma
										-height -palette -width
									}]]
								}
							}
						}
					}
				}
				delete { return [CompleteFromList ${text} [image names]] }
				default {}
			}
		}
	}
}

proc complete(label) {text start end line pos mod} {
	switch -- ${pos} {
		1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
		default {
			return [CompleteWidgetConfigurations ${text} ${start} ${line} {
				-anchor -background -bitmap -borderwidth -cursor -font
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867

3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878















































































































































































































































































































































































































































































































































































































3879
4038
4039
4040
4041
4042
4043
4044





































































4045
4046
4047
4048

4049



4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




-
+
-
-
-








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

				-use -visual -width
			}]
		}
	}
	return ""
}

proc complete(image) {text start end line pos mod} {
set sub [Lindex ${line} 1]
	switch -- ${pos} {
		1 { return [CompleteFromList ${text} [TrySubCmds image]] }
		2 {
			switch -- ${sub} {
				create { return [CompleteFromList ${text} [image types]] }
				delete -
				height -
				type -
				width { return [CompleteFromList ${text} [image names]] }
				names {}
				types {}
			}
		}
		3 {
			switch -- ${sub} {
				create {
					set type [Lindex ${line} 2]
					switch -- ${type} {
						bitmap {
							return [CompleteFromList ${text} {
								?name? -background -data -file
								-foreground -maskdata -maskfile
							}]
						}
						photo {
							# TODO
						}
						default {}
					}
				}
				default {}
			}
		}
		default {
			switch -- ${sub} {
				create {
					set type [Lindex ${line} 2]
					set prev [PreviousWord ${start} ${line}]
					# puts stderr prev=$prev
					switch -- ${type} {
						bitmap {
							switch -- ${prev} {
								-background -
								-foreground { return [DisplayHints <color>] }
								-data -
								-maskdata { return [DisplayHints <string>] }
								-file -
								-maskfile { return "" }
								default {
									return [CompleteFromList ${text} \
									[RemoveUsedOptions ${line} {
										-background -data -file
										-foreground -maskdata -maskfile
									}]]
								}
							}
						}
						photo {
							# TODO
						}
					}
				}
			}
		}
	}
}

proc complete(winfo) {text start end line pos mod} {
	set cmd [lindex ${line} 1]
	switch -- ${pos} {
		1 {
			set cmds [TrySubCmds winfo]
			return [TrySubCmds ${text} winfo]
			if {[llength ${cmds}]} {
				return [TryFromList ${text} ${cmds}]
			}
		}
		2 {
			return [TryFromList ${text} [WidgetChildren ${text}]]
		}
	}
	return ""
}

# ==== ObjCmd completers ==========================
#
# @note when a proc is commented out, the fallback
#       completers do the job rather well.
#
# =================================================


# proc ImageObj {text start end line pos} {
# 	set type [image type [Lindex ${line} 0]]
# 	switch -- ${type} {
# 		bitmap {}
# 		photo {}
# 	}
# 	return ""
# }

# proc ButtonObj {text start end line pos} {
# 	return ""
# }

proc CompleteFromBitmaps text {
	set inames [image names]
	set bitmaps ""
	foreach name $inames {
		if {"bitmap" == [image type $name]} {
			lappend bitmaps ${name}
		}
	}
	if {[string length ${bitmaps}]} {
		return [CompleteFromList \
		${text} ${bitmaps}]
	} else {
		return [DisplayHints <bitmaps>]
	}
}

proc CompleteAnchor text {
	return [CompleteFromList ${text} {
		n ne e se s sw w nw center
	}]
}

proc CompleteJustify text {
	return [CompleteFromList ${text} {
		left center right
	}]
}

proc CanvasItem {text start end line pos prev type} {

	switch -- ${type} {
		arc {
			switch -- ${prev} {
				-extent { return [DisplayHints <degrees>] }
				-fill -
				-outline { return [DisplayHints <color>] }
				-outlinestipple -
				-stipple {
					set inames [image names]
					set bitmaps ""
					foreach name $inames {
						if {"bitmap" == [image type $name]} {
							lappend bitmaps ${name}
						}
					}
					if {[string length ${bitmaps}]} {
						return [CompleteFromList \
						${text} ${bitmaps}]
					} else {
						return [DisplayHints <bitmaps>]
					}
				}
				-start { return [DisplayHints <degrees>] }
				-style { return [DisplayHints <type>] }
				-tags { return [DisplayHints <tagList>] }
				-width { return [DisplayHints <outlineWidth>] }
				default {
					return [CompleteFromList ${text} \
					[RemoveUsedOptions ${line} {
						-extent -fill -outline -outlinestipple
						-start -stipple -style -tags -width
					}]]
				}
			}
		}
		bitmap {
			switch -- ${prev} {
				-anchor { return [CompleteAnchor ${text}] }
				-background -
				-foreground { return [DisplayHints <color>] }
				-bitmap { return [CompleteFromBitmaps ${text}] }
				-tags { return [DisplayHints <tagList>] }
				default {
					return [CompleteFromList ${text} \
					[RemoveUsedOptions ${line} {
						-anchor -background -bitmap
						-foreground -tags
					}]]
				}
			}
		}
		image {
			switch -- ${prev} {
				-anchor { return [CompleteAnchor ${text}] }
				-image {
					set images [image names]
					if {[string length ${images}]} {
						return [CompleteFromList ${text} ${images}]
					} else {
						return [DisplayHints <image>]
					}
				}
				-tags { return [DisplayHints <tagList>] }
				default {
					return [CompleteFromList ${text} \
					[RemoveUsedOptions ${line} {
						-anchor -image -tags
					}]]
				}
			}
		}
		line {
			switch -- ${prev} {
				-arrow {
					return [CompleteFromList ${text} {
						none first last both
					}]
				}
				-arrowshape { return [DisplayHints <shape>] }
				-capstyle {
					return [CompleteFromList ${text} {
						butt projecting round
					}]
				}
				-fill { return [DisplayHints <color>] }
				-joinstyle {
					return [CompleteFromList ${text} {
						bevel miter round
					}]
				}
				-smooth { return [CompleteBoolean ${text}] }
				-splinesteps { return [DisplayHints <number>] }
				-stipple { return [CompleteFromBitmaps ${text}] }
				-tags { return [DisplayHints <tagList>] }
				-width { return [DisplayHints <lineWidth>] }
				default {
					return [CompleteFromList ${text} \
					[RemoveUsedOptions ${line} {
						-arrow -arrowshape -capstyle -fill -joinstyle
						-smooth -splinesteps -stipple -tags -width
					}]]
				}
			}
		}
		oval {
			switch -- ${prev} {
				-fill -
				-outline { return [DisplayHints <color>] }
				-stipple { return [CompleteFromBitmaps ${text}] }
				-tags { return [DisplayHints <tagList>] }
				-width { return [DisplayHints <lineWidth>] }
				default {
					return [CompleteFromList ${text} \
					[RemoveUsedOptions ${line} {
						-fill -outline -stipple -tags -width
					}]]
				}
			}
		}
		polygon {
			switch -- ${prev} {
				-fill -
				-outline { return [DisplayHints <color>] }
				-smooth { return [CompleteBoolean ${text}] }
				-splinesteps { return [DisplayHints <number>] }
				-stipple { return [CompleteFromBitmaps ${text}] }
				-tags { return [DisplayHints <tagList>] }
				-width { return [DisplayHints <outlineWidth>] }
				default {
					return [CompleteFromList ${text} \
					[RemoveUsedOptions ${line} {
						-fill -outline -smooth -splinesteps
						-stipple -tags -width
					}]]
				}
			}
		}
		rectangle {
			switch -- ${prev} {
				-fill -
				-outline { return [DisplayHints <color>] }
				-stipple { return [CompleteFromBitmaps ${text}] }
				-tags { return [DisplayHints <tagList>] }
				-width { return [DisplayHints <lineWidth>] }
				default {
					return [CompleteFromList ${text} \
					[RemoveUsedOptions ${line} {
						-fill -outline -stipple -tags -width
					}]]
				}
			}
		}
		text {
			switch -- ${prev} {
				-anchor { return [CompleteAnchor ${text}] }
				-fill { return [DisplayHints <color>] }
				-font { return [DisplayHints <font>] }
				-justify { return [CompleteJustify ${text}] }
				-stipple { return [CompleteFromBitmaps ${text}] }
				-tags { return [DisplayHints <tagList>] }
				-text { return [DisplayHints <string>] }
				-width { return [DisplayHints <lineLength>] }
				default {
					return [CompleteFromList ${text} \
					[RemoveUsedOptions ${line} {
						-anchor -fill -font -justify
						-stipple -tags -text -width
					}]]
				}
			}
		}
		window {
			switch -- ${prev} {
				-anchor { return [CompleteAnchor ${text}] }
				-height { return [DisplayHints <pixels>] }
				-tags { return [DisplayHints <tagList>] }
				-width { return [DisplayHints <lineWidth>] }
				-window {
					return [TryFromList ${text} [WidgetChildren ${text}]]
				}
				default {
					return [CompleteFromList ${text} \
					[RemoveUsedOptions ${line} {
						-anchor -height -tags -width -window
					}]]
				}
			}
		}
	}
}

proc CanvasObj {text start end line pos} {
	set sub [Lindex ${line} 1]
	set prev [PreviousWord ${start} ${line}]
	if {1 == $pos} {
		return; # let the fallback routines do the job.
	}
	switch -- ${sub} {
		addtag {
			switch -- ${pos} {
				2 { return [DisplayHints <tag>] }
				3 {
					return [CompleteFromList ${text} {
						above all below closest enclosed
						overlapping withtag
					}]
				}
				default {
					set search [Lindex ${line} 3]
					switch -- ${search} {
						all {}
						above -
						withtag -
						below { return [DisplayHints <tagOrId>] }
						closest {
							switch -- ${pos} {
								4 { return [DisplayHints <x>] }
								5 { return [DisplayHints <y>] }
								6 { return [DisplayHints ?halo?] }
								7 { return [DisplayHints ?start?] }
							}
						}
						enclosed -
						overlapping {
							switch -- ${pos} {
								4 { return [DisplayHints <x1>] }
								5 { return [DisplayHints <y1>] }
								6 { return [DisplayHints <x2>] }
								7 { return [DisplayHints <y2>] }
							}
						}
					}
				}
			}
		}
		bbox {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
				default { return [DisplayHints ?tagOrId?] }
			}
		}
		bind {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
				3 {
					set fulltext [Lindex ${line} 3]
					return [CompleteSequence ${text} ${fulltext}]
					# return [DisplayHints ?sequence?]
				}
				default {
					return [BraceOrCommand ${text} \
					${start} ${end} ${line} ${pos} ${text}]
				}
			}
		}
		canvasx {
			switch -- ${pos} {
				2 { return [DisplayHints <screenx>] }
				3 { return [DisplayHints ?gridspacing?] }
			}
		}
		canvasy {
			switch -- ${pos} {
				2 { return [DisplayHints <screeny>] }
				3 { return [DisplayHints ?gridspacing?] }
			}
		}
		coords {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
				default {
					switch [expr ${pos} % 2] {
						1 { return [DisplayHints ?x?] }
						0 { return [DisplayHints ?y?] }
					}
				}
			}
		}
		dchars {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
				3 { return [DisplayHints <first>] }
				4 { return [DisplayHints ?last?] }
			}
		}
		delete { return [DisplayHints ?tagOrId?] }
		dtag {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
				3 { return [DisplayHints ?tagToDelete?] }
			}
		}
		find {
			# let the fallback routines do the job.
		}
		focus {
			switch -- ${pos} {
				2 { return [DisplayHints ?tagOrId?] }
			}
		}
		gettags {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
			}
		}
		icursor -
		index {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
				3 { return [DisplayHints <index>] }
			}
		}
		insert {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
				3 { return [DisplayHints <beforeThis>] }
				4 { return [DisplayHints <string>] }
			}
		}
		lower {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
				3 { return [DisplayHints ?belowThis?] }
			}
		}
		move {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
				3 { return [DisplayHints <xAmount>] }
				4 { return [DisplayHints <yAmount>] }
			}
		}
		postscript {
			switch -- ${prev} {
				-file { return "" }
				-colormap -
				-colormode -
				-fontmap -
				-height -
				-pageanchor -
				-pageheight -
				-pagewidth -
				-pagex -
				-pagey -
				-rotate -
				-width -
				-x -
				-y { return [DisplayHints <[String range ${prev} 1 end]>] }
				default {
					return [CompleteFromList ${text} \
					[RemoveUsedOptions ${line} {
						-colormap -colormode -file -fontmap -height
						-pageanchor -pageheight -pagewidth -pagex
						-pagey -rotate -width -x -y
					}]]
				}
			}
		}
		raise {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
				3 { return [DisplayHints ?aboveThis?] }
			}
		}
		scale {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
				3 { return [DisplayHints <xOrigin>] }
				4 { return [DisplayHints <yOrigin>] }
				5 { return [DisplayHints <xScale>] }
				6 { return [DisplayHints <yScale>] }
			}
		}
		scan {
			switch -- ${pos} {
				2 { return [CompleteFromList ${text} {mark dragto}] }
				3 { return [DisplayHints <x>] }
				4 { return [DisplayHints <y>] }
			}
		}
		select {
			switch -- ${pos} {
				2 {
					return [CompleteFromList ${text} {
						adjust clear item from to
					}]
				}
				3 {
					set sub [Lindex ${line} 2]
					switch -- ${sub} {
						adjust -
						from -
						to { return [DisplayHints <tagOrId>] }
					}
				}
				4 {
					set sub [Lindex ${line} 2]
					switch -- ${sub} {
						adjust -
						from -
						to { return [DisplayHints <index>] }
					}
				}
			}
		}
		xview -
		yview {
			switch -- ${pos} {
				2 { return [CompleteFromList ${text} {moveto scroll}] }
				3 {
					switch -- ${prev} {
						moveto { return [DisplayHints <fraction>] }
						scroll { return [DisplayHints <number>] }
					}
				}
				4 {
					set subcmd [Lindex ${line} 2]
					switch -- ${subcmd} {
						scroll { return [DisplayHints <what>] }
					}
				}
			}
		}
		create {
			switch -- ${pos} {
				2 {
					return [CompleteFromList ${text} {
						arc bitmap image line oval
						polygon rectangle text window
					}]
				}
				3 { return [DisplayHints <x1>] }
				4 { return [DisplayHints <y1>] }
				5 {
					set type [Lindex ${line} 2]
					switch -- ${type} {
						arc -
						oval -
						rectangle { return [DisplayHints <x2>] }
						# TODO items with more than 4 coordinates
						default {
							return [CanvasItem ${text} ${start} \
							${end} ${line} ${pos} ${prev} ${type}]
						}
					}
				}
				6 {
					set type [Lindex ${line} 2]
					switch -- ${type} {
						arc -
						oval -
						rectangle { return [DisplayHints <y2>] }
						# TODO items with more than 4 coordinates
						default {
							return [CanvasItem ${text} ${start} \
							${end} ${line} ${pos} ${prev} ${type}]
						}
					}
				}
				default {
					set type [Lindex ${line} 2]
					# TODO items with more than 4 coordinates
					return [CanvasItem ${text} ${start} \
					${end} ${line} ${pos} ${prev} ${type}]
				}
			}
		}
		itemconfigure -
		itemcget {
			switch -- ${pos} {
				2 { return [DisplayHints <tagOrId>] }
				default {

					set id [Lindex ${line} 2]
					set type [[Lindex ${line} 0] type ${id}]
					if {![string length ${type}]} {
						return ""; # no such element
					}

					return [CanvasItem ${text} ${start} \
					${end} ${line} ${pos} ${prev} ${type}]
				}
			}
		}
	}
	return ""
}

proc EntryObj {text start end line pos} {
	set sub [Lindex ${line} 1]
	set prev [PreviousWord ${start} ${line}]
	if {1 == $pos} {
		return; # let the fallback routines do the job.
	}
	switch -- ${sub} {
		bbox {}
		cget {}
		configure {}
		delete {}
		get {}
		icursor {}
		index {}
		insert {}
		scan {
			switch -- ${pos} {
				2 { return [CompleteFromList ${text} {mark dragto}] }
				3 { return [DisplayHints <x>] }
				4 { return [DisplayHints <y>] }
			}
		}
		selection {}
		xview -
		yview {
			switch -- ${pos} {
				2 { return [CompleteFromList ${text} {moveto scroll}] }
				3 {
					switch -- ${prev} {
						moveto { return [DisplayHints <fraction>] }
						scroll { return [DisplayHints <number>] }
					}
				}
				4 {
					set subcmd [Lindex ${line} 2]
					switch -- ${subcmd} {
						scroll { return [DisplayHints <what>] }
					}
				}
			}
		}
	}
	return ""
}

# proc CheckbuttonObj {text start end line pos} {
# }

# proc FrameObj {text start end line pos} {
# 	return ""
# }

}; # namespace tclreadline