Check-in [32efe7b8fe]
Not logged in
Overview
Comment: Modified Files: README tclreadline.n.in tclreadlineSetup.tcl.in Added Files: Makefile.in tclreadline.c tclreadlineConfig.sh.in tclreadlineInit.tcl.in
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:32efe7b8feae9c8f743c9a42ca5a582878c064f9
User & Date: johannes@zellner.org on 1999-08-22 21:31:14
Other Links: manifest | tags
Context
1999-08-22
22:28
Modified Files: README sample.tclshrc tclreadline.n.in tclreadlineSetup.tcl.in Added Files: Makefile.in tclreadline.c tclreadlineConfig.sh.in tclreadlineInit.tcl.in check-in: 12f1ef0408 user: johannes@zellner.org tags: trunk
21:31
Modified Files: README tclreadline.n.in tclreadlineSetup.tcl.in Added Files: Makefile.in tclreadline.c tclreadlineConfig.sh.in tclreadlineInit.tcl.in check-in: 32efe7b8fe user: johannes@zellner.org tags: trunk
18:52
Modified Files: .tclshrc src/tclreadline/README src/tclreadline/configure.in Added Files: src/tclreadline/Makefile.in src/tclreadline/tclreadline.c src/tclreadline/tclreadlineConfig.sh.in src/tclreadline/tclreadlineInit.tcl.in check-in: ca84c60bc0 user: johannes@zellner.org tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Modified README from [4b475b39b8] to [b445706663].

     1      1   
     2      2       FILE: "/home/joze/src/tclreadline/README"
     3         -    LAST MODIFICATION: "Sun Aug 22 18:34:26 1999 (joze)"
            3  +    LAST MODIFICATION: "Sun Aug 22 23:24:34 1999 (joze)"
     4      4       (C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org>
     5      5       $Id$
     6      6       ---
     7      7   
     8      8       tclreadline -- gnu readline for tcl
     9      9       Copyright (C) 1999  Johannes Zellner
    10     10   
................................................................................
    68     68   
    69     69   copy the sample.tclshrc to $HOME/.tclshrc. If you use another interpreter
    70     70   like wish, you should copy the file sample.tclshrc to $HOME/.wishrc
    71     71   (or whatever the manual page of your interpreter says.) If you have
    72     72   installed tclreadline properly, you are just ready to start:
    73     73   start your favorite interpreter. The tclreadlineSetup.tcl script
    74     74   does the rest.
           75  +
           76  +
           77  +4. History and Changes.
           78  +-----------------------
           79  +
           80  +tclreadline-0.9: (Aug 1999)
           81  +
           82  +    changes:
           83  +        - tclreadline::readline customcompleter
           84  +        - tclreadline::readline builtincompleter
           85  +        - tclreadline::readline eofchar
           86  +        - variable, array and '[' command completion.
           87  +
           88  +    bug fixes:
           89  +        - history entries.
           90  +        - macro mappings didn't work. (only on hitting
           91  +          mapped characters more than once.)
           92  +        - minor fixes in configure.in
           93  +
           94  +tclreadline-0.8:
           95  +    minor bug fixes.
           96  +
           97  +tclreadline-0.7:
           98  +    first `public release'.

Modified tclreadline.c from [b8b89d75f0] to [ebe0deb081].

     1      1   
     2      2    /* ==================================================================
     3      3   
     4      4       FILE: "/home/joze/src/tclreadline/tclreadline.c"
     5         -    LAST MODIFICATION: "Sun Aug 22 19:06:26 1999 (joze)"
            5  +    LAST MODIFICATION: "Sun Aug 22 21:26:05 1999 (joze)"
     6      6       (C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org>
     7      7       $Id$
     8      8       ---
     9      9   
    10     10       tclreadline -- gnu readline for tcl
    11     11       Copyright (C) 1999  Johannes Zellner
    12     12   
................................................................................
   327    327   {
   328    328   
   329    329       rl_readline_name = "tclreadline";
   330    330       rl_special_prefixes = "${";
   331    331       using_history();
   332    332       /**
   333    333        * default is " \t\n\"\\'`@$><=;|&{("
   334         -     * removed '{'.
          334  +     * removed "{(.
   335    335        */
   336         -    rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&(";
          336  +    rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&";
   337    337       if (!tclrl_eof_string)
   338    338           tclrl_eof_string = strdup("puts {}; exit");
   339    339   
   340    340       /*
   341    341        * try to read historyfile in home
   342    342        * directory. If this failes, this
   343    343        * is *not* an error.

Modified tclreadline.n.in from [7b31b0a3f2] to [401a33cf08].

     1      1   .TH tclreadline n "@TCLREADLINE_VERSION@" "Johannes Zellner"
     2      2   
     3      3   .\" (C) 1999 by Johannes Zellner
     4      4   .\" FILE: "/home/joze/src/tclreadline/tclreadline.n.in"
     5         -.\" LAST MODIFICATION: "Sat Aug 21 00:33:01 1999 (joze)"
            5  +.\" LAST MODIFICATION: "Sun Aug 22 23:24:34 1999 (joze)"
     6      6   .\" (C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org>
     7      7   .\" $Id$
     8      8   .\" ---
     9      9   .\"
    10     10   .\" tclreadline -- gnu readline for the tcl scripting language
    11     11   .\" Copyright (C) 1999  Johannes Zellner
    12     12   .\"
................................................................................
    95     95   typing but<Tab> will complete to button. Hitting <Tab> again
    96     96   will complete to "button pathName".  ...
    97     97   
    98     98   .TP 5
    99     99   \fB::tclreadline::readline complete\fP \fIstring\fP
   100    100   returns 1 if \fIstring\fP is a complete tcl command and 0 otherwise.
   101    101   
          102  +.TP 5
          103  +\fB::tclreadline::readline customcompleter\fP [\fIstring\fP]
          104  +Register the proc \fIstring\fP as custom completer. This proc is called
          105  +with exactly four arguments each time completion takes place:
          106  +the word to complete ("text"), the "start" and "end" positions of this word
          107  +in the line entered so far, and this line ("line"). The custom completion
          108  +script should return an array of strings which is a list of completions
          109  +for "text".  If there are no completions, it should return an empty
          110  +string "".  The first entry in the returned list is the substitution
          111  +for "text". The remaining entries are the possible completions. If
          112  +the custom completion script returns an empty string and builtin
          113  +completion is enabled (see \fBtclreadline::readline builtincompleter\fP),
          114  +the builtin completer is called.
          115  +\fBtclreadline::readline customcompleter\fP simply returns the current
          116  +custom completer if called w/o \fIstring\fP. To turn of custom
          117  +completion, call \fBtclreadline::readline customcompleter\fP with
          118  +an empty \fIstring\fP.
          119  +
          120  +Example: \fB% puts $b<TAB>\fP will call the custom completer
          121  +with the four arguments \fI"$b"\fP, \fI"5"\fP, \fI"8"\fP and \fI"puts $b"\fP.
          122  +The custom completer could return a string like "$bl $black $blue", which
          123  +will complete "$b" to "$bl" (the longest match) and offer a list of two
          124  +further matches "$black" and "$blue".
          125  +
          126  +For further reference, see the proc tclreadline::script_completer in
          127  +the file tclreadlineSetup.tcl.
          128  +
          129  +.TP 5
          130  +\fB::tclreadline::readline builtincompleter\fP [\fIbool\fP]
          131  +enable or disable the builtin completer. If the builtin completer
          132  +is enabled, it will be invoked either if there is no custom completer,
          133  +or the custom completer returned an empty  string. The builtin
          134  +completer is on by default.
          135  +\fBtclreadline::readline builtincompleter\fP returns the current
          136  +custom completer (also, if called w/o the \fIbool\fP argument).
          137  +
          138  +.TP 5
          139  +\fB::tclreadline::readline eofchar\fP [\fIscript\fP]
          140  +set a script which will be called, if readline returns the eof character
          141  +(this is typically the case if CTRL-D is entered at the very beginning
          142  +of the line). The default for this script is "puts {}; exit". Setting
          143  +this to an empty value disables any action on eof.
          144  +\fBtclreadline::readline eof\fP returns the current eof script.
          145  +
   102    146   .TP 5
   103    147   \fB::tclreadline::readline initialize\fP \fIhistoryfile\fP
   104    148   initialize the tclreadline interface and read the history from
   105    149   the \fIhistoryfile\fP. On succes an empty string is returned.
   106    150   This command has to be called before any other tclreadline commands.
   107    151   
   108    152   
................................................................................
   238    282   
   239    283   .SH HISTORY
   240    284   This version of \fBtclreadline\fP is still a development version.
   241    285   Pretty a lot of features and ideas are not implemented yet. The
   242    286   reason for this is the lack of time and manpower.
   243    287   So you are welcome to modify and contribute to the code.
   244    288   If you have suggestions, please let me know.
   245         -
   246         -

Modified tclreadlineSetup.tcl.in from [8545e21571] to [92fdf6b439].

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