summaryrefslogtreecommitdiff
path: root/src/face_registry.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-04-10 19:57:16 +1000
committerMaxime Coste <mawww@kakoune.org>2018-04-10 19:57:16 +1000
commit9c82f6586cde0ac1111a1e96a705fb624e79a564 (patch)
tree029cce3ff07ba596279b701164105d5bf43fe39c /src/face_registry.cc
parenta2978bff257ac57b68cebdafaba4c7d4fec7f4d9 (diff)
FaceRegistry: Support referencing a named face from a parent scope
Diffstat (limited to 'src/face_registry.cc')
-rw-r--r--src/face_registry.cc32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/face_registry.cc b/src/face_registry.cc
index 880ef6e9..5a7a8df6 100644
--- a/src/face_registry.cc
+++ b/src/face_registry.cc
@@ -98,26 +98,26 @@ void FaceRegistry::add_face(StringView name, StringView facedesc, bool override)
if (name == facedesc)
throw runtime_error(format("cannot alias face '{}' to itself", name));
- FaceOrAlias& face = m_faces[name];
- auto it = m_faces.find(facedesc);
- if (it != m_faces.end())
+ for (auto it = m_faces.find(facedesc);
+ it != m_faces.end() and not it->value.alias.empty();
+ it = m_faces.find(it->value.alias))
{
- while (it != m_faces.end())
- {
- if (it->value.alias.empty())
- break;
- if (it->value.alias == name)
- throw runtime_error("face cycle detected");
- it = m_faces.find(it->value.alias);
- }
-
- face.alias = facedesc.str();
+ if (it->value.alias == name)
+ throw runtime_error("face cycle detected");
}
- else
+
+ FaceOrAlias& face = m_faces[name];
+
+ for (auto* registry = this; registry != nullptr; registry = registry->m_parent.get())
{
- face.alias = "";
- face.face = parse_face(facedesc);
+ if (not registry->m_faces.contains(facedesc))
+ continue;
+ face.alias = facedesc.str(); // This is referencing another face
+ return;
}
+
+ face.alias = "";
+ face.face = parse_face(facedesc);
}
void FaceRegistry::remove_face(StringView name)