1fb3774
1fb3774
Move syntax highlighting options into their own menu, and make TAB and
1fb3774
Whitespace highlighting selectable.
1fb3774
1fb3774
Signed-off-by: Jan Engelhardt <jengelh@computergmbh.de>
1fb3774
1fb3774
---
1fb3774
 edit/edit.c        |    6 ++
1fb3774
 edit/edit.h        |    7 ++
1fb3774
 edit/editcmddef.h  |    1 
1fb3774
 edit/editdraw.c    |    4 +
1fb3774
 edit/editkeys.c    |    1 
1fb3774
 edit/editmenu.c    |    6 ++
1fb3774
 edit/editoptions.c |  141 ++++++++++++++++++++++++++++++++++++++++-------------
1fb3774
 src/setup.c        |    1 
1fb3774
 8 files changed, 133 insertions(+), 34 deletions(-)
1fb3774
1fb3774
Index: mc/edit/edit.c
1fb3774
===================================================================
1fb3774
--- mc.orig/edit/edit.c
1fb3774
+++ mc/edit/edit.c
1fb3774
@@ -2487,6 +2487,12 @@ edit_execute_cmd (WEdit *edit, int comma
1fb3774
 	edit->force |= REDRAW_PAGE;
1fb3774
 	break;
1fb3774
 
1fb3774
+    case CK_Toggle_Syntax2:
1fb3774
+	++option_highlighting;
1fb3774
+	option_highlighting %= 4;
1fb3774
+	edit->force |= REDRAW_PAGE;
1fb3774
+	break;
1fb3774
+
1fb3774
     case CK_Find:
1fb3774
 	edit_search_cmd (edit, 0);
1fb3774
 	break;
1fb3774
Index: mc/edit/edit.h
1fb3774
===================================================================
1fb3774
--- mc.orig/edit/edit.h
1fb3774
+++ mc/edit/edit.h
1fb3774
@@ -228,6 +228,7 @@ int line_is_blank (WEdit *edit, long lin
1fb3774
 int edit_indent_width (WEdit *edit, long p);
1fb3774
 void edit_insert_indent (WEdit *edit, int indent);
1fb3774
 void edit_options_dialog (void);
1fb3774
+void edit_syntax_opt_dialog(void);
1fb3774
 void edit_syntax_dialog (void);
1fb3774
 void edit_mail_dialog (WEdit *edit);
1fb3774
 void format_paragraph (WEdit *edit, int force);
1fb3774
@@ -279,10 +280,16 @@ typedef enum {
1fb3774
     EDIT_DO_BACKUP
1fb3774
 } edit_save_mode_t;
1fb3774
 
1fb3774
+enum {
1fb3774
+	HL_WHITESPACE = 1 << 0,
1fb3774
+	HL_TABS       = 1 << 1,
1fb3774
+};
1fb3774
+
1fb3774
 extern int option_save_mode;
1fb3774
 extern int option_save_position;
1fb3774
 extern int option_max_undo;
1fb3774
 extern int option_syntax_highlighting;
1fb3774
+extern unsigned int option_highlighting;
1fb3774
 extern int option_auto_syntax;
1fb3774
 extern char *option_syntax_type;
1fb3774
 extern int editor_option_check_nl_at_eof;
1fb3774
Index: mc/edit/editcmddef.h
1fb3774
===================================================================
1fb3774
--- mc.orig/edit/editcmddef.h
1fb3774
+++ mc/edit/editcmddef.h
1fb3774
@@ -109,6 +109,7 @@
1fb3774
 #define CK_Maximize		458
1fb3774
 
1fb3774
 #define CK_Toggle_Syntax	480
1fb3774
+#define CK_Toggle_Syntax2	481
1fb3774
 
1fb3774
 /* macro */
1fb3774
 #define CK_Begin_Record_Macro	501
1fb3774
Index: mc/edit/editdraw.c
1fb3774
===================================================================
1fb3774
--- mc.orig/edit/editdraw.c
1fb3774
+++ mc/edit/editdraw.c
1fb3774
@@ -273,7 +273,9 @@ print_to_widget (WEdit *edit, long row,
1fb3774
     }
1fb3774
 }
1fb3774
 
1fb3774
-int visible_tabs = 1, visible_tws = 1;
1fb3774
+unsigned int option_highlighting = HL_TABS | HL_WHITESPACE;
1fb3774
+#define visible_tabs (option_highlighting & HL_TABS)
1fb3774
+#define visible_tws  (option_highlighting & HL_WHITESPACE)
1fb3774
 
1fb3774
 /* b is a pointer to the beginning of the line */
1fb3774
 static void
1fb3774
Index: mc/edit/editkeys.c
1fb3774
===================================================================
1fb3774
--- mc.orig/edit/editkeys.c
1fb3774
+++ mc/edit/editkeys.c
1fb3774
@@ -114,6 +114,7 @@ static const edit_key_map_type common_ke
1fb3774
     { XCTRL ('l'), CK_Refresh },
1fb3774
     { XCTRL ('o'), CK_Shell },
1fb3774
     { XCTRL ('s'), CK_Toggle_Syntax },
1fb3774
+    { XCTRL ('v'), CK_Toggle_Syntax2 },
1fb3774
     { XCTRL ('u'), CK_Undo },
1fb3774
     { XCTRL ('t'), CK_Select_Codepage },
1fb3774
     { XCTRL ('q'), CK_Insert_Literal },
1fb3774
Index: mc/edit/editmenu.c
1fb3774
===================================================================
1fb3774
--- mc.orig/edit/editmenu.c
1fb3774
+++ mc/edit/editmenu.c
1fb3774
@@ -283,6 +283,11 @@ menu_options (void)
1fb3774
     edit_options_dialog ();
1fb3774
 }
