diff options
-rw-r--r-- | jim.c | 35 | ||||
-rw-r--r-- | jim_tcl.txt | 9 | ||||
-rw-r--r-- | tests/alias.test | 9 |
3 files changed, 42 insertions, 11 deletions
@@ -13626,13 +13626,13 @@ static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg "body", "statics", "commands", "procs", "channels", "exists", "globals", "level", "frame", "locals", "vars", "version", "patchlevel", "complete", "args", "hostname", "script", "source", "stacktrace", "nameofexecutable", "returncodes", - "references", NULL + "references", "alias", NULL }; enum { INFO_BODY, INFO_STATICS, INFO_COMMANDS, INFO_PROCS, INFO_CHANNELS, INFO_EXISTS, INFO_GLOBALS, INFO_LEVEL, INFO_FRAME, INFO_LOCALS, INFO_VARS, INFO_VERSION, INFO_PATCHLEVEL, INFO_COMPLETE, INFO_ARGS, INFO_HOSTNAME, INFO_SCRIPT, INFO_SOURCE, INFO_STACKTRACE, INFO_NAMEOFEXECUTABLE, - INFO_RETURNCODES, INFO_REFERENCES, + INFO_RETURNCODES, INFO_REFERENCES, INFO_ALIAS }; if (argc < 2) { @@ -13646,14 +13646,31 @@ static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg /* Test for the the most common commands first, just in case it makes a difference */ switch (cmd) { - case INFO_EXISTS:{ - if (argc != 3) { - Jim_WrongNumArgs(interp, 2, argv, "varName"); - return JIM_ERR; - } - Jim_SetResultBool(interp, Jim_GetVariable(interp, argv[2], 0) != NULL); - break; + case INFO_EXISTS: + if (argc != 3) { + Jim_WrongNumArgs(interp, 2, argv, "varName"); + return JIM_ERR; + } + Jim_SetResultBool(interp, Jim_GetVariable(interp, argv[2], 0) != NULL); + break; + + case INFO_ALIAS:{ + Jim_Cmd *cmdPtr; + + if (argc != 3) { + Jim_WrongNumArgs(interp, 2, argv, "command"); + return JIM_ERR; + } + if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) { + return JIM_ERR; } + if (cmdPtr->isproc || cmdPtr->u.native.cmdProc != JimAliasCmd) { + Jim_SetResultFormatted(interp, "command \"%#s\" is not an alias", argv[2]); + return JIM_ERR; + } + Jim_SetResult(interp, (Jim_Obj *)cmdPtr->u.native.privData); + return JIM_OK; + } case INFO_CHANNELS: mode++; /* JIM_CMDLIST_CHANNELS */ diff --git a/jim_tcl.txt b/jim_tcl.txt index ccfb57e..c40235e 100644 --- a/jim_tcl.txt +++ b/jim_tcl.txt @@ -63,6 +63,7 @@ Changes between 0.72 and 0.73 4. Add `info statics` 5. Add +build-jim-ext+ for easy separate building of loadable modules (extensions) 6. `local` now works with any command, not just procs +7. Add `info alias` to access the target of an alias Changes between 0.71 and 0.72 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1546,7 +1547,7 @@ alias ~~~~~ +*alias* 'name args\...'+ -Creates a single word alias (`proc`) for one or more words. For example, +Creates a single word alias (command) for one or more words. For example, the following creates an alias for the command `info exists`. alias e info exists @@ -1556,7 +1557,7 @@ the following creates an alias for the command `info exists`. `alias` returns +'name'+, allowing it to be used with `local`. -See also `proc`, `curry`, `lambda`, `local`. +See also `proc`, `curry`, `lambda`, `local`, `info alias` append ~~~~~~ @@ -2570,6 +2571,10 @@ The legal +'option'+'s (which may be abbreviated) are: +'procname'+, in order. +'procname'+ must be the name of a Tcl command procedure. ++*info alias* 'command'+:: + +'command'+ must be an alias created with `alias`. In which case the target + command and arguments, as passed to `alias` are returned. + +*info body* 'procname'+:: Returns the body of procedure +'procname'+. +'procname'+ must be the name of a Tcl command procedure. diff --git a/tests/alias.test b/tests/alias.test index 8b4d857..201f6e2 100644 --- a/tests/alias.test +++ b/tests/alias.test @@ -42,6 +42,15 @@ test alias-1.9 "error message from alias" -body { newstring match } -returnCodes error -result {wrong # args: should be "newstring match ?-nocase? pattern string"} +test alias-1.10 "info alias" { + alias x info exists + info alias x +} {info exists} + +test alias-1.10 "info alias on non-alias" -body { + info alias format +} -returnCodes error -result {command "format" is not an alias} + test curry-1.1 "One word curry" { set x 2 set one [curry incr] |