Fixes some clang-tidy warning and add a few missing meta.hh include

This commit is contained in:
Maxime Coste 2017-03-16 23:08:10 +00:00
parent 5f7464d90d
commit e44f95820e
21 changed files with 47 additions and 53 deletions

View File

@ -14,7 +14,7 @@ public:
AliasRegistry(AliasRegistry& parent) : m_parent(&parent) {}
void add_alias(String alias, String command);
void remove_alias(StringView alias);
StringView operator[](StringView name) const;
StringView operator[](StringView alias) const;
using AliasMap = HashMap<String, String, MemoryDomain::Aliases>;
using iterator = AliasMap::const_iterator;

View File

@ -28,21 +28,12 @@ private:
bool notify_fatal_error(StringView msg)
{
#if defined(__CYGWIN__)
int res = MessageBox(NULL, msg.zstr(), "Kakoune: fatal error",
MB_OKCANCEL | MB_ICONERROR);
switch (res)
{
case IDCANCEL:
return false;
case IDOK:
return true;
}
return MessageBox(NULL, msg.zstr(), "Kakoune: fatal error",
MB_OKCANCEL | MB_ICONERROR) == IDOK;
#elif defined(__linux__)
auto cmd = format("xmessage -buttons 'quit:0,ignore:1' '{}'", msg);
if (system(cmd.c_str()) == 1)
return true;
return system(cmd.c_str()) == 1;
#endif
return false;
}
void on_assert_failed(const char* message)

View File