1fb3774
 
1fb3774
+static void menu_syntax_options(void)
1fb3774
+{
1fb3774
+	edit_syntax_opt_dialog();
1fb3774
+}
1fb3774
+
1fb3774
 static void
1fb3774
 menu_syntax (void)
1fb3774
 {
1fb3774
@@ -410,6 +415,7 @@ static menu_entry CmdMenuEmacs[] =
1fb3774
 static menu_entry OptMenu[] =
1fb3774
 {
1fb3774
     {' ', N_("&General...  "), 'G', menu_options},
1fb3774
+    {' ', N_("Highlight options... "), ' ', menu_syntax_options},
1fb3774
     {' ', N_("&Save mode..."), 'S', menu_save_mode_cmd},
1fb3774
     {' ', N_("Learn &Keys..."), 'K', learn_keys},
1fb3774
     {' ', N_("Syntax &Highlighting..."), 'H', menu_syntax},
1fb3774
Index: mc/edit/editoptions.c
1fb3774
===================================================================
1fb3774
--- mc.orig/edit/editoptions.c
1fb3774
+++ mc/edit/editoptions.c
1fb3774
@@ -43,9 +43,6 @@
1fb3774
 #include "../src/dialog.h"	/* B_CANCEL */
1fb3774
 #include "../src/wtools.h"	/* QuickDialog */
1fb3774
 
1fb3774
-#define OPT_DLG_H 17
1fb3774
-#define OPT_DLG_W 72
1fb3774
-
1fb3774
 #ifndef USE_INTERNAL_EDIT
1fb3774
 #define USE_INTERNAL_EDIT 1
1fb3774
 #endif
1fb3774
@@ -65,12 +62,98 @@ i18n_translate_array (const char *array[
1fb3774
     }
1fb3774
 }
1fb3774
 
1fb3774
+#define OPT_DLG_H 12
1fb3774
+#define OPT_DLG_W 40
1fb3774
+void edit_syntax_opt_dialog(void)
1fb3774
+{
1fb3774
+	int f_syntax_hl = option_syntax_highlighting;
1fb3774
+	int f_tab_hl    = option_highlighting & HL_TABS;
1fb3774
+	int f_ws_hl     = option_highlighting & HL_WHITESPACE;
1fb3774
+
1fb3774
+	int old_syntax_hl = f_syntax_hl;
1fb3774
+
1fb3774
+	QuickWidget quick_widgets[] = {
1fb3774
+		{
1fb3774
+			.widget_type = quick_button,
1fb3774
+			.relative_x  = 6,
1fb3774
+			.x_divisions = 10,
1fb3774
+			.relative_y  = OPT_DLG_H - 3,
1fb3774
+			.y_divisions = OPT_DLG_H,
1fb3774
+			.text        = N_("&Cancel"),
1fb3774
+			.value       = B_CANCEL,
1fb3774
+		},
1fb3774
+		{
1fb3774
+			.widget_type = quick_button,
1fb3774
+			.relative_x  = 2,
1fb3774
+			.x_divisions = 10,
1fb3774
+			.relative_y  = OPT_DLG_H - 3,
1fb3774
+			.y_divisions = OPT_DLG_H,
1fb3774
+			.text        = N_("&OK"),
1fb3774
+			.value       = B_ENTER,
1fb3774
+		},
1fb3774
+		{
1fb3774
+			.widget_type = quick_checkbox,
1fb3774
+			.relative_x  = 6,
1fb3774
+			.x_divisions = OPT_DLG_W,
1fb3774
+			.relative_y  = 6,
1fb3774
+			.y_divisions = OPT_DLG_H,
1fb3774
+			.text        = N_("Whitespace highlighting"),
1fb3774
+			.result      = &f_ws_hl,
1fb3774
+		},
1fb3774
+		{
1fb3774
+			.widget_type = quick_checkbox,
1fb3774
+			.relative_x  = 6,
1fb3774
+			.x_divisions = OPT_DLG_W,
1fb3774
+			.relative_y  = 5,
1fb3774
+			.y_divisions = OPT_DLG_H,
1fb3774
+			.text        = N_("Tab highlighting"),
1fb3774
+			.result      = &f_tab_hl,
1fb3774
+		},
1fb3774
+		{
1fb3774
+			.widget_type = quick_checkbox,
1fb3774
+			.relative_x  = 6,
1fb3774
+			.x_divisions = OPT_DLG_W,
1fb3774
+			.relative_y  = 4,
1fb3774
+			.y_divisions = OPT_DLG_H,
1fb3774
+			.text        = N_("Syntax highlighting"),
1fb3774
+			.result      = &f_syntax_hl,
1fb3774
+		},
1fb3774
+		NULL_QuickWidget,
1fb3774
+	};
1fb3774
+	QuickDialog quick_options = {
1fb3774
+		.xlen    = OPT_DLG_W,
1fb3774
+		.ylen    = OPT_DLG_H,
1fb3774
+		.xpos    = -1,
1fb3774
+		.ypos    = 0,
1fb3774
+		.title   = N_(" Syntax options "),
1fb3774
+		.help    = "",
1fb3774
+		.widgets = quick_widgets,
1fb3774
+	};
1fb3774
+
1fb3774
+	if (quick_dialog(&quick_options) == B_CANCEL)
1fb3774
+		return;
1fb3774
+
1fb3774
+	if (old_syntax_hl != f_syntax_hl)
1fb3774
+		/* Load or unload syntax rules if the option has changed */
1fb3774
+		edit_load_syntax(wedit, NULL, option_syntax_type);
1fb3774
+
1fb3774
+	option_syntax_highlighting = f_syntax_hl;
1fb3774
+	option_highlighting = 0;
1fb3774
+	if (f_tab_hl)
1fb3774
+		option_highlighting |= HL_TABS;
1fb3774
+	if (f_ws_hl)
1fb3774
+		option_highlighting |= HL_WHITESPACE;
1fb3774
+}
1fb3774
+#undef OPT_DLG_H
1fb3774
+#undef OPT_DLG_W
1fb3774
+
1fb3774
+#define OPT_DLG_H 17
1fb3774
+#define OPT_DLG_W 72
1fb3774
 void
1fb3774
 edit_options_dialog (void)
1fb3774
 {
1fb3774
     char wrap_length[32], tab_spacing[32], *p, *q;
1fb3774
     int wrap_mode = 0;
1fb3774
-    int old_syntax_hl;
1fb3774
     int tedit_key_emulation = edit_key_emulation;
1fb3774
     int toption_fill_tabs_with_spaces = option_fill_tabs_with_spaces;
1fb3774
     int toption_save_position = option_save_position;
1fb3774
@@ -102,37 +185,34 @@ edit_options_dialog (void)
1fb3774
 	 OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0, 0, 0,
1fb3774
 	 "edit-tab-spacing"},
1fb3774
 	/* 6 */
1fb3774
-	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 8,
1fb3774
-	 OPT_DLG_H, N_("Synta&x highlighting"), 8, 0, 0, 0, NULL},
1fb3774
-	/* 7 */
1fb3774
 	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9,
1fb3774
 	 OPT_DLG_H, N_("Save file &position"), 0, 0, 0, 0, NULL},
