Ticket #1832: 1832-F2_MultiComment__Del-Uncomm__C-s_Save__M-y_TSyntax.patch

File 1832-F2_MultiComment__Del-Uncomm__C-s_Save__M-y_TSyntax.patch, 9.4 KB (added by vit_r, 14 years ago)
  • edit/edit.c

    From ba30d9da31e1d69fcb4b13ec47364a330f728dcf Mon Sep 17 00:00:00 2001
    From: Vit Rosin <vit_r@list.ru>
    Date: Tue, 17 Nov 2009 05:04:43 +0000
    Subject: [PATCH]  F2_MultiComment__Del-Uncomm__C-s_Save__M-y_TSyntax
    
    ---
     edit/edit.c            |  135 +++++++++++++++++++++++++++++++++++++++++++++++-
     edit/edit.h            |    7 +++
     misc/mc.keymap.default |    5 +-
     misc/mc.keymap.emacs   |    5 +-
     src/cmddef.h           |   13 +++--
     src/keybind.c          |    6 ++-
     6 files changed, 160 insertions(+), 11 deletions(-)
    
    diff --git a/edit/edit.c b/edit/edit.c
    index 9a51b79..6a4c947 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_MultiComment: 
     3181        case_CK_MultiComment (edit); 
     3182        return; 
    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_MultiComment (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..01fa4e0 100644
    a b const char *edit_get_file_name (const WEdit *edit); 
    7272int edit_get_curs_col (const WEdit *edit); 
    7373const char *edit_get_syntax_type (const WEdit *edit); 
    7474 
     75int it_is_C (WEdit * edit); 
     76int it_is_ELF (WEdit * edit); 
     77int it_is_ASM (WEdit * edit); 
     78void case_CK_Delete (WEdit * edit); 
     79void edit_show_bottom (WEdit * edit); 
     80void case_CK_MultiComment (WEdit * edit); 
     81 
    7582#endif                          /* MC_EDIT_H */ 
  • misc/mc.keymap.default

    diff --git a/misc/mc.keymap.default b/misc/mc.keymap.default
    index f571d0d..d7885cd 100644
    a b EditDeleteWordLeft = alt-backspace 
    3333EditDeleteWordRight = alt-d 
    3434EditParagraphUp = 
    3535EditParagraphDown = 
    36 EditSave = f2 
    3736EditLoad = 
    3837EditNew = ctrl-n 
     38EditSave = ctrl-s 
    3939EditSaveas = f12 
    4040EditMark = f3 
    4141EditCopy = f5 
    EditDeleteMacro = 
    149149 
    150150EditToggleLineState = alt-n 
    151151EditToggleTabTWS = alt-underline 
    152 EditToggleSyntax = ctrl-s 
     152EditToggleSyntax = alt-y 
    153153 
    154154EditFindDefinition = alt-enter 
    155155EditLoadPrevFile = alt-minus 
    156156EditLoadNextFile = alt-plus 
     157EditMultiComment = f2 
    157158 
    158159SelectCodepage = alt-e 
    159160 
  • misc/mc.keymap.emacs

    diff --git a/misc/mc.keymap.emacs b/misc/mc.keymap.emacs
    index 1acb5cd..6c1ac38 100644
    a b EditDeleteWordLeft = alt-backspace 
    3333EditDeleteWordRight = alt-d 
    3434EditParagraphUp = 
    3535EditParagraphDown = 
    36 EditSave = f2 
    3736EditLoad = 
     37EditSave = ctrl-s 
    3838EditSaveas = f12 
    3939EditMark = f3 
    4040EditCopy = f5 
    EditDeleteMacro = 
    147147 
    148148EditToggleLineState = alt-n 
    149149EditToggleTabTWS = alt-underline 
    150 EditToggleSyntax = ctrl-s 
     150EditToggleSyntax = alt-y 
    151151 
    152152EditFindDefinition = alt-enter 
    153153EditLoadPrevFile = alt-minus 
    154154EditLoadNextFile = alt-plus 
     155EditMultiComment = f2 
    155156 
    156157SelectCodepage = alt-e 
    157158 
  • src/cmddef.h

    diff --git a/src/cmddef.h b/src/cmddef.h
    index 2644130..55ef6a9 100644
    a b  
    109109#define CK_ExtCmd               424 
    110110#define CK_User_Menu            425 
    111111#define CK_Find_Definition      426 
    112 #define CK_Edit_Options     427 
    113 #define CK_Edit_Save_Mode   428 
    114 #define CK_Choose_Syntax    429 
    115 #define CK_About            430 
     112#define CK_Edit_Options         427 
     113#define CK_Edit_Save_Mode       428 
     114#define CK_Choose_Syntax        429 
     115#define CK_About                430 
     116 
     117/* to comment lines: F2 (while pressing) 
     118   to uncomment first Home (if needed) 
     119   then Delete (while pressing) */ 
     120#define CK_MultiComment         431 
    116121 
    117122#if 0 
    118123/* application control */ 
  • src/keybind.c

    diff --git a/src/keybind.c b/src/keybind.c
    index c898e8c..7d2df7f 100644
    a b static const name_keymap_t command_names[] = { 
    192192    { "EditOptions",                       CK_Edit_Options }, 
    193193    { "EditSaveMode",                      CK_Edit_Save_Mode }, 
    194194    { "EditChooseSyntax",                  CK_Choose_Syntax }, 
     195    { "EditMultiComment",                  CK_MultiComment }, 
    195196    { "EditAbout",                         CK_About }, 
    196197 
    197198#if 0 
    const global_keymap_t default_editor_keymap[] = { 
    518519    { ALT ('i'),                            CK_Prev_Bookmark,       "M-i" }, 
    519520    { ALT ('j'),                            CK_Next_Bookmark,       "M-j" }, 
    520521    { ALT ('o'),                            CK_Flush_Bookmarks,     "M-o" }, 
     522    { ALT ('y'),                            CK_Toggle_Syntax,       "M-y" }, 
    521523 
    522524    { XCTRL ('n'),                          CK_New,                 "C-n" }, 
    523525    { XCTRL ('k'),                          CK_Delete_To_Line_End,  "C-k" }, 
    524526    { XCTRL ('l'),                          CK_Refresh,             "C-l" }, 
    525527    { XCTRL ('o'),                          CK_Shell,               "C-o" }, 
    526     { XCTRL ('s'),                          CK_Toggle_Syntax,       "C-s" }, 
     528    { XCTRL ('s'),                          CK_Save,                "C-s" }, 
    527529    { XCTRL ('u'),                          CK_Undo,                "C-u" }, 
    528530    { ALT ('e'),                            CK_SelectCodepage,      "M-e" }, 
    529531    { XCTRL ('q'),                          CK_Insert_Literal,      "C-q" }, 
    const global_keymap_t default_editor_keymap[] = { 
    533535    { XCTRL ('a'),                          CK_Execute_Macro,       "C-a" }, 
    534536 
    535537    { KEY_F (1),                            CK_Help,                "F1" }, 
    536     { KEY_F (2),                            CK_Save,                "F2" }, 
     538    { KEY_F (2),                            CK_MultiComment,        "F2" }, 
    537539    { KEY_F (3),                            CK_Mark,                "F3" }, 
    538540    { KEY_F (4),                            CK_Replace,             "F4" }, 
    539541    { KEY_F (5),                            CK_Copy,                "F5" },