Add trim_selections primitive

This commit is contained in:
Delapouite 2018-02-13 14:35:10 +01:00
parent c939c30135
commit fccfc76e89
8 changed files with 34 additions and 0 deletions

View File

@ -351,6 +351,9 @@ is a sequence of non whitespace characters
convert spaces to tabs in current selections, uses the buffer tabstop
option or the count parameter for tabstop
*_*::
trim selections
*<a-">*::
rotate selections content, if specified, the count groups selections,
so the following command

View File

@ -1618,6 +1618,22 @@ void spaces_to_tabs(Context& context, NormalParams params)
SelectionList{ buffer, std::move(spaces) }.insert("\t"_str, InsertMode::Replace);
}
void trim_selections(Context& context, NormalParams)
{
auto& buffer = context.buffer();
for (auto& sel : context.selections())
{
auto beg = buffer.iterator_at(sel.min());
auto end = buffer.iterator_at(sel.max());
while (beg != end and is_blank(*beg))
++beg;
while (beg != end and is_blank(*end))
--end;
sel.min() = beg.coord();
sel.max() = end.coord();
}
}
SelectionList read_selections_from_register(char reg, Context& context)
{
if (not is_basic_alpha(reg) and reg != '^')
@ -2166,6 +2182,8 @@ static const HashMap<Key, NormalCmd, MemoryDomain::Undefined, KeymapBackend> key
{ {'@'}, {"convert tabs to spaces in selections", tabs_to_spaces} },
{ {alt('@')}, {"convert spaces to tabs in selections", spaces_to_tabs} },
{ {'_'}, {"trim selections", trim_selections} },
{ {'C'}, {"copy selection on next lines", copy_selections_on_next_lines<Forward>} },
{ {alt('C')}, {"copy selection on previous lines", copy_selections_on_next_lines<Backward>} },

1
test/normal/trim/cmd Normal file
View File

@ -0,0 +1 @@
%<a-s>_<a-">

3
test/normal/trim/in Normal file
View File

@ -0,0 +1,3 @@
line 1
line 2
line 3

3
test/normal/trim/out Normal file
View File

@ -0,0 +1,3 @@
line 3
line 1
line 2

View File

@ -0,0 +1 @@
_

View File

@ -0,0 +1,4 @@
| | | | |
|:------|------:|:------:|----------------|
|%(foo )|%( bar)|%( qux )|%( pop )%( hip )|
%( kakoune )

View File

@ -0,0 +1 @@
foo:bar:qux:pop:hip:kakoune