1fb3774
-	/* 8 */
1fb3774
+	/* 7 */
1fb3774
 	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10,
1fb3774
 	 OPT_DLG_H, N_("Confir&m before saving"), 6, 0, 0, 0, NULL},
1fb3774
-	/* 9 */
1fb3774
+	/* 8 */
1fb3774
 	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11,
1fb3774
 	 OPT_DLG_H, N_("Fill tabs with &spaces"), 0, 0, 0, 0, NULL},
1fb3774
-	/* 10 */
1fb3774
+	/* 9 */
1fb3774
 	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12,
1fb3774
 	 OPT_DLG_H, N_("&Return does autoindent"), 0, 0, 0, 0, NULL},
1fb3774
-	/* 11 */
1fb3774
+	/* 10 */
1fb3774
 	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 13,
1fb3774
 	 OPT_DLG_H, N_("&Backspace through tabs"), 0, 0, 0, 0, NULL},
1fb3774
-	/* 12 */
1fb3774
+	/* 11 */
1fb3774
 	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 14,
1fb3774
 	 OPT_DLG_H, N_("&Fake half tabs"), 0, 0, 0, 0, NULL},
1fb3774
-	/* 13 */
1fb3774
+	/* 12 */
1fb3774
 	{quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, "", 3, 0, 0,
1fb3774
 	 const_cast(char **, wrap_str), "wrapm"},
