Ticket #2421: mc_ho.patch

File mc_ho.patch, 6.3 KB (added by myehorov, 13 years ago)

patch

  • src/cmddef.h

    diff -Naur mc-4.7.0.10/src/cmddef.h mc-4.7.0.10_ho/src/cmddef.h
    old new  
    117117#define CK_Edit_Save_Mode   428 
    118118#define CK_Choose_Syntax    429 
    119119#define CK_About            430 
     120#define CK_Highlight_Occurences     431 
     121#define CK_Unhighlight_Occurences   432 
    120122 
    121123#if 0 
    122124/* application control */ 
  • src/editor/edit.c

    diff -Naur mc-4.7.0.10/src/editor/edit.c mc-4.7.0.10_ho/src/editor/edit.c
    old new  
    969969 
    970970    edit_set_keymap (); 
    971971 
     972    edit->hword_symbols_left = 0; 
     973    memset(edit->highlight_word, 0, HW_LEN * sizeof(char)); 
     974    edit->highlight_word_length = 0; 
     975 
    972976    return edit; 
    973977} 
    974978 
     
    30433047 
    30443048    switch (command) 
    30453049    { 
     3050    case CK_Highlight_Occurences: 
     3051        exec_highlight_occurences(edit); 
     3052        break; 
     3053 
     3054    case CK_Unhighlight_Occurences: 
     3055        exec_unhighlight_occurences(edit); 
     3056        break; 
    30463057    case CK_Begin_Page: 
    30473058    case CK_End_Page: 
    30483059    case CK_Begin_Page_Highlight: 
  • src/editor/edit.h

    diff -Naur mc-4.7.0.10/src/editor/edit.h mc-4.7.0.10_ho/src/editor/edit.h
    old new  
    6363 
    6464extern int simple_statusbar; 
    6565extern int option_check_nl_at_eof; 
     66extern int option_highlight_occurences; 
    6667 
    6768/* used in main() */ 
    6869void edit_stack_init (void); 
     
    7475int edit_get_curs_col (const WEdit *edit); 
    7576const char *edit_get_syntax_type (const WEdit *edit); 
    7677 
     78extern int need_highlighing(WEdit* edit, long byte_index); 
     79extern void exec_highlight_occurences(WEdit *edit); 
     80extern void exec_unhighlight_occurences(WEdit *edit); 
     81 
    7782#endif                          /* MC_EDIT_H */ 
  • src/editor/editmenu.c

    diff -Naur mc-4.7.0.10/src/editor/editmenu.c mc-4.7.0.10_ho/src/editor/editmenu.c
    old new  
    116116    entries = g_list_append (entries, menu_entry_create (_("&Next bookmark"),       CK_Next_Bookmark)); 
    117117    entries = g_list_append (entries, menu_entry_create (_("&Prev bookmark"),       CK_Prev_Bookmark)); 
    118118    entries = g_list_append (entries, menu_entry_create (_("&Flush bookmark"),      CK_Flush_Bookmarks)); 
     119    entries = g_list_append (entries, menu_entry_create (_("Highlight occurences"),   CK_Highlight_Occurences)); 
     120    entries = g_list_append (entries, menu_entry_create (_("Unhighlight occurences"), CK_Unhighlight_Occurences)); 
    119121 
    120122    return entries; 
    121123} 
  • src/editor/edit-widget.h

    diff -Naur mc-4.7.0.10/src/editor/edit-widget.h mc-4.7.0.10_ho/src/editor/edit-widget.h
    old new  
    1414 
    1515#define MAX_MACRO_LENGTH 1024 
    1616#define N_LINE_CACHES 32 
     17/* HW_LEN max length of word to highlight */ 
     18#define HW_LEN      512 
    1719 
    1820struct _book_mark { 
    1921    int line;                   /* line number */ 
     
    127129 
    128130    char *labels[10]; 
    129131 
     132    int hword_symbols_left; 
     133 
     134    char highlight_word[HW_LEN]; 
     135    int  highlight_word_length; 
    130136}; 
    131137 
    132138#endif                          /* MC_EDIT_WIDGET_H */ 
  • src/editor/syntax.c

    diff -Naur mc-4.7.0.10/src/editor/syntax.c mc-4.7.0.10_ho/src/editor/syntax.c
    old new  
    5656 
    5757#include "edit-impl.h" 
    5858#include "edit-widget.h" 
     59//#include "../src/myslang.h" 
    5960 
    6061/* bytes */ 
    6162#define SYNTAX_MARKER_DENSITY 512 
     
    7576#define SYNTAX_TOKEN_BRACKET    '\003' 
    7677#define SYNTAX_TOKEN_BRACE      '\004' 
    7778 
     79/** 
     80    Section related to highlighting of occurences 
     81 */ 
     82 
     83#define HIGHLIGHT_DLG_WIDTH 58 
     84#define HIGHLIGHT_DLG_HEIGHT 8 
     85#define B_REPLACE_ALL (B_USER+1) 
     86#define B_REPLACE_ONE (B_USER+2) 
     87#define B_SKIP_REPLACE (B_USER+3) 
     88 
     89int option_highlight_occurences = 0; 
     90 
     91int need_highlighing(WEdit* edit, long byte_index) 
     92{ 
     93    int ret = 0; 
     94    int i = 0; 
     95    char token[edit->highlight_word_length+1]; 
     96 
     97    token[edit->highlight_word_length] = 0; 
     98    for ( ; i < edit->highlight_word_length; i++) 
     99        token[i] = edit_get_byte(edit, byte_index++); 
     100 
     101    ret = !strncmp(token, edit->highlight_word, edit->highlight_word_length); 
     102 
     103    if ( ret ) 
     104        ret = edit->highlight_word_length; 
     105 
     106    return ret; 
     107} 
     108 
     109void exec_highlight_occurences(WEdit *edit) 
     110{ 
     111    char *text = input_expand_dialog (_("Highlight occurences"), _(" Text:"), "", ""); 
     112 
     113    if ( text ) 
     114    { 
     115        option_highlight_occurences = 1; 
     116        edit->highlight_word_length = strlen(text); 
     117        strcpy(edit->highlight_word, text); // TODO: Check for Unicode 
     118        g_free(text); 
     119        edit_refresh_cmd(edit); 
     120    } 
     121} 
     122 
     123void exec_unhighlight_occurences(WEdit *edit) 
     124{ 
     125    option_highlight_occurences = 0; 
     126    edit->highlight_word_length = 0; 
     127    memset(edit->highlight_word, 0, HW_LEN); 
     128    edit_refresh_cmd(edit); 
     129} 
     130 
     131/*---------------------*/ 
     132 
    78133struct key_word { 
    79134    char *keyword; 
    80135    unsigned char first; 
     
    494549void 
    495550edit_get_syntax_color (WEdit * edit, long byte_index, int *color) 
    496551{ 
     552 
    497553    if (!tty_use_colors ()) 
    498         *color = 0; 
    499     else if (edit->rules && byte_index < edit->last_byte && 
    500                  option_syntax_highlighting) 
    501         translate_rule_to_color (edit, edit_get_rule (edit, byte_index), color); 
     554        *color = 0; 
    502555    else 
    503         *color = EDITOR_NORMAL_COLOR; 
     556    { 
     557        if (edit->rules && byte_index < edit->last_byte && option_syntax_highlighting) 
     558            translate_rule_to_color (edit, edit_get_rule (edit, byte_index), color); 
     559        else 
     560            *color = EDITOR_NORMAL_COLOR; 
     561 
     562        if ( option_highlight_occurences ) 
     563        { 
     564            if ( edit->hword_symbols_left ) 
     565            { 
     566                --edit->hword_symbols_left; 
     567                *color = SELECTED_COLOR; 
     568                return; 
     569            } 
     570            else if (( edit->hword_symbols_left = need_highlighing(edit, byte_index) )) 
     571            { 
     572                --edit->hword_symbols_left; 
     573                *color = SELECTED_COLOR; 
     574                return; 
     575            } 
     576        } 
     577    } 
    504578} 
    505579 
    506580 
     
    12531327{ 
    12541328    return edit->syntax_type; 
    12551329} 
     1330 
     1331 
     1332 
     1333