Exemple #1
0
void
format_paragraph (WEdit *edit, int force)
{
    long p, q;
    int size;
    unsigned char *t;
    int indent = 0;
    if (option_word_wrap_line_length < 2)
	return;
    if (line_is_blank (edit, edit->curs_line))
	return;
    p = begin_paragraph (edit, force);
    q = end_paragraph (edit, force);
    indent = test_indent (edit, p, q);
    t = get_paragraph (edit, p, q, indent, &size);
    if (!t)
	return;
    if (!force) {
	int i;
	if (strchr (NO_FORMAT_CHARS_START, *t)) {
	    g_free (t);
	    return;
	}
	for (i = 0; i < size - 1; i++) {
	    if (t[i] == '\n') {
		if (strchr (NO_FORMAT_CHARS_START "\t ", t[i + 1])) {
		    g_free (t);
		    return;
		}
	    }
	}
    }
    format_this (t, q - p, indent);
    put_paragraph (edit, t, p, indent, size);
    g_free (t);

    /* Scroll left as much as possible to show the formatted paragraph */
    edit_scroll_left (edit, -edit->start_col);
}
Exemple #2
0
void
format_paragraph (WEdit * edit, gboolean force)
{
    off_t p, q;
    off_t size;
    GString *t;
    long indent;
    unsigned char *t2;
    gboolean utf8 = FALSE;

    if (option_word_wrap_line_length < 2)
        return;
    if (edit_line_is_blank (edit, edit->buffer.curs_line))
        return;

    p = begin_paragraph (edit, force);
    q = end_paragraph (edit, force);
    indent = test_indent (edit, p, q);

    t = get_paragraph (&edit->buffer, p, q, indent != 0);
    size = t->len - 1;

    if (!force)
    {
        off_t i;
        char *stop_format_chars;

        if (option_stop_format_chars != NULL
            && strchr (option_stop_format_chars, t->str[0]) != NULL)
        {
            g_string_free (t, TRUE);
            return;
        }

        if (option_stop_format_chars == NULL || *option_stop_format_chars == '\0')
            stop_format_chars = g_strdup ("\t");
        else
            stop_format_chars = g_strconcat (option_stop_format_chars, "\t", (char *) NULL);

        for (i = 0; i < size - 1; i++)
            if (t->str[i] == '\n' && strchr (stop_format_chars, t->str[i + 1]) != NULL)
            {
                g_free (stop_format_chars);
                g_string_free (t, TRUE);
                return;
            }

        g_free (stop_format_chars);
    }

    t2 = (unsigned char *) g_string_free (t, FALSE);
#ifdef HAVE_CHARSET
    utf8 = edit->utf8;
#endif
    format_this (t2, q - p, indent, utf8);
    put_paragraph (edit, t2, p, indent, size);
    g_free ((char *) t2);

    /* Scroll left as much as possible to show the formatted paragraph */
    edit_scroll_left (edit, -edit->start_col);
}
Exemple #3
0
void
format_paragraph (WEdit * edit, gboolean force)
{
    off_t p, q;
    long lines;
    off_t size;
    GString *t;
    long indent;
    unsigned char *t2;
    gboolean utf8 = FALSE;

    if (option_word_wrap_line_length < 2)
        return;
    if (edit_line_is_blank (edit, edit->buffer.curs_line))
        return;

    p = begin_paragraph (edit, force, &lines);
    q = end_paragraph (edit, force);
    indent = test_indent (edit, p, q);

    t = get_paragraph (&edit->buffer, p, q, indent != 0);
    size = t->len - 1;

    if (!force)
    {
        off_t i;
        char *stop_format_chars;

        if (option_stop_format_chars != NULL
            && strchr (option_stop_format_chars, t->str[0]) != NULL)
        {
            g_string_free (t, TRUE);
            return;
        }

        if (option_stop_format_chars == NULL || *option_stop_format_chars == '\0')
            stop_format_chars = g_strdup ("\t");
        else
            stop_format_chars = g_strconcat (option_stop_format_chars, "\t", (char *) NULL);

        for (i = 0; i < size - 1; i++)
            if (t->str[i] == '\n' && strchr (stop_format_chars, t->str[i + 1]) != NULL)
            {
                g_free (stop_format_chars);
                g_string_free (t, TRUE);
                return;
            }

        g_free (stop_format_chars);
    }

    t2 = (unsigned char *) g_string_free (t, FALSE);
#ifdef HAVE_CHARSET
    utf8 = edit->utf8;
#endif
    /* scroll up to show 1st line of paragraph */
    edit_move_up (edit, lines, TRUE);
    /* scroll left as much as possible to show the formatted paragraph */
    edit_scroll_left (edit, -edit->start_col);

    format_this (t2, q - p, indent, utf8);
    put_paragraph (edit, t2, p, indent, size);
    g_free ((char *) t2);

    /* move to the end of paragraph */
    q = end_paragraph (edit, force);
    edit_cursor_move (edit, q - edit->buffer.curs1);

    /* try move to the start of next paragraph */
    if (edit->buffer.curs_line < edit->buffer.lines)
    {
        edit_execute_cmd (edit, CK_Home, -1);

        do
        {
            edit_execute_cmd (edit, CK_Down, -1);
        }
        while (edit->buffer.curs_line < edit->buffer.lines
               && edit_line_is_blank (edit, edit->buffer.curs_line));
    }
}