Ticket #113: 16003-cedit-configurable-highlight.diff
File 16003-cedit-configurable-highlight.diff, 11.0 KB (added by slavazanko, 16 years ago) |
---|
-
edit/edit.c
Move syntax highlighting options into their own menu, and make TAB and Whitespace highlighting selectable. Signed-off-by: Jan Engelhardt <jengelh@computergmbh.de> --- edit/edit.c | 6 ++ edit/edit.h | 7 ++ edit/editcmddef.h | 1 edit/editdraw.c | 4 + edit/editkeys.c | 1 edit/editmenu.c | 6 ++ edit/editoptions.c | 141 ++++++++++++++++++++++++++++++++++++++++------------- src/setup.c | 1 8 files changed, 133 insertions(+), 34 deletions(-)
old new edit_execute_cmd (WEdit *edit, int comma 2487 2487 edit->force |= REDRAW_PAGE; 2488 2488 break; 2489 2489 2490 case CK_Toggle_Syntax2: 2491 ++option_highlighting; 2492 option_highlighting %= 4; 2493 edit->force |= REDRAW_PAGE; 2494 break; 2495 2490 2496 case CK_Find: 2491 2497 edit_search_cmd (edit, 0); 2492 2498 break; -
edit/edit.h
old new int line_is_blank (WEdit *edit, long lin 228 228 int edit_indent_width (WEdit *edit, long p); 229 229 void edit_insert_indent (WEdit *edit, int indent); 230 230 void edit_options_dialog (void); 231 void edit_syntax_opt_dialog(void); 231 232 void edit_syntax_dialog (void); 232 233 void edit_mail_dialog (WEdit *edit); 233 234 void format_paragraph (WEdit *edit, int force); … … typedef enum { 279 280 EDIT_DO_BACKUP 280 281 } edit_save_mode_t; 281 282 283 enum { 284 HL_WHITESPACE = 1 << 0, 285 HL_TABS = 1 << 1, 286 }; 287 282 288 extern int option_save_mode; 283 289 extern int option_save_position; 284 290 extern int option_max_undo; 285 291 extern int option_syntax_highlighting; 292 extern unsigned int option_highlighting; 286 293 extern int option_auto_syntax; 287 294 extern char *option_syntax_type; 288 295 extern int editor_option_check_nl_at_eof; -
edit/editcmddef.h
old new 109 109 #define CK_Maximize 458 110 110 111 111 #define CK_Toggle_Syntax 480 112 #define CK_Toggle_Syntax2 481 112 113 113 114 /* macro */ 114 115 #define CK_Begin_Record_Macro 501 -
edit/editdraw.c
old new print_to_widget (WEdit *edit, long row, 273 273 } 274 274 } 275 275 276 int visible_tabs = 1, visible_tws = 1; 276 unsigned int option_highlighting = HL_TABS | HL_WHITESPACE; 277 #define visible_tabs (option_highlighting & HL_TABS) 278 #define visible_tws (option_highlighting & HL_WHITESPACE) 277 279 278 280 /* b is a pointer to the beginning of the line */ 279 281 static void -
edit/editkeys.c
old new static const edit_key_map_type common_ke 114 114 { XCTRL ('l'), CK_Refresh }, 115 115 { XCTRL ('o'), CK_Shell }, 116 116 { XCTRL ('s'), CK_Toggle_Syntax }, 117 { XCTRL ('v'), CK_Toggle_Syntax2 }, 117 118 { XCTRL ('u'), CK_Undo }, 118 119 { XCTRL ('t'), CK_Select_Codepage }, 119 120 { XCTRL ('q'), CK_Insert_Literal }, -
edit/editmenu.c
old new menu_options (void) 283 283 edit_options_dialog (); 284 284 } 285 285 286 static void menu_syntax_options(void) 287 { 288 edit_syntax_opt_dialog(); 289 } 290 286 291 static void 287 292 menu_syntax (void) 288 293 { … … static menu_entry CmdMenuEmacs[] = 410 415 static menu_entry OptMenu[] = 411 416 { 412 417 {' ', N_("&General... "), 'G', menu_options}, 418 {' ', N_("Highlight options... "), ' ', menu_syntax_options}, 413 419 {' ', N_("&Save mode..."), 'S', menu_save_mode_cmd}, 414 420 {' ', N_("Learn &Keys..."), 'K', learn_keys}, 415 421 {' ', N_("Syntax &Highlighting..."), 'H', menu_syntax}, -
edit/editoptions.c
old new 43 43 #include "../src/dialog.h" /* B_CANCEL */ 44 44 #include "../src/wtools.h" /* QuickDialog */ 45 45 46 #define OPT_DLG_H 1747 #define OPT_DLG_W 7248 49 46 #ifndef USE_INTERNAL_EDIT 50 47 #define USE_INTERNAL_EDIT 1 51 48 #endif … … i18n_translate_array (const char *array[ 65 62 } 66 63 } 67 64 65 #define OPT_DLG_H 12 66 #define OPT_DLG_W 40 67 void edit_syntax_opt_dialog(void) 68 { 69 int f_syntax_hl = option_syntax_highlighting; 70 int f_tab_hl = option_highlighting & HL_TABS; 71 int f_ws_hl = option_highlighting & HL_WHITESPACE; 72 73 int old_syntax_hl = f_syntax_hl; 74 75 QuickWidget quick_widgets[] = { 76 { 77 .widget_type = quick_button, 78 .relative_x = 6, 79 .x_divisions = 10, 80 .relative_y = OPT_DLG_H - 3, 81 .y_divisions = OPT_DLG_H, 82 .text = N_("&Cancel"), 83 .value = B_CANCEL, 84 }, 85 { 86 .widget_type = quick_button, 87 .relative_x = 2, 88 .x_divisions = 10, 89 .relative_y = OPT_DLG_H - 3, 90 .y_divisions = OPT_DLG_H, 91 .text = N_("&OK"), 92 .value = B_ENTER, 93 }, 94 { 95 .widget_type = quick_checkbox, 96 .relative_x = 6, 97 .x_divisions = OPT_DLG_W, 98 .relative_y = 6, 99 .y_divisions = OPT_DLG_H, 100 .text = N_("Whitespace highlighting"), 101 .result = &f_ws_hl, 102 }, 103 { 104 .widget_type = quick_checkbox, 105 .relative_x = 6, 106 .x_divisions = OPT_DLG_W, 107 .relative_y = 5, 108 .y_divisions = OPT_DLG_H, 109 .text = N_("Tab highlighting"), 110 .result = &f_tab_hl, 111 }, 112 { 113 .widget_type = quick_checkbox, 114 .relative_x = 6, 115 .x_divisions = OPT_DLG_W, 116 .relative_y = 4, 117 .y_divisions = OPT_DLG_H, 118 .text = N_("Syntax highlighting"), 119 .result = &f_syntax_hl, 120 }, 121 NULL_QuickWidget, 122 }; 123 QuickDialog quick_options = { 124 .xlen = OPT_DLG_W, 125 .ylen = OPT_DLG_H, 126 .xpos = -1, 127 .ypos = 0, 128 .title = N_(" Syntax options "), 129 .help = "", 130 .widgets = quick_widgets, 131 }; 132 133 if (quick_dialog(&quick_options) == B_CANCEL) 134 return; 135 136 if (old_syntax_hl != f_syntax_hl) 137 /* Load or unload syntax rules if the option has changed */ 138 edit_load_syntax(wedit, NULL, option_syntax_type); 139 140 option_syntax_highlighting = f_syntax_hl; 141 option_highlighting = 0; 142 if (f_tab_hl) 143 option_highlighting |= HL_TABS; 144 if (f_ws_hl) 145 option_highlighting |= HL_WHITESPACE; 146 } 147 #undef OPT_DLG_H 148 #undef OPT_DLG_W 149 150 #define OPT_DLG_H 17 151 #define OPT_DLG_W 72 68 152 void 69 153 edit_options_dialog (void) 70 154 { 71 155 char wrap_length[32], tab_spacing[32], *p, *q; 72 156 int wrap_mode = 0; 73 int old_syntax_hl;74 157 int tedit_key_emulation = edit_key_emulation; 75 158 int toption_fill_tabs_with_spaces = option_fill_tabs_with_spaces; 76 159 int toption_save_position = option_save_position; … … edit_options_dialog (void) 102 185 OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0, 0, 0, 103 186 "edit-tab-spacing"}, 104 187 /* 6 */ 105 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 8,106 OPT_DLG_H, N_("Synta&x highlighting"), 8, 0, 0, 0, NULL},107 /* 7 */108 188 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9, 109 189 OPT_DLG_H, N_("Save file &position"), 0, 0, 0, 0, NULL}, 110 /* 8*/190 /* 7 */ 111 191 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10, 112 192 OPT_DLG_H, N_("Confir&m before saving"), 6, 0, 0, 0, NULL}, 113 /* 9*/193 /* 8 */ 114 194 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11, 115 195 OPT_DLG_H, N_("Fill tabs with &spaces"), 0, 0, 0, 0, NULL}, 116 /* 10*/196 /* 9 */ 117 197 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12, 118 198 OPT_DLG_H, N_("&Return does autoindent"), 0, 0, 0, 0, NULL}, 119 /* 1 1*/199 /* 10 */ 120 200 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 13, 121 201 OPT_DLG_H, N_("&Backspace through tabs"), 0, 0, 0, 0, NULL}, 122 /* 1 2*/202 /* 11 */ 123 203 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 14, 124 204 OPT_DLG_H, N_("&Fake half tabs"), 0, 0, 0, 0, NULL}, 125 /* 1 3*/205 /* 12 */ 126 206 {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, "", 3, 0, 0, 127 207 const_cast(char **, wrap_str), "wrapm"}, 128 /* 1 4*/208 /* 13 */ 129 209 {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 8, OPT_DLG_H, 130 210 N_("Wrap mode"), 0, 0, 131 211 0, 0, NULL}, 132 /* 1 5*/212 /* 14 */ 133 213 {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 13, OPT_DLG_H, "", 3, 0, 0, 134 214 const_cast(char **, key_emu_str), "keyemu"}, 135 /* 1 6*/215 /* 15 */ 136 216 {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 14, OPT_DLG_H, 137 217 N_("Key emulation"), 0, 0, 0, 0, NULL}, 138 218 NULL_QuickWidget … … edit_options_dialog (void) 156 236 quick_widgets[3].str_result = &p; 157 237 quick_widgets[5].text = tab_spacing; 158 238 quick_widgets[5].str_result = &q; 159 quick_widgets[6].result = &tedit_syntax_highlighting; 160 quick_widgets[7].result = &toption_save_position; 161 quick_widgets[8].result = &tedit_confirm_save; 162 quick_widgets[9].result = &toption_fill_tabs_with_spaces; 163 quick_widgets[10].result = &toption_return_does_auto_indent; 164 quick_widgets[11].result = &toption_backspace_through_tabs; 165 quick_widgets[12].result = &toption_fake_half_tabs; 239 quick_widgets[6].result = &toption_save_position; 240 quick_widgets[7].result = &tedit_confirm_save; 241 quick_widgets[8].result = &toption_fill_tabs_with_spaces; 242 quick_widgets[9].result = &toption_return_does_auto_indent; 243 quick_widgets[10].result = &toption_backspace_through_tabs; 244 quick_widgets[11].result = &toption_fake_half_tabs; 166 245 167 246 if (option_auto_para_formatting) 168 247 wrap_mode = 1; … … edit_options_dialog (void) 171 250 else 172 251 wrap_mode = 0; 173 252 174 quick_widgets[1 3].result = &wrap_mode;175 quick_widgets[1 3].value = wrap_mode;253 quick_widgets[12].result = &wrap_mode; 254 quick_widgets[12].value = wrap_mode; 176 255 177 quick_widgets[1 5].result = &tedit_key_emulation;178 quick_widgets[1 5].value = tedit_key_emulation;256 quick_widgets[14].result = &tedit_key_emulation; 257 quick_widgets[14].value = tedit_key_emulation; 179 258 180 259 Quick_options.widgets = quick_widgets; 181 260 182 261 if (quick_dialog (&Quick_options) == B_CANCEL) 183 262 return; 184 263 185 old_syntax_hl = option_syntax_highlighting;186 187 264 if (p) { 188 265 option_word_wrap_line_length = atoi (p); 189 266 g_free (p); … … edit_options_dialog (void) 195 272 g_free (q); 196 273 } 197 274 198 option_syntax_highlighting = tedit_syntax_highlighting;199 275 edit_confirm_save = tedit_confirm_save; 200 276 option_save_position = toption_save_position; 201 277 option_fill_tabs_with_spaces = toption_fill_tabs_with_spaces; … … edit_options_dialog (void) 220 296 edit_reload_menu (); 221 297 } 222 298 223 /* Load or unload syntax rules if the option has changed */224 if (option_syntax_highlighting != old_syntax_hl)225 edit_load_syntax (wedit, NULL, option_syntax_type);226 299 /* Load usermap if it's needed */ 227 300 edit_load_user_map (wedit); 228 301 } 302 #undef DLG_OPT_W 303 #undef DLG_OPT_H -
src/setup.c
old new static const struct { 216 216 { "editor_option_typewriter_wrap", &option_typewriter_wrap }, 217 217 { "editor_edit_confirm_save", &edit_confirm_save }, 218 218 { "editor_syntax_highlighting", &option_syntax_highlighting }, 219 { "editor_highlight", &option_highlighting }, 219 220 #endif /* USE_INTERNAL_EDIT */ 220 221 221 222 { "nice_rotating_dash", &nice_rotating_dash },