From 336f467b3f8dd0dc45a607025007d95e232ecb13 Mon Sep 17 00:00:00 2001 From: piegames Date: Fri, 14 Feb 2025 16:58:48 +0100 Subject: [PATCH] repl: Print message when adding variable I've always been annoyed that it just silently succeeded without any feedback, but now with the upcoming improvements on defining variables this is more necessary than ever. Change-Id: I565897fa2f97cf6f567d4449dcc8d4ad4eb73fce --- doc/manual/rl-next/repl-improvements.md | 1 + lix/libcmd/repl.cc | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/manual/rl-next/repl-improvements.md b/doc/manual/rl-next/repl-improvements.md index f2cbb217c..3fb25611d 100644 --- a/doc/manual/rl-next/repl-improvements.md +++ b/doc/manual/rl-next/repl-improvements.md @@ -10,3 +10,4 @@ The REPL has seen various minor improvements: - Better error messages overall - The `:env` command to print currently available variables now also works outside of debug mode +- Adding variables to the REPL now prints a small message on success diff --git a/lix/libcmd/repl.cc b/lix/libcmd/repl.cc index a088e33a9..8383d1ab8 100644 --- a/lix/libcmd/repl.cc +++ b/lix/libcmd/repl.cc @@ -1088,8 +1088,12 @@ void NixRepl::addVarToScope(const Symbol name, Value & v) { if (displ >= envSize) throw Error("environment full; cannot add more variables"); - if (auto oldVar = staticEnv->find(name); oldVar != staticEnv->vars.end()) + if (auto oldVar = staticEnv->find(name); oldVar != staticEnv->vars.end()) { staticEnv->vars.erase(oldVar); + notice("Updated %s.", evaluator.symbols[name]); + } else { + notice("Added %s.", evaluator.symbols[name]); + } staticEnv->vars.emplace_back(name, displ); staticEnv->sort(); env->values[displ++] = &v;