diff --git a/doc/man/mcedit.1.in b/doc/man/mcedit.1.in index 56bcaf17b..f92ffc82b 100644 --- a/doc/man/mcedit.1.in +++ b/doc/man/mcedit.1.in @@ -598,6 +598,12 @@ Use .B spell_language = NONE to disable aspell support. Default value is 'en'. Option must located in the [Misc] section. +.TP +.I editor_stop_format_chars +Set of characters to stop paragraph formatting. If one of those characters +is found in the begin of line, that line and all following lines of paragraph +will be untouched. Default value is +"\fB-\fR\fB+\fR\fB*\fR\fB\\\fR\fB,\fR\fB.\fR\fB;\fR\fB:\fR\fB&\fR\fB>\fR". .SH MISCELLANEOUS You can use scanf search and replace to search and replace a C format string. First take a look at the diff --git a/src/editor/edit.h b/src/editor/edit.h index 5db38c7eb..0ff0af438 100644 --- a/src/editor/edit.h +++ b/src/editor/edit.h @@ -49,6 +49,7 @@ extern int option_syntax_highlighting; extern int option_group_undo; extern char *option_backup_ext; extern char *option_filesize_threshold; +extern char *option_stop_format_chars; extern int edit_confirm_save; diff --git a/src/editor/wordproc.c b/src/editor/wordproc.c index 8c42ce962..9ac63244e 100644 --- a/src/editor/wordproc.c +++ b/src/editor/wordproc.c @@ -57,11 +57,12 @@ /*** global variables ****************************************************************************/ +char *option_stop_format_chars = NULL; + /*** file scope macro definitions ****************************************************************/ #define tab_width option_tab_spacing -#define NO_FORMAT_CHARS_START "-+*\\,.;:&>" #define FONT_MEAN_WIDTH 1 /*** file scope type declarations ****************************************************************/ @@ -112,7 +113,7 @@ bad_line_start (const edit_buffer_t * buf, off_t p) && edit_buffer_get_byte (buf, p + 2) == '-'); } - return (strchr (NO_FORMAT_CHARS_START, c) != NULL); + return (option_stop_format_chars != NULL && strchr (option_stop_format_chars, c) != NULL); } /* --------------------------------------------------------------------------------------------- */ @@ -316,7 +317,6 @@ word_start (unsigned char *t, off_t q, off_t size) return (-1); if (c == ' ' || c == '\t') return i; - i--; } } @@ -498,15 +498,29 @@ format_paragraph (WEdit * edit, gboolean force) if (!force) { off_t i; + char *stop_format_chars; - if (strchr (NO_FORMAT_CHARS_START, t->str[0]) == NULL) - for (i = 0; i < size - 1; i++) - if (t->str[i] == '\n' - && strchr (NO_FORMAT_CHARS_START "\t ", t->str[i + 1]) != NULL) - break; + if (option_stop_format_chars != NULL + && strchr (option_stop_format_chars, t->str[0]) != NULL) + { + g_string_free (t, TRUE); + return; + } - 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); diff --git a/src/setup.c b/src/setup.c index 99b6c7f6b..20c71454d 100644 --- a/src/setup.c +++ b/src/setup.c @@ -376,6 +376,7 @@ static const struct #ifdef USE_INTERNAL_EDIT { "editor_backup_extension", &option_backup_ext, "~" }, { "editor_filesize_threshold", &option_filesize_threshold, "64M" }, + { "editor_stop_format_chars", &option_stop_format_chars, "-+*\\,.;:&>" }, #endif { "mcview_eof", &mcview_show_eof, "" }, { NULL, NULL, NULL }