summaryrefslogtreecommitdiff
path: root/src/face_registry.hh
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/face_registry.hh
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/face_registry.hh')
-rw-r--r--src/face_registry.hh46
1 files changed, 27 insertions, 19 deletions
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);