summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-03-16 23:08:10 +0000
committerMaxime Coste <mawww@kakoune.org>2017-03-16 23:34:02 +0000
commite44f95820ee182460bee2e7569ab4ecb1d444112 (patch)
treeeaf60c648066fef5b57512dc6ccc47d8095717e4
parent5f7464d90d0bfe641dd2c7bbbca6e78d92d9d818 (diff)
Fixes some clang-tidy warning and add a few missing meta.hh include
-rw-r--r--src/alias_registry.hh2
-rw-r--r--src/assert.cc15
-rw-r--r--src/buffer.cc6
-rw-r--r--src/command_manager.cc2
-rw-r--r--src/command_manager.hh2
-rw-r--r--src/completion.hh4
-rw-r--r--src/highlighters.cc14
-rw-r--r--src/input_handler.cc8
-rw-r--r--src/keys.hh1
-rw-r--r--src/main.cc4
-rw-r--r--src/normal.cc5
-rw-r--r--src/option.hh1
-rw-r--r--src/option_manager.hh2
-rw-r--r--src/option_types.hh12
-rw-r--r--src/regex.cc2
-rw-r--r--src/remote.cc4
-rw-r--r--src/selectors.cc6
-rw-r--r--src/selectors.hh2
-rw-r--r--src/shell_manager.cc4
-rw-r--r--src/word_db.cc2
-rw-r--r--src/word_db.hh2
21 files changed, 47 insertions, 53 deletions
diff --git a/src/alias_registry.hh b/src/alias_registry.hh
index e9437ab0..4d44c6c5 100644
--- a/src/alias_registry.hh
+++ b/src/alias_registry.hh
@@ -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;
diff --git a/src/assert.cc b/src/assert.cc
index 1e5542ee..5f8a3f9d 100644
--- a/src/assert.cc
+++ b/src/assert.cc
@@ -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)
diff --git a/src/buffer.cc b/src/buffer.cc
index dac1e19c..04c53083 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -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)
diff --git a/src/command_manager.cc b/src/command_manager.cc
index 9d42b0a9..155eb0c7 100644
--- a/src/command_manager.cc
+++ b/src/command_manager.cc
@@ -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)); });
diff --git a/src/command_manager.hh b/src/command_manager.hh
index be2dd7d6..c0442255 100644
--- a/src/command_manager.hh
+++ b/src/command_manager.hh
@@ -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);
}
diff --git a/src/completion.hh b/src/completion.hh
index 335cfbd6..19275824 100644
--- a/src/completion.hh
+++ b/src/completion.hh
@@ -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};
diff --git a/src/highlighters.cc b/src/highlighters.cc
index e68f2088..6f0c3848 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -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)
diff --git a/src/input_handler.cc b/src/input_handler.cc
index 6cac4b27..4f921a8a 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -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)
diff --git a/src/keys.hh b/src/keys.hh
index 02df20a6..3d023453 100644
--- a/src/keys.hh
+++ b/src/keys.hh
@@ -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"
diff --git a/src/main.cc b/src/main.cc
index 2c6b996d..19eb351f 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -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({
diff --git a/src/normal.cc b/src/normal.cc
index 03826487..119b91d1 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -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();
}
diff --git a/src/option.hh b/src/option.hh
index c54de083..dc1acaae 100644
--- a/src/option.hh
+++ b/src/option.hh
@@ -2,6 +2,7 @@
#define option_hh_INCLUDED
#include "enum.hh"
+#include "meta.hh"
namespace Kakoune
{
diff --git a/src/option_manager.hh b/src/option_manager.hh
index e19ae44a..f68f6662 100644
--- a/src/option_manager.hh
+++ b/src/option_manager.hh
@@ -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>
diff --git a/src/option_types.hh b/src/option_types.hh
index ec7796f6..7cdfb48d 100644
--- a/src/option_types.hh
+++ b/src/option_types.hh
@@ -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");
}
diff --git a/src/regex.cc b/src/regex.cc
index 4482cb59..1658af76 100644
--- a/src/regex.cc
+++ b/src/regex.cc
@@ -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)
diff --git a/src/remote.cc b/src/remote.cc
index 4f9a9ca5..721c4759 100644
--- a/src/remote.cc
+++ b/src/remote.cc
@@ -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)
diff --git a/src/selectors.cc b/src/selectors.cc
index ece2b9ce..87a4a345 100644
--- a/src/selectors.cc
+++ b/src/selectors.cc
@@ -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)
{
diff --git a/src/selectors.hh b/src/selectors.hh
index 8b2ced6d..c87f6321 100644
--- a/src/selectors.hh
+++ b/src/selectors.hh
@@ -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,
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index ad7f18ed..357724b1 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -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())
diff --git a/src/word_db.cc b/src/word_db.cc
index cb4dc669..6c5167d6 100644
--- a/src/word_db.cc
+++ b/src/word_db.cc
@@ -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)},
diff --git a/src/word_db.hh b/src/word_db.hh
index 23c77695..a585aaa8 100644
--- a/src/word_db.hh
+++ b/src/word_db.hh
@@ -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);