Merge branch '3119_format_paragraph'

* 3119_format_paragraph:
  Add editor_stop_format_chars ini option.
  (format_paragraph): fix wrong refactoring.
  Ticket #3119: fix format paragrap formatting.
This commit is contained in:
Andrew Borodin 2014-01-14 14:39:45 +04:00
commit bc2f24b0e5
4 changed files with 32 additions and 10 deletions

View File

@ -598,6 +598,12 @@ Use
.B spell_language = NONE .B spell_language = NONE
to disable aspell support. Default value is 'en'. Option must located to disable aspell support. Default value is 'en'. Option must located
in the [Misc] section. 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 .SH MISCELLANEOUS
You can use scanf search and replace to search and replace a C format You can use scanf search and replace to search and replace a C format
string. First take a look at the string. First take a look at the

View File

@ -49,6 +49,7 @@ extern int option_syntax_highlighting;
extern int option_group_undo; extern int option_group_undo;
extern char *option_backup_ext; extern char *option_backup_ext;
extern char *option_filesize_threshold; extern char *option_filesize_threshold;
extern char *option_stop_format_chars;
extern int edit_confirm_save; extern int edit_confirm_save;

View File

@ -57,11 +57,12 @@
/*** global variables ****************************************************************************/ /*** global variables ****************************************************************************/
char *option_stop_format_chars = NULL;
/*** file scope macro definitions ****************************************************************/ /*** file scope macro definitions ****************************************************************/
#define tab_width option_tab_spacing #define tab_width option_tab_spacing
#define NO_FORMAT_CHARS_START "-+*\\,.;:&>"
#define FONT_MEAN_WIDTH 1 #define FONT_MEAN_WIDTH 1
/*** file scope type declarations ****************************************************************/ /*** 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) == '-'); && 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); return (-1);
if (c == ' ' || c == '\t') if (c == ' ' || c == '\t')
return i; return i;
i--;
} }
} }
@ -498,15 +498,29 @@ format_paragraph (WEdit * edit, gboolean force)
if (!force) if (!force)
{ {
off_t i; off_t i;
char *stop_format_chars;
if (strchr (NO_FORMAT_CHARS_START, t->str[0]) == NULL) if (option_stop_format_chars != NULL
for (i = 0; i < size - 1; i++) && strchr (option_stop_format_chars, t->str[0]) != NULL)
if (t->str[i] == '\n' {
&& strchr (NO_FORMAT_CHARS_START "\t ", t->str[i + 1]) != NULL) g_string_free (t, TRUE);
break; return;
}
g_string_free (t, TRUE); if (option_stop_format_chars == NULL || *option_stop_format_chars == '\0')
return; 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); t2 = (unsigned char *) g_string_free (t, FALSE);

View File

@ -376,6 +376,7 @@ static const struct
#ifdef USE_INTERNAL_EDIT #ifdef USE_INTERNAL_EDIT
{ "editor_backup_extension", &option_backup_ext, "~" }, { "editor_backup_extension", &option_backup_ext, "~" },
{ "editor_filesize_threshold", &option_filesize_threshold, "64M" }, { "editor_filesize_threshold", &option_filesize_threshold, "64M" },
{ "editor_stop_format_chars", &option_stop_format_chars, "-+*\\,.;:&>" },
#endif #endif
{ "mcview_eof", &mcview_show_eof, "" }, { "mcview_eof", &mcview_show_eof, "" },
{ NULL, NULL, NULL } { NULL, NULL, NULL }