1fb3774
-	/* 14 */
1fb3774
+	/* 13 */
1fb3774
 	{quick_label, 4, OPT_DLG_W, OPT_DLG_H - 8, OPT_DLG_H,
1fb3774
 	 N_("Wrap mode"), 0, 0,
1fb3774
 	 0, 0, NULL},
1fb3774
-	/* 15 */
1fb3774
+	/* 14 */
1fb3774
 	{quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 13, OPT_DLG_H, "", 3, 0, 0,
1fb3774
 	 const_cast(char **, key_emu_str), "keyemu"},
1fb3774
-	/* 16 */
1fb3774
+	/* 15 */
1fb3774
 	{quick_label, 4, OPT_DLG_W, OPT_DLG_H - 14, OPT_DLG_H,
1fb3774
 	 N_("Key emulation"), 0, 0, 0, 0, NULL},
1fb3774
 	NULL_QuickWidget
1fb3774
@@ -156,13 +236,12 @@ edit_options_dialog (void)
1fb3774
     quick_widgets[3].str_result = &p;
1fb3774
     quick_widgets[5].text = tab_spacing;
1fb3774
     quick_widgets[5].str_result = &q;
1fb3774
-    quick_widgets[6].result = &tedit_syntax_highlighting;
1fb3774
-    quick_widgets[7].result = &toption_save_position;
1fb3774
-    quick_widgets[8].result = &tedit_confirm_save;
1fb3774
-    quick_widgets[9].result = &toption_fill_tabs_with_spaces;
1fb3774
-    quick_widgets[10].result = &toption_return_does_auto_indent;
1fb3774
-    quick_widgets[11].result = &toption_backspace_through_tabs;
1fb3774
-    quick_widgets[12].result = &toption_fake_half_tabs;
1fb3774
+    quick_widgets[6].result = &toption_save_position;
1fb3774
+    quick_widgets[7].result = &tedit_confirm_save;
1fb3774
+    quick_widgets[8].result = &toption_fill_tabs_with_spaces;
1fb3774
+    quick_widgets[9].result = &toption_return_does_auto_indent;
1fb3774
+    quick_widgets[10].result = &toption_backspace_through_tabs;
1fb3774
+    quick_widgets[11].result = &toption_fake_half_tabs;
1fb3774
 
