summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-08-09 18:33:32 +1000
committerMaxime Coste <mawww@kakoune.org>2024-08-12 20:02:11 +1000
commit6ed01f402b3a54495c8d9e462b7674864fbbe402 (patch)
tree2a5c3fcb1da1c8577fe58a87fdd3376c44b8ba49 /src
parent1b2100753e4bdc65b1c6a78662ab5eeb7eaaa8d3 (diff)
Reduce headers dependency graph
Move more code into the implementation files to reduce the amount of code pulled by headers.
Diffstat (limited to 'src')
-rw-r--r--src/alias_registry.hh1
-rw-r--r--src/assert.cc1
-rw-r--r--src/completion.cc1
-rw-r--r--src/display_buffer.hh2
-rw-r--r--src/file.hh1
-rw-r--r--src/hook_manager.hh1
-rw-r--r--src/input_handler.hh1
-rw-r--r--src/json.hh1
-rw-r--r--src/json_ui.cc1
-rw-r--r--src/keymap_manager.cc1
-rw-r--r--src/keys.cc1
-rw-r--r--src/normal.cc2
-rw-r--r--src/option_manager.hh1
-rw-r--r--src/option_types.hh2
-rw-r--r--src/parameters_parser.cc1
-rw-r--r--src/ranked_match.cc1
-rw-r--r--src/regex_impl.cc1
-rw-r--r--src/regex_impl.hh1
-rw-r--r--src/register_manager.cc1
-rw-r--r--src/register_manager.hh1
-rw-r--r--src/selection.cc34
-rw-r--r--src/selection.hh45
-rw-r--r--src/selectors.hh1
-rw-r--r--src/unicode.hh9
24 files changed, 79 insertions, 33 deletions
diff --git a/src/alias_registry.hh b/src/alias_registry.hh
index 1b7a49eb..32f9e2fb 100644
--- a/src/alias_registry.hh
+++ b/src/alias_registry.hh
@@ -3,6 +3,7 @@
#include "safe_ptr.hh"
#include "string.hh"
+#include "ranges.hh"
#include "hash_map.hh"
namespace Kakoune
diff --git a/src/assert.cc b/src/assert.cc
index e755e8ba..7be769a1 100644
--- a/src/assert.cc
+++ b/src/assert.cc
@@ -1,6 +1,7 @@
#include "assert.hh"
#include "backtrace.hh"
+#include "format.hh"
#include "buffer_utils.hh"
#include "exception.hh"
diff --git a/src/completion.cc b/src/completion.cc
index 762a0413..60e79e07 100644
--- a/src/completion.cc
+++ b/src/completion.cc
@@ -2,6 +2,7 @@
#include "file.hh"
#include "context.hh"
#include "option_types.hh"
+#include "option_manager.hh"
#include "regex.hh"
namespace Kakoune
diff --git a/src/display_buffer.hh b/src/display_buffer.hh
index c4ea6fb5..b1a18098 100644
--- a/src/display_buffer.hh
+++ b/src/display_buffer.hh
@@ -7,6 +7,8 @@
#include "string.hh"
#include "vector.hh"
#include "hash_map.hh"
+#include "ranges.hh"
+
#include <functional>
namespace Kakoune
diff --git a/src/file.hh b/src/file.hh
index cfc68ac2..9411fd78 100644
--- a/src/file.hh
+++ b/src/file.hh
@@ -6,6 +6,7 @@
#include "meta.hh"
#include "string.hh"
#include "units.hh"
+#include "constexpr_utils.hh"
#include "vector.hh"
#include <sys/types.h>
diff --git a/src/hook_manager.hh b/src/hook_manager.hh
index bee06064..114deefd 100644
--- a/src/hook_manager.hh
+++ b/src/hook_manager.hh
@@ -6,6 +6,7 @@
#include "safe_ptr.hh"
#include "meta.hh"
#include "enum.hh"
+#include "constexpr_utils.hh"
#include <memory>
diff --git a/src/input_handler.hh b/src/input_handler.hh
index dd475c92..fa7c91b1 100644
--- a/src/input_handler.hh
+++ b/src/input_handler.hh
@@ -5,6 +5,7 @@
#include "constexpr_utils.hh"
#include "context.hh"
#include "env_vars.hh"
+#include "enum.hh"
#include "face.hh"
#include "normal.hh"
#include "optional.hh"
diff --git a/src/json.hh b/src/json.hh
index 84c14d36..6765c793 100644
--- a/src/json.hh
+++ b/src/json.hh
@@ -3,6 +3,7 @@
#include "hash_map.hh"
#include "string.hh"
+#include "string_utils.hh"
#include "value.hh"
namespace Kakoune
diff --git a/src/json_ui.cc b/src/json_ui.cc
index 01768897..1efbf2a5 100644
--- a/src/json_ui.cc
+++ b/src/json_ui.cc
@@ -8,6 +8,7 @@
#include "keys.hh"
#include "ranges.hh"
#include "string_utils.hh"
+#include "format.hh"
#include <cstdio>
#include <utility>
diff --git a/src/keymap_manager.cc b/src/keymap_manager.cc
index 583fb2e7..8894267a 100644
--- a/src/keymap_manager.cc
+++ b/src/keymap_manager.cc
@@ -4,6 +4,7 @@
#include "assert.hh"
#include "exception.hh"
#include "format.hh"
+#include "ranges.hh"
#include <algorithm>
diff --git a/src/keys.cc b/src/keys.cc
index 5ba44181..4a14e0fc 100644
--- a/src/keys.cc
+++ b/src/keys.cc
@@ -6,6 +6,7 @@
#include "unit_tests.hh"
#include "utf8_iterator.hh"
#include "utils.hh"
+#include "format.hh"
#include "string_utils.hh"
namespace Kakoune
diff --git a/src/normal.cc b/src/normal.cc
index ea183bc4..5a7c4e58 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -1841,7 +1841,7 @@ SelectionList read_selections_from_register(char reg, const Context& context)
const auto buffer_name = StringView{ content[0].begin (), end_content[1].begin () - 1 };
Buffer& buffer = BufferManager::instance().get_buffer(buffer_name);
- return selection_list_from_strings(buffer, ColumnType::Byte, content | skip(1), timestamp, main);
+ return selection_list_from_strings(buffer, ColumnType::Byte, content.subrange(1), timestamp, main);
}
enum class CombineOp
diff --git a/src/option_manager.hh b/src/option_manager.hh
index 3a4bb5a5..480b589b 100644
--- a/src/option_manager.hh
+++ b/src/option_manager.hh
@@ -8,6 +8,7 @@
#include "ranges.hh"
#include "utils.hh"
#include "vector.hh"
+#include "format.hh"
#include "string_utils.hh"
#include <memory>
diff --git a/src/option_types.hh b/src/option_types.hh
index 40d367df..fedc476f 100644
--- a/src/option_types.hh
+++ b/src/option_types.hh
@@ -7,9 +7,9 @@
#include "flags.hh"
#include "hash_map.hh"
#include "option.hh"
-#include "ranges.hh"
#include "string.hh"
#include "string_utils.hh"
+#include "format.hh"
#include "units.hh"
#include <tuple>
diff --git a/src/parameters_parser.cc b/src/parameters_parser.cc
index 75575323..5d2858ed 100644
--- a/src/parameters_parser.cc
+++ b/src/parameters_parser.cc
@@ -1,5 +1,6 @@
#include "parameters_parser.hh"
+#include "ranges.hh"
#include "flags.hh"
namespace Kakoune
diff --git a/src/ranked_match.cc b/src/ranked_match.cc
index a13decdf..87bcece7 100644
--- a/src/ranked_match.cc
+++ b/src/ranked_match.cc
@@ -4,6 +4,7 @@
#include "unit_tests.hh"
#include "utf8_iterator.hh"
#include "optional.hh"
+#include "ranges.hh"
#include <algorithm>
diff --git a/src/regex_impl.cc b/src/regex_impl.cc
index 2cebf964..f6393b56 100644
--- a/src/regex_impl.cc
+++ b/src/regex_impl.cc
@@ -9,6 +9,7 @@
#include "format.hh"
#include "vector.hh"
#include "utils.hh"
+#include "ranges.hh"
#include <cstdio>
#include <cstring>
diff --git a/src/regex_impl.hh b/src/regex_impl.hh
index b772169d..7f3eb495 100644
--- a/src/regex_impl.hh
+++ b/src/regex_impl.hh
@@ -9,6 +9,7 @@
#include "utils.hh"
#include <bit>
+#include <algorithm>
namespace Kakoune
{
diff --git a/src/register_manager.cc b/src/register_manager.cc
index bb198dc6..254104a4 100644
--- a/src/register_manager.cc
+++ b/src/register_manager.cc
@@ -4,6 +4,7 @@
#include "context.hh"
#include "hash_map.hh"
#include "format.hh"
+#include "hook_manager.hh"
namespace Kakoune
{
diff --git a/src/register_manager.hh b/src/register_manager.hh
index 2e760e6f..c7ca8590 100644
--- a/src/register_manager.hh
+++ b/src/register_manager.hh
@@ -6,6 +6,7 @@
#include "exception.hh"
#include "utils.hh"
#include "hash_map.hh"
+#include "ranges.hh"
#include "string.hh"
#include "vector.hh"
diff --git a/src/selection.cc b/src/selection.cc
index f0f0270c..03dd4721 100644
--- a/src/selection.cc
+++ b/src/selection.cc
@@ -7,6 +7,8 @@
namespace Kakoune
{
+SelectionList::~SelectionList() = default;
+
SelectionList::SelectionList(Buffer& buffer, Selection s, size_t timestamp)
: m_selections({ std::move(s) }), m_buffer(&buffer), m_timestamp(timestamp)
{
@@ -27,6 +29,11 @@ SelectionList::SelectionList(Buffer& buffer, Vector<Selection> list, size_t time
SelectionList::SelectionList(Buffer& buffer, Vector<Selection> list)
: SelectionList(buffer, std::move(list), buffer.timestamp()) {}
+SelectionList::SelectionList(const SelectionList&) = default;
+SelectionList::SelectionList(SelectionList&&) = default;
+SelectionList& SelectionList::operator=(const SelectionList&) = default;
+SelectionList& SelectionList::operator=(SelectionList&&) = default;
+
void SelectionList::remove(size_t index)
{
m_selections.erase(begin() + index);
@@ -538,4 +545,31 @@ Selection selection_from_string(ColumnType column_type, const Buffer& buffer, St
return Selection{anchor, cursor};
}
+SelectionList selection_list_from_strings(Buffer& buffer, ColumnType column_type, ConstArrayView<String> descs, size_t timestamp, size_t main, ColumnCount tabstop)
+{
+ if ((column_type != ColumnType::Byte and timestamp != buffer.timestamp()) or timestamp > buffer.timestamp())
+ throw runtime_error{format("invalid timestamp '{}'", timestamp)};
+
+ auto from_string = [&](StringView desc) {
+ return selection_from_string(column_type, buffer, desc, tabstop);
+ };
+
+ auto sels = descs | transform(from_string) | gather<Vector<Selection>>();
+ if (sels.empty())
+ throw runtime_error{"empty selection description"};
+ if (main >= sels.size())
+ throw runtime_error{"invalid main selection index"};
+
+ sort_selections(sels, main);
+ merge_overlapping_selections(sels, main);
+ if (timestamp < buffer.timestamp())
+ update_selections(sels, main, buffer, timestamp);
+ else
+ clamp_selections(sels, buffer);
+
+ SelectionList res{buffer, std::move(sels)};
+ res.set_main_index(main);
+ return res;
+}
+
}
diff --git a/src/selection.hh b/src/selection.hh
index 509a527d..ede4fa7b 100644
--- a/src/selection.hh
+++ b/src/selection.hh
@@ -1,13 +1,21 @@
#ifndef selection_hh_INCLUDED
#define selection_hh_INCLUDED
-#include "buffer.hh"
+#include "coord.hh"
+#include "range.hh"
+#include "safe_ptr.hh"
+#include "utils.hh"
+#include "string.hh"
+#include "vector.hh"
#include <limits>
namespace Kakoune
{
+class Buffer;
+using BufferRange = Range<BufferCoord>;
+
using CaptureList = Vector<String, MemoryDomain::Selections>;
constexpr ColumnCount max_column{std::numeric_limits<int>::max()};
@@ -84,11 +92,18 @@ struct SelectionList
{
static constexpr MemoryDomain Domain = MemoryDomain::Selections;
+ ~SelectionList();
SelectionList(Buffer& buffer, Selection s);
SelectionList(Buffer& buffer, Selection s, size_t timestamp);
SelectionList(Buffer& buffer, Vector<Selection> s);
SelectionList(Buffer& buffer, Vector<Selection> s, size_t timestamp);
+ SelectionList(const SelectionList&);
+ SelectionList(SelectionList&&);
+
+ SelectionList& operator=(const SelectionList&);
+ SelectionList& operator=(SelectionList&&);
+
void update(bool merge = true);
void check_invariant() const;
@@ -166,33 +181,7 @@ String selection_to_string(ColumnType column_type, const Buffer& buffer, const S
String selection_list_to_string(ColumnType column_type, const SelectionList& selections, ColumnCount tabstop = -1);
-template<typename StringArray>
-SelectionList selection_list_from_strings(Buffer& buffer, ColumnType column_type, StringArray&& descs, size_t timestamp, size_t main, ColumnCount tabstop = -1)
-{
- if ((column_type != ColumnType::Byte and timestamp != buffer.timestamp()) or timestamp > buffer.timestamp())
- throw runtime_error{format("invalid timestamp '{}'", timestamp)};
-
- auto from_string = [&](StringView desc) {
- return selection_from_string(column_type, buffer, desc, tabstop);
- };
-
- auto sels = descs | transform(from_string) | gather<Vector<Selection>>();
- if (sels.empty())
- throw runtime_error{"empty selection description"};
- if (main >= sels.size())
- throw runtime_error{"invalid main selection index"};
-
- sort_selections(sels, main);
- merge_overlapping_selections(sels, main);
- if (timestamp < buffer.timestamp())
- update_selections(sels, main, buffer, timestamp);
- else
- clamp_selections(sels, buffer);
-
- SelectionList res{buffer, std::move(sels)};
- res.set_main_index(main);
- return res;
-}
+SelectionList selection_list_from_strings(Buffer& buffer, ColumnType column_type, ConstArrayView<String> descs, size_t timestamp, size_t main, ColumnCount tabstop = -1);
}
diff --git a/src/selectors.hh b/src/selectors.hh
index a9a61314..e947250f 100644
--- a/src/selectors.hh
+++ b/src/selectors.hh
@@ -6,6 +6,7 @@
#include "meta.hh"
#include "unicode.hh"
#include "vector.hh"
+#include "constexpr_utils.hh"
namespace Kakoune
{
diff --git a/src/unicode.hh b/src/unicode.hh
index 0acf4005..5ce63f4b 100644
--- a/src/unicode.hh
+++ b/src/unicode.hh
@@ -5,7 +5,6 @@
#include <cwchar>
#include "array_view.hh"
-#include "ranges.hh"
#include "units.hh"
namespace Kakoune
@@ -75,8 +74,12 @@ enum WordType { Word, WORD };
template<WordType word_type = Word>
inline bool is_word(Codepoint c, ConstArrayView<Codepoint> extra_word_chars = {'_'}) noexcept
{
- return (c < 128 ? is_basic_alpha(c) or is_basic_digit(c) : iswalnum((wchar_t)c)) or
- contains(extra_word_chars, c);
+ if (c < 128 ? is_basic_alpha(c) or is_basic_digit(c) : iswalnum((wchar_t)c))
+ return true;
+ for (auto cp : extra_word_chars)
+ if (c == cp)
+ return true;
+ return false;
}
template<>