Check-in [3257fb6735]
Not logged in
Overview
Comment: Modified Files: src/tclreadline/tclreadline.c src/tclreadline/tclreadlineCompleter.tcl src/tclreadline/tclreadlineSetup.tcl.in Added Files: src/csym/version
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3257fb6735879419a823e3c56da1b380918a7df2
User & Date: johannes@zellner.org on 1999-09-14 00:00:35
Other Links: manifest | tags
Context
1999-09-14
14:56
.complete .login .tclshrc .vimrc .wishrc tcltags vimrc tcl_ft.vim Align.vim SpecificSettings.vim comment.vim configure.in sources tclreadline.c tclreadlineCompleter.tcl check-in: db706bec68 user: johannes@zellner.org tags: trunk
00:00
Modified Files: src/tclreadline/tclreadline.c src/tclreadline/tclreadlineCompleter.tcl src/tclreadline/tclreadlineSetup.tcl.in Added Files: src/csym/version check-in: 3257fb6735 user: johannes@zellner.org tags: trunk
1999-09-13
16:33
.tclshrc .vimrc Modified Files: Makefile.in configure.in sample.tclshrc tclreadline.c tclreadline.h.in Added Files: config.h.in check-in: 0d1401e9c1 user: johannes@zellner.org tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Modified tclreadline.c from [9394d14783] to [1096dacb0c].

     1      1   
     2      2    /* ==================================================================
     3      3   
     4         -    FILE: "/diska/home/joze/src/tclreadline/tclreadline.c"
     5         -    LAST MODIFICATION: "Mon Sep 13 18:04:01 1999 (joze)"
            4  +    FILE: "/home/joze/src/tclreadline/tclreadline.c"
            5  +    LAST MODIFICATION: "Tue Sep 14 00:57:33 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   
................................................................................
    77     77   
    78     78   /*
    79     79    * forward declarations.
    80     80    */
    81     81   char* stripleft(char* in);
    82     82   char* stripright(char* in);
    83     83   char* stripwhite(char* in);
           84  +int TclReadlineLineComplete(void);
           85  +void TclReadlineTerminate(int state);
    84     86   char* TclReadlineQuote(char* text, char* quotechars);
    85     87   int TclReadlineCmd(ClientData clientData, Tcl_Interp* interp,
    86     88       int argc, char** argv);
    87     89   void TclReadlineReadHandler(ClientData clientData, int mask);
    88     90   void TclReadlineLineCompleteHandler(char* ptr);
    89     91   int Tclreadline_SafeInit(Tcl_Interp* interp);
    90     92   int Tclreadline_Init(Tcl_Interp* interp);
................................................................................
    92     94   int blank_line(char* str);
    93     95   char** TclReadlineCompletion(char* text, int start, int end);
    94     96   char* TclReadline0generator(char* text, int state);
    95     97   char* TclReadlineKnownCommands(char* text, int state, int mode);
    96     98   int TclReadlineParse(char** args, int maxargs, char* buf);
    97     99   
    98    100   enum { 
    99         -    LINE_PENDING,
   100         -    LINE_EOF,
   101         -    LINE_COMPLETE
          101  +    LINE_PENDING = -1,
          102  +    LINE_EOF = (1 << 8),
          103  +    LINE_COMPLETE = (1 << 9)
   102    104   };
   103    105   
   104    106   /**
   105    107    * global variables
   106    108    */
   107         -static int tclrl_line_complete = LINE_PENDING;
   108    109   static int tclrl_state = TCL_OK;
   109    110   static char* tclrl_eof_string = (char*) NULL;
   110         -static char* tclrl_line = (char*) NULL;
   111    111   static char* tclrl_custom_completer = (char*) NULL;
          112  +static char* tclrl_last_line = (char*) NULL;
   112    113   static int tclrl_use_builtin_completer = 1;
   113    114   static int tclrl_history_length = -1;
   114    115   Tcl_Interp* tclrl_interp = (Tcl_Interp*) NULL;
   115    116   
   116    117   
   117    118   char*
   118    119   stripleft(char* in)
