Change how we separate toplevel and global scopes

Instead of introducing a new local scope at the point of `set`, merely
push a new local scope at the end of env_init(). This means we have a
single toplevel local scope across the lifetime of the fish process,
which means that

    set -l foo bar
    echo $foo

behaves as expected, without modifying the global environment.
This commit is contained in:
Kevin Ballard
2014-07-13 13:21:06 -07:00
parent 387ec5c06a
commit 7b12fd26f3
3 changed files with 8 additions and 27 deletions

18
env.cpp
View File

@@ -593,6 +593,14 @@ void env_init(const struct config_paths_t *paths /* or NULL */)
/* Set fish_bind_mode to "default" */
env_set(FISH_BIND_MODE_VAR, DEFAULT_BIND_MODE, ENV_GLOBAL);
/*
Now that the global scope is fully initialized, add a toplevel local
scope. This same local scope will persist throughout the lifetime of the
fish process, and it will ensure that `set -l` commands run at the
command-line don't affect the global scope.
*/
env_push(false);
}
/**
@@ -1195,16 +1203,6 @@ void env_pop()
}
}
bool env_ensure_local_scope()
{
if (top == global_env)
{
env_push(false);
return true;
}
return false;
}
/**
Function used with to insert keys of one table into a set::set<wcstring>
*/