diff --git a/plugins/trailsave/xed-trail-save-plugin.c b/plugins/trailsave/xed-trail-save-plugin.c index b1e2495..288e5e8 100644 --- a/plugins/trailsave/xed-trail-save-plugin.c +++ b/plugins/trailsave/xed-trail-save-plugin.c @@ -20,6 +20,8 @@ #include #endif +#include + #include "xed-trail-save-plugin.h" #include @@ -59,6 +61,7 @@ strip_trailing_spaces (GtkTextBuffer *text_buffer) gchar byte; gint byte_index; gint strip_start_index, strip_end_index; + gint empty_lines_start = -1; gboolean should_strip; GtkTextIter strip_start, strip_end; @@ -89,6 +92,7 @@ strip_trailing_spaces (GtkTextBuffer *text_buffer) /* Find indices of bytes that should be stripped */ should_strip = FALSE; + empty_lines_start = (empty_lines_start < 0) ? line_num : empty_lines_start; for (byte_index = 0; slice [byte_index] != 0; ++byte_index) { @@ -111,6 +115,7 @@ strip_trailing_spaces (GtkTextBuffer *text_buffer) else { should_strip = FALSE; + empty_lines_start = -1; } } @@ -124,6 +129,14 @@ strip_trailing_spaces (GtkTextBuffer *text_buffer) gtk_text_buffer_delete (text_buffer, &strip_start, &strip_end); } } + + /* Strip trailing lines (except for one) */ + if (empty_lines_start != -1 && empty_lines_start != (line_count - 1)) + { + gtk_text_buffer_get_iter_at_line (text_buffer, &strip_start, empty_lines_start); + gtk_text_buffer_get_end_iter (text_buffer, &strip_end); + gtk_text_buffer_delete (text_buffer, &strip_start, &strip_end); + } } static void