diff --git a/src/alias_registry.hh b/src/alias_registry.hh index e9437ab0f..4d44c6c51 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; using iterator = AliasMap::const_iterator; diff --git a/src/assert.cc b/src/assert.cc index 1e5542ee9..5f8a3f9d9 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 dac1e19c8..04c530830 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 9d42b0a97..155eb0c76 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 postprocess) + const std::function& 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 be2dd7d69..c0442255e 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 postprocess); + const std::function& postprocess); } diff --git a/src/completion.hh b/src/completion.hh index 335cfbd64..192758249 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) { return true; } using Completer = std::function; -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 e68f20881..6f0c3848f 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 6cac4b271..4f921a8ae 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 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 02df20a62..3d023453b 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 2c6b996d7..19eb351fe 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 038264876..119b91d1f 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(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 c54de083c..dc1acaaeb 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 e19ae44a8..f68f66626 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 #include diff --git a/src/option_types.hh b/src/option_types.hh index ec7796f66..7cdfb48d0 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 #include @@ -211,7 +213,7 @@ inline bool option_add(StronglyTypedNumber& opt, struct WorstMatch { template 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 4482cb596..1658af760 100644 --- a/src/regex.cc +++ b/src/regex.cc @@ -8,7 +8,7 @@ namespace Kakoune using Utf8It = RegexUtf8It; 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 4f9a9ca5b..721c47596 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 ece2b9ce7..87a4a3455 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& 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& matches, const Regex& ex, bool& wrapped) { diff --git a/src/selectors.hh b/src/selectors.hh index 8b2ced6db..c87f63210 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 select_surrounding(const Buffer& buffer, const Selection& selection, diff --git a/src/shell_manager.cc b/src/shell_manager.cc index ad7f18ed3..357724b1e 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -248,7 +248,7 @@ std::pair 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 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 cb4dc669e..6c5167d6a 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 23c776959..a585aaa86 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);