Merge remote-tracking branch 'Delapouite/trim'
This commit is contained in:
commit
99d1fee44c
|
@ -351,6 +351,9 @@ is a sequence of non whitespace characters
|
||||||
convert spaces to tabs in current selections, uses the buffer tabstop
|
convert spaces to tabs in current selections, uses the buffer tabstop
|
||||||
option or the count parameter for tabstop
|
option or the count parameter for tabstop
|
||||||
|
|
||||||
|
*_*::
|
||||||
|
trim selections
|
||||||
|
|
||||||
*<a-">*::
|
*<a-">*::
|
||||||
rotate selections content, if specified, the count groups selections,
|
rotate selections content, if specified, the count groups selections,
|
||||||
so the following command
|
so the following command
|
||||||
|
|
|
@ -1612,6 +1612,22 @@ void spaces_to_tabs(Context& context, NormalParams params)
|
||||||
SelectionList{ buffer, std::move(spaces) }.insert("\t"_str, InsertMode::Replace);
|
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)
|
SelectionList read_selections_from_register(char reg, Context& context)
|
||||||
{
|
{
|
||||||
if (not is_basic_alpha(reg) and reg != '^')
|
if (not is_basic_alpha(reg) and reg != '^')
|
||||||
|
@ -2160,6 +2176,8 @@ static const HashMap<Key, NormalCmd, MemoryDomain::Undefined, KeymapBackend> key
|
||||||
{ {'@'}, {"convert tabs to spaces in selections", tabs_to_spaces} },
|
{ {'@'}, {"convert tabs to spaces in selections", tabs_to_spaces} },
|
||||||
{ {alt('@')}, {"convert spaces to tabs in selections", spaces_to_tabs} },
|
{ {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>} },
|
{ {'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>} },
|
{ {alt('C')}, {"copy selection on previous lines", copy_selections_on_next_lines<Backward>} },
|
||||||
|
|
||||||
|
|
1
test/normal/trim/cmd
Normal file
1
test/normal/trim/cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
%<a-s>_<a-">
|
3
test/normal/trim/in
Normal file
3
test/normal/trim/in
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
line 1
|
||||||
|
line 2
|
||||||
|
line 3
|
3
test/normal/trim/out
Normal file
3
test/normal/trim/out
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
line 3
|
||||||
|
line 1
|
||||||
|
line 2
|
1
test/normal/trim/table/cmd
Normal file
1
test/normal/trim/table/cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
_
|
4
test/normal/trim/table/in
Normal file
4
test/normal/trim/table/in
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
| | | | |
|
||||||
|
|:------|------:|:------:|----------------|
|
||||||
|
|%(foo )|%( bar)|%( qux )|%( pop )%( hip )|
|
||||||
|
%( kakoune )
|
1
test/normal/trim/table/selections
Normal file
1
test/normal/trim/table/selections
Normal file
|
@ -0,0 +1 @@
|
||||||
|
foo:bar:qux:pop:hip:kakoune
|
Loading…
Reference in New Issue
Block a user