summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-08-10 11:26:26 +1000
committerMaxime Coste <mawww@kakoune.org>2024-08-12 20:02:11 +1000
commit560e3631ec57d34c679e6b0faec1e0efdd18d915 (patch)
tree4b4e00ab1fefaaa4a98b3d6a7c46fab50120fd8b /src
parent6ed01f402b3a54495c8d9e462b7674864fbbe402 (diff)
Move debug utils to debug.hh/debug.cc
Lots of code includes buffer_utils.hh just for write_to_debug_buffer which pulls many unnecessary dependencies. Reorganise to reduce compile times.
Diffstat (limited to 'src')
-rw-r--r--src/assert.cc3
-rw-r--r--src/buffer_utils.cc30
-rw-r--r--src/client.cc1
-rw-r--r--src/command_manager.cc4
-rw-r--r--src/commands.cc1
-rw-r--r--src/debug.cc39
-rw-r--r--src/debug.hh40
-rw-r--r--src/hash_map.cc4
-rw-r--r--src/highlighter.cc2
-rw-r--r--src/highlighter.hh5
-rw-r--r--src/highlighters.cc1
-rw-r--r--src/hook_manager.cc2
-rw-r--r--src/input_handler.cc2
-rw-r--r--src/insert_completer.cc1
-rw-r--r--src/main.cc3
-rw-r--r--src/option.hh23
-rw-r--r--src/option_types.cc1
-rw-r--r--src/profile.hh1
-rw-r--r--src/register_manager.cc11
-rw-r--r--src/register_manager.hh5
-rw-r--r--src/remote.cc2
-rw-r--r--src/shared_string.cc3
-rw-r--r--src/shell_manager.cc2
-rw-r--r--src/window.cc4
24 files changed, 122 insertions, 68 deletions
diff --git a/src/assert.cc b/src/assert.cc
index 7be769a1..6e5fc512 100644
--- a/src/assert.cc
+++ b/src/assert.cc
@@ -2,8 +2,9 @@
#include "backtrace.hh"
#include "format.hh"
-#include "buffer_utils.hh"
+#include "file.hh"
#include "exception.hh"
+#include "debug.hh"
#include <sys/types.h>
#include <unistd.h>
diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc
index 6a66b000..28b2de05 100644
--- a/src/buffer_utils.cc
+++ b/src/buffer_utils.cc
@@ -271,36 +271,6 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll
return buffer;
}
-void write_to_debug_buffer(StringView str)
-{
- if (not BufferManager::has_instance())
- {
- write(2, str);
- write(2, "\n");
- return;
- }
-
- constexpr StringView debug_buffer_name = "*debug*";
- // Try to ensure we keep an empty line at the end of the debug buffer
- // where the user can put its cursor to scroll with new messages
- const bool eol_back = not str.empty() and str.back() == '\n';
- if (Buffer* buffer = BufferManager::instance().get_buffer_ifp(debug_buffer_name))
- {
- buffer->flags() &= ~Buffer::Flags::ReadOnly;
- auto restore = on_scope_end([buffer] { buffer->flags() |= Buffer::Flags::ReadOnly; });
-
- buffer->insert(buffer->back_coord(), eol_back ? str : str + "\n");
- }
- else
- {
- String line = str + (eol_back ? "\n" : "\n\n");
- create_buffer_from_string(
- debug_buffer_name.str(), Buffer::Flags::NoUndo | Buffer::Flags::Debug | Buffer::Flags::ReadOnly,
- line);
- }
-}
-
-
auto to_string(Buffer::HistoryId id)
{
using Result = decltype(to_string(size_t{}));
diff --git a/src/client.cc b/src/client.cc
index 8b084fd5..77fb7dcc 100644
--- a/src/client.cc
+++ b/src/client.cc
@@ -4,6 +4,7 @@
#include "context.hh"
#include "buffer_manager.hh"
#include "buffer_utils.hh"
+#include "debug.hh"
#include "file.hh"
#include "remote.hh"
#include "option.hh"
diff --git a/src/command_manager.cc b/src/command_manager.cc
index f7d094bb..3e44ab1e 100644
--- a/src/command_manager.cc
+++ b/src/command_manager.cc
@@ -2,10 +2,11 @@
#include "alias_registry.hh"
#include "assert.hh"
-#include "buffer_utils.hh"
#include "context.hh"
+#include "debug.hh"
#include "flags.hh"
#include "file.hh"
+#include "hook_manager.hh"
#include "optional.hh"
#include "option_types.hh"
#include "profile.hh"
@@ -13,6 +14,7 @@
#include "regex.hh"
#include "register_manager.hh"
#include "shell_manager.hh"
+#include "scope.hh"
#include "utils.hh"
#include "unit_tests.hh"
diff --git a/src/commands.cc b/src/commands.cc
index d22c0647..8446edf5 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -8,6 +8,7 @@
#include "command_manager.hh"
#include "completion.hh"
#include "context.hh"
+#include "debug.hh"
#include "event_manager.hh"
#include "face_registry.hh"
#include "file.hh"
diff --git a/src/debug.cc b/src/debug.cc
new file mode 100644
index 00000000..55f7e4d3
--- /dev/null
+++ b/src/debug.cc
@@ -0,0 +1,39 @@
+#include "debug.hh"
+
+#include "buffer_manager.hh"
+#include "buffer_utils.hh"
+#include "utils.hh"
+
+namespace Kakoune
+{
+
+void write_to_debug_buffer(StringView str)
+{
+ if (not BufferManager::has_instance())
+ {
+ write(2, str);
+ write(2, "\n");
+ return;
+ }
+
+ constexpr StringView debug_buffer_name = "*debug*";
+ // Try to ensure we keep an empty line at the end of the debug buffer
+ // where the user can put its cursor to scroll with new messages
+ const bool eol_back = not str.empty() and str.back() == '\n';
+ if (Buffer* buffer = BufferManager::instance().get_buffer_ifp(debug_buffer_name))
+ {
+ buffer->flags() &= ~Buffer::Flags::ReadOnly;
+ auto restore = on_scope_end([buffer] { buffer->flags() |= Buffer::Flags::ReadOnly; });
+
+ buffer->insert(buffer->back_coord(), eol_back ? str : str + "\n");
+ }
+ else
+ {
+ String line = str + (eol_back ? "\n" : "\n\n");
+ create_buffer_from_string(
+ debug_buffer_name.str(), Buffer::Flags::NoUndo | Buffer::Flags::Debug | Buffer::Flags::ReadOnly,
+ line);
+ }
+}
+
+}
diff --git a/src/debug.hh b/src/debug.hh
new file mode 100644
index 00000000..ec010460
--- /dev/null
+++ b/src/debug.hh
@@ -0,0 +1,40 @@
+#ifndef debug_hh_INCLUDED
+#define debug_hh_INCLUDED
+
+#include "constexpr_utils.hh"
+#include "enum.hh"
+#include "flags.hh"
+
+namespace Kakoune
+{
+
+class StringView;
+
+enum class DebugFlags
+{
+ None = 0,
+ Hooks = 1 << 0,
+ Shell = 1 << 1,
+ Profile = 1 << 2,
+ Keys = 1 << 3,
+ Commands = 1 << 4,
+};
+
+constexpr bool with_bit_ops(Meta::Type<DebugFlags>) { return true; }
+
+constexpr auto enum_desc(Meta::Type<DebugFlags>)
+{
+ return make_array<EnumDesc<DebugFlags>>({
+ { DebugFlags::Hooks, "hooks" },
+ { DebugFlags::Shell, "shell" },
+ { DebugFlags::Profile, "profile" },
+ { DebugFlags::Keys, "keys" },
+ { DebugFlags::Commands, "commands" },
+ });
+}
+
+void write_to_debug_buffer(StringView str);
+
+}
+
+#endif // debug_hh_INCLUDED
diff --git a/src/hash_map.cc b/src/hash_map.cc
index ae486490..c0afa4a2 100644
--- a/src/hash_map.cc
+++ b/src/hash_map.cc
@@ -2,10 +2,12 @@
#include "clock.hh"
#include "string.hh"
-#include "buffer_utils.hh"
#include "unit_tests.hh"
+#include "format.hh"
+#include "debug.hh"
#include <random>
+#include <algorithm>
#include <unordered_map>
namespace Kakoune
diff --git a/src/highlighter.cc b/src/highlighter.cc
index 86da8ac6..c6b1a13d 100644
--- a/src/highlighter.cc
+++ b/src/highlighter.cc
@@ -1,6 +1,6 @@
#include "highlighter.hh"
-#include "buffer_utils.hh"
+#include "debug.hh"
namespace Kakoune
{
diff --git a/src/highlighter.hh b/src/highlighter.hh
index 925dcaa7..c1070d9a 100644
--- a/src/highlighter.hh
+++ b/src/highlighter.hh
@@ -3,9 +3,9 @@
#include "coord.hh"
#include "completion.hh"
-#include "display_buffer.hh"
#include "exception.hh"
#include "flags.hh"
+#include "range.hh"
#include "hash_map.hh"
#include "array_view.hh"
#include "string.hh"
@@ -18,6 +18,9 @@ namespace Kakoune
{
class Context;
+class DisplayBuffer;
+
+using BufferRange = Range<BufferCoord>;
enum class HighlightPass
{
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 86985084..4b18a447 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -2,6 +2,7 @@
#include "assert.hh"
#include "buffer_utils.hh"
+#include "debug.hh"
#include "changes.hh"
#include "command_manager.hh"
#include "context.hh"
diff --git a/src/hook_manager.cc b/src/hook_manager.cc
index a1b29434..00b38677 100644
--- a/src/hook_manager.cc
+++ b/src/hook_manager.cc
@@ -1,6 +1,6 @@
#include "hook_manager.hh"
-#include "buffer_utils.hh"
+#include "debug.hh"
#include "clock.hh"
#include "command_manager.hh"
#include "context.hh"
diff --git a/src/input_handler.cc b/src/input_handler.cc
index 56999d45..615dbf10 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -1,7 +1,7 @@
#include "input_handler.hh"
#include "buffer_manager.hh"
-#include "buffer_utils.hh"
+#include "debug.hh"
#include "command_manager.hh"
#include "client.hh"
#include "event_manager.hh"
diff --git a/src/insert_completer.cc b/src/insert_completer.cc
index 73c08a43..b369359a 100644
--- a/src/insert_completer.cc
+++ b/src/insert_completer.cc
@@ -2,6 +2,7 @@
#include "buffer_manager.hh"
#include "buffer_utils.hh"
+#include "debug.hh"
#include "client.hh"
#include "command_manager.hh"
#include "changes.hh"
diff --git a/src/main.cc b/src/main.cc
index e86ffae3..21cb0446 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -1,12 +1,13 @@
#include "assert.hh"
#include "backtrace.hh"
#include "buffer.hh"
-#include "buffer_manager.hh"
#include "buffer_utils.hh"
+#include "buffer_manager.hh"
#include "client_manager.hh"
#include "command_manager.hh"
#include "commands.hh"
#include "context.hh"
+#include "debug.hh"
#include "event_manager.hh"
#include "face_registry.hh"
#include "file.hh"
diff --git a/src/option.hh b/src/option.hh
index 732fefca..b6edca0c 100644
--- a/src/option.hh
+++ b/src/option.hh
@@ -64,29 +64,6 @@ struct PrefixedList
template<typename T>
using TimestampedList = PrefixedList<size_t, T>;
-enum class DebugFlags
-{
- None = 0,
- Hooks = 1 << 0,
- Shell = 1 << 1,
- Profile = 1 << 2,
- Keys = 1 << 3,
- Commands = 1 << 4,
-};
-
-constexpr bool with_bit_ops(Meta::Type<DebugFlags>) { return true; }
-
-constexpr auto enum_desc(Meta::Type<DebugFlags>)
-{
- return make_array<EnumDesc<DebugFlags>>({
- { DebugFlags::Hooks, "hooks" },
- { DebugFlags::Shell, "shell" },
- { DebugFlags::Profile, "profile" },
- { DebugFlags::Keys, "keys" },
- { DebugFlags::Commands, "commands" },
- });
-}
-
}
#endif // option_hh_INCLUDED
diff --git a/src/option_types.cc b/src/option_types.cc
index a1eeb418..f005c1db 100644
--- a/src/option_types.cc
+++ b/src/option_types.cc
@@ -1,4 +1,5 @@
#include "option_types.hh"
+#include "debug.hh"
#include "unit_tests.hh"
namespace Kakoune
diff --git a/src/profile.hh b/src/profile.hh
index 7feff017..f107ebd3 100644
--- a/src/profile.hh
+++ b/src/profile.hh
@@ -3,6 +3,7 @@
#include "option.hh"
#include "clock.hh"
+#include "option_manager.hh"
namespace Kakoune
{
diff --git a/src/register_manager.cc b/src/register_manager.cc
index 254104a4..b9d09a52 100644
--- a/src/register_manager.cc
+++ b/src/register_manager.cc
@@ -4,11 +4,22 @@
#include "context.hh"
#include "hash_map.hh"
#include "format.hh"
+#include "ranges.hh"
#include "hook_manager.hh"
namespace Kakoune
{
+Register::RestoreInfo Register::save(const Context& context)
+{
+ return get(context) | gather<RestoreInfo>();
+}
+
+void Register::restore(Context& context, const RestoreInfo& info)
+{
+ set(context, info, true);
+}
+
void StaticRegister::set(Context& context, ConstArrayView<String> values, bool)
{
m_content.assign(values.begin(), values.end());
diff --git a/src/register_manager.hh b/src/register_manager.hh
index c7ca8590..9d843eff 100644
--- a/src/register_manager.hh
+++ b/src/register_manager.hh
@@ -6,7 +6,6 @@
#include "exception.hh"
#include "utils.hh"
#include "hash_map.hh"
-#include "ranges.hh"
#include "string.hh"
#include "vector.hh"
@@ -25,8 +24,8 @@ public:
virtual const String& get_main(const Context& context, size_t main_index) = 0;
using RestoreInfo = Vector<String, MemoryDomain::Registers>;
- RestoreInfo save(const Context& context) { return get(context) | gather<RestoreInfo>(); }
- void restore(Context& context, const RestoreInfo& info) { set(context, info, true); }
+ RestoreInfo save(const Context& context);
+ void restore(Context& context, const RestoreInfo& info);
NestedBool& modified_hook_disabled() { return m_disable_modified_hook; }
diff --git a/src/remote.cc b/src/remote.cc
index 025a4458..97a62b02 100644
--- a/src/remote.cc
+++ b/src/remote.cc
@@ -1,7 +1,7 @@
#include "remote.hh"
-#include "buffer_manager.hh"
#include "buffer_utils.hh"
+#include "debug.hh"
#include "client_manager.hh"
#include "command_manager.hh"
#include "display_buffer.hh"
diff --git a/src/shared_string.cc b/src/shared_string.cc
index f88008b1..8b4f6e6e 100644
--- a/src/shared_string.cc
+++ b/src/shared_string.cc
@@ -1,5 +1,6 @@
#include "shared_string.hh"
-#include "buffer_utils.hh"
+#include "debug.hh"
+#include "format.hh"
namespace Kakoune
{
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index 47432df5..d08c4dbd 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -1,6 +1,6 @@
#include "shell_manager.hh"
-#include "buffer_utils.hh"
+#include "debug.hh"
#include "client.hh"
#include "clock.hh"
#include "context.hh"
diff --git a/src/window.cc b/src/window.cc
index e296a62d..e992af01 100644
--- a/src/window.cc
+++ b/src/window.cc
@@ -1,13 +1,15 @@
#include "window.hh"
#include "assert.hh"
+#include "buffer.hh"
+#include "buffer_utils.hh"
#include "clock.hh"
#include "context.hh"
#include "highlighter.hh"
#include "hook_manager.hh"
#include "input_handler.hh"
#include "client.hh"
-#include "buffer_utils.hh"
+#include "debug.hh"
#include "option.hh"
#include "option_types.hh"
#include "profile.hh"