Ticket #2644: mc.patch

File mc.patch, 8.9 KB (added by gvy, 12 years ago)

wordstar-like hack by "arisu" (see the links above)

  • src/editor/edit-impl.h

    diff --git a/src/editor/edit-impl.h b/src/editor/edit-impl.h
    index f9d3efe..753d8f5 100644
    a b void edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_inserti 
    313313 
    314314/*** inline functions ****************************************************************************/ 
    315315 
     316 
     317 
     318enum { 
     319  WS_CK_FirstCommand = 103666, 
     320  WS_CK_BlockStart, 
     321  WS_CK_BlockEnd, 
     322  WS_CK_BlockToggleVis, 
     323  WS_CK_GoToBlockStart, 
     324  WS_CK_GoToBlockEnd, 
     325  WS_CK_LastCommand 
     326}; 
     327 
     328 
    316329#endif /* MC__EDIT_IMPL_H */ 
  • src/editor/edit-widget.h

    diff --git a/src/editor/edit-widget.h b/src/editor/edit-widget.h
    index fa866b4..bd23f5f 100644
    a b struct WEdit 
    133133    /* line break */ 
    134134    LineBreaks lb; 
    135135    gboolean extmod; 
     136    gchar wsextmod; /* wordstar mode cmd type */ 
     137    gboolean wsmarkshidden; 
     138    gboolean wsblock; 
    136139 
    137140    char *labels[10]; 
    138141 
  • src/editor/edit.c

    diff --git a/src/editor/edit.c b/src/editor/edit.c
    index 0da86a6..81b7893 100644
    a b edit_init (WEdit * edit, int y, int x, int lines, int cols, const char *filename 
    22692269    edit->stat1.st_gid = getgid (); 
    22702270    edit->stat1.st_mtime = 0; 
    22712271 
     2272    edit->extmod = FALSE; 
     2273    edit->wsextmod = 0; 
     2274    edit->wsmarkshidden = FALSE; 
     2275    edit->wsblock = FALSE; 
     2276 
    22722277    edit->over_col = 0; 
    22732278    edit->bracket = -1; 
    22742279    edit->force |= REDRAW_PAGE; 
    edit_push_markers (WEdit * edit) 
    32993304void 
    33003305edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2) 
    33013306{ 
     3307/* 
     3308  if (m1 > m2 || (m1 == m2 && c1 > c2)) { 
     3309    int ti = m1; 
     3310    long tl = c1; 
     3311    m1 = m2; m2 = ti; 
     3312    c1 = c2; c2 = tl; 
     3313  } 
     3314*/ 
    33023315    edit->mark1 = m1; 
    33033316    edit->mark2 = m2; 
    33043317    edit->column1 = c1; 
    edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2) 
    33123325void 
    33133326edit_mark_cmd (WEdit * edit, int unmark) 
    33143327{ 
     3328    edit->wsmarkshidden = FALSE; 
     3329    edit->wsblock = FALSE; 
    33153330    edit_push_markers (edit); 
    33163331    if (unmark) 
    33173332    { 
    edit_execute_key_command (WEdit * edit, unsigned long command, int char_for_inse 
    35233538        edit->force |= REDRAW_PAGE; 
    35243539} 
    35253540 
     3541 
     3542static void edit_goto_line_pos (WEdit *edit, int line, int pos) { 
     3543  edit->force |= REDRAW_PAGE; /*FIXME: determine what to redraw?*/ 
     3544  if (line < 0) line = 0; 
     3545  if (line > edit->total_lines-1) line = edit->total_lines-1; 
     3546  if (line >= edit->start_line+edit->widget.lines || line < edit->start_line) { 
     3547    edit_move_display(edit, line-edit->widget.lines/2); 
     3548  } 
     3549  edit_move_to_line(edit, line); 
     3550  edit_cursor_to_bol(edit); 
     3551  if (pos > 0) { 
     3552    int len = edit_eol(edit, edit->curs1)-edit->curs1; 
     3553    if (pos > len) pos = len; 
     3554    edit_cursor_move(edit, pos); 
     3555  } 
     3556  edit->search_start = edit->curs1; 
     3557  edit->prev_col = edit_get_col(edit); 
     3558  edit->over_col = 0; 
     3559} 
     3560 
     3561 
     3562static void edit_goto_pos (WEdit *edit, int pos) { 
     3563  int line, cp, linebol; 
     3564  // 
     3565  if (pos > edit->last_byte) pos = edit->last_byte; 
     3566  for (line = linebol = cp = 0; cp < pos; ++cp) { 
     3567    if (edit_get_byte(edit, cp) == '\n') { 
     3568      ++line; 
     3569      linebol = cp+1; 
     3570    } 
     3571  } 
     3572  edit_goto_line_pos(edit, line, pos-linebol); 
     3573} 
     3574 
     3575 
    35263576/* --------------------------------------------------------------------------------------------- */ 
    35273577/** 
    35283578   This executes a command at a lower level than macro recording. 
    edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) 
    36713721 
    36723722    switch (command) 
    36733723    { 
     3724    case WS_CK_BlockStart: 
     3725      edit->force |= REDRAW_PAGE; /*FIXME: determine what to redraw?*/ 
     3726      if (edit->wsblock && !edit->wsmarkshidden && edit->mark2 >= 0) { 
     3727        /* we have 'endmark' */ 
     3728        edit->end_mark_curs = edit->curs1; 
     3729        edit_set_markers(edit, edit->curs1, edit->mark2, edit->curs_col+edit->over_col, edit->column2); 
     3730      } else { 
     3731        /* we have no 'endmark' or block was hidden */ 
     3732        edit->end_mark_curs = edit->curs1; 
     3733        edit_set_markers(edit, edit->curs1, edit->curs1, edit->curs_col+edit->over_col, edit->curs_col+edit->over_col); 
     3734      } 
     3735      edit->wsmarkshidden = FALSE; 
     3736      edit->wsblock = TRUE; 
     3737      edit->column_highlight = 0; 
     3738      break; 
     3739 
     3740    case WS_CK_BlockEnd: 
     3741      edit->force |= REDRAW_PAGE; /*FIXME: determine what to redraw?*/ 
     3742      if (edit->wsblock && !edit->wsmarkshidden && edit->mark2 >= 0) { 
     3743        /* we have 'endmark' */ 
     3744        edit_set_markers(edit, edit->mark1, edit->curs1, edit->column1, edit->curs_col+edit->over_col); 
     3745      } else { 
     3746        /* we have no 'endmark' or block was hidden */ 
     3747        edit->wsmarkshidden = FALSE; 
     3748        edit_set_markers(edit, edit->curs1, edit->curs1, edit->curs_col+edit->over_col, edit->curs_col+edit->over_col); 
     3749      } 
     3750      edit->wsmarkshidden = FALSE; 
     3751      edit->wsblock = TRUE; 
     3752      edit->column_highlight = 0; 
     3753      break; 
     3754 
     3755    case WS_CK_BlockToggleVis: 
     3756      if (edit->wsblock) { 
     3757        edit->force |= REDRAW_PAGE; 
     3758        edit->wsmarkshidden = !edit->wsmarkshidden; 
     3759      } 
     3760      break; 
     3761 
     3762    case WS_CK_GoToBlockStart: 
     3763      if (!edit->wsmarkshidden && edit->mark1 >= 0) { 
     3764        edit_goto_pos(edit, edit->mark1); 
     3765      } 
     3766      break; 
     3767 
     3768    case WS_CK_GoToBlockEnd: 
     3769      if (!edit->wsmarkshidden && edit->mark2 >= 0) { 
     3770        edit_goto_pos(edit, edit->mark2); 
     3771      } 
     3772      break; 
     3773 
    36743774    case CK_TopOnScreen: 
    36753775    case CK_BottomOnScreen: 
    36763776    case CK_MarkToPageBegin: 
    edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) 
    39614061        break; 
    39624062 
    39634063    case CK_Mark: 
     4064      if (edit->wsblock) { 
     4065        edit->wsblock = FALSE; 
     4066        edit->wsmarkshidden = FALSE; 
     4067        edit->mark1 = edit->mark2 = 1; 
     4068        edit->column_highlight = 0; 
     4069      } else 
    39644070        if (edit->mark2 >= 0) 
    39654071        { 
    39664072            if (edit->column_highlight) 
  • src/editor/editcmd.c

    diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c
    index a852ea5..e393350 100644
    a b pipe_mail (WEdit * edit, char *to, char *subject, char *cc) 
    979979static gboolean 
    980980is_break_char (char c) 
    981981{ 
    982     return (isspace (c) || strchr ("{}[]()<>=|/\\!?~'\",.;:#$%^&*", c)); 
     982    /*return (isspace (c) || strchr ("{}[]()<>=|/\\!?~'\",.;:#$%^&*", c));*/ 
     983    /*k8:*/ 
     984    return (isspace (c) || strchr ("{}[]()<>=|/\\!?~'\",.;:#$%^&*+-@#", c)); 
    983985} 
    984986 
    985987/* --------------------------------------------------------------------------------------------- */ 
    edit_load_cmd (WEdit * edit, edit_current_file_t what) 
    18881890int 
    18891891eval_marks (WEdit * edit, long *start_mark, long *end_mark) 
    18901892{ 
     1893    if (edit->wsmarkshidden) { 
     1894      *start_mark = *end_mark = 0; 
     1895      edit->column2 = edit->column1 = 0; 
     1896      return 1; 
     1897    } 
     1898 
    18911899    if (edit->mark1 != edit->mark2) 
    18921900    { 
    18931901        long start_bol, start_eol; 
  • src/editor/editkeys.c

    diff --git a/src/editor/editkeys.c b/src/editor/editkeys.c
    index f4c34a8..2f7ec80 100644
    a b  
    7070/*** public functions ****************************************************************************/ 
    7171/* --------------------------------------------------------------------------------------------- */ 
    7272 
     73typedef struct { 
     74  long key; 
     75  long key1; 
     76  unsigned long cmd; 
     77} WSCommandDef; 
     78 
     79 
     80static const WSCommandDef wsQCommands[] = { 
     81  {  2, 'B', WS_CK_GoToBlockStart}, 
     82  { 11, 'K', WS_CK_GoToBlockEnd}, 
     83  {-1, -1, 0} 
     84}; 
     85 
     86 
     87static const WSCommandDef wsKCommands[] = { 
     88  {  2, 'B', WS_CK_BlockStart}, 
     89  { 11, 'K', WS_CK_BlockEnd}, 
     90  {400, 'H', WS_CK_BlockToggleVis}, /*8*/ 
     91  { 25, 'Y', CK_Remove}, 
     92  {  3, 'C', CK_Copy}, 
     93  { 22, 'V', CK_Move}, 
     94  { 21, 'U', CK_BlockShiftLeft}, 
     95  {  9, 'I', CK_BlockShiftRight}, 
     96  { 23, 'W', CK_Store}, 
     97  { 18, 'R', CK_Paste}, 
     98  {  5, 'E', CK_DeleteToEnd}, 
     99  {-1, -1, 0} 
     100}; 
     101 
     102 
     103static unsigned long wsFindCommand (const WSCommandDef *list, long key) { 
     104  if (key >= 'a' && key <= 'z') key -= 32; 
     105  if (key >= 16384 && key <= 16384+26) key -= 16384; 
     106  for (; list->key > 0; ++list) { 
     107    if (key == list->key || key == list->key1) return list->cmd; 
     108  } 
     109  return 0; 
     110} 
     111 
     112 
     113static unsigned long edit_wordstar (gchar emode, long x_key) { 
     114  unsigned long cmd = wsFindCommand(emode==11?wsKCommands:wsQCommands, x_key); 
     115  if (cmd == 0) cmd = (unsigned long)CK_InsertChar; 
     116  return cmd; 
     117} 
     118 
     119 
    73120/* 
    74121 * Translate the keycode into either 'command' or 'char_for_insertion'. 
    75122 * 'command' is one of the editor commands from cmddef.h. 
    edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch) 
    81128    int char_for_insertion = -1; 
    82129    int c; 
    83130 
     131    if (!edit->extmod && edit->wsextmod) { 
     132      command = edit_wordstar(edit->wsextmod, x_key); 
     133      edit->wsextmod = 0; 
     134      goto fin; 
     135    } 
     136 
     137    if (!edit->extmod && (x_key-16384 == 11 || x_key-16384 == 17)) { 
     138      edit->wsextmod = x_key-16384; 
     139      goto fin; 
     140    } 
     141 
    84142    /* an ordinary insertable character */ 
    85     if (!edit->extmod && x_key < 256) 
     143    if (!edit->extmod && !edit->wsextmod && x_key < 256) 
    86144    { 
    87145#ifdef HAVE_CHARSET 
    88146        if (edit->charpoint >= 4)