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: |
3257fb6735879419a823e3c56da1b380 |
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
Modified tclreadline.c from [9394d14783] to [1096dacb0c].
1 2 3 | /* ================================================================== | | | | 1 2 3 4 5 6 7 8 9 10 11 12 | /* ================================================================== FILE: "/home/joze/src/tclreadline/tclreadline.c" LAST MODIFICATION: "Tue Sep 14 00:57:33 1999 (joze)" (C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org> $Id$ --- tclreadline -- gnu readline for tcl Copyright (C) 1999 Johannes Zellner |
︙ | ︙ | |||
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | /* * forward declarations. */ char* stripleft(char* in); char* stripright(char* in); char* stripwhite(char* in); char* TclReadlineQuote(char* text, char* quotechars); int TclReadlineCmd(ClientData clientData, Tcl_Interp* interp, int argc, char** argv); void TclReadlineReadHandler(ClientData clientData, int mask); void TclReadlineLineCompleteHandler(char* ptr); int Tclreadline_SafeInit(Tcl_Interp* interp); int Tclreadline_Init(Tcl_Interp* interp); int TclReadlineInitialize(Tcl_Interp* interp, char* historyfile); int blank_line(char* str); char** TclReadlineCompletion(char* text, int start, int end); char* TclReadline0generator(char* text, int state); char* TclReadlineKnownCommands(char* text, int state, int mode); int TclReadlineParse(char** args, int maxargs, char* buf); enum { | > > | | | < < > | 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 | /* * forward declarations. */ char* stripleft(char* in); char* stripright(char* in); char* stripwhite(char* in); int TclReadlineLineComplete(void); void TclReadlineTerminate(int state); char* TclReadlineQuote(char* text, char* quotechars); int TclReadlineCmd(ClientData clientData, Tcl_Interp* interp, int argc, char** argv); void TclReadlineReadHandler(ClientData clientData, int mask); void TclReadlineLineCompleteHandler(char* ptr); int Tclreadline_SafeInit(Tcl_Interp* interp); int Tclreadline_Init(Tcl_Interp* interp); int TclReadlineInitialize(Tcl_Interp* interp, char* historyfile); int blank_line(char* str); char** TclReadlineCompletion(char* text, int start, int end); char* TclReadline0generator(char* text, int state); char* TclReadlineKnownCommands(char* text, int state, int mode); int TclReadlineParse(char** args, int maxargs, char* buf); enum { LINE_PENDING = -1, LINE_EOF = (1 << 8), LINE_COMPLETE = (1 << 9) }; /** * global variables */ static int tclrl_state = TCL_OK; static char* tclrl_eof_string = (char*) NULL; static char* tclrl_custom_completer = (char*) NULL; static char* tclrl_last_line = (char*) NULL; static int tclrl_use_builtin_completer = 1; static int tclrl_history_length = -1; Tcl_Interp* tclrl_interp = (Tcl_Interp*) NULL; char* stripleft(char* in) |
︙ | ︙ | |||
137 138 139 140 141 142 143 144 145 146 147 148 149 150 | char* stripwhite(char* in) { stripleft(in); stripright(in); return in; } char* TclReadlineQuote(char* text, char* quotechars) { char* ptr; char* result_c; int i, len = strlen(quotechars); | > > > > > > > > > > > > > | 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | char* stripwhite(char* in) { stripleft(in); stripright(in); return in; } int TclReadlineLineComplete(void) { return !(tclrl_state == LINE_PENDING); } void TclReadlineTerminate(int state) { tclrl_state = state; rl_callback_handler_remove(); } char* TclReadlineQuote(char* text, char* quotechars) { char* ptr; char* result_c; int i, len = strlen(quotechars); |
︙ | ︙ | |||
162 163 164 165 166 167 168 | } result_c = strdup(Tcl_DStringValue(&result)); return result_c; } int TclReadlineCmd( | | | | | > > | > > > > > > > > > | | > | > > > > | > | | > > | | > > | < > > | | | > | > > | | | | | | | | | | | > > > > > > > > > > > > | | | | < | | | > > | | < < | < < < < | | < > > | < < < | > | > > | < < < | < < < | < < < < | < > > | | > > | > | < > > | | | | | | | | > | > | < > > | | > > | > | < > > | | | | > > | > | < > > | | | | | | | | | > | < > > | > | | | > | | | | | | | > | > | < > > | | | | | | | > | > | > > > > > | | | | > | | < < < | > | | | > > > > > > > | | > | > > > > > > > > > > | > > > > > > > | > | > > > > > > > > > > > > > > > > > | > > > | > > > > > > > | 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 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 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | } result_c = strdup(Tcl_DStringValue(&result)); return result_c; } int TclReadlineCmd( ClientData clientData, Tcl_Interp* interp, /* Current interpreter */ int argc, /* Number of arguments */ char** argv /* Argument strings */ ) { int i, obj_idx, status; Tcl_Obj** objv = (Tcl_Obj**) MALLOC((argc + 1) * sizeof(Tcl_Obj *)); static char *subCmds[] = { "read", "initialize", "write", "add", "complete", "customcompleter", "builtincompleter", "eofchar", (char *) NULL }; enum SubCmdIdx { TCLRL_READ, TCLRL_INITIALIZE, TCLRL_WRITE, TCLRL_ADD, TCLRL_COMPLETE, TCLRL_CUSTOMCOMPLETER, TCLRL_BUILTINCOMPLETER, TCLRL_EOFCHAR }; Tcl_ResetResult(interp); /* clear the result space */ for (i = 0; i < argc; i++) { Tcl_Obj* objPtr = Tcl_NewStringObj(argv[i], -1); Tcl_IncrRefCount(objPtr); objv[i] = objPtr; } objv[argc] = 0; /* terminate */ if (argc < 2) { Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?"); return TCL_ERROR; } status = Tcl_GetIndexFromObj (interp, objv[1], subCmds, "option", 0, (int *) &obj_idx); if (status != TCL_OK) { FREE(objv) return status; } switch (obj_idx) { case TCLRL_READ: rl_callback_handler_install(argc == 3 ? argv[2] : "%", TclReadlineLineCompleteHandler); Tcl_CreateFileHandler(0, TCL_READABLE, TclReadlineReadHandler, (ClientData) NULL); /** * Main Loop. * XXX each modification of the global variables * which terminates the main loop must call * rl_callback_handler_remove() to leave * readline in a defined state. XXX */ tclrl_state = LINE_PENDING; while (!TclReadlineLineComplete()) { #ifdef EXECUTING_MACRO_HACK /** * check first, if more characters are * available from _rl_executing_macro, * because Tcl_DoOneEvent() will (naturally) * not detect this `event'. */ if (_rl_executing_macro) TclReadlineReadHandler((ClientData) NULL, TCL_READABLE); else #endif Tcl_DoOneEvent(TCL_ALL_EVENTS); } Tcl_DeleteFileHandler(0); switch (tclrl_state) { case LINE_COMPLETE: return TCL_OK; /* NOTREACHED */ break; case LINE_EOF: if (tclrl_eof_string) return Tcl_Eval(interp, tclrl_eof_string); else return TCL_OK; /* NOTREACHED */ break; default: return tclrl_state; /* NOTREACHED */ break; } break; case TCLRL_INITIALIZE: if (3 != argc) { Tcl_WrongNumArgs(interp, 2, objv, "historyfile"); return TCL_ERROR; } else { return TclReadlineInitialize(interp, argv[2]); } break; case TCLRL_WRITE: if (3 != argc) { Tcl_WrongNumArgs(interp, 2, objv, "historyfile"); return TCL_ERROR; } else if (write_history(argv[2])) { Tcl_AppendResult(interp, "unable to write history to `", argv[2], "'\n", (char*) NULL); return TCL_ERROR; } if (tclrl_history_length >= 0) { history_truncate_file(argv[2], tclrl_history_length); } return TCL_OK; break; case TCLRL_ADD: if (3 != argc) { Tcl_WrongNumArgs(interp, 2, objv, "completerLine"); return TCL_ERROR; } else if (TclReadlineKnownCommands(argv[2], (int) 0, _CMD_SET)) { Tcl_AppendResult(interp, "unable to add command \"", argv[2], "\"\n", (char*) NULL); } break; case TCLRL_COMPLETE: if (3 != argc) { Tcl_WrongNumArgs(interp, 2, objv, "line"); return TCL_ERROR; } else if (Tcl_CommandComplete(argv[2])) { Tcl_AppendResult(interp, "1", (char*) NULL); } else { Tcl_AppendResult(interp, "0", (char*) NULL); } break; case TCLRL_CUSTOMCOMPLETER: if (argc > 3) { Tcl_WrongNumArgs(interp, 2, objv, "?scriptCompleter?"); return TCL_ERROR; } else if (3 == argc) { if (tclrl_custom_completer) FREE(tclrl_custom_completer); if (!blank_line(argv[2])) tclrl_custom_completer = stripwhite(strdup(argv[2])); } Tcl_AppendResult(interp, tclrl_custom_completer, (char*) NULL); break; case TCLRL_BUILTINCOMPLETER: if (argc > 3) { Tcl_WrongNumArgs(interp, 2, objv, "?boolean?"); return TCL_ERROR; } else if (3 == argc) { int bool = tclrl_use_builtin_completer; if (TCL_OK != Tcl_GetBoolean(interp, argv[2], &bool)) { Tcl_AppendResult(interp, "wrong # args: should be a boolean value.", (char*) NULL); return TCL_ERROR; } else { tclrl_use_builtin_completer = bool; } } Tcl_AppendResult(interp, tclrl_use_builtin_completer ? "1" : "0", (char*) NULL); break; case TCLRL_EOFCHAR: if (argc > 3) { Tcl_WrongNumArgs(interp, 2, objv, "?script?"); return TCL_ERROR; } else if (3 == argc) { if (tclrl_eof_string) FREE(tclrl_eof_string); if (!blank_line(argv[2])) tclrl_eof_string = stripwhite(strdup(argv[2])); } Tcl_AppendResult(interp, tclrl_eof_string, (char*) NULL); break; default: goto BAD_COMMAND; /* NOTREACHED */ break; } return TCL_OK; BAD_COMMAND: Tcl_AppendResult(interp, "wrong # args: should be \"readline option ?arg ...?\"", (char*) NULL); return TCL_ERROR; } void TclReadlineReadHandler(ClientData clientData, int mask) { if (mask & TCL_READABLE) { #ifdef EXECUTING_MACRO_HACK do { #endif rl_callback_read_char(); #ifdef EXECUTING_MACRO_HACK /** * check, if we're inside a macro and * if so, read all macro characters * until the next eol. */ } while (_rl_executing_macro && !TclReadlineLineComplete()); #endif } } void TclReadlineLineCompleteHandler(char* ptr) { if (!ptr) { /* <c-d> */ TclReadlineTerminate(LINE_EOF); } else { /** * From version 0.9.3 upwards, all lines are * returned, even empty lines. (Only non-empty * lines are stuffed in readline's history.) * The calling script is responsible for handling * empty strings. */ char* expansion = (char*) NULL; int status = history_expand(ptr, &expansion); if (status >= 1) { #if 0 Tcl_Channel channel = Tcl_MakeFileChannel(stdout, TCL_WRITABLE); /* Tcl_RegisterChannel(interp, channel); */ (void) Tcl_WriteChars(channel, expansion, -1); Tcl_Flush(channel); Tcl_Close(interp, channel); #else /* TODO: make this a valid tcl output */ printf("%s\n", expansion); #endif } else if (-1 == status) { Tcl_AppendResult (tclrl_interp, "error in history expansion\n", (char*) NULL); TclReadlineTerminate(TCL_ERROR); } /** * TODO: status == 2 ... */ Tcl_AppendResult(tclrl_interp, expansion, (char*) NULL); #ifdef EXECUTING_MACRO_HACK /** * don't stuff macro lines * into readline's history. */ if(!_rl_executing_macro) { #endif /** * don't stuff empty lines * into readline's history. * don't stuff twice the same * line into readline's history. */ if (expansion && *expansion && (!tclrl_last_line || strcmp(tclrl_last_line, expansion))) { add_history(expansion); } if (tclrl_last_line) free(tclrl_last_line); tclrl_last_line = strdup(expansion); #ifdef EXECUTING_MACRO_HACK } #endif /** * tell the calling routines to terminate. */ TclReadlineTerminate(LINE_COMPLETE); FREE(ptr); FREE(expansion); } } int Tclreadline_SafeInit(Tcl_Interp *interp) { return Tclreadline_Init(interp); } |
︙ | ︙ | |||
398 399 400 401 402 403 404 | return Tcl_PkgProvide(interp, "tclreadline", TCLRL_VERSION); } int TclReadlineInitialize(Tcl_Interp* interp, char* historyfile) { rl_readline_name = "tclreadline"; | | | | 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 | return Tcl_PkgProvide(interp, "tclreadline", TCLRL_VERSION); } int TclReadlineInitialize(Tcl_Interp* interp, char* historyfile) { rl_readline_name = "tclreadline"; /* rl_special_prefixes = "${\"["; */ rl_special_prefixes = "$"; /** * default is " \t\n\"\\'`@$><=;|&{(" * removed "(" <-- arrays * removed "{" <-- `${' variables * removed "<" <-- completion lists with < ... > * added "[]" * added "}" */ /* 11.Sep rl_basic_word_break_characters = " \t\n\"\\@$}=;|&[]"; */ /* besser (11. Sept) 2. (removed \") */ /* rl_basic_word_break_characters = " \t\n\\@$}=;|&[]"; */ /* besser (11. Sept) 3. (removed }) */ rl_basic_word_break_characters = " \t\n\\@$=;|&[]"; #if 0 rl_basic_quote_characters = "\"{"; /* XXX ??? XXX */ rl_completer_quote_characters = "\""; #endif /* rl_filename_quote_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; rl_filename_quoting_function |
︙ | ︙ | |||
492 493 494 495 496 497 498 499 500 501 502 503 504 | } if (tclrl_custom_completer) { char start_s[BUFSIZ], end_s[BUFSIZ]; Tcl_Obj* obj; Tcl_Obj** objv; int objc; char* quoted_text = TclReadlineQuote(text, "$[]{}\""); char* quoted_rl_line_buffer = TclReadlineQuote(rl_line_buffer, "$[]{}\""); sprintf(start_s, "%d", start); sprintf(end_s, "%d", end); Tcl_ResetResult(tclrl_interp); /* clear result space */ | > | | < > | 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 | } if (tclrl_custom_completer) { char start_s[BUFSIZ], end_s[BUFSIZ]; Tcl_Obj* obj; Tcl_Obj** objv; int objc; int state; char* quoted_text = TclReadlineQuote(text, "$[]{}\""); char* quoted_rl_line_buffer = TclReadlineQuote(rl_line_buffer, "$[]{}\""); sprintf(start_s, "%d", start); sprintf(end_s, "%d", end); Tcl_ResetResult(tclrl_interp); /* clear result space */ state = Tcl_VarEval(tclrl_interp, tclrl_custom_completer, " \"", quoted_text, "\" ", start_s, " ", end_s, " \"", quoted_rl_line_buffer, "\"", (char*) NULL); FREE(quoted_text); FREE(quoted_rl_line_buffer); if (TCL_OK != state) { Tcl_AppendResult (tclrl_interp, " `", tclrl_custom_completer, " \"", quoted_text, "\" ", start_s, " ", end_s, " \"", quoted_rl_line_buffer, "\"' failed.", (char*) NULL); TclReadlineTerminate(state); return matches; } obj = Tcl_GetObjResult(tclrl_interp); status = Tcl_ListObjGetElements(tclrl_interp, obj, &objc, &objv); if (TCL_OK != status) return matches; |
︙ | ︙ |
Modified tclreadlineCompleter.tcl from [6becbaf62d] to [db38bf929f].
1 2 | #!/usr/locanl/bin/tclsh # FILE: "/home/joze/src/tclreadline/tclreadlineCompleter.tcl" | | | 1 2 3 4 5 6 7 8 9 10 | #!/usr/locanl/bin/tclsh # FILE: "/home/joze/src/tclreadline/tclreadlineCompleter.tcl" # LAST MODIFICATION: "Tue Sep 14 01:55:17 1999 (joze)" # (C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org> # $Id$ # --- # # tclreadline -- gnu readline for tcl # Copyright (C) 1999 Johannes Zellner # |
︙ | ︙ | |||
143 144 145 146 147 148 149 150 151 152 153 154 155 156 | } } #** # build a list hosts from the /etc/hosts file. # this is only done once. This is sort of a # dirty hack, /etc/hosts is hardcoded ... # proc HostList {} { # read the host table only once. # variable hosts if {![info exists hosts]} { catch { | > > > > < > | 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | } } #** # build a list hosts from the /etc/hosts file. # this is only done once. This is sort of a # dirty hack, /etc/hosts is hardcoded ... # But on the other side, if the user supplies # a valid host table in tclreadline::hosts # before entering the event loop, this proc # will return this list. # proc HostList {} { # 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] } } |
︙ | ︙ | |||
203 204 205 206 207 208 209 210 211 212 213 214 215 216 | foreach word $lst { if {[string match ${text}* ${word}]} { lappend result ${word} } } return [string trim $result] } proc FirstNonOption {line} { set expr_pos 1 foreach word [lrange ${line} 1 end] {; # 0 is the command itself if {"-" != [string index ${word} 0]} { break } else { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 252 253 254 255 256 257 258 | foreach word $lst { 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. # # @param cmd # @return list of options for cmd # @date Sep-14-1999 # proc TrySubCmds {cmd} { set trystring ____ set result "" if [catch {set result [${cmd} ${trystring}]} msg] { if {[regexp {bad *option.*____.*: *must *be( .*$)} ${msg} all 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} } } } else { # check, if it's a blt error msg ... # set msglst [split ${msg} \n] foreach line ${msglst} { if {[regexp "${cmd}\[ \t\]\+\(\[^ \t\]*\)\[^:\]*$" \ ${line} all sub]} { lappend result [list ${sub}] } } } } return ${result} } proc FirstNonOption {line} { set expr_pos 1 foreach word [lrange ${line} 1 end] {; # 0 is the command itself if {"-" != [string index ${word} 0]} { break } else { |
︙ | ︙ | |||
655 656 657 658 659 660 661 | return [CommandCompletion ${cmd} procs] } proc CommandsOnlyCompletion {cmd} { return [CommandCompletion ${cmd} commands] } | | > > > > > > < < < < < < | | 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 | return [CommandCompletion ${cmd} procs] } proc CommandsOnlyCompletion {cmd} { return [CommandCompletion ${cmd} commands] } proc CommandCompletion {cmd {action both} {spc ::}} { # get the leading colons in `cmd'. 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}]} { # puts stderr \nquali=|$quali| set matches [CommandCompletionWithPre \ [namespace tail ${cmd}] ${action} ${spc}${quali} ${pre}] # puts stderr \nmatches1=|$matches| return $matches } set cmd [string trim ${cmd}]* # puts stderr \ncmd=|$cmd|\n if {"procs" != ${action}} { |
︙ | ︙ | |||
695 696 697 698 699 700 701 | set commands "" } if {"commands" != ${action}} { set all_procs [namespace eval $spc [list info procs ${cmd}]] # puts stderr procs=|$procs| set procs "" foreach proc $all_procs { | | | | | | 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 | set commands "" } 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]]} { lappend procs $proc } } } else { set procs "" } 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}] # puts stderr \nmatches=|$matches| return $matches } # make `namespaces' having exactly # the same number of colons as `cmd'. # |
︙ | ︙ | |||
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 | # [SplitLine] --> {1 " put $b"} == sub # new_start = [lindex $sub 0] == 1 # 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_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]]} { # puts stderr "(PartPosition) $part $start $end $line" set all [CommandCompletion ${part}] # puts stderr "(ScriptCompleter) all=$all" #puts \nmatches=$matches\n # return [Format $all $part] return [TryFromList $part $all] } else { # try to use $pos further ... # puts stderr |$line| # if {"." == [string index [string trim ${line}] 0]} { set alias WIDGET | > > > > | 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 | # [SplitLine] --> {1 " put $b"} == sub # new_start = [lindex $sub 0] == 1 # 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_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]]} { # puts stderr "(PartPosition) $part $start $end $line" set all [CommandCompletion ${part}] # puts stderr "(ScriptCompleter) all=$all" #puts \nmatches=$matches\n # return [Format $all $part] return [TryFromList $part $all] } else { # try to use $pos further ... # puts stderr |$line| # if {"." == [string index [string trim ${line}] 0]} { set alias WIDGET |
︙ | ︙ | |||
905 906 907 908 909 910 911 912 913 914 915 916 917 918 | error [list error during evaluation of `complete(${cmd})'] } # puts stderr \nscript_result=|${script_result}| return ${script_result} } # set namespc ""; # no qualifiers for tclreadline_complete_unknown } # no specific command completer found. return "" } error "{NOTREACHED (this is probably an error)}" } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | error [list error during evaluation of `complete(${cmd})'] } # puts stderr \nscript_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 [uplevel [info level] info proc $alias]]} { set args [uplevel [info level] info args $alias] set arg [lindex $args [expr $pos - 1]] if {"" != $arg} { if {[uplevel [info level] info default $alias $arg junk]} { return [DisplayHints ?$arg?] } else { return [DisplayHints <$arg>] } } } # Ok, also no proc. Try to do the same as for widgets now: # try to get at least the first option from an error output. # switch -- $pos { 1 { set cmds [TrySubCmds ${alias}] if {[llength ${cmds}]} { return [TryFromList ${part} ${cmds}] } } } # no specific command completer found. return "" } error "{NOTREACHED (this is probably an error)}" } |
︙ | ︙ | |||
1049 1050 1051 1052 1053 1054 1055 | switch -- $pos { 1 { return [DisplayHints <script>] } 2 { return [DisplayHints ?varName?] } } return "" } | | | > | 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 | switch -- $pos { 1 { return [DisplayHints <script>] } 2 { return [DisplayHints ?varName?] } } return "" } proc complete(cd) {text start end line pos mod} { return "" } proc complete(clock) {text start end line pos mod} { set cmd [Lindex $line 1] switch -- $pos { 1 { return [CompleteFromList $text {clicks format scan seconds}] } |
︙ | ︙ | |||
2229 2230 2231 2232 2233 2234 2235 2236 2237 | names {} unknown { return [DisplayHints ?command?] } vcompare - vsatisfies { return [DisplayHints <version1>] } } } 3 { switch -- $cmd { forget {} | > > > > > > | > > > > > > | > > > > > | > | 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 | names {} unknown { return [DisplayHints ?command?] } vcompare - vsatisfies { return [DisplayHints <version1>] } } } 3 { set versions "" catch [list set versions [package versions [Lindex $line 2]]] switch -- $cmd { forget {} ifneeded { if {"" != $versions} { return [CompleteFromList ${text} $versions] } else { return [DisplayHints <version>] } } provide { if {"" != $versions} { return [CompleteFromList ${text} $versions] } else { return [DisplayHints ?version?] } } versions {} present - require { if {"-exact" == [PreviousWord ${start} ${line}]} { return [CompleteFromList ${mod} [package names]] } else { if {"" != $versions} { return [CompleteFromList ${text} $versions] } else { return [DisplayHints ?version?] } } } names {} unknown {} vcompare - vsatisfies { return [DisplayHints <version2>] } } |
︙ | ︙ | |||
2769 2770 2771 2772 2773 2774 2775 2776 2777 | } } } } return "" } proc complete(tell) {text start end line pos mod} { switch -- $pos { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | 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 | } } } } return "" } # --- TCLREADLINE PACKAGE --- # create a tclreadline namespace inside # tclreadline and import some commands. # namespace eval tclreadline { catch { namespace import \ ::tclreadline::DisplayHints \ ::tclreadline::CompleteFromList \ ::tclreadline::Lindex } } 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 builtincompleter eofchar}] } 2 { switch -- $cmd { read {} initialize {} write {} add { return [DisplayHints <completerLine>] } completer { return [DisplayHints <line>] } customcompleter { return [DisplayHints ?scriptCompleter?] } builtincompleter { return [DisplayHints ?boolean?] } eofchar { return [DisplayHints ?script?] } } } } return "" } # --- END OF TCLREADLINE PACKAGE --- proc complete(tell) {text start end line pos mod} { switch -- $pos { 1 { return [ChannelId ${text}] } } return "" } proc complete(time) {text start end line pos mod} { switch -- $pos { 1 { return [DisplayHints <script>] } |
︙ | ︙ | |||
2926 2927 2928 2929 2930 2931 2932 | return "" } # ------------------------------------- # TK # ------------------------------------- | | | < < < < | | < < < < < < | | < < < < < < < < < < < < < < < < < > > > > > > > > > | | | | | > | | | > | | | | > | > | | | | | | | > > > > > > > > > > > > > > > > | | | | | > | | > | 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 | return "" } # ------------------------------------- # TK # ------------------------------------- # GENERIC WIDGET CONFIGURATION proc WidgetChildren {pattern} { regsub {^([^\.])} ${pattern} {\.\1} pattern if {![string length ${pattern}]} { set pattern . } if {[winfo exists ${pattern}]} { return [winfo children ${pattern}] } else { regsub {.[^.]*$} $pattern {} pattern if {[winfo exists ${pattern}]} { return [winfo children ${pattern}] } else { return "" } } } proc WidgetDescendants {pattern} { set tree [WidgetChildren ${pattern}] foreach widget $tree { append tree " [WidgetDescendants $widget]" } return $tree } proc complete(WIDGET) {text start end line pos mod} { set widget [lindex ${line} 0] set cmd [lindex ${line} 1] # first we build an option table # if {[catch [list set option_table [${widget} configure]] msg]} { return "" } foreach optline ${option_table} { if {5 != [llength ${optline}]} continue else { lappend options(switches) [lindex ${optline} 0] lappend options(value) [lindex ${optline} 4] } } switch -- $pos { 1 { set cmds [TrySubCmds ${widget}] if {[llength ${cmds}]} { return [TryFromList ${mod} ${cmds}] } } 2 { if {([string match ${cmd}* cget] || \ [string match ${cmd}* configure]) } { set prev [PreviousWord ${start} ${line}] #puts \nprev=|$prev| #puts switches=|$options(switches)| #puts found=[lsearch -exact ${prev} $options(switches)] if {-1 != [set found \ [lsearch -exact $options(switches) ${prev}]] } { if {![llength ${mod}]} { return [list "[lindex $options(value) ${found}]"] } } else { return [TryFromList ${mod} $options(switches)] } } } } return "" } # SPECIFIC TK COMMAND COMPLETERS proc complete(bell) {text start end line pos mod} { switch -- $pos { 1 { return [CompleteFromList ${text} -displayof] } 2 { if {"-displayof" == [PreviousWord ${start} ${line}]} { return [CompleteFromList ${text} [WidgetDescendants ${text}]] } } } } proc complete(winfo) {text start end line pos mod} { set cmd [lindex ${line} 1] switch -- $pos { 1 { set cmds [TrySubCmds winfo] if {[llength ${cmds}]} { return [TryFromList ${text} ${cmds}] } } 2 { return [TryFromList ${text} [WidgetChildren ${text}]] } } return "" } }; # namespace tclreadline |
Modified tclreadlineSetup.tcl.in from [602286f12e] to [026fd75a9a].
1 | #!/usr/locanl/bin/tclsh | | | | 1 2 3 4 5 6 7 8 9 10 | #!/usr/locanl/bin/tclsh # FILE: "/home/joze/src/tclreadline/tclreadlineSetup.tcl.in" # LAST MODIFICATION: "Mon Sep 13 23:44:55 1999 (joze)" # (C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org> # $Id$ # --- # # tclreadline -- gnu readline for tcl # Copyright (C) 1999 Johannes Zellner # |
︙ | ︙ | |||
24 25 26 27 28 29 30 | # # johannes@zellner.org # http://www.zellner.org/tclreadline/ # # ================================================================== | | > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | # # johannes@zellner.org # http://www.zellner.org/tclreadline/ # # ================================================================== # package provide tclreadline @TCLREADLINE_VERSION@ package provide tclreadline 0.9 proc unknown args { global auto_noexec auto_noload env unknown_pending tcl_interactive global errorCode errorInfo # Save the values of errorCode and errorInfo variables, since they |
︙ | ︙ | |||
294 295 296 297 298 299 300 | } ::tclreadline::errorMsg]} { puts stderr [list tclreadline::Loop: error. \ $::tclreadline::errorMsg] continue } # Magnus Eriksson <magnus.eriksson@netinsight.se> proposed | > > > > > > > > | > | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | } ::tclreadline::errorMsg]} { puts stderr [list 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 $LINE] && [history event 0] != $LINE} { history add $LINE } if [catch { set result [eval $LINE] if {$result != "" && [tclreadline::Print]} { puts $result } set result "" |
︙ | ︙ |