static GString *
get_next_line(GtkTextBuffer *b, GtkTextIter *iter)
{
- GtkTextIter iter2;
+ GtkTextIter iter2, iter3;
gchar *tmp;
+ GString *line;
+
+ if (gtk_text_iter_is_end(iter))
+ return g_string_new("");
gtk_text_buffer_get_iter_at_line_offset(b,
&iter2,
gtk_text_iter_get_line(iter),
- gtk_text_iter_get_chars_in_line(iter) -1
+ gtk_text_iter_get_chars_in_line(iter) - 1
);
- tmp = gtk_text_buffer_get_text(b, &iter2, iter, FALSE);
+ iter3 = iter2;
+ gtk_text_iter_forward_char(&iter2);
+ if (gtk_text_iter_is_end(&iter2)) {
+ tmp = gtk_text_buffer_get_text(b, &iter2, iter, FALSE);
+ } else {
+ tmp = gtk_text_buffer_get_text(b, &iter3, iter, FALSE);
+ }
+ line = g_string_new(tmp);
+
gtk_text_iter_forward_line(iter);
- return g_string_new(tmp);
+
+ return line;
}
static int
get_indent_level(const char *l)
{
int indent = 0;
+
while (l[0]) {
if (l[0] == '>') {
indent++;
l++;
}
- return indent;
+
+ /* if we hit the signature marker "-- ", we return -(indent + 1). This
+ * stops reformatting.
+ */
+ if (strcmp(l, "-- ") == 0) {
+ return -1-indent;
+ } else {
+ return indent;
+ }
}
static void
}
static void
-append_quoted(GString *buf, const int indent, const GString *str, const int cutpoint) {
+append_quoted(GString *buf, int indent, const GString *str, const int cutpoint) {
int i;
+ indent = indent < 0? abs(indent) -1 : indent;
for (i=0; i<=indent; i++) {
g_string_append(buf, "> ");
}
}
static int
-get_breakpoint_utf8(const gchar *s, const gint indent, const gint limit) {
+get_breakpoint_utf8(const gchar *s, gint indent, const gint limit) {
gint index = 0;
const gchar *pos, *last;
gunichar *uni;
+ indent = indent < 0? abs(indent) -1 : indent;
+
last = NULL;
pos = s;
uni = g_utf8_to_ucs4_fast(s, -1, NULL);
index++;
}
g_free(uni);
- return index;
+ return strlen(s);
}
static int
rem_indent = indent;
append_quoted(q, indent, l, breakpoint);
g_string_free(l, TRUE);
- } while (!gtk_text_iter_is_end(&iter));
+ } while (remaining->str[0] || !gtk_text_iter_is_end(&iter));
return g_string_free(q, FALSE);
}