Browse Source

Add editor_stop_format_chars ini option.

This option contains a 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
"-+*\,.;:&>".

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 11 years ago
parent
commit
943320c434
4 changed files with 23 additions and 5 deletions
  1. 6 0
      doc/man/mcedit.1.in
  2. 1 0
      src/editor/edit.h
  3. 15 5
      src/editor/wordproc.c
  4. 1 0
      src/setup.c

+ 6 - 0
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

+ 1 - 0
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;
 

+ 15 - 5
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);
 }
 
 /* --------------------------------------------------------------------------------------------- */
@@ -497,20 +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)
+        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 (NO_FORMAT_CHARS_START "\t ", t->str[i + 1]) != NULL)
+            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);

+ 1 - 0
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 }