parent
6eb820dc54
commit
5fae16faef
|
@ -311,6 +311,12 @@ The following expansions are supported (with required context _in italics_):
|
|||
the number of bytes from the start of the line to the cursor (like
|
||||
`%val{cursor_column}`), and all are 1-based decimal integers
|
||||
|
||||
*%val{selections_char_desc}*::
|
||||
_in window scope_ +
|
||||
unquoted list of the ranges of all selections, in the same format as
|
||||
`%val{selection_desc}`, except that the columns are in codepoints rather
|
||||
than bytes
|
||||
|
||||
*%val{selections_desc}*::
|
||||
_in window scope_ +
|
||||
unquoted list of the ranges of all selections, in the same format as
|
||||
|
|
|
@ -252,7 +252,11 @@ static const EnvVarDesc builtin_env_vars[] = { {
|
|||
}, {
|
||||
"selections_desc", false,
|
||||
[](StringView name, const Context& context, Quoting quoting)
|
||||
{ return selection_list_to_string(context.selections()); }
|
||||
{ return selection_list_to_string<false>(context.selections()); }
|
||||
}, {
|
||||
"selections_char_desc", false,
|
||||
[](StringView name, const Context& context, Quoting quoting)
|
||||
{ return selection_list_to_string<true>(context.selections()); }
|
||||
}, {
|
||||
"selection_length", false,
|
||||
[](StringView name, const Context& context, Quoting quoting) -> String
|
||||
|
@ -793,7 +797,7 @@ int run_server(StringView session, StringView server_init,
|
|||
kak_assert(local_client);
|
||||
const String client_name = local_client->context().name();
|
||||
const String buffer_name = local_client->context().buffer().name();
|
||||
const String selections = selection_list_to_string(local_client->context().selections());
|
||||
const String selections = selection_list_to_string<false>(local_client->context().selections());
|
||||
|
||||
ClientManager::instance().remove_client(*local_client, true, 0);
|
||||
client_manager.clear_client_trash();
|
||||
|
|
|
@ -480,13 +480,13 @@ String selection_to_string(const Selection& selection)
|
|||
cursor.line + 1, cursor.column + 1);
|
||||
}
|
||||
|
||||
String selection_list_to_string(const SelectionList& selections)
|
||||
String selection_to_string_char(const Buffer& buffer, const Selection& selection)
|
||||
{
|
||||
auto beg = &*selections.begin(), end = &*selections.end();
|
||||
auto main = beg + selections.main_index();
|
||||
using View = ConstArrayView<Selection>;
|
||||
return join(concatenated(View{main, end}, View{beg, main}) |
|
||||
transform(selection_to_string), ' ', false);
|
||||
const auto& cursor = selection.cursor();
|
||||
const auto& anchor = selection.anchor();
|
||||
return format("{}.{},{}.{}",
|
||||
anchor.line + 1, buffer[anchor.line].char_count_to(anchor.column) + 1,
|
||||
cursor.line + 1, buffer[cursor.line].char_count_to(cursor.column) + 1);
|
||||
}
|
||||
|
||||
Selection selection_from_string(StringView desc)
|
||||
|
|
|
@ -95,7 +95,6 @@ struct SelectionList
|
|||
SelectionList(Buffer& buffer, Vector<Selection> s, size_t timestamp);
|
||||
|
||||
void update(bool merge = true);
|
||||
|
||||
void check_invariant() const;
|
||||
|
||||
const Selection& main() const { return (*this)[m_main]; }
|
||||
|
@ -157,9 +156,27 @@ private:
|
|||
|
||||
Vector<Selection> compute_modified_ranges(const Buffer& buffer, size_t timestamp);
|
||||
|
||||
String selection_to_string(const Selection& selection);
|
||||
String selection_list_to_string(const SelectionList& selection);
|
||||
Selection selection_from_string(StringView desc);
|
||||
String selection_to_string(const Selection& selection);
|
||||
String selection_to_string_char(const Buffer& buffer, const Selection& selection);
|
||||
|
||||
template<bool char_columns>
|
||||
String selection_list_to_string(const SelectionList& selections)
|
||||
{
|
||||
auto& buffer = selections.buffer();
|
||||
kak_assert(selections.timestamp() == buffer.timestamp());
|
||||
|
||||
auto to_string = [&](const Selection& selection) {
|
||||
return char_columns ? selection_to_string_char(buffer, selection)
|
||||
: selection_to_string(selection);
|
||||
};
|
||||
|
||||
auto beg = &*selections.begin(), end = &*selections.end();
|
||||
auto main = beg + selections.main_index();
|
||||
using View = ConstArrayView<Selection>;
|
||||
return join(concatenated(View{main, end}, View{beg, main}) |
|
||||
transform(to_string), ' ', false);
|
||||
}
|
||||
|
||||
template<class StringArray>
|
||||
SelectionList selection_list_from_strings(Buffer& buffer, StringArray&& descs, size_t timestamp, size_t main)
|
||||
|
|
0
test/compose/selections_char_desc-expansion/cmd
Normal file
0
test/compose/selections_char_desc-expansion/cmd
Normal file
4
test/compose/selections_char_desc-expansion/in
Normal file
4
test/compose/selections_char_desc-expansion/in
Normal file
|
@ -0,0 +1,4 @@
|
|||
sin%(gle)-byte
|
||||
%(λx.)λy.y x - start on wide char
|
||||
∃e∈%(C.∀)g∈C.g⊗e≡e⊗g≡e - tabs, ending on wide char
|
||||
%(x̦̏)- combining characters
|
|
@ -0,0 +1 @@
|
|||
4.2,4.4 1.4,1.6 2.1,2.3 3.5,3.7
|
Loading…
Reference in New Issue
Block a user