summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-04-07 15:36:39 +1000
committerMaxime Coste <mawww@kakoune.org>2018-04-07 16:27:50 +1000
commit57baad4afde8d1bab4040c5a5cbe8a5b367bceba (patch)
tree5e4f5fba17f8a6038301fcb129f36db102b0bd70 /src
parent6adb28ec1243adf13126ee47444d57dd2b842945 (diff)
Make FaceRegistry scoped
set-face now takes a scope argument, and faces can be overridden on a buffer or window basis. colorscheme apply on global scope, which should be good enough for now. Fixes #1411
Diffstat (limited to 'src')
-rw-r--r--src/alias_registry.hh2
-rw-r--r--src/client.cc28
-rw-r--r--src/client_manager.cc3
-rw-r--r--src/commands.cc40
-rw-r--r--src/context.cc6
-rw-r--r--src/context.hh3
-rw-r--r--src/display_buffer.cc5
-rw-r--r--src/display_buffer.hh4
-rw-r--r--src/face_registry.cc43
-rw-r--r--src/face_registry.hh46
-rw-r--r--src/highlighter.cc55
-rw-r--r--src/highlighter.hh28
-rw-r--r--src/highlighters.cc67
-rw-r--r--src/hook_manager.cc2
-rw-r--r--src/input_handler.cc49
-rw-r--r--src/insert_completer.cc26
-rw-r--r--src/insert_completer.hh14
-rw-r--r--src/main.cc6
-rw-r--r--src/normal.cc32
-rw-r--r--src/scope.hh7
-rw-r--r--src/shell_manager.cc2
21 files changed, 279 insertions, 189 deletions
diff --git a/src/alias_registry.hh b/src/alias_registry.hh
index 952669a0..c35cdf70 100644
--- a/src/alias_registry.hh
+++ b/src/alias_registry.hh
@@ -33,7 +33,7 @@ public:
private:
friend class Scope;
- AliasRegistry() {}
+ AliasRegistry() = default;
SafePtr<AliasRegistry> m_parent;
using AliasMap = HashMap<String, String, MemoryDomain::Aliases>;
diff --git a/src/client.cc b/src/client.cc
index 6520dc9c..22836a25 100644
--- a/src/client.cc
+++ b/src/client.cc
@@ -96,7 +96,8 @@ bool Client::process_pending_inputs()
catch (Kakoune::runtime_error& error)
{
write_to_debug_buffer(format("Error: {}", error.what()));
- context().print_status({ fix_atom_text(error.what().str()), get_face("Error") });
+ context().print_status({ fix_atom_text(error.what().str()),
+ context().faces()["Error"] });
context().hooks().run_hook("RuntimeError", error.what(), context());
}
}
@@ -142,15 +143,16 @@ DisplayLine Client::generate_mode_line() const
{
const String& modelinefmt = context().options()["modelinefmt"].get<String>();
HashMap<String, DisplayLine> atoms{{ "mode_info", context().client().input_handler().mode_line() },
- { "context_info", {generate_context_info(context()), get_face("Information")}}};
+ { "context_info", {generate_context_info(context()),
+ context().faces()["Information"]}}};
auto expanded = expand(modelinefmt, context(), ShellContext{},
[](String s) { return escape(s, '{', '\\'); });
- modeline = parse_display_line(expanded, atoms);
+ modeline = parse_display_line(expanded, context().faces(), atoms);
}
catch (runtime_error& err)
{
write_to_debug_buffer(format("Error while parsing modelinefmt: {}", err.what()));
- modeline.push_back({ "modelinefmt error, see *debug* buffer", get_face("Error") });
+ modeline.push_back({ "modelinefmt error, see *debug* buffer", context().faces()["Error"] });
}
return modeline;
@@ -207,9 +209,11 @@ void Client::redraw_ifn()
if (m_ui_pending == 0)
return;
+ auto& faces = context().faces();
+
if (m_ui_pending & Draw)
m_ui->draw(window.update_display_buffer(context()),
- get_face("Default"), get_face("BufferPadding"));
+ faces["Default"], faces["BufferPadding"]);
const bool update_menu_anchor = (m_ui_pending & Draw) and not (m_ui_pending & MenuHide) and
not m_menu.items.empty() and m_menu.style == MenuStyle::Inline;
@@ -224,7 +228,7 @@ void Client::redraw_ifn()
if (m_ui_pending & MenuShow and m_menu.ui_anchor)
m_ui->menu_show(m_menu.items, *m_menu.ui_anchor,
- get_face("MenuForeground"), get_face("MenuBackground"),
+ faces["MenuForeground"], faces["MenuBackground"],
m_menu.style);
if (m_ui_pending & MenuSelect and m_menu.ui_anchor)
m_ui->menu_select(m_menu.selected);
@@ -244,12 +248,12 @@ void Client::redraw_ifn()
if (m_ui_pending & InfoShow and m_info.ui_anchor)
m_ui->info_show(m_info.title, m_info.content, *m_info.ui_anchor,
- get_face("Information"), m_info.style);
+ faces["Information"], m_info.style);
if (m_ui_pending & InfoHide)
m_ui->info_hide();
if (m_ui_pending & StatusLine)
- m_ui->draw_status(m_status_line, m_mode_line, get_face("StatusLine"));
+ m_ui->draw_status(m_status_line, m_mode_line, faces["StatusLine"]);
auto cursor = m_input_handler.get_cursor_info();
m_ui->set_cursor(cursor.first, cursor.second);
@@ -272,12 +276,12 @@ void Client::reload_buffer()
{
reload_file_buffer(buffer);
context().print_status({ format("'{}' reloaded", buffer.display_name()),
- get_face("Information") });
+ context().faces()["Information"] });
}
catch (runtime_error& error)
{
context().print_status({ format("error while reloading buffer: '{}'", error.what()),
- get_face("Error") });
+ context().faces()["Error"] });
buffer.set_fs_timestamp(get_fs_timestamp(buffer.name()));
}
}
@@ -305,14 +309,14 @@ void Client::on_buffer_reload_key(Key key)
// reread timestamp in case the file was modified again
buffer.set_fs_timestamp(get_fs_timestamp(buffer.name()));
print_status({ format("'{}' kept", buffer.display_name()),
- get_face("Information") });
+ context().faces()["Information"] });
if (key == 'N')
set_autoreload(Autoreload::No);
}
else
{
print_status({ format("'{}' is not a valid choice", key_to_str(key)),
- get_face("Error") });
+ context().faces()["Error"] });
m_input_handler.on_next_key(KeymapMode::None, [this](Key key, Context&){ on_buffer_reload_key(key); });
return;
}
diff --git a/src/client_manager.cc b/src/client_manager.cc
index e4e37f0b..b812c958 100644
--- a/src/client_manager.cc
+++ b/src/client_manager.cc
@@ -65,7 +65,8 @@ Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui, int pi
}
catch (Kakoune::runtime_error& error)
{
- client->context().print_status({ fix_atom_text(error.what().str()), get_face("Error") });
+ client->context().print_status({ fix_atom_text(error.what().str()),
+ client->context().faces()["Error"] });
client->context().hooks().run_hook("RuntimeError", error.what(),
client->context());
}
diff --git a/src/commands.cc b/src/commands.cc
index b287c652..7d93afb8 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -249,7 +249,7 @@ void edit(const ParametersParser& parser, Context& context, const ShellContext&)
: open_or_create_file_buffer(name, flags);
if (buffer->flags() & Buffer::Flags::New)
context.print_status({ format("new file '{}'", name),
- get_face("StatusLine") });
+ context.faces()["StatusLine"] });
}
buffer->flags() &= ~Buffer::Flags::NoHooks;
@@ -1102,9 +1102,9 @@ const CommandDesc echo_cmd = {
if (parser.get_switch("debug"))
write_to_debug_buffer(message);
else if (parser.get_switch("markup"))
- context.print_status(parse_display_line(message));
+ context.print_status(parse_display_line(message, context.faces()));
else
- context.print_status({ std::move(message), get_face("StatusLine") });
+ context.print_status({ std::move(message), context.faces()["StatusLine"] });
}
};
@@ -1192,7 +1192,7 @@ const CommandDesc debug_cmd = {
else if (parser[0] == "faces")
{
write_to_debug_buffer("Faces:");
- for (auto& face : FaceRegistry::instance().aliases())
+ for (auto& face : context.faces().flatten_faces())
write_to_debug_buffer(format(" * {}: {}", face.key, face.value.face));
}
else if (parser[0] == "mappings")
@@ -1809,7 +1809,7 @@ const CommandDesc prompt_cmd = {
CapturedShellContext sc{shell_context};
context.input_handler().prompt(
- parser[0], initstr.str(), {}, get_face("Prompt"),
+ parser[0], initstr.str(), {}, context.faces()["Prompt"],
flags, std::move(completer),
[=](StringView str, PromptEvent event, Context& context) mutable
{
@@ -1873,7 +1873,7 @@ const CommandDesc menu_cmd = {
Vector<String> select_cmds;
for (int i = 0; i < count; i += modulo)
{
- choices.push_back(markup ? parse_display_line(parser[i])
+ choices.push_back(markup ? parse_display_line(parser[i], context.faces())
: DisplayLine{ parser[i], {} });
commands.push_back(parser[i+1]);
if (with_select_cmds)
@@ -1998,17 +1998,18 @@ const CommandDesc try_catch_cmd = {
}
};
-static Completions complete_face(const Context&, CompletionFlags flags,
+static Completions complete_face(const Context& context, CompletionFlags flags,
const String& prefix, ByteCount cursor_pos)
{
return {0_byte, cursor_pos,
- FaceRegistry::instance().complete_alias_name(prefix, cursor_pos)};
+ complete(prefix, cursor_pos, context.faces().flatten_faces() |
+ transform([](auto& entry) -> const String& { return entry.key; }))};
}
const CommandDesc set_face_cmd = {
"set-face",
"face",
- "set-face <name> <facespec>: set face <name> to refer to <facespec>\n"
+ "set-face <scope> <name> <facespec>: set face <name> to refer to <facespec> in <scope>\n"
"\n"
"facespec format is <fg color>[,<bg color>][+<attributes>]\n"
"colors are either a color name, or rgb:###### values.\n"
@@ -2016,19 +2017,33 @@ const CommandDesc set_face_cmd = {
" u: underline, i: italic, b: bold, r: reverse,\n"
" B: blink, d: dim, e: exclusive\n"
"facespec can as well just be the name of another face",
- ParameterDesc{{}, ParameterDesc::Flags::None, 2, 2},
+ ParameterDesc{{}, ParameterDesc::Flags::None, 3, 3},
CommandFlags::None,
CommandHelper{},
- make_completer(complete_face, complete_face),
+ make_completer(complete_scope, complete_face, complete_face),
[](const ParametersParser& parser, Context& context, const ShellContext&)
{
- FaceRegistry::instance().register_alias(parser[0], parser[1], true);
+ get_scope(parser[0], context).faces().add_face(parser[1], parser[2], true);
for (auto& client : ClientManager::instance())
client->force_redraw();
}
};
+const CommandDesc unset_face_cmd = {
+ "unset-face",
+ nullptr,
+ "unset-face <scope> <name>: remove <face> from <scope>",
+ ParameterDesc{{}, ParameterDesc::Flags::None, 2, 2},
+ CommandFlags::None,
+ CommandHelper{},
+ make_completer(complete_scope, complete_face),
+ [](const ParametersParser& parser, Context& context, const ShellContext&)
+ {
+ get_scope(parser[0], context).faces().remove_face(parser[1]);
+ }
+};
+
const CommandDesc rename_client_cmd = {
"rename-client",
"nc",
@@ -2257,6 +2272,7 @@ void register_commands()
register_command(info_cmd);
register_command(try_catch_cmd);
register_command(set_face_cmd);
+ register_command(unset_face_cmd);
register_command(rename_client_cmd);
register_command(set_register_cmd);
register_command(select_cmd);
diff --git a/src/context.cc b/src/context.cc
index ece4a2f4..03cf1586 100644
--- a/src/context.cc
+++ b/src/context.cc
@@ -96,7 +96,7 @@ const SelectionList& JumpList::forward(Context& context, int count)
res.update();
context.print_status({ format("jumped to #{} ({})",
m_current, m_jumps.size() - 1),
- get_face("Information") });
+ context.faces()["Information"] });
return res;
}
throw runtime_error("no next jump");
@@ -117,7 +117,7 @@ const SelectionList& JumpList::backward(Context& context, int count)
res.update();
context.print_status({ format("jumped to #{} ({})",
m_current, m_jumps.size() - 1),
- get_face("Information") });
+ context.faces()["Information"] });
return res;
}
if (m_current != 0)
@@ -133,7 +133,7 @@ const SelectionList& JumpList::backward(Context& context, int count)
res.update();
context.print_status({ format("jumped to #{} ({})",
m_current, m_jumps.size() - 1),
- get_face("Information") });
+ context.faces()["Information"] });
return res;
}
throw runtime_error("no previous jump");
diff --git a/src/context.hh b/src/context.hh
index cad77d4c..e2903b50 100644
--- a/src/context.hh
+++ b/src/context.hh
@@ -92,9 +92,10 @@ public:
Scope& scope() const;
OptionManager& options() const { return scope().options(); }
- HookManager& hooks() const { return scope().hooks(); }
+ HookManager& hooks() const { return scope().hooks(); }
KeymapManager& keymaps() const { return scope().keymaps(); }
AliasRegistry& aliases() const { return scope().aliases(); }
+ FaceRegistry& faces() const { return scope().faces(); }
void print_status(DisplayLine status) const;
diff --git a/src/display_buffer.cc b/src/display_buffer.cc
index a634ff5b..20b5588c 100644
--- a/src/display_buffer.cc
+++ b/src/display_buffer.cc
@@ -3,6 +3,7 @@
#include "assert.hh"
#include "buffer.hh"
#include "buffer_utils.hh"
+#include "face_registry.hh"
#include "utf8.hh"
#include "face_registry.hh"
@@ -241,7 +242,7 @@ void DisplayBuffer::optimize()
line.optimize();
}
-DisplayLine parse_display_line(StringView line, const HashMap<String, DisplayLine>& builtins)
+DisplayLine parse_display_line(StringView line, const FaceRegistry& faces, const HashMap<String, DisplayLine>& builtins)
{
DisplayLine res;
bool was_antislash = false;
@@ -278,7 +279,7 @@ DisplayLine parse_display_line(StringView line, const HashMap<String, DisplayLin
++closing;
}
else
- face = get_face({it+1, closing});
+ face = faces[{it+1, closing}];
it = closing;
pos = closing + 1;
}
diff --git a/src/display_buffer.hh b/src/display_buffer.hh
index 2b0a989d..e284fe1f 100644
--- a/src/display_buffer.hh
+++ b/src/display_buffer.hh
@@ -142,8 +142,10 @@ private:
AtomList m_atoms;
};
+class FaceRegistry;
+
String fix_atom_text(StringView str);
-DisplayLine parse_display_line(StringView line, const HashMap<String, DisplayLine>& builtins = {});
+DisplayLine parse_display_line(StringView line, const FaceRegistry& faces, const HashMap<String, DisplayLine>& builtins = {});
class DisplayBuffer : public UseMemoryDomain<MemoryDomain::Display>
{
diff --git a/src/face_registry.cc b/src/face_registry.cc
index 73e4b7b0..880ef6e9 100644
--- a/src/face_registry.cc
+++ b/src/face_registry.cc
@@ -71,63 +71,62 @@ String to_string(Face face)
return format("{},{}{}", face.fg, face.bg, face.attributes);
}
-Face FaceRegistry::operator[](StringView facedesc)
+Face FaceRegistry::operator[](StringView facedesc) const
{
- auto it = m_aliases.find(facedesc);
- while (it != m_aliases.end())
+ auto it = m_faces.find(facedesc);
+ if (it != m_faces.end())
{
if (it->value.alias.empty())
return it->value.face;
- it = m_aliases.find(it->value.alias);
+ return operator[](it->value.alias);
}
+ if (m_parent)
+ return (*m_parent)[facedesc];
return parse_face(facedesc);
}
-void FaceRegistry::register_alias(StringView name, StringView facedesc,
- bool override)
+void FaceRegistry::add_face(StringView name, StringView facedesc, bool override)
{
- if (not override and m_aliases.find(name) != m_aliases.end())
- throw runtime_error(format("alias '{}' already defined", name));
+ if (not override and m_faces.find(name) != m_faces.end())
+ throw runtime_error(format("face '{}' already defined", name));
if (name.empty() or is_color_name(name) or
std::any_of(name.begin(), name.end(),
[](char c){ return not isalnum(c); }))
- throw runtime_error(format("invalid alias name: '{}'", name));
+ throw runtime_error(format("invalid face name: '{}'", name));
if (name == facedesc)
throw runtime_error(format("cannot alias face '{}' to itself", name));
- FaceOrAlias& alias = m_aliases[name];
- auto it = m_aliases.find(facedesc);
- if (it != m_aliases.end())
+ FaceOrAlias& face = m_faces[name];
+ auto it = m_faces.find(facedesc);
+ if (it != m_faces.end())
{
- while (it != m_aliases.end())
+ while (it != m_faces.end())
{
if (it->value.alias.empty())
break;
if (it->value.alias == name)
throw runtime_error("face cycle detected");
- it = m_aliases.find(it->value.alias);
+ it = m_faces.find(it->value.alias);
}
- alias.alias = facedesc.str();
+ face.alias = facedesc.str();
}
else
{
- alias.alias = "";
- alias.face = parse_face(facedesc);
+ face.alias = "";
+ face.face = parse_face(facedesc);
}
}
-CandidateList FaceRegistry::complete_alias_name(StringView prefix,
- ByteCount cursor_pos) const
+void FaceRegistry::remove_face(StringView name)
{
- return complete(prefix, cursor_pos,
- m_aliases | transform(&AliasMap::Item::key));
+ m_faces.remove(name);
}
FaceRegistry::FaceRegistry()
- : m_aliases{
+ : m_faces{
{ "Default", {Face{ Color::Default, Color::Default }} },
{ "PrimarySelection", {Face{ Color::White, Color::Blue }} },
{ "SecondarySelection", {Face{ Color::Black, Color::Blue }} },
diff --git a/src/face_registry.hh b/src/face_registry.hh
index 82006bd2..049227eb 100644
--- a/src/face_registry.hh
+++ b/src/face_registry.hh
@@ -3,23 +3,35 @@
#include "face.hh"
#include "utils.hh"
-#include "completion.hh"
#include "hash_map.hh"
+#include "ranges.hh"
+#include "string.hh"
+#include "safe_ptr.hh"
namespace Kakoune
{
-class FaceRegistry : public Singleton<FaceRegistry>
+class FaceRegistry : public SafeCountable
{
public:
- FaceRegistry();
+ FaceRegistry(FaceRegistry& parent) : SafeCountable{}, m_parent(&parent) {}
- Face operator[](StringView facedesc);
- void register_alias(StringView name, StringView facedesc,
- bool override = false);
+ Face operator[](StringView facedesc) const;
+ void add_face(StringView name, StringView facedesc, bool override = false);
+ void remove_face(StringView name);
- CandidateList complete_alias_name(StringView prefix,
- ByteCount cursor_pos) const;
+ auto flatten_faces() const
+ {
+ auto merge = [](auto&& first, const FaceMap& second) {
+ return concatenated(std::forward<decltype(first)>(first)
+ | filter([&second](auto& i) { return not second.contains(i.key); }),
+ second);
+ };
+ static const FaceMap empty;
+ auto& parent = m_parent ? m_parent->m_faces : empty;
+ auto& grand_parent = (m_parent and m_parent->m_parent) ? m_parent->m_parent->m_faces : empty;
+ return merge(merge(grand_parent, parent), m_faces);
+ }
struct FaceOrAlias
{
@@ -27,19 +39,15 @@ public:
String alias = {};
};
- using AliasMap = HashMap<String, FaceOrAlias, MemoryDomain::Faces>;
- const AliasMap &aliases() const { return m_aliases; }
-
private:
- AliasMap m_aliases;
-};
+ friend class Scope;
+ FaceRegistry();
-inline Face get_face(StringView facedesc)
-{
- if (FaceRegistry::has_instance())
- return FaceRegistry::instance()[facedesc];
- return Face{};
-}
+ SafePtr<FaceRegistry> m_parent;
+
+ using FaceMap = HashMap<String, FaceOrAlias, MemoryDomain::Faces>;
+ FaceMap m_faces;
+};
String to_string(Face face);
diff --git a/src/highlighter.cc b/src/highlighter.cc
new file mode 100644
index 00000000..66759af5
--- /dev/null
+++ b/src/highlighter.cc
@@ -0,0 +1,55 @@
+#include "highlighter.hh"
+
+#include "buffer_utils.hh"
+
+namespace Kakoune
+{
+
+void Highlighter::highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range)
+{
+ if (context.pass & m_passes) try
+ {
+ do_highlight(context, display_buffer, range);
+ }
+ catch (runtime_error& error)
+ {
+ write_to_debug_buffer(format("Error while highlighting: {}", error.what()));
+ }
+}
+
+void Highlighter::compute_display_setup(HighlightContext context, DisplaySetup& setup) const
+{
+ if (context.pass & m_passes)
+ do_compute_display_setup(context, setup);
+}
+
+
+bool Highlighter::has_children() const
+{
+ return false;
+}
+
+Highlighter& Highlighter::get_child(StringView path)
+{
+ throw runtime_error("this highlighter do not hold children");
+}
+
+void Highlighter::add_child(HighlighterAndId&& hl)
+{
+ throw runtime_error("this highlighter do not hold children");
+}
+
+void Highlighter::remove_child(StringView id)
+{
+ throw runtime_error("this highlighter do not hold children");
+}
+
+Completions Highlighter::complete_child(StringView path, ByteCount cursor_pos, bool group) const
+{
+ throw runtime_error("this highlighter do not hold children");
+}
+
+void Highlighter::fill_unique_ids(Vector<StringView>& unique_ids) const
+{}
+
+}
diff --git a/src/highlighter.hh b/src/highlighter.hh
index 122f26ac..f3b7e3fd 100644
--- a/src/highlighter.hh
+++ b/src/highlighter.hh
@@ -65,25 +65,15 @@ struct Highlighter
Highlighter(HighlightPass passes) : m_passes{passes} {}
virtual ~Highlighter() = default;
- void highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range)
- {
- if (context.pass & m_passes)
- do_highlight(context, display_buffer, range);
- }
-
- void compute_display_setup(HighlightContext context, DisplaySetup& setup) const
- {
- if (context.pass & m_passes)
- do_compute_display_setup(context, setup);
- }
-
- virtual bool has_children() const { return false; }
- virtual Highlighter& get_child(StringView path) { throw runtime_error("this highlighter do not hold children"); }
- virtual void add_child(HighlighterAndId&& hl) { throw runtime_error("this highlighter do not hold children"); }
- virtual void remove_child(StringView id) { throw runtime_error("this highlighter do not hold children"); }
- virtual Completions complete_child(StringView path, ByteCount cursor_pos, bool group) const { throw runtime_error("this highlighter do not hold children"); }
-
- virtual void fill_unique_ids(Vector<StringView>& unique_ids) const {}
+ void highlight(HighlightContext context, DisplayBuffer& display_buffer, BufferRange range);
+ void compute_display_setup(HighlightContext context, DisplaySetup& setup) const;
+
+ virtual bool has_children() const;
+ virtual Highlighter& get_child(StringView path);
+ virtual void add_child(HighlighterAndId&& hl);
+ virtual void remove_child(StringView id);
+ virtual Completions complete_child(StringView path, ByteCount cursor_pos, bool group) const;
+ virtual void fill_unique_ids(Vector<StringView>& unique_ids) const;
HighlightPass passes() const { return m_passes; }
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 59a67f1a..323257ab 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -225,12 +225,10 @@ static HighlighterAndId create_fill_highlighter(HighlighterParameters params)
throw runtime_error("wrong parameter count");
const String& facespec = params[0];
- get_face(facespec); // validate param
-
- auto func = [=](HighlightContext, DisplayBuffer& display_buffer, BufferRange range)
+ auto func = [facespec](HighlightContext context, DisplayBuffer& display_buffer, BufferRange range)
{
highlight_range(display_buffer, range.begin, range.end, false,
- apply_face(get_face(facespec)));
+ apply_face(context.context.faces()[facespec]));
};
return {"fill_" + facespec, make_highlighter(std::move(func))};
}
@@ -278,7 +276,7 @@ public:
for (int f = 0; f < m_faces.size(); ++f)
{
if (not m_faces[f].second.empty())
- faces[f] = get_face(m_faces[f].second);
+ faces[f] = context.context.faces()[m_faces[f].second];
}
auto& matches = get_matches(context.context.buffer(), display_buffer.range(), range);
@@ -314,7 +312,6 @@ public:
auto colon = find(spec, ':');
if (colon == spec.end())
throw runtime_error(format("wrong face spec: '{}' expected <capture>:<facespec>", spec));
- get_face({colon+1, spec.end()}); // throw if wrong face spec
int capture = str_to_int({spec.begin(), colon});
faces.emplace_back(capture, String{colon+1, spec.end()});
}
@@ -495,7 +492,6 @@ HighlighterAndId create_dynamic_regex_highlighter(HighlighterParameters params)
if (colon == spec.end())
throw runtime_error("wrong face spec: '" + spec +
"' expected <capture>:<facespec>");
- get_face({colon+1, spec.end()}); // throw if wrong face spec
int capture = str_to_int({spec.begin(), colon});
faces.emplace_back(capture, String{colon+1, spec.end()});
}
@@ -539,12 +535,8 @@ HighlighterAndId create_line_highlighter(HighlighterParameters params)
if (params.size() != 2)
throw runtime_error("wrong parameter count");
- String facespec = params[1];
- String line_expr = params[0];
-
- get_face(facespec); // validate facespec
-
- auto func = [=](HighlightContext context, DisplayBuffer& display_buffer, BufferRange)
+ auto func = [line_expr=params[0], facespec=params[1]]
+ (HighlightContext context, DisplayBuffer& display_buffer, BufferRange)
{
LineCount line = -1;
try
@@ -566,7 +558,7 @@ HighlighterAndId create_line_highlighter(HighlighterParameters params)
if (it == display_buffer.lines().end())
return;
- auto face = get_face(facespec);
+ auto face = context.context.faces()[facespec];
ColumnCount column = 0;
for (auto& atom : *it)
{
@@ -590,12 +582,8 @@ HighlighterAndId create_column_highlighter(HighlighterParameters params)
if (params.size() != 2)
throw runtime_error("wrong parameter count");
- String facespec = params[1];
- String col_expr = params[0];
-
- get_face(facespec); // validate facespec
-
- auto func = [=](HighlightContext context, DisplayBuffer& display_buffer, BufferRange)
+ auto func = [col_expr=params[0], facespec=params[1]]
+ (HighlightContext context, DisplayBuffer& display_buffer, BufferRange)
{
ColumnCount column = -1;
try
@@ -611,7 +599,7 @@ HighlighterAndId create_column_highlighter(HighlighterParameters params)
if (column < 0)
return;
- auto face = get_face(facespec);
+ auto face = context.context.faces()[facespec];
auto win_column = context.context.window().position().column;
for (auto& line : display_buffer.lines())
{
@@ -937,7 +925,7 @@ void show_whitespaces(HighlightContext context, DisplayBuffer& display_buffer, B
StringView spc, StringView lf, StringView nbsp)
{
const int tabstop = context.context.options()["tabstop"].get<int>();
- auto whitespaceface = get_face("Whitespace");
+ auto whitespaceface = context.context.faces()["Whitespace"];
auto& buffer = context.context.buffer();
auto win_column = context.context.window().position().column;
for (auto& line : display_buffer.lines())
@@ -1043,9 +1031,10 @@ private:
if (contains(context.disabled_ids, ms_id))
return;
- const Face face = get_face("LineNumbers");
- const Face face_wrapped = get_face("LineNumbersWrapped");
- const Face face_absolute = get_face("LineNumberCursor");
+ auto& faces = context.context.faces();
+ const Face face = faces["LineNumbers"];
+ const Face face_wrapped = faces["LineNumbersWrapped"];
+ const Face face_absolute = faces["LineNumberCursor"];
int digit_count = compute_digit_count(context.context);
char format[16];
@@ -1102,7 +1091,7 @@ constexpr StringView LineNumbersHighlighter::ms_id;
void show_matching_char(HighlightContext context, DisplayBuffer& display_buffer, BufferRange)
{
- const Face face = get_face("MatchingChar");
+ const Face face = context.context.faces()["MatchingChar"];
using CodepointPair = std::pair<Codepoint, Codepoint>;
static const CodepointPair matching_chars[] = { { '(', ')' }, { '{', '}' }, { '[', ']' }, { '<', '>' } };
const auto range = display_buffer.range();
@@ -1162,10 +1151,11 @@ HighlighterAndId create_matching_char_highlighter(HighlighterParameters params)
void highlight_selections(HighlightContext context, DisplayBuffer& display_buffer, BufferRange)
{
const auto& buffer = context.context.buffer();
- const Face faces[6] = {
- get_face("PrimarySelection"), get_face("SecondarySelection"),
- get_face("PrimaryCursor"), get_face("SecondaryCursor"),
- get_face("PrimaryCursorEol"), get_face("SecondaryCursorEol"),
+ const auto& faces = context.context.faces();
+ const Face sel_faces[6] = {
+ faces["PrimarySelection"], faces["SecondarySelection"],
+ faces["PrimaryCursor"], faces["SecondaryCursor"],
+ faces["PrimaryCursorEol"], faces["SecondaryCursorEol"],
};
const auto& selections = context.context.selections();
@@ -1178,7 +1168,7 @@ void highlight_selections(HighlightContext context, DisplayBuffer& display_buffe
const bool primary = (i == selections.main_index());
highlight_range(display_buffer, begin, end, false,
- apply_face(faces[primary ? 0 : 1]));
+ apply_face(sel_faces[primary ? 0 : 1]));
}
for (size_t i = 0; i < selections.size(); ++i)
{
@@ -1187,14 +1177,14 @@ void highlight_selections(HighlightContext context, DisplayBuffer& display_buffe
const bool primary = (i == selections.main_index());
const bool eol = buffer[coord.line].length() - 1 == coord.column;
highlight_range(display_buffer, coord, buffer.char_next(coord), false,
- apply_face(faces[2 + (eol ? 2 : 0) + (primary ? 0 : 1)]));
+ apply_face(sel_faces[2 + (eol ? 2 : 0) + (primary ? 0 : 1)]));
}
}
void expand_unprintable(HighlightContext context, DisplayBuffer& display_buffer, BufferRange)
{
auto& buffer = context.context.buffer();
- auto error = get_face("Error");
+ auto error = context.context.faces()["Error"];
for (auto& line : display_buffer.lines())
{
for (auto atom_it = line.begin(); atom_it != line.end(); ++atom_it)
@@ -1281,7 +1271,6 @@ struct FlagLinesHighlighter : Highlighter
const String& option_name = params[1];
const String& default_face = params[0];
- get_face(default_face); // validate param
// throw if wrong option type
GlobalScope::instance().options()[option_name].get<LineAndSpecList>();
@@ -1296,14 +1285,14 @@ private:
auto& buffer = context.context.buffer();
update_line_specs_ifn(buffer, line_flags);
- auto def_face = get_face(m_default_face);
+ auto def_face = context.context.faces()[m_default_face];
Vector<DisplayLine> display_lines;
auto& lines = line_flags.list;
try
{
for (auto& line : lines)
{
- display_lines.push_back(parse_display_line(std::get<1>(line)));
+ display_lines.push_back(parse_display_line(std::get<1>(line), context.context.faces()));
for (auto& atom : display_lines.back())
atom.face = merge_faces(def_face, atom.face);
}
@@ -1350,7 +1339,7 @@ private:
try
{
for (auto& line : line_flags.list)
- width = std::max(parse_display_line(std::get<1>(line)).length(), width);
+ width = std::max(parse_display_line(std::get<1>(line), context.context.faces()).length(), width);
}
catch (runtime_error& err)
{
@@ -1471,7 +1460,7 @@ private:
auto& r = std::get<0>(range);
if (buffer.is_valid(r.first) and (buffer.is_valid(r.last) and not buffer.is_end(r.last)))
highlight_range(display_buffer, r.first, buffer.char_next(r.last), false,
- apply_face(get_face(std::get<1>(range))));
+ apply_face(context.context.faces()[std::get<1>(range)]));
}
catch (runtime_error&)
{}
@@ -1513,7 +1502,7 @@ private:
auto& r = std::get<0>(range);
if (buffer.is_valid(r.first) and buffer.is_valid(r.last))
{
- auto replacement = parse_display_line(std::get<1>(range));
+ auto replacement = parse_display_line(std::get<1>(range), context.context.faces());
replace_range(display_buffer, r.first, buffer.char_next(r.last),
[&](DisplayLine& line, int beg_idx, int end_idx){
auto it = line.erase(line.begin() + beg_idx, line.begin() + end_idx);
diff --git a/src/hook_manager.cc b/src/hook_manager.cc
index d5238de6..b869c261 100644
--- a/src/hook_manager.cc
+++ b/src/hook_manager.cc
@@ -133,7 +133,7 @@ void HookManager::run_hook(StringView hook_name, StringView param, Context& cont
if (hook_error)
context.print_status({
format("Error running hooks for '{}' '{}', see *debug* buffer",
- hook_name, param), get_face("Error") });
+ hook_name, param), context.faces()["Error"] });
if (profile)
{
diff --git a/src/input_handler.cc b/src/input_handler.cc
index 07909d60..2ee1d40d 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -251,7 +251,7 @@ public:
{
long long new_val = (long long)m_params.count * 10 + *cp - '0';
if (new_val > std::numeric_limits<int>::max())
- context().print_status({ "parameter overflowed", get_face("Error") });
+ context().print_status({ "parameter overflowed", context().faces()["Error"] });
else
m_params.count = new_val;
}
@@ -277,7 +277,7 @@ public:
else
context.print_status(
{ format("invalid register '{}'", *cp),
- get_face("Error") });
+ context.faces()["Error"] });
}, "enter target register", register_doc);
}
else
@@ -319,19 +319,19 @@ public:
auto num_sel = context().selections().size();
auto main_index = context().selections().main_index();
if (num_sel == 1)
- atoms.emplace_back(format("{} sel", num_sel), get_face("StatusLineInfo"));
+ atoms.emplace_back(format("{} sel", num_sel), context().faces()["StatusLineInfo"]);
else
- atoms.emplace_back(format("{} sels ({})", num_sel, main_index + 1), get_face("StatusLineInfo"));
+ atoms.emplace_back(format("{} sels ({})", num_sel, main_index + 1), context().faces()["StatusLineInfo"]);
if (m_params.count != 0)
{
- atoms.emplace_back(" param=", get_face("StatusLineInfo"));
- atoms.emplace_back(to_string(m_params.count), get_face("StatusLineValue"));
+ atoms.emplace_back(" param=", context().faces()["StatusLineInfo"]);
+ atoms.emplace_back(to_string(m_params.count), context().faces()["StatusLineValue"]);
}
if (m_params.reg)
{
- atoms.emplace_back(" reg=", get_face("StatusLineInfo"));
- atoms.emplace_back(StringView(m_params.reg).str(), get_face("StatusLineValue"));
+ atoms.emplace_back(" reg=", context().faces()["StatusLineInfo"]);
+ atoms.emplace_back(StringView(m_params.reg).str(), context().faces()["StatusLineValue"]);
}
return atoms;
}
@@ -425,6 +425,8 @@ void to_prev_word_begin(CharCount& pos, StringView line)
class LineEditor
{
public:
+ LineEditor(const FaceRegistry& faces) : m_faces{faces} {}
+
void handle_key(Key key)
{
if (key == Key::Left or key == alt('h'))
@@ -528,8 +530,8 @@ public:
const bool empty = m_line.empty();
StringView str = empty ? m_empty_text : m_line;
- const Face line_face = get_face(empty ? "StatusLineInfo" : "StatusLine");
- const Face cursor_face = get_face("StatusCursor");
+ const Face line_face = m_faces[empty ? "StatusLineInfo" : "StatusLine"];
+ const Face cursor_face = m_faces["StatusCursor"];
if (m_cursor_pos == str.char_length())
return DisplayLine{{ { fix_atom_text(str.substr(m_display_pos, width-1)), line_face },
@@ -545,6 +547,8 @@ private:
String m_line;
StringView m_empty_text = {};
+
+ const FaceRegistry& m_faces;
};
class Menu : public InputMode
@@ -554,7 +558,8 @@ public:
MenuCallback callback)
: InputMode(input_handler),
m_callback(std::move(callback)), m_choices(choices.begin(), choices.end()),
- m_selected(m_choices.begin())
+ m_selected(m_choices.begin()),
+ m_filter_editor{context().faces()}
{
if (not context().has_client())
return;
@@ -648,14 +653,14 @@ public:
auto prompt = "filter:"_str;
auto width = context().client().dimensions().column - prompt.column_length();
auto display_line = m_filter_editor.build_display_line(width);
- display_line.insert(display_line.begin(), { prompt, get_face("Prompt") });
+ display_line.insert(display_line.begin(), { prompt, context().faces()["Prompt"] });
context().print_status(display_line);
}
}
DisplayLine mode_line() const override
{
- return { "menu", get_face("StatusLineMode") };
+ return { "menu", context().faces()["StatusLineMode"] };
}
KeymapMode keymap_mode() const override { return KeymapMode::Menu; }
@@ -714,7 +719,8 @@ public:
m_line_changed = false;
}
context().hooks().run_hook("PromptIdle", "", context());
- }}
+ }},
+ m_line_editor{context().faces()}
{
m_history_it = ms_history[m_prompt].end();
m_line_editor.reset(std::move(initstr), m_empty_text);
@@ -884,7 +890,7 @@ public:
}
catch (std::runtime_error& error)
{
- context().print_status({error.what(), get_face("Error")});
+ context().print_status({error.what(), context().faces()["Error"]});
return;
}
}
@@ -912,7 +918,7 @@ public:
DisplayLine mode_line() const override
{
- return { "prompt", get_face("StatusLineMode") };
+ return { "prompt", context().faces()["StatusLineMode"] };
}
KeymapMode keymap_mode() const override { return KeymapMode::Prompt; }
@@ -1046,7 +1052,7 @@ public:
DisplayLine mode_line() const override
{
- return { "enter key", get_face("StatusLineMode") };
+ return { "enter key", context().faces()["StatusLineMode"] };
}
KeymapMode keymap_mode() const override { return m_keymap_mode; }
@@ -1257,7 +1263,7 @@ public:
context().buffer().commit_undo_group();
context().print_status({ format("committed change #{}",
context().buffer().current_history_id()),
- get_face("Information") });
+ context().faces()["Information"] });
}
else if (key == ctrl('v'))
{
@@ -1291,9 +1297,10 @@ public:
{
auto num_sel = context().selections().size();
auto main_index = context().selections().main_index();
- return {AtomList{ { "insert", get_face("StatusLineMode") },
- { " ", get_face("StatusLine") },
- { format( "{} sels ({})", num_sel, main_index + 1), get_face("StatusLineInfo") } }};
+ return {AtomList{ { "insert", context().faces()["StatusLineMode"] },
+ { " ", context().faces()["StatusLine"] },
+ { format( "{} sels ({})", num_sel, main_index + 1),
+ context().faces()["StatusLineInfo"] } }};
}
KeymapMode keymap_mode() const override { return KeymapMode::Insert; }
diff --git a/src/insert_completer.cc b/src/insert_completer.cc
index 542a1b8a..1785648c 100644
--- a/src/insert_completer.cc
+++ b/src/insert_completer.cc
@@ -89,7 +89,9 @@ WordDB& get_word_db(const Buffer& buffer)
}
template<bool other_buffers>
-InsertCompletion complete_word(const SelectionList& sels, const OptionManager& options)
+InsertCompletion complete_word(const SelectionList& sels,
+ const OptionManager& options,
+ const FaceRegistry& faces)
{
ConstArrayView<Codepoint> extra_word_chars = options["extra_word_chars"].get<Vector<Codepoint, MemoryDomain::Options>>();
auto is_word_pred = [extra_word_chars](Codepoint c) { return is_word(c, extra_word_chars); };
@@ -190,7 +192,7 @@ InsertCompletion complete_word(const SelectionList& sels, const OptionManager& o
const auto pad_len = longest + 1 - first->candidate().char_length();
menu_entry.push_back(first->candidate().str());
menu_entry.push_back(String{' ', pad_len});
- menu_entry.push_back({ first->buffer->display_name(), get_face("MenuInfo") });
+ menu_entry.push_back({ first->buffer->display_name(), faces["MenuInfo"] });
}
else
menu_entry.push_back(first->candidate().str());
@@ -205,7 +207,8 @@ InsertCompletion complete_word(const SelectionList& sels, const OptionManager& o
template<bool require_slash>
InsertCompletion complete_filename(const SelectionList& sels,
- const OptionManager& options)
+ const OptionManager& options,
+ const FaceRegistry&)
{
const Buffer& buffer = sels.buffer();
auto pos = buffer.iterator_at(sels.main().cursor());
@@ -268,6 +271,7 @@ InsertCompletion complete_filename(const SelectionList& sels,
InsertCompletion complete_option(const SelectionList& sels,
const OptionManager& options,
+ const FaceRegistry& faces,
StringView option_name)
{
const Buffer& buffer = sels.buffer();
@@ -323,7 +327,7 @@ InsertCompletion complete_option(const SelectionList& sels,
match.docstring = std::get<1>(candidate);
auto& menu = std::get<2>(candidate);
match.menu_entry = not menu.empty() ?
- parse_display_line(expand_tabs(menu, tabstop, column))
+ parse_display_line(expand_tabs(menu, tabstop, column), faces)
: DisplayLine{ expand_tabs(menu, tabstop, column) };
matches.push_back(std::move(match));
@@ -353,7 +357,9 @@ InsertCompletion complete_option(const SelectionList& sels,
}
template<bool other_buffers>
-InsertCompletion complete_line(const SelectionList& sels, const OptionManager& options)
+InsertCompletion complete_line(const SelectionList& sels,
+ const OptionManager& options,
+ const FaceRegistry&)
{
const Buffer& buffer = sels.buffer();
BufferCoord cursor_pos = sels.main().cursor();
@@ -403,7 +409,7 @@ InsertCompletion complete_line(const SelectionList& sels, const OptionManager& o
}
InsertCompleter::InsertCompleter(Context& context)
- : m_context(context), m_options(context.options())
+ : m_context(context), m_options(context.options()), m_faces(context.faces())
{
m_options.register_watcher(*this);
}
@@ -516,8 +522,10 @@ bool InsertCompleter::setup_ifn()
try_complete(complete_filename<true>))
return true;
if (completer.mode == InsertCompleterDesc::Option and
- try_complete([&](const SelectionList& sels, const OptionManager& options) {
- return complete_option(sels, options, *completer.param);
+ try_complete([&](const SelectionList& sels,
+ const OptionManager& options,
+ const FaceRegistry& faces) {
+ return complete_option(sels, options, faces, *completer.param);
}))
return true;
if (completer.mode == InsertCompleterDesc::Word and
@@ -583,7 +591,7 @@ bool InsertCompleter::try_complete(Func complete_func)
auto& sels = m_context.selections();
try
{
- m_completions = complete_func(sels, m_options);
+ m_completions = complete_func(sels, m_options, m_faces);
}
catch (runtime_error& e)
{
diff --git a/src/insert_completer.hh b/src/insert_completer.hh
index a47a4267..15244bf1 100644
--- a/src/insert_completer.hh
+++ b/src/insert_completer.hh
@@ -13,6 +13,7 @@ namespace Kakoune
struct SelectionList;
struct Key;
+class FaceRegistry;
struct InsertCompleterDesc
{
@@ -100,12 +101,15 @@ private:
void menu_show();
- Context& m_context;
- OptionManager& m_options;
- InsertCompletion m_completions;
- int m_current_candidate = -1;
+ Context& m_context;
+ OptionManager& m_options;
+ const FaceRegistry& m_faces;
+ InsertCompletion m_completions;
+ int m_current_candidate = -1;
- using CompleteFunc = InsertCompletion (const SelectionList& sels, const OptionManager& options);
+ using CompleteFunc = InsertCompletion (const SelectionList& sels,
+ const OptionManager& options,
+ const FaceRegistry& faces);
CompleteFunc* m_explicit_completer = nullptr;
};
diff --git a/src/main.cc b/src/main.cc
index b7c62aec..8d6b2b67 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -50,7 +50,8 @@ static const char* startup_info =
" * selections merging behaviour is now a bit more complex again\n"
" * 'x' will only jump to next line if full line is already selected\n"
" * WORD text object moved to <a-w> instead of W for consistency\n"
-" * rotate main selection moved to ), rotate content to <a-)>, ( for backward\n";
+" * rotate main selection moved to ), rotate content to <a-)>, ( for backward\n"
+" * faces are now scoped, set-face command takes an additional scope parameter\n";
struct startup_error : runtime_error
{
@@ -585,7 +586,6 @@ int run_server(StringView session, StringView server_init,
RegisterManager register_manager;
HighlighterRegistry highlighter_registry;
DefinedHighlighters defined_highlighters;
- FaceRegistry face_registry;
ClientManager client_manager;
BufferManager buffer_manager;
@@ -667,7 +667,7 @@ int run_server(StringView session, StringView server_init,
if (startup_error)
local_client->print_status({
"error during startup, see *debug* buffer for details",
- get_face("Error")
+ local_client->context().faces()["Error"]
});
if (flags & ServerFlags::StartupInfo)
diff --git a/src/normal.cc b/src/normal.cc
index b9f9b7f4..4662a23d 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -444,7 +444,7 @@ void command(Context& context, NormalParams params)
context.input_handler().prompt(
":", {}, context.main_sel_register_value(':').str(),
- get_face("Prompt"), PromptFlags::DropHistoryEntriesWithBlankPrefix,
+ context.faces()["Prompt"], PromptFlags::DropHistoryEntriesWithBlankPrefix,
[](const Context& context, CompletionFlags flags,
StringView cmd_line, ByteCount pos) {
return CommandManager::instance().complete(context, flags, cmd_line, pos);
@@ -456,7 +456,7 @@ void command(Context& context, NormalParams params)
if (event == PromptEvent::Change)
{
auto info = CommandManager::instance().command_info(context, cmdline);
- context.input_handler().set_prompt_face(get_face(info ? "Prompt" : "Error"));
+ context.input_handler().set_prompt_face(context.faces()[info ? "Prompt" : "Error"]);
auto autoinfo = context.options()["autoinfo"].get<AutoInfo>();
if (autoinfo & AutoInfo::Command)
@@ -524,7 +524,7 @@ void pipe(Context& context, NormalParams)
{
const char* prompt = replace ? "pipe:" : "pipe-to:";
context.input_handler().prompt(
- prompt, {}, context.main_sel_register_value("|").str(), get_face("Prompt"),
+ prompt, {}, context.main_sel_register_value("|").str(), context.faces()["Prompt"],
PromptFlags::DropHistoryEntriesWithBlankPrefix,
shell_complete,
[](StringView cmdline, PromptEvent event, Context& context)
@@ -599,7 +599,7 @@ void insert_output(Context& context, NormalParams)
{
const char* prompt = mode == InsertMode::Insert ? "insert-output:" : "append-output:";
context.input_handler().prompt(
- prompt, {}, context.main_sel_register_value("|").str(), get_face("Prompt"),
+ prompt, {}, context.main_sel_register_value("|").str(), context.faces()["Prompt"],
PromptFlags::DropHistoryEntriesWithBlankPrefix,
shell_complete,
[](StringView cmdline, PromptEvent event, Context& context)
@@ -628,7 +628,7 @@ void yank(Context& context, NormalParams params)
RegisterManager::instance()[reg].set(context, context.selections_content());
context.print_status({ format("yanked {} selections to register {}",
context.selections().size(), reg),
- get_face("Information") });
+ context.faces()["Information"] });
}
template<bool yank>
@@ -733,7 +733,7 @@ void regex_prompt(Context& context, String prompt, String default_regex, T func)
DisplayCoord position = context.has_window() ? context.window().position() : DisplayCoord{};
SelectionList selections = context.selections();
context.input_handler().prompt(
- std::move(prompt), {}, default_regex, get_face("Prompt"),
+ std::move(prompt), {}, default_regex, context.faces()["Prompt"],
PromptFlags::None, complete_nothing,
[=](StringView str, PromptEvent event, Context& context) mutable {
try
@@ -749,7 +749,7 @@ void regex_prompt(Context& context, String prompt, String default_regex, T func)
if (context.has_window())
context.window().set_position(position);
- context.input_handler().set_prompt_face(get_face("Prompt"));
+ context.input_handler().set_prompt_face(context.faces()["Prompt"]);
}
if (not incsearch and event == PromptEvent::Change)
@@ -766,7 +766,7 @@ void regex_prompt(Context& context, String prompt, String default_regex, T func)
if (event == PromptEvent::Validate)
throw;
else
- context.input_handler().set_prompt_face(get_face("Error"));
+ context.input_handler().set_prompt_face(context.faces()["Error"]);
}
catch (runtime_error&)
{
@@ -852,7 +852,7 @@ void search_next(Context& context, NormalParams params)
} while (--params.count > 0);
if (main_wrapped)
- context.print_status({"main selection search wrapped around buffer", get_face("Information")});
+ context.print_status({"main selection search wrapped around buffer", context.faces()["Information"]});
}
else
throw runtime_error("no search pattern");
@@ -877,7 +877,7 @@ void use_selection_as_search_pattern(Context& context, NormalParams params)
context.print_status({
format("register '{}' set to '{}'", reg, fix_atom_text(patterns[sels.main_index()])),
- get_face("Information") });
+ context.faces()["Information"] });
RegisterManager::instance()[reg].set(context, patterns);
@@ -1059,7 +1059,7 @@ void keep(Context& context, NormalParams params)
void keep_pipe(Context& context, NormalParams)
{
context.input_handler().prompt(
- "keep pipe:", {}, {}, get_face("Prompt"),
+ "keep pipe:", {}, {}, context.faces()["Prompt"],
PromptFlags::DropHistoryEntriesWithBlankPrefix, shell_complete,
[](StringView cmdline, PromptEvent event, Context& context) {
if (event != PromptEvent::Validate)
@@ -1216,7 +1216,7 @@ void select_object(Context& context, NormalParams params)
AutoInfo::Command, context);
context.input_handler().prompt(
- "object desc:", {}, {}, get_face("Prompt"),
+ "object desc:", {}, {}, context.faces()["Prompt"],
PromptFlags::None, complete_nothing,
[count,info](StringView cmdline, PromptEvent event, Context& context) {
if (event != PromptEvent::Change)
@@ -1499,7 +1499,7 @@ void push_selections(Context& context, NormalParams)
{
context.push_jump();
context.print_status({ format("saved {} selections", context.selections().size()),
- get_face("Information") });
+ context.faces()["Information"] });
}
void align(Context& context, NormalParams)
@@ -1813,7 +1813,7 @@ void save_selections(Context& context, NormalParams params)
RegisterManager::instance()[reg].set(context, desc);
context.print_status({format("{} {} selections to register '{}'",
combine ? "Combined" : "Saved", sels.size(), reg),
- get_face("Information")});
+ context.faces()["Information"]});
};
if (combine and not empty)
@@ -1833,7 +1833,7 @@ void restore_selections(Context& context, NormalParams params)
context.selections_write_only() = std::move(sels);
context.print_status({format("{} {} selections from register '{}'",
combine ? "Combined" : "Restored", size, reg),
- get_face("Information")});
+ context.faces()["Information"]});
};
if (not combine)
@@ -1890,7 +1890,7 @@ void move_in_history(Context& context, NormalParams params)
context.print_status({ format("moved to change #{} ({})",
history_id, max_history_id),
- get_face("Information") });
+ context.faces()["Information"] });
}
else
throw runtime_error(format("no such change: #{} ({})",
diff --git a/src/scope.hh b/src/scope.hh
index c4b52586..b01799ed 100644
--- a/src/scope.hh
+++ b/src/scope.hh
@@ -2,10 +2,11 @@
#define scope_hh_INCLUDED
#include "alias_registry.hh"
+#include "face_registry.hh"
+#include "highlighter_group.hh"
#include "hook_manager.hh"
#include "keymap_manager.hh"
#include "option_manager.hh"
-#include "highlighter_group.hh"
#include "utils.hh"
namespace Kakoune
@@ -19,6 +20,7 @@ public:
m_hooks(parent.hooks()),
m_keymaps(parent.keymaps()),
m_aliases(parent.aliases()),
+ m_faces(parent.faces()),
m_highlighters(parent.highlighters()) {}
OptionManager& options() { return m_options; }
@@ -29,6 +31,8 @@ public:
const KeymapManager& keymaps() const { return m_keymaps; }
AliasRegistry& aliases() { return m_aliases; }
const AliasRegistry& aliases() const { return m_aliases; }
+ FaceRegistry& faces() { return m_faces; }
+ const FaceRegistry& faces() const { return m_faces; }
Highlighters& highlighters() { return m_highlighters; }
const Highlighters& highlighters() const { return m_highlighters; }
@@ -40,6 +44,7 @@ private:
HookManager m_hooks;
KeymapManager m_keymaps;
AliasRegistry m_aliases;
+ FaceRegistry m_faces;
Highlighters m_highlighters;
};
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index 2d0744e0..a6d4a954 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -268,7 +268,7 @@ std::pair<String, int> ShellManager::eval(
client.print_status({ format("waiting for shell command to finish ({}s)",
duration_cast<seconds>(wait_duration).count()),
- get_face("Information") });
+ context.faces()["Information"] });
client.redraw_ifn();
}
timer.set_next_date(Clock::now() + wait_timeout);