diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-02-22 22:06:27 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-02-22 22:06:27 +1100 |
| commit | 99d1fee44c0b05d15fc710680cf65e471e39c066 (patch) | |
| tree | 1b13288a4814c16de0157191fbb0321d2774d0e1 | |
| parent | 13ac0e367d61c7127b1467d70011999e94944f4b (diff) | |
| parent | fccfc76e8935a3ce0cd89f6c03d2aae13b8af077 (diff) | |
Merge remote-tracking branch 'Delapouite/trim'
| -rw-r--r-- | doc/pages/keys.asciidoc | 3 | ||||
| -rw-r--r-- | src/normal.cc | 18 | ||||
| -rw-r--r-- | test/normal/trim/cmd | 1 | ||||
| -rw-r--r-- | test/normal/trim/in | 3 | ||||
| -rw-r--r-- | test/normal/trim/out | 3 | ||||
| -rw-r--r-- | test/normal/trim/table/cmd | 1 | ||||
| -rw-r--r-- | test/normal/trim/table/in | 4 | ||||
| -rw-r--r-- | test/normal/trim/table/selections | 1 |
8 files changed, 34 insertions, 0 deletions
diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc index e03eae39..e61160e7 100644 --- a/doc/pages/keys.asciidoc +++ b/doc/pages/keys.asciidoc @@ -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 diff --git a/src/normal.cc b/src/normal.cc index 16270c18..6518f9f8 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1612,6 +1612,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 != '^') @@ -2160,6 +2176,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>} }, diff --git a/test/normal/trim/cmd b/test/normal/trim/cmd new file mode 100644 index 00000000..d7c8655d --- /dev/null +++ b/test/normal/trim/cmd @@ -0,0 +1 @@ +%<a-s>_<a-"> diff --git a/test/normal/trim/in b/test/normal/trim/in new file mode 100644 index 00000000..1310992b --- /dev/null +++ b/test/normal/trim/in @@ -0,0 +1,3 @@ +line 1 + line 2 + line 3 diff --git a/test/normal/trim/out b/test/normal/trim/out new file mode 100644 index 00000000..0be30260 --- /dev/null +++ b/test/normal/trim/out @@ -0,0 +1,3 @@ +line 3 + line 1 + line 2 diff --git a/test/normal/trim/table/cmd b/test/normal/trim/table/cmd new file mode 100644 index 00000000..31354ec1 --- /dev/null +++ b/test/normal/trim/table/cmd @@ -0,0 +1 @@ +_ diff --git a/test/normal/trim/table/in b/test/normal/trim/table/in new file mode 100644 index 00000000..78114048 --- /dev/null +++ b/test/normal/trim/table/in @@ -0,0 +1,4 @@ +| | | | | +|:------|------:|:------:|----------------| +|%(foo )|%( bar)|%( qux )|%( pop )%( hip )| +%( kakoune ) diff --git a/test/normal/trim/table/selections b/test/normal/trim/table/selections new file mode 100644 index 00000000..ed988a11 --- /dev/null +++ b/test/normal/trim/table/selections @@ -0,0 +1 @@ +foo:bar:qux:pop:hip:kakoune |
