home/src/debug.cc

32 lines
713 B
C++
Raw Normal View History

#include "debug.hh"
#include "assert.hh"
#include "buffer.hh"
#include "buffer_manager.hh"
#include "buffer_utils.hh"
2014-11-12 22:27:07 +01:00
#include "string.hh"
namespace Kakoune
{
2014-04-30 20:27:38 +02:00
void write_debug(StringView str)
{
if (not BufferManager::has_instance())
{
write(2, str.data(), (int)str.length());
write(2, "\n", 1);
return;
}
2015-01-02 12:55:15 +01:00
const StringView debug_buffer_name = "*debug*";
if (Buffer* buffer = BufferManager::instance().get_buffer_ifp(debug_buffer_name))
buffer->insert(buffer->end(), str);
else
{
String line = str + ((str.empty() or str.back() != '\n') ? "\n" : "");
create_buffer_from_data(line, debug_buffer_name, Buffer::Flags::NoUndo);
}
}
}