mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-28 17:13:00 +03:00
Cleanup include dependencies a bit
This commit is contained in:
parent
da6d7f4530
commit
12856066b1
@ -4,6 +4,8 @@
|
|||||||
#include "event_manager.hh"
|
#include "event_manager.hh"
|
||||||
#include "file.hh"
|
#include "file.hh"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#define st_mtim st_mtimespec
|
#define st_mtim st_mtimespec
|
||||||
#endif
|
#endif
|
||||||
@ -128,7 +130,7 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll)
|
|||||||
ssize_t count = 0;
|
ssize_t count = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
count = read(fifo, data, buffer_size);
|
count = ::read(fifo, data, buffer_size);
|
||||||
auto pos = buffer->back_coord();
|
auto pos = buffer->back_coord();
|
||||||
|
|
||||||
const bool prevent_scrolling = pos == BufferCoord{0,0} and not scroll;
|
const bool prevent_scrolling = pos == BufferCoord{0,0} and not scroll;
|
||||||
@ -165,8 +167,8 @@ void write_to_debug_buffer(StringView str)
|
|||||||
{
|
{
|
||||||
if (not BufferManager::has_instance())
|
if (not BufferManager::has_instance())
|
||||||
{
|
{
|
||||||
write_stderr(str);
|
write(2, str);
|
||||||
write_stderr("\n");
|
write(2, "\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "register_manager.hh"
|
#include "register_manager.hh"
|
||||||
#include "insert_completer.hh"
|
#include "insert_completer.hh"
|
||||||
#include "remote.hh"
|
#include "remote.hh"
|
||||||
|
#include "regex.hh"
|
||||||
#include "shell_manager.hh"
|
#include "shell_manager.hh"
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
#include "window.hh"
|
#include "window.hh"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "completion.hh"
|
#include "completion.hh"
|
||||||
#include "file.hh"
|
#include "file.hh"
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
|
#include "regex.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
28
src/file.cc
28
src/file.cc
@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
#include "assert.hh"
|
#include "assert.hh"
|
||||||
#include "buffer.hh"
|
#include "buffer.hh"
|
||||||
#include "unicode.hh"
|
#include "exception.hh"
|
||||||
#include "ranked_match.hh"
|
#include "ranked_match.hh"
|
||||||
#include "regex.hh"
|
#include "regex.hh"
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
|
#include "unicode.hh"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
@ -33,6 +34,14 @@
|
|||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
|
struct file_access_error : runtime_error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
file_access_error(StringView filename,
|
||||||
|
StringView error_desc)
|
||||||
|
: runtime_error(format("{}: {}", filename, error_desc)) {}
|
||||||
|
};
|
||||||
|
|
||||||
String parse_filename(StringView filename)
|
String parse_filename(StringView filename)
|
||||||
{
|
{
|
||||||
if (filename.length() >= 1 and filename[0_byte] == '~' and
|
if (filename.length() >= 1 and filename[0_byte] == '~' and
|
||||||
@ -168,14 +177,9 @@ String read_file(StringView filename, bool text)
|
|||||||
{
|
{
|
||||||
int fd = open(parse_filename(filename).c_str(), O_RDONLY);
|
int fd = open(parse_filename(filename).c_str(), O_RDONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
|
||||||
if (errno == ENOENT)
|
|
||||||
throw file_not_found(filename);
|
|
||||||
|
|
||||||
throw file_access_error(filename, strerror(errno));
|
throw file_access_error(filename, strerror(errno));
|
||||||
}
|
|
||||||
auto close_fd = on_scope_end([fd]{ close(fd); });
|
|
||||||
|
|
||||||
|
auto close_fd = on_scope_end([fd]{ close(fd); });
|
||||||
return read_fd(fd, text);
|
return read_fd(fd, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,12 +189,7 @@ MappedFile::MappedFile(StringView filename)
|
|||||||
|
|
||||||
fd = open(real_filename.c_str(), O_RDONLY | O_NONBLOCK);
|
fd = open(real_filename.c_str(), O_RDONLY | O_NONBLOCK);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
|
||||||
if (errno == ENOENT)
|
|
||||||
throw file_not_found{real_filename};
|
|
||||||
|
|
||||||
throw file_access_error(real_filename, strerror(errno));
|
throw file_access_error(real_filename, strerror(errno));
|
||||||
}
|
|
||||||
|
|
||||||
fstat(fd, &st);
|
fstat(fd, &st);
|
||||||
if (S_ISDIR(st.st_mode))
|
if (S_ISDIR(st.st_mode))
|
||||||
@ -208,6 +207,11 @@ MappedFile::~MappedFile()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MappedFile::operator StringView() const
|
||||||
|
{
|
||||||
|
return { data, (int)st.st_size };
|
||||||
|
}
|
||||||
|
|
||||||
bool file_exists(StringView filename)
|
bool file_exists(StringView filename)
|
||||||
{
|
{
|
||||||
String real_filename = real_path(parse_filename(filename));
|
String real_filename = real_path(parse_filename(filename));
|
||||||
|
27
src/file.hh
27
src/file.hh
@ -2,10 +2,9 @@
|
|||||||
#define file_hh_INCLUDED
|
#define file_hh_INCLUDED
|
||||||
|
|
||||||
#include "array_view.hh"
|
#include "array_view.hh"
|
||||||
#include "completion.hh"
|
|
||||||
#include "exception.hh"
|
|
||||||
#include "regex.hh"
|
|
||||||
#include "flags.hh"
|
#include "flags.hh"
|
||||||
|
#include "units.hh"
|
||||||
|
#include "vector.hh"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -13,23 +12,12 @@
|
|||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
struct file_access_error : runtime_error
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
file_access_error(StringView filename,
|
|
||||||
StringView error_desc)
|
|
||||||
: runtime_error(format("{}: {}", filename, error_desc)) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct file_not_found : file_access_error
|
|
||||||
{
|
|
||||||
file_not_found(StringView filename)
|
|
||||||
: file_access_error(filename, "file not found") {}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Buffer;
|
class Buffer;
|
||||||
class String;
|
class String;
|
||||||
class StringView;
|
class StringView;
|
||||||
|
class Regex;
|
||||||
|
|
||||||
|
using CandidateList = Vector<String, MemoryDomain::Completion>;
|
||||||
|
|
||||||
// parse ~/ and $env values in filename and returns the translated filename
|
// parse ~/ and $env values in filename and returns the translated filename
|
||||||
String parse_filename(StringView filename);
|
String parse_filename(StringView filename);
|
||||||
@ -45,16 +33,13 @@ bool fd_readable(int fd);
|
|||||||
String read_fd(int fd, bool text = false);
|
String read_fd(int fd, bool text = false);
|
||||||
String read_file(StringView filename, bool text = false);
|
String read_file(StringView filename, bool text = false);
|
||||||
void write(int fd, StringView data);
|
void write(int fd, StringView data);
|
||||||
inline void write_stdout(StringView str) { write(1, str); }
|
|
||||||
inline void write_stderr(StringView str) { write(2, str); }
|
|
||||||
|
|
||||||
|
|
||||||
struct MappedFile
|
struct MappedFile
|
||||||
{
|
{
|
||||||
MappedFile(StringView filename);
|
MappedFile(StringView filename);
|
||||||
~MappedFile();
|
~MappedFile();
|
||||||
|
|
||||||
operator StringView() const { return { data, (int)st.st_size }; }
|
operator StringView() const;
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
const char* data;
|
const char* data;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "containers.hh"
|
#include "containers.hh"
|
||||||
#include "display_buffer.hh"
|
#include "display_buffer.hh"
|
||||||
|
#include "exception.hh"
|
||||||
#include "keys.hh"
|
#include "keys.hh"
|
||||||
#include "file.hh"
|
#include "file.hh"
|
||||||
#include "event_manager.hh"
|
#include "event_manager.hh"
|
||||||
@ -159,7 +160,7 @@ void rpc_call(StringView method, Args&&... args)
|
|||||||
auto q = format(R"(\{ "jsonrpc": "2.0", "method": "{}", "params": [{}] }{})",
|
auto q = format(R"(\{ "jsonrpc": "2.0", "method": "{}", "params": [{}] }{})",
|
||||||
method, concat(std::forward<Args>(args)...), "\n");
|
method, concat(std::forward<Args>(args)...), "\n");
|
||||||
|
|
||||||
write_stdout(q);
|
write(1, q);
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonUI::JsonUI()
|
JsonUI::JsonUI()
|
||||||
@ -424,7 +425,7 @@ void JsonUI::parse_requests(EventMode mode)
|
|||||||
}
|
}
|
||||||
catch (runtime_error& error)
|
catch (runtime_error& error)
|
||||||
{
|
{
|
||||||
write_stderr(format("error while handling requests '{}': '{}'",
|
write(2, format("error while handling requests '{}': '{}'",
|
||||||
m_requests, error.what()));
|
m_requests, error.what()));
|
||||||
// try to salvage request by dropping its first line
|
// try to salvage request by dropping its first line
|
||||||
pos = std::min(m_requests.end(), find(m_requests, '\n')+1);
|
pos = std::min(m_requests.end(), find(m_requests, '\n')+1);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "parameters_parser.hh"
|
#include "parameters_parser.hh"
|
||||||
#include "register_manager.hh"
|
#include "register_manager.hh"
|
||||||
#include "remote.hh"
|
#include "remote.hh"
|
||||||
|
#include "regex.hh"
|
||||||
#include "scope.hh"
|
#include "scope.hh"
|
||||||
#include "shell_manager.hh"
|
#include "shell_manager.hh"
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
@ -38,6 +39,9 @@ struct startup_error : Kakoune::runtime_error
|
|||||||
using Kakoune::runtime_error::runtime_error;
|
using Kakoune::runtime_error::runtime_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline void write_stdout(StringView str) { write(1, str); }
|
||||||
|
inline void write_stderr(StringView str) { write(2, str); }
|
||||||
|
|
||||||
String runtime_directory()
|
String runtime_directory()
|
||||||
{
|
{
|
||||||
char relpath[PATH_MAX+1];
|
char relpath[PATH_MAX+1];
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
#include "ranked_match.hh"
|
#include "ranked_match.hh"
|
||||||
|
|
||||||
#include "utf8_iterator.hh"
|
#include "flags.hh"
|
||||||
#include "unit_tests.hh"
|
#include "unit_tests.hh"
|
||||||
|
#include "utf8_iterator.hh"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
|
template<> struct WithBitOps<RankedMatch::Flags> : std::true_type {};
|
||||||
|
|
||||||
UsedLetters used_letters(StringView str)
|
UsedLetters used_letters(StringView str)
|
||||||
{
|
{
|
||||||
UsedLetters res = 0;
|
UsedLetters res = 0;
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#define ranked_match_hh_INCLUDED
|
#define ranked_match_hh_INCLUDED
|
||||||
|
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
#include "flags.hh"
|
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
@ -51,8 +50,6 @@ private:
|
|||||||
int m_max_index = 0;
|
int m_max_index = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<> struct WithBitOps<RankedMatch::Flags> : std::true_type {};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ranked_match_hh_INCLUDED
|
#endif // ranked_match_hh_INCLUDED
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#include "shell_manager.hh"
|
#include "shell_manager.hh"
|
||||||
|
|
||||||
|
#include "buffer_utils.hh"
|
||||||
#include "clock.hh"
|
#include "clock.hh"
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
#include "buffer_utils.hh"
|
|
||||||
#include "event_manager.hh"
|
|
||||||
#include "file.hh"
|
|
||||||
#include "face_registry.hh"
|
|
||||||
#include "display_buffer.hh"
|
#include "display_buffer.hh"
|
||||||
|
#include "event_manager.hh"
|
||||||
|
#include "face_registry.hh"
|
||||||
|
#include "file.hh"
|
||||||
|
#include "regex.hh"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -114,7 +114,7 @@ public:
|
|||||||
explicit String(Codepoint cp, ColumnCount count)
|
explicit String(Codepoint cp, ColumnCount count)
|
||||||
{
|
{
|
||||||
kak_assert(count % codepoint_width(cp) == 0);
|
kak_assert(count % codepoint_width(cp) == 0);
|
||||||
int cp_count = (int)count / codepoint_width(cp);
|
int cp_count = (int)(count / codepoint_width(cp));
|
||||||
reserve(utf8::codepoint_size(cp) * cp_count);
|
reserve(utf8::codepoint_size(cp) * cp_count);
|
||||||
while (cp_count-- > 0)
|
while (cp_count-- > 0)
|
||||||
utf8::dump(std::back_inserter(*this), cp);
|
utf8::dump(std::back_inserter(*this), cp);
|
||||||
@ -289,7 +289,7 @@ inline String& operator+=(String& lhs, StringView rhs)
|
|||||||
inline String operator+(StringView lhs, StringView rhs)
|
inline String operator+(StringView lhs, StringView rhs)
|
||||||
{
|
{
|
||||||
String res;
|
String res;
|
||||||
res.reserve((int)(lhs.length() + rhs.length()));
|
res.reserve(lhs.length() + rhs.length());
|
||||||
res.append(lhs.data(), lhs.length());
|
res.append(lhs.data(), lhs.length());
|
||||||
res.append(rhs.data(), rhs.length());
|
res.append(rhs.data(), rhs.length());
|
||||||
return res;
|
return res;
|
||||||
@ -312,6 +312,11 @@ inline bool operator<(const StringView& lhs, const StringView& rhs)
|
|||||||
rhs.begin(), rhs.end());
|
rhs.begin(), rhs.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline String operator"" _str(const char* str, size_t)
|
||||||
|
{
|
||||||
|
return String(str);
|
||||||
|
}
|
||||||
|
|
||||||
Vector<String> split(StringView str, char separator, char escape);
|
Vector<String> split(StringView str, char separator, char escape);
|
||||||
Vector<StringView> split(StringView str, char separator);
|
Vector<StringView> split(StringView str, char separator);
|
||||||
|
|
||||||
@ -335,11 +340,17 @@ String join(const Container& container, char joiner, bool esc_joiner = true)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline String operator"" _str(const char* str, size_t)
|
inline bool prefix_match(StringView str, StringView prefix)
|
||||||
{
|
{
|
||||||
return String(str);
|
return str.substr(0_byte, prefix.length()) == prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool subsequence_match(StringView str, StringView subseq);
|
||||||
|
|
||||||
|
String expand_tabs(StringView line, ColumnCount tabstop, ColumnCount col = 0);
|
||||||
|
|
||||||
|
Vector<StringView> wrap_lines(StringView text, ColumnCount max_width);
|
||||||
|
|
||||||
int str_to_int(StringView str); // throws on error
|
int str_to_int(StringView str); // throws on error
|
||||||
Optional<int> str_to_int_ifp(StringView str);
|
Optional<int> str_to_int_ifp(StringView str);
|
||||||
|
|
||||||
@ -377,17 +388,6 @@ to_string(const StronglyTypedNumber<RealType, ValueType>& val)
|
|||||||
return to_string((ValueType)val);
|
return to_string((ValueType)val);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool prefix_match(StringView str, StringView prefix)
|
|
||||||
{
|
|
||||||
return str.substr(0_byte, prefix.length()) == prefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool subsequence_match(StringView str, StringView subseq);
|
|
||||||
|
|
||||||
String expand_tabs(StringView line, ColumnCount tabstop, ColumnCount col = 0);
|
|
||||||
|
|
||||||
Vector<StringView> wrap_lines(StringView text, ColumnCount max_width);
|
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
|
||||||
|
#include "units.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -49,7 +51,7 @@ inline bool is_basic_alpha(Codepoint c)
|
|||||||
return (c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z');
|
return (c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z');
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t codepoint_width(Codepoint c)
|
inline ColumnCount codepoint_width(Codepoint c)
|
||||||
{
|
{
|
||||||
return c == '\n' ? 1 : wcwidth((wchar_t)c);
|
return c == '\n' ? 1 : wcwidth((wchar_t)c);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user