1fb3774
     if (option_auto_para_formatting)
1fb3774
 	wrap_mode = 1;
1fb3774
@@ -171,19 +250,17 @@ edit_options_dialog (void)
1fb3774
     else
1fb3774
 	wrap_mode = 0;
1fb3774
 
1fb3774
-    quick_widgets[13].result = &wrap_mode;
1fb3774
-    quick_widgets[13].value = wrap_mode;
1fb3774
+    quick_widgets[12].result = &wrap_mode;
1fb3774
+    quick_widgets[12].value = wrap_mode;
1fb3774
 
1fb3774
-    quick_widgets[15].result = &tedit_key_emulation;
1fb3774
-    quick_widgets[15].value = tedit_key_emulation;
1fb3774
+    quick_widgets[14].result = &tedit_key_emulation;
1fb3774
+    quick_widgets[14].value = tedit_key_emulation;
1fb3774
 
1fb3774
     Quick_options.widgets = quick_widgets;
1fb3774
 
1fb3774
     if (quick_dialog (&Quick_options) == B_CANCEL)
1fb3774
 	return;
1fb3774
 
1fb3774
-    old_syntax_hl = option_syntax_highlighting;
1fb3774
-
1fb3774
     if (p) {
1fb3774
 	option_word_wrap_line_length = atoi (p);
1fb3774
 	g_free (p);
1fb3774
@@ -195,7 +272,6 @@ edit_options_dialog (void)
1fb3774
 	g_free (q);
1fb3774
     }
1fb3774
 
1fb3774
-    option_syntax_highlighting = tedit_syntax_highlighting;
1fb3774
     edit_confirm_save = tedit_confirm_save;
1fb3774
     option_save_position = toption_save_position;
1fb3774
     option_fill_tabs_with_spaces = toption_fill_tabs_with_spaces;
1fb3774
@@ -220,9 +296,8 @@ edit_options_dialog (void)
1fb3774
 	edit_reload_menu ();
1fb3774
     }
1fb3774
 
1fb3774
-    /* Load or unload syntax rules if the option has changed */
1fb3774
-    if (option_syntax_highlighting != old_syntax_hl)
1fb3774
- 	edit_load_syntax (wedit, NULL, option_syntax_type);
1fb3774
     /* Load usermap if it's needed */
1fb3774
     edit_load_user_map (wedit);
1fb3774
 }
1fb3774
+#undef DLG_OPT_W
1fb3774
+#undef DLG_OPT_H
1fb3774
Index: mc/src/setup.c
1fb3774
===================================================================
1fb3774
--- mc.orig/src/setup.c
1fb3774
+++ mc/src/setup.c
1fb3774
@@ -216,6 +216,7 @@ static const struct {
1fb3774
     { "editor_option_typewriter_wrap", &option_typewriter_wrap },
1fb3774
     { "editor_edit_confirm_save", &edit_confirm_save },
1fb3774
     { "editor_syntax_highlighting", &option_syntax_highlighting },
1fb3774
+    { "editor_highlight", &option_highlighting },
1fb3774
 #endif /* USE_INTERNAL_EDIT */
1fb3774
 
1fb3774
     { "nice_rotating_dash", &nice_rotating_dash },