Ticket #113: 16003-cedit-configurable-highlight.diff

File 16003-cedit-configurable-highlight.diff, 11.0 KB (added by slavazanko, 15 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 
    24872487        edit->force |= REDRAW_PAGE; 
    24882488        break; 
    24892489 
     2490    case CK_Toggle_Syntax2: 
     2491        ++option_highlighting; 
     2492        option_highlighting %= 4; 
     2493        edit->force |= REDRAW_PAGE; 
     2494        break; 
     2495 
    24902496    case CK_Find: 
    24912497        edit_search_cmd (edit, 0); 
    24922498        break; 
  • edit/edit.h

    old new int line_is_blank (WEdit *edit, long lin 
    228228int edit_indent_width (WEdit *edit, long p); 
    229229void edit_insert_indent (WEdit *edit, int indent); 
    230230void edit_options_dialog (void); 
     231void edit_syntax_opt_dialog(void); 
    231232void edit_syntax_dialog (void); 
    232233void edit_mail_dialog (WEdit *edit); 
    233234void format_paragraph (WEdit *edit, int force); 
    typedef enum { 
    279280    EDIT_DO_BACKUP 
    280281} edit_save_mode_t; 
    281282 
     283enum { 
     284        HL_WHITESPACE = 1 << 0, 
     285        HL_TABS       = 1 << 1, 
     286}; 
     287 
    282288extern int option_save_mode; 
    283289extern int option_save_position; 
    284290extern int option_max_undo; 
    285291extern int option_syntax_highlighting; 
     292extern unsigned int option_highlighting; 
    286293extern int option_auto_syntax; 
    287294extern char *option_syntax_type; 
    288295extern int editor_option_check_nl_at_eof; 
  • edit/editcmddef.h

    old new  
    109109#define CK_Maximize             458 
    110110 
    111111#define CK_Toggle_Syntax        480 
     112#define CK_Toggle_Syntax2       481 
    112113 
    113114/* macro */ 
    114115#define CK_Begin_Record_Macro   501 
  • edit/editdraw.c

    old new print_to_widget (WEdit *edit, long row, 
    273273    } 
    274274} 
    275275 
    276 int visible_tabs = 1, visible_tws = 1; 
     276unsigned int option_highlighting = HL_TABS | HL_WHITESPACE; 
     277#define visible_tabs (option_highlighting & HL_TABS) 
     278#define visible_tws  (option_highlighting & HL_WHITESPACE) 
    277279 
    278280/* b is a pointer to the beginning of the line */ 
    279281static void 
  • edit/editkeys.c

    old new static const edit_key_map_type common_ke 
    114114    { XCTRL ('l'), CK_Refresh }, 
    115115    { XCTRL ('o'), CK_Shell }, 
    116116    { XCTRL ('s'), CK_Toggle_Syntax }, 
     117    { XCTRL ('v'), CK_Toggle_Syntax2 }, 
    117118    { XCTRL ('u'), CK_Undo }, 
    118119    { XCTRL ('t'), CK_Select_Codepage }, 
    119120    { XCTRL ('q'), CK_Insert_Literal }, 
  • edit/editmenu.c

    old new menu_options (void) 
    283283    edit_options_dialog (); 
    284284} 
    285285 
     286static void menu_syntax_options(void) 
     287{ 
     288        edit_syntax_opt_dialog(); 
     289} 
     290 
    286291static void 
    287292menu_syntax (void) 
    288293{ 
    static menu_entry CmdMenuEmacs[] = 
    410415static menu_entry OptMenu[] = 
    411416{ 
    412417    {' ', N_("&General...  "), 'G', menu_options}, 
     418    {' ', N_("Highlight options... "), ' ', menu_syntax_options}, 
    413419    {' ', N_("&Save mode..."), 'S', menu_save_mode_cmd}, 
    414420    {' ', N_("Learn &Keys..."), 'K', learn_keys}, 
    415421    {' ', N_("Syntax &Highlighting..."), 'H', menu_syntax}, 
  • edit/editoptions.c

    old new  
    4343#include "../src/dialog.h"      /* B_CANCEL */ 
    4444#include "../src/wtools.h"      /* QuickDialog */ 
    4545 
    46 #define OPT_DLG_H 17 
    47 #define OPT_DLG_W 72 
    48  
    4946#ifndef USE_INTERNAL_EDIT 
    5047#define USE_INTERNAL_EDIT 1 
    5148#endif 
    i18n_translate_array (const char *array[ 
    6562    } 
    6663} 
    6764 
     65#define OPT_DLG_H 12 
     66#define OPT_DLG_W 40 
     67void 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 
    68152void 
    69153edit_options_dialog (void) 
    70154{ 
    71155    char wrap_length[32], tab_spacing[32], *p, *q; 
    72156    int wrap_mode = 0; 
    73     int old_syntax_hl; 
    74157    int tedit_key_emulation = edit_key_emulation; 
    75158    int toption_fill_tabs_with_spaces = option_fill_tabs_with_spaces; 
    76159    int toption_save_position = option_save_position; 
    edit_options_dialog (void) 
    102185         OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0, 0, 0, 
    103186         "edit-tab-spacing"}, 
    104187        /* 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 */ 
    108188        {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9, 
    109189         OPT_DLG_H, N_("Save file &position"), 0, 0, 0, 0, NULL}, 
    110         /* 8 */ 
     190        /* 7 */ 
    111191        {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10, 
    112192         OPT_DLG_H, N_("Confir&m before saving"), 6, 0, 0, 0, NULL}, 
    113         /* 9 */ 
     193        /* 8 */ 
    114194        {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11, 
    115195         OPT_DLG_H, N_("Fill tabs with &spaces"), 0, 0, 0, 0, NULL}, 
    116         /* 10 */ 
     196        /* 9 */ 
    117197        {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12, 
    118198         OPT_DLG_H, N_("&Return does autoindent"), 0, 0, 0, 0, NULL}, 
    119         /* 11 */ 
     199        /* 10 */ 
    120200        {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 13, 
    121201         OPT_DLG_H, N_("&Backspace through tabs"), 0, 0, 0, 0, NULL}, 
    122         /* 12 */ 
     202        /* 11 */ 
    123203        {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 14, 
    124204         OPT_DLG_H, N_("&Fake half tabs"), 0, 0, 0, 0, NULL}, 
    125         /* 13 */ 
     205        /* 12 */ 
    126206        {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, "", 3, 0, 0, 
    127207         const_cast(char **, wrap_str), "wrapm"}, 
    128         /* 14 */ 
     208        /* 13 */ 
    129209        {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 8, OPT_DLG_H, 
    130210         N_("Wrap mode"), 0, 0, 
    131211         0, 0, NULL}, 
    132         /* 15 */ 
     212        /* 14 */ 
    133213        {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 13, OPT_DLG_H, "", 3, 0, 0, 
    134214         const_cast(char **, key_emu_str), "keyemu"}, 
    135         /* 16 */ 
     215        /* 15 */ 
    136216        {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 14, OPT_DLG_H, 
    137217         N_("Key emulation"), 0, 0, 0, 0, NULL}, 
    138218        NULL_QuickWidget 
    edit_options_dialog (void) 
    156236    quick_widgets[3].str_result = &p; 
    157237    quick_widgets[5].text = tab_spacing; 
    158238    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; 
    166245 
    167246    if (option_auto_para_formatting) 
    168247        wrap_mode = 1; 
    edit_options_dialog (void) 
    171250    else 
    172251        wrap_mode = 0; 
    173252 
    174     quick_widgets[13].result = &wrap_mode; 
    175     quick_widgets[13].value = wrap_mode; 
     253    quick_widgets[12].result = &wrap_mode; 
     254    quick_widgets[12].value = wrap_mode; 
    176255 
    177     quick_widgets[15].result = &tedit_key_emulation; 
    178     quick_widgets[15].value = tedit_key_emulation; 
     256    quick_widgets[14].result = &tedit_key_emulation; 
     257    quick_widgets[14].value = tedit_key_emulation; 
    179258 
    180259    Quick_options.widgets = quick_widgets; 
    181260 
    182261    if (quick_dialog (&Quick_options) == B_CANCEL) 
    183262        return; 
    184263 
    185     old_syntax_hl = option_syntax_highlighting; 
    186  
    187264    if (p) { 
    188265        option_word_wrap_line_length = atoi (p); 
    189266        g_free (p); 
    edit_options_dialog (void) 
    195272        g_free (q); 
    196273    } 
    197274 
    198     option_syntax_highlighting = tedit_syntax_highlighting; 
    199275    edit_confirm_save = tedit_confirm_save; 
    200276    option_save_position = toption_save_position; 
    201277    option_fill_tabs_with_spaces = toption_fill_tabs_with_spaces; 
    edit_options_dialog (void) 
    220296        edit_reload_menu (); 
    221297    } 
    222298 
    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); 
    226299    /* Load usermap if it's needed */ 
    227300    edit_load_user_map (wedit); 
    228301} 
     302#undef DLG_OPT_W 
     303#undef DLG_OPT_H 
  • src/setup.c

    old new static const struct { 
    216216    { "editor_option_typewriter_wrap", &option_typewriter_wrap }, 
    217217    { "editor_edit_confirm_save", &edit_confirm_save }, 
    218218    { "editor_syntax_highlighting", &option_syntax_highlighting }, 
     219    { "editor_highlight", &option_highlighting }, 
    219220#endif /* USE_INTERNAL_EDIT */ 
    220221 
    221222    { "nice_rotating_dash", &nice_rotating_dash },