diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-09-10 06:46:40 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-09-10 06:46:40 -0700 |
commit | e046e1890f4655478a99fa7c1cb078eefdc54e00 (patch) | |
tree | 29f3aec8a500b6113534457fbf593577389bfb8b /txr.c | |
parent | 0f55e4b727694c0c926ef0979f11b438edccc675 (diff) | |
download | txr-e046e1890f4655478a99fa7c1cb078eefdc54e00.tar.gz txr-e046e1890f4655478a99fa7c1cb078eefdc54e00.tar.bz2 txr-e046e1890f4655478a99fa7c1cb078eefdc54e00.zip |
Bugfix: make self-path visible to Lisp.
The self-path variable is not bound in TXR Lisp scripts
or the command line.
* txr.c (txr_main): Set self-path to "cmdline-expr" before
command line Lisp evaluations. (For TXR pattern language
syntax invoked in a -c, it continues to be "cmdline").
Set self-path to the file name when reading a Lisp file.
Also, the legacy, undocumented *self-path* is only set
for TXR scripts, and is reverted to being a special variable,
not a global lexical.
* txr.1: Documented self-path in more detail.
Diffstat (limited to 'txr.c')
-rw-r--r-- | txr.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -398,6 +398,7 @@ int txr_main(int argc, char **argv) val parse_stream = std_input; val txr_lisp_p = nil; val enter_repl = nil; + val self_path_s = intern(lit("self-path"), user_package); list_collect_decl(arg_list, arg_tail); setvbuf(stderr, 0, _IOLBF, 0); @@ -581,6 +582,7 @@ int txr_main(int argc, char **argv) spec_file = arg; break; case 'e': + reg_varl(self_path_s, lit("cmdline-expr")); eval_intrinsic(lisp_parse(arg, std_error, colon_k, lit("cmdline-expr"), colon_k), make_env(bindings, nil, nil)); @@ -595,6 +597,7 @@ int txr_main(int argc, char **argv) if3(c_chr(opt) == 'P', pprinl, tprint)); + reg_varl(self_path_s, lit("cmdline-expr")); pf(eval_intrinsic(lisp_parse(arg, std_error, colon_k, lit("cmdline-expr"), colon_k), make_env(bindings, nil, nil)), std_output); @@ -716,6 +719,7 @@ int txr_main(int argc, char **argv) } reg_var(intern(lit("*args*"), user_package), arg_list); + reg_varl(intern(lit("self-path"), user_package), spec_file_str); if (!txr_lisp_p) { @@ -736,8 +740,7 @@ int txr_main(int argc, char **argv) format(std_error, lit("bindings:\n~s\n"), bindings, nao); } - reg_varl(intern(lit("*self-path*"), user_package), spec_file_str); - reg_var(intern(lit("self-path"), user_package), spec_file_str); + reg_var(intern(lit("*self-path*"), user_package), spec_file_str); { val result = extract(spec, arg_list, bindings); |