@ -317,7 +317,7 @@ bool Buffer::undo(size_t count) noexcept
if (not m_history_cursor->parent)
return false;
while (count-- and m_history_cursor->parent)
while (count-- != 0 and m_history_cursor->parent)
{
for (const Modification& modification : m_history_cursor->undo_group | reverse())
apply_modification(modification.inverse());
@ -335,7 +335,7 @@ bool Buffer::redo(size_t count) noexcept
kak_assert(m_current_undo_group.empty());
while (count-- and m_history_cursor->redo_child)
while (count-- != 0 and m_history_cursor->redo_child)
{
m_history_cursor = m_history_cursor->redo_child.get();
@ -671,7 +671,7 @@ BufferCoord Buffer::char_prev(BufferCoord coord) const
{
kak_assert(is_valid(coord));
if (is_end(coord))
return coord = {(int)m_lines.size()-1, m_lines.back().length() - 1};
return {(int)m_lines.size()-1, m_lines.back().length() - 1};
else if (coord.column == 0)
{
if (coord.line > 0)

View File

@ -394,7 +394,7 @@ String expand(StringView str, const Context& context,
String expand(StringView str, const Context& context,
const ShellContext& shell_context,
std::function<String (String)> postprocess)
const std::function<String (String)>& postprocess)
{
return expand_impl(str, context, shell_context,
[&](String s) { return postprocess(std::move(s)); });

View File

@ -135,7 +135,7 @@ String expand(StringView str, const Context& context,
String expand(StringView str, const Context& context,
const ShellContext& shell_context,
std::function<String (String)> postprocess);
const std::function<String (String)>& postprocess);
}

View File

@ -29,7 +29,7 @@ struct Completions
: start(start), end(end) {}
Completions(ByteCount start, ByteCount end, CandidateList candidates)
: start(start), end(end), candidates(std::move(candidates)) {}
: candidates(std::move(candidates)), start(start), end(end) {}
};
enum class CompletionFlags
@ -44,7 +44,7 @@ constexpr bool with_bit_ops(Meta::Type<CompletionFlags>) { return true; }
using Completer = std::function<Completions (const Context&, CompletionFlags,
StringView, ByteCount)>;
inline Completions complete_nothing(const Context& context, CompletionFlags,
inline Completions complete_nothing(const Context&, CompletionFlags,
StringView, ByteCount cursor_pos)
{
return {cursor_pos, cursor_pos};

View File

@ -314,9 +314,9 @@ private:
RegexIt re_end;
for (; re_it != re_end; ++re_it)
{
for (size_t i = 0; i < m_faces.size(); ++i)
for (auto& face : m_faces)
{
const auto& sub = (*re_it)[m_faces[i].first];
const auto& sub = (*re_it)[face.first];
matches.push_back({sub.first.coord(), sub.second.coord()});
}
}
@ -516,14 +516,14 @@ HighlighterAndId create_line_highlighter(HighlighterParameters params)
auto face = get_face(facespec);
ColumnCount column = 0;
for (auto atom_it = it->begin(); atom_it != it->end(); ++atom_it)
for (auto& atom : *it)
{
column += atom_it->length();
if (!atom_it->has_buffer_range())
column += atom.length();
if (!atom.has_buffer_range())
continue;
kak_assert(atom_it->begin().line == line);
apply_face(face)(*atom_it);
kak_assert(atom.begin().line == line);
apply_face(face)(atom);
}
const ColumnCount remaining = context.window().dimensions().column - column;
if (remaining > 0)

View File

@ -1381,8 +1381,8 @@ void InputHandler::prompt(StringView prompt, String initstr,
Face prompt_face, PromptFlags flags,
Completer completer, PromptCallback callback)
{
push_mode(new InputModes::Prompt(*this, prompt, initstr, prompt_face,
flags, completer, callback));
push_mode(new InputModes::Prompt(*this, prompt, std::move(initstr), prompt_face,
flags, std::move(completer), std::move(callback)));
}
void InputHandler::set_prompt_face(Face prompt_face)
@ -1394,12 +1394,12 @@ void InputHandler::set_prompt_face(Face prompt_face)
void InputHandler::menu(Vector<DisplayLine> choices, MenuCallback callback)
{
push_mode(new InputModes::Menu(*this, std::move(choices), callback));
push_mode(new InputModes::Menu(*this, std::move(choices), std::move(callback)));
}
void InputHandler::on_next_key(KeymapMode keymap_mode, KeyCallback callback)
{
push_mode(new InputModes::NextKey(*this, keymap_mode, callback));
push_mode(new InputModes::NextKey(*this, keymap_mode, std::move(callback)));
}
InputHandler::ScopedForceNormal::ScopedForceNormal(InputHandler& handler, NormalParams params)

View File

@ -4,6 +4,7 @@
#include "coord.hh"
#include "flags.hh"
#include "hash.hh"
#include "meta.hh"
#include "optional.hh"
#include "unicode.hh"
#include "vector.hh"

View File

@ -466,7 +466,7 @@ int run_client(StringView session, StringView init_cmds,
try
{
EventManager event_manager;
RemoteClient client{session, make_ui(ui_type), get_env_vars(), init_cmds, init_coord};
RemoteClient client{session, make_ui(ui_type), get_env_vars(), init_cmds, std::move(init_coord)};
while (true)
event_manager.handle_next_events(EventMode::Normal);
}
@ -594,7 +594,7 @@ int run_server(StringView session,
if (not (flags & ServerFlags::Daemon))
{
local_client = client_manager.create_client(
create_local_ui(ui_type), get_env_vars(), init_cmds, init_coord);
create_local_ui(ui_type), get_env_vars(), init_cmds, std::move(init_coord));
if (startup_error)
local_client->print_status({

View File

@ -730,9 +730,8 @@ void search(Context& context, NormalParams params)
auto& buffer = context.buffer();
do {
bool wrapped = false;
for (int i = 0; i < selections.size(); ++i)
for (auto& sel : selections)
{
auto& sel = selections[i];
if (mode == SelectMode::Replace)
sel = keep_direction(find_next_match<direction>(buffer, sel, regex, wrapped), sel);
if (mode == SelectMode::Extend)
@ -1398,7 +1397,7 @@ void align(Context& context, NormalParams)
CharCount spaces = (int)(targetcol - (tabs ? (tabcol + (int)tabs * tabstop) : inscol));
padstr = String{ '\t', tabs } + String{ ' ', spaces };
}
buffer.insert(insert_coord, std::move(padstr));
buffer.insert(insert_coord, padstr);
}
selections.update();
}

View File

@ -2,6 +2,7 @@
#define option_hh_INCLUDED
#include "enum.hh"
#include "meta.hh"
namespace Kakoune
{

View File

@ -4,8 +4,8 @@
#include "completion.hh"
#include "containers.hh"
#include "exception.hh"
#include "vector.hh"
#include "option.hh"
#include "vector.hh"
#include <memory>
#include <type_traits>

View File

@ -1,13 +1,15 @@
#ifndef option_types_hh_INCLUDED
#define option_types_hh_INCLUDED
#include "option.hh"
#include "array_view.hh"
#include "coord.hh"
#include "containers.hh"
#include "exception.hh"
#include "flags.hh"
#include "hash_map.hh"
#include "option.hh"
#include "string.hh"
#include "units.hh"
#include "coord.hh"
#include "array_view.hh"
#include "hash_map.hh"
#include <tuple>
#include <vector>
@ -211,7 +213,7 @@ inline bool option_add(StronglyTypedNumber<RealType, ValueType>& opt,
struct WorstMatch { template<typename T> WorstMatch(T&&) {} };
inline bool option_add(WorstMatch, StringView str)
inline bool option_add(WorstMatch, StringView)
{
throw runtime_error("no add operation supported for this option type");
}

View File

@ -8,7 +8,7 @@ namespace Kakoune
using Utf8It = RegexUtf8It<const char*>;
Regex::Regex(StringView re, flag_type flags) try
: RegexBase{Utf8It{re.begin(), re}, Utf8It{re.end(), re}}, m_str(re.str())
: RegexBase{Utf8It{re.begin(), re}, Utf8It{re.end(), re}, flags}, m_str{re.str()}
{} catch (std::runtime_error& err) { throw regex_error(err.what()); }
String option_to_string(const Regex& re)

View File

@ -195,7 +195,7 @@ public:
{
T object;
alignas(T) char data[sizeof(T)];
U() {};
U() {}
~U() { object.~T(); }
} u;
read(u.data, sizeof(T));
@ -359,7 +359,7 @@ private:
static bool send_data(int fd, RemoteBuffer& buffer)
{
while (buffer.size() > 0 and fd_writable(fd))
while (not buffer.empty() and fd_writable(fd))
{
int res = ::write(fd, buffer.data(), buffer.size());
if (res <= 0)

View File

@ -807,13 +807,13 @@ void select_buffer(SelectionList& selections)
}
static RegexConstant::match_flag_type
match_flags(const Buffer& buf, BufferIterator begin, BufferIterator end)
match_flags(const Buffer& buf, const BufferIterator& begin, const BufferIterator& end)
{
return match_flags(is_bol(begin.coord()), is_eol(buf, end.coord()),
is_bow(buf, begin.coord()), is_eow(buf, end.coord()));
}
static bool find_next(const Buffer& buffer, BufferIterator pos,
static bool find_next(const Buffer& buffer, const BufferIterator& pos,
MatchResults<BufferIterator>& matches,
const Regex& ex, bool& wrapped)
{
@ -826,7 +826,7 @@ static bool find_next(const Buffer& buffer, BufferIterator pos,
match_flags(buffer, buffer.begin(), buffer.end()));
}
static bool find_prev(const Buffer& buffer, BufferIterator pos,
static bool find_prev(const Buffer& buffer, const BufferIterator& pos,
MatchResults<BufferIterator>& matches,
const Regex& ex, bool& wrapped)
{

View File

@ -105,7 +105,7 @@ Selection find_next_match(const Buffer& buffer, const Selection& sel,
const Regex& regex, bool& wrapped);
void select_all_matches(SelectionList& selections, const Regex& regex, int capture = 0);
void split_selections(SelectionList& selections, const Regex& separator_regex, int capture = 0);
void split_selections(SelectionList& selections, const Regex& regex, int capture = 0);
Optional<Selection>
select_surrounding(const Buffer& buffer, const Selection& selection,

View File

@ -248,7 +248,7 @@ std::pair<String, int> ShellManager::eval(
int status = 0;
// check for termination now that SIGCHLD is blocked
bool terminated = waitpid(pid, &status, WNOHANG);
bool terminated = waitpid(pid, &status, WNOHANG) != 0;
using namespace std::chrono;
static constexpr seconds wait_timeout{1};
@ -269,7 +269,7 @@ std::pair<String, int> ShellManager::eval(
{
EventManager::instance().handle_next_events(EventMode::Urgent, &orig_mask);
if (not terminated)
terminated = waitpid(pid, &status, WNOHANG);
terminated = waitpid(pid, &status, WNOHANG) != 0;
}
if (not stderr_contents.empty())

View File

@ -73,7 +73,7 @@ WordDB::WordDB(const Buffer& buffer)
rebuild_db();
}
WordDB::WordDB(WordDB&& other)
WordDB::WordDB(WordDB&& other) noexcept
: m_buffer{std::move(other.m_buffer)},
m_timestamp{other.m_timestamp},
m_words{std::move(other.m_words)},

View File

@ -19,7 +19,7 @@ public:
WordDB(const Buffer& buffer);
~WordDB() override;
WordDB(const WordDB&) = delete;
WordDB(WordDB&&);
WordDB(WordDB&&) noexcept;
RankedMatchList find_matching(StringView str);