2014-04-28 22:54:00 +02:00
|
|
|
#ifndef insert_completer_hh_INCLUDED
|
|
|
|
#define insert_completer_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "buffer.hh"
|
|
|
|
#include "option_manager.hh"
|
2015-10-05 02:48:00 +02:00
|
|
|
#include "display_buffer.hh"
|
2014-04-28 22:54:00 +02:00
|
|
|
|
2014-08-19 19:56:11 +02:00
|
|
|
#include "optional.hh"
|
|
|
|
|
2014-04-28 22:54:00 +02:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2014-08-19 19:56:11 +02:00
|
|
|
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; }
|
2014-08-19 19:56:11 +02:00
|
|
|
|
|
|
|
bool operator!=(const InsertCompleterDesc& other) const
|
|
|
|
{ return !(*this == other); }
|
|
|
|
|
|
|
|
Mode mode;
|
|
|
|
Optional<String> param;
|
|
|
|
};
|
|
|
|
|
2015-01-12 14:24:30 +01:00
|
|
|
using InsertCompleterDescList = Vector<InsertCompleterDesc, MemoryDomain::Options>;
|
2014-08-19 19:56:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
String option_to_string(const InsertCompleterDesc& opt);
|
2014-10-07 22:11:55 +02:00
|
|
|
void option_from_string(StringView str, InsertCompleterDesc& opt);
|
2014-08-19 19:56:11 +02:00
|
|
|
|
2014-04-28 22:54:00 +02:00
|
|
|
struct InsertCompletion
|
|
|
|
{
|
2015-08-30 12:05:48 +02:00
|
|
|
struct Candidate
|
|
|
|
{
|
|
|
|
String completion;
|
|
|
|
String docstring;
|
2015-10-05 02:48:00 +02:00
|
|
|
DisplayLine menu_entry;
|
2015-08-30 12:05:48 +02:00
|
|
|
|
|
|
|
bool operator==(const Candidate& other) const { return completion == other.completion; }
|
|
|
|
bool operator<(const Candidate& other) const { return completion < other.completion; }
|
|
|
|
};
|
|
|
|
|
|
|
|
using CandidateList = Vector<Candidate>;
|
|
|
|
|
2014-05-07 20:51:01 +02:00
|
|
|
ByteCoord begin;
|
|
|
|
ByteCoord end;
|
2015-08-30 12:05:48 +02:00
|
|
|
CandidateList candidates;
|
2014-05-07 20:51:01 +02:00
|
|
|
size_t timestamp;
|
2014-04-28 22:54:00 +02:00
|
|
|
|
|
|
|
bool is_valid() const { return not candidates.empty(); }
|
|
|
|
};
|
|
|
|
|
2014-11-02 17:04:24 +01:00
|
|
|
class InsertCompleter : public OptionManagerWatcher
|
2014-04-28 22:54:00 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
InsertCompleter(const Context& context);
|
|
|
|
InsertCompleter(const InsertCompleter&) = delete;
|
|
|
|
InsertCompleter& operator=(const InsertCompleter&) = delete;
|
2014-11-02 17:04:24 +01:00
|
|
|
~InsertCompleter();
|
2014-04-28 22:54:00 +02:00
|
|
|
|
2015-03-15 19:44:11 +01:00
|
|
|
void select(int offset, Vector<Key>& keystrokes);
|
2014-04-28 22:54:00 +02:00
|
|
|
void update();
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
void explicit_file_complete();
|
|
|
|
void explicit_word_complete();
|
|
|
|
void explicit_line_complete();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool setup_ifn();
|
|
|
|
|
|
|
|
template<typename CompleteFunc>
|
|
|
|
bool try_complete(CompleteFunc complete_func);
|
|
|
|
void on_option_changed(const Option& opt) override;
|
|
|
|
|
|
|
|
void menu_show();
|
|
|
|
|
2015-08-30 12:05:48 +02:00
|
|
|
using CandidateList = InsertCompletion::CandidateList;
|
|
|
|
|
2014-04-28 22:54:00 +02:00
|
|
|
const Context& m_context;
|
2014-11-05 00:51:41 +01:00
|
|
|
OptionManager& m_options;
|
2014-04-28 22:54:00 +02:00
|
|
|
InsertCompletion m_completions;
|
2015-08-30 12:05:48 +02:00
|
|
|
CandidateList m_matching_candidates;
|
2014-04-28 22:54:00 +02:00
|
|
|
int m_current_candidate = -1;
|
2015-10-19 14:43:23 +02:00
|
|
|
|
|
|
|
std::function<InsertCompletion (const Buffer&, ByteCoord)> m_explicit_completer;
|
2014-04-28 22:54:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // insert_completer_hh_INCLUDED
|