summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2011-12-20 14:27:01 +0000
committerMaxime Coste <frrrwww@gmail.com>2011-12-20 14:27:01 +0000
commit17cab9c7c4d820b762b5d8e6e703a6d4bd3e30e3 (patch)
tree2daf4bf1589a18c2e8c2716372a215accc3e27b6 /src
parente77f58c0108c5298581a148d034de9262cb2172f (diff)
Filters: add cleanup_whitespace filter
this filter remove trailing whitespaces on the previous line when inserting an end-of-line.
Diffstat (limited to 'src')
-rw-r--r--src/filters.cc18
-rw-r--r--src/kakrc1
2 files changed, 19 insertions, 0 deletions
diff --git a/src/filters.cc b/src/filters.cc
index 42fa50c7..8290d6a7 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -20,6 +20,23 @@ void preserve_indent(Buffer& buffer, Modification& modification)
}
}
+void cleanup_whitespaces(Buffer& buffer, Modification& modification)
+{
+ if (modification.type == Modification::Insert and
+ modification.content[0] == '\n' and not modification.position.is_begin())
+ {
+ BufferIterator position = modification.position-1;
+ while (*position == ' ' or *position == '\t' and not position.is_begin())
+ --position;
+ ++position;
+ if (position != modification.position)
+ {
+ buffer.modify(Modification::make_erase(position, modification.position));
+ modification.position = position;
+ }
+ }
+}
+
void expand_tabulations(Buffer& buffer, Modification& modification)
{
const int tabstop = 8;
@@ -63,6 +80,7 @@ void register_filters()
FilterRegistry& registry = FilterRegistry::instance();
registry.register_factory("preserve_indent", SimpleFilterFactory<preserve_indent>("preserve_indent"));
+ registry.register_factory("cleanup_whitespaces", SimpleFilterFactory<cleanup_whitespaces>("cleanup_whitespaces"));
registry.register_factory("expand_tabulations", SimpleFilterFactory<expand_tabulations>("expand_tabulations"));
}
diff --git a/src/kakrc b/src/kakrc
index cd65ca56..e175a484 100644
--- a/src/kakrc
+++ b/src/kakrc
@@ -1,3 +1,4 @@
hook WinCreate .*\.(c|cc|cpp|cxx|C|h|hh|hpp|hxx|H) addhl hlcpp
hook WinCreate .*\.(c|cc|cpp|cxx|C|h|hh|hpp|hxx|H) addfilter preserve_indent
+hook WinCreate .*\.(c|cc|cpp|cxx|C|h|hh|hpp|hxx|H) addfilter cleanup_whitespaces
hook WinCreate .* addhl regex \h+(?=\n) default red