home/src/insert_completer.hh

100 lines
2.3 KiB
C++
Raw Normal View History

#ifndef insert_completer_hh_INCLUDED
#define insert_completer_hh_INCLUDED
#include "option_manager.hh"
#include "display_buffer.hh"
#include "vector.hh"
#include "optional.hh"
namespace Kakoune
{
class Buffer;
struct Key;
struct InsertCompleterDesc
{
enum Mode
{
Word,
Option,
Filename
};
bool operator==(const InsertCompleterDesc& other) const
2014-10-28 21:01:55 +01:00
{ return mode == other.mode and param == other.param; }
bool operator!=(const InsertCompleterDesc& other) const
{ return not (*this == other); }
Mode mode;
Optional<String> param;
};
2015-01-12 14:24:30 +01:00
using InsertCompleterDescList = Vector<InsertCompleterDesc, MemoryDomain::Options>;
String option_to_string(const InsertCompleterDesc& opt);
void option_from_string(StringView str, InsertCompleterDesc& opt);
struct InsertCompletion
{
struct Candidate
{
String completion;
String docstring;
DisplayLine menu_entry;
bool operator==(const Candidate& other) const { return completion == other.completion; }
bool operator<(const Candidate& other) const { return completion < other.completion; }
};
using CandidateList = Vector<Candidate>;
ByteCoord begin;
ByteCoord end;
CandidateList candidates;
size_t timestamp;
bool is_valid() const { return not candidates.empty(); }
};
2014-11-02 17:04:24 +01:00
class InsertCompleter : public OptionManagerWatcher
{
public:
InsertCompleter(const Context& context);
InsertCompleter(const InsertCompleter&) = delete;
InsertCompleter& operator=(const InsertCompleter&) = delete;
2014-11-02 17:04:24 +01:00
~InsertCompleter();
void select(int offset, Vector<Key>& keystrokes);
void update();
void reset();
void explicit_file_complete();
void explicit_word_complete();
void explicit_line_complete();
private:
bool setup_ifn();
template<typename Func>
bool try_complete(Func complete_func);
void on_option_changed(const Option& opt) override;
void menu_show();
const Context& m_context;
OptionManager& m_options;
InsertCompletion m_completions;
int m_current_candidate = -1;
using CompleteFunc = InsertCompletion (const Buffer&, ByteCoord, const OptionManager& options);
CompleteFunc* m_explicit_completer = nullptr;
};
}
#endif // insert_completer_hh_INCLUDED