................................................................................
   137    138   char*
   138    139   stripwhite(char* in)
   139    140   {
   140    141       stripleft(in);
   141    142       stripright(in);
   142    143       return in;
   143    144   }
          145  +
          146  +int
          147  +TclReadlineLineComplete(void)
          148  +{
          149  +    return !(tclrl_state == LINE_PENDING);
          150  +}
          151  +
          152  +void
          153  +TclReadlineTerminate(int state)
          154  +{
          155  +    tclrl_state = state;
          156  +    rl_callback_handler_remove();
          157  +}
   144    158   
   145    159   char*
   146    160   TclReadlineQuote(char* text, char* quotechars)
   147    161   {
   148    162       char* ptr;
   149    163       char* result_c;
   150    164       int i, len = strlen(quotechars);
................................................................................
   162    176       }
   163    177       result_c = strdup(Tcl_DStringValue(&result));
   164    178       return result_c;
   165    179   }
   166    180   
   167    181   int
   168    182   TclReadlineCmd(
   169         -    ClientData  clientData, /* Main window associated with interpreter  */
   170         -    Tcl_Interp* interp,     /* Current interpreter                      */
   171         -    int         argc,       /* Number of arguments                      */
   172         -    char**      argv        /* Argument strings                         */
          183  +    ClientData  clientData,
          184  +    Tcl_Interp* interp,     /* Current interpreter */
          185  +    int         argc,       /* Number of arguments */
          186  +    char**      argv        /* Argument strings    */
   173    187   )
   174    188   {
   175         -    int		c, length;
          189  +    int i, obj_idx, status;
          190  +    Tcl_Obj** objv = (Tcl_Obj**) MALLOC((argc + 1) * sizeof(Tcl_Obj *));
          191  +
          192  +    static char *subCmds[] = {
          193  +        "read", "initialize", "write", "add", "complete",
          194  +        "customcompleter", "builtincompleter", "eofchar",
          195  +        (char *) NULL
          196  +    };
          197  +    enum SubCmdIdx {
          198  +        TCLRL_READ, TCLRL_INITIALIZE, TCLRL_WRITE, TCLRL_ADD, TCLRL_COMPLETE,
          199  +        TCLRL_CUSTOMCOMPLETER, TCLRL_BUILTINCOMPLETER, TCLRL_EOFCHAR
          200  +    };
          201  +
          202  +
          203  +    Tcl_ResetResult(interp); /* clear the result space */
          204  +
          205  +    for (i = 0;  i < argc;  i++) {
          206  +        Tcl_Obj* objPtr = Tcl_NewStringObj(argv[i], -1);
          207  +        Tcl_IncrRefCount(objPtr);
          208  +        objv[i] = objPtr;
          209  +    }
          210  +    objv[argc] = 0; /* terminate */
          211  +
          212  +    if (argc < 2) {
          213  +        Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?");
          214  +        return TCL_ERROR;
          215  +    }
   176    216       
   177         -    if (argc < 2)
   178         -        goto BAD_COMMAND;
          217  +    status = Tcl_GetIndexFromObj
          218  +        (interp, objv[1], subCmds, "option", 0, (int *) &obj_idx);
   179    219   
   180         -    c = argv[1][0];
   181         -    length = strlen(argv[1]);
          220  +    if (status != TCL_OK) {
          221  +        FREE(objv)
          222  +        return status;
          223  +    }
   182    224   
   183         -    if (c == 'r'  && strncmp(argv[1], "read", length) == 0) {
   184         -        
   185         -        char* expansion = (char*) NULL;
   186         -        int status;
   187         -        
   188         -        tclrl_line_complete = LINE_PENDING;
   189         -        tclrl_state = TCL_OK;
   190         -        rl_callback_handler_install(argc == 3 ? argv[2] : "%",
          225  +    switch (obj_idx) {
          226  +
          227  +        case TCLRL_READ:
          228  +
          229  +            rl_callback_handler_install(argc == 3 ? argv[2] : "%",
   191    230                   TclReadlineLineCompleteHandler);
   192    231   
   193         -        Tcl_CreateFileHandler(0, TCL_READABLE,
          232  +            Tcl_CreateFileHandler(0, TCL_READABLE,
   194    233                   TclReadlineReadHandler, (ClientData) NULL);
   195    234   
   196         -        /**
   197         -         * Main Loop.
   198         -         * XXX each modification of the global variables
   199         -         *     which terminates the main loop must call
   200         -         *     rl_callback_handler_remove() to leave
   201         -         *     readline in a defined state.          XXX
   202         -         */
   203         -        while (LINE_PENDING == tclrl_line_complete
   204         -            && TCL_OK == tclrl_state && !rl_done) {
   205         -            Tcl_DoOneEvent(TCL_ALL_EVENTS);
   206         -        }
   207         -
   208         -        Tcl_DeleteFileHandler(0);
   209         -
   210         -        if (TCL_OK != tclrl_state)
   211         -            return tclrl_state; /* !! */
   212         -
   213         -	if ((LINE_EOF == tclrl_line_complete) && tclrl_eof_string) {
   214         -	    Tcl_Eval(interp, tclrl_eof_string);
   215         -            return tclrl_state;
   216         -	}
   217         -
   218         -        status = history_expand(tclrl_line, &expansion);
   219         -        if (status >= 1) {
   220         -#if 0
   221         -            Tcl_Channel channel = Tcl_MakeFileChannel(stdout, TCL_WRITABLE);
   222         -            /* Tcl_RegisterChannel(interp, channel); */
   223         -            (void) Tcl_WriteChars(channel, expansion, -1);
   224         -            Tcl_Flush(channel);
   225         -            Tcl_Close(interp, channel);
   226         -#else
   227         -            printf("%s\n", expansion);
          235  +            /**
          236  +             * Main Loop.
          237  +             * XXX each modification of the global variables
          238  +             *     which terminates the main loop must call
          239  +             *     rl_callback_handler_remove() to leave
          240  +             *     readline in a defined state.          XXX
          241  +             */
          242  +            tclrl_state = LINE_PENDING;
          243  +
          244  +            while (!TclReadlineLineComplete()) {
          245  +#ifdef EXECUTING_MACRO_HACK
          246  +                /**
          247  +                 * check first, if more characters are
          248  +                 * available from _rl_executing_macro,
          249  +                 * because Tcl_DoOneEvent() will (naturally)
          250  +                 * not detect this `event'.
          251  +                 */
          252  +                if (_rl_executing_macro)
          253  +                    TclReadlineReadHandler((ClientData) NULL, TCL_READABLE);
          254  +                else
   228    255   #endif
   229         -        }
   230         -        else if (status == -1) {
   231         -            Tcl_AppendResult
   232         -                (interp, "error in history expansion\n", (char*) NULL);
   233         -            return tclrl_state;
   234         -        }
   235         -        /**
   236         -         * TODO: status == 2 ...
   237         -         */
   238         -        
   239         -        if (expansion && *expansion)
   240         -            add_history(expansion);
   241         -
   242         -        Tcl_SetResult(interp, expansion, TCL_VOLATILE);
   243         -
   244         -        FREE(tclrl_line);
   245         -        FREE(expansion);
   246         -        return tclrl_state;
   247         -    } else if (c == 'i'  && strncmp(argv[1], "initialize", length) == 0) {
   248         -        if (3 != argc)
   249         -            goto BAD_COMMAND;
   250         -        else
   251         -            return TclReadlineInitialize(interp, argv[2]);
   252         -    } else if (c == 'w'  && strncmp(argv[1], "write", length) == 0) {
   253         -        if (3 != argc) {
   254         -            goto BAD_COMMAND;
   255         -        }  else if (write_history(argv[2])) {
   256         -            Tcl_AppendResult(interp, "unable to write history to `",
          256  +                    Tcl_DoOneEvent(TCL_ALL_EVENTS);
          257  +            }
          258  +
          259  +            Tcl_DeleteFileHandler(0);
          260  +
          261  +            switch (tclrl_state) {
          262  +
          263  +                case LINE_COMPLETE:
          264  +
          265  +                    return TCL_OK;
          266  +                    /* NOTREACHED */
          267  +                    break;
          268  +
          269  +                case LINE_EOF:
          270  +                    if (tclrl_eof_string)
          271  +                        return Tcl_Eval(interp, tclrl_eof_string);
          272  +                    else
          273  +                        return TCL_OK;
          274  +                    /* NOTREACHED */
          275  +                    break;
          276  +
          277  +                default:
          278  +                    return tclrl_state;
          279  +                    /* NOTREACHED */
          280  +                    break;
          281  +            }
          282  +            break;
          283  +
          284  +        case TCLRL_INITIALIZE:
          285  +            if (3 != argc) {
          286  +                Tcl_WrongNumArgs(interp, 2, objv, "historyfile");
          287  +                return TCL_ERROR;
          288  +            } else {
          289  +                return TclReadlineInitialize(interp, argv[2]);
          290  +            }
          291  +            break;
          292  +
          293  +        case TCLRL_WRITE:
          294  +            if (3 != argc) {
          295  +                Tcl_WrongNumArgs(interp, 2, objv, "historyfile");
          296  +                return TCL_ERROR;
          297  +            }  else if (write_history(argv[2])) {
          298  +                Tcl_AppendResult(interp, "unable to write history to `",
   257    299                       argv[2], "'\n", (char*) NULL);
   258         -            return TCL_ERROR;
   259         -        }
   260         -        if (tclrl_history_length >= 0) {
   261         -            history_truncate_file(argv[2], tclrl_history_length);
   262         -        }
   263         -        return TCL_OK;
   264         -    } else if (c == 'a'  && strncmp(argv[1], "add", length) == 0) {
   265         -        if (3 != argc)
   266         -            goto BAD_COMMAND;
   267         -        else if (TclReadlineKnownCommands(argv[2], (int) 0, _CMD_SET))
   268         -            Tcl_AppendResult(interp, "unable to add command \"",
          300  +                return TCL_ERROR;
          301  +            }
          302  +            if (tclrl_history_length >= 0) {
          303  +                history_truncate_file(argv[2], tclrl_history_length);
          304  +            }
          305  +            return TCL_OK;
          306  +            break;
          307  +
          308  +        case TCLRL_ADD:
          309  +            if (3 != argc) {
          310  +                Tcl_WrongNumArgs(interp, 2, objv, "completerLine");
          311  +                return TCL_ERROR;
          312  +            } else if (TclReadlineKnownCommands(argv[2], (int) 0, _CMD_SET)) {
          313  +                Tcl_AppendResult(interp, "unable to add command \"",
   269    314                       argv[2], "\"\n", (char*) NULL);
   270         -    } else if (c == 'c'  && strncmp(argv[1], "complete", length) == 0) {
   271         -        if (3 != argc)
   272         -            goto BAD_COMMAND;
   273         -        else if (Tcl_CommandComplete(argv[2]))
   274         -            Tcl_AppendResult(interp, "1", (char*) NULL);
   275         -        else
   276         -            Tcl_AppendResult(interp, "0", (char*) NULL);
   277         -    } else if (c == 'c'  && strncmp(argv[1], "customcompleter", length) == 0) {
   278         -        if (3 != argc && 2 != argc)
   279         -            goto BAD_COMMAND;
   280         -        if (3 == argc) {
   281         -            if (tclrl_custom_completer)
   282         -                FREE(tclrl_custom_completer);
   283         -            if (!blank_line(argv[2]))
   284         -                tclrl_custom_completer = stripwhite(strdup(argv[2]));
   285         -        }
   286         -        Tcl_AppendResult(interp, tclrl_custom_completer, (char*) NULL);
   287         -    } else if (c == 'b'  && strncmp(argv[1], "builtincompleter", length) == 0) {
   288         -        int bool = tclrl_use_builtin_completer;
   289         -        if (3 != argc && 2 != argc)
   290         -            goto BAD_COMMAND;
   291         -        if (3 == argc) {
   292         -            if (TCL_OK != Tcl_GetBoolean(interp, argv[2], &bool)) {
   293         -                Tcl_AppendResult(interp,
   294         -                    "wrong # args: should be a boolean value.", (char*) NULL);
          315  +            }
          316  +            break;
          317  +
          318  +        case TCLRL_COMPLETE:
          319  +            if (3 != argc) {
          320  +                Tcl_WrongNumArgs(interp, 2, objv, "line");
   295    321                   return TCL_ERROR;
          322  +            } else if (Tcl_CommandComplete(argv[2])) {
          323  +                Tcl_AppendResult(interp, "1", (char*) NULL);
   296    324               } else {
   297         -                tclrl_use_builtin_completer = bool;
          325  +                Tcl_AppendResult(interp, "0", (char*) NULL);
          326  +            }
          327  +            break;
          328  +
          329  +        case TCLRL_CUSTOMCOMPLETER:
          330  +            if (argc > 3) {
          331  +                Tcl_WrongNumArgs(interp, 2, objv, "?scriptCompleter?");
          332  +                return TCL_ERROR;
          333  +            } else if (3 == argc) {
          334  +                if (tclrl_custom_completer)
          335  +                    FREE(tclrl_custom_completer);
          336  +                if (!blank_line(argv[2]))
          337  +                    tclrl_custom_completer = stripwhite(strdup(argv[2]));
          338  +            }
          339  +            Tcl_AppendResult(interp, tclrl_custom_completer, (char*) NULL);
          340  +            break;
          341  +
          342  +        case TCLRL_BUILTINCOMPLETER:
          343  +            if (argc > 3) {
          344  +                Tcl_WrongNumArgs(interp, 2, objv, "?boolean?");
          345  +                return TCL_ERROR;
          346  +            } else if (3 == argc) {
          347  +                int bool = tclrl_use_builtin_completer;
          348  +                if (TCL_OK != Tcl_GetBoolean(interp, argv[2], &bool)) {
          349  +                    Tcl_AppendResult(interp,
          350  +                        "wrong # args: should be a boolean value.",
          351  +                        (char*) NULL);
          352  +                    return TCL_ERROR;
          353  +                } else {
          354  +                    tclrl_use_builtin_completer = bool;
          355  +                }
          356  +            }
          357  +            Tcl_AppendResult(interp, tclrl_use_builtin_completer ? "1" : "0",
          358  +                (char*) NULL);
          359  +            break;
          360  +
          361  +        case TCLRL_EOFCHAR:
          362  +            if (argc > 3) {
          363  +                Tcl_WrongNumArgs(interp, 2, objv, "?script?");
          364  +                return TCL_ERROR;
          365  +            } else if (3 == argc) {
          366  +                if (tclrl_eof_string)
          367  +                    FREE(tclrl_eof_string);
          368  +                if (!blank_line(argv[2]))
          369  +                    tclrl_eof_string = stripwhite(strdup(argv[2]));
   298    370               }
   299         -        }
   300         -        Tcl_AppendResult(interp, tclrl_use_builtin_completer ? "1" : "0",
   301         -            (char*) NULL);
   302         -    } else if (c == 'e'  && strncmp(argv[1], "eofchar", length) == 0) {
   303         -        if (3 != argc && 2 != argc)
          371  +            Tcl_AppendResult(interp, tclrl_eof_string, (char*) NULL);
          372  +            break;
          373  +
          374  +        default:
   304    375               goto BAD_COMMAND;
   305         -        if (3 == argc) {
   306         -            if (tclrl_eof_string)
   307         -                FREE(tclrl_eof_string);
   308         -            if (!blank_line(argv[2]))
   309         -                tclrl_eof_string = stripwhite(strdup(argv[2]));
   310         -        }
   311         -        Tcl_AppendResult(interp, tclrl_eof_string, (char*) NULL);
   312         -    } else {
   313         -        goto BAD_COMMAND;
          376  +            /* NOTREACHED */
          377  +            break;
   314    378       }
   315    379   
   316    380       return TCL_OK;
   317    381   
   318    382   BAD_COMMAND:
   319    383       Tcl_AppendResult(interp,
   320    384           "wrong # args: should be \"readline option ?arg ...?\"",
................................................................................
   323    387   
   324    388   }
   325    389   
   326    390   void
   327    391   TclReadlineReadHandler(ClientData clientData, int mask)
   328    392   {
   329    393       if (mask & TCL_READABLE) {
   330         -        rl_callback_read_char();
          394  +#ifdef EXECUTING_MACRO_HACK
          395  +        do {
          396  +#endif
          397  +            rl_callback_read_char();
   331    398   #ifdef EXECUTING_MACRO_HACK
   332         -        /**
   333         -         * check, if we're inside a macro and
   334         -         * if so, read all macro characters.
   335         -         */
   336         -        while (_rl_executing_macro) {
   337         -            rl_callback_read_char();
   338         -        }
          399  +            /**
          400  +             * check, if we're inside a macro and
          401  +             * if so, read all macro characters
          402  +             * until the next eol.
          403  +             */
          404  +        } while (_rl_executing_macro && !TclReadlineLineComplete());
   339    405   #endif
   340    406       }
   341    407   }
   342    408   
   343    409   void
   344    410   TclReadlineLineCompleteHandler(char* ptr)
   345    411   {
   346         -#if 1
   347    412       if (!ptr) { /* <c-d> */
   348         -        tclrl_line_complete = LINE_EOF;
   349         -        rl_callback_handler_remove();
   350         -    } else if (*ptr) {
   351         -        tclrl_line_complete = LINE_COMPLETE;
   352         -        rl_callback_handler_remove();
   353         -        tclrl_line = ptr;
   354         -    }
          413  +
          414  +        TclReadlineTerminate(LINE_EOF);
          415  +
          416  +    } else {
          417  +
          418  +        /**
          419  +         * From version 0.9.3 upwards, all lines are
          420  +         * returned, even empty lines. (Only non-empty
          421  +         * lines are stuffed in readline's history.)
          422  +         * The calling script is responsible for handling
          423  +         * empty strings.
          424  +         */
          425  +
          426  +        char* expansion = (char*) NULL;
          427  +        int status = history_expand(ptr, &expansion);
          428  +
          429  +        if (status >= 1) {
          430  +#if 0
          431  +            Tcl_Channel channel = Tcl_MakeFileChannel(stdout, TCL_WRITABLE);
          432  +            /* Tcl_RegisterChannel(interp, channel); */
          433  +            (void) Tcl_WriteChars(channel, expansion, -1);
          434  +            Tcl_Flush(channel);
          435  +            Tcl_Close(interp, channel);
   355    436   #else
   356         -    if (ptr && *ptr) {
   357         -        tclrl_line_complete = 1;
   358         -        rl_callback_handler_remove();
   359         -        tclrl_line = ptr;
   360         -    }
          437  +            /* TODO: make this a valid tcl output */
          438  +            printf("%s\n", expansion);
          439  +#endif
          440  +        } else if (-1 == status) {
          441  +            Tcl_AppendResult
          442  +                (tclrl_interp, "error in history expansion\n", (char*) NULL);
          443  +            TclReadlineTerminate(TCL_ERROR);
          444  +        }
          445  +        /**
          446  +         * TODO: status == 2 ...
          447  +         */
          448  +
          449  +        Tcl_AppendResult(tclrl_interp, expansion, (char*) NULL);
          450  +
          451  +#ifdef EXECUTING_MACRO_HACK
          452  +        /**
          453  +         * don't stuff macro lines
          454  +         * into readline's history.
          455  +         */
          456  +        if(!_rl_executing_macro) {
          457  +#endif
          458  +            /**
          459  +             * don't stuff empty lines
          460  +             * into readline's history.
          461  +             * don't stuff twice the same
          462  +             * line into readline's history.
          463  +             */
          464  +            if (expansion && *expansion && (!tclrl_last_line ||
          465  +                strcmp(tclrl_last_line, expansion))) {
          466  +                add_history(expansion);
          467  +            }
          468  +            if (tclrl_last_line)
          469  +                free(tclrl_last_line);
          470  +            tclrl_last_line = strdup(expansion);
          471  +#ifdef EXECUTING_MACRO_HACK
          472  +        }
   361    473   #endif
          474  +        /**
          475  +         * tell the calling routines to terminate.
          476  +         */
          477  +        TclReadlineTerminate(LINE_COMPLETE);
          478  +        FREE(ptr);
          479  +        FREE(expansion);
          480  +    }
   362    481   }
   363    482   
   364    483   int
   365    484   Tclreadline_SafeInit(Tcl_Interp *interp)
   366    485   {
   367    486       return Tclreadline_Init(interp);
   368    487   }
................................................................................
   398    517       return Tcl_PkgProvide(interp, "tclreadline", TCLRL_VERSION);
   399    518   }
   400    519   
   401    520   int
   402    521   TclReadlineInitialize(Tcl_Interp* interp, char* historyfile)
   403    522   {
   404    523       rl_readline_name = "tclreadline";
   405         -    //    rl_special_prefixes = "${\"[";
          524  +    /*    rl_special_prefixes = "${\"["; */
   406    525       rl_special_prefixes = "$";
   407    526       /**
   408    527        * default is " \t\n\"\\'`@$><=;|&{("
   409    528        * removed "(" <-- arrays
   410    529        * removed "{" <-- `${' variables 
   411    530        * removed "<" <-- completion lists with < ... >
   412    531        * added "[]"
................................................................................
   414    533        */
   415    534       /* 11.Sep rl_basic_word_break_characters = " \t\n\"\\@$}=;|&[]"; */
   416    535       /* besser (11. Sept) 2. (removed \") */
   417    536       /* rl_basic_word_break_characters = " \t\n\\@$}=;|&[]"; */
   418    537       /* besser (11. Sept) 3. (removed }) */
   419    538       rl_basic_word_break_characters = " \t\n\\@$=;|&[]";
   420    539   #if 0
   421         -    rl_basic_quote_characters = "\"{"; // XXX ??? XXX
          540  +    rl_basic_quote_characters = "\"{"; /* XXX ??? XXX */
   422    541       rl_completer_quote_characters = "\"";
   423    542   #endif
   424    543       /*
   425    544       rl_filename_quote_characters
   426    545       = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   427    546   
   428    547       rl_filename_quoting_function
................................................................................
   492    611       }
   493    612   
   494    613       if (tclrl_custom_completer) {
   495    614           char start_s[BUFSIZ], end_s[BUFSIZ];
   496    615           Tcl_Obj* obj;
   497    616           Tcl_Obj** objv;
   498    617           int objc;
          618  +        int state;
   499    619           char* quoted_text = TclReadlineQuote(text, "$[]{}\"");
   500    620           char* quoted_rl_line_buffer
   501    621               = TclReadlineQuote(rl_line_buffer, "$[]{}\"");
   502    622           sprintf(start_s, "%d", start);
   503    623           sprintf(end_s, "%d", end);
   504    624           Tcl_ResetResult(tclrl_interp); /* clear result space */
   505         -        tclrl_state = Tcl_VarEval(tclrl_interp, tclrl_custom_completer,
          625  +        state = Tcl_VarEval(tclrl_interp, tclrl_custom_completer,
   506    626               " \"", quoted_text, "\" ", start_s, " ", end_s,
   507    627               " \"", quoted_rl_line_buffer, "\"", (char*) NULL);
   508    628           FREE(quoted_text);
   509    629           FREE(quoted_rl_line_buffer);
   510         -        if (TCL_OK != tclrl_state) {
   511         -            rl_callback_handler_remove();
          630  +        if (TCL_OK != state) {
   512    631               Tcl_AppendResult (tclrl_interp, " `", tclrl_custom_completer,
   513    632                   " \"", quoted_text, "\" ", start_s, " ", end_s,
   514    633                   " \"", quoted_rl_line_buffer, "\"' failed.", (char*) NULL);
          634  +            TclReadlineTerminate(state);
   515    635               return matches;
   516    636           }
   517    637           obj = Tcl_GetObjResult(tclrl_interp);
   518    638           status = Tcl_ListObjGetElements(tclrl_interp, obj, &objc, &objv);
   519    639           if (TCL_OK != status)
   520    640               return matches;
   521    641   

Modified tclreadlineCompleter.tcl from [6becbaf62d] to [db38bf929f].

     1      1   #!/usr/locanl/bin/tclsh
     2      2   # FILE: "/home/joze/src/tclreadline/tclreadlineCompleter.tcl"
     3         -# LAST MODIFICATION: "Mon Sep 13 02:21:21 1999 (joze)"
            3  +# LAST MODIFICATION: "Tue Sep 14 01:55:17 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   #
................................................................................
   143    143       }
   144    144   }
   145    145   
   146    146   #**
   147    147   # build a list hosts from the /etc/hosts file.
   148    148   # this is only done once. This is sort of a
   149    149   # dirty hack, /etc/hosts is hardcoded ...
          150  +# But on the other side, if the user supplies
          151  +# a valid host table in tclreadline::hosts
          152  +# before entering the event loop, this proc
          153  +# will return this list.
   150    154   # 
   151    155   proc HostList {} {
   152    156       # read the host table only once.
   153    157       #
   154    158       variable hosts
   155    159       if {![info exists hosts]} {
   156    160           catch {
   157         -            set id [open /etc/hosts r]
   158    161               set hosts ""
          162  +            set id [open /etc/hosts r]
   159    163               if {0 != ${id}} {
   160    164                   while {-1 != [gets ${id} line]} {
   161    165                       regsub {#.*} ${line} {} line
   162    166                       if {[llength ${line}] >= 2} {
   163    167                           lappend hosts [lindex ${line} 1]
   164    168                       }
   165    169                   }
................................................................................
   203    207       foreach word $lst {
   204    208           if {[string match ${text}* ${word}]} {
   205    209               lappend result ${word}
   206    210           }
   207    211       }
   208    212       return [string trim $result]
   209    213   }
          214  +
          215  +#**
          216  +# invoke cmd with a (hopefully) invalid string and
          217  +# parse the error message to get an option list.
          218  +#
          219  +# @param cmd
          220  +# @return list of options for cmd
          221  +# @date Sep-14-1999
          222  +#
          223  +proc TrySubCmds {cmd} {
          224  +    set trystring ____
          225  +    set result ""
          226  +    if [catch {set result [${cmd} ${trystring}]} msg] {
          227  +        if {[regexp {bad *option.*____.*: *must *be( .*$)} ${msg} all raw]} {
          228  +            regsub -all -- , ${raw} { } raw
          229  +            set len [llength ${raw}]
          230  +            set len_2 [expr ${len} - 2]
          231  +            for {set i 0} {${i} < ${len}} {incr i} {
          232  +                set word [lindex ${raw} ${i}]
          233  +                if {"or" != ${word} && ${i} != ${len_2}} {
          234  +                    lappend result ${word}
          235  +                }
          236  +
          237  +            }
          238  +        } else {
          239  +            # check, if it's a blt error msg ...
          240  +            #
          241  +            set msglst [split ${msg} \n]
          242  +            foreach line ${msglst} {
          243  +                if {[regexp "${cmd}\[ \t\]\+\(\[^ \t\]*\)\[^:\]*$" \
          244  +                    ${line} all sub]} {
          245  +                    lappend result [list ${sub}]
          246  +                }
          247  +            }
          248  +        }
          249  +    }
          250  +    return ${result}
          251  +}
   210    252   
   211    253   proc FirstNonOption {line} {
   212    254       set expr_pos 1
   213    255       foreach word [lrange ${line} 1 end] {; # 0 is the command itself
   214    256           if {"-" != [string index ${word} 0]} {
   215    257               break
   216    258           } else {
................................................................................
   655    697       return [CommandCompletion ${cmd} procs]
   656    698   }
   657    699   
   658    700   proc CommandsOnlyCompletion {cmd} {
   659    701       return [CommandCompletion ${cmd} commands]
   660    702   }
   661    703   
   662         -proc CommandCompletion {cmd {action both} {spc ::} {pre UNDEFINED}} {
          704  +proc CommandCompletion {cmd {action both} {spc ::}} {
          705  +    # get the leading colons in `cmd'.
          706  +    regexp {^:*} ${cmd} pre
          707  +    return [CommandCompletionWithPre $cmd $action $spc $pre]
          708  +}
          709  +
          710  +proc CommandCompletionWithPre {cmd action spc pre} {
   663    711       # puts stderr "(CommandCompletion) cmd=|$cmd|"
   664    712       # puts stderr "(CommandCompletion) action=|$action|"
   665    713       # puts stderr "(CommandCompletion) spc=|$spc|"
   666    714   
   667         -    # get the leading colons in `cmd'.
   668         -    if {"UNDEFINED" == $pre} {
   669         -        regexp {^:*} ${cmd} pre
   670         -    }
   671         -    # puts stderr \npre=|$pre|
   672         -
   673    715       set cmd [StripPrefix ${cmd}]
   674    716       set quali [namespace qualifiers ${cmd}]
   675    717       if {[string length ${quali}]} {
   676    718           # puts stderr \nquali=|$quali|
   677         -        set matches [CommandCompletion \
          719  +        set matches [CommandCompletionWithPre \
   678    720           [namespace tail ${cmd}] ${action} ${spc}${quali} ${pre}]
   679    721           # puts stderr \nmatches1=|$matches|
   680    722           return $matches
   681    723       }
   682    724       set cmd [string trim ${cmd}]*
   683    725       # puts stderr \ncmd=|$cmd|\n
   684    726       if {"procs" != ${action}} {
................................................................................
   695    737           set commands ""
   696    738       }
   697    739       if {"commands" != ${action}} {
   698    740           set all_procs [namespace eval $spc [list info procs ${cmd}]]
   699    741           # puts stderr procs=|$procs|
   700    742           set procs ""
   701    743           foreach proc $all_procs {
   702         -            if {[namespace eval $spc [list namespace origin $command]] == \
   703         -                [namespace eval $spc [list namespace which $command]]} {
   704         -                lappend procs $command
          744  +            if {[namespace eval $spc [list namespace origin $proc]] == \
          745  +                [namespace eval $spc [list namespace which $proc]]} {
          746  +                lappend procs $proc
   705    747               }
   706    748           }
   707    749       } else {
   708    750           set procs ""
   709    751       }
   710    752       set matches [namespace eval $spc concat ${commands} ${procs}]
   711    753       set namespaces [namespace children $spc ${cmd}]
   712    754   
   713    755       if {![llength ${matches}] && 1 == [llength ${namespaces}]} {
   714         -        set matches [CommandCompletion {} ${action} ${namespaces} ${pre}]
          756  +        set matches [CommandCompletionWithPre {} ${action} ${namespaces} ${pre}]
   715    757           # puts stderr \nmatches=|$matches|
   716    758           return $matches
   717    759       }
   718    760   
   719    761       # make `namespaces' having exactly
   720    762       # the same number of colons as `cmd'.
   721    763       #
................................................................................
   828    870       # [SplitLine] --> {1 " put $b"} == sub
   829    871       # new_start = [lindex $sub 0] == 1
   830    872       # new_end   = [expr $end - ($start - $new_start)] == 4
   831    873       # new_part  == $part == put
   832    874       # new_line  = [lindex $sub 1] == " put $b"
   833    875       # 
   834    876       } elseif {"" != [set sub [SplitLine $start $line]]} {
          877  +
   835    878           set new_start [lindex $sub 0]
   836    879           set new_end [expr $end - ($start - $new_start)]
   837    880           set new_line [lindex $sub 1]
   838    881           # puts stderr "(SplitLine) $new_start $new_end $new_line"
   839    882           return [ScriptCompleter $part $new_start $new_end $new_line]
          883  +
   840    884       } elseif {0 == [set pos [PartPosition part start end line]]} {
          885  +
   841    886           # puts stderr "(PartPosition) $part $start $end $line"
   842    887           set all [CommandCompletion ${part}]
   843    888           # puts stderr "(ScriptCompleter) all=$all"
   844    889           #puts \nmatches=$matches\n
   845    890           # return [Format $all $part]
   846    891           return [TryFromList $part $all]
          892  +
   847    893       } else {
   848    894   
   849    895           # try to use $pos further ...
   850    896           # puts stderr |$line|
   851    897           #
   852    898           if {"." == [string index [string trim ${line}] 0]} {
   853    899               set alias WIDGET
................................................................................
   905    951                       error [list error during evaluation of `complete(${cmd})']
   906    952                   }
   907    953                   # puts stderr \nscript_result=|${script_result}|
   908    954                   return ${script_result}
   909    955               }
   910    956               # set namespc ""; # no qualifiers for tclreadline_complete_unknown
   911    957           }
          958  +
          959  +        # as we've reached here no valid specific completer
          960  +        # was found. Check, if it's a proc and return the
          961  +        # arguments.
          962  +        #
          963  +        if {[string length [uplevel [info level] info proc $alias]]} {
          964  +            set args [uplevel [info level] info args $alias]
          965  +            set arg [lindex $args [expr $pos - 1]]
          966  +            if {"" != $arg} {
          967  +                if {[uplevel [info level] info default $alias $arg junk]} {
          968  +                    return [DisplayHints ?$arg?]
          969  +                } else {
          970  +                    return [DisplayHints <$arg>]
          971  +                }
          972  +            }
          973  +        }
          974  +
          975  +
          976  +        # Ok, also no proc. Try to do the same as for widgets now:
          977  +        # try to get at least the first option from an error output.
          978  +        #
          979  +        switch -- $pos {
          980  +            1 {
          981  +                set cmds [TrySubCmds ${alias}]
          982  +                if {[llength ${cmds}]} {
          983  +                    return [TryFromList ${part} ${cmds}]
          984  +                }
          985  +            }
          986  +        }
          987  +
          988  +
   912    989           # no specific command completer found.
   913    990           return ""
   914    991       }
   915    992       error "{NOTREACHED (this is probably an error)}"
   916    993   }
   917    994   
   918    995   
................................................................................
  1049   1126       switch -- $pos {
  1050   1127           1 { return [DisplayHints <script>] }
  1051   1128           2 { return [DisplayHints ?varName?] }
  1052   1129       }
  1053   1130       return ""
  1054   1131   }
  1055   1132   
  1056         -# proc complete(cd) {text start end line pos mod} {
  1057         -# }
         1133  +proc complete(cd) {text start end line pos mod} {
         1134  +    return ""
         1135  +}
  1058   1136   
  1059   1137   proc complete(clock) {text start end line pos mod} {
  1060   1138       set cmd [Lindex $line 1]
  1061   1139       switch -- $pos {
  1062   1140           1 {
  1063   1141               return [CompleteFromList $text {clicks format scan seconds}]
  1064   1142           }
................................................................................
  2229   2307                   names {}
  2230   2308                   unknown { return [DisplayHints ?command?] }
  2231   2309                   vcompare -
  2232   2310                   vsatisfies { return [DisplayHints <version1>] }
  2233   2311               }
  2234   2312           }
  2235   2313           3 {
         2314  +            set versions ""
         2315  +            catch [list set versions [package versions [Lindex $line 2]]]
  2236   2316               switch -- $cmd {
  2237   2317                   forget {}
  2238         -                ifneeded { return [DisplayHints <version>] }
  2239         -                provide { return [DisplayHints ?version?] }
         2318  +                ifneeded {
         2319  +                    if {"" != $versions} {
         2320  +                        return [CompleteFromList ${text} $versions]
         2321  +                    } else {
         2322  +                        return [DisplayHints <version>]
         2323  +                    }
         2324  +                }
         2325  +                provide {
         2326  +                    if {"" != $versions} {
         2327  +                        return [CompleteFromList ${text} $versions]
         2328  +                    } else {
         2329  +                        return [DisplayHints ?version?]
         2330  +                    }
         2331  +                }
  2240   2332                   versions {}
  2241   2333                   present -
  2242   2334                   require {
  2243   2335                       if {"-exact" == [PreviousWord ${start} ${line}]} {
  2244   2336                           return [CompleteFromList ${mod} [package names]]
  2245   2337                       } else {
  2246         -                        return [DisplayHints ?version?]
         2338  +                        if {"" != $versions} {
         2339  +                            return [CompleteFromList ${text} $versions]
         2340  +                        } else {
         2341  +                            return [DisplayHints ?version?]
         2342  +                        }
  2247   2343                       }
  2248   2344                   }
  2249   2345                   names {}
  2250   2346                   unknown {}
  2251   2347                   vcompare -
  2252   2348                   vsatisfies { return [DisplayHints <version2>] }
  2253   2349               }
................................................................................
  2769   2865                   }
  2770   2866               }
  2771   2867           }
  2772   2868       }
  2773   2869       return ""
  2774   2870   }
  2775   2871   
         2872  +# --- TCLREADLINE PACKAGE ---
         2873  +
         2874  +# create a tclreadline namespace inside
         2875  +# tclreadline and import some commands.
         2876  +#
         2877  +namespace eval tclreadline {
         2878  +    catch {
         2879  +        namespace import \
         2880  +        ::tclreadline::DisplayHints \
         2881  +        ::tclreadline::CompleteFromList \
         2882  +        ::tclreadline::Lindex
         2883  +    }
         2884  +}
         2885  +
         2886  +proc tclreadline::complete(readline) {text start end line pos mod} {
         2887  +    set cmd [Lindex $line 1]
         2888  +    switch -- $pos {
         2889  +        1 { return [CompleteFromList ${text} {
         2890  +            read initialize write add complete
         2891  +            customcompleter builtincompleter eofchar}]
         2892  +        }
         2893  +        2 {
         2894  +            switch -- $cmd {
         2895  +                read {}
         2896  +                initialize {}
         2897  +                write {}
         2898  +                add { return [DisplayHints <completerLine>] }
         2899  +                completer { return [DisplayHints <line>] }
         2900  +                customcompleter { return [DisplayHints ?scriptCompleter?] }
         2901  +                builtincompleter { return [DisplayHints ?boolean?] }
         2902  +                eofchar { return [DisplayHints ?script?] }
         2903  +            }
         2904  +        }
         2905  +    }
         2906  +    return ""
         2907  +}
         2908  +
         2909  +# --- END OF TCLREADLINE PACKAGE ---
         2910  +
  2776   2911   proc complete(tell) {text start end line pos mod} {
  2777   2912       switch -- $pos {
  2778         -        1 { return [ChannelId ${mod}] }
         2913  +        1 { return [ChannelId ${text}] }
  2779   2914       }
  2780   2915       return ""
  2781   2916   }
  2782   2917   
  2783   2918   proc complete(time) {text start end line pos mod} {
  2784   2919       switch -- $pos {
  2785   2920           1 { return [DisplayHints <script>] }
................................................................................
  2926   3061       return ""
  2927   3062   }
  2928   3063   
  2929   3064   # -------------------------------------
  2930   3065   #                  TK
  2931   3066   # -------------------------------------
  2932   3067   
  2933         -# generic widget configuration
         3068  +# GENERIC WIDGET CONFIGURATION
  2934   3069   
  2935         -proc TrySubCmds {cmd} {
  2936         -    set trystring ____
  2937         -    set result ""
  2938         -    if [catch {set result [${cmd} ${trystring}]} msg] {
  2939         -        if {[regexp {bad *option.*____.*: *must *be( .*$)} ${msg} all raw]} {
  2940         -            regsub -all -- , ${raw} { } raw
  2941         -            set len [llength ${raw}]
  2942         -            set len_2 [expr ${len} - 2]
  2943         -            for {set i 0} {${i} < ${len}} {incr i} {
  2944         -                set word [lindex ${raw} ${i}]
  2945         -                if {"or" != ${word} && ${i} != ${len_2}} {
  2946         -                    lappend result ${word}
  2947         -                }
  2948         -
  2949         -            }
  2950         -        } else {
  2951         -            # check, if it's a blt error msg ...
  2952         -            #
  2953         -            set msglst [split ${msg} \n]
  2954         -            foreach line ${msglst} {
  2955         -                if {[regexp "${cmd}\[ \t\]\+\(\[^ \t\]*\)\[^:\]*$" \
  2956         -                    ${line} all sub]} {
  2957         -                    lappend result [list ${sub}]
  2958         -                }
  2959         -            }
  2960         -        }
  2961         -    }
  2962         -    return ${result}
  2963         -}
  2964         -
  2965         -proc WidgetList {pattern} {
         3070  +proc WidgetChildren {pattern} {
  2966   3071       regsub {^([^\.])} ${pattern} {\.\1} pattern
         3072  +    if {![string length ${pattern}]} {
         3073  +        set pattern .
         3074  +    }
  2967   3075       if {[winfo exists ${pattern}]} {
  2968   3076           return [winfo children ${pattern}]
  2969   3077       } else {
  2970   3078           regsub {.[^.]*$} $pattern {} pattern
  2971   3079           if {[winfo exists ${pattern}]} {
  2972   3080               return [winfo children ${pattern}]
  2973   3081           } else {
  2974   3082               return ""
  2975   3083           }
  2976   3084       }
  2977   3085   }
         3086  +
         3087  +proc WidgetDescendants {pattern} {
         3088  +    set tree [WidgetChildren ${pattern}]
         3089  +    foreach widget $tree {
         3090  +        append tree " [WidgetDescendants $widget]"
         3091  +    }
         3092  +    return $tree
         3093  +}
  2978   3094   
  2979   3095   proc complete(WIDGET) {text start end line pos mod} {
  2980   3096       set widget [lindex ${line} 0]
  2981   3097       set cmd [lindex ${line} 1]
  2982   3098   
  2983   3099       # first we build an option table
  2984   3100       #
................................................................................
  2988   3104       foreach optline ${option_table} {
  2989   3105           if {5 != [llength ${optline}]} continue else {
  2990   3106               lappend options(switches) [lindex ${optline} 0]
  2991   3107               lappend options(value)    [lindex ${optline} 4]
  2992   3108           }
  2993   3109       }
  2994   3110   
  2995         -    if {1 >= ${pos}} {
  2996         -        set cmds [TrySubCmds ${widget}]
  2997         -        if {[llength ${cmds}]} {
  2998         -            return [TryFromList ${mod} ${cmds}]
         3111  +    switch -- $pos {
         3112  +        1 {
         3113  +            set cmds [TrySubCmds ${widget}]
         3114  +            if {[llength ${cmds}]} {
         3115  +                return [TryFromList ${mod} ${cmds}]
         3116  +            }
  2999   3117           }
  3000         -    } elseif {2 <= ${pos} && 
  3001         -        ([string match ${cmd}* cget] || \
  3002         -         [string match ${cmd}* configure])} {
  3003         -        set prev [PreviousWord ${start} ${line}]
  3004         -        #puts \nprev=|$prev|
  3005         -        #puts switches=|$options(switches)|
  3006         -        #puts found=[lsearch -exact ${prev} $options(switches)]
  3007         -        if {-1 != [set found [lsearch -exact $options(switches) ${prev}]]} {
  3008         -            if {![llength ${mod}]} {
  3009         -                return [list "[lindex $options(value) ${found}]"]
         3118  +        2 {
         3119  +            if {([string match ${cmd}* cget] || \
         3120  +                [string match ${cmd}* configure])
         3121  +            } {
         3122  +                set prev [PreviousWord ${start} ${line}]
         3123  +                #puts \nprev=|$prev|
         3124  +                #puts switches=|$options(switches)|
         3125  +                #puts found=[lsearch -exact ${prev} $options(switches)]
         3126  +                if {-1 != [set found \
         3127  +                    [lsearch -exact $options(switches) ${prev}]]
         3128  +                } {
         3129  +                    if {![llength ${mod}]} {
         3130  +                        return [list "[lindex $options(value) ${found}]"]
         3131  +                    }
         3132  +                } else {
         3133  +                    return [TryFromList ${mod} $options(switches)]
         3134  +                }
  3010   3135               }
  3011         -        } else {
  3012         -            return [TryFromList ${mod} $options(switches)]
  3013   3136           }
  3014   3137       }
  3015   3138       return ""
  3016   3139   }
         3140  +
         3141  +# SPECIFIC TK COMMAND COMPLETERS
         3142  +
         3143  +proc complete(bell) {text start end line pos mod} {
         3144  +    switch -- $pos {
         3145  +        1 { return [CompleteFromList ${text} -displayof] }
         3146  +        2 {
         3147  +            if {"-displayof" == [PreviousWord ${start} ${line}]} {
         3148  +                return [CompleteFromList ${text} [WidgetDescendants ${text}]]
         3149  +            }
         3150  +        }
         3151  +    }
         3152  +}
  3017   3153   
  3018   3154   proc complete(winfo) {text start end line pos mod} {
  3019   3155       set cmd [lindex ${line} 1]
  3020         -    if {1 >= ${pos}} {
  3021         -        set cmds [TrySubCmds winfo]
  3022         -        if {[llength ${cmds}]} {
  3023         -            return [TryFromList ${mod} ${cmds}]
         3156  +    switch -- $pos {
         3157  +        1 {
         3158  +            set cmds [TrySubCmds winfo]
         3159  +            if {[llength ${cmds}]} {
         3160  +                return [TryFromList ${text} ${cmds}]
         3161  +            }
  3024   3162           }
  3025         -    } elseif {2 == ${pos}} {
  3026         -        return [TryFromList ${mod} [WidgetList ${mod}]]
         3163  +        2 {
         3164  +            return [TryFromList ${text} [WidgetChildren ${text}]]
         3165  +        }
  3027   3166       }
  3028   3167       return ""
  3029   3168   }
  3030   3169   
  3031   3170   }; # namespace tclreadline

Modified tclreadlineSetup.tcl.in from [602286f12e] to [026fd75a9a].

     1      1   #!/usr/locanl/bin/tclsh
     2         -# FILE: "/diska/home/joze/src/tclreadline/tclreadlineSetup.tcl.in"
     3         -# LAST MODIFICATION: "Wed Sep  8 18:09:57 1999 (joze)"
            2  +# FILE: "/home/joze/src/tclreadline/tclreadlineSetup.tcl.in"
            3  +# LAST MODIFICATION: "Mon Sep 13 23:44:55 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   #
................................................................................
    24     24   #
    25     25   # johannes@zellner.org
    26     26   # http://www.zellner.org/tclreadline/
    27     27   #
    28     28   # ================================================================== 
    29     29   
    30     30   
    31         -package provide tclreadline @TCLREADLINE_VERSION@
           31  +# package provide tclreadline @TCLREADLINE_VERSION@
           32  +package provide tclreadline 0.9
    32     33   
    33     34   proc unknown args {
    34     35   
    35     36       global auto_noexec auto_noload env unknown_pending tcl_interactive
    36     37       global errorCode errorInfo
    37     38   
    38     39       # Save the values of errorCode and errorInfo variables, since they
................................................................................
   294    295               } ::tclreadline::errorMsg]} {
   295    296                   puts stderr [list tclreadline::Loop: error. \
   296    297                   $::tclreadline::errorMsg]
   297    298                   continue
   298    299               }
   299    300   
   300    301               # Magnus Eriksson <magnus.eriksson@netinsight.se> proposed
   301         -            history add $LINE
          302  +            # to add the line also to tclsh's history.
          303  +            #
          304  +            # I decided to add only lines which are different from
          305  +            # the previous one to the history. This is different
          306  +            # from tcsh's behaviour, but I found it quite convenient
          307  +            # while using mshell on os9.
          308  +            #
          309  +            if {[string length $LINE] && [history event 0] != $LINE} {
          310  +                history add $LINE
          311  +            }
   302    312   
   303    313               if [catch {
   304    314                   set result [eval $LINE]
   305    315                   if {$result != "" && [tclreadline::Print]} {
   306    316                       puts $result
   307    317                   }
   308    318                   set result ""