2011-09-21 16:37:09 +02:00
|
|
|
#ifndef selectors_hh_INCLUDED
|
|
|
|
#define selectors_hh_INCLUDED
|
|
|
|
|
2014-10-23 19:55:45 +02:00
|
|
|
#include "flags.hh"
|
2012-02-07 15:26:51 +01:00
|
|
|
#include "selection.hh"
|
2011-09-21 16:37:09 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2017-01-01 20:14:18 +01:00
|
|
|
class Regex;
|
|
|
|
template<typename Iterator> struct MatchResults;
|
|
|
|
|
2014-09-18 01:34:23 +02:00
|
|
|
inline Selection keep_direction(Selection res, const Selection& ref)
|
|
|
|
{
|
|
|
|
if ((res.cursor() < res.anchor()) != (ref.cursor() < ref.anchor()))
|
2016-09-22 21:36:26 +02:00
|
|
|
std::swap<BufferCoord>(res.cursor(), res.anchor());
|
2014-09-18 01:34:23 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-10-07 19:44:22 +02:00
|
|
|
template<WordType word_type>
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_to_next_word(const Buffer& buffer, const Selection& selection);
|
2013-12-14 15:49:10 +01:00
|
|
|
|
2013-10-07 19:44:22 +02:00
|
|
|
template<WordType word_type>
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_to_next_word_end(const Buffer& buffer, const Selection& selection);
|
2013-12-14 15:49:10 +01:00
|
|
|
|
2013-10-07 19:44:22 +02:00
|
|
|
template<WordType word_type>
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_to_previous_word(const Buffer& buffer, const Selection& selection);
|
2012-10-08 19:12:09 +02:00
|
|
|
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_line(const Buffer& buffer, const Selection& selection);
|
2012-10-08 19:12:09 +02:00
|
|
|
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_matching(const Buffer& buffer, const Selection& selection);
|
|
|
|
|
|
|
|
Optional<Selection>
|
|
|
|
select_to(const Buffer& buffer, const Selection& selection,
|
2012-11-30 18:32:49 +01:00
|
|
|
Codepoint c, int count, bool inclusive);
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_to_reverse(const Buffer& buffer, const Selection& selection,
|
|
|
|
Codepoint c, int count, bool inclusive);
|
2012-02-10 00:47:55 +01:00
|
|
|
|
2015-06-08 14:51:06 +02:00
|
|
|
template<bool only_move>
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_to_line_end(const Buffer& buffer, const Selection& selection);
|
2015-06-08 14:51:06 +02:00
|
|
|
|
|
|
|
template<bool only_move>
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_to_line_begin(const Buffer& buffer, const Selection& selection);
|
2012-02-10 00:47:55 +01:00
|
|
|
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_to_first_non_blank(const Buffer& buffer, const Selection& selection);
|
2017-01-23 00:53:08 +01:00
|
|
|
|
2013-05-15 14:24:09 +02:00
|
|
|
enum class ObjectFlags
|
|
|
|
{
|
|
|
|
ToBegin = 1,
|
|
|
|
ToEnd = 2,
|
|
|
|
Inner = 4
|
|
|
|
};
|
2014-10-23 19:55:45 +02:00
|
|
|
|
|
|
|
template<> struct WithBitOps<ObjectFlags> : std::true_type {};
|
2013-05-15 14:24:09 +02:00
|
|
|
|
2013-10-07 19:44:22 +02:00
|
|
|
template<WordType word_type>
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_word(const Buffer& buffer, const Selection& selection,
|
|
|
|
int count, ObjectFlags flags);
|
2013-12-14 15:49:10 +01:00
|
|
|
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_number(const Buffer& buffer, const Selection& selection,
|
|
|
|
int count, ObjectFlags flags);
|
2014-05-27 10:50:12 +02:00
|
|
|
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_sentence(const Buffer& buffer, const Selection& selection,
|
|
|
|
int count, ObjectFlags flags);
|
2014-05-26 22:44:57 +02:00
|
|
|
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_paragraph(const Buffer& buffer, const Selection& selection,
|
|
|
|
int count, ObjectFlags flags);
|
2014-05-26 22:44:57 +02:00
|
|
|
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_whitespaces(const Buffer& buffer, const Selection& selection,
|
|
|
|
int count, ObjectFlags flags);
|
2014-06-11 15:00:45 +02:00
|
|
|
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_indent(const Buffer& buffer, const Selection& selection,
|
|
|
|
int count, ObjectFlags flags);
|
2014-05-26 22:44:57 +02:00
|
|
|
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_argument(const Buffer& buffer, const Selection& selection,
|
|
|
|
int level, ObjectFlags flags);
|
2015-06-25 15:44:43 +02:00
|
|
|
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_lines(const Buffer& buffer, const Selection& selection);
|
2014-05-26 22:44:57 +02:00
|
|
|
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
trim_partial_lines(const Buffer& buffer, const Selection& selection);
|
2012-02-10 00:47:55 +01:00
|
|
|
|
2014-05-27 01:35:12 +02:00
|
|
|
void select_buffer(SelectionList& selections);
|
2014-05-26 22:44:57 +02:00
|
|
|
|
2013-07-02 14:55:34 +02:00
|
|
|
enum Direction { Forward, Backward };
|
|
|
|
|
|
|
|
template<Direction direction>
|
2017-03-03 21:12:52 +01:00
|
|
|
Selection find_next_match(const Buffer& buffer, const Selection& sel,
|
|
|
|
const Regex& regex, bool& wrapped);
|
2013-12-14 19:39:03 +01:00
|
|
|
|
2017-01-16 19:49:27 +01:00
|
|
|
void select_all_matches(SelectionList& selections, const Regex& regex, int capture = 0);
|
|
|
|
void split_selections(SelectionList& selections, const Regex& separator_regex, int capture = 0);
|
2011-11-21 20:30:44 +01:00
|
|
|
|
2017-03-03 21:12:52 +01:00
|
|
|
Optional<Selection>
|
|
|
|
select_surrounding(const Buffer& buffer, const Selection& selection,
|
2016-01-27 09:28:25 +01:00
|
|
|
StringView opening, StringView closing, int level,
|
|
|
|
ObjectFlags flags);
|
2013-01-07 18:53:27 +01:00
|
|
|
|
2011-09-21 16:37:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // selectors_hh_INCLUDED
|