From 1f85332906dea437b7efe9bf4a50984513bc8883 Mon Sep 17 00:00:00 2001 From: "Gavin D. Howard" Date: Wed, 30 Aug 2017 04:17:08 -0600 Subject: [PATCH] Make the trailsave plugin also strip trailing lines (#135) Make the trailsave plugin also strip trailing lines --- plugins/trailsave/xed-trail-save-plugin.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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