Check-in [dc9268f6ad]
Not logged in
Overview
Comment:Harmonize style in all Tcl files Brace arguments of if/expr constructs
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | origin/devel
Files: files | file ages | folders
SHA1: dc9268f6ad4c91f21cb139567a0cb8b4a018c48b
User & Date: quentin@minster.io on 2014-03-17 21:17:14
Other Links: branch diff | manifest | tags
Context
2014-03-17
21:17
Enhance a bit of logic (expr should be cheaper than regexp) check-in: 320bbe752c user: quentin@minster.io tags: trunk, origin/devel
21:17
Harmonize style in all Tcl files Brace arguments of if/expr constructs check-in: dc9268f6ad user: quentin@minster.io tags: trunk, origin/devel
2014-02-26
22:37
Cleanup of compilation warnings * Add the -Wall compilation flag * Use rl_ding() instead of undeclared ding() check-in: a9511ba2db user: quentin@minster.io tags: trunk, origin/devel
Changes

Modified tclreadlineCompleter.tcl from [1ea8a61e03] to [b445227807].

127
128
129
130
131
132
133



134
135
136
137
138
139
140
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143







+
+
+







    ::proc AssureTraceWindow {} {
        variable trace
        if {![info exists trace]} {
            return 0
        }
        if {!$trace} {
            return 0
            }
            if {[catch {package require Tk}]} {
                return 0
        }
        if {![winfo exists .tclreadline_trace.text]} {
            toplevel .tclreadline_trace
            text .tclreadline_trace.text \
                -yscrollcommand { tclreadline::TraceReconf } \
                -wrap none
            scrollbar .tclreadline_trace.scroll \
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
241

242
243
244

245
246
247
248
249
250
251
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
241
242
243
244
245
246







-
-
-
-
+
+

-

-
-

-
-
+
+
-


-
+






-
+
-
-
+
-

-
+

-
+














-
-
+
+

-
-
-
+
+
+

-
+


-
+







# completer.
# If inhibit is non-zero, the result will be
# formatted such that readline will not insert
# a space after a complete (single) match.
#
proc TryFromList {text lst {allow ""} {inhibit 0}} {

    # puts stderr "(CompleteFromList) \ntext=|$text|"
    # puts stderr "(CompleteFromList) lst=|$lst|"
    set pre [GetQuotedPrefix ${text}]
    set matches [MatchesFromList ${text} ${lst} ${allow}]
        set pre [GetQuotedPrefix $text]
        set matches [MatchesFromList $text $lst $allow]

    # puts stderr "(CompleteFromList) matches=|$matches|"
    if {1 == [llength $matches]} { ; # unique match
        # puts stderr \nunique=$matches\n
        # puts stderr "\n|${pre}${matches}[Right ${pre}]|\n"
        set null [string index $matches 0]
        if {("<" == ${null} || "?" == ${null}) && \
            -1 == [string first ${null} ${allow}]
            if {("<" == $null || "?" == $null)
                    && -1 == [string first $null $allow]} {
        } {
            set completion [string trim "[list $text] $lst"]
        } else {
            set completion [string trim ${pre}${matches}[Right ${pre}]]
                set completion [string trim ${pre}${matches}[Right $pre]]
        }
        if {$inhibit} {
            return [list $completion {}]
        } else {
            return $completion
        }
    } elseif {"" != ${matches}} {
        } elseif {"" != $matches} {
        # puts stderr \nmore=$matches\n
        set longest [CompleteLongest ${matches}]
            set longest [CompleteLongest $matches]
        # puts stderr longest=|$longest|
        if {"" == $longest} {
            return [string trim "[list $text] ${matches}"]
                return [string trim "[list $text] $matches"]
        } else {
            return [string trim "${pre}${longest} ${matches}"]
                return [string trim "${pre}${longest} $matches"]
        }
    } else {
        return ""; # nothing to complete
    }
}

#**
# CompleteFromList will never return an empty string.
# completes, if a completion can be done, or ring
# the bell if not. If inhibit is non-zero, the result
# will be formatted such that readline will not insert
# a space after a complete (single) match.
#
proc CompleteFromList {text lst {allow ""} {inhibit 0}} {
    set result [TryFromList ${text} ${lst} ${allow} ${inhibit}]
    if {![llength ${result}]} {
        set result [TryFromList $text $lst $allow $inhibit]
        if {![llength $result]} {
        Alert
        # return [string trim [list ${text}] ${lst}"]
        if {[llength ${lst}]} {
            return [string trim "${text} ${lst}"]
            # return [string trim [list $text] $lst"]
            if {[llength $lst]} {
                return [string trim "$text $lst"]
        } else {
            return [string trim [list ${text} {}]]
                return [string trim [list $text {}]]
        }
    } else {
        return ${result}
            return $result
    }
}

#**
# CompleteBoolean does a CompleteFromList
# with a list of all valid boolean values.
#
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284







-
+







    }

    set executables 0
    foreach dir [split $env(PATH) :] {
        if {[catch [list set files [glob -nocomplain ${dir}/*]]]} { continue }
        foreach file $files {
            if {[file executable $file]} {
                lappend executables [file tail ${file}]
                    lappend executables [file tail $file]
            }
        }
    }
}

#**
# build a list hosts from the /etc/hosts file.
298
299
300
301
302
303
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
293
294
295
296
297
298
299





300
301
302
303
304
305
306

307
308
309
310

311
312
313
314
315
316
317
318

319
320
321
322
323
324
325
326







-
-
-
-
-
+
+
+
+
+


-
+



-
+







-
+







    # read the host table only once.
    #
    variable hosts
    if {![info exists hosts]} {
        catch {
            set hosts ""
            set id [open /etc/hosts r]
            if {0 != ${id}} {
                while {-1 != [gets ${id} line]} {
                    regsub {#.*} ${line} {} line
                    if {[llength ${line}] >= 2} {
                        lappend hosts [lindex ${line} 1]
                if {0 != $id} {
                    while {-1 != [gets $id line]} {
                        regsub {#.*} $line {} line
                        if {[llength $line] >= 2} {
                            lappend hosts [lindex $line 1]
                    }
                }
                close ${id}
                    close $id
            }
        }
    }
    return ${hosts}
        return $hosts
}

#**
# never return an empty string, never complete.
# This is useful for showing options lists for example.
#
proc DisplayHints {lst} {
    return [string trim "{} ${lst}"]
        return [string trim "{} $lst"]
}

#**
# find (partial) matches for `text' in `lst'. Ring
# the bell and return the whole list, if the user
# tries to complete ?..? options or <..> hints.
#
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
590
591
592
593
594


595
596
597
598
599
600
601
602
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
633
634
635
636
637
638

639
640
641
642
643

644
645
646
647


648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672

673
674
675
676
677

678
679

680
681
682
683
684
685
686



687
688
689

690
691
692

693
694
695

696
697
698
699
700
701
702
703

704
705
706

707
708

709
710
711

712
713
714
715
716
717



718
719

720
721
722
723
724
725
726
727


728
729
730
731
732
733

734
735
736
737
738


739
740
741
742
743
744
745



746
747
748
749
750
751
752
753
754
755
756
757



758
759
760


761
762
763
764

765
766
767
768
769
770
771
772
773
774

775
776
777
778

779
780

781
782
783
784
785

786
787
788
789
790
791
792
793
794
795
796

797
798
799
800
801
802
803
804
805
806

807
808
809
810
811
812
813

814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829

830
831
832
833
834
835
836
837

838
839

840
841
842
843

844
845
846
847

848
849

850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870

871
872
873
874
875
876
877
878
879
880
881
882
883

884
885
886
887

888
889
890
891
892
893
894
895
896


897
898

899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928

929
930
931

932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
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
590

591


592
593
594
595
596
597
598
599
600
601
602

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
633
634
635
636
637
638
639

640
641
642








643
644
645
646
647

648
649

650
651
652
653
654



655
656
657
658
659

660
661
662

663

664

665
666
667
668
669
670



671
672
673

674
675

676
677
678

679
680

681



682
683
684
685

686
687
688
689
690
691
692


693
694
695
696
697
698
699

700
701
702
703


704
705
706
707
708
709



710
711
712
713
714
715
716
717
718
719
720
721



722
723
724



725
726
727
728
729

730
731
732
733
734
735
736
737
738
739

740
741
742


743
744

745
746
747
748
749

750
751
752
753
754
755
756
757
758
759


760
761
762
763
764

765
766
767
768

769
770
771
772
773
774
775

776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791

792
793
794
795
796
797
798
799

800
801

802
803
804
805

806
807
808
809

810
811

812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832

833
834
835
836
837
838
839
840
841
842
843
844
845

846
847
848
849

850
851
852
853
854
855
856
857


858
859
860

861
862
863
864
865
866
867
868
869
870
871
872
873
874
875

876
877
878
879
880
881
882
883
884
885
886
887
888
889

890
891
892

893
894
895
896
897
898
899
900
901
902
903
904

905
906
907
908
909
910
911







-
-

-
-
+
+















-












-
+

-
+



-
+
-






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


-
-
+
+
-
-
+




-
+
-
-
-

-
+





-
-
+
+

-
+
-
-
+


-
-
+
+
-
-
+



-
+







-
+




-








-
+



-
-
-
+
+
+
+
+


-
+








-








-
+



-
-
+
+

-
-
+
+

-
+

-
-
+
+











-



-
+




-
+

-
-
+
+



-
+



-
+



-
+








-
+

-
-
+
+

-
-
+
+




-
+









-
+

-
-
+
+


-
-
+
+




-
+
-


+


-


-
+




-
-
+
+







-
-
-
+
+
+


-
+

-
+
-
-











-
+

-
+












-
+




-
+

-
-
-
+
+













-



-
-
-
-
-
-
-
-
+




-
+

-
+




-
-
-
+
+
+


-
+


-
+
-

-
+





-
-
-
+


-
+

-
+


-
+

-

-
-
-
+
+
+

-
+






-
-
+
+





-
+



-
-
+
+




-
-
-
+
+
+









-
-
-
+
+
+
-
-
-
+
+



-
+









-
+


-
-
+

-
+




-
+









-
-
+




-




-
+






-
+















-
+







-
+

-
+



-
+



-
+

-
+




















-
+












-
+



-
+







-
-
+
+

-
+














-














-
+


-
+











-







    set null [string index $text 0]
    foreach char {< ?} {
        if {$char == $null && -1 == [string first $char $allow]} {
            Alert
            return $lst
        }
    }
    # puts stderr "(MatchesFromList) text=$text"
    # puts stderr "(MatchesFromList) lst=$lst"
    foreach word $lst {
        if {[string match ${text}* ${word}]} {
            lappend result ${word}
            if {[string match ${text}* $word]} {
                lappend result $word
        }
    }
    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
# @date    Sep-14-1999
#
proc TrySubCmds {text cmd} {

    set trystring ----

    # 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 ""} {
        for {set str $trystring} {1} {set str ""} {

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

        if {$code} {
            set tcmd [string trim ${cmd}]
                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]
                         $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}
                    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}]
                    if {[string length $result]
                            && -1 == [string first $trystring $result]} {
                } {
                    return [TryFromList ${text} ${result}]
                        return [TryFromList $text $result]
                }

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

            } {

                # XXX see tclIndexObj.c XXX
                if {-1 == [string first ${trystring} ${hint}]} {
                    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} {
                    set msglst [split $msg \n]
                    foreach line $msglst {
                    if {[regexp "${tcmd}\[ \t\]\+\(\[^ \t\]*\)\[^:\]*$" \
                        ${line} all sub]
                                 $line all sub]} {
                    } {
                        lappend result [list ${sub}]
                            lappend result [list $sub]
                    }
                }
                if {[string length ${result}] && \
                    -1 == [string first ${trystring} ${result}]
                    if {[string length $result]
                            && -1 == [string first $trystring $result]} {
                } {
                    return [TryFromList ${text} ${result}]
                        return [TryFromList $text $result]
                }
            }
        }
        if {"" == ${str}} {
            if {"" == $str} {
            break
        }
    }
    return ""
}

#**
# try to get casses for commands which
    # try to get classes for commands which
# allow `configure' (cget).
# @param  command.
# @param  optionsT where the table will be stored.
# @return number of options
# @date   Sat-Sep-18
#
proc ClassTable {cmd} {

    # 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]} {
        if {[catch [list set option_table [eval $cmd configure]] msg]} {
        return ""
    }
    set classes ""
    foreach optline ${option_table} {
        if {5 != [llength ${optline}]} continue else {
            lappend classes [lindex ${optline} 2]
        foreach optline $option_table {
            if {5 != [llength $optline]} {
                continue
            } else {
                lappend classes [lindex $optline 2]
        }
    }
    return ${classes}
        return $classes
}

#**
# 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]} {
        if {[catch [list set option_table [eval $cmd configure]] msg]} {
        return 0
    }
    set retval 0
    foreach optline ${option_table} {
        if {5 == [llength ${optline}]} {
        foreach optline $option_table {
            if {5 == [llength $optline]} {
            # tk returns a list of length 5
            lappend options(switches) [lindex ${optline} 0]
            lappend options(value)    [lindex ${optline} 4]
                lappend options(switches) [lindex $optline 0]
                lappend options(value)    [lindex $optline 4]
            incr retval
        } elseif {3 == [llength ${optline}]} {
            } elseif {3 == [llength $optline]} {
            # itcl returns a list of length 3
            lappend options(switches) [lindex ${optline} 0]
            lappend options(value)    [lindex ${optline} 2]
                lappend options(switches) [lindex $optline 0]
                lappend options(value)    [lindex $optline 2]
            incr retval
        }
    }
    return $retval
}

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

    upvar ${resultT} result
        upvar $resultT result
    set result ""

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

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

    # 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]]
        set cmd [lrange $lst 0 [expr {$idx - 1}]]

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

        set prev [PreviousWord ${start} ${line}]
        if {-1 != [set found [lsearch -exact $options(switches) ${prev}]]} {
            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}]} {
                if {![llength $text]} {

                # check first, if the SpecificSwitchCompleter
                # knows something about this switch. (note that
                # `prev' contains the switch). The `0' as last
                # argument makes the SpecificSwitchCompleter
                # returning "" if it knows nothing specific
                # about this switch.
                #
                set values [SpecificSwitchCompleter \
                ${text} ${start} ${line} ${prev} 0]
                                    $text $start $line $prev 0]

                if [string length ${values}] {
                    set result ${values}
                    if [string length $values] {
                        set result $values
                    return 1
                } else {
                    set val [lindex $options(value) ${found}]
                    if [string length ${val}] {
                        set val [lindex $options(value) $found]
                        if [string length $val] {
                        # return the old value only, if it's non-empty.
                        # Use this double list to quote option
                        # values which have to be quoted.
                        #
                        set result [list [list ${val}]]
                            set result [list [list $val]]
                        return 1
                    } else {
                        set result ""
                        }
                        return 1
                    }
                }
            } else {
                set result [SpecificSwitchCompleter \
                ${text} ${start} ${line} ${prev} 1]
                                    $text $start $line $prev 1]
                return 1
            }

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

proc ObjectClassCompleter {text start end line pos resultT} {
    upvar ${resultT} result
    set cmd [Lindex ${line} 0]
    if {"." == [string index ${line} 0]} {
        upvar $resultT result
        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 {![catch [list set class [winfo class [Lindex $line 0]]]]} {
            if {[string length [info proc ${class}Obj]]} {
                set result [${class}Obj ${text} ${start} ${end} ${line} ${pos}]
                    set result [${class}Obj $text $start $end $line $pos]
                # puts stderr result=|$result|
                # joze, Thu Sep 30 16:43:17 1999
                if {[string length $result]} {
                    return 1
                } else {
                    return 0
                }
            } else {
                return 0
            }
        }
    }
    if {![catch {set type [image type $cmd]}]} {
        switch -- ${type} {
            switch -- $type {
            photo {
                set result [PhotoObj ${text} ${start} ${end} ${line} ${pos}]
                    set result [PhotoObj $text $start $end $line $pos]
                return 1
            }
            default {
                # let the fallback completers do the job.
                return 0
            }
        }
    }
    return 0
}

proc CompleteFromOptionsOrSubCmds {text start end line pos} {
    if [CompleteFromOptions ${text} ${start} ${line} from_opts] {
        if [CompleteFromOptions $text $start $line from_opts] {
        # always return, if CompleteFromOptions returns non-zero,
        # that means (configure|cget) were present. This ensures
        # that TrySubCmds will not configure something by chance.
        #
        return ${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 [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}]} {
        if {![string length $fullpart]} {

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

    } elseif {${post} == [String index ${text} end]} {
        } elseif {$post == [String index $text end]} {

        # 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}
                [expr {[CountChar $fullpart $pre] - [CountChar $fullpart $post]}]
            for {set i 0} {$i < $diff} {incr i} {
                append text $post
        }
        append text " "
        return ${text}
            return $text

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

    # TraceVar left
    # TraceVar right

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

proc FirstNonOption {line} {
    set expr_pos 1
    foreach word [lrange ${line} 1 end] {; # 0 is the command itself
        if {"-" != [string index ${word} 0]} {
        foreach word [lrange $line 1 end] {; # 0 is the command itself
            if {"-" != [string index $word 0]} {
            break
        } else {
            incr expr_pos
        }
    }
    return ${expr_pos}
        return $expr_pos
}

proc RemoveUsedOptions {line opts {terminate {}}} {
    if {[llength ${terminate}]} {
        if {[regexp -- ${terminate} ${line}]} {
        if {[llength $terminate]} {
            if {[regexp -- $terminate $line]} {
            return ""
        }
    }
    set new ""
    foreach word ${opts} {
        if {-1 == [string first ${word} ${line}]} {
            lappend new ${word}
        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}]
        set last [Lindex $line end]
        if {[string last $last $line] + [string length $last]
                == [string length $line]} {
    } {
        if {-1 != [lsearch ${opts} ${last}]} {
            lappend new ${last}
            if {-1 != [lsearch $opts $last]} {
                lappend new $last
        }
    }

    return [string trim ${new}]
        return [string trim $new]
}

proc Alert {} {
    ::tclreadline::readline bell
}

#**
# get the longest common completion
# e.g. str == {tcl_version tclreadline_version tclreadline_library}
# --> [CompleteLongest ${str}] == "tcl"
    # --> [CompleteLongest $str] == "tcl"
#
proc CompleteLongest {str} {
    # puts stderr str=$str
    set match0 [lindex ${str} 0]
        set match0 [lindex $str 0]
    set len0 [string length $match0]
    set no_matches [llength ${str}]
        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]} {
                if {$char != [string index [lindex $str $j] $i]} {
                break
            }
        }
        if {$j < $no_matches} {
            break
        } else {
            append part $char
        }
    }
    # puts stderr part=$part
    return ${part}
        return $part
}

proc SplitLine {start line} {
    set depth 0
    # puts stderr SplitLine
    for {set i $start} {$i >= 0} {incr i -1} {
        set c [string index $line $i]
        if {{;} == $c} {
            incr i; # discard command break character
            return [list [expr $start - $i] [String range $line $i end]]
                return [list [expr {$start - $i}] [String range $line $i end]]
        } elseif {{]} == $c} {
            incr depth
        } elseif {{[} == $c} {
            incr depth -1
            if {$depth < 0} {
                incr i; # discard command break character
                return [list [expr $start - $i] [String range $line $i end]]
                    return [list [expr {$start - $i}] [String range $line $i end]]
            }
        }
    }
    return ""
}

proc IsWhite {char} {
    if {" " == $char || "\n" == $char || "\t" == $char} {
        return 1
    } else {
        return 0
    }
}

proc PreviousWordOfIncompletePosition {start line} {
    return [lindex [ProperList [string range ${line} 0 ${start}]] end]
        return [lindex [ProperList [string range $line 0 $start]] end]
}

proc PreviousWord {start line} {
    incr start -1
    set found 0
    for {set i $start} {$i > 0} {incr i -1} {
        set c [string index $line $i]
        if {${found} && [IsWhite $c]} {
            if {$found && [IsWhite $c]} {
            break
        } elseif {!${found} && ![IsWhite $c]} {
            } elseif {!$found && ![IsWhite $c]} {
            set found 1
        }
    }
    return [string trim [string range ${line} $i $start]]
        return [string trim [string range $line $i $start]]
}

proc Quote {value left} {
    set right [Right ${left}]
        set right [Right $left]
    if {1 < [llength $value] && "" == $right} {
        return [list \"${value}\"]
            return [list \"$value\"]
    } else {
        return [list ${left}${value}${right}]
    }
}

# the following two channel proc's make use of
# the brandnew (Sep 99) `file channels' command
# but have some fallback behaviour for older
# tcl version.
#
proc InChannelId {text {switches ""}} {
    if [catch {set chs [file channels]}] {
        set chs {stdin}
    }
    set result ""
    foreach ch $chs {
        if {![catch {fileevent $ch readable}]} {
            lappend result $ch
        }
    }
    return [ChannelId ${text} <inChannel> $result $switches]
        return [ChannelId $text <inChannel> $result $switches]
}

proc OutChannelId {text {switches ""}} {
    if [catch {set chs [file channels]}] {
        set chs {stdout stderr}
    }
    set result ""
    foreach ch $chs {
        if {![catch {fileevent $ch writable}]} {
            lappend result $ch
        }
    }
    return [ChannelId ${text} <outChannel> $result $switches]
        return [ChannelId $text <outChannel> $result $switches]
}

proc ChannelId {text {descript <channelId>} {chs ""} {switches ""}} {
    if {"" == ${chs}} {
        if {"" == $chs} {
        # the `file channels' command is present
        # only in pretty new versions.
        #
        if [catch {set chs [file channels]}] {
            set chs {stdin stdout stderr}
        }
    }
    if {[llength [set channel [TryFromList ${text} "${chs} ${switches}"]]]} {
        return ${channel}
        if {[llength [set channel [TryFromList $text "$chs $switches"]]]} {
            return $channel
    } else {
        return [DisplayHints [string trim "${descript} ${switches}"]]
            return [DisplayHints [string trim "$descript $switches"]]
    }
}

proc QuoteQuotes {line} {
    regsub -all -- \" $line {\"} line
    regsub -all -- \{ $line {\{} line; # \}\} (keep the editor happy)
    return $line
}

#**
# get the word position.
# @return the word position
# @note will returned modified values.
# @sa EventuallyEvaluateFirst
# @date Sep-06-1999
#
# % p<TAB>
# % bla put<TAB> $b
# % put<TAB> $b
# part  == put
# start == 0
# end   == 3
# line  == "put $b"
# [PartPosition] should return 0
#
proc PartPosition {partT startT endT lineT} {

    upvar $partT part $startT start $endT end $lineT line
    EventuallyEvaluateFirst part start end line
    return [Llength [string range $line 0 [expr $start - 1]]]
        return [Llength [string range $line 0 [expr {$start - 1}]]]

#
#     set local_start [expr $start - 1]
    #     set local_start [expr {$start - 1}]
#     set local_start_chr [string index $line $local_start]
#     if {"\"" == $local_start_chr || "\{" == $local_start_chr} {
#         incr local_start -1
#     }
#
#     set pre_text [QuoteQuotes [string range $line 0 $local_start]]
#     return [llength $pre_text]
#
}

proc Right {left} {
    # puts left=$left
    if {"\"" == $left} {
        return "\""
    } elseif {"\\\"" == $left} {
        return "\\\""
    } elseif {"\{" == $left} {
        return "\}"
    } elseif {"\\\{" == $left} {
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985

986
987
988
989
990
991
992
993
994
995
996

997
998
999
1000

1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020



1021
1022

1023
1024

1025
1026

1027
1028
1029
1030
1031
1032
1033
1034
1035



1036
1037
1038

1039
1040
1041
1042
1043
1044
1045
1046
1047
1048




1049
1050
1051
1052


1053
1054
1055

1056
1057
1058
1059


1060
1061
1062
1063
1064
1065
1066
1067
1068
1069



1070
1071
1072

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
1109
1110


1111
1112
1113
1114
1115
1116
1117


1118
1119
1120
1121
1122
1123
1124


1125
1126
1127
1128



1129
1130
1131
1132
1133
1134
1135
1136

1137
1138
1139
1140
1141
1142





1143
1144
1145

1146
1147
1148
1149

1150
1151
1152
1153
1154
1155
1156


1157
1158

1159
1160
1161

1162
1163
1164
1165
1166
1167
1168

1169
1170
1171
1172


1173
1174
1175
1176
1177
1178
1179


1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198

1199
1200
1201

1202
1203
1204
1205
1206
1207
1208
920
921
922
923
924
925
926

927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944

945
946
947
948
949
950
951
952
953
954
955

956
957
958
959

960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977



978
979
980
981

982


983
984

985
986
987
988
989
990
991



992
993
994
995


996
997
998
999
1000
1001
1002




1003
1004
1005
1006
1007
1008


1009
1010
1011
1012

1013
1014
1015
1016
1017
1018
1019
1020
1021


1022
1023
1024



1025
1026
1027
1028
1029

1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047

1048
1049
1050
1051
1052
1053
1054
1055
1056

1057
1058
1059
1060
1061
1062
1063
1064
1065


1066
1067
1068
1069
1070
1071
1072


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
1109


1110
1111
1112

1113
1114
1115

1116
1117
1118
1119
1120
1121
1122

1123
1124



1125
1126
1127
1128
1129
1130
1131


1132
1133





1134
1135
1136








1137


1138
1139
1140

1141
1142
1143
1144
1145
1146
1147
1148







-


















-
+










-
+



-
+

















-
-
-
+
+
+

-
+
-
-
+

-
+






-
-
-
+
+
+

-
-
+






-
-
-
-
+
+
+
+


-
-
+
+


-
+




+
+


-
-



-
-
-
+
+
+


-
+

















-
+








-









-
-
+
+





-
-
+
+
-
-



-
-
+
+

-
-
-
+
+
+







-
+

-
-
-
-
-
+
+
+
+
+


-
+



-
+





-
-
+
+

-
+


-
+






-
+

-
-
-
+
+





-
-
+
+
-
-
-
-
-



-
-
-
-
-
-
-
-

-
-
+


-
+







        return \\$null
    } else {
        return {}
    }
}

proc CountChar {line char} {
    # puts stderr char=|$char|
    set found 0
    set pos 0
    while {-1 != [set pos [string first $char $line $pos]]} {
        incr pos
        incr found
    }
    return $found
}

#**
# make a proper tcl list from an icomplete
# string, that is: remove the junk. This is
# complementary to `IncompleteListRemainder'.
# e.g.:
#       for {set i 1} "
#  -->  for {set i 1}
#
proc ProperList {line} {
    set last [expr [string length $line] - 1]
        set last [expr {[string length $line] - 1}]
    for {set i $last} {$i >= 0} {incr i -1} {
        if {![catch {llength [string range $line 0 $i]}]} {
            break
        }
    }
    return [string range $line 0 $i]
}

#**
# return the last part of a line which
# prevents the line from beeing a list.
    # prevents the line from being a list.
# This is complementary to `ProperList'.
#
proc IncompleteListRemainder {line} {
    set last [expr [string length $line] - 1]
        set last [expr {[string length $line] - 1}]
    for {set i $last} {$i >= 0} {incr i -1} {
        if {![catch {llength [string range $line 0 $i]}]} {
            break
        }
    }
    incr i
    return [String range $line $i end]
}

#**
# save `lindex'. works also for non-complete lines
# with opening parentheses or quotes.
# usage as `lindex'.
# Eventually returns the Rest of an incomplete line,
# if the index is `end' or == [Llength $line].
#
proc Lindex {line pos} {
    if {[catch [list set sub [lindex ${line} ${pos}]]]} {
        if {"end" == ${pos} || [Llength ${line}] == ${pos}} {
            return [IncompleteListRemainder ${line}]
        if {[catch [list set sub [lindex $line $pos]]]} {
            if {"end" == $pos || [Llength $line] == $pos} {
                return [IncompleteListRemainder $line]
        }
        set line [ProperList ${line}]
            set line [ProperList $line]
        # puts stderr \nproper_line=|$proper_line|
        if {[catch [list set sub [lindex ${line} ${pos}]]]} { return {} }
            if {[catch [list set sub [lindex $line $pos]]]} { return {} }
    }
    return ${sub}
        return $sub
}

#**
# save `llength' (see above).
#
proc Llength {line} {
    if {[catch [list set len [llength ${line}]]]} {
        set line [ProperList ${line}]
        if {[catch [list set len [llength ${line}]]]} { return {} }
        if {[catch [list set len [llength $line]]]} {
            set line [ProperList $line]
            if {[catch [list set len [llength $line]]]} { return {} }
    }
    # puts stderr \nline=$line
    return ${len}
        return $len
}

#**
# save `lrange' (see above).
#
proc Lrange {line first last} {
    if {[catch [list set range [lrange ${line} ${first} ${last}]]]} {
        set rest [IncompleteListRemainder ${line}]
        set proper [ProperList ${line}]
        if {[catch [list set range [lindex ${proper} ${first} ${last}]]]} {
        if {[catch [list set range [lrange $line $first $last]]]} {
            set rest [IncompleteListRemainder $line]
            set proper [ProperList $line]
            if {[catch [list set range [lindex $proper $first $last]]]} {
            return {}
        }
        if {"end" == ${last} || [Llength ${line}] == ${last}} {
            append sub " ${rest}"
            if {"end" == $last || [Llength $line] == $last} {
                append sub " $rest"
        }
    }
    return ${range}
        return $range
}

#**
# Lunique -- remove duplicate entries from a sorted list
    # Only useful prior to Tcl 8.3 when lsort didn't have the
    # -unique flag
# @param   list
# @return  unique list
# @author  Johannes Zellner
# @date    Sep-19-1999
#
proc Lunique lst {
    set unique ""
    foreach element ${lst} {
        if {${element} != [lindex ${unique} end]} {
            lappend unique ${element}
        foreach element $lst {
            if {$element != [lindex $unique end]} {
                lappend unique $element
        }
    }
    return ${unique}
        return $unique
}

#**
# string function, which works also for older versions
# of tcl, which don't have the `end' index.
# I tried also defining `string' and thus overriding
# the builtin `string' which worked, but slowed down
# things considerably. So I decided to call `String'
# only if I really need the `end' index.
#
proc String args {
    if {[info tclversion] < 8.2} {
        switch [lindex $args 1] {
            range -
            index {
                if {"end" == [lindex $args end]} {
                    set str [lindex $args 2]
                    lreplace args end end [expr [string length $str] - 1]
                        lreplace args end end [expr {[string length $str] - 1}]
                }
            }
        }
    }
    return [eval string $args]
}

proc StripPrefix {text} {
    # puts "(StripPrefix) text=|$text|"
    set null [string index $text 0]
    if {"\"" == $null || "\{" == $null} {
        return [String range $text 1 end]
    } else {
        return $text
    }
}

proc VarCompletion {text {level -1}} {
    if {"#" != [string index ${level} 0]} {
        if {-1 == ${level}} {
        if {"#" != [string index $level 0]} {
            if {-1 == $level} {
            set level [info level]
        } else {
            incr level
        }
    }
    set pre [GetQuotedPrefix ${text}]
    set var [StripPrefix ${text}]
        set pre [GetQuotedPrefix $text]
        set var [StripPrefix $text]
    # puts stderr "(VarCompletion) pre=|$pre|"
    # puts stderr "(VarCompletion) var=|$var|"

    # arrays
    #
    if {[regexp {([^(]*)\((.*)} ${var} all array name]} {
        set names [uplevel ${level} array names ${array} ${name}*]
        if {[regexp {([^(]*)\((.*)} $var all array name]} {
            set names [uplevel $level array names $array $name*]
        if {1 == [llength $names]} { ; # unique match
            return "${array}(${names})"
        } elseif {"" != ${names}} {
            return "${array}([CompleteLongest ${names}] ${names}"
                return "${array}($names)"
            } elseif {"" != $names} {
                return "${array}([CompleteLongest $names] $names"
        } else {
            return ""; # nothing to complete
        }
    }

    # non-arrays
    #
    regsub ":$" ${var} "::" var
        regsub ":$" $var "::" var
    set namespaces [namespace children :: ${var}*]
    if {[llength ${namespaces}] && "::" != [string range ${var} 0 1]} {
        foreach name ${namespaces} {
            regsub "^::" ${name} "" name
            if {[string length ${name}]} {
                lappend new ${name}::
        if {[llength $namespaces] && "::" != [string range $var 0 1]} {
            foreach name $namespaces {
                regsub "^::" $name "" name
                if {[string length $name]} {
                    lappend new $name::
            }
        }
        set namespaces ${new}
            set namespaces $new
        unset new
    }
    set matches \
    [string trim "[uplevel ${level} info vars ${var}*] ${namespaces}"]
            [string trim "[uplevel $level info vars ${var}*] $namespaces"]
    if {1 == [llength $matches]} { ; # unique match

        # check if this unique match is an
        # array name, (whith no "(" yet).
        #
        if {[uplevel ${level} array exists $matches]} {
            return [VarCompletion ${matches}( ${level}]; # recursion
            if {[uplevel $level array exists $matches]} {
                return [VarCompletion ${matches}( $level]; # recursion
        } else {
            return ${pre}${matches}[Right ${pre}]
                return ${pre}${matches}[Right $pre]
        }
    } elseif {"" != $matches} { ; # more than one match
          return [CompleteFromList ${text} ${matches}]
              return [CompleteFromList $text $matches]
    } else {
        return ""; # nothing to complete
    }
}

proc CompleteControlStatement {text start end line pos mod pre new_line} {
    set pre [GetQuotedPrefix ${pre}]
        set pre [GetQuotedPrefix $pre]
    set cmd [Lindex $new_line 0]
    set diff [expr \
    [string length $line] - [string length $new_line]]
    if {$diff == [expr $start + 1]} {
        set diff [expr {[string length $line] - [string length $new_line]}]
        if {$diff == [expr {$start + 1}]} {
        set mod1 $mod
    } else {
        set mod1 $text
        set pre ""
    }
    set new_end [expr $end - $diff]
    set new_start [expr $new_end - [string length $mod1]]
        set new_end [expr {$end - $diff}]
        set new_start [expr {$new_end - [string length $mod1]}]
    # puts ""
    # puts new_start=$new_start
    # puts new_end=$new_end
    # puts new_line=$new_line
    # puts mod1=$mod1
    if {$new_start < 0} {
        return ""; # when does this occur?
    }
    # puts stderr ""
    # puts stderr start=|$start|
    # puts stderr end=|$end|
    # puts stderr mod=|$mod|
    # puts stderr new_start=|$new_start|
    # puts stderr new_end=|$new_end|
    # puts stderr new_line=|$new_line|
    # puts stderr ""
    set res [ScriptCompleter $mod1 $new_start $new_end $new_line]
    # puts stderr \n\${pre}\${res}=|${pre}${res}|
    if {[string length [Lindex ${res} 0]]} {
        if {[string length [Lindex $res 0]]} {
        return ${pre}${res}
    } else {
        return ${res}
            return $res
    }
    return ""
}

proc BraceOrCommand {text start end line pos mod} {
    if {![string length [Lindex $line $pos]]} {
        return [list \{ {}]; # \}
1217
1218
1219
1220
1221
1222
1223
1224

1225
1226
1227


1228
1229
1230

1231
1232
1233
1234

1235
1236
1237
1238

1239
1240
1241
1242
1243

1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254



1255
1256
1257

1258
1259
1260
1261

1262
1263
1264


1265
1266
1267
1268
1269


1270
1271
1272
1273
1274
1275
1276
1277


1278
1279
1280
1281
1282


1283
1284
1285
1286
1287
1288
1289
1290


1291
1292
1293


1294
1295
1296
1297
1298
1299
1300
1301
1302
1303

1304
1305

1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322




1323
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
1373
1374
1375
1376
1377

1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392

1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410

1411
1412
1413
1414
1415
1416
1417

1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430

1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441

1442
1443
1444
1445
1446
1447
1448
1449
1450
1451

1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471

1472
1473
1474

1475
1476
1477
1478
1479
1480


1481
1482

1483
1484
1485

1486
1487
1488
1489
1490
1491
1492
1493

1494
1495
1496


1497
1498

1499
1500
1501
1502


1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513


1514
1515
1516
1517
1518
1519
1520
1521
1522
1523

1524
1525
1526
1527

1528
1529
1530
1531
1532


1533
1534
1535

1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549


1550
1551
1552
1553
1554
1555
1556
1557
1558

1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576

1577
1578
1579
1580
1581

1582
1583
1584

1585
1586
1587

1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604

1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615


1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630



1631
1632
1633

1634
1635
1636
1637
1638
1639
1640
1641
1642
1643

1644
1645
1646
1647

1648
1649
1650
1651
1652
1653
1654
1157
1158
1159
1160
1161
1162
1163

1164
1165


1166
1167
1168
1169

1170
1171
1172
1173

1174
1175
1176
1177

1178
1179
1180
1181
1182

1183
1184
1185
1186
1187







1188
1189
1190

1191

1192

1193
1194

1195



1196
1197

1198
1199


1200
1201
1202
1203
1204
1205
1206
1207


1208
1209

1210
1211


1212
1213
1214
1215
1216
1217
1218
1219


1220
1221
1222


1223
1224

1225
1226
1227
1228
1229
1230
1231
1232

1233


1234
1235
1236
1237
1238
1239
1240
1241

1242
1243
1244
1245
1246




1247
1248
1249
1250
1251
1252
1253


1254
1255
1256
1257



1258
1259
1260
1261
1262

1263
1264
1265
1266



1267
1268
1269
1270

1271
1272
1273



1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287


1288
1289
1290
1291

1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302

1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317

1318
1319
1320
1321

1322
1323
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
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390

1391

1392

1393


1394
1395
1396

1397
1398
1399

1400



1401
1402
1403
1404
1405
1406

1407

1408
1409


1410
1411


1412
1413



1414
1415

1416
1417
1418
1419
1420
1421
1422
1423


1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434

1435
1436
1437
1438

1439

1440
1441


1442
1443
1444
1445

1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458


1459
1460
1461
1462
1463
1464
1465
1466
1467
1468

1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483

1484
1485

1486
1487
1488
1489


1490



1491



1492

1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507

1508
1509
1510
1511
1512
1513
1514
1515
1516



1517
1518

1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529



1530
1531
1532
1533
1534

1535
1536
1537
1538
1539
1540
1541
1542
1543
1544

1545
1546
1547
1548

1549
1550
1551
1552
1553
1554
1555
1556







-
+

-
-
+
+


-
+



-
+



-
+




-
+




-
-
-
-
-
-
-
+
+
+
-

-
+
-


-
+
-
-
-
+
+
-


-
-
+
+






-
-
+
+
-


-
-
+
+






-
-
+
+

-
-
+
+
-








-
+
-
-
+







-





-
-
-
-
+
+
+
+



-
-
+
+


-
-
-
+
+
+


-
+



-
-
-
+
+
+

-
+


-
-
-
+
+
+











-
-




-
+










-
+














-
+



-













-
+






-
+

-









-
-
+
-
-






-

-
+









-
+



















-
+
-

-
+
-
-



-
+
+

-
+
-
-
-
+





-

-
+

-
-
+
+
-
-
+

-
-
-
+
+
-








-
-
+
+









-
+



-
+
-


-
-
+
+


-
+












-
-
+
+








-
+














-


-
+



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















-
+








-
-
-
+
+
-











-
-
-
+
+
+


-
+









-
+



-
+







}

proc FullQualifiedMatches {qualifier matchlist} {
    set new ""
    if {"" != $qualifier && ![regexp ::$ $qualifier]} {
        append qualifier ::
    }
    foreach entry ${matchlist} {
        foreach entry $matchlist {
        set full ${qualifier}${entry}
        if {"" != [namespace which ${full}]} {
            lappend new ${full}
            if {"" != [namespace which $full]} {
                lappend new $full
        }
    }
    return ${new}
        return $new
}

proc ProcsOnlyCompletion {cmd} {
    return [CommandCompletion ${cmd} procs]
        return [CommandCompletion $cmd procs]
}

proc CommandsOnlyCompletion {cmd} {
    return [CommandCompletion ${cmd} commands]
        return [CommandCompletion $cmd commands]
}

proc CommandCompletion {cmd {action both} {spc ::}} {
    # get the leading colons in `cmd'.
    regexp {^:*} ${cmd} pre
        regexp {^:*} $cmd pre
    return [CommandCompletionWithPre $cmd $action $spc $pre]
}

proc CommandCompletionWithPre {cmd action spc pre} {
    # puts stderr "(CommandCompletion) cmd=|$cmd|"
    # puts stderr "(CommandCompletion) action=|$action|"
    # puts stderr "(CommandCompletion) spc=|$spc|"

    set cmd [StripPrefix ${cmd}]
    set quali [namespace qualifiers ${cmd}]
    if {[string length ${quali}]} {
        set cmd [StripPrefix $cmd]
        set quali [namespace qualifiers $cmd]
        if {[string length $quali]} {
        # puts stderr \nquali=|$quali|
        set matches [CommandCompletionWithPre \
        [namespace tail ${cmd}] ${action} ${spc}${quali} ${pre}]
                             [namespace tail $cmd] $action ${spc}${quali} $pre]
        # puts stderr \nmatches1=|$matches|
        return $matches
    }
    set cmd [string trim ${cmd}]*
        set cmd [string trim $cmd]*
    # puts stderr \ncmd=|$cmd|\n
    if {"procs" != ${action}} {
        set all_commands [namespace eval $spc [list info commands ${cmd}]]
        if {"procs" != $action} {
            set all_commands [namespace eval $spc [list info commands $cmd]]
        # puts stderr all_commands=|$all_commands|
        set commands ""
        foreach command $all_commands {
            if {[namespace eval $spc [list namespace origin $command]] == \
                [namespace eval $spc [list namespace which $command]]} {
                if {[namespace eval $spc [list namespace origin $command]]
                        == [namespace eval $spc [list namespace which $command]]} {
                lappend commands $command
            }
        }
    } else {
        set commands ""
    }
    if {"commands" != ${action}} {
        set all_procs [namespace eval $spc [list info procs ${cmd}]]
        if {"commands" != $action} {
            set all_procs [namespace eval $spc [list info procs $cmd]]
        # puts stderr procs=|$procs|
        set procs ""
        foreach proc $all_procs {
            if {[namespace eval $spc [list namespace origin $proc]] == \
                [namespace eval $spc [list namespace which $proc]]} {
                if {[namespace eval $spc [list namespace origin $proc]]
                        == [namespace eval $spc [list namespace which $proc]]} {
                lappend procs $proc
            }
        }
    } else {
        set procs ""
    }
    set matches [namespace eval $spc concat ${commands} ${procs}]
    set namespaces [namespace children $spc ${cmd}]
        set matches [namespace eval $spc concat $commands $procs]
        set namespaces [namespace children $spc $cmd]

    if {![llength ${matches}] && 1 == [llength ${namespaces}]} {
        set matches [CommandCompletionWithPre {} ${action} ${namespaces} ${pre}]
        if {![llength $matches] && 1 == [llength $namespaces]} {
            set matches [CommandCompletionWithPre {} $action $namespaces $pre]
        # puts stderr \nmatches=|$matches|
        return $matches
    }

    # make `namespaces' having exactly
    # the same number of colons as `cmd'.
    #
    regsub -all {^:*} $spc $pre spc

    set matches [FullQualifiedMatches ${spc} ${matches}]
        set matches [FullQualifiedMatches $spc $matches]
    # puts stderr \nmatches3=|$matches|
    return [string trim "${matches} ${namespaces}"]
        return [string trim "$matches $namespaces"]
}

#**
# check, if the first argument starts with a '['
# and must be evaluated before continuing.
# NOTE: trims the `line'.
#       eventually modifies all arguments.
# DATE: Sep-06-1999
#
proc EventuallyEvaluateFirst {partT startT endT lineT} {
    # return; # disabled
    upvar $partT part $startT start $endT end $lineT line

    set oldlen [string length ${line}]
    # set line [string trim ${line}]
    set line [string trimleft ${line}]
    set diff [expr [string length $line] - $oldlen]
        set oldlen [string length $line]
        # set line [string trim $line]
        set line [string trimleft $line]
        set diff [expr {[string length $line] - $oldlen}]
    incr start $diff
    incr end $diff

    set char [string index ${line} 0]
    if {{[} != ${char} && {$} != ${char}} {return}
        set char [string index $line 0]
        if {{[} != $char && {$} != $char} {return}

    set pos 0
    while {-1 != [set idx [string first {]} ${line} ${pos}]]} {
        set cmd [string range ${line} 0 ${idx}]
        if {[info complete ${cmd}]} {
        while {-1 != [set idx [string first {]} $line $pos]]} {
            set cmd [string range $line 0 $idx]
            if {[info complete $cmd]} {
            break;
        }
        set pos [expr ${idx} + 1]
            set pos [expr {$idx + 1}]
    }

    if {![info exists cmd]} {return}
    if {![info complete ${cmd}]} {return}
    set cmd [string range ${cmd} 1 [expr [string length ${cmd}] - 2]]
    set rest [String range ${line} [expr ${idx} + 1] end]
        if {![info complete $cmd]} {return}
        set cmd [string range $cmd 1 [expr {[string length $cmd] - 2}]]
        set rest [String range $line [expr {$idx + 1}] end]

    if {[catch [list set result [string trim [eval ${cmd}]]]]} {return}
        if {[catch [list set result [string trim [eval $cmd]]]]} {return}

    set line ${result}${rest}
    set diff [expr [string length ${result}] - ([string length ${cmd}] + 2)]
    incr start ${diff}
    incr end ${diff}
        set diff [expr {[string length $result] - ([string length $cmd] + 2)}]
        incr start $diff
        incr end $diff
}

# if the line entered so far is
# % puts $b<TAB>
# part  == $b
# start == 5
# end   == 7
# line  == "$puts $b"
#
proc ScriptCompleter {part start end line} {

    # puts stderr "(ScriptCompleter) |$part| $start $end |$line|"

    # if the character before the cursor is a terminating
    # quote and the user wants completion, we insert a white
    # space here.
    #
    set char [string index $line [expr $end - 1]]
        set char [string index $line [expr {$end - 1}]]
    if {"\}" == $char} {
        append $part " "
        return [list $part]
    }

    if {{$} == [string index $part 0]} {

        # check for a !$ history event
        #
        if {$start > 0} {
            if {{!} == [string index $line [expr $start - 1]]} {
                if {{!} == [string index $line [expr {$start - 1}]]} {
                return ""
            }
        }
        # variable completion. Check first, if the
        # variable starts with a plain `$' or should
        # be enclosed in braces.
        #
        set var [String range $part 1 end]

        # check if $var is an array name, which
        # already has already a "(" somewhere inside.
        #
        if {"" != [set vc [VarCompletion $var]]} {
            if {"" == [lindex $vc 0]} {
                return "\$ [lrange ${vc} 1 end]"
                    return "\$ [lrange $vc 1 end]"
            } else {
                return \$${vc}
            }
            # puts stderr vc=|$vc|
        } else {
            return ""
        }

    # SCENARIO:
    #
    # % puts bla; put<TAB> $b
    # part  == put
    # start == 10
    # end   == 13
    # line  == "puts bla; put $b"
    # [SplitLine] --> {1 " put $b"} == sub
    # new_start = [lindex $sub 0] == 1
    # new_end   = [expr $end - ($start - $new_start)] == 4
        # new_end   = [expr {$end - ($start - $new_start)}] == 4
    # new_part  == $part == put
    # new_line  = [lindex $sub 1] == " put $b"
    #
    } elseif {"" != [set sub [SplitLine $start $line]]} {

        set new_start [lindex $sub 0]
        set new_end [expr $end - ($start - $new_start)]
            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}]
            set all [CommandCompletion $part]
        # puts stderr "(ScriptCompleter) all=$all"
        #puts \nmatches=$matches\n
        # return [Format $all $part]
        return [TryFromList $part $all]

    } else {

        # try to use $pos further ...
        # puts stderr |$line|
        #
        # if {"." == [string index [string trim ${line}] 0]} {
            # if {"." == [string index [string trim $line] 0]} {
        #   set alias WIDGET
        #   set namespc ""; # widgets are always in the global
        # } else {

            # the double `lindex' strips {} or quotes.
            # the subst enables variables containing
            # command names.
            #
            set alias [uplevel [info level] \
            subst [lindex [lindex [QuoteQuotes ${line}] 0] 0]]
                               subst [lindex [lindex [QuoteQuotes $line] 0] 0]]

            # make `alias' a fully qualified name.
            # this can raise an error, if alias is
            # no valid command.
            #
            if {[catch {set alias [namespace origin $alias]}]} {
                return ""
            }

            # strip leading ::'s.
            #
            regsub -all {^::} $alias {} alias
            set namespc [namespace qualifiers $alias]
            set alias [namespace tail $alias]
        # }

        # try first a specific completer, then, and only then
        # the tclreadline_complete_unknown.
        #
        foreach cmd [list ${alias} tclreadline_complete_unknown] {
            foreach cmd [list $alias tclreadline_complete_unknown] {
            # puts stderr ${namespc}complete(${cmd})
            if {"" != [namespace eval ::tclreadline::${namespc} \
                [list info procs complete(${cmd})]]
                               [list info procs complete($cmd)]]} {
            } {
                # puts found=|complete($cmd)|
                # to be more error-proof, we check here,
                # if complete($cmd) takes exactly 5 arguments.
                #
                if {6 != [set arguments [llength \
                    if {6 != [set arguments \
                                  [llength \
                    [namespace eval ::tclreadline::${namespc} \
                    [list info args complete($cmd)]]]]
                                            [list info args complete($cmd)]]]]} {
                } {
                    error [list complete(${cmd}) takes ${arguments} \
                    arguments, but should take exactly 6.]
                        error "complete($cmd) takes $arguments arguments, but should take exactly 6"
                }

                # remove leading quotes
                #
                set mod [StripPrefix $part]
                # puts stderr mod=$mod

                if {[catch [list set script_result \
                    if {[catch {set script_result \
                    [namespace eval ::tclreadline::${namespc} \
                    [list complete(${cmd}) $part $start $end $line $pos $mod]]]\
                    ::tclreadline::errorMsg]
                                         [list complete($cmd) $part $start $end $line $pos $mod]]} \
                             ::tclreadline::errorMsg]} {
                } {
                    error [list error during evaluation of `complete(${cmd})']
                        error "error during evaluation of `complete($cmd)'"
                }
                # puts stderr \nscript_result=|${script_result}|
                if {![string length ${script_result}] && \
                    "tclreadline_complete_unknown" == ${cmd}
                    if {![string length $script_result]
                            && "tclreadline_complete_unknown" == $cmd} {
                } {
                    # as we're here, the tclreadline_complete_unknown
                    # 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}
                        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}]} {
            if {![string length $namespc]} {
            set namespc ::
        }
        if {[string length [uplevel [info level] \
            namespace eval ${namespc} [list ::info proc $alias]]]
                                    namespace eval $namespc [list ::info proc $alias]]]} {
        } {
            if ![string length [string trim $part]] {
                set args [uplevel [info level] \
                namespace eval ${namespc} [list info args $alias]]
                set arg [lindex $args [expr $pos - 1]]
                                  namespace eval $namespc [list info args $alias]]
                    set arg [lindex $args [expr {$pos - 1}]]
                if {"" != $arg && "args" != $arg} {
                    if {[uplevel [info level] namespace eval \
                        ${namespc} [list info default $alias $arg junk]]} {
                                 $namespc [list info default $alias $arg junk]]} {
                            return [DisplayHints ?$arg?]
                        } else {
                            return [DisplayHints <$arg>]
                        }
                }
            } else {
                return ""; # enable file name completion
            }
        }

        # check if the command is an object of known class.
        #
        if [ObjectClassCompleter ${part} ${start} ${end} ${line} ${pos} res] {
            return ${res}
            if [ObjectClassCompleter $part $start $end $line $pos 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}]
                        $part $start $end $line $pos]
    }
    error "{NOTREACHED (this is probably an error)}"
}


# explicit command completers
#

# -------------------------------------
#                 TCL
# -------------------------------------

proc complete(after) {text start end line pos mod} {
    set sub [Lindex $line 1]
    # puts \npos=$pos
    switch -- $pos {
        1 {
            return [CompleteFromList ${text} {<ms> cancel idle info}]
                return [CompleteFromList $text {<ms> cancel idle info}]
        }
        2 {
            switch -- $sub {
                cancel {
                    return [CompleteFromList $text "<script> [after info]"]
                    cancel  { return [CompleteFromList $text "<script> [after info]"] }
                }
                idle {
                    return [DisplayHints <script>]
                    idle    { return [DisplayHints <script>] }
                }
                info {
                    return [CompleteFromList $text [after info]]
                    info    { return [CompleteFromList $text [after info]] }
                }
                default { return [DisplayHints ?script?] }
            }
        }
        default {
            switch -- $sub {
                info { return [DisplayHints {}] }
                default { return [DisplayHints ?script?] }
            }
        }
    }
    return ""
}

proc complete(append) {text start end line pos mod} {
    switch -- $pos {
        1       { return [VarCompletion ${text}] }
            1       { return [VarCompletion $text] }
        default { return [DisplayHints ?value?] }
    }
    return ""
}

proc complete(array) {text start end line pos mod} {
    switch -- $pos {
        1 {
            set cmds {
                anymore donesearch exists get names
                nextelement set size startsearch
                set cmds {anymore donesearch exists get names
                          nextelement set size startsearch}
            }
            return [CompleteFromList $text $cmds]
        }
        2 {
            set matches ""
            # set vars [uplevel [info level] info vars ${mod}*]
            #
            # better: this displays a list of array names if the
            # user inters with something which cannot be matched.
            # The matching against `text' is done by CompleteFromList.
            #
            set vars [uplevel [info level] info vars]
            foreach var ${vars} {
                if {[uplevel [info level] array exists ${var}]} {
                    lappend matches ${var}
                foreach var $vars {
                    if {[uplevel [info level] array exists $var]} {
                        lappend matches $var
                }
            }
            return [CompleteFromList ${text} ${matches}]
                return [CompleteFromList $text $matches]
        }
        3 {
            set cmd [Lindex $line 1]
            set array_name [Lindex $line 2]
            switch -- $cmd {
                get -
                names {
                    set pattern [Lindex $line 3]
                    set matches [uplevel [info level] \
                    array names ${array_name} ${pattern}*]
                                         array names $array_name ${pattern}*]
                    if {![llength $matches]} {
                        return [DisplayHints ?pattern?]
                    } else {
                        return [CompleteFromList ${text} ${matches}]
                            return [CompleteFromList $text $matches]
                    }
                }
                anymore -
                donesearch -
                nextelement { return [DisplayHints <searchId>] }
            }
        }
1729
1730
1731
1732
1733
1734
1735
1736

1737
1738
1739
1740
1741
1742
1743
1631
1632
1633
1634
1635
1636
1637

1638
1639
1640
1641
1642
1643
1644
1645







-
+







                }
                clicks  -
                seconds {}
            }
        }
        4 -
        6 {
            set sub [Lindex $line [expr $pos - 1]]
                set sub [Lindex $line [expr {$pos - 1}]]
            switch -- $cmd {
                format {
                    switch -- $sub {
                        -format { return [DisplayHints <string>] }
                        -gmt    { return [DisplayHints <boolean>] }
                    }
                }
1780
1781
1782
1783
1784
1785
1786
1787

1788
1789
1790
1791
1792
1793
1794
1682
1683
1684
1685
1686
1687
1688

1689
1690
1691
1692
1693
1694
1695
1696







-
+







            return [CompleteFromList $text {convertfrom convertto names system}]
        }
        2 {
            switch -- $cmd {
                convertfrom -
                convertto -
                system {
                    return [CompleteFromList ${text} [encoding names]]
                        return [CompleteFromList $text [encoding names]]
                }
            }
        }
        3 {
            switch -- $cmd {
                convertfrom { return [DisplayHints <data>] }
                convertto { return [DisplayHints <string>] }
1829
1830
1831
1832
1833
1834
1835
1836

1837
1838
1839
1840
1841
1842
1843
1731
1732
1733
1734
1735
1736
1737

1738
1739
1740
1741
1742
1743
1744
1745







-
+







        Rehash
    }
    switch -- $pos {
        1 {
            return [TryFromList $text "-keepnewline -- $executables"]
        }
        default {
            set prev [PreviousWord ${start} ${line}]
                set prev [PreviousWord $start $line]
            if {"-keepnewline" == $prev && 2 == $pos} {
                return [TryFromList $text "-- $executables"]
            }
            switch -exact -- $prev {
                | -
                |& { return [TryFromList $text $executables] }
                < -
1938
1939
1940
1941
1942
1943
1944
1945
1946

1947
1948
1949

1950
1951
1952

1953
1954
1955

1956
1957
1958

1959
1960
1961
1962
1963

1964
1965
1966

1967
1968

1969
1970
1971
1972
1973




1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985

1986
1987
1988

1989
1990
1991

1992
1993
1994
1995
1996
1997
1998
1840
1841
1842
1843
1844
1845
1846


1847

1848

1849
1850


1851



1852

1853

1854
1855
1856
1857


1858



1859


1860





1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874


1875



1876

1877

1878
1879
1880
1881
1882
1883
1884
1885







-
-
+
-

-
+

-
-
+
-
-
-
+
-

-
+



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










-
-
+
-
-
-
+
-

-
+







    }
    return ""
}

proc complete(fconfigure) {text start end line pos mod} {
    set cmd [Lindex $line 1]
    switch -- $pos {
        1 {
            return [ChannelId ${text}]
            1       { return [ChannelId $text] }
        }
        default {
            set option [PreviousWord ${start} ${line}]
                set option [PreviousWord $start $line]
            switch -- $option {
                -blocking {
                    return [CompleteBoolean ${text}]
                    -blocking    { return [CompleteBoolean $text] }
                }
                -buffering {
                    return [CompleteFromList ${text} {full line none}]
                    -buffering   { return [CompleteFromList $text {full line none}] }
                }
                -buffersize {
                    if {![llength ${text}]} {
                        if {![llength $text]} {
                        return [DisplayHints <newSize>]
                    }
                }
                -encoding {
                    return [CompleteFromList ${text} [encoding names]]
                    -encoding    { return [CompleteFromList $text [encoding names]] }
                }
                -eofchar {
                    return [DisplayHints {\{<inChar>\ <outChar>\}}]
                    -eofchar     { return [DisplayHints {\{<inChar>\ <outChar>\}}] }
                }
                -translation {
                    -translation { return [CompleteFromList $text {auto binary cr crlf lf}] }
                    return [CompleteFromList ${text} {auto binary cr crlf lf}]
                }
                default {return [CompleteFromList $text \
                    [RemoveUsedOptions $line {
                    -blocking -buffering -buffersize
                    default      {
                        return [CompleteFromList $text \
                                    [RemoveUsedOptions $line \
                                         {-blocking -buffering -buffersize
                    -encoding -eofchar -translation}]]
                }
            }
        }
    }
    return ""
}

proc complete(fcopy) {text start end line pos mod} {
    switch -- $pos {
        1 {
            return [InChannelId ${text}]
            1       { return [InChannelId $text] }
        }
        2 {
            return [OutChannelId ${text}]
            2       { return [OutChannelId $text] }
        }
        default {
            set option [PreviousWord ${start} ${line}]
                set option [PreviousWord $start $line]
            switch -- $option {
                -size    { return [DisplayHints <size>] }
                -command { return [DisplayHints <callback>] }
                default  { return [CompleteFromList $text \
                    [RemoveUsedOptions $line {-size -command}]]
                }
            }
2056
2057
2058
2059
2060
2061
2062
2063
2064

2065
2066
2067

2068
2069
2070

2071
2072
2073
2074
2075
2076
2077
2078

2079
2080
2081
2082
2083
2084
2085
1943
1944
1945
1946
1947
1948
1949


1950



1951



1952

1953
1954
1955
1956
1957
1958

1959
1960
1961
1962
1963
1964
1965
1966







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






-
+







        }
    }
    return ""
}

proc complete(fileevent) {text start end line pos mod} {
    switch -- $pos {
        1 {
            return [ChannelId ${text}]
            1 { return [ChannelId $text] }
        }
        2 {
            return [CompleteFromList ${text} {readable writable}]
            2 { return [CompleteFromList $text {readable writable}] }
        }
        3 {
            return [DisplayHints ?script?]
            3 { return [DisplayHints ?script?] }
        }
    }
    return ""
}

proc complete(flush) {text start end line pos mod} {
    switch -- $pos {
        1 { return [OutChannelId ${text}] }
            1 { return [OutChannelId $text] }
    }
    return ""
}

proc complete(for) {text start end line pos mod} {
    switch -- $pos {
        1 -
2093
2094
2095
2096
2097
2098
2099
2100

2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121


2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133



2134
2135
2136
2137
2138
2139
2140
2141

2142
2143
2144
2145
2146
2147
2148
1974
1975
1976
1977
1978
1979
1980

1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000


2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011



2012
2013
2014
2015
2016
2017
2018
2019
2020
2021

2022
2023
2024
2025
2026
2027
2028
2029







-
+



















-
-
+
+









-
-
-
+
+
+







-
+







}

proc complete(foreach) {text start end line pos mod} {
    switch -- $pos {
        1 { return [DisplayHints <varname>] }
        2 { return [DisplayHints <list>] }
        default {
            if {[expr $pos % 2]} {
                if {[expr {$pos % 2}]} {
                return [DisplayHints [list ?varname? <body>]]
            } else {
                return [DisplayHints ?list?]
            }
        }
    }
    return ""
}

proc complete(format) {text start end line pos mod} {
    switch -- $pos {
        1 { return [DisplayHints <formatString>] }
        default { return [DisplayHints ?arg?] }
    }
    return ""
}

proc complete(gets) {text start end line pos mod} {
    switch -- $pos {
        1 { return [InChannelId ${text}] }
        2 { return [VarCompletion ${text}]}
            1 { return [InChannelId $text] }
            2 { return [VarCompletion $text]}
    }
    return ""
}

proc complete(glob) {text start end line pos mod} {
    switch -- $pos {
        1 {
            # This also is not perfect.
            # This will not display the options as hints!
            set matches [TryFromList ${text} {-nocomplain --}]
            if {[llength [string trim ${text}]] && [llength ${matches}]} {
                return ${matches}
                set matches [TryFromList $text {-nocomplain --}]
                if {[llength [string trim $text]] && [llength $matches]} {
                    return $matches
            }
        }
    }
    return ""
}

proc complete(global) {text start end line pos mod} {
    return [VarCompletion ${text}]
        return [VarCompletion $text]
}

proc complete(history) {text start end line pos mod} {
    switch -- $pos {
        1 {
            set cmds {add change clear event info keep nextid redo}
            return [TryFromList $text $cmds]
2180
2181
2182
2183
2184
2185
2186
2187

2188
2189
2190
2191

2192
2193
2194
2195

2196
2197
2198
2199
2200
2201




2202
2203
2204
2205
2206
2207
2208
2209
2210
2211

2212
2213
2214

2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227





2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241

2242
2243
2244
2245
2246
2247
2248
2061
2062
2063
2064
2065
2066
2067

2068
2069
2070


2071

2072


2073

2074
2075



2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088

2089
2090
2091

2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102



2103
2104
2105
2106
2107

2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119

2120
2121
2122
2123
2124
2125
2126
2127







-
+


-
-
+
-

-
-
+
-


-
-
-
+
+
+
+









-
+


-
+










-
-
-
+
+
+
+
+
-












-
+







        ::tclreadline::RemoveUsedOptions ::tclreadline::HostList \
        ::tclreadline::ChannelId ::tclreadline::Lindex \
        ::tclreadline::CompleteBoolean
    }
}

proc http::complete(config) {text start end line pos mod} {
    set prev [PreviousWord ${start} ${line}]
        set prev [PreviousWord $start $line]
    switch -- $prev {
        -accept { return [DisplayHints <mimetypes>] }
        -proxyhost {
            return [CompleteFromList $text [HostList]]
            -proxyhost   { return [CompleteFromList $text [HostList]] }
        }
        -proxyport { return [DisplayHints <number>] }
        -proxyfilter {
            return [CompleteFromList $text [CommandCompletion $text]]
            -proxyfilter { return [CompleteFromList $text [CommandCompletion $text]] }
        }
        -useragent { return [DisplayHints <string>] }
        default {
            return [CompleteFromList $text [RemoveUsedOptions $line {
                -accept -proxyhost -proxyport -proxyfilter -useragent
            }]]
                return [CompleteFromList $text \
                            [RemoveUsedOptions $line \
                                 {-accept -proxyhost -proxyport
                                  -proxyfilter -useragent}]]
        }
    }
    return ""
}

proc http::complete(geturl) {text start end line pos mod} {
    switch -- $pos {
        1 { return [DisplayHints <url>] }
        default {
            set prev [PreviousWord ${start} ${line}]
                set prev [PreviousWord $start $line]
            switch -- $prev {
                -blocksize { return [DisplayHints <size>] }
                -channel { return [ChannelId ${text}] }
                    -channel   { return [ChannelId $text] }
                -command -
                -handler -
                -progress {
                    return [CompleteFromList $text [CommandCompletion $text]]
                }
                -headers { return [DisplayHints <keyvaluelist>] }
                -query { return [DisplayHints <query>] }
                -timeout { return [DisplayHints <milliseconds>] }
                -validate { return [CompleteBoolean $text] }
                default {
                    return [CompleteFromList $text [RemoveUsedOptions $line {
                        -blocksize -channel -command -handler -headers
                        -progress -query -timeout -validate
                        return [CompleteFromList $text \
                                    [RemoveUsedOptions $line \
                                         {-blocksize -channel -command
                                          -handler -headers -progress
                                          -query -timeout -validate}]]
                    }]]
                }
            }
        }
    }
    return ""
}

proc http::complete(formatQuery) {text start end line pos mod} {
    switch -- $pos {
        1 { return [DisplayHints <key>] }
        2 { return [DisplayHints <value>] }
        default {
            switch [expr $pos % 2] {
                switch [expr {$pos % 2}] {
                0 { return [DisplayHints ?value?] }
                1 { return [DisplayHints ?key?] }
            }
        }
    }
    return ""
}
2287
2288
2289
2290
2291
2292
2293
2294

2295
2296
2297
2298
2299
2300


2301
2302
2303
2304
2305
2306
2307
2166
2167
2168
2169
2170
2171
2172

2173
2174
2175
2176
2177


2178
2179
2180
2181
2182
2183
2184
2185
2186







-
+




-
-
+
+







    #
    switch -- $pos {
        1 -
        2 {
            return [BraceOrCommand $text $start $end $line $pos $mod]
        }
        default {
            set prev [PreviousWord ${start} ${line}]
                set prev [PreviousWord $start $line]
            switch -- $prev {
                then -
                else -
                elseif {
                    return [BraceOrCommand \
                    $text $start $end $line $pos $mod]
                        return [BraceOrCommand $text $start \
                                    $end $line $pos $mod]
                }
                default {
                    if {-1 == [lsearch [ProperList $line] else]} {
                        return [CompleteFromList $text {else elseif}]
                    }
                }
            }
2321
2322
2323
2324
2325
2326
2327
2328

2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342


2343
2344
2345
2346
2347
2348
2349
2350

2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366


2367
2368
2369
2370
2371
2372
2373
2374

2375
2376
2377
2378
2379
2380
2381
2382
2383

2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398


2399
2400
2401
2402
2403
2404
2405

2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420

2421
2422
2423
2424
2425

2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438

2439
2440
2441
2442
2443
2444
2445
2446
2447

2448
2449
2450
2451
2452
2453
2454


2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467

2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481

2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493

2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507

2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525


2526
2527
2528
2529
2530
2531
2532
2200
2201
2202
2203
2204
2205
2206

2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220

2221
2222
2223
2224
2225
2226
2227
2228
2229

2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243



2244
2245
2246
2247
2248
2249
2250
2251
2252

2253
2254
2255
2256
2257
2258
2259
2260


2261

2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274

2275
2276
2277
2278
2279
2280

2281

2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296

2297
2298
2299
2300
2301

2302
2303
2304
2305
2306
2307
2308
2309
2310

2311
2312
2313

2314
2315
2316
2317
2318
2319
2320
2321
2322

2323
2324
2325
2326
2327
2328


2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342

2343
2344
2345
2346
2347

2348
2349
2350
2351
2352
2353
2354
2355

2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367

2368
2369
2370
2371
2372

2373
2374
2375
2376
2377
2378
2379
2380

2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397


2398
2399
2400
2401
2402
2403
2404
2405
2406







-
+













-
+
+







-
+













-
-
-
+
+







-
+







-
-
+
-













-
+
+




-

-
+














-
+




-
+








-



-
+








-
+





-
-
+
+












-
+




-








-
+











-
+




-








-
+
















-
-
+
+







                if {[uplevel [info level] array exists $match]} {
                    continue
                }
                if {[regexp {^[0-9]+$} [uplevel [info level] set $match]]} {
                    lappend integers $match
                }
            }
            return [CompleteFromList ${text} ${integers}]
                return [CompleteFromList $text $integers]
        }
        2 { return [DisplayHints ?increment?] }
    }
    return ""
}

proc complete(info) {text start end line pos mod} {
    set cmd [Lindex $line 1]
    switch -- $pos {
        1 {
            set cmds {
                args body cmdcount commands complete default exists
                globals hostname level library loaded locals nameofexecutable
                patchlevel procs script sharedlibextension tclversion vars}
                    patchlevel procs script sharedlibextension tclversion vars
                }
            return [CompleteFromList $text $cmds]
        }
        2 {
            switch -- $cmd {
                args -
                body -
                default -
                procs { return [complete(proc) ${text} 0 0 ${line} 1 ${mod}] }
                    procs    { return [complete(proc) $text 0 0 $line 1 $mod] }
                complete { return [DisplayHints <command>] }
                level { return [DisplayHints ?number?] }
                loaded { return [DisplayHints ?interp?] }
                commands -
                exists -
                globals -
                locals -
                vars {
                    if {"exists" == $cmd} {
                        set do vars
                    } else {
                        set do $cmd
                    }
                    # puts stderr [list complete(info) level = [info level]]
                    return \
                    [CompleteFromList ${text} [uplevel [info level] info ${do}]]
                        return [CompleteFromList $text \
                                    [uplevel [info level] info $do]]
                }
            }
        }
        3 {
            switch -- $cmd {
                default {
                    set proc [Lindex $line 2]
                    return [CompleteFromList ${text} \
                        return [CompleteFromList $text \
                    [uplevel [info level] info args $proc]]
                }
                default {}
            }
        }
        4 {
            switch -- $cmd {
                default {
                    return [VarCompletion ${text}]
                    default { return [VarCompletion $text] }
                }
                default {}
            }
        }
    }
    return ""
}

proc complete(interp) {text start end line pos mod} {
    set cmd [Lindex $line 1]
    switch -- $pos {
        1 {
            set cmds {
                alias aliases create delete eval exists expose hide hidden
                invokehidden issafe marktrusted share slaves target transfer}
                    invokehidden issafe marktrusted share slaves target transfer
                }
            return [TryFromList $text $cmds]
        }
        2 {
            switch -- $cmd {

                create {
                    set cmds [RemoveUsedOptions ${line} {-save --} {--}]
                        set cmds [RemoveUsedOptions $line {-save --} {--}]
                    if {[llength $cmds]} {
                        return [CompleteFromList $text "$cmds ?path?"]
                    } else {
                        return [DisplayHints ?path?]
                    }
                }

                eval -
                exists -
                expose -
                hide -
                hidden -
                invokehidden -
                marktrusted -
                target { return [CompleteFromList ${text} [interp slaves]] }
                    target       { return [CompleteFromList $text [interp slaves]] }

                aliases -
                delete -
                issafe -
                slaves { return [CompleteFromList ${text} [interp slaves]] }
                    slaves  { return [CompleteFromList $text [interp slaves]] }

                alias -
                share -
                transfer { return [DisplayHints <srcPath>] }
            }
        }
        3 {
            switch -- $cmd {

                alias { return [DisplayHints <srcCmd>] }

                create {
                    set cmds [RemoveUsedOptions ${line} {-save --} {--}]
                        set cmds [RemoveUsedOptions $line {-save --} {--}]
                    if {[llength $cmds]} {
                        return [CompleteFromList $text "$cmds ?path?"]
                    } else {
                        return [DisplayHints ?path?]
                    }
                }

                eval { return [DisplayHints <arg>] }
                delete { return [CompleteFromList ${text} [interp slaves]] }
                    delete { return [CompleteFromList $text [interp slaves]] }

                expose { return [DisplayHints <hiddenName>] }
                hide { return [DisplayHints <exposedCmdName>] }

                invokehidden {
                    return \
                    [CompleteFromList $text {?-global? <hiddenCmdName>}]
                        return [CompleteFromList $text \
                                    {?-global? <hiddenCmdName>}]
                }

                target { return [DisplayHints <alias>] }

                exists {}
                hidden {}
                marktrusted {}
                aliases {}
                issafe {}
                slaves {}

                share -
                transfer {return [ChannelId ${text}]}
                    transfer { return [ChannelId $text] }
            }
        }
        4 {
            switch -- $cmd {

                alias { return [DisplayHints <targetPath>] }
                eval { return [DisplayHints ?arg?] }

                invokehidden {
                    return [CompleteFromList $text {<hiddenCmdName> ?arg?}]
                }

                create {
                    set cmds [RemoveUsedOptions ${line} {-save --} {--}]
                        set cmds [RemoveUsedOptions $line {-save --} {--}]
                    if {[llength $cmds]} {
                        return [CompleteFromList $text "$cmds ?path?"]
                    } else {
                        return [DisplayHints ?path?]
                    }
                }

                expose { return [DisplayHints ?exposedCmdName?] }
                hide { return [DisplayHints ?hiddenCmdName?] }

                share -
                transfer { return [CompleteFromList ${text} [interp slaves]] }
                    transfer { return [CompleteFromList $text [interp slaves]] }
            }
        }
        5 {
            switch -- $cmd {

                alias { return [DisplayHints <targetCmd>] }
                invokehidden -
                eval { return [DisplayHints ?arg?] }

                expose { return [DisplayHints ?exposedCmdName?] }
                hide { return [DisplayHints ?hiddenCmdName?] }

                share -
                transfer { return [CompleteFromList ${text} [interp slaves]] }
                    transfer { return [CompleteFromList $text [interp slaves]] }
            }
        }
    }
    return ""
}

proc complete(join) {text start end line pos mod} {
    switch -- $pos {
        1 { return [DisplayHints <list>] }
        2 { return [DisplayHints ?joinString?] }
    }
    return ""
}

proc complete(lappend) {text start end line pos mod} {
    switch -- $pos {
        1 { return [VarCompletion ${text}] }
        default { return [TryFromList ${text} ?value?] }
            1       { return [VarCompletion $text] }
            default { return [TryFromList $text ?value?] }
    }
    return ""
}

# the following routines are described in the
# `library' man page.
# --- LIBRARY ---
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577



2578
2579
2580
2581
2582
2583
2584
2442
2443
2444
2445
2446
2447
2448



2449
2450
2451
2452
2453
2454
2455
2456
2457
2458







-
-
-
+
+
+







    return ""
}

proc complete(parray) {text start end line pos mod} {
    switch -- $pos {
        1 {
            set vars [uplevel [info level] info vars]
            foreach var ${vars} {
                if {[uplevel [info level] array exists ${var}]} {
                    lappend matches ${var}
                foreach var $vars {
                    if {[uplevel [info level] array exists $var]} {
                        lappend matches $var
                }
            }
            return [CompleteFromList $text $matches]
        }
    }
    return ""
}
2642
2643
2644
2645
2646
2647
2648
2649

2650
2651
2652
2653
2654

2655
2656
2657
2658
2659
2660
2661
2516
2517
2518
2519
2520
2521
2522

2523
2524
2525
2526
2527

2528
2529
2530
2531
2532
2533
2534
2535







-
+




-
+








proc complete(load) {text start end line pos mod} {
    switch -- $pos {
        1 {
            return ""; # filename
        }
        2 {
            if {![llength ${mod}]} {
                if {![llength $mod]} {
                return [DisplayHints ?packageName?]
            }
        }
        3 {
            if {![llength ${mod}]} {
                if {![llength $mod]} {
                return [DisplayHints ?interp?]
            }
        }
    }
    return ""
}

2678
2679
2680
2681
2682
2683
2684
2685

2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706



2707
2708
2709

2710
2711

2712
2713

2714
2715
2716

2717
2718
2719
2720
2721
2722
2723
2552
2553
2554
2555
2556
2557
2558

2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577



2578
2579
2580

2581

2582
2583

2584


2585

2586

2587
2588
2589
2590
2591
2592
2593
2594







-
+


















-
-
-
+
+
+
-

-
+

-
+
-
-
+
-

-
+







    return ""
}

proc complete(lsearch) {text start end line pos mod} {
    set options {-exact -glob -regexp}
    switch -- $pos {
        1 {
            return [CompleteFromList ${text} "$options <list>"]
                return [CompleteFromList $text "$options <list>"]
        }
        2 -
        3 -
        4 {
            set sub [Lindex $line 1]
            if {-1 != [lsearch $options $sub]} {
                incr pos -1
            }
            switch -- $pos {
                1 { return [DisplayHints <list>] }
                2 { return [DisplayHints <pattern>] }
            }
        }
    }
    return ""
}

proc complete(lsort) {text start end line pos mod} {
    set options [RemoveUsedOptions ${line} {
        -ascii -dictionary -integer -real -command
        -increasing -decreasing -index <list>
        set options [RemoveUsedOptions $line \
                         {-ascii -dictionary -integer -real -command
                          -increasing -decreasing -index <list>}]
    }]
    switch -- $pos {
        1 { return [CompleteFromList ${text} ${options}] }
            1       { return [CompleteFromList $text $options] }
        default {
            switch -- [PreviousWord ${start} ${line}] {
                switch -- [PreviousWord $start $line] {
                -command {
                    return [CompleteFromList $text [CommandCompletion $text]]
                    -command { return [CompleteFromList $text [CommandCompletion $text]] }
                }
                -index { return [DisplayHints <index>] }
                default { return [CompleteFromList ${text} ${options}] }
                    default  { return [CompleteFromList $text $options] }
            }
        }
    }
    return ""
}

# --- MSGCAT PACKAGE ---
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785


2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799


2800
2801
2802
2803

2804
2805
2806


2807
2808

2809
2810
2811
2812
2813
2814

2815
2816
2817
2818
2819
2820
2821
2822
2823

2824
2825
2826
2827

2828
2829

2830
2831
2832
2833
2834
2835
2836
2837

2838
2839
2840

2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853






2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866


2867
2868
2869
2870

2871
2872
2873
2874

2875
2876
2877

2878
2879
2880
2881
2882
2883
2884
2885
2886
2887


2888
2889
2890
2891

2892
2893
2894
2895
2896
2897
2898


2899
2900
2901
2902
2903
2904
2905
2906
2907


2908
2909
2910


2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928


2929
2930
2931
2932
2933
2934
2935
2936




2937
2938
2939


2940
2941

2942
2943
2944
2945

2946
2947
2948


2949
2950
2951
2952


2953
2954
2955
2956
2957
2958
2959

2960
2961
2962
2963

2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975

2976
2977
2978
2979

2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999

3000
3001
3002
3003

3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016





3017
3018
3019


3020
3021
3022
3023


3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043







3044
3045
3046
3047


3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060

3061
3062
3063

3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077


3078
3079
3080
3081
3082

3083
3084
3085

3086
3087
3088
3089
3090
3091
3092
2643
2644
2645
2646
2647
2648
2649

2650
2651
2652
2653
2654

2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668


2669
2670
2671
2672
2673

2674
2675


2676
2677
2678

2679
2680
2681

2682


2683
2684
2685
2686
2687
2688
2689
2690
2691

2692
2693



2694


2695
2696
2697
2698
2699
2700
2701
2702

2703
2704
2705

2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716



2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734

2735
2736
2737
2738
2739

2740
2741
2742
2743

2744
2745
2746

2747
2748
2749
2750
2751
2752
2753
2754
2755


2756
2757
2758
2759
2760

2761
2762
2763
2764
2765
2766


2767
2768
2769
2770
2771
2772
2773
2774
2775


2776
2777
2778


2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796


2797
2798
2799
2800
2801
2802




2803
2804
2805
2806
2807


2808
2809
2810

2811
2812
2813
2814

2815
2816


2817
2818
2819
2820


2821
2822
2823
2824
2825
2826
2827
2828

2829
2830
2831
2832

2833

2834
2835
2836
2837
2838
2839
2840
2841
2842
2843

2844
2845
2846
2847

2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867

2868
2869
2870
2871

2872
2873
2874
2875
2876
2877
2878
2879
2880





2881
2882
2883
2884
2885
2886


2887
2888
2889
2890


2891
2892
2893
2894
2895
2896
2897
2898
2899
2900




2901







2902
2903
2904
2905
2906
2907
2908
2909
2910


2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923


2924



2925

2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936


2937
2938
2939
2940
2941
2942

2943
2944
2945

2946
2947
2948
2949
2950
2951
2952
2953







-





-
+
+












-
-
+
+



-
+

-
-
+
+

-
+


-

-
-
+








-
+

-
-
-
+
-
-
+







-
+


-
+










-
-
-
+
+
+
+
+
+












-
+
+



-
+



-
+


-
+








-
-
+
+



-
+





-
-
+
+







-
-
+
+

-
-
+
+
















-
-
+
+




-
-
-
-
+
+
+
+

-
-
+
+

-
+



-
+

-
-
+
+


-
-
+
+






-
+



-
+
-










-
+



-
+



















-
+



-
+








-
-
-
-
-
+
+
+
+
+

-
-
+
+


-
-
+
+








-
-
-
-

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


-
-
+
+











-
-
+
-
-
-
+
-











-
-
+
+




-
+


-
+








# --- END OF MSGCAT PACKAGE ---

# TODO import ! -force
proc complete(namespace) {text start end line pos mod} {
    # TODO dosn't work ???
    set space_matches [namespace children :: [string trim ${mod}*]]
    # puts \nspace_matches=|${space_matches}|
    set cmd [Lindex $line 1]
    switch -- $pos {
        1 {
            set cmds {
                children code current delete eval export forget
                import inscope origin parent qualifiers tail which}
                    import inscope origin parent qualifiers tail which
                }
            return [TryFromList $text $cmds]
        }
        2 {
            switch -- $cmd {
                children -
                delete -
                eval -
                inscope -
                forget -
                parent -
                qualifiers -
                tail {
                    regsub {^([^:])} ${mod} {::\1} mod; # full qual. name
                    return [TryFromList ${mod} $space_matches]
                        regsub {^([^:])} $mod {::\1} mod; # full qual. name
                        return [TryFromList $mod $space_matches]
                }
                code { return [DisplayHints <script> ] }
                current {}
                export { return [CompleteFromList ${text} {-clear ?pattern?}] }
                    export     { return [CompleteFromList $text {-clear ?pattern?}] }
                import {
                    if {"-" != [string index ${mod} 0]} {
                        regsub {^([^:])} ${mod} {::\1} mod; # full qual. name
                        if {"-" != [string index $mod 0]} {
                            regsub {^([^:])} $mod {::\1} mod; # full qual. name
                    }
                    return [CompleteFromList ${mod} "-force $space_matches"]
                        return [CompleteFromList $mod "-force $space_matches"]
                }
                origin { return [DisplayHints <command>] }
                # qualifiers -
                # tail { return [DisplayHints <string>] }
                which { return [CompleteFromList ${mod} {
                    -command -variable <name>}] }
                    which      { return [CompleteFromList $mod {-command -variable <name>}] }
            }
        }
        3 {
            switch -- $cmd {
                children -
                export -
                forget -
                import { return [DisplayHints ?pattern?] }
                delete { return [TryFromList ${mod} $space_matches] }
                    delete   { return [TryFromList $mod $space_matches] }
                eval -
                inscope {
                    return [BraceOrCommand \
                    $text $start $end $line $pos $mod]
                    inscope  { return [BraceOrCommand $text $start $end $line $pos $mod] }
                }
                which { return [CompleteFromList ${mod} {-variable <name>}] }
                    which    { return [CompleteFromList $mod {-variable <name>}] }
            }
        }
        4 {
            switch -- $cmd {
                export -
                forget -
                import { return [DisplayHints ?pattern?] }
                delete { return [TryFromList ${mod} $space_matches] }
                    delete  { return [TryFromList $mod $space_matches] }
                eval -
                inscope { return [DisplayHints ?arg?] }
                which { return [CompleteFromList ${mod} {<name>}] }
                    which   { return [CompleteFromList $mod {<name>}] }
            }
        }
    }
    return ""
}

proc complete(open) {text start end line pos mod} {
        # 2 { return [DisplayHints ?access?] }
    switch -- $pos {
        2 {
            set access {r r+ w w+ a a+
                RDONLY WRONLY RDWR APPEND CREAT EXCL NOCTTY NONBLOCK TRUNC}
            return [CompleteFromList ${text} ${access}]
                set access {
                    r r+ w w+ a a+
                    RDONLY WRONLY RDWR APPEND CREAT
                    EXCL NOCTTY NONBLOCK TRUNC
                }
                return [CompleteFromList $text $access]
        }
        3 { return [DisplayHints ?permissions?] }
    }
    return ""
}

proc complete(package) {text start end line pos mod} {
    set cmd [Lindex $line 1]
    switch -- $pos {
        1 {
            set cmds {
                forget ifneeded names present provide require
                unknown vcompare versions vsatisfies}
                    unknown vcompare versions vsatisfies
                }
            return [TryFromList $text $cmds]
        }
        2 {
            switch -- ${cmd} {
                switch -- $cmd {
                forget -
                ifneeded -
                provide -
                versions { return [CompleteFromList ${mod} [package names]] }
                    versions   { return [CompleteFromList $mod [package names]] }
                present -
                require {
                    return [CompleteFromList ${mod} "-exact [package names]"] }
                        return [CompleteFromList $mod "-exact [package names]"] }
                names {}
                unknown { return [DisplayHints ?command?] }
                vcompare -
                vsatisfies { return [DisplayHints <version1>] }
            }
        }
        3 {
            set versions ""
            catch [list set versions [package versions [Lindex ${line} 2]]]
            switch -- ${cmd} {
                catch [list set versions [package versions [Lindex $line 2]]]
                switch -- $cmd {
                forget {}
                ifneeded {
                    if {"" != $versions} {
                        return [CompleteFromList ${text} ${versions}]
                            return [CompleteFromList $text $versions]
                    } else {
                        return [DisplayHints <version>]
                    }
                }
                provide {
                    if {"" != ${versions}} {
                        return [CompleteFromList ${text} ${versions}]
                        if {"" != $versions} {
                            return [CompleteFromList $text $versions]
                    } else {
                        return [DisplayHints ?version?]
                    }
                }
                versions {}
                present -
                require {
                    if {"-exact" == [PreviousWord ${start} ${line}]} {
                        return [CompleteFromList ${mod} [package names]]
                        if {"-exact" == [PreviousWord $start $line]} {
                            return [CompleteFromList $mod [package names]]
                    } else {
                        if {"" != ${versions}} {
                            return [CompleteFromList ${text} ${versions}]
                            if {"" != $versions} {
                                return [CompleteFromList $text $versions]
                        } else {
                            return [DisplayHints ?version?]
                        }
                    }
                }
                names {}
                unknown {}
                vcompare -
                vsatisfies { return [DisplayHints <version2>] }
            }
        }
    }
    return ""
}

proc complete(pid) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [ChannelId ${text}] }
        switch -- $pos {
            1 { return [ChannelId $text] }
    }
}

proc complete(pkg_mkIndex) {text start end line pos mod} {
    set cmds [RemoveUsedOptions ${line} {-direct -load -verbose -- <dir>} {--}]
    set res [string trim [TryFromList ${text} ${cmds}]]
    set prev [PreviousWord ${start} ${line}]
    if {"-load" == ${prev}} {
        set cmds [RemoveUsedOptions $line {-direct -load -verbose -- <dir>} {--}]
        set res [string trim [TryFromList $text $cmds]]
        set prev [PreviousWord $start $line]
        if {"-load" == $prev} {
        return [DisplayHints <pkgPat>]
    } elseif {"--" == ${prev}} {
        return [TryFromList ${text} <dir>]
        } elseif {"--" == $prev} {
            return [TryFromList $text <dir>]
    }
    return ${res}
        return $res
}

proc complete(proc) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 {
            set known_procs [ProcsOnlyCompletion ${text}]
            return [CompleteFromList ${text} ${known_procs}]
                set known_procs [ProcsOnlyCompletion $text]
                return [CompleteFromList $text $known_procs]
        }
        2 {
            set proc [Lindex ${line} 1]
            if {[catch {set args [uplevel [info level] info args ${proc}]}]} {
                set proc [Lindex $line 1]
                if {[catch {set args [uplevel [info level] info args $proc]}]} {
                return [DisplayHints <args>]
            } else {
                return [list "\{${args}\}"]
            }
        }
        3 {
            if {![string length [Lindex ${line} ${pos}]]} {
                if {![string length [Lindex $line $pos]]} {
                return [list \{ {}]; # \}
            } else {
                # return [DisplayHints <body>]
                return [BraceOrCommand \
                    return [BraceOrCommand $text $start $end $line $pos $mod]
                ${text} ${start} ${end} ${line} ${pos} ${mod}]
            }
        }
    }
    return ""
}

proc complete(puts) {text start end line pos mod} {
    set cmd [Lindex $line 1]
    switch -- $pos {
        1 {
            return [OutChannelId ${text} "-nonewline"]
                return [OutChannelId $text "-nonewline"]
        }
        2 {
            switch -- $cmd {
                -nonewline { return [OutChannelId ${text}] }
                    -nonewline { return [OutChannelId $text] }
                default { return [DisplayHints <string>] }
            }
        }
        3 {
            switch -- $cmd {
                -nonewline { return [DisplayHints <string>] }
            }
        }
    }
    return ""
}

# proc complete(pwd) {text start end line pos mod} {
# }

proc complete(read) {text start end line pos mod} {
    set cmd [Lindex $line 1]
    switch -- $pos {
        1 {
            return [InChannelId ${text} "-nonewline"]
                return [InChannelId $text "-nonewline"]
        }
        2 {
            switch -- $cmd {
                -nonewline { return [InChannelId ${text}] }
                    -nonewline { return [InChannelId $text] }
                default { return [DisplayHints <numChars>] }
            }
        }
    }
    return ""
}

proc complete(regexp) {text start end line pos mod} {
    set prev [PreviousWord ${start} ${line}]
    if {[llength ${prev}] && "--" != $prev && \
        ("-" == [string index ${prev} 0] || 1 == $pos)} {
        set cmds [RemoveUsedOptions ${line} {
            -nocase -indices -expanded -line
        set prev [PreviousWord $start $line]
        if {[llength $prev] && "--" != $prev
                && ("-" == [string index $prev 0] || 1 == $pos)} {
            set cmds [RemoveUsedOptions $line \
                          {-nocase -indices -expanded -line
            -linestop -lineanchor -about <expression> --} {--}]
        if {[llength ${cmds}]} {
            return [string trim [CompleteFromList ${text} ${cmds}]]
            if {[llength $cmds]} {
                return [string trim [CompleteFromList $text $cmds]]
        }
    } else {
        set virtual_pos [expr ${pos} - [FirstNonOption ${line}]]
        switch -- ${virtual_pos} {
            set virtual_pos [expr {$pos - [FirstNonOption $line]}]
            switch -- $virtual_pos {
            0 { return [DisplayHints <string>] }
            1 { return [DisplayHints ?matchVar?] }
            default { return [DisplayHints ?subMatchVar?] }
        }
    }
    return ""
}

# proc complete(regexp) {text start end line pos mod} {
#     We're not on windoze here ...
# }

proc complete(regsub) {text start end line pos mod} {
    set prev [PreviousWord ${start} ${line}]
    if {[llength ${prev}] && "--" != $prev && \
        ("-" == [string index ${prev} 0] || 1 == ${pos})} {
        set cmds [RemoveUsedOptions ${line} {
            -all -nocase --} {--}]
        if {[llength ${cmds}]} {
            return [string trim [CompleteFromList ${text} ${cmds}]]
        set prev [PreviousWord $start $line]
        if {[llength $prev] && "--" != $prev
                && ("-" == [string index $prev 0] || 1 == $pos)} {
            set cmds [RemoveUsedOptions $line \
                          {-all -nocase --} {--}]
            if {[llength $cmds]} {
                return [string trim [CompleteFromList $text $cmds]]
        }
    } else {
        set virtual_pos [expr ${pos} - [FirstNonOption ${line}]]
        switch -- ${virtual_pos} {
            set virtual_pos [expr {$pos - [FirstNonOption $line]}]
            switch -- $virtual_pos {
            0 { return [DisplayHints <expression>] }
            1 { return [DisplayHints <string>] }
            2 { return [DisplayHints <subSpec>] }
            3 { return [DisplayHints <varName>] }
        }
    }
    return ""
}

proc complete(rename) {text start end line pos mod} {
    switch -- $pos {
        1 {
            return [CompleteFromList ${text} [CommandCompletion ${text}]]
            1 { return [CompleteFromList $text [CommandCompletion $text]] }
        }
        2 {
            return [DisplayHints <newName>]
            2 { return [DisplayHints <newName>] }
        }
    }
    return ""
}

# proc complete(resource) {text start end line pos mod} {
#     This is not a mac ...
# }

proc complete(return) {text start end line pos mod} {
    # TODO this is not perfect yet
    set cmds {-code -errorinfo -errorcode ?string?}
    set res [PreviousWord ${start} ${line}]
    switch -- ${res} {
        set res [PreviousWord $start $line]
        switch -- $res {
        -errorinfo { return [DisplayHints <info>] }
        -code -
        -errorcode {
            set codes {ok error return break continue}
            return [TryFromList ${mod} ${codes}]
                return [TryFromList $mod $codes]
        }
    }
    return [CompleteFromList ${text} [RemoveUsedOptions ${line} ${cmds}]]
        return [CompleteFromList $text [RemoveUsedOptions $line $cmds]]
}

# --- SAFE PACKAGE ---

# create a safe namespace inside
# tclreadline and import some commands.
#
3101
3102
3103
3104
3105
3106
3107
3108

3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120


3121
3122
3123
3124
3125
3126
3127

3128
3129
3130
3131

3132
3133
3134
3135
3136
3137
3138
3139

3140
3141
3142
3143
3144


3145
3146
3147
3148
3149
3150


3151
3152
3153
3154
3155

3156
3157
3158
3159
3160
3161
3162

3163
3164
3165

3166
3167
3168


3169
3170
3171

3172
3173
3174
3175


3176
3177
3178
3179
3180
3181
3182
3183
3184
3185

3186
3187
3188

3189
3190
3191
3192
3193
3194
3195


3196
3197

3198
3199
3200
3201
3202
3203
3204


3205
3206

3207

3208
3209


3210
3211
3212
3213

3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224



3225
3226
3227

3228
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
3424
3425


3426
3427
3428


3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439

3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450







3451
3452
3453
3454


3455
3456
3457
3458
3459

3460
3461
3462
3463
3464
3465
3466
2962
2963
2964
2965
2966
2967
2968

2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979


2980
2981
2982
2983
2984
2985
2986
2987

2988
2989
2990
2991

2992
2993
2994
2995
2996
2997
2998
2999

3000
3001
3002
3003


3004
3005
3006
3007
3008
3009


3010
3011
3012
3013
3014
3015

3016
3017
3018
3019
3020
3021
3022

3023
3024
3025

3026
3027


3028
3029
3030


3031

3032


3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043

3044
3045
3046

3047
3048
3049
3050
3051
3052


3053
3054
3055

3056
3057
3058
3059
3060
3061


3062
3063
3064

3065
3066
3067


3068
3069

3070
3071

3072
3073
3074
3075
3076
3077
3078
3079
3080



3081
3082
3083
3084
3085

3086
3087
3088

3089
3090
3091

3092
3093
3094
3095
3096
3097
3098
3099

3100
3101
3102
3103
3104
3105
3106

3107
3108
3109


3110
3111
3112
3113

3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125

3126
3127
3128
3129
3130
3131
3132


3133
3134
3135
3136
3137
3138

3139


3140

3141

3142
3143
3144

3145

3146
3147
3148
3149
3150


3151
3152
3153
3154


3155
3156
3157

3158

3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177

3178
3179
3180

3181
3182
3183


3184
3185
3186
3187
3188
3189
3190
3191

3192
3193
3194
3195
3196
3197
3198

3199
3200
3201
3202
3203
3204
3205
3206


3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226

3227
3228
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







-
+










-
-
+
+






-
+



-
+







-
+



-
-
+
+




-
-
+
+




-
+






-
+


-
+

-
-
+
+

-
-
+
-

-
-
+
+









-
+


-
+





-
-
+
+

-
+





-
-
+
+

-
+

+
-
-
+
+
-


-
+








-
-
-
+
+
+


-
+


-
+


-
+







-
+






-
+


-
-
+
+


-
+











-
+






-
-
+
+




-
+
-
-
+
-

-
+


-
+
-





-
-
+
+


-
-
+
+

-
+
-



















-
+


-
+


-
-
+
+






-
+






-
+







-
-
+
+


















-
+


-
+


-
+










-
-
+
+

-
+




















-
+


-
+


-
+




-
-
+
+

-
-
+
+










-
+




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


-
-
+
+




-
+







        ::tclreadline::WidgetChildren
    }
    variable opts
    set opts {
        -accessPath -statics -noStatics -nested -nestedLoadOk -deleteHook
    }
    proc SlaveOrOpts {text start line pos slave} {
        set prev [PreviousWord ${start} ${line}]
            set prev [PreviousWord $start $line]
        variable opts
        if {$pos > 1} {
            set slave ""
        }
        switch -- $prev {
            -accessPath { return [DisplayHints <directoryList>] }
            -statics { return [CompleteBoolean $text] }
            -nested { return [CompleteBoolean $text] }
            -deleteHook { return [DisplayHints <script>] }
            default {
                return [CompleteFromList ${text} \
                [RemoveUsedOptions ${line} "${opts} $slave"]]
                    return [CompleteFromList $text \
                                [RemoveUsedOptions $line "$opts $slave"]]
            }
        }
    }
}

proc safe::complete(interpCreate) {text start end line pos mod} {
    return [SlaveOrOpts ${text} ${start} ${line} ${pos} ?slave?]
        return [SlaveOrOpts $text $start $line $pos ?slave?]
}

proc safe::complete(interpInit) {text start end line pos mod} {
    return [SlaveOrOpts ${text} ${start} ${line} ${pos} [interp slaves]]
        return [SlaveOrOpts $text $start $line $pos [interp slaves]]
}

proc safe::complete(interpConfigure) {text start end line pos mod} {
    return [SlaveOrOpts $text $start $line $pos [interp slaves]]
}

proc safe::complete(interpDelete) {text start end line pos mod} {
    return [CompleteFromList ${text} [interp slaves]]
        return [CompleteFromList $text [interp slaves]]
}

proc safe::complete(interpAddToAccessPath) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [CompleteFromList ${text} [interp slaves]] }
        switch -- $pos {
            1 { return [CompleteFromList $text [interp slaves]] }
    }
}

proc safe::complete(interpFindInAccessPath) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [CompleteFromList ${text} [interp slaves]] }
        switch -- $pos {
            1 { return [CompleteFromList $text [interp slaves]] }
    }
}

proc safe::complete(setLogCmd) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 { return [DisplayHints ?cmd?] }
        default { return [DisplayHints ?arg?] }
    }
}

proc safe::complete(loadTk) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 { return [DisplayHints <slave>] }
        default {
            switch -- [PreviousWord ${start} ${line}] {
                switch -- [PreviousWord $start $line] {
                -use {
                    return [CompleteFromList ${text} \
                    [::tclreadline::WidgetChildren ${text}]]
                        return [CompleteFromList $text \
                                    [::tclreadline::WidgetChildren $text]]
                }
                -display {
                    return [DisplayHints <display>]
                    -display { return [DisplayHints <display>] }
                }
                default {
                    return [CompleteFromList ${text} \
                    [RemoveUsedOptions ${line} {-use -display}]]
                        return [CompleteFromList $text \
                                    [RemoveUsedOptions $line {-use -display}]]
                }
            }
        }
    }
}

# --- END OF SAFE PACKAGE ---

proc complete(scan) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 { return [DisplayHints <string>] }
        2 { return [DisplayHints <format>] }
        default { return [VarCompletion ${text}] }
            default { return [VarCompletion $text] }
    }
    return ""
}

proc complete(seek) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [ChannelId ${text}] }
        switch -- $pos {
            1 { return [ChannelId $text] }
        2 { return [DisplayHints <offset>] }
        3 { return [TryFromList ${text} {start current end}] }
            3 { return [TryFromList $text {start current end}] }
    }
    return ""
}

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

proc complete(socket) {text start end line pos mod} {
    set cmd [Lindex ${line} 1]
    set prev [PreviousWord ${start} ${line}]
    if {"-server" == ${cmd}} {
        set cmd [Lindex $line 1]
        set prev [PreviousWord $start $line]
        if {"-server" == $cmd} {
        # server sockets
        #
        switch -- ${pos} {
            switch -- $pos {
            2 { return [DisplayHints <command>] }
            default {
                if {"-myaddr" == ${prev}} {
                    if {"-myaddr" == $prev} {
                    return [DisplayHints <addr>]
                } else {
                    return [CompleteFromList ${mod} \
                        return [CompleteFromList $mod \
                    [RemoveUsedOptions $line {-myaddr -error -sockname <port>}]]
                }
            }
        }
    } else {
        # client sockets
        #
        switch -- ${prev} {
            switch -- $prev {
            -myaddr { return [DisplayHints <addr>] }
            -myport { return [DisplayHints <port>] }
        }

        set hosts [HostList]
        set cmds {-myaddr -myport -async -myaddr -error -sockname -peername}
        if {${pos} <= 1} {
            if {$pos <= 1} {
            lappend cmds -server
        }
        set cmds [RemoveUsedOptions ${line} ${cmds}]
        if {-1 != [lsearch ${hosts} ${prev}]} {
            set cmds [RemoveUsedOptions $line $cmds]
            if {-1 != [lsearch $hosts $prev]} {
            return [DisplayHints <port>]
        } else {
            return [CompleteFromList ${mod} [concat ${cmds} ${hosts}]]
                return [CompleteFromList $mod [concat $cmds $hosts]]
        }
    }
    return ""
}

proc complete(source) {text start end line pos mod} {
    # allow file name completion
    return ""
}

proc complete(split) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 { return [DisplayHints <string>] }
        2 { return [DisplayHints ?splitChars?] }
    }
}

proc complete(string) {text start end line pos mod} {
    set cmd [Lindex ${line} 1]
    set prev [PreviousWord ${start} ${line}]
        set cmd [Lindex $line 1]
        set prev [PreviousWord $start $line]
    set cmds {
        bytelength compare equal first index is last length map match
        range repeat replace tolower toupper totitle trim trimleft
        trimright wordend wordstart}
    switch -- ${pos} {
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} ${cmds}]
            1 { return [CompleteFromList $text $cmds] }
        }
        2 {
            switch -- ${cmd} {
                switch -- $cmd {
                compare -
                equal {
                    return [CompleteFromList ${text} {
                        return [CompleteFromList $text {-nocase -length <string>}]
                        -nocase -length <string> }]
                }

                first -
                last { return [DisplayHints <string1>] }

                map { return [CompleteFromList ${text} {-nocase <charMap>]} }
                match { return [CompleteFromList ${text} {-nocase <pattern>]} }
                    map   { return [CompleteFromList $text {-nocase <charMap>]} }
                    match { return [CompleteFromList $text {-nocase <pattern>]} }

                is {
                    return [CompleteFromList ${text} {
                        alnum alpha ascii boolean control digit double
                        return [CompleteFromList $text \
                                    {alnum alpha ascii boolean control digit double
                        false graph integer lower print punct space
                        true upper wordchar xdigit
                                     true upper wordchar xdigit}]
                    }]
                }

                bytelength -
                index -
                length -
                range -
                repeat -
                replace -
                tolower -
                totitle -
                toupper -
                trim -
                trimleft -
                trimright -
                wordend -
                wordstart { return [DisplayHints <string>] }
            }
        }
        3 {
            switch -- ${cmd} {
                switch -- $cmd {
                compare -
                equal {
                    if {"-length" == ${prev}} {
                        if {"-length" == $prev} {
                        return [DisplayHints <int>]
                    }
                    return [CompleteFromList ${text} \
                    [RemoveUsedOptions ${line} {-nocase -length <string>}]]
                        return [CompleteFromList $text \
                                    [RemoveUsedOptions $line {-nocase -length <string>}]]
                }

                first -
                last { return [DisplayHints <string2>] }

                map {
                    if {"-nocase" == ${prev}} {
                        if {"-nocase" == $prev} {
                        return [DisplayHints <charMap>]
                    } else {
                        return [DisplayHints <string>]
                    }
                }
                match {
                    if {"-nocase" == ${prev}} {
                        if {"-nocase" == $prev} {
                        return [DisplayHints <pattern>]
                    } else {
                        return [DisplayHints <string>]
                    }
                }

                is {
                    return [CompleteFromList ${text} \
                    [RemoveUsedOptions ${line} {-strict -failindex <string>}]]
                        return [CompleteFromList $text \
                                    [RemoveUsedOptions $line {-strict -failindex <string>}]]
                }

                bytelength {}
                index -
                wordend -
                wordstart { return [DisplayHints <charIndex>] }
                range -
                replace { return [DisplayHints <first>] }
                repeat { return [DisplayHints <count>] }
                tolower -
                totitle -
                toupper { return [DisplayHints ?first?] }
                trim -
                trimleft -
                trimright { return [DisplayHints ?chars?] }
            }
        }
        4 {
            switch -- ${cmd} {
                switch -- $cmd {
                compare -
                equal {
                    if {"-length" == ${prev}} {
                        if {"-length" == $prev} {
                        return [DisplayHints <int>]
                    }
                    return [CompleteFromList ${text} \
                        return [CompleteFromList $text \
                    [RemoveUsedOptions $line {-nocase -length <string>}]]
                }

                first -
                last { return [DisplayHints ?startIndex?] }

                map -
                match { return [DisplayHints <string>] }

                is {
                    if {"-failindex" == ${prev}} {
                        return [VarCompletion ${text}]
                        if {"-failindex" == $prev} {
                            return [VarCompletion $text]
                    }
                    return [CompleteFromList ${text} \
                        return [CompleteFromList $text \
                    [RemoveUsedOptions $line {-strict -failindex <string>}]]
                }

                bytelength {}
                index {}
                length {}
                range -
                replace { return [DisplayHints <last>] }
                repeat {}
                tolower -
                totitle -
                toupper { return [DisplayHints ?last?] }
                trim -
                trimleft -
                trimright {}
                wordend -
                wordstart {}
            }
        }
        default {
            switch -- ${cmd} {
                switch -- $cmd {
                compare -
                equal {
                    if {"-length" == ${prev}} {
                        if {"-length" == $prev} {
                        return [DisplayHints <int>]
                    }
                    return [CompleteFromList ${text} \
                        return [CompleteFromList $text \
                    [RemoveUsedOptions $line {-nocase -length <string>}]]
                }

                is {
                    if {"-failindex" == ${prev}} {
                        return [VarCompletion ${text}]
                        if {"-failindex" == $prev} {
                            return [VarCompletion $text]
                    }
                    return [CompleteFromList ${text} \
                    [RemoveUsedOptions ${line} {-strict -failindex <string>}]]
                        return [CompleteFromList $text \
                                    [RemoveUsedOptions $line {-strict -failindex <string>}]]
                }

                replace { return [DisplayHints ?newString?] }
            }
        }
    }
    return ""
}

proc complete(subst) {text start end line pos mod} {
    return [CompleteFromList ${text} [RemoveUsedOptions ${line} {
        return [CompleteFromList $text [RemoveUsedOptions $line {
        -nobackslashes -nocommands -novariables <string>}]]
}

proc complete(switch) {text start end line pos mod} {
    set prev [PreviousWord ${start} ${line}]
    if {[llength ${prev}] && "--" != ${prev} && \
        ("-" == [string index ${prev} 0] || 1 == ${pos})} {
        set cmds [RemoveUsedOptions ${line} {
            -exact -glob -regexp --} {--}]
        if {[llength ${cmds}]} {
            return [string trim [CompleteFromList ${text} ${cmds}]]
        set prev [PreviousWord $start $line]
        if {[llength $prev] && "--" != $prev
                && ("-" == [string index $prev 0] || 1 == $pos)} {
            set cmds [RemoveUsedOptions $line \
                          {-exact -glob -regexp --} {--}]
            if {[llength $cmds]} {
                return [string trim [CompleteFromList $text $cmds]]
        }
    } else {
        set virtual_pos [expr ${pos} - [FirstNonOption ${line}]]
        switch -- ${virtual_pos} {
            set virtual_pos [expr {$pos - [FirstNonOption $line]}]
            switch -- $virtual_pos {
            0 { return [DisplayHints <string>] }
            1 { return [DisplayHints <pattern>] }
            2 { return [DisplayHints <body>] }
            default {
                switch [expr ${virtual_pos} % 2] {
                    switch [expr {$virtual_pos % 2}] {
                    0 { return [DisplayHints ?body?] }
                    1 { return [DisplayHints ?pattern?] }
                }
            }
        }
    }
    return ""
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
3541
3542

3543
3544
3545
3546
3547
3548
3549
3550
3551




3552
3553
3554
3555
3556
3557


3558
3559
3560
3561
3562
3563
3564
3565
3566
3567


3568
3569
3570
3571
3572
3573
3574
3575
3576
3577


3578
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
3651
3652


3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663

3664
3665
3666

3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687

3688
3689
3690
3691
3692
3693
3694
3695
3696
3697

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
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






3424
3425

3426
3427

3428
3429

3430
3431

3432
3433


3434
3435
3436

3437
3438
3439
3440
3441

3442
3443

3444

3445
3446


3447
3448
3449



3450
3451
3452
3453
3454

3455
3456
3457
3458
3459
3460
3461
3462
3463

3464


3465

3466
3467
3468
3469
3470
3471

3472
3473
3474
3475

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

3541
3542

3543
3544
3545
3546
3547
3548
3549
3550
3551
3552

3553
3554
3555
3556
3557
3558
3559
3560







-
-
-
-
+
+
+
+



-
+






-
+



-
+













-
-
+
+






-
-
+
+

-
-
+
+
-


-
+

-
+
-

-
-
+
-
-
-
+
-




-
-
-
-
+
+
+
+
-



-
-
+
+
-







-
-
+
+
-







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

+
-
+

-
+

-
+

-
-
+
+

-
+




-
+

-
+
-


-
-
+
+

-
-
-
+
+
+


-
+








-
+
-
-
+
-






-
+



-
+






-
-
+
+

-
+
-


-
-
+
+










-
+

-
-
+
-



















-
+









-
+

-
+



-
-
+
+
-


-
+









-
+







        ::tclreadline::CompleteFromList \
        ::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} {
            read initialize write add complete customcompleter
        set cmd [Lindex $line 1]
        switch -- $pos {
            1 { return [CompleteFromList $text \
                            {read initialize write add complete customcompleter
            builtincompleter eofchar reset-terminal bell}]
        }
        2 {
            switch -- ${cmd} {
                switch -- $cmd {
                read {}
                initialize {}
                write {}
                add { return [DisplayHints <completerLine>] }
                completer { return [DisplayHints <line>] }
                customcompleter { return [DisplayHints ?scriptCompleter?] }
                builtincompleter { return [CompleteBoolean ${text}] }
                    builtincompleter { return [CompleteBoolean $text] }
                eofchar { return [DisplayHints ?script?] }
                reset-terminal {
                    if {[info exists ::env(TERM)]} {
                        return [CompleteFromList ${text} $::env(TERM)]
                            return [CompleteFromList $text $::env(TERM)]
                    } else {
                        return [DisplayHints ?terminalName?]
                    }
                }
            }
        }
    }
    return ""
}

# --- END OF TCLREADLINE PACKAGE ---

proc complete(tell) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [ChannelId ${text}] }
        switch -- $pos {
            1 { return [ChannelId $text] }
    }
    return ""
}

proc complete(testthread) {text start end line pos mod} {

    set cmd [Lindex ${line} 1]
    switch -- ${pos} {
        set cmd [Lindex $line 1]
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} {
                -async create errorproc exit id names send wait
                return [CompleteFromList $text \
                            {-async create errorproc exit id names send wait}]
            }]
        }
        2 {
            switch -- [PreviousWord ${start} ${line}] {
                switch -- [PreviousWord $start $line] {
                create {
                    return [BraceOrCommand \
                        return [BraceOrCommand $text $start $end $line $pos $mod]
                    ${text} ${start} ${end} ${line} ${pos} ${mod}]
                }
                -async {
                    return [CompleteFromList ${text} send]
                    -async  { return [CompleteFromList $text send] }
                }
                send {
                    return [CompleteFromList ${text} [testthread names]]
                    send    { return [CompleteFromList $text [testthread names]] }
                }
                default {}
            }
        }
        3 {
            if {"send" == [PreviousWord ${start} ${line}]} {
                return [CompleteFromList ${text} [testthread names]]
            } elseif {"send" == ${cmd}} {
                return [BraceOrCommand \
                if {"send" == [PreviousWord $start $line]} {
                    return [CompleteFromList $text [testthread names]]
                } elseif {"send" == $cmd} {
                    return [BraceOrCommand $text $start $end $line $pos $mod]
                ${text} ${start} ${end} ${line} ${pos} ${mod}]
            }
        }
        4 {
            if {"send" == [Lindex ${line} 2]} {
                return [BraceOrCommand \
                if {"send" == [Lindex $line 2]} {
                    return [BraceOrCommand $text $start $end $line $pos $mod]
                ${text} ${start} ${end} ${line} ${pos} ${mod}]
            }
        }
    }
    return ""
}

proc complete(time) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [BraceOrCommand \
        switch -- $pos {
            1 { return [BraceOrCommand $text $start $end $line $pos $mod]
            ${text} ${start} ${end} ${line} ${pos} ${mod}]
        }
        2 { return [DisplayHints ?count?] }
    }
    return ""
}

proc complete(trace) {text start end line pos mod} {
    set cmd [Lindex ${line} 1]
    switch -- ${pos} {
        set cmd [Lindex $line 1]
        switch -- $pos {
        1 {
            return [CompleteFromList ${mod} {variable vdelete vinfo}]
        }
        2 {
            return [CompleteFromList ${text} \
            [uplevel [info level] info vars "${mod}*"]]
            1 { return [CompleteFromList $mod {variable vdelete vinfo}] }
            2 { return [CompleteFromList $text [uplevel [info level] info vars "${mod}*"]] }
        }
        3 {
                # TODO LW: 2 'variable' cases, missing 'vinfo' case?
            switch -- ${cmd} {
                switch -- $cmd {
                variable -
                variable { return [CompleteFromList ${text} {r w u}] }
                    variable { return [CompleteFromList $text {r w u}] }
                vdelete {
                    set var [PreviousWord ${start} ${line}]
                        set var [PreviousWord $start $line]
                    set modes ""
                    foreach info [uplevel [info level] trace vinfo ${var}] {
                        lappend modes [lindex ${info} 0]
                        foreach info [uplevel [info level] trace vinfo $var] {
                            lappend modes [lindex $info 0]
                    }
                    return [CompleteFromList ${text} ${modes}]
                        return [CompleteFromList $text $modes]
                }
            }
        }
        4 {
            switch -- ${cmd} {
                switch -- $cmd {
                variable {
                    return [CompleteFromList ${text} \
                        return [CompleteFromList $text [CommandCompletion $text]]
                    [CommandCompletion ${text}]]
                }
                vdelete {
                    set var [Lindex ${line} 2]
                    set mode [PreviousWord ${start} ${line}]
                        set var [Lindex $line 2]
                        set mode [PreviousWord $start $line]
                    set scripts ""
                    foreach info [uplevel [info level] trace vinfo ${var}] {
                        if {${mode} == [lindex ${info} 0]} {
                            lappend scripts [list [lindex ${info} 1]]
                        foreach info [uplevel [info level] trace vinfo $var] {
                            if {$mode == [lindex $info 0]} {
                                lappend scripts [list [lindex $info 1]]
                        }
                    }
                    return [DisplayHints ${scripts}]
                        return [DisplayHints $scripts]
                }
            }
        }
    }
    return ""
}

proc complete(unknown) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} [CommandCompletion ${text}]]
            1       { return [CompleteFromList $text [CommandCompletion $text]] }
        }
        default { return [DisplayHints ?arg?] }
    }
    return ""
}

proc complete(unset) {text start end line pos mod} {
    return [VarCompletion ${text}]
        return [VarCompletion $text]
}

proc complete(update) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 { return idletasks }
    }
    return ""
}

proc complete(uplevel) {text start end line pos mod} {
    set one [Lindex ${line} 1]
    switch -- ${pos} {
        set one [Lindex $line 1]
        switch -- $pos {
        1 {
            return [CompleteFromList \
                return [CompleteFromList $text "?level? [CommandCompletion $text]"]
            ${text} "?level? [CommandCompletion ${text}]"]
        }
        2 {
            if {"#" == [string index ${one} 0] || [regexp {^[0-9]*$} ${one}]} {
                return [CompleteFromList ${text} [CommandCompletion ${text}]]
                if {"#" == [string index $one 0] || [regexp {^[0-9]*$} $one]} {
                    return [CompleteFromList $text [CommandCompletion $text]]
            } else {
                return [DisplayHints ?arg?]
            }
        }
        default { return [DisplayHints ?arg?] }
    }
    return ""
}

proc complete(upvar) {text start end line pos mod} {
    set one [Lindex ${line} 1]
        set one [Lindex $line 1]
    switch -- $pos {
        1 {
            return [DisplayHints {?level? <otherVar>}]
            1       { return [DisplayHints {?level? <otherVar>}] }
        }
        2 {
            if {"#" == [string index $one 0] || [regexp {^[0-9]*$} $one]} {
                return [DisplayHints <otherVar>]
            } else {
                return [DisplayHints <myVar>]
            }
        }
        3 {
            if {"#" == [string index $one 0] || [regexp {^[0-9]*$} $one]} {
                return [DisplayHints <myVar>]
            } else {
                return [DisplayHints ?otherVar?]
            }
        }
        default {
            set virtual_pos $pos
            if {"#" == [string index $one 0] || [regexp {^[0-9]*$} $one]} {
                incr virtual_pos
            }
            switch [expr $virtual_pos % 2] {
                switch [expr {$virtual_pos % 2}] {
                0 { return [DisplayHints ?myVar?] }
                1 { return [DisplayHints ?otherVar?] }
            }
        }
    }
    return ""
}

proc complete(variable) {text start end line pos mod} {
    set modulo [expr $pos % 2]
        set modulo [expr {$pos % 2}]
    switch -- $modulo {
        1 { return [VarCompletion ${text}] }
            1 { return [VarCompletion $text] }
        0 {
            if {$text == "" || $text == "\"" || $text == "\{"} {
                set line [QuoteQuotes $line]
                if {[catch [list set value [list [uplevel [info level] \
                    set [PreviousWord $start $line]]]] msg]
                    if {[catch {set value [list [uplevel [info level] \
                                    set [PreviousWord $start $line]]]} msg]} {
                } {
                    return ""
                } else {
                    return [Quote $value ${text}]
                        return [Quote $value $text]
                }
            }
        }
    }
    return ""
}

proc complete(vwait) {text start end line pos mod} {
    switch -- $pos {
        1 { return [VarCompletion ${mod}] }
            1 { return [VarCompletion $mod] }
    }
    return ""
}

proc complete(while) {text start end line pos mod} {
    switch -- $pos {
        1 -
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
3761
3762
3763
3764
3568
3569
3570
3571
3572
3573
3574


3575
3576
3577
3578


3579
3580
3581
3582


3583
3584
3585
3586
3587
3588
3589
3590
3591

3592
3593
3594
3595
3596
3597
3598
3599







-
-
+
+


-
-
+
+


-
-
+
+







-
+







# -------------------------------------
#                  TK
# -------------------------------------

# GENERIC WIDGET CONFIGURATION

proc WidgetChildren {{pattern .}} {
    regsub {^([^\.])} ${pattern} {\.\1} pattern
    if {![string length ${pattern}]} {
        regsub {^([^\.])} $pattern {\.\1} pattern
        if {![string length $pattern]} {
        set pattern .
    }
    if {[winfo exists ${pattern}]} {
        return [concat ${pattern} [winfo children ${pattern}]]
        if {[winfo exists $pattern]} {
            return [concat $pattern [winfo children $pattern]]
    } else {
        regsub {.[^.]*$} $pattern {.} pattern
        if {[winfo exists ${pattern}]} {
            return [concat ${pattern} [winfo children ${pattern}]]
            if {[winfo exists $pattern]} {
                return [concat $pattern [winfo children $pattern]]
        } else {
            return ""
        }
    }
}

proc WidgetDescendants {{pattern .}} {
    set tree [WidgetChildren ${pattern}]
        set tree [WidgetChildren $pattern]
    foreach widget $tree {
        append tree " [WidgetDescendants $widget]"
    }
    return $tree
}

proc ToplevelWindows {} {
3774
3775
3776
3777
3778
3779
3780
3781

3782
3783
3784
3785

3786
3787
3788

3789
3790
3791
3792
3793
3794
3795
3609
3610
3611
3612
3613
3614
3615

3616
3617
3618
3619

3620
3621
3622

3623
3624
3625
3626
3627
3628
3629
3630







-
+



-
+


-
+







}

# 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}]
    #   return [CompleteFromOptionsOrSubCmds $text $start $end $line $pos]
# }

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

# TODO
proc CompleteColor {text {add ""}} {

    # we set the variable only once to speed up.
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907



3908

3909



3910

3911
3912
3913
3914
3915





3916
3917

3918
3919
3920
3921

3922
3923
3924
3925
3926
3927
3928
3929


3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942

3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959

3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973

3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985

3986
3987
3988
3989
3990
3991
3992
3993

3994
3995
3996
3997
3998
3999

4000
4001
4002
4003

4004
4005
4006
4007
4008
4009

4010
4011
4012
4013


4014
4015

4016
4017
4018
4019
4020
4021
4022
4023
4024
4025

4026
4027

4028
4029
4030
4031
4032
4033
4034
4035
4036

4037
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
4650
4651
4652
4653
4654


4655
4656
4657


4658
4659

4660
4661
4662
4663
4664
4665
4666
4667

4668
4669
4670


4671
4672
4673

4674
4675
4676
4677
4678

4679
4680
4681

4682
4683
4684
4685
4686
4687

4688
4689

4690
4691

4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708


4709
4710
4711
4712

4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723

4724
4725
4726
4727



4728
4729
4730
4731
4732
4733
4734


4735
4736
4737
4738
4739
4740
4741
4742



4743
4744
4745
4746



4747
4748

4749
4750
4751
4752

4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764

4765
4766
4767

4768
4769
4770
4771
4772

4773
4774

4775
4776
4777
4778
4779
4780
4781

4782
4783
4784

4785
4786
4787
4788
4789
4790
4791



4792
4793
4794
4795
4796
4797
4798

4799
4800
4801
4802
4803

4804
4805
4806
4807

4808
4809
4810
4811
4812
4813
4814


4815
4816
4817
4818
4819

4820
4821
4822
4823
4824


4825
4826
4827
4828
4829

4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840



4841
4842
4843


4844
4845
4846
4847

4848
4849
4850
4851
4852
4853

4854
4855
4856


4857
4858
4859
4860



4861
4862
4863
4864
4865
4866



4867
4868
4869
4870
4871
4872

4873
4874
4875
4876
4877

4878
4879
4880


4881
4882

4883
4884

4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895




4896
4897
4898
4899
4900
4901

4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915




4916
4917
4918
4919
4920
4921
4922

4923
4924
4925
4926
4927
4928
4929
4930
4931


4932
4933
4934


4935
4936
4937
4938

4939
4940
4941
4942
4943
4944
4945
4946
4947


4948
4949
4950


4951
4952
4953
4954
4955

4956
4957
4958
4959
4960
4961
4962
4963

4964
4965
4966

4967
4968
4969
4970
4971
4972
4973


4974
4975
4976


4977
4978
4979

4980
4981
4982
4983
4984
4985
4986
4987
4988


4989
4990
4991


4992
4993
4994
4995
4996

4997
4998
4999
5000
5001
5002
5003
5004
5005


5006
5007
5008


5009
5010
5011

5012
5013
5014
5015
5016
5017
5018
5019
5020

5021
5022
5023
5024
5025
5026


5027
5028

5029
5030
5031
5032
5033

5034
5035
5036

5037
5038
5039
5040
5041
5042

5043
5044
5045

5046
5047
5048
5049
5050


5051
5052

5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067


5068
5069
5070
5071

5072
5073
5074
5075
5076




5077
5078
5079
5080
5081
5082
5083
5084


5085
5086
5087
5088


5089
5090
5091
5092
5093
5094
5095
5096



5097
5098
5099
5100



5101
5102
5103
5104

5105
5106
5107
5108
5109
5110

5111
5112
5113

5114
5115
5116
5117
5118
5119


5120
5121
5122
5123

5124
5125
5126
5127
5128


5129
5130
5131
5132
5133

5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146

5147
5148

5149
5150
5151
5152
5153
5154
5155

5156
5157
5158
5159
5160
5161
5162

5163
5164

5165
5166
5167

5168
5169
5170
5171
5172
5173
5174
5175
5176



5177
5178
5179
5180



5181
5182
5183
5184

5185
5186
5187
5188
5189

5190
5191
5192

5193
5194
5195
5196
5197
5198


5199
5200
5201
5202
5203
5204
5205

5206
5207
5208
5209
5210
5211
5212
5213
5214
5215


5216
5217
5218


5219
5220
5221
5222
5223
5224

5225
5226
5227
5228
5229
5230
5231
5232

5233
5234
5235
5236
5237


5238
5239
5240


5241
5242
5243
5244
5245
5246

5247
5248
5249
5250
5251
5252
5253
5254
5255


5256
5257
5258


5259
5260
5261
5262

5263
5264
5265
5266
5267
5268
5269
5270
5271


5272
5273
5274

5275
5276

5277
5278
5279
5280
5281

5282
5283
5284
5285

5286
5287
5288

5289
5290
5291
5292
5293

5294
5295
5296

5297
5298
5299
5300
5301
5302
5303

5304
5305

5306
5307
5308
5309
5310



5311
5312

5313
5314

5315
5316
5317
5318

5319
5320

5321
5322
5323
5324

5325
5326

5327
5328
5329

5330
5331

5332
5333
5334
5335
5336
5337
5338
5339
5340
5341



5342
5343

5344
5345
5346
5347


5348
5349
5350

5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362


5363
5364
5365


5366
5367
5368
5369
5370
5371
5372

5373
5374
5375
5376
5377
5378
5379
5380

5381
5382

5383
5384
5385

5386
5387
5388

5389
5390

5391
5392
5393
5394
5395


5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410



5411
5412
5413
5414


5415
5416
5417
5418
5419
5420
5421


5422
5423
5424

5425
5426
5427
5428
5429
5430
5431
5432


5433
5434
5435
5436
5437
5438


5439
5440
5441
5442
5443
5444
5445
5446
5447

5448
5449
5450
5451
5452
5453

5454
5455
5456
5457
5458
5459
5460




5461
5462
5463
5464
5465
5466

5467
5468
5469
5470
5471

5472
5473
5474
5475
5476

5477
5478
5479

5480
5481
5482
5483
5484

5485
5486
5487
5488
5489

5490
5491
5492
5493
5494
5495



5496
5497
5498
5499
5500
5501




5502
5503
5504
5505
5506
5507
5508
5509



5510
5511
5512
5513
5514
5515
5516

5517
5518
5519
5520

5521
5522
5523
5524



5525
5526
5527
5528


5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548

5549
5550

5551
5552
5553

5554
5555

5556
5557
5558

5559
5560
5561
5562
5563
5564
5565
5566

5567
5568
5569

5570
5571
5572
5573

5574
5575

5576
5577
5578
5579

5580
5581
5582
5583
5584
5585
5586
5587
5588


5589
5590
5591


5592
5593
5594

5595
5596
5597
5598
5599
5600
5601
5602
5603


5604
5605

5606
5607
5608

5609
5610

5611
5612

5613
5614
5615
5616

5617
5618
5619
5620


5621
5622
5623
5624
5625
5626
5627
5628

5629
5630
5631


5632
5633
5634
5635
5636
5637
5638
5639

5640
5641

5642
5643

5644
5645
5646
5647

5648
5649
5650

5651
5652
5653
5654
5655
5656
5657
5658
5659


5660
5661
5662
5663
5664
5665
5666
5667
5668
5669


5670
5671
5672
5673
5674
5675
5676
5677
5678

5679
5680
5681
5682
5683
5684
5685
5686
5687
5688


5689
5690
5691


5692
5693
5694
5695

5696
5697
5698
5699

5700
5701
5702

5703
5704
5705
5706
5707


5708
5709
5710
5711
5712

5713
5714
5715

5716
5717
5718
5719

5720
5721
5722

5723
5724
5725

5726
5727
5728
5729
5730

5731
5732
5733

5734
5735
5736
5737


5738
5739
5740
5741
5742

5743
5744
5745
5746

5747
5748
5749
5750
5751

5752
5753
5754
5755
5756
5757
5758

5759
5760
5761
5762
5763
5764
5765

5766
5767
5768
5769
5770
5771

5772
5773
5774
5775
5776
5777
5778
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
3761
3762
3763
3764
3765


3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
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
3885
3886

3887
3888

3889
3890
3891
3892
3893
3894
3895
3896

3897

3898
3899
3900
3901


3902



3903
3904
3905

3906


3907




3908
3909

3910



3911
3912
3913
3914
3915
3916
3917
3918
3919

3920

3921
3922
3923
3924
3925
3926
3927
3928
3929
3930

3931
3932



3933
3934
3935
3936

3937

3938
3939
3940
3941
3942
3943
3944
3945


3946
3947
3948


3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969


3970
3971
3972
3973
3974

3975
3976

3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987


3988
3989
3990
3991

3992
3993
3994
3995

3996

3997
3998
3999
4000
4001
4002


4003
4004
4005

4006




4007
4008
4009
4010
4011
4012
4013
4014
4015


4016
4017
4018


4019
4020
4021
4022
4023
4024
4025
4026

4027

4028
4029
4030
4031
4032
4033


4034
4035
4036


4037
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
4650
4651
4652

4653

4654
4655
4656
4657
4658
4659

4660
4661


4662

4663
4664
4665
4666


4667
4668
4669


4670
4671
4672
4673

4674

4675
4676
4677
4678
4679
4680


4681
4682
4683


4684
4685
4686
4687
4688
4689

4690

4691
4692
4693
4694
4695
4696


4697
4698
4699


4700
4701
4702
4703

4704

4705
4706
4707
4708
4709
4710


4711

4712
4713
4714


4715
4716


4717



4718

4719
4720


4721

4722
4723
4724
4725

4726
4727
4728

4729
4730
4731
4732


4733
4734


4735


4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746


4747
4748
4749
4750
4751

4752
4753




4754
4755
4756
4757
4758
4759
4760
4761
4762
4763


4764
4765
4766
4767


4768
4769
4770
4771
4772
4773
4774



4775
4776
4777
4778



4779
4780
4781

4782
4783

4784
4785
4786
4787
4788


4789



4790

4791
4792
4793


4794
4795




4796

4797
4798


4799
4800
4801
4802
4803


4804

4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815

4816
4817

4818
4819
4820
4821
4822
4823
4824

4825
4826
4827
4828
4829
4830
4831

4832


4833



4834


4835
4836
4837
4838



4839
4840
4841
4842



4843
4844
4845

4846
4847

4848
4849
4850
4851


4852



4853

4854
4855
4856


4857
4858


4859
4860
4861


4862

4863
4864
4865
4866
4867
4868
4869


4870
4871
4872


4873
4874
4875
4876
4877
4878
4879

4880

4881
4882
4883
4884
4885
4886

4887
4888
4889
4890


4891
4892
4893


4894
4895
4896
4897
4898
4899
4900

4901

4902
4903
4904
4905
4906
4907


4908
4909
4910


4911
4912
4913
4914
4915

4916

4917
4918
4919
4920
4921
4922


4923
4924
4925
4926

4927


4928


4929
4930

4931
4932
4933
4934

4935
4936
4937

4938

4939
4940
4941

4942
4943
4944

4945

4946
4947
4948
4949
4950

4951


4952

4953



4954
4955
4956
4957

4958


4959

4960
4961

4962


4963

4964
4965

4966


4967
4968
4969

4970


4971
4972
4973
4974
4975
4976
4977
4978



4979
4980
4981
4982

4983




4984
4985

4986

4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997


4998
4999
5000


5001
5002
5003
5004
5005
5006
5007
5008

5009

5010
5011
5012
5013
5014
5015

5016


5017

5018

5019
5020
5021

5022
5023

5024

5025
5026


5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040



5041
5042
5043
5044
5045


5046
5047
5048
5049
5050
5051
5052


5053
5054
5055
5056

5057
5058
5059
5060
5061
5062
5063


5064
5065
5066
5067
5068
5069


5070
5071
5072
5073
5074
5075
5076
5077
5078
5079

5080
5081
5082
5083
5084


5085

5086
5087




5088
5089
5090
5091
5092
5093
5094
5095
5096

5097

5098
5099
5100

5101

5102
5103
5104

5105



5106





5107


5108


5109

5110
5111



5112
5113
5114
5115
5116




5117
5118
5119
5120
5121
5122
5123
5124
5125



5126
5127
5128
5129
5130
5131
5132
5133
5134

5135
5136
5137
5138

5139
5140



5141
5142
5143
5144
5145


5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166

5167


5168

5169

5170


5171



5172

5173
5174
5175
5176
5177
5178

5179



5180


5181

5182


5183

5184


5185

5186
5187
5188
5189
5190
5191


5192
5193
5194


5195
5196
5197
5198

5199

5200
5201
5202
5203
5204
5205


5206
5207


5208

5209

5210


5211


5212




5213

5214


5215
5216




5217
5218
5219

5220
5221


5222
5223



5224
5225
5226
5227

5228
5229

5230


5231




5232



5233

5234
5235
5236
5237
5238
5239


5240
5241



5242
5243
5244
5245
5246


5247
5248



5249
5250
5251
5252


5253

5254
5255
5256
5257
5258
5259
5260


5261
5262
5263


5264
5265
5266
5267
5268

5269

5270


5271

5272

5273
5274
5275
5276


5277
5278
5279
5280
5281


5282



5283

5284


5285

5286

5287
5288
5289

5290


5291
5292

5293
5294


5295

5296


5297
5298

5299
5300
5301

5302




5303

5304
5305
5306

5307
5308
5309
5310
5311
5312
5313

5314

5315
5316
5317
5318
5319

5320
5321
5322
5323
5324
5325

5326
5327
5328
5329
5330
5331
5332
5333







-
-
-
+
+
+

+
-
+
+
+

+
-
-
-
-
-
+
+
+
+
+

-
+
-


-
+






-
-
+
+












-
+
-











-



-
+













-
+











-
+







-
+




-
-
+



-
+





-
+


-
-
+
+

-
+







-

-
+

-
+
-
-






-
+





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

-
+
-
-



-
+





-
+

-
+







-
+
-




-
-
+
-
-
-



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

-
-
-
+
+
+






-
+
-










-


-
-
-
+
+
+

-
+
-








-
-
+
+

-
-
+
+



















-
-
+
+



-
+

-
+










-
-
+
+


-
+



-
+
-






-
-
+
+

-
+
-
-
-
-
+
+
+






-
-
+
+

-
-
+
+






-
+
-






-
-
+
+

-
-
+
+





-
+
-






-
-
+
+

-
-
+
+







-
+
-






-
-
+
+

-
-
-
+
+
+

-
+

-
+




-
-
+
+
-
-
+


-
+





-
+

-
+


-
-
+
+
-
-









-
-
+
+



-
-
+
+

-
-
+
+





-
+
-






-
-
+
+

-
+


-
+


-
-
+
-
-
+
-
-



-
+


-
-
+
-




-
+

-
-
+
-


-
-
+
-


-
+
-
-
-










-
-
+
+


-
+
-




-
+







-
-
-
+
+
+
-



-
+
-
-








-
+
-
-
-
+
+
-
-



-
-
+
-
-
-
+
-

-
-
-
+
+
+



-
+
-
-
+






-




-
+

-
-
+
+


-
+



-
+
-









-
+
-
-
+
-

-
+

-
-
+
-
-
-
+
-

-
+
-







-
-
-
+
+
+

-
-
-
+
+
+


-
+


-
-
+
-



-
-
+
+




-
-
+
-
-
-
-
+
-




-
+
-
-
+
-
-

-
-
+
-


-
-
+
+





-
+
-
-
+
-


-
-
-
+
-
-
-
+
-
-




-
+

-
+
-
-
+
-
-
-
-
+


-

-
-
+
-


-
-
+
+






-
+
-
-
+
-
-
-
-
+
-



-
-
-
+
+
+
-
-
-
-
-






-
+


-
-
+
-


-
-
+
+





-
-
+
-
-
-
+
-








-
-
+
+

-
-
+
+

-
+
-






-
+

-
-
+
+


-
+



-
-
+
-

-
+
-




-
+

-
+
-
-
+
-
-













-
-
+
+



-
+










-
+

-
-
-
+
+
+



-

-
-
+
+





-
-
-
+
+
+

-
-
-
+
+
+

-
+
-


-
+










-
-
+
-
-
-
+
-



-
+

-
+






-
+


-
+




-
-
-
+
+
+
-





-
+
-
-

-
-
+
-


-
+





-
-
+
+




-
+



-
-
+
+



-
-
+
-







-
-
-
+
+
+

-
-
+
+



-
+





-
+

-
-
+
+

-
-
-
+
+
+
-


-
-
-
+
+
+
-




-
+




-
+

-
-
+
+
-
-
+

-
+







-
-
-
-
+
+
+
+
-




-
+










-
-
-
-
+
+
+
+
-





-
+







-
-
+
+

-
-
+
+



-
+
-






-
-
+
+

-
-
+
+




-
+
-






-
+

-
-
+
-




-
-
+
+

-
-
+
+


-
+
-






-
-
+
+

-
-
+
+




-
+
-






-
-
+
+

-
-
+
+


-
+
-






-
-
+
-



-
-
+
+
-
-
+
-
-
-

-
+

-
-
+
-




-
+


-
+



-
-
+
+
-
-
+
-
-











-
-
+
+



-
+

-
-
-
-
+
+
+
+






-
-
+
+


-
-
+
+





-
-
-
+
+
+

-
-
-
+
+
+
-


-
+




-
-
+
-
-
-
+
-



-
-
+
+
-
-
-
-
+
-


-
-
+
+



-
-
+
-











-
+

-
+






-
+






-
+
-
-
+
-
-
-
+
-
-




-
-
-
+
+
+

-
-
-
+
+
+
-


-
+



-
-
+
-
-
-
+
-



-
-
+
+
-
-



-
-
+
-







-
-
+
+

-
-
+
+





-
+
-






-
+



-
-
+
+

-
-
+
+





-
+
-






-
-
+
+

-
-
+
+



-
+
-






-
-
+
+


-
+
-
-
+
-
-


-
+



-
+


-
+
-



-
+


-
+
-





-
+
-
-
+
-

-
-
-
+
+
+

-
+
-
-
+
-


-
+
-
-
+
-


-
+
-
-
+


-
+
-
-
+







-
-
-
+
+
+

-
+
-
-
-
-
+
+
-

-
+










-
-
+
+

-
-
+
+






-
+
-






-
+
-
-
+
-

-
+


-
+

-
+
-


-
-
+
+












-
-
-
+
+
+


-
-
+
+





-
-
+
+


-
+






-
-
+
+




-
-
+
+








-
+




-
-
+
-


-
-
-
-
+
+
+
+





-
+
-



-
+
-



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

-
-
+
-


-
-
-
+
+
+


-
-
-
-
+
+
+
+





-
-
-
+
+
+






-
+



-
+

-
-
-
+
+
+


-
-
+
+



















-
+
-
-
+
-

-
+
-
-
+
-
-
-
+
-






-
+
-
-
-
+
-
-

-
+
-
-
+
-

-
-
+
-






-
-
+
+

-
-
+
+


-
+
-






-
-
+
+
-
-
+
-

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

-
-
+
+
-
-
-
-



-
+

-
-
+
+
-
-
-




-
+

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






-
-
+
+
-
-
-





-
-
+
+
-
-
-




-
-
+
-







-
-
+
+

-
-
+
+



-
+
-

-
-
+
-

-
+



-
-
+
+



-
-
+
-
-
-
+
-

-
-
+
-

-
+


-
+
-
-


-
+

-
-
+
-

-
-
+
+
-



-
+
-
-
-
-
+
-



-
+






-
+
-





-
+





-
+







            gray92 grey92 gray93 grey93 gray94 grey94 gray95 grey95 gray96
            grey96 gray97 grey97 gray98 grey98 gray99 grey99 gray100 grey100
            DarkGrey DarkGray DarkBlue DarkCyan DarkMagenta DarkRed LightGreen
        }
    }
    if ![info exists numberless_colors] {
        set numberless_colors ""
        foreach color ${colors} {
            regsub -all {[0-9]*} ${color} "" color
            lappend numberless_colors ${color}
            foreach color $colors {
                regsub -all {[0-9]*} $color "" color
                lappend numberless_colors $color
        }
            if {[info tclversion] < 8.3} {
        set numberless_colors [Lunique [lsort ${numberless_colors}]]
                set numberless_colors [Lunique [lsort $numberless_colors]]
            } else {
                set numberless_colors [lsort -unique $numberless_colors]
    }
        }
    set matches [MatchesFromList ${text} ${numberless_colors}]
    if {[llength ${matches}] < 5} {
        set matches [MatchesFromList ${text} ${colors}]
        if {[llength ${matches}]} {
            return [CompleteFromList ${text} [concat ${colors} ${add}]]
        set matches [MatchesFromList $text $numberless_colors]
        if {[llength $matches] < 5} {
            set matches [MatchesFromList $text $colors]
            if {[llength $matches]} {
                return [CompleteFromList $text [concat $colors $add]]
        } else {
            return [CompleteFromList ${text} \
                return [CompleteFromList $text [concat $numberless_colors $add]]
            [concat ${numberless_colors} ${add}]]
        }
    } else {
        return [CompleteFromList ${text} [concat ${numberless_colors} ${add}]]
            return [CompleteFromList $text [concat $numberless_colors $add]]
    }
}

proc CompleteCursor text {
    # from <X11/cursorfont.h>
    #
    return [CompleteFromList ${text} {
        num_glyphs x_cursor arrow based_arrow_down based_arrow_up
        return [CompleteFromList $text \
                    {num_glyphs x_cursor arrow based_arrow_down based_arrow_up
        boat bogosity bottom_left_corner bottom_right_corner
        bottom_side bottom_tee box_spiral center_ptr circle clock
        coffee_mug cross cross_reverse crosshair diamond_cross dot
        dotbox double_arrow draft_large draft_small draped_box
        exchange fleur gobbler gumby hand1 hand2 heart icon iron_cross
        left_ptr left_side left_tee leftbutton ll_angle lr_angle
        man middlebutton mouse pencil pirate plus question_arrow
        right_ptr right_side right_tee rightbutton rtl_logo sailboat
        sb_down_arrow sb_h_double_arrow sb_left_arrow sb_right_arrow
        sb_up_arrow sb_v_double_arrow shuttle sizing spider spraycan
        star target tcross top_left_arrow top_left_corner
        top_right_corner top_side top_tee trek ul_angle umbrella
        ur_angle watch xterm
                     ur_angle watch xterm}]
    }]
}

#**
# 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.
# @return   a std tclreadline formatted completer string.
# @sa       CompleteWidgetConfigurations
# @date     Sep-17-1999
#
proc SpecificSwitchCompleter {text start line switch {always 1}} {

    switch -- ${switch} {
        switch -- $switch {

        -activebackground -
        -activeforeground -
        -fg -
        -foreground -
        -bg -
        -background -
        -disabledforeground -
        -highlightbackground -
        -highlightcolor -
        -insertbackground -
        -troughcolor -
        -selectbackground -
        -selectforeground { return [CompleteColor ${text}] }
            -selectforeground    { return [CompleteColor $text] }

        -activeborderwidth -
        -bd -
        -borderwidth -
        -insertborderwidth -
        -insertwidth -
        -selectborderwidth -
        -highlightthickness -
        -padx -
        -pady -
        -wraplength {
            if ${always} {
                if $always {
                return [DisplayHints <pixels>]
            } else {
                return ""
            }
        }

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


        -bitmap { return [CompleteFromBitmaps ${text} ${always}] }
            -bitmap { return [CompleteFromBitmaps $text $always] }


        -cursor {
            return [CompleteCursor ${text}]
                return [CompleteCursor $text]
            # return [DisplayHints <cursor>]
        }
        -exportselection -
        -jump -
        -setgrid -
        -takefocus { return [CompleteBoolean ${text}] }
            -takefocus       { return [CompleteBoolean $text] }
        -font {
            set names [font names]
            if {[string length ${names}]} {
                return [CompleteFromList ${text} ${names}]
                if {[string length $names]} {
                    return [CompleteFromList $text $names]
            } else {
                if ${always} {
                    if $always {
                    return [DisplayHints <font>]
                } else {
                    return ""
                }
            }
        }


        -image -
        -selectimage { return [CompleteFromImages ${text} ${always}] }
            -selectimage { return [CompleteFromImages $text $always] }
        -selectmode {
            return [CompleteFromList ${text} {
                return [CompleteFromList $text {single browse multiple extended}]
                single browse multiple extended
            }]
        }

        -insertofftime -
        -insertontime -
        -repeatdelay -
        -repeatinterval {
            if ${always} {
                if $always {
                return [DisplayHints <milliSec>]
            } else {
                return ""
            }
        }
        -justify {
            return [CompleteFromList ${text} {
            -justify        { return [CompleteFromList $text {left center right}] }
                left center right
            }]
        }
        -orient {
            return [CompleteFromList ${text} {
            -orient         { return [CompleteFromList $text {vertical horizontal}] }
                vertical horizontal
            }]
        }
        -relief {
            return [CompleteFromList ${text} {
                return [CompleteFromList $text { raised sunken flat ridge solid groove }]
                raised sunken flat ridge solid groove
            }]
        }

        -text {
            if ${always} {
                if $always {
                return [DisplayHints <text>]
            } else {
                return ""
            }
        }
        -textvariable { return [VarCompletion ${text} #0] }
            -textvariable { return [VarCompletion $text #0] }
        -underline {
            if ${always} {
                if $always {
                return [DisplayHints <index>]
            } else {
                return ""
            }
        }

-xscrollcommand -
-yscrollcommand {
            -yscrollcommand {}
}

        # WIDGET SPECIFIC OPTIONS
        # ---

        -state {
            return [CompleteFromList ${text} {
            -state { return [CompleteFromList $text {normal active disabled}] }
                normal active disabled
            }]
        }

        -columnbreak -
        -hidemargin -
        -indicatoron {
            -indicatoron { return [CompleteBoolean $text] }
            return [CompleteBoolean ${text}]
        }


        -variable {
            return [VarCompletion ${text} #0]
        }
            -variable { return [VarCompletion $text #0] }


        default {
            # if ${always} {
            #   set prev [PreviousWord ${start} ${line}]
            #   return [DisplayHints <[String range ${prev} 1 end]>]
                # if $always {
                #   set prev [PreviousWord $start $line]
                #   return [DisplayHints <[String range $prev 1 end]>]
            #} else {
                return ""
            #}
        }
    }
}
            # return [BraceOrCommand ${text} \
                # return [BraceOrCommand $text $start $line $pos $mod]
            # ${start}  ${line} ${pos} ${mod}]

#**
# CompleteWidgetConfigurations
# ---
# @param    text  -- the word to complete.
# @param    start -- the actual cursor position.
# @param    line  -- the line gathered so far.
# @param    lst   -- a list of possible completions.
# @return   a std tclreadline formatted completer string.
# @sa       SpecificSwitchCompleter
# @date     Sep-17-1999
#
proc CompleteWidgetConfigurations {text start line lst} {
    set prev [PreviousWord ${start} ${line}]
    if {"-" == [string index ${prev} 0]} {
        return [SpecificSwitchCompleter ${text} ${start} ${line} ${prev}]
        set prev [PreviousWord $start $line]
        if {"-" == [string index $prev 0]} {
            return [SpecificSwitchCompleter $text $start $line $prev]
    } else {
        return [CompleteFromList ${text} \
            return [CompleteFromList $text [RemoveUsedOptions $line $lst]]
        [RemoveUsedOptions ${line} ${lst}]]
    }
}

# --------------------------------------
# === SPECIFIC TK COMMAND COMPLETERS ===
# --------------------------------------

proc complete(bell) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [CompleteFromList ${text} -displayof] }
        switch -- $pos {
            1 { return [CompleteFromList $text -displayof] }
        2 {
            if {"-displayof" == [PreviousWord ${start} ${line}]} {
                return [CompleteFromList ${text} [ToplevelWindows]]
                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} < - >]
        set sequence [concat $modifiers $events]
        return [CompleteListFromList $text $fulltext $sequence < - >]
}

proc complete(bind) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 {
            set widgets [WidgetChildren ${text}]
                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]]
                return [CompleteFromList $text \
                            [concat $toplevels $widgets $toplevelClass $rest]]
        }
        2 {
            return [CompleteSequence ${text} [Lindex ${line} 2]]
                return [CompleteSequence $text [Lindex $line 2]]
        }
        default {
            # return [DisplayHints {<script> <+script>}]
            return [BraceOrCommand ${text} \
                return [BraceOrCommand $text $start $end $line $pos $mod]
            ${start} ${end} ${line} ${pos} ${mod}]
        }
    }
    return ""
}

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

proc complete(button) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -activebackground -activeforeground -anchor
                return [CompleteWidgetConfigurations $text $start $line \
                            {-activebackground -activeforeground -anchor
                -background -bitmap -borderwidth -cursor
                -disabledforeground -font -foreground
                -highlightbackground -highlightcolor
                -highlightthickness -image -justify
                -padx -pady -relief -takefocus -text
                -textvariable -underline -wraplength
                -command -default -height -state -width
                             -command -default -height -state -width}]
            }]
        }
    }
    return ""
}

proc complete(canvas) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -background -borderwidth -cursor -highlightbackground
                return [CompleteWidgetConfigurations $text $start $line \
                            {-background -borderwidth -cursor -highlightbackground
                -highlightcolor -highlightthickness -insertbackground
                -insertborderwidth -insertofftime -insertontime
                -insertwidth -relief -selectbackground -selectborderwidth
                -selectforeground -takefocus -xscrollcommand -yscrollcommand
                -closeenough -confine -height -scrollregion -width
                -xscrollincrement -yscrollincrement
                             -xscrollincrement -yscrollincrement}]
            }]
        }
    }
    return ""
}

proc complete(checkbutton) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -activebackground activeBackground Foreground
                return [CompleteWidgetConfigurations $text $start $line \
                            {-activebackground activeBackground Foreground
                -activeforeground -anchor -background -bitmap
                -borderwidth -cursor -disabledforeground -font
                -foreground -highlightbackground -highlightcolor
                -highlightthickness -image -justify -padx -pady
                -relief -takefocus -text -textvariable -underline
                -wraplength -command -height -indicatoron -offvalue
                -onvalue -selectcolor -selectimage -state -variable
                -width
                             -width}]
            }]
        }
    }
    return ""
}

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

proc complete(destroy) {text start end line pos mod} {
    set remaining [RemoveUsedOptions ${line} [WidgetChildren ${text}]]
    return [CompleteFromList ${text} ${remaining}]
        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>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -background -borderwidth -cursor -exportselection
                return [CompleteWidgetConfigurations $text $start $line \
                            {-background -borderwidth -cursor -exportselection
                -font -foreground -highlightbackground -highlightcolor
                -highlightthickness -insertbackground -insertborderwidth
                -insertofftime -insertontime -insertwidth -justify -relief
                -selectbackground -selectborderwidth -selectforeground
                -takefocus -textvariable -xscrollcommand -show -state
                -width
                             -width}]
            }]
        }
    }
    return ""
}

proc complete(event) {text start end line pos mod} {
    set sub [Lindex ${line} 1]
    switch -- ${pos} {
        set sub [Lindex $line 1]
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} { add delete generate info }]
                return [CompleteFromList $text {add delete generate info}]
        }
        2 {
            switch -- ${sub} {
                switch -- $sub {
                add { return [DisplayHints <<virtual>>] }
                info -
                delete {
                    return [CompleteFromList ${text} [event info] "<"]
                    delete   { return [CompleteFromList $text [event info] "<"] }
                }
                generate {
                    generate { return [TryFromList $text [WidgetChildren $text]] }
                    return [TryFromList ${text} [WidgetChildren ${text}]]
                }
            }
        }
        3 {
            switch -- ${sub} {
                switch -- $sub {
                add -
                delete -
                generate {
                    return [CompleteSequence ${text} [Lindex ${line} 3]]
                    generate { return [CompleteSequence $text [Lindex $line 3]] }
                }
                info {}
            }
        }
        default {
            switch -- ${sub} {
                switch -- $sub {
                add -
                delete {
                    return [CompleteSequence ${text} [Lindex ${line} 3]]
                    delete   { return [CompleteSequence $text [Lindex $line 3]] }
                }
                info {}
                generate {

                    switch -- [PreviousWord ${start} ${line}] {
                        switch -- [PreviousWord $start $line] {

                        -above -
                        -root -
                        -subwindow {
                            -subwindow { return [TryFromList $text [WidgetChildren $text]] }
                            return [TryFromList ${text} \
                            [WidgetChildren ${text}]]
                        }

                        -borderwidth { return [DisplayHints <size>] }

                        -button -
                        -delta -
                        -keycode -
                        -serial -
                        -count { return [DisplayHints <number>] }

                        -detail {
                            return [CompleteFromList ${text} {
                                NotifyAncestor    NotifyNonlinearVirtual
                                return [CompleteFromList $text \
                                            {NotifyAncestor    NotifyNonlinearVirtual
                                NotifyDetailNone  NotifyPointer
                                NotifyInferior    NotifyPointerRoot
                                NotifyNonlinear   NotifyVirtual
                                             NotifyNonlinear   NotifyVirtual}]
                            }]
                        }

                        -focus -
                        -override -
                        -sendevent { return [CompleteBoolean ${text}] }
                            -sendevent { return [CompleteBoolean $text] }

                        -height -
                        -width { return [DisplayHints <size>] }

                        -keysym { return [DisplayHints <name>] }

                        -mode {
                            return [CompleteFromList ${text} {
                                NotifyNormal NotifyGrab
                                NotifyUngrab NotifyWhileGrabbed
                                return [CompleteFromList $text \
                                            {NotifyNormal NotifyGrab
                                             NotifyUngrab NotifyWhileGrabbed}]
                            }]
                        }

                        -place {
                            return [CompleteFromList ${text} {
                                return [CompleteFromList $text {PlaceOnTop PlaceOnBottom}]
                                PlaceOnTop PlaceOnBottom
                            }]
                        }

                        -rootx -
                        -rooty -
                        -x -
                        -y { return [DisplayHints <coord>] }

                        -state {
                            return [CompleteFromList ${text} {
                                return [CompleteFromList $text \
                                VisibilityUnobscured
                                VisibilityPartiallyObscured
                                VisibilityFullyObscured
                                            {VisibilityUnobscured VisibilityPartiallyObscured
                                             VisibilityFullyObscured <integer>}]
                                <integer>
                            }]
                        }

                        -time { return [DisplayHints <integer>] }
                        -when {
                            return [CompleteFromList ${text} {
                            -when { return [CompleteFromList $text {now tail head mark}] }
                                now tail head mark
                            }]
                        }


                        default {
                            return [CompleteFromList ${text} \
                            [RemoveUsedOptions ${line} {
                                -above -borderwidth -button -count -delta
                                return [CompleteFromList $text \
                                            [RemoveUsedOptions $line \
                                                 {-above -borderwidth -button -count -delta
                                -detail -focus -height -keycode -keysym
                                -mode -override -place -root -rootx -rooty
                                -sendevent -serial -state -subwindow -time
                                -width -when -x -y
                                                  -width -when -x -y}]]
                            }]]

                            }
                        }
                    }
                    default { }
                }
            }
        }
    }
    return ""
}

proc complete(focus) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} \
            [concat [WidgetChildren ${text}] -displayof -force -lastfor]]
                return [CompleteFromList $text \
                            [concat [WidgetChildren $text] -displayof -force -lastfor]]
        }
        default {
            switch -- [PreviousWord ${start} ${line}] {
                switch -- [PreviousWord $start $line] {
                -displayof -
                -force -
                -lastfor {
                    return [CompleteFromList ${text} \
                        return [CompleteFromList $text [WidgetChildren $text]]
                    [WidgetChildren ${text}]]
                }
            }
        }
    }
    return ""
}

proc FontConfigure {text line prev} {
    set fontopts {-family -overstrike -size -slant -underline -weight}
    switch -- ${prev} {
        switch -- $prev {
        -family {
            return [CompleteFromList ${text} [font families]]
            -family     { return [CompleteFromList $text [font families]] }
        }
        -underline -
        -overstrike { return [CompleteBoolean ${text}] }
            -overstrike { return [CompleteBoolean $text] }
        -size { return [DisplayHints <size>] }
        -slant {
            return [CompleteFromList ${text} { roman italic }]
            -slant      { return [CompleteFromList $text {roman italic}] }
        }
        -weight {
            return [CompleteFromList ${text} { normal bold }]
            -weight     { return [CompleteFromList $text {normal bold}] }
        }
        default {
            return [CompleteFromList ${text} \
                return [CompleteFromList $text [RemoveUsedOptions $line $fontopts]]
            [RemoveUsedOptions ${line} ${fontopts}]]
        }
    }
}

proc complete(font) {text start end line pos mod} {
    set fontopts {-family -overstrike -size -slant -underline -weight}
    set fontmetrics {-ascent -descent -linespace -fixed}
    set sub [Lindex ${line} 1]
    set prev [PreviousWord ${start} ${line}]
    switch -- ${pos} {
        set sub [Lindex $line 1]
        set prev [PreviousWord $start $line]
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} {
                actual configure create delete families measure metrics names
            }]
                return [CompleteFromList $text \
                            {actual configure create delete
                             families measure metrics names}]
        }
        2 {
            switch -- ${sub} {
                switch -- $sub {
                actual -
                measure -
                metrics {
                    return [DisplayHints <font>]
                    metrics   { return [DisplayHints <font>] }
                }
                configure -
                delete {
                    set names [font names]
                    if {[string length ${names}]} {
                        return [CompleteFromList ${text} ${names}]
                        if {[string length $names]} {
                            return [CompleteFromList $text $names]
                    } else {
                        return [DisplayHints <fontname>]
                    }
                }
                create {
                    return [CompleteFromList ${text} \
                    create    { return [CompleteFromList $text [concat ?fontname? $fontopts]] }
                    [concat ?fontname? ${fontopts}]]
                }
                families {
                    return [CompleteFromList ${text} -displayof]
                    families  { return [CompleteFromList $text -displayof] }
                }
                names {}
            }
        }
        3 {
            switch -- ${sub} {
                switch -- $sub {
                actual {
                    return [CompleteFromList ${text} \
                    actual    { return [CompleteFromList $text [concat -displayof $fontopts]] }
                    [concat -displayof ${fontopts}]]
                }
                configure -
                create {
                    return [FontConfigure ${text} ${line} ${prev}]
                    create    { return [FontConfigure $text $line $prev] }
                }
                delete {
                    set names [font names]
                    if {[string length ${names}]} {
                        return [CompleteFromList ${text} ${names}]
                        if {[string length $names]} {
                            return [CompleteFromList $text $names]
                    } else {
                        return [DisplayHints <fontname>]
                    }
                }
                families {
                    switch -- ${prev} {
                        switch -- $prev {
                        -displayof {
                            return [CompleteFromList ${text} \
                            -displayof { return [CompleteFromList $text [WidgetChildren $text]] }
                            [WidgetChildren ${text}]]
                        }
                    }
                }
                measure {
                    return [CompleteFromList ${text} {-displayof <text>}]
                    measure   { return [CompleteFromList $text {-displayof <text>}] }
                }
                metrics {
                    return [CompleteFromList ${text} \
                    metrics   { return [CompleteFromList $text [concat -displayof $fontmetrics]] }
                    [concat -displayof ${fontmetrics}]]
                }
                names {}
            }
        }
        4 {
            switch -- ${sub} {
                switch -- $sub {
                actual {
                    switch -- ${prev} {
                        switch -- $prev {
                        -displayof {
                            return [CompleteFromList ${text} \
                            -displayof { return [CompleteFromList $text [WidgetChildren $text]] }
                            [WidgetChildren ${text}]]
                        }
                        default {
                            return [FontConfigure ${text} ${line} ${prev}]
                            default    { return [FontConfigure $text $line $prev] }
                        }
                    }
                }
                configure -
                create {
                    return [FontConfigure ${text} ${line} ${prev}]
                    create    { return [FontConfigure $text $line $prev] }
                }
                delete {
                    set names [font names]
                    if {[string length ${names}]} {
                        return [CompleteFromList ${text} ${names}]
                        if {[string length $names]} {
                            return [CompleteFromList $text $names]
                    } else {
                        return [DisplayHints <fontname>]
                    }
                }
                families {}
                measure {
                    switch -- ${prev} {
                        switch -- $prev {
                        -displayof {
                            return [CompleteFromList ${text} \
                            -displayof { return [CompleteFromList $text [WidgetChildren $text]] }
                            [WidgetChildren ${text}]]
                        }
                        default {
                            return [DisplayHints <text>]
                            default    { return [DisplayHints <text>] }
                        }
                    }
                }
                metrics {
                    switch -- ${prev} {
                        -displayof {
                            return [CompleteFromList ${text} \
                        switch -- $prev {
                            -displayof { return [CompleteFromList $text [WidgetChildren $text]] }
                            default    { return [CompleteFromList $text $fontmetrics] }
                            [WidgetChildren ${text}]]
                        }
                        default {
                            return [CompleteFromList ${text} ${fontmetrics}]
                        }
                    }
                }
                names {}
            }
        }
        default {
            switch -- ${sub} {
                switch -- $sub {
                actual -
                configure -
                create {
                    return [FontConfigure ${text} ${line} ${prev}]
                    create    { return [FontConfigure $text $line $prev] }
                }
                delete {
                    set names [font names]
                    if {[string length ${names}]} {
                        return [CompleteFromList ${text} ${names}]
                        if {[string length $names]} {
                            return [CompleteFromList $text $names]
                    } else {
                        return [DisplayHints <fontname>]
                    }
                }
                families {}
                measure {
                    return [DisplayHints <text>]
                    measure   { return [DisplayHints <text>] }
                }
                metrics {
                    return [CompleteFromList ${text} ${fontmetrics}]
                    metrics   { return [CompleteFromList $text $fontmetrics] }
                }
                names {}
            }
        }
    }
    return ""
}

proc complete(frame) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -borderwidth -cursor -highlightbackground -highlightcolor
                return [CompleteWidgetConfigurations $text $start $line \
                            {-borderwidth -cursor -highlightbackground -highlightcolor
                -highlightthickness -relief -takefocus -background
                -class -colormap -container -height -visual -width
                             -class -colormap -container -height -visual -width}]
            }]
        }
    }
    return ""
}

proc complete(grab) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} [concat \
            current release set status -global [WidgetChildren ${text}]]]
                return [CompleteFromList $text \
                            [concat current release set status -global [WidgetChildren $text]]]
        }
        2 {
            switch -- [Lindex ${line} 1] {
                switch -- [Lindex $line 1] {
                -global -
                current -
                release -
                status {
                    return [CompleteFromList ${text} [WidgetChildren ${text}]]
                    status  { return [CompleteFromList $text [WidgetChildren $text]] }
                }
                set {
                    return [CompleteFromList ${text} \
                        return [CompleteFromList $text [concat -global [WidgetChildren $text]]]
                    [concat -global [WidgetChildren ${text}]]]
                }
            }
        }
        3 {
            switch -- [Lindex ${line} 1] {
                switch -- [Lindex $line 1] {
                set {
                    switch -- [PreviousWord ${start} ${line}] {
                        switch -- [PreviousWord $start $line] {
                        -global {
                            return [CompleteFromList ${text} \
                            -global { return [CompleteFromList $text [WidgetChildren $text]] }
                            [WidgetChildren ${text}]]
                        }
                    }
                }
            }
        }
    }
    return ""
}

proc GridConfig {text start line prev} {
    set opts {
        -column -columnspan -in -ipadx -ipady
        -padx -pady -row -rowspan -sticky
    }
    if {-1 == [string first "-" ${line}]} {
        set slave [WidgetChildren ${text}]
        if {-1 == [string first "-" $line]} {
            set slave [WidgetChildren $text]
    } else {
        set slave ""
    }
    switch -- ${prev} {
        switch -- $prev {
        -column -
        -columnspan -
        -row -
        -rowspan { return [DisplayHints <n>] }

        -ipadx -
        -ipady -
        -padx -
        -pady { return [DisplayHints <amount>] }

        -in { return [CompleteFromList ${text} [WidgetChildren ${text}]] }
            -in     { return [CompleteFromList $text [WidgetChildren $text]] }
        -sticky {
            set prev [PreviousWordOfIncompletePosition ${start} ${line}]
            return [CompleteListFromList ${text} \
            [string trimleft [IncompleteListRemainder ${line}]] \
                set prev [PreviousWordOfIncompletePosition $start $line]
                return [CompleteListFromList $text \
                            [string trimleft [IncompleteListRemainder $line]] \
            {n e s w} \{ { } \}]
        }


        default {
            return [CompleteFromList ${text} \
            [RemoveUsedOptions ${line} [concat ${opts} ${slave}]]]
                return [CompleteFromList $text \
                            [RemoveUsedOptions $line [concat $opts $slave]]]
        }
    }
}

proc complete(grid) {text start end line pos mod} {
    set sub [Lindex ${line} 1]
    set prev [PreviousWord ${start} ${line}]
    switch -- ${pos} {
        set sub [Lindex $line 1]
        set prev [PreviousWord $start $line]
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} \
            [concat [WidgetChildren ${text}] {
                bbox columnconfigure configure forget
                return [CompleteFromList $text \
                            [concat [WidgetChildren $text] \
                                 {bbox columnconfigure configure forget
                info location propagate rowconfigure
                remove size slaves
                                  remove size slaves}]]
            }]]
        }
        2 {
            switch -- ${sub} {
                switch -- $sub {
                bbox -
                columnconfigure -
                configure -
                forget -
                info -
                location -
                propagate -
                rowconfigure -
                remove -
                size -
                slaves {
                    return [CompleteFromList ${text} [WidgetChildren ${text}]]
                    slaves          { return [CompleteFromList $text [WidgetChildren $text]] }
                }
                default {
                    return [GridConfig ${text} ${start} ${line} ${prev}]
                    default         { return [GridConfig $text $start $line $prev] }
                }
            }
        }
        default {
            switch -- ${sub} {
                switch -- $sub {
                bbox {
                    switch [expr ${pos} % 2] {
                        switch [expr {$pos % 2}] {
                        0 { return [DisplayHints ?row?] }
                        1 { return [DisplayHints ?column?] }
                    }
                }
                rowconfigure -
                columnconfigure {
                    switch -- ${pos} {
                        switch -- $pos {
                        3 { return [DisplayHints <index>] }
                        default {
                            switch -- ${prev} {
                                switch -- $prev {
                                -minsize { return [DisplayHints <minsize>] }
                                -weight { return [DisplayHints <weight>] }
                                -pad { return [DisplayHints <pad>] }
                                default {
                                    return [CompleteFromList ${text} \
                                    [RemoveUsedOptions ${line}  {
                                        -minsize -weight -pad
                                        return [CompleteFromList $text \
                                                    [RemoveUsedOptions $line \
                                                         {-minsize -weight -pad}]]
                                    }]]
                                }
                            }
                        }
                    }
                }
                configure {
                    configure       { return [GridConfig $text $start $line $prev] }
                    return [GridConfig ${text} ${start} ${line} ${prev}]
                }
                forget -
                remove {
                    return [CompleteFromList ${text} [WidgetChildren ${text}]]
                    remove          { return [CompleteFromList $text [WidgetChildren $text]] }
                }
                info {}
                location {
                    switch -- ${pos} {
                        switch -- $pos {
                        3 { return [DisplayHints <x>] }
                        4 { return [DisplayHints <y>] }
                    }
                }
                propagate {
                    switch -- ${pos} {
                        3 { return [CompleteBoolean ${text}] }
                        switch -- $pos {
                            3 { return [CompleteBoolean $text] }
                    }
                }
                size {}
                slaves {
                    switch -- ${prev} {
                        switch -- $prev {
                        -row { return [DisplayHints <row>] }
                        -column { return [DisplayHints <column>] }
                        default {
                            return [CompleteFromList ${text} \
                            [RemoveUsedOptions ${line}  { -row -column }]]
                                return [CompleteFromList $text \
                                            [RemoveUsedOptions $line {-row -column}]]
                        }
                    }
                }
                default {
                    return [GridConfig ${text} ${start} ${line} ${prev}]
                    default         { return [GridConfig $text $start $line $prev] }
                }
            }
        }
    }
    return ""
}

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

proc complete(label) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -anchor -background -bitmap -borderwidth -cursor -font
                return [CompleteWidgetConfigurations $text $start $line \
                            {-anchor -background -bitmap -borderwidth -cursor -font
                -foreground -highlightbackground -highlightcolor
                -highlightthickness -image -justify -padx -pady -relief
                -takefocus -text -textvariable -underline -wraplength
                -height -width
                             -height -width}]
            }]
        }
    }
    return ""
}

proc complete(listbox) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -background -borderwidth -cursor -exportselection -font
                return [CompleteWidgetConfigurations $text $start $line \
                            {-background -borderwidth -cursor -exportselection -font
                -foreground -height -highlightbackground -highlightcolor
                -highlightthickness -relief -selectbackground
                -selectborderwidth -selectforeground -setgrid -takefocus
                -width -xscrollcommand -yscrollcommand -height -selectmode
                -width
                             -width}]
            }]
        }
    }
    return ""
}

proc complete(lower) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 -
        2 {
            return [CompleteFromList ${text} [WidgetChildren ${text}]]
            2 { return [CompleteFromList $text [WidgetChildren $text]] }
        }
    }
}

proc complete(menu) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -activebackground -activeborderwidth -activeforeground
                return [CompleteWidgetConfigurations $text $start $line \
                            {-activebackground -activeborderwidth -activeforeground
                -background -borderwidth -cursor -disabledforeground
                -font -foreground -relief -takefocus -postcommand
                -selectcolor -tearoff -tearoffcommand -title -type
                             -selectcolor -tearoff -tearoffcommand -title -type}]
            }]
        }
    }
    return ""
}

proc complete(menubutton) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -activebackground -activeforeground -anchor -background
                return [CompleteWidgetConfigurations $text $start $line \
                            {-activebackground -activeforeground -anchor -background
                -bitmap -borderwidth -cursor -disabledforeground -font
                -foreground -highlightbackground -highlightcolor
                -highlightthickness -image -justify -padx -pady -relief
                -takefocus -text -textvariable -underline -wraplength
                -direction -height -indicatoron -menu -state -width
                             -direction -height -indicatoron -menu -state -width}]
            }]
        }
    }
    return ""
}

proc complete(message) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -anchor -background -borderwidth -cursor -font -foreground
                return [CompleteWidgetConfigurations $text $start $line \
                            {-anchor -background -borderwidth -cursor -font -foreground
                -highlightbackground -highlightcolor -highlightthickness
                -padx -pady -relief -takefocus -text -textvariable -width
                -aspect -justify -width
                             -aspect -justify -width}]
            }]
        }
    }
    return ""
}

proc OptionPriority text {
    return [CompleteFromList ${text} {
        widgetDefault startupFile userDefault interactive
        return [CompleteFromList $text {widgetDefault startupFile userDefault interactive}]
    }]
}

proc complete(option) {text start end line pos mod} {
    set sub [Lindex ${line} 1]
    switch -- ${pos} {
        set sub [Lindex $line 1]
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} {
            1 { return [CompleteFromList $text {add clear get readfile}] }
                add clear get readfile
            }]
        }
        2 {
            switch -- ${sub} {
                switch -- $sub {
                add { return [DisplayHints <pattern>] }
                get {
                    return [CompleteFromList ${text} [WidgetChildren ${text}]]
                    get      { return [CompleteFromList $text [WidgetChildren $text]] }
                }
                readfile { return "" }
            }
        }
        3 {
            switch -- ${sub} {
                switch -- $sub {
                add { return [DisplayHints <value>] }
                get { return [DisplayHints <name>] }
                readfile { return [OptionPriority ${text}] }
                    readfile { return [OptionPriority $text] }
            }
        }
        4 {
            switch -- ${sub} {
                add { return [OptionPriority ${text}] }
                switch -- $sub {
                    add      { return [OptionPriority $text] }
                get {
                    return [CompleteFromList ${text} \
                    get      { return [CompleteFromList $text [ClassTable [Lindex $line 2]]] }
                    [ClassTable [Lindex ${line} 2]]]
                }
                readfile {}
            }
        }
    }
}

proc PackConfig {text line prev} {
    set opts {
        -after -anchor -before -expand -fill
        -in -ipadx -ipady -padx -pady -side
    }
    if {-1 == [string first "-" ${line}]} {
        set slave [WidgetChildren ${text}]
        if {-1 == [string first "-" $line]} {
            set slave [WidgetChildren $text]
    } else {
        set slave ""
    }
    switch -- ${prev} {
        switch -- $prev {
        -after -
        -before  { return [CompleteFromList ${text} [WidgetChildren ${text}]] }
        -anchor { return [CompleteAnchor ${text}] }
        -expand { return [CompleteBoolean ${text}] }
        -fill { return [CompleteFromList ${text} { none x y both }] }
            -before { return [CompleteFromList $text [WidgetChildren $text]] }
            -anchor { return [CompleteAnchor $text] }
            -expand { return [CompleteBoolean $text] }
            -fill   { return [CompleteFromList $text { none x y both }] }

        -ipadx -
        -ipady -
        -padx -
        -pady { return [DisplayHints <amount>] }

        -in { return [CompleteFromList ${text} [WidgetChildren ${text}]] }
        -side { return [CompleteFromList ${text} { left right top bottom }] }
            -in   { return [CompleteFromList $text [WidgetChildren $text]] }
            -side { return [CompleteFromList $text { left right top bottom }] }

        default {
            return [CompleteFromList ${text} \
            [RemoveUsedOptions ${line} [concat ${opts} ${slave}]]]
                return [CompleteFromList $text \
                            [RemoveUsedOptions $line [concat $opts $slave]]]
        }
    }
}

proc complete(pack) {text start end line pos mod} {
    set sub [Lindex ${line} 1]
    set prev [PreviousWord ${start} ${line}]
    switch -- ${pos} {
        set sub [Lindex $line 1]
        set prev [PreviousWord $start $line]
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} \
            [concat [WidgetChildren ${text}] {
                configure forget info propagate slaves
                return [CompleteFromList $text \
                            [concat [WidgetChildren $text] \
                                 {configure forget info propagate slaves}]]
            }]]
        }
        2 {
            switch -- ${sub} {
                switch -- $sub {
                configure -
                forget -
                info -
                propagate -
                slaves {
                    return [CompleteFromList ${text} [WidgetChildren ${text}]]
                    slaves    { return [CompleteFromList $text [WidgetChildren $text]] }
                }
                default {
                    return [PackConfig ${text} ${line} ${prev}]
                    default   { return [PackConfig $text $line $prev] }
                }
            }
        }
        default {
            switch -- ${sub} {
                configure {
                switch -- $sub {
                    configure { return [PackConfig $text $line $prev] }
                    return [PackConfig ${text} ${line} ${prev}]
                }
                forget {
                    return [CompleteFromList ${text} [WidgetChildren ${text}]]
                    forget    { return [CompleteFromList $text [WidgetChildren $text]] }
                }
                info {}
                propagate {
                    switch -- ${pos} {
                        3 { return [CompleteBoolean ${text}] }
                        switch -- $pos {
                            3 { return [CompleteBoolean $text] }
                    }
                }
                slaves {}
                default {
                    return [PackConfig ${text} ${line} ${prev}]
                    default   { return [PackConfig $text $line $prev] }
                }
            }
        }
    }
    return ""
}

proc PlaceConfig {text line prev} {
    set opts {
        -in -x -relx -y -rely -anchor -width
        -relwidth -height -relheight -bordermode
    }
    switch -- ${prev} {
        switch -- $prev {

        -in { return [CompleteFromList ${text} [WidgetChildren ${text}]] }
            -in { return [CompleteFromList $text [WidgetChildren $text]] }

        -x -
        -relx -
        -y -
        -rely { return [DisplayHints <location>] }

        -anchor { return [CompleteAnchor ${text}] }
            -anchor { return [CompleteAnchor $text] }

        -width -
        -relwidth -
        -height -
        -relheight { return [DisplayHints <size>] }

        -bordermode {
            -bordermode { return [CompleteFromList $text {ignore inside outside}] }
            return [CompleteFromList ${text} {ignore inside outside}]
        }


        default {
            return [CompleteFromList ${text} \
            default { return [CompleteFromList $text [RemoveUsedOptions $line $opts]] }
            [RemoveUsedOptions ${line} ${opts}]]
        }
    }
}

proc complete(place) {text start end line pos mod} {
    set sub [Lindex ${line} 1]
    set prev [PreviousWord ${start} ${line}]
    switch -- ${pos} {
        set sub [Lindex $line 1]
        set prev [PreviousWord $start $line]
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} \
            [concat [WidgetChildren ${text}] {
                configure forget info slaves
                return [CompleteFromList $text \
                            [concat [WidgetChildren $text] \
                                 {configure forget info slaves}]]
            }]]
        }
        2 {
            switch -- ${sub} {
                switch -- $sub {
                configure -
                forget -
                info -
                slaves {
                    return [CompleteFromList ${text} [WidgetChildren ${text}]]
                    slaves    { return [CompleteFromList $text [WidgetChildren $text]] }
                }
                default {
                    return [PlaceConfig ${text} ${line} ${prev}]
                    default   { return [PlaceConfig $text $line $prev] }
                }
            }
        }
        default {
            switch -- ${sub} {
                configure {
                switch -- $sub {
                    configure { return [PlaceConfig $text $line $prev] }
                    return [PlaceConfig ${text} ${line} ${prev}]
                }
                forget {}
                info {}
                slaves {}
                default {
                    return [PlaceConfig ${text} ${line} ${prev}]
                    default   { return [PlaceConfig $text $line $prev] }
                }
            }
        }
    }
    return ""
}

proc complete(radiobutton) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -activebackground -activeforeground -anchor -background
                return [CompleteWidgetConfigurations $text $start $line \
                            {-activebackground -activeforeground -anchor -background
                -bitmap -borderwidth -cursor -disabledforeground -font
                -foreground -highlightbackground -highlightcolor
                -highlightthickness -image -justify -padx -pady -relief
                -takefocus -text -textvariable -underline -wraplength -command
                -height -indicatoron -selectcolor -selectimage -state -value
                -variable -width
                             -variable -width}]
            }]
        }
    }
    return ""
}

proc complete(raise) {text start end line pos mod} {
    return [complete(lower) ${text} ${start} ${end} ${line} ${pos} ${mod}]
        return [complete(lower) $text $start $end $line $pos $mod]
}

proc complete(scale) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -activebackground -background -borderwidth -cursor -font
                return [CompleteWidgetConfigurations $text $start $line \
                            {-activebackground -background -borderwidth -cursor -font
                -foreground -highlightbackground -highlightcolor
                -highlightthickness -orient -relief -repeatdelay
                -repeatinterval -takefocus -troughcolor -bigincrement
                -command -digits -from -label -length -resolution
                -showvalue -sliderlength -sliderrelief -state -tickinterval
                -to -variable -width
                             -to -variable -width}]
            }]
        }
    }
    return ""
}

proc complete(scrollbar) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -activebackground -background -borderwidth -cursor
                return [CompleteWidgetConfigurations $text $start $line \
                            {-activebackground -background -borderwidth -cursor
                -highlightbackground -highlightcolor -highlightthickness
                -jump -orient -relief -repeatdelay -repeatinterval
                -takefocus -troughcolor -activerelief -command
                -elementborderwidth -width
                             -elementborderwidth -width}]
            }]
        }
    }
    return ""
}

proc SelectionOpts {text start end line pos mod lst} {
    set prev [PreviousWord ${start} ${line}]
    if {-1 == [lsearch ${lst} ${prev}]} {
        set prev [PreviousWord $start $line]
        if {-1 == [lsearch $lst $prev]} {
        set prev "" ;# force the default arm
    }
    switch -- ${prev} {
        switch -- $prev {
        -displayof {
            return [CompleteFromList ${text} \
            -displayof { return [CompleteFromList $text [WidgetChildren $text]] }
            [WidgetChildren ${text}]]
        }
        -selection {
            variable selection-selections
            return [CompleteFromList ${text} ${selection-selections}]
                return [CompleteFromList $text ${selection-selections}]
        }
        -type {
            variable selection-types
            return [CompleteFromList ${text} ${selection-types}]
                return [CompleteFromList $text ${selection-types}]
        }
        -command {
            return [BraceOrCommand ${text} \
                return [BraceOrCommand $text $start $end $line $pos $mod]
            ${start} ${end} ${line} ${pos} ${mod}]
        }
        -format {
            variable selection-formats
            return [CompleteFromList ${text} ${selection-formats}]
                return [CompleteFromList $text ${selection-formats}]
        }
        default {
            return [CompleteFromList ${text} \
                return [CompleteFromList $text [RemoveUsedOptions $line $lst]]
            [RemoveUsedOptions ${line} ${lst}]]
        }
    }
}

proc complete(selection) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 {
            return [TrySubCmds ${text} [Lindex ${line} 0]]
            1       { return [TrySubCmds $text [Lindex $line 0]] }
        }
        default {
            set sub [Lindex ${line} 1]
            set widgets [WidgetChildren ${text}]
            switch -- ${sub} {
                set sub [Lindex $line 1]
                set widgets [WidgetChildren $text]
                switch -- $sub {
                clear {
                    return [SelectionOpts \
                        return [SelectionOpts $text $start $end $line \
                    ${text} ${start} ${end} ${line} ${pos} ${mod} {
                        -displayof -selection
                                    $pos $mod {-displayof -selection}]
                    }]
                }
                get {
                    return [SelectionOpts \
                        return [SelectionOpts $text $start $end $line \
                    ${text} ${start} ${end} ${line} ${pos} ${mod} {
                        -displayof -selection -type
                                    $pos $mod {-displayof -selection -type}]
                    }]
                }
                handle {
                    return [SelectionOpts \
                        return [SelectionOpts $text $start $end $line $pos $mod \
                    ${text} ${start} ${end} ${line} ${pos} ${mod} \
                    [concat {-selection -type -format} ${widgets}]]
                                    [concat {-selection -type -format} $widgets]]
                }
                own {
                    return [SelectionOpts \
                        return [SelectionOpts $text $start $end $line $pos $mod \
                    ${text} ${start} ${end} ${line} ${pos} ${mod} \
                    [concat {-command -selection} ${widgets}]]
                                    [concat {-command -selection} $widgets]]
                }
            }
        }
    }
}

proc complete(send) {text start end line pos mod} {
    set prev [PreviousWord ${start} ${line}]
    if {"-displayof" == ${prev}} {
        return [TryFromList ${text} [WidgetChildren ${text}]]
        set prev [PreviousWord $start $line]
        if {"-displayof" == $prev} {
            return [TryFromList $text [WidgetChildren $text]]
    }
    set cmds [RemoveUsedOptions ${line} {
        set cmds [RemoveUsedOptions $line {-async -displayof --} {--}]
        -async -displayof --
    } {--}]
    if {[llength ${cmds}]} {
        return [string trim [CompleteFromList ${text} \
        if {[llength $cmds]} {
            return [string trim [CompleteFromList $text [concat $cmds <app>]]]
        [concat ${cmds} <app>]]]
    } else {
        if {[regexp -- --$ ${line}]} {
            if {[regexp -- --$ $line]} {
            return [list {--}]; # append a blank
        } else {
            # TODO make this better!
            return [DisplayHints [list {<app cmd ?arg ...?>}]]
        }
    }
    return ""
}

proc complete(text) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -background -borderwidth -cursor -exportselection -font
                return [CompleteWidgetConfigurations $text $start $line \
                            {-background -borderwidth -cursor -exportselection -font
                -foreground -highlightbackground -highlightcolor
                -highlightthickness -insertbackground -insertborderwidth
                -insertofftime -insertontime -insertwidth -padx -pady
                -relief -selectbackground -selectborderwidth
                -selectforeground -setgrid -takefocus -xscrollcommand
                -yscrollcommand -height -spacing1 -spacing2 -spacing3
                -state -tabs -width -wrap
                             -state -tabs -width -wrap}]
            }]
        }
    }
    return ""
}

proc complete(tk) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 {
            return [TrySubCmds ${text} [Lindex ${line} 0]]
            1       { return [TrySubCmds $text [Lindex $line 0]] }
        }
        default {
            switch -- [Lindex ${line} 1] {
                switch -- [Lindex $line 1] {
                appname { return [DisplayHints ?newName?]  }
                scaling {
                    switch -- [PreviousWord ${start} ${line}] {
                        switch -- [PreviousWord $start $line] {
                        -displayof {
                            return [TryFromList ${text} \
                                return [TryFromList $text [WidgetChildren $text]]
                            [WidgetChildren ${text}]]
                        }
                        default {
                            return [CompleteFromList ${text} \
                            [RemoveUsedOptions ${line} {-displayof ?number?}]]
                                return [CompleteFromList $text \
                                            [RemoveUsedOptions $line {-displayof ?number?}]]
                        }
                    }
                }
            }
        }
    }
}

# proc complete(tk_bisque) {text start end line pos mod} {
# }

proc complete(tk_chooseColor) {text start end line pos mod} {
    switch -- [PreviousWord ${start} ${line}] {
        -initialcolor { return [CompleteColor ${text}] }
        -parent { return [TryFromList ${text} [WidgetChildren ${text}]] }
        switch -- [PreviousWord $start $line] {
            -initialcolor { return [CompleteColor $text] }
            -parent       { return [TryFromList $text [WidgetChildren $text]] }
        -title { return [DisplayHints <string>] }
        default {
            return [TryFromList ${text} \
            [RemoveUsedOptions ${line} {-initialcolor -parent -title}]]
                return [TryFromList $text \
                            [RemoveUsedOptions $line {-initialcolor -parent -title}]]
        }
    }
}

proc complete(tk_dialog) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [CompleteFromList ${text} [ToplevelWindows]] }
        switch -- $pos {
            1       { return [CompleteFromList $text [ToplevelWindows]] }
        2 { return [DisplayHints <title>] }
        3 { return [DisplayHints <text>] }
        4 { return [CompleteFromBitmaps ${text}] }
            4       { return [CompleteFromBitmaps $text] }
        5 { return [DisplayHints <defaultIndex>] }
        default { return [DisplayHints ?buttonName?] }
    }
}

proc complete(tk_focusNext) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [CompleteFromList ${text} [WidgetChildren ${text}]] }
        switch -- $pos {
            1 { return [CompleteFromList $text [WidgetChildren $text]] }
    }
}

proc complete(tk_focusPrev) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [CompleteFromList ${text} [WidgetChildren ${text}]] }
        switch -- $pos {
            1 { return [CompleteFromList $text [WidgetChildren $text]] }
    }
}

# proc complete(tk_focusFollowsMouse) {text start end line pos mod} {
# }

proc GetOpenSaveFile {text start end line pos mod {add ""}} {
    # enable filename completion for the first four switches.
    switch -- [PreviousWord ${start} ${line}] {
        switch -- [PreviousWord $start $line] {
        -defaultextension {}
        -filetypes {}
        -initialdir {}
        -initialfile {}
        -parent {
            return [CompleteFromList ${text} [WidgetChildren ${text}]]
            -parent           { return [CompleteFromList $text [WidgetChildren $text]] }
        }
        -title { return [DisplayHints <titleString>] }
        default {
            return [CompleteFromList ${text} \
            [RemoveUsedOptions ${line} [concat {
                -defaultextension -filetypes -initialdir -parent -title
            } ${add}]]]
                return [CompleteFromList $text \
                            [RemoveUsedOptions $line \
                                 [concat {-defaultextension -filetypes
                                          -initialdir -parent -title} $add]]]
        }
    }
}

proc complete(tk_getOpenFile) {text start end line pos mod} {
    return [GetOpenSaveFile \
        return [GetOpenSaveFile $text $start $end $line $pos $mod]
    ${text} ${start} ${end} ${line} ${pos} ${mod}]
}

proc complete(tk_getSaveFile) {text start end line pos mod} {
    return [GetOpenSaveFile \
        return [GetOpenSaveFile $text $start $end $line $pos $mod -initialfile]
    ${text} ${start} ${end} ${line} ${pos} ${mod} -initialfile]
}

proc complete(tk_messageBox) {text start end line pos mod} {
    switch -- [PreviousWord ${start} ${line}] {
        switch -- [PreviousWord $start $line] {
        -default {
            return [CompleteFromList ${text} {
                abort cancel ignore no ok retry yes
            -default { return [CompleteFromList $text {abort cancel ignore no ok retry yes}] }
            }]
        }
        -icon {
            return [CompleteFromList ${text} {
                error info question warning
            -icon    { return [CompleteFromList $text {error info question warning}] }
            }]
        }
        -message { return [DisplayHints <string>] }
        -parent {
            return [CompleteFromList ${text} [WidgetChildren ${text}]]
            -parent  { return [CompleteFromList $text [WidgetChildren $text]] }
        }
        -title { return [DisplayHints <titleString>] }
        -type {
            return [CompleteFromList ${text} {
                abortretryignore ok okcancel retrycancel yesno yesnocancel
            }]
                return [CompleteFromList $text \
                            {abortretryignore ok okcancel
                             retrycancel yesno yesnocancel}]
        }
        default {
            return [CompleteFromList ${text} \
            [RemoveUsedOptions ${line} {
                -default -icon -message -parent -title -type
            }]]
                return [CompleteFromList $text \
                            [RemoveUsedOptions $line \
                                 {-default -icon -message
                                  -parent -title -type}]]
        }
    }
}

proc complete(tk_optionMenu) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        2 { return [VarCompletion ${text} #0] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
            2       { return [VarCompletion $text #0] }
        3 { return [DisplayHints <value>] }
        default { return [DisplayHints ?value?] }
    }
}

proc complete(tk_popup) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 {
            # display only menu widgets
            #
            set widgets [WidgetChildren ${text}]
                set widgets [WidgetChildren $text]
            set menu_widgets ""
            foreach widget ${widgets} {
                if {"Menu" == [winfo class ${widget}]} {
                    lappend menu_widgets ${widget}
                foreach widget $widgets {
                    if {"Menu" == [winfo class $widget]} {
                        lappend menu_widgets $widget
                }
            }
            if {[llength ${menu_widgets}]} {
                return [TryFromList ${text} ${menu_widgets}]
                if {[llength $menu_widgets]} {
                    return [TryFromList $text $menu_widgets]
            } else {
                return [DisplayHints <menu>]
            }
        }
        2 { return [DisplayHints <x>] }
        3 { return [DisplayHints <y>] }
        4 { return [DisplayHints ?entryIndex?] }
    }
}

# TODO: the name - value construct didn't work in my wish.
#
proc complete(tk_setPalette) {text start end line pos mod} {
    set database {
        activeBackground        foreground              selectColor
        activeForeground        highlightBackground     selectBackground
        background              highlightColor          selectForeground
        disabledForeground      insertBackground        troughColor
    }
    switch -- ${pos} {
        switch -- $pos {
        1 {
            return [CompleteColor ${text} ${database}]
            1       { return [CompleteColor $text $database] }
        }
        default {
            switch [expr ${pos} % 2] {
                switch [expr {$pos % 2}] {
                1 {
                    return [CompleteFromList ${text} ${database}]
                    1 { return [CompleteFromList $text $database] }
                }
                0 {
                    return [CompleteColor ${text}]
                    0 { return [CompleteColor $text] }
                }
            }
        }
    }
}

proc complete(tkwait) {text start end line pos mod} {
    switch -- ${pos} {
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} {
                variable visibility window
            1 { return [CompleteFromList $text {variable visibility window}] }
            }]
        }
        2 {
            switch [Lindex ${line} 1] {
                switch [Lindex $line 1] {
                variable {
                    return [VarCompletion ${text} #0]
                    variable   { return [VarCompletion $text #0] }
                }
                visibility -
                window {
                    return [TryFromList ${text} [WidgetChildren ${text}]]
                    window     { return [TryFromList $text [WidgetChildren $text]] }
                }
            }
        }
    }
}

proc complete(toplevel) {text start end line pos mod} {
    switch -- ${pos} {
        1 { return [EventuallyInsertLeadingDot ${text} <pathName>] }
        switch -- $pos {
            1       { return [EventuallyInsertLeadingDot $text <pathName>] }
        default {
            return [CompleteWidgetConfigurations ${text} ${start} ${line} {
                -borderwidth -cursor -highlightbackground -highlightcolor
                return [CompleteWidgetConfigurations $text $start $line \
                            {-borderwidth -cursor -highlightbackground -highlightcolor
                -highlightthickness -relief -takefocus -background
                -class -colormap -container -height -menu -screen
                -use -visual -width
                             -use -visual -width}]
            }]
        }
    }
    return ""
}

proc complete(winfo) {text start end line pos mod} {
    set sub [Lindex ${line} 1]
    switch -- ${pos} {
        set sub [Lindex $line 1]
        switch -- $pos {
        1 {
            return [TrySubCmds ${text} winfo]
            1       { return [TrySubCmds $text winfo] }
        }
        2 {
            switch -- ${sub} {
                switch -- $sub {
                atom {
                    return [TryFromList ${text} {-displayof <name>}]
                    atom       { return [TryFromList $text {-displayof <name>}] }
                }
                containing {
                    containing { return [TryFromList $text {-displayof <rootX>}] }
                    return [TryFromList ${text} {-displayof <rootX>}]
                }
                interps {
                    return [TryFromList ${text} -displayof]
                    interps    { return [TryFromList $text -displayof] }
                }
                atomname -
                pathname {
                    return [TryFromList ${text} {-displayof <id>}]
                    pathname   { return [TryFromList $text {-displayof <id>}] }
                    default    { return [TryFromList $text [WidgetChildren $text]] }
                }
                default {
                    return [TryFromList ${text} [WidgetChildren ${text}]]
                }
            }
        }
        default {
            switch -- ${sub} {
                switch -- $sub {
                atom {
                    switch -- [PreviousWord ${start} ${line}] {
                        -displayof {
                        switch -- [PreviousWord $start $line] {
                            -displayof { return [TryFromList $text [WidgetChildren $text]] }
                            return [TryFromList ${text} \
                            [WidgetChildren ${text}]]
                        }
                        default { return [DisplayHints <name>] }
                    }
                }
                containing {
                    switch -- [Lindex ${line} 2] {
                        switch -- [Lindex $line 2] {
                        -displayof {
                            switch -- ${pos} {
                                switch -- $pos {
                                3 {
                                    return [TryFromList ${text} \
                                    3 { return [TryFromList $text [WidgetChildren $text]] }
                                    [WidgetChildren ${text}]]
                                }
                                4 {
                                    return [DisplayHints <rootX>]
                                    4 { return [DisplayHints <rootX>] }
                                }
                                5 {
                                    return [DisplayHints <rootY>]
                                    5 { return [DisplayHints <rootY>] }
                                }
                            }
                        }
                        default { return [DisplayHints <rootY>] }
                    }
                }
                interps {
                    switch -- [PreviousWord ${start} ${line}] {
                        -displayof {
                        switch -- [PreviousWord $start $line] {
                            -displayof { return [TryFromList $text [WidgetChildren $text]] }
                            return [TryFromList ${text} \
                            [WidgetChildren ${text}]]
                        }
                        default {}
                    }
                }
                atomname -
                pathname {
                    switch -- [PreviousWord ${start} ${line}] {
                        -displayof {
                        switch -- [PreviousWord $start $line] {
                            -displayof { return [TryFromList $text [WidgetChildren $text]] }
                            return [TryFromList ${text} \
                            [WidgetChildren ${text}]]
                        }
                        default { return [DisplayHints <id>] }
                    }
                }
                visualsavailable { return [DisplayHints ?includeids?] }
                default {
                    return [TryFromList ${text} [WidgetChildren ${text}]]
                    default          { return [TryFromList $text [WidgetChildren $text]] }
                }
            }
        }
    }
    return ""
}

proc complete(wm) {text start end line pos mod} {
    set sub [Lindex ${line} 1]
    switch -- ${pos} {
        set sub [Lindex $line 1]
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} {
                aspect client colormapwindows command deiconify focusmodel
                return [CompleteFromList $text \
                            {aspect client colormapwindows command deiconify focusmodel
                frame geometry grid group iconbitmap iconify iconmask iconname
                iconposition iconwindow maxsize minsize overrideredirect
                positionfrom protocol resizable sizefrom state title transient
                withdraw
                             withdraw}]
            }]
        }
        2 {
            return [TryFromList ${text} [ToplevelWindows]]
            2 { return [TryFromList $text [ToplevelWindows]] }
        }
        3 {
            switch -- ${sub} {
                switch -- $sub {
                aspect { return [DisplayHints ?minNumer?] }
                client { return [DisplayHints ?name?] }
                colormapwindows {
                    return [CompleteListFromList ${text} \
                    [string trimleft [IncompleteListRemainder ${line}]] \
                        return [CompleteListFromList $text \
                                    [string trimleft [IncompleteListRemainder $line]] \
                    [WidgetChildren .] \{ { } \}]
                }
                command { return [DisplayHints ?value?] }
                focusmodel {
                    return [CompleteListFromList ${text} {active passive}]
                    focusmodel       { return [CompleteListFromList $text {active passive}] }
                }
                geometry {
                    return [DisplayHints ?<width>x<height>+-<x>+-<y>?]
                    geometry         { return [DisplayHints ?<width>x<height>+-<x>+-<y>?] }
                }
                grid { return [DisplayHints ?baseWidth?] }
                group {
                    return [TryFromList ${text} [WidgetChildren ${text}]]
                    group            { return [TryFromList $text [WidgetChildren $text]] }
                }
                iconbitmap -
                iconmask { return [CompleteFromBitmaps ${text}] }
                    iconmask         { return [CompleteFromBitmaps $text] }
                iconname { return [DisplayHints ?newName?] }
                iconposition { return [DisplayHints ?x?] }
                iconwindow {
                    iconwindow       { return [TryFromList $text [WidgetChildren $text]] }
                    return [TryFromList ${text} [WidgetChildren ${text}]]
                }
                maxsize -
                minsize { return [DisplayHints ?width?] }
                overrideredirect { return [CompleteBoolean ${text}] }
                    overrideredirect { return [CompleteBoolean $text] }
                positionfrom -
                sizefrom {
                    return [CompleteFromList ${text} {position user}]
                    sizefrom         { return [CompleteFromList $text {position user}] }
                }
                protocol {
                    return [CompleteFromList ${text} {
                        WM_TAKE_FOCUS WM_SAVE_YOURSELF WM_DELETE_WINDOW
                        return [CompleteFromList $text \
                                    {WM_TAKE_FOCUS WM_SAVE_YOURSELF WM_DELETE_WINDOW}]
                    }]
                }
                resizable { return [DisplayHints ?width?] }
                title { return [DisplayHints ?string?] }
                transient {
                    transient        { return [TryFromList $text [WidgetChildren $text]] }
                    return [TryFromList ${text} [WidgetChildren ${text}]]
                }
                default {
                    return [TryFromList ${text} [ToplevelWindows]]
                    default          { return [TryFromList $text [ToplevelWindows]] }
                }
            }
        }
        4 {
            switch -- ${sub} {
                switch -- $sub {
                aspect { return [DisplayHints ?minDenom?] }
                grid { return [DisplayHints ?baseHeight?] }
                iconposition { return [DisplayHints ?y?] }
                maxsize -
                minsize { return [DisplayHints ?height?] }
                protocol {
                    return [BraceOrCommand ${text} \
                        return [BraceOrCommand $text $start $end $line $pos $mod]
                    ${start} ${end} ${line} ${pos} ${mod}]
                }
                resizable { return [DisplayHints ?height?] }
            }
        }
        5 {
            switch -- ${sub} {
                switch -- $sub {
                aspect { return [DisplayHints ?maxNumer?] }
                grid { return [DisplayHints ?widthInc?] }
            }
        }
        6 {
            switch -- ${sub} {
                switch -- $sub {
                aspect { return [DisplayHints ?maxDenom?] }
                grid { return [DisplayHints ?heightInc?] }
            }
        }
    }
    return ""
}
5790
5791
5792
5793
5794
5795
5796
5797

5798
5799
5800
5801


5802
5803
5804

5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815


5816
5817

5818
5819
5820
5821
5822
5823
5824
5825
5826

5827
5828
5829
5830
5831
5832

5833
5834
5835
5836
5837
5838
5839

5840
5841

5842
5843
5844
5845
5846
5847
5848
5849
5850
5851

5852
5853
5854
5855


5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869





5870
5871
5872
5873
5874
5875
5876


5877
5878
5879

5880
5881
5882
5883
5884
5885




5886
5887
5888
5889
5890
5891
5892
5893



5894
5895
5896
5897
5898



5899
5900
5901
5902
5903
5904

5905
5906

5907
5908
5909
5910
5911
5912

5913
5914
5915
5916
5917
5918

5919
5920
5921
5922

5923
5924

5925
5926
5927
5928
5929
5930
5931





5932
5933
5934
5935
5936
5937

5938
5939
5940

5941
5942
5943
5944
5945
5946



5947
5948
5949
5950
5951
5952

5953
5954
5955

5956
5957

5958
5959
5960
5961
5962
5963
5964




5965
5966
5967
5968
5969
5970

5971
5972
5973

5974
5975
5976
5977
5978
5979



5980
5981
5982
5983
5984
5985
5986


5987
5988
5989
5990


5991
5992
5993
5994
5995
5996
5997
5998




5999
6000
6001
6002
6003
6004
6005


6006
6007
6008
6009

6010
6011
6012
6013
6014
6015



6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036


6037
6038

6039
6040
6041
6042
6043
6044
6045


6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063


6064
6065
6066
6067
6068
6069
6070
6071


6072
6073

6074
6075

6076
6077

6078
6079
6080
6081


6082
6083
6084
6085
6086
6087


6088
6089
6090
6091
6092
6093

6094
6095
6096
6097
6098
6099
6100
6101
6102

6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114

6115
6116
6117
6118
6119
6120

6121
6122
6123
6124


6125
6126
6127
6128

6129
6130
6131
6132
6133
6134

6135
6136
6137
6138
6139
6140

6141
6142
6143
6144
6145
6146

6147
6148
6149

6150
6151
6152
6153
6154
6155
6156
6157

6158
6159
6160
6161
6162
6163
6164
6165

6166
6167
6168
6169
6170
6171

6172
6173

6174
6175
6176
6177
6178
6179

6180
6181
6182
6183
6184

6185
6186
6187
6188
6189
6190

6191
6192
6193
6194
6195
6196

6197
6198
6199
6200
6201
6202
6203

6204
6205
6206
6207
6208
6209

6210
6211
6212
6213
6214
6215
6216

6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230

6231
6232
6233
6234



6235
6236

6237
6238
6239
6240
6241
6242

6243
6244
6245
6246
6247
6248

6249
6250
6251
6252
6253
6254
6255
6256

6257
6258

6259
6260
6261

6262
6263
6264
6265
6266


6267
6268
6269
6270
6271
6272
6273
6274


6275
6276
6277
6278
6279
6280
6281
6282
6283

6284
6285

6286
6287
6288
6289



6290
6291
6292
6293
6294
6295
6296


6297
6298
6299
6300
6301
6302
6303


6304
6305
6306
6307
6308
6309


6310
6311
6312
6313
6314
6315
6316


6317
6318
6319
6320
6321

6322
6323
6324


6325
6326
6327
6328
6329
6330

6331
6332
6333
6334
6335
6336



6337
6338
6339
6340
6341


6342
6343
6344
6345
6346
6347
6348
6349
6350
6351

6352
6353
6354
6355
6356
6357


6358
6359

6360
6361

6362
6363
6364

6365
6366
6367
6368
6369
6370


6371
6372
6373
6374

6375
6376

6377
6378

6379
6380
6381

6382
6383
6384

6385
6386
6387
6388
6389
6390
6391

6392
6393
6394
6395
6396
6397
6398

6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417


6418
6419

6420
6421

6422
6423
6424
6425
6426

6427
6428

6429
6430
6431
6432
6433

6434
6435

6436
6437
6438

6439
6440
6441
6442
6443
6444
6445
6446
6447

6448
6449

6450
6451
6452

6453
6454
6455
6456
6457

6458
6459

6460
6461
6462
6463
6464
6465

6466
6467
6468

6469
6470
6471

6472
6473
6474

6475
6476
6477
6478

6479
6480
6481
6482


6483
6484
6485
6486
6487
6488
6489
6490

6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502

6503
6504
6505
6506
6507

6508
6509
6510


6511
6512
6513
6514

6515
6516
6517
6518
6519
6520
6521


6522
6523
6524

6525
6526
6527
6528

6529
6530
6531
6532
6533


6534
6535
6536
6537
6538


6539
6540
6541
6542
6543
6544

6545
6546
6547
6548
6549
6550



6551
6552
6553
6554
6555
6556
6557
6558
6559
6560

6561
6562
6563
6564
6565
6566
6567
6568


6569
6570
6571
6572
6573



6574
6575
6576
6577
6578

6579
6580
6581
6582
6583
6584
6585
6586
6587
6588


6589
6590

6591
6592

6593
6594
6595
6596
6597
6598
6599

6600
6601

6602
6603
6604
6605
6606
6607
6608
6609

6610
6611
6612

6613
6614
6615

6616
6617
6618
6619
6620
6621
6622

6623
6624

6625
6626
6627
6628
6629


6630
6631
6632


6633
6634
6635
6636
6637
6638
6639
6640



6641
6642
6643
6644
6645
6646
6647

6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659


6660
6661
6662
6663

6664
6665
6666


6667
6668
6669
6670

6671
6672
6673
6674
6675

6676
6677
6678
6679
6680
6681
6682
6683

6684
6685
6686
6687
6688

6689
6690
6691
6692



6693
6694
6695
6696

6697
6698
6699
6700
6701
6702
6703

6704
6705
6706
6707
6708
6709
6710


6711
6712
6713
6714
6715

6716
6717

6718
6719
6720
6721
6722

6723
6724
6725
6726
6727
6728


6729
6730
6731
6732
6733

6734
6735
6736
6737
6738


6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754


6755
6756

6757
6758

6759
6760
6761

6762
6763
6764
6765
6766
6767
6768
6769

6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780


6781
6782
6783
6784
6785

6786
6787

6788
6789
6790

6791
6792

6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804

6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817

6818
6819
6820
6821

5345
5346
5347
5348
5349
5350
5351

5352
5353
5354


5355
5356

5357

5358
5359
5360
5361
5362
5363
5364
5365
5366
5367


5368
5369
5370

5371
5372
5373
5374
5375
5376
5377
5378
5379

5380


5381
5382
5383

5384


5385
5386
5387


5388
5389

5390
5391
5392
5393
5394
5395
5396
5397
5398
5399

5400
5401
5402


5403
5404

5405
5406
5407
5408
5409
5410
5411
5412
5413




5414
5415
5416
5417
5418

5419
5420
5421
5422


5423
5424
5425
5426

5427
5428
5429




5430
5431
5432
5433

5434
5435
5436
5437



5438
5439
5440
5441
5442



5443
5444
5445

5446
5447
5448
5449

5450


5451



5452


5453



5454


5455




5456
5457

5458
5459
5460
5461




5462
5463
5464
5465
5466

5467
5468
5469
5470

5471
5472
5473

5474
5475
5476
5477



5478
5479
5480

5481
5482
5483
5484

5485
5486
5487

5488
5489

5490
5491
5492
5493




5494
5495
5496
5497

5498
5499
5500
5501

5502
5503
5504

5505
5506
5507
5508



5509
5510
5511

5512
5513
5514
5515


5516
5517
5518
5519


5520
5521
5522
5523
5524
5525




5526
5527
5528
5529

5530
5531
5532
5533


5534
5535
5536
5537
5538

5539


5540



5541
5542
5543

5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558

5559
5560


5561
5562
5563

5564
5565
5566
5567
5568
5569


5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584

5585
5586


5587
5588
5589
5590
5591
5592
5593
5594


5595
5596
5597

5598
5599

5600
5601

5602
5603
5604


5605
5606


5607
5608


5609
5610
5611
5612
5613
5614
5615

5616
5617
5618
5619
5620
5621
5622
5623
5624

5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636

5637
5638
5639
5640
5641
5642

5643
5644
5645


5646
5647
5648
5649
5650

5651

5652
5653
5654
5655

5656
5657
5658
5659
5660
5661

5662
5663
5664
5665
5666
5667

5668
5669
5670

5671
5672
5673
5674
5675
5676
5677
5678

5679
5680
5681
5682
5683
5684
5685
5686

5687
5688
5689
5690
5691
5692

5693


5694

5695
5696
5697
5698

5699
5700
5701
5702
5703

5704
5705
5706
5707
5708
5709

5710
5711
5712
5713
5714
5715

5716
5717
5718
5719
5720
5721
5722

5723
5724
5725
5726
5727
5728

5729
5730
5731
5732
5733
5734
5735

5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749

5750
5751



5752
5753
5754
5755

5756

5757
5758
5759
5760

5761
5762
5763
5764
5765
5766

5767
5768
5769
5770
5771
5772
5773
5774

5775
5776

5777



5778


5779


5780
5781
5782
5783
5784
5785
5786
5787


5788
5789
5790
5791
5792
5793
5794
5795
5796
5797

5798
5799

5800
5801



5802
5803
5804

5805
5806
5807
5808


5809
5810
5811
5812
5813
5814
5815


5816
5817
5818
5819
5820
5821


5822
5823
5824
5825
5826
5827
5828


5829
5830
5831
5832
5833
5834

5835
5836


5837
5838
5839
5840
5841
5842
5843

5844
5845
5846




5847
5848
5849
5850
5851
5852


5853
5854
5855
5856
5857
5858
5859
5860
5861
5862


5863

5864
5865
5866


5867
5868
5869

5870
5871

5872
5873
5874

5875
5876
5877
5878
5879


5880
5881
5882
5883
5884

5885
5886

5887


5888

5889

5890
5891
5892

5893
5894
5895
5896
5897
5898
5899

5900
5901
5902
5903
5904
5905
5906

5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924


5925
5926
5927

5928
5929

5930
5931
5932
5933
5934

5935


5936

5937
5938
5939

5940


5941



5942

5943
5944
5945
5946
5947
5948
5949

5950


5951



5952

5953
5954
5955

5956


5957

5958
5959
5960
5961

5962
5963
5964

5965
5966
5967

5968



5969


5970

5971
5972
5973


5974
5975

5976
5977
5978
5979
5980
5981

5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992


5993

5994
5995
5996

5997
5998


5999
6000

6001
6002

6003
6004
6005
6006
6007



6008
6009

6010

6011
6012
6013
6014

6015


6016


6017
6018
6019
6020
6021


6022
6023
6024
6025
6026
6027
6028

6029
6030
6031
6032



6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043


6044



6045
6046



6047
6048

6049



6050
6051
6052
6053
6054
6055
6056

6057

6058
6059
6060
6061
6062
6063
6064


6065
6066
6067

6068
6069

6070
6071
6072
6073
6074
6075
6076

6077


6078

6079
6080
6081
6082
6083


6084

6085

6086
6087


6088



6089
6090
6091

6092
6093

6094
6095
6096
6097


6098
6099
6100


6101
6102
6103
6104
6105
6106
6107



6108
6109
6110



6111
6112
6113

6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124


6125
6126
6127
6128
6129

6130
6131


6132
6133

6134
6135

6136
6137
6138
6139
6140

6141
6142
6143
6144
6145
6146
6147
6148

6149
6150
6151
6152
6153

6154
6155



6156
6157
6158
6159
6160
6161

6162
6163
6164
6165
6166
6167
6168

6169
6170
6171
6172
6173
6174


6175
6176
6177
6178
6179
6180

6181


6182

6183
6184
6185

6186
6187
6188
6189
6190


6191
6192
6193
6194
6195
6196

6197
6198
6199
6200


6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216


6217
6218
6219

6220


6221

6222

6223
6224
6225
6226
6227
6228
6229
6230

6231
6232
6233
6234
6235
6236
6237
6238
6239
6240


6241
6242
6243
6244
6245
6246

6247


6248

6249

6250


6251




6252
6253
6254
6255
6256
6257
6258

6259

6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270

6271

6272
6273
6274
6275







-
+


-
-
+
+
-

-
+









-
-
+
+

-
+








-
+
-
-



-
+
-
-



-
-
+

-
+









-
+


-
-
+
+
-









-
-
-
-
+
+
+
+
+
-




-
-
+
+


-
+


-
-
-
-
+
+
+
+
-




-
-
-
+
+
+


-
-
-
+
+
+
-




-
+
-
-
+
-
-
-

-
-
+
-
-
-

-
-
+
-
-
-
-
+

-
+



-
-
-
-
+
+
+
+
+
-




-
+


-
+



-
-
-
+
+
+
-




-
+


-
+

-
+



-
-
-
-
+
+
+
+
-




-
+


-
+



-
-
-
+
+
+
-




-
-
+
+


-
-
+
+




-
-
-
-
+
+
+
+
-




-
-
+
+



-
+
-
-

-
-
-
+
+
+
-















-


-
-
+
+

-
+





-
-
+
+













-


-
-
+
+






-
-
+
+

-
+

-
+

-
+


-
-
+
+
-
-


-
-
+
+





-
+








-
+











-
+





-
+


-
-
+
+



-
+
-




-
+





-
+





-
+


-
+







-
+







-
+





-
+
-
-
+
-




-
+




-
+





-
+





-
+






-
+





-
+






-
+













-
+

-
-
-
+
+
+

-
+
-




-
+





-
+







-
+

-
+
-
-
-
+
-
-

-
-
+
+






-
-
+
+








-
+

-
+

-
-
-
+
+
+
-




-
-
+
+





-
-
+
+




-
-
+
+





-
-
+
+




-
+

-
-
+
+





-
+


-
-
-
-
+
+
+



-
-
+
+








-
-
+
-



-
-
+
+

-
+

-
+


-
+




-
-
+
+



-
+

-
+
-
-
+
-

-
+


-
+






-
+






-
+

















-
-
+
+

-
+

-
+




-
+
-
-
+
-



-
+
-
-
+
-
-
-
+
-







-
+
-
-
+
-
-
-
+
-



-
+
-
-
+
-




-
+


-
+


-
+
-
-
-
+
-
-

-
+


-
-
+
+
-






-
+










-
-
+
-



-
+

-
-
+
+
-


-
+




-
-
-
+
+
-

-
+



-
+
-
-

-
-
+
+



-
-
+
+





-
+



-
-
-
+
+
+








-
-
+
-
-
-


-
-
-
+
+
-

-
-
-
+
+
+




-
+
-







-
-
+
+

-
+

-
+






-
+
-
-
+
-





-
-
+
-

-
+

-
-
+
-
-
-



-
+

-
+



-
-
+
+

-
-
+
+





-
-
-
+
+
+
-
-
-



-
+










-
-
+
+



-
+

-
-
+
+
-


-
+




-
+







-
+




-
+

-
-
-
+
+
+



-
+






-
+





-
-
+
+




-
+
-
-
+
-



-
+




-
-
+
+




-
+



-
-
+
+














-
-
+
+

-
+
-
-
+
-

-
+







-
+









-
-
+
+




-
+
-
-
+
-

-
+
-
-
+
-
-
-
-







-
+
-











-
+
-



+
# }

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

proc CompleteFromImages {text {always 1}} {
    set inames [image names]
    if {[string length ${inames}]} {
        return [CompleteFromList ${text} ${inames}]
        if {[string length $inames]} {
            return [CompleteFromList $text $inames]
    } else {
        if ${always} {
            if $always {
            return [DisplayHints <image>]
        } else {
            return ""
        }
    }
}

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

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

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

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

#**
# WidgetXviewYview
#
# @param    text  -- the word to complete.
# @param    line  -- the line gathered so far.
# @param    pos   -- the current word position.
# @param    prev  -- the previous word.
# @return   a std tclreadline formatted completer string.
# @sa       CanvasObj, EntryObj
# @date     Sep-18-1999
#
proc WidgetXviewYview {text line pos prev} {
    switch -- ${pos} {
        2 { return [CompleteFromList ${text} {<index> moveto scroll}] }
        switch -- $pos {
            2 { return [CompleteFromList $text {<index> moveto scroll}] }
        3 {
            switch -- ${prev} {
                switch -- $prev {
                moveto { return [DisplayHints <fraction>] }
                scroll { return [DisplayHints <number>] }
            }
        }
        4 {
            set subcmd [Lindex ${line} 2]
            switch -- ${subcmd} {
                set subcmd [Lindex $line 2]
                switch -- $subcmd {
                scroll { return [DisplayHints <what>] }
            }
        }
    }
}

#**
# WidgetScan
#
# @param    text  -- the word to complete.
# @param    pos   -- the current word position.
# @return   a std tclreadline formatted completer string.
# @sa       CanvasObj, EntryObj
# @date     Sep-18-1999
#
proc WidgetScan {text pos} {
    switch -- ${pos} {
        2 { return [CompleteFromList ${text} {mark dragto}] }
        switch -- $pos {
            2 { return [CompleteFromList $text {mark dragto}] }
        3 { return [DisplayHints <x>] }
        4 { return [DisplayHints <y>] }
    }
}

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

                    set id [Lindex ${line} 2]
                    set type [[Lindex ${line} 0] type ${id}]
                    if {![string length ${type}]} {
                        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 [CanvasItem $text $start $end \
                                    $line $pos $prev $type]
                }
            }
        }
    }
    return ""
}

proc EntryIndex text {
    return [CompleteFromList ${text} {
        <number> <@number> anchor end sel.first sel.last
        return [CompleteFromList $text {<number> <@number> anchor end sel.first sel.last}]
    }]
}

proc EntryObj {text start end line pos} {
    set sub [Lindex ${line} 1]
    set prev [PreviousWord ${start} ${line}]
        set sub [Lindex $line 1]
        set prev [PreviousWord $start $line]
    if {1 == $pos} {
        return [TrySubCmds ${text} [Lindex ${line} 0]]
            return [TrySubCmds $text [Lindex $line 0]]
    }
    switch -- ${sub} {
        switch -- $sub {
        bbox -
        icursor -
        index { return [EntryIndex ${text}] }
            index     { return [EntryIndex $text] }
        cget {}
        configure {}
        get {}
        insert {
            switch -- ${pos} {
                2 { return [EntryIndex ${text}] }
                switch -- $pos {
                    2 { return [EntryIndex $text] }
                3 { return [DisplayHints <string>] }
            }
        }
        scan { return [WidgetScan ${text} ${pos}] }
            scan      { return [WidgetScan $text $pos] }
        selection {
            switch -- ${pos} {
                switch -- $pos {
                2 {
                    return [TrySubCmds ${text} [Lrange ${line} 0 1]]
                    2 { return [TrySubCmds $text [Lrange $line 0 1]] }
                }
                3 {
                    switch -- ${prev} {
                        switch -- $prev {
                        adjust -
                        from -
                        to { return [EntryIndex ${text}] }
                            to      { return [EntryIndex $text] }
                        clear -
                        present {}
                        range { return [DisplayHints <start>] }
                    }
                }
                4 {
                    switch -- [Lindex ${line} 2] {
                        switch -- [Lindex $line 2] {
                        range { return [DisplayHints <end>] }
                    }
                }
            }
        }
        xview -
        yview { return [WidgetXviewYview ${text} ${line} ${pos} ${prev}] }
            yview     { return [WidgetXviewYview $text $line $pos $prev] }
    }
    return ""
}

# proc CheckbuttonObj {text start end line pos} {
# the fallback routines do the job pretty well.
# }

# proc FrameObj {text start end line pos} {
# the fallback routines do the job pretty well.
# }

# proc LabelObj {text start end line pos} {
# the fallback routines do the job pretty well.
# }

proc ListboxObj {text start end line pos} {
    set sub [Lindex ${line} 1]
    set prev [PreviousWord ${start} ${line}]
        set sub [Lindex $line 1]
        set prev [PreviousWord $start $line]
    if {1 == $pos} {
        return [TrySubCmds ${text} [Lindex ${line} 0]]
            return [TrySubCmds $text [Lindex $line 0]]
    }
    switch -- ${sub} {
        switch -- $sub {
        activate -
        bbox -
        index -
        see {
            switch -- ${pos} {
                switch -- $pos {
                2 {
                    return [DisplayHints <index>]
                    2 { return [DisplayHints <index>] }
                }
            }
        }
        insert {
            switch -- ${pos} {
                switch -- $pos {
                2 {
                    return [DisplayHints <index>]
                    2       { return [DisplayHints <index>] }
                }
                default {
                    return [DisplayHints ?element?]
                    default { return [DisplayHints ?element?] }
                }
            }
        }
        cget {}
        configure {}
        curselection {}
        delete -
        get {
            switch -- ${pos} {
                switch -- $pos {
                2 {
                    return [DisplayHints <first>]
                    2 { return [DisplayHints <first>] }
                }
                3 {
                    return [DisplayHints ?last?]
                    3 { return [DisplayHints ?last?] }
                }
            }
        }
        nearest {
            switch -- ${pos} {
                switch -- $pos {
                2 {
                    return [DisplayHints <y>]
                    2 { return [DisplayHints <y>] }
                }
            }
        }
        size {}

        scan { return [WidgetScan ${text} ${pos}] }
            scan { return [WidgetScan $text $pos] }

        xview -
        yview { return [WidgetXviewYview ${text} ${line} ${pos} ${prev}] }
            yview { return [WidgetXviewYview $text $line $pos $prev] }

        selection {
            switch -- ${pos} {
                switch -- $pos {
                2 {
                    return [CompleteFromList ${text} {
                        anchor clear includes set
                    2 { return [CompleteFromList $text {anchor clear includes set}] }
                    }]
                }
                3 {
                    switch -- ${prev} {
                        switch -- $prev {
                        anchor -
                        includes {
                            return [CompleteFromList ${text} {
                                active anchor end @x @y <number>
                                return [CompleteFromList $text \
                                            {active anchor end @x @y <number>}]
                            }]
                        }
                        clear -
                        set { return [DisplayHints <first>] }
                    }
                }
                4 {
                    switch -- [Lindex ${line} 2] {
                        switch -- [Lindex $line 2] {
                        clear -
                        set { return [DisplayHints ?last?] }
                    }
                }
            }
        }
    }
}

proc MenuIndex text {
    return [CompleteFromList ${text} {
        <number> active end last none <@number> <labelPattern>
        return [CompleteFromList $text {<number> active end last none <@number> <labelPattern>}]
    }]
}

proc MenuItem {text start end line pos virtualpos} {
    switch -- ${virtualpos} {
        switch -- $virtualpos {
        2 {
            return [CompleteFromList ${text} {
                cascade checkbutton command radiobutton separator
                return [CompleteFromList $text \
                            {cascade checkbutton command radiobutton separator}]
            }]
        }
        default {
            switch -- [PreviousWord ${start} ${line}] {
                switch -- [PreviousWord $start $line] {
                -activebackground -
                -activeforeground -
                -background -
                -foreground -
                -selectcolor {
                    return [DisplayHints <color>]
                }
                    -selectcolor      { return [DisplayHints <color>] }


                -accelerator { return [DisplayHints <accel>] }
                -bitmap { return [CompleteFromBitmaps ${text}] }
                    -bitmap      { return [CompleteFromBitmaps $text] }

                -columnbreak -
                -hidemargin -
                -indicatoron {
                    -indicatoron { return [CompleteBoolean $text] }
                    return [CompleteBoolean ${text}]
                }
                -command {
                    return [BraceOrCommand ${text} \
                    ${start} ${end} ${line} ${pos} ${text}]
                        return [BraceOrCommand $text $start \
                                    $end $line $pos $text]
                }
                -font {
                    set names [font names]
                    if {[string length ${names}]} {
                        return [CompleteFromList ${text} ${names}]
                        if {[string length $names]} {
                            return [CompleteFromList $text $names]
                    } else {
                        return [DisplayHints <fontname>]
                    }
                }
                -image -
                -selectimage { return [CompleteFromImages ${text}] }
                    -selectimage { return [CompleteFromImages $text] }

                -label { return [DisplayHints <label>] }
                -menu {
                    set names [WidgetChildren [Lindex ${line} 0]]
                    if {[string length ${names}]} {
                        return [CompleteFromList ${text} ${names}]
                        set names [WidgetChildren [Lindex $line 0]]
                        if {[string length $names]} {
                            return [CompleteFromList $text $names]
                    } else {
                        return [DisplayHints <menu>]
                    }
                }

                -offvalue -
                -onvalue { return [DisplayHints <value>] }

                -state {
                    return [CompleteFromList ${text} {
                    -state     { return [CompleteFromList $text {normal active disabled}] }
                        normal active disabled
                    }]
                }
                -underline { return [DisplayHints <integer>] }
                -value { return [DisplayHints <value>] }
                -variable {
                    return [VarCompletion ${text} #0]
                }
                    -variable  { return [VarCompletion $text #0] }


                default {
                    return [CompleteFromList ${text} \
                    [RemoveUsedOptions ${line} {
                        -activebackground -activeforeground
                        return [CompleteFromList $text \
                                    [RemoveUsedOptions $line \
                                         {-activebackground -activeforeground
                        -accelerator -background -bitmap -columnbreak
                        -command -font -foreground -hidemargin -image
                        -indicatoron -label -menu -offvalue -onvalue
                        -selectcolor -selectimage -state -underline
                        -value -variable
                                          -value -variable}]]
                    }]]
                }
            }
        }
    }
}

proc MenuObj {text start end line pos} {
    set sub [Lindex ${line} 1]
    set prev [PreviousWord ${start} ${line}]
        set sub [Lindex $line 1]
        set prev [PreviousWord $start $line]
    if {1 == $pos} {
        return [TrySubCmds ${text} [Lindex ${line} 0]]
            return [TrySubCmds $text [Lindex $line 0]]
    }
    switch -- ${sub} {
        switch -- $sub {
        activate -
        index -
        invoke -
        postcascade -
        type -
        yposition {
            switch -- ${pos} {
                switch -- $pos {
                2 {
                    return [MenuIndex ${text}]
                    2 { return [MenuIndex $text] }
                }
            }
        }
        configure {}
        cget {}

        add {
            return [MenuItem ${text} ${start} ${end} ${line} ${pos} ${pos}]
            add            { return [MenuItem $text $start $end $line $pos $pos] }
        }
        clone {
            switch -- ${pos} {
                switch -- $pos {
                2 { return [DisplayHints <newPathname>] }
                3 {
                    return [CompleteFromList ${text} {
                    3 { return [CompleteFromList $text {normal menubar tearoff}] }
                        normal menubar tearoff
                    }]
                }
            }
        }
        delete {
            switch -- ${pos} {
                switch -- $pos {
                2 -
                3 { return [MenuIndex ${text}] }
                    3 { return [MenuIndex $text] }
            }
        }
        insert {
            switch -- ${pos} {
                2 { return [MenuIndex ${text}] }
                switch -- $pos {
                    2       { return [MenuIndex $text] }
                default {
                    return [MenuItem ${text} ${start} ${end} \
                    ${line} ${pos} [expr ${pos} - 1]]
                        return [MenuItem $text $start $end \
                                    $line $pos [expr {$pos - 1}]]
                }
            }
        }
        entrycget -
        entryconfigure {
            switch -- ${pos} {
                2 { return [MenuIndex ${text}] }
                default {
                switch -- $pos {
                    2       { return [MenuIndex $text] }
                    default { return [MenuItem $text $start $end $line $pos $pos] }
                    return [MenuItem ${text} ${start} \
                    ${end} ${line} ${pos} ${pos}]
                }
            }
        }
        post {
            switch -- ${pos} {
                switch -- $pos {
                2 { return [DisplayHints <x>] }
                3 { return [DisplayHints <y>] }
            }
        }
        # ??? XXX
        unpost {}
    }
}

proc PhotoObj {text start end line pos} {
    set sub [Lindex ${line} 1]
    set prev [PreviousWord ${start} ${line}]
        set sub [Lindex $line 1]
        set prev [PreviousWord $start $line]
    set copy_opts { -from -to -shrink -zoom -subsample }
    set read_opts { -from -to -shrink -format }
    set write_opts { -from -format }
    switch -- ${pos} {
        switch -- $pos {
        1 {
            return [CompleteFromList ${text} {
                blank cget configure copy get put read redither write
                return [CompleteFromList $text \
                            {blank cget configure copy get put read redither write}]
            }]
        }
        2 {
            switch -- ${sub} {
                switch -- $sub {
                blank {}
                cget {}
                configure {}
                redither {}
                copy { return [CompleteFromImages ${text}] }
                    copy      { return [CompleteFromImages $text] }
                get { return [DisplayHints <x>] }
                put { return [DisplayHints <data>] }
                read {}
                write {}
            }
        }
        3 {
            switch -- ${sub} {
                switch -- $sub {
                blank {}
                cget {}
                configure {}
                redither {}
                copy { return [CompleteFromList ${text} ${copy_opts}] }
                    copy      { return [CompleteFromList $text $copy_opts] }
                get { return [DisplayHints <y>] }
                put { return [CompleteFromList ${text} -to] }
                read { return [CompleteFromList ${text} ${read_opts}] }
                write { return [CompleteFromList ${text} ${write_opts}] }
                    put       { return [CompleteFromList $text -to] }
                    read      { return [CompleteFromList $text $read_opts] }
                    write     { return [CompleteFromList $text $write_opts] }
            }
        }
        default {
            switch -- ${sub} {
                switch -- $sub {
                blank {}
                cget {}
                configure {}
                redither {}
                get {}
                copy {
                    switch -- ${prev} {
                        switch -- $prev {
                        -from -
                        -to { return [DisplayHints [list <x1 y1 x2 y2>]] }
                        -zoom -
                        -subsample { return [DisplayHints [list <x y>]] }
                        default {
                            return [CompleteFromList ${text} \
                            [RemoveUsedOptions ${line} ${copy_opts}]]
                                return [CompleteFromList $text \
                                            [RemoveUsedOptions $line $copy_opts]]
                        }
                    }
                }
                put {
                    switch -- ${prev} {
                        switch -- $prev {
                        -to {
                            return [DisplayHints [list <x1 y1 x2 y2>]]
                            -to { return [DisplayHints [list <x1 y1 x2 y2>]] }
                        }
                    }
                }
                read {
                    switch -- ${prev} {
                        switch -- $prev {
                        -from { return [DisplayHints [list <x1 y1 x2 y2>]] }
                        -to { return [DisplayHints [list <x y>]] }
                        -format { return [DisplayHints <formatName>] }
                        default {
                            return [CompleteFromList ${text} \
                            [RemoveUsedOptions ${line} ${read_opts}]]
                                return [CompleteFromList $text \
                                            [RemoveUsedOptions $line $read_opts]]
                        }
                    }
                }
                write {
                    switch -- ${prev} {
                        switch -- $prev {
                        -from { return [DisplayHints [list <x1 y1 x2 y2>]] }
                        -format { return [DisplayHints <formatName>] }
                        default {
                            return [CompleteFromList ${text} \
                            [RemoveUsedOptions ${line} ${write_opts}]]
                                return [CompleteFromList $text \
                                            [RemoveUsedOptions $line $write_opts]]
                        }
                    }
                }
            }
        }
    }
}

# proc RadiobuttonObj {text start end line pos} {
# the fallback routines do the job pretty well.
# }

proc ScaleObj {text start end line pos} {

    set sub [Lindex ${line} 1]
    set prev [PreviousWord ${start} ${line}]
        set sub [Lindex $line 1]
        set prev [PreviousWord $start $line]

    switch -- ${pos} {
        switch -- $pos {
        1 {
            return [TrySubCmds ${text} [Lindex ${line} 0]]
            1 { return [TrySubCmds $text [Lindex $line 0]] }
        }
        2 {
            switch -- ${sub} {
                switch -- $sub {
                coords { return [DisplayHints ?value?] }
                get { return [DisplayHints ?x?] }
                identify { return [DisplayHints <x>] }
                set { return [DisplayHints <value>] }
            }
        }
        3 {
            switch -- ${sub} {
                switch -- $sub {
                get { return [DisplayHints ?y?] }
                identify { return [DisplayHints <y>] }
            }
        }
    }
}

proc ScrollbarObj {text start end line pos} {

    set sub [Lindex ${line} 1]
    set prev [PreviousWord ${start} ${line}]
        set sub [Lindex $line 1]
        set prev [PreviousWord $start $line]

    # note that the `prefix moveto|scroll'
    # construct is hard to complete.
    #
    switch -- ${pos} {
        switch -- $pos {
        1 {
            return [TrySubCmds ${text} [Lindex ${line} 0]]
            1 { return [TrySubCmds $text [Lindex $line 0]] }
        }
        2 {
            switch -- ${sub} {
                switch -- $sub {
                activate {
                    return [CompleteFromList ${text} {
                    activate { return [CompleteFromList $text {arrow1 slider arrow2}] }
                        arrow1 slider arrow2
                    }]
                }

                fraction -
                identify { return [DisplayHints <x>] }
                delta { return [DisplayHints <deltaX>] }
                set { return [DisplayHints <first>] }
            }
        }
        3 {
            switch -- ${sub} {
                switch -- $sub {

                fraction -
                identify { return [DisplayHints <y>] }
                delta { return [DisplayHints <deltaY>] }
                set { return [DisplayHints <last>] }
            }
        }
    }
}

proc TextObj {text start end line pos} {
    # TODO ...
    return [CompleteFromOptionsOrSubCmds \
        return [CompleteFromOptionsOrSubCmds $text $start $end $line $pos]
    ${text} ${start} ${end} ${line} ${pos}]
}

}; # namespace tclreadline

Modified tclreadlineInit.tcl.in from [554b1c74c7] to [339306884c].

11
12
13
14
15
16
17
18
19


20
21
22
23
24
25
26
11
12
13
14
15
16
17


18
19
20
21
22
23
24
25
26







-
-
+
+








namespace eval tclreadline:: {
    namespace export Init
}

proc ::tclreadline::Init {} {
    uplevel #0 {
    if ![info exists tclreadline::library] {
        if [catch {load [file join @TCLRL_LIBDIR@ libtclreadline[info sharedlibextension]]} msg] {
        if {![info exists tclreadline::library]} {
            if {[catch {load [file join @TCLRL_LIBDIR@ libtclreadline[info sharedlibextension]]} msg]} {
        puts stderr $msg
        exit 2
        }
    }
    }
}

Modified tclreadlineSetup.tcl.in from [601cc4d255] to [3c98c4bea3].

18
19
20
21
22
23
24
25

26
27
28
29

30
31
32
33
34
35
36

37
38
39

40
41
42

43
44
45
46
47
48
49
50
51
52
53
54


55
56
57
58
59
60
61
62
63
64

65
66
67
68
69
70
71
72
73
74


75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

111
112
113
114
115

116
117
118
119
120
121
122
18
19
20
21
22
23
24

25
26
27
28

29
30
31
32
33
34
35

36

37

38
39
40

41
42
43
44
45
46
47
48
49
50
51


52
53

54
55
56
57
58
59

60

61
62
63
64
65
66
67
68
69


70
71

72
73
74
75
76
77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104


105
106
107
108
109
110
111
112
113
114
115
116
117
118







-
+



-
+






-
+
-

-
+


-
+










-
-
+
+
-






-

-
+








-
-
+
+
-












-
+




















-
-
+





+







    # Save the values of errorCode and errorInfo variables, since they
    # may get modified if caught errors occur below.  The variables will
    # be restored just before re-executing the missing command.

    set savedErrorCode $errorCode
    set savedErrorInfo $errorInfo
    set name [lindex $args 0]
    if ![info exists auto_noload] {
    if {![info exists auto_noload]} {
    #
    # Make sure we're not trying to load the same proc twice.
    #
    if [info exists unknown_pending($name)] {
        if {[info exists unknown_pending($name)]} {
        return -code error "self-referential recursion in \"unknown\" for command \"$name\""
    }
    set unknown_pending($name) pending
    set ret [catch {auto_load $name [uplevel 1 {namespace current}]} msg]
    unset unknown_pending($name)
    if {$ret != 0} {
        return -code $ret -errorcode $errorCode \
            return -code $ret -errorcode $errorCode "error while autoloading \"$name\": $msg"
        "error while autoloading \"$name\": $msg"
    }
    if ![array size unknown_pending] {
        if {![array size unknown_pending]} {
        unset unknown_pending
    }
    if $msg {
        if {$msg} {
        set errorCode $savedErrorCode
        set errorInfo $savedErrorInfo
        set code [catch {uplevel 1 $args} msg]
        if {$code ==  1} {
        #
        # Strip the last five lines off the error stack (they're
            # from the "uplevel" command).
        #

        set new [split $errorInfo \n]
        set new [join [lrange $new 0 [expr [llength $new] - 6]] \n]
        return -code error -errorcode $errorCode \
                set new [join [lrange $new 0 [expr {[llength $new] - 6}]] \n]
                return -code error -errorcode $errorCode -errorinfo $new $msg
        -errorinfo $new $msg
        } else {
        return -code $code $msg
        }
    }
    }

    # REMOVED THE [info script] TEST (joze, SEP 98)
    if {([info level] == 1) && [info exists tcl_interactive] && $tcl_interactive} {
    if ![info exists auto_noexec] {
    if {![info exists auto_noexec]} {
        set new [auto_execok $name]
        if {$new != ""} {
        set errorCode $savedErrorCode
        set errorInfo $savedErrorInfo
        set redir ""
        if {[info commands console] == ""} {
            set redir ">&@stdout <@stdin"
        }
        # LOOK FOR GLOB STUFF IN $ARGS (joze, SEP 98)
        return [uplevel eval exec $redir $new \
            # look for glob stuff in $args
            return [uplevel eval exec $redir $new [::tclreadline::Glob [lrange $args 1 end]]]
        [::tclreadline::Glob [lrange $args 1 end]]]
        }
    }
    set errorCode $savedErrorCode
    set errorInfo $savedErrorInfo
    if {$name == "!!"} {
        set newcmd [history event]
    } elseif {[regexp {^!(.+)$} $name dummy event]} {
        set newcmd [history event $event]
    } elseif {[regexp {^\^([^^]*)\^([^^]*)\^?$} $name dummy old new]} {
        set newcmd [history event -1]
        catch {regsub -all -- $old $newcmd $new newcmd}
    }
    if [info exists newcmd] {
    if {[info exists newcmd]} {
        tclLog $newcmd
        history change $newcmd 0
        return [uplevel $newcmd]
    }

    set ret [catch {set cmds [info commands $name*]} msg]
    if {[string compare $name "::"] == 0} {
        set name ""
    }
    if {$ret != 0} {
        return -code $ret -errorcode $errorCode \
        "error in unknown while checking if \"$name\" is a unique command abbreviation: $msg"
    }
    if {[llength $cmds] == 1} {
        return [uplevel [lreplace $args 0 0 $cmds]]
    }
    if {[llength $cmds] != 0} {
        if {$name == ""} {
        return -code error "empty command name \"\""
        } else {
        return -code error \
        "ambiguous command name \"$name\": [lsort $cmds]"
            return -code error "ambiguous command name \"$name\": [lsort $cmds]"
        }
    }
    }
    return -code error "invalid command name \"$name\""
}


namespace eval tclreadline {

namespace export Setup Loop InitTclCmds InitTkCmds Print ls

proc ls {args} {
    if {[exec uname -s] == "Linux"} {
137
138
139
140
141
142
143
144
145
146


147
148
149
150
151
152
153
154
133
134
135
136
137
138
139



140
141

142
143
144
145
146
147
148







-
-
-
+
+
-







    if {"" == [info procs ::tclreadline::prompt1] && [info nameofexecutable] != ""} {

        namespace eval ::tclreadline {
        variable prompt_string
        set base [file tail [info nameofexecutable]]

        if {[string match tclsh* $base] && [info exists tcl_version]} {
            set prompt_string \
            "\[0;31mtclsh$tcl_version\[0m"
        } elseif {[string match wish* $base] \
                        set prompt_string "\[0;31mtclsh$tcl_version\[0m"
                    } elseif {[string match wish* $base] && [info exists tk_version]} {
            && [info exists tk_version]} {
            set prompt_string "\[0;34mwish$tk_version\[0m"
            } else {
            set prompt_string "\[0;31m$base\[0m"
            }

        }

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
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







-









-









-
-
-
-
+
+










-
+












-
+

-
-
+
-

-
+


-
+








            if [info exists env(HOME)] {
            regsub $env(HOME) $pwd "~" pwd
            }
            return "$prompt_string \[$pwd\]"
        }
        }
        # puts body=[info body ::tclreadline::prompt1]
    }

    if {"" == [info procs ::tclreadline::prompt2] && [info nameofexecutable] != ""} {

        if {"" == [info procs ::tclreadline::prompt2]} {
        proc ::tclreadline::prompt2 {} {
            return ">"
        }
        }
        # puts body=[info body ::tclreadline::prompt2]
    }

    if {"" == [info procs exit]} {

        catch {rename ::tclreadline::Exit ""}
        rename exit ::tclreadline::Exit

        proc exit {args} {

        if {[catch {
            ::tclreadline::readline write \
            [::tclreadline::HistoryFileGet]
        } ::tclreadline::errorMsg]} {
                    if {[catch {::tclreadline::readline write [::tclreadline::HistoryFileGet]} \
                             ::tclreadline::errorMsg]} {
            puts stderr $::tclreadline::errorMsg
        }

        # this call is ignored, if tclreadline.c
        # was compiled with CLEANUP_AFER_SIGNAL
        # not defined. This is the case for
        # older versions of libreadline.
        #
        ::tclreadline::readline reset-terminal

        if [catch "eval ::tclreadline::Exit $args" message] {
                    if {[catch "eval ::tclreadline::Exit $args" message]} {
            puts stderr "error:"
            puts stderr "$message"
        }
        # NOTREACHED
        }
    }

    }

    global env
    variable historyfile

    if {[string trim [llength ${args}]]} {
        if {[string trim [llength $args]]} {
    set historyfile ""
    catch {
        set historyfile [file nativename [lindex ${args} 0]]
            catch {set historyfile [file nativename [lindex $args 0]]}
    }
    if {"" == [string trim $historyfile]} {
        set historyfile [lindex ${args} 0]
                set historyfile [lindex $args 0]
    }
    } else {
    if [info exists env(HOME)] {
            if {[info exists env(HOME)]} {
        set historyfile  $env(HOME)/.tclsh-history
    } else {
        set historyfile  .tclsh-history
    }
    }
    set ::tclreadline::errorMsg [readline initialize $historyfile]
    if {$::tclreadline::errorMsg != ""} {
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277



278
279
280

281
282
283
284
285



286
287
288

289
290
291
292

293
294
295
296
297
298
299
300
301
302
303
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
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260
261



262
263
264


265
266
267
268



269
270
271


272
273
274
275


276
277
278
279
280
281
282
283
284
285
286
287


288
289
290
291
292

293
294
295
296
297
298

299
300

301
302
303
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







-









-
-
-
+
+
+
-
-

+


-
-
-
+
+
+
-
-

+


-
-
+











-
-
+
+



-
+





-
+

-
+








-
+









-
-
+
+







    }
    # return $commandstring
    # Christian Krone <krischan@sql.de> proposed
    return [eval concat $commandstring]
}



proc Loop {args} {

    eval Setup ${args}

    uplevel #0 {

    while {1} {

        if {[catch {
        if {"" != [namespace eval ::tclreadline {info procs prompt1}]} {
            set ::tclreadline::LINE [::tclreadline::readline read \
            [::tclreadline::prompt1]]
                    set prompt "% "
                    if {"" != [info procs ::tclreadline::prompt1]} {
                        set prompt [::tclreadline::prompt1]
        } else {
            set ::tclreadline::LINE [::tclreadline::readline read %]
        }
                    set ::tclreadline::LINE [::tclreadline::readline read $prompt]
        while {![::tclreadline::readline complete $::tclreadline::LINE]} {
            append ::tclreadline::LINE "\n"
            if {"" != [namespace eval ::tclreadline {info procs prompt2}]} {
            append ::tclreadline::LINE \
                [tclreadline::readline read [::tclreadline::prompt2]]
                        set prompt2 "> "
                        if {"" != [info procs ::tclreadline::prompt2]} {
                            set prompt2 [::tclreadline::prompt2]
            } else {
            append ::tclreadline::LINE [tclreadline::readline read >]
            }
                        append ::tclreadline::LINE [tclreadline::readline read $prompt2]
        }
        } ::tclreadline::errorMsg]} {
        puts stderr [list tclreadline::Loop: error. \
        $::tclreadline::errorMsg]
                    puts stderr "tclreadline::Loop: error. $::tclreadline::errorMsg"
        continue
        }

        # Magnus Eriksson <magnus.eriksson@netinsight.se> proposed
        # to add the line also to tclsh's history.
        #
        # I decided to add only lines which are different from
        # the previous one to the history. This is different
        # from tcsh's behaviour, but I found it quite convenient
        # while using mshell on os9.
        #
        if {[string length $::tclreadline::LINE] && \
            [history event 0] != $::tclreadline::LINE} {
                if {[string length $::tclreadline::LINE]
                        && [history event 0] != $::tclreadline::LINE} {
        history add $::tclreadline::LINE
        }

        if [catch {
                if {[catch {
        set ::tclreadline::result [eval $::tclreadline::LINE]
        if {$::tclreadline::result != "" && [tclreadline::Print]} {
            puts $::tclreadline::result
        }
        set ::tclreadline::result ""
        } ::tclreadline::errorMsg] {
                } ::tclreadline::errorMsg]} {
        puts stderr $::tclreadline::errorMsg
        puts stderr [list while evaluating $::tclreadline::LINE]
                    puts stderr "while evaluating $::tclreadline::LINE"
        }

    }
    }
}

proc Print {args} {
    variable PRINT
    if ![info exists PRINT] {
        if {![info exists PRINT]} {
    set PRINT yes
    }
    if [regexp -nocase \(true\|yes\|1\) $args] {
    set PRINT yes
    } elseif [regexp -nocase \(false\|no\|0\) $args] {
    set PRINT no
    }
    return $PRINT
}
#
#


# proc InitCmds {} {
#     # XXX
#     return
#     # XXX
#     global tcl_version tk_version
#     if {[info exists tcl_version]} {
#         InitTclCmds
449
450
451
452
453
454
455
456
457
458
459
433
434
435
436
437
438
439

440
441
442







-



#         "wm option window ?arg ...?"
#     } {
#         readline add $line
#         set known_cmds([lindex $line 0]) ${line}
#     }
#     rename InitTkCmds ""
# }
#


}; # namespace tclreadline