Ticket #1819: 1819-While__pressingPrtScr-comment__pressingDelete-uncomm.patch

File 1819-While__pressingPrtScr-comment__pressingDelete-uncomm.patch, 7.1 KB (added by vit_r, 14 years ago)
  • edit/edit.c

    From 67d4f002a9575b1d1a45a18062720167d1edd412 Mon Sep 17 00:00:00 2001
    From: Vit Rosin <vit_r@list.ru>
    Date: Thu, 12 Nov 2009 22:51:48 +0000
    Subject: [PATCH] While__pressingPrtScr-comment__pressingDelete-uncomment
    
    ---
     edit/edit.c     |  135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
     edit/edit.h     |   12 ++++-
     edit/editkeys.c |    7 +++
     src/cmddef.h    |   16 ++++---
     4 files changed, 161 insertions(+), 9 deletions(-)
    
    diff --git a/edit/edit.c b/edit/edit.c
    index 9a51b79..70ab398 100644
    a b edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) 
    27322732                break; 
    27332733            } 
    27342734        } 
    2735         edit_delete (edit, 0); 
     2735        case_CK_Delete (edit); 
    27362736        break; 
    27372737    case CK_Delete_Word_Left: 
    27382738        edit->over_col = 0; 
    edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) 
    31773177    case CK_Ext_Mode: 
    31783178        edit->extmod = 1; 
    31793179        break; 
     3180    case CK_PrtScr: 
     3181        case_CK_PrtScr (edit); 
     3182        break; 
    31803183    default: 
    31813184        break; 
    31823185    } 
    edit_stack_free (void) 
    33363339            edit_stack_iterator++) 
    33373340        g_free (edit_history_moveto[edit_stack_iterator].filename); 
    33383341} 
     3342 
     3343void edit_show_bottom (WEdit * edit) 
     3344{ 
     3345    edit_cursor_to_bol (edit); 
     3346    if (edit->curs_line >= (edit->total_lines - 1)) { 
     3347        edit->force |= REDRAW_PAGE; 
     3348        return; 
     3349    } 
     3350    edit_move_down (edit, 1, 0); 
     3351    edit_cursor_to_bol (edit); 
     3352    edit->force |= REDRAW_PAGE; 
     3353    if (edit->curs_line > (edit->start_line + edit->num_widget_lines - 3)) { 
     3354        edit_update_screen (edit); 
     3355        edit_move_display (edit, edit->start_line + 1); 
     3356        edit->force |= REDRAW_PAGE; 
     3357    } 
     3358} 
     3359 
     3360int it_is_ELF (WEdit * edit) 
     3361{ 
     3362    if ('E' == edit_get_byte (edit, 1)) { 
     3363        if ('L' == edit_get_byte (edit, 2)) { 
     3364            if ('F' == edit_get_byte (edit, 3)) { 
     3365                return 1; 
     3366            } 
     3367        } 
     3368    } 
     3369    return 0; 
     3370} 
     3371 
     3372/* for "*.[s,S]" filenames */ 
     3373int it_is_ASM (WEdit * edit) 
     3374{ 
     3375    int fn_len = (int) strlen ((char *) edit->filename); 
     3376    if (fn_len > 2 && '.' == edit->filename[fn_len - 2]) { 
     3377        if ('s' == edit->filename[fn_len - 1] 
     3378                || 'S' == edit->filename[fn_len - 1]) { 
     3379            edit_cursor_to_bol (edit); 
     3380            return 1; 
     3381        } 
     3382    } 
     3383    return 0; 
     3384} 
     3385 
     3386/* for "*.[h,H,c,C]" | "*.[c,C]??" filenames */ 
     3387int it_is_C (WEdit * edit) 
     3388{ 
     3389    int fn_len = (int) strlen ((char *) edit->filename); 
     3390 
     3391    if (fn_len < 3)  
     3392        return 0; 
     3393 
     3394    if ('.' == edit->filename[fn_len - 2]) { 
     3395        if ('h' == edit->filename[fn_len - 1] 
     3396                || 'H' == edit->filename[fn_len - 1] 
     3397                || 'c' == edit->filename[fn_len - 1] 
     3398                || 'C' == edit->filename[fn_len - 1]) { 
     3399            edit_cursor_to_bol (edit); 
     3400            return 1; 
     3401        } 
     3402    } 
     3403 
     3404    if ((fn_len = (fn_len - 2)) < 3) 
     3405        return 0; 
     3406 
     3407    if ('.' == edit->filename[fn_len - 2]) { 
     3408        if ('h' == edit->filename[fn_len - 1] 
     3409                || 'H' == edit->filename[fn_len - 1] 
     3410                || 'c' == edit->filename[fn_len - 1] 
     3411                || 'C' == edit->filename[fn_len - 1]) { 
     3412            edit_cursor_to_bol (edit); 
     3413            return 1; 
     3414        } 
     3415    } 
     3416    return 0; 
     3417} 
     3418 
     3419void case_CK_Delete (WEdit * edit) 
     3420{ 
     3421    int c1; 
     3422 
     3423    if (edit->curs_col) { 
     3424        edit_delete (edit, 0); 
     3425        return; 
     3426    } 
     3427    c1 = edit_get_byte (edit, edit->curs1); 
     3428    edit_delete (edit, 0); 
     3429 
     3430    if ('/' == c1) { 
     3431        if (it_is_C (edit)) { 
     3432            if ('/' == edit_get_byte (edit, edit->curs1))  
     3433                edit_delete (edit, 1); 
     3434            else 
     3435                return; 
     3436        } 
     3437    } else if (!( '#' == c1 || ';' == c1 )) { 
     3438        return; 
     3439    } 
     3440    edit_show_bottom (edit); 
     3441} 
     3442 
     3443void case_CK_PrtScr (WEdit * edit) 
     3444{ 
     3445    if (edit->curs_line >= edit->total_lines) { 
     3446        return; 
     3447    } else if (it_is_ELF (edit)) { 
     3448        return; 
     3449    } else if (it_is_ASM (edit)) { /* for "*.[s,S]" filenames */ 
     3450        if ((edit->total_lines - 1) == edit->curs_line) { 
     3451            if (';' == edit_get_byte (edit, edit->curs1)) 
     3452                return; 
     3453        } 
     3454        edit_insert (edit, ';'); 
     3455    } else if (it_is_C (edit)) { /* for "*.[h,H,c,C]" | "*.[c,C]??" filenames */ 
     3456        if ((edit->total_lines - 1) == edit->curs_line) { 
     3457            if ('/' == edit_get_byte (edit, edit->curs1)) 
     3458                return; 
     3459        } 
     3460        edit_insert (edit, '/'); 
     3461        edit_insert (edit, '/'); 
     3462    } else { 
     3463        edit_cursor_to_bol (edit); 
     3464        if ((edit->total_lines - 1) == edit->curs_line) { 
     3465            if ('#' == edit_get_byte (edit, edit->curs1)) 
     3466                return; 
     3467        } 
     3468        edit_insert (edit, '#'); 
     3469    } 
     3470    edit_show_bottom (edit); 
     3471} 
  • edit/edit.h

    diff --git a/edit/edit.h b/edit/edit.h
    index 0891801..31b2180 100644
    a b extern int option_syntax_highlighting; 
    5555extern char *option_backup_ext; 
    5656 
    5757extern int edit_confirm_save; 
    58  
    5958extern int visible_tabs; 
    6059extern int visible_tws; 
    61  
    6260extern int simple_statusbar; 
    6361extern int option_check_nl_at_eof; 
    6462 
    const char *edit_get_file_name (const WEdit *edit); 
    7270int edit_get_curs_col (const WEdit *edit); 
    7371const char *edit_get_syntax_type (const WEdit *edit); 
    7472 
     73/* While pressing: 
     74      PrtScr comments lines 
     75      Delete uncomments lines */ 
     76int it_is_ELF (WEdit * edit); 
     77int it_is_ASM (WEdit * edit); 
     78int it_is_C (WEdit * edit); 
     79void edit_show_bottom (WEdit * edit); 
     80void case_CK_PrtScr (WEdit * edit); 
     81void case_CK_Delete (WEdit * edit); 
     82 
    7583#endif                          /* MC_EDIT_H */ 
  • edit/editkeys.c

    diff --git a/edit/editkeys.c b/edit/editkeys.c
    index 6804e17..68103d6 100644
    a b edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch) 
    160160            } 
    161161        } 
    162162    } 
     163 
    163164  fin: 
    164165    *cmd = command; 
    165166    *ch = char_for_insertion; 
    166167 
     168    if (16412 == x_key) { 
     169        *ch = -1; 
     170        *cmd = CK_PrtScr; 
     171        return 1; 
     172    } 
     173 
    167174    return (command == CK_Insert_Char && char_for_insertion == -1) ? 0 : 1; 
    168175} 
  • src/cmddef.h

    diff --git a/src/cmddef.h b/src/cmddef.h
    index 2644130..fef6d8b 100644
    a b  
    364364#define CK_PanelSortOrderBySize         8038 
    365365#define CK_PanelSortOrderByMTime        8039 
    366366 
     367/* While pressing: 
     368      PrtScr comments lines 
     369      Delete uncomments lines */ 
     370#define CK_PrtScr                      16412 
     371 
    367372/* 
    368373   Process a block through a shell command: CK_Pipe_Block(i) executes shell_cmd[i]. 
    369374   shell_cmd[i] must process the file ~/cooledit.block and output ~/cooledit.block 
     
    377382#define SHELL_COMMANDS_i {"/edit.indent.rc", "/edit.spell.rc", /* and so on */ 0 } 
    378383#define CK_Macro(i)             (2000+(i)) 
    379384#define CK_Last_Macro           CK_Macro(0x7FFF) 
    380 #else 
    381  
    382 #define CK_User_Command(i)      ((i) | (1 << 16)) 
    383 #define IS_USER_COMMAND(i)      ((i) & (1 << 16)) 
    384 #define CK_Macro(i)             ((i) | (1 << 17)) 
    385 #define IS_MACRO_COMMAND(i)     ((i) & (1 << 17)) 
    386385 
     386#else 
     387    #define CK_User_Command(i)  ((i) | (1 << 16)) 
     388    #define IS_USER_COMMAND(i)  ((i) & (1 << 16)) 
     389    #define CK_Macro(i)         ((i) | (1 << 17)) 
     390    #define IS_MACRO_COMMAND(i) ((i) & (1 << 17)) 
    387391#endif                                  /* MC_CMD_DEF_H */