Ticket #1847: 1847-multiline-vertical-move.patch

File 1847-multiline-vertical-move.patch, 10.7 KB (added by vit_r, 9 years ago)

F6 usual behaviour is _NOT_ changed - F6 marks unmarked line and moves it down - Ctrl-F6 marks unmarked line and moves it up If there are marked area and cursor is between start and end marks (start_mark <= cursor && cursor <= end_mark) F6 press till now had no effect. Lets try this design: - F6 marks all touched lines and moves them down - Ctrl-F6 up Lines with at least one marked CHAR are affected too ('\n' == new line is CHAR also) ps just to remind: F3 pressed twice - unmarks

  • edit/edit-impl.h

    From e62ff17b07c57d07798ccd82dbe3a1dbbe9f2e7d Mon Sep 17 00:00:00 2001
    From: Vit Rosin <vit_r@list.ru>
    Date: Fri, 27 Nov 2009 14:56:59 +0000
    Subject: [PATCH] multiline vertical move
    
    ---
     edit/edit-impl.h       |    8 ++
     edit/edit.c            |  207 +++++++++++++++++++++++++++++++++++++++++++++++-
     misc/mc.keymap.default |    1 +
     misc/mc.keymap.emacs   |    1 +
     src/cmddef.h           |    1 +
     src/keybind.c          |    2 +
     6 files changed, 218 insertions(+), 2 deletions(-)
    
    diff --git a/edit/edit-impl.h b/edit/edit-impl.h
    index 6efb373..f0359f4 100644
    a b void edit_syntax_dialog (void); 
    277277void edit_mail_dialog (WEdit *edit); 
    278278void format_paragraph (WEdit *edit, int force); 
    279279 
     280/* mlvm - multiline vertical move */ 
     281void mlvm_get_block_marks (WEdit * edit, long *start_mark, long *end_mark); 
     282int mlvm_proceed_unmarked_line (WEdit * edit, const int command); 
     283int mlvm_move_marked_block_up (WEdit * edit, const long start_mark, const long end_mark); 
     284int mlvm_move_marked_block_down (WEdit * edit, const long start_mark, const long end_mark); 
     285int mlvm_block_up_move (WEdit * edit, const int command); 
     286int mlvm_block_down_move (WEdit * edit, const int command); 
     287 
    280288/* either command or char_for_insertion must be passed as -1 */ 
    281289void edit_execute_cmd (WEdit *edit, int command, int char_for_insertion); 
    282290 
  • edit/edit.c

    diff --git a/edit/edit.c b/edit/edit.c
    index 0b0b1eb..dea0ba0 100644
    a b const char VERTICAL_MAGIC[] = {'\1', '\1', '\1', '\1', '\n'}; 
    121121const global_keymap_t *editor_map; 
    122122const global_keymap_t *editor_x_map; 
    123123 
     124static long marked_topline;           /* upper highlighted line */ 
     125static long marked_lowline;           /* lower highlighted line */ 
     126 
    124127static void user_menu (WEdit *edit); 
    125128 
    126129int edit_get_byte (WEdit * edit, long byte_index) 
    edit_execute_key_command (WEdit *edit, unsigned long command, int char_for_inser 
    25532556    if (command != CK_Undo && command != CK_Ext_Mode) 
    25542557        edit_push_key_press (edit); 
    25552558 
     2559    if (marked_topline >= 0 || marked_lowline >= 0) { 
     2560        if (! (command == CK_Move_Up || command == CK_Move) ) { 
     2561            marked_topline = -1; 
     2562            marked_lowline = -1; 
     2563        } 
     2564    } 
    25562565    edit_execute_cmd (edit, command, char_for_insertion); 
    25572566    if (column_highlighting) 
    25582567        edit->force |= REDRAW_PAGE; 
    edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) 
    25862595        edit->highlight = 1; 
    25872596    } else {                    /* any other command */ 
    25882597        if (edit->highlight) 
    2589             edit_mark_cmd (edit, 0);    /* clear */ 
     2598            edit_mark_cmd (edit, 0);    /* marking on */ 
    25902599        edit->highlight = 0; 
    25912600    } 
    25922601 
    edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) 
    29973006    case CK_Remove: 
    29983007        edit_block_delete_cmd (edit); 
    29993008        break; 
     3009    case CK_Move_Up: 
     3010        if (mlvm_block_up_move (edit, command)) 
     3011            break; 
     3012        if ( option_cursor_beyond_eol && edit->over_col > 0 ) 
     3013            edit_insert_over (edit); 
     3014        edit_block_move_cmd (edit); 
     3015        break; 
    30003016    case CK_Move: 
     3017        if (mlvm_block_down_move (edit, command)) 
     3018            break; 
    30013019        if ( option_cursor_beyond_eol && edit->over_col > 0 ) 
    30023020            edit_insert_over (edit); 
    30033021        edit_block_move_cmd (edit); 
    30043022        break; 
    3005  
    30063023    case CK_Shift_Block_Left: 
    30073024        if (edit->mark1 != edit->mark2) 
    30083025            edit_move_block_to_left (edit); 
    edit_stack_free (void) 
    33413358            edit_stack_iterator++) 
    33423359        g_free (edit_history_moveto[edit_stack_iterator].filename); 
    33433360} 
     3361 
     3362void mlvm_get_block_marks (WEdit * edit, long *start_mark, long *end_mark) 
     3363{ 
     3364    edit_cursor_move (edit, (*end_mark - 1) - edit->curs1); 
     3365    edit_cursor_to_eol (edit); 
     3366    *end_mark = edit->curs1 + 1; 
     3367    marked_lowline = edit->curs_line; 
     3368    edit_cursor_move (edit, *start_mark - edit->curs1); 
     3369    marked_topline = edit->curs_line; 
     3370    edit_cursor_to_bol (edit); 
     3371    *start_mark = edit->curs1; 
     3372} 
     3373 
     3374int mlvm_proceed_unmarked_line (WEdit * edit, const int command) /* F6  |  C-F6 */ 
     3375{ 
     3376    long start_mark, end_mark; 
     3377 
     3378    if (edit->total_lines < 2) 
     3379        return 0; 
     3380 
     3381    edit_cursor_to_bol (edit); 
     3382 
     3383    if (edit->curs1 < edit->last_byte) { 
     3384        start_mark = edit->curs1; 
     3385        edit_cursor_move (edit, 1); 
     3386        end_mark = edit->curs1; 
     3387    } else { 
     3388        end_mark = edit->curs1; 
     3389        edit_cursor_move (edit, -1); 
     3390        start_mark = edit->curs1; 
     3391    } 
     3392 
     3393    mlvm_get_block_marks (edit, &start_mark, &end_mark); 
     3394 
     3395    if (command == CK_Move) { 
     3396        if (mlvm_move_marked_block_down (edit, start_mark, end_mark)) 
     3397            return 1; 
     3398        else 
     3399            marked_lowline = -1; 
     3400 
     3401    } else if (command == CK_Move_Up) { 
     3402        if (mlvm_move_marked_block_up (edit, start_mark, end_mark)) 
     3403            return 1; 
     3404        else 
     3405            marked_topline = -1; 
     3406    } 
     3407 
     3408    return 0; 
     3409} 
     3410 
     3411int mlvm_move_marked_block_up (WEdit * edit, const long start_mark, const long end_mark) 
     3412{ 
     3413    long p, upline_min, upline_max; 
     3414 
     3415    if (edit->total_lines < 2) 
     3416        return 0; 
     3417 
     3418    if (marked_topline < 1) 
     3419        return 0; 
     3420 
     3421    edit_cursor_move (edit, start_mark - edit->curs1); 
     3422 
     3423    if (!edit->curs_line) 
     3424        return 0; 
     3425 
     3426    upline_max = start_mark - 1; 
     3427    edit_cursor_to_bol (edit); 
     3428    edit_move_up (edit, 1, 0); 
     3429    marked_topline = edit->curs_line; 
     3430    upline_min = edit->curs1; 
     3431    edit_cursor_move (edit, (end_mark - 1) - edit->curs1); 
     3432 
     3433    for (p = (upline_min - 1); p < (start_mark - 1); p++) 
     3434        edit_insert (edit, edit_get_byte (edit, p)); 
     3435 
     3436    edit_cursor_move (edit, upline_min - upline_max); 
     3437    marked_lowline = edit->curs_line - 1; 
     3438    edit_mark_cmd (edit, 1);    /* clear */ 
     3439    edit_mark_cmd (edit, 0);    /* mark1 */ 
     3440    edit_cursor_move (edit, upline_min - edit->curs1); 
     3441    edit_delete_line (edit); 
     3442    edit_mark_cmd (edit, 0);    /* mark2 */ 
     3443    edit_move_to_line (edit, marked_topline); 
     3444    edit_cursor_to_bol (edit); 
     3445 
     3446    if (edit->curs_line < (edit->start_line + 2)) 
     3447        edit_move_display (edit, edit->curs_line - 2); 
     3448 
     3449    return 1; 
     3450} 
     3451 
     3452int mlvm_block_up_move (WEdit * edit, const int command) 
     3453{ 
     3454    long start_mark, end_mark; 
     3455 
     3456    if (column_highlighting) 
     3457        return 0; 
     3458 
     3459    marked_lowline = -1; 
     3460 
     3461    if (eval_marks (edit, &start_mark, &end_mark)) { 
     3462        if (mlvm_proceed_unmarked_line (edit, command)) 
     3463            return 1; 
     3464    } else if (start_mark <= edit->curs1 && edit->curs1 <= end_mark) { 
     3465        if (marked_topline < 0) 
     3466            mlvm_get_block_marks (edit, &start_mark, &end_mark); 
     3467 
     3468        if (mlvm_move_marked_block_up (edit, start_mark, end_mark)) 
     3469            return 1; 
     3470    } else { 
     3471        marked_topline = -1; 
     3472    } 
     3473 
     3474    return 0; 
     3475} 
     3476 
     3477int mlvm_move_marked_block_down (WEdit * edit, const long start_mark, const long end_mark) 
     3478{ 
     3479    long p, n, lowline_min, lowline_max; 
     3480 
     3481    if (edit->total_lines < 2) 
     3482        return 0; 
     3483 
     3484    if (marked_lowline < 0) 
     3485        return 0; 
     3486 
     3487    if (end_mark >= (edit->last_byte - 1)) { 
     3488        marked_lowline = -1; 
     3489        return 0; 
     3490    } 
     3491    edit_mark_cmd (edit, 1);    /* clear */ 
     3492    edit_cursor_move (edit, end_mark - edit->curs1); 
     3493    lowline_min = edit->curs1; 
     3494    edit_cursor_to_eol (edit); 
     3495    lowline_max = edit->curs1 + 1; 
     3496    edit_cursor_move (edit, start_mark - edit->curs1); 
     3497 
     3498    for (n = -1, p = lowline_min; p < lowline_max; p++) 
     3499        edit_insert (edit, edit_get_byte (edit, ++n + p)); 
     3500 
     3501    edit_mark_cmd (edit, 0);    /* mark1 */ 
     3502    marked_topline = edit->curs_line; 
     3503    edit_cursor_move (edit, (end_mark - start_mark)); 
     3504    edit_cursor_to_eol (edit); 
     3505 
     3506    while (edit_get_byte (edit, edit->curs1 - 1) != '\n') 
     3507        edit_backspace (edit, 1); 
     3508 
     3509    edit_backspace (edit, 1); 
     3510    marked_lowline = edit->curs_line; 
     3511    edit_cursor_move (edit, 1); 
     3512    edit_mark_cmd (edit, 0);    /* mark2 */ 
     3513    edit_move_to_line (edit, marked_lowline); 
     3514    edit_cursor_to_bol (edit); 
     3515 
     3516    if (edit->curs_line > (edit->start_line 
     3517            + edit->num_widget_lines - 3)) 
     3518        edit_move_display (edit, edit->curs_line - edit->num_widget_lines + 3); 
     3519 
     3520    return 1; 
     3521} 
     3522 
     3523int mlvm_block_down_move (WEdit * edit, const int command) 
     3524{ 
     3525    long start_mark, end_mark; 
     3526 
     3527    if (column_highlighting) 
     3528        return 0; 
     3529 
     3530    marked_topline = -1; 
     3531 
     3532    if (eval_marks (edit, &start_mark, &end_mark)) { 
     3533        if (mlvm_proceed_unmarked_line (edit, command)) 
     3534            return 1; 
     3535    } else if (start_mark <= edit->curs1 && edit->curs1 <= end_mark) { 
     3536        if (marked_lowline < 0) 
     3537            mlvm_get_block_marks (edit, &start_mark, &end_mark); 
     3538 
     3539        if (mlvm_move_marked_block_down (edit, start_mark, end_mark)) 
     3540            return 1; 
     3541    } else { 
     3542        marked_lowline = -1; 
     3543    } 
     3544 
     3545    return 0; 
     3546} 
  • misc/mc.keymap.default

    diff --git a/misc/mc.keymap.default b/misc/mc.keymap.default
    index 5883787..467cd77 100644
    a b EditSaveas = f12 
    4040EditMark = f3 
    4141EditCopy = f5 
    4242EditMove = f6 
     43EditMoveUp = ctrl-f6 
    4344EditRemove = f8 
    4445EditUnmark = 
    4546EditFind = f7 
  • misc/mc.keymap.emacs

    diff --git a/misc/mc.keymap.emacs b/misc/mc.keymap.emacs
    index b30d85f..8face7a 100644
    a b EditSaveas = f12 
    3939EditMark = f3 
    4040EditCopy = f5 
    4141EditMove = f6 
     42EditMoveUp = ctrl-f6 
    4243EditRemove = f8 
    4344EditUnmark = 
    4445EditFind = f7 
  • src/cmddef.h

    diff --git a/src/cmddef.h b/src/cmddef.h
    index 594223e..3550078 100644
    a b  
    6363#define CK_Column_Mark          208 
    6464#define CK_Shift_Block_Left     211 
    6565#define CK_Shift_Block_Right    212 
     66#define CK_Move_Up              213 
    6667 
    6768/* search and replace */ 
    6869#define CK_Find                 301 
  • src/keybind.c

    diff --git a/src/keybind.c b/src/keybind.c
    index 66657ab..c15eac8 100644
    a b static name_keymap_t command_names[] = { 
    8383    { "EditMark",                          CK_Mark }, 
    8484    { "EditCopy",                          CK_Copy }, 
    8585    { "EditMove",                          CK_Move }, 
     86    { "EditMoveUp",                        CK_Move_Up}, 
    8687    { "EditRemove",                        CK_Remove }, 
    8788    { "EditUnmark",                        CK_Unmark }, 
    8889    { "EditSaveBlock",                     CK_Save_Block }, 
    const global_keymap_t default_editor_keymap[] = { 
    603604    /* Ctrl */ 
    604605    { KEY_M_CTRL | (KEY_F (2)),             CK_Save_As,                     "C-F2" }, 
    605606    { KEY_M_CTRL | (KEY_F (4)),             CK_Replace_Again,               "C-F4" }, 
     607    { KEY_M_CTRL | (KEY_F (6)),             CK_Move_Up,                     "C-F6" }, 
    606608    { KEY_M_CTRL | (KEY_F (7)),             CK_Find_Again,                  "C-F7" }, 
    607609    { KEY_M_CTRL | KEY_BACKSPACE,           CK_Undo,                        "C-BackSpace" }, 
    608610    { KEY_M_CTRL | KEY_NPAGE,               CK_End_Of_Text,                 "C-PgDn" },