From 847a7b6c5292bd2126303e3ab7a6916657e13a71 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 8 Nov 2016 21:09:45 -0800 Subject: Implement *package* special var; package overhaul. * eval.c (load): Rebind *package* in the local dynamic environment already established for the sake of *load-path*. By doing this we cause *package* to be restored to its prior value, which allows the loaded file to alter it. Common Lisp works this way. (eval_init): Register *package* variable, with the user package as its default value. * lib.c (package_s): New symbol variable. (intern, rehome_sym): Default the package argument to the current package, not to user_package. (get_user_package, get_system_package, get_keyword_package): Functions removed. (get_current_package): New function. (obj_print_impl): Revise symbol printing. Keyword and uninterned symbols are printed with : and #: prefixes. The remainder are printed with a package prefix if their home package isn't the current package. * lib.h (keyword_package, user_package, system_package): These macros are just straight aliases for the global variables, not going through the lookup mechanism, which was pointless. (cur_package): New macro. (package_s): Declared. (get_current_package): Declared. * lisplib.c (lisplib_try_load): Establish a local dynamic environment, and bind the *package* variable to the user package which the library modules expect. * parser.c (find_matching_syms, provide_completions): Treat unqualified symbols in the current package rather than user package. * parser.y (sym_helper): Intern unqualified symbols in the current package, not user package. * txr.1: Document that the variables user-package, system-package and keyword-package should not be modified. Document the *package* special variable, and that intern and rehome-sym default their package argument to its value. (Here we get rid of wrong references to the undocumented variable *user-package*). --- parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'parser.c') diff --git a/parser.c b/parser.c index 655ee8f1..bf243711 100644 --- a/parser.c +++ b/parser.c @@ -634,7 +634,7 @@ static void find_matching_syms(lino_completions_t *cpl, val line_prefix, char par, val force_qualify) { - val qualify = tnil(force_qualify || package != user_package); + val qualify = tnil(force_qualify || package != cur_package); val pkg_name = if2(qualify, if3(package == keyword_package && !force_qualify, lit(""), @@ -761,7 +761,7 @@ static void provide_completions(const char *data, int dwim = (prev == '['); char par = (!pprev || (!quote && !meth && !ppar) || dwim) ? prev : 0; - find_matching_syms(cpl, or2(package, user_package), + find_matching_syms(cpl, or2(package, cur_package), sym_pfx, line_pfx, par, if2(package, null(keyword))); } } -- cgit v1.2.3