Ticket #1819: 1819-While__pressingPrtScr-comment__pressingDelete-uncomm.patch
File 1819-While__pressingPrtScr-comment__pressingDelete-uncomm.patch, 7.1 KB (added by vit_r, 15 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) 2732 2732 break; 2733 2733 } 2734 2734 } 2735 edit_delete (edit, 0);2735 case_CK_Delete (edit); 2736 2736 break; 2737 2737 case CK_Delete_Word_Left: 2738 2738 edit->over_col = 0; … … edit_execute_cmd (WEdit *edit, int command, int char_for_insertion) 3177 3177 case CK_Ext_Mode: 3178 3178 edit->extmod = 1; 3179 3179 break; 3180 case CK_PrtScr: 3181 case_CK_PrtScr (edit); 3182 break; 3180 3183 default: 3181 3184 break; 3182 3185 } … … edit_stack_free (void) 3336 3339 edit_stack_iterator++) 3337 3340 g_free (edit_history_moveto[edit_stack_iterator].filename); 3338 3341 } 3342 3343 void 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 3360 int 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 */ 3373 int 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 */ 3387 int 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 3419 void 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 3443 void 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; 55 55 extern char *option_backup_ext; 56 56 57 57 extern int edit_confirm_save; 58 59 58 extern int visible_tabs; 60 59 extern int visible_tws; 61 62 60 extern int simple_statusbar; 63 61 extern int option_check_nl_at_eof; 64 62 … … const char *edit_get_file_name (const WEdit *edit); 72 70 int edit_get_curs_col (const WEdit *edit); 73 71 const char *edit_get_syntax_type (const WEdit *edit); 74 72 73 /* While pressing: 74 PrtScr comments lines 75 Delete uncomments lines */ 76 int it_is_ELF (WEdit * edit); 77 int it_is_ASM (WEdit * edit); 78 int it_is_C (WEdit * edit); 79 void edit_show_bottom (WEdit * edit); 80 void case_CK_PrtScr (WEdit * edit); 81 void case_CK_Delete (WEdit * edit); 82 75 83 #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) 160 160 } 161 161 } 162 162 } 163 163 164 fin: 164 165 *cmd = command; 165 166 *ch = char_for_insertion; 166 167 168 if (16412 == x_key) { 169 *ch = -1; 170 *cmd = CK_PrtScr; 171 return 1; 172 } 173 167 174 return (command == CK_Insert_Char && char_for_insertion == -1) ? 0 : 1; 168 175 } -
src/cmddef.h
diff --git a/src/cmddef.h b/src/cmddef.h index 2644130..fef6d8b 100644
a b 364 364 #define CK_PanelSortOrderBySize 8038 365 365 #define CK_PanelSortOrderByMTime 8039 366 366 367 /* While pressing: 368 PrtScr comments lines 369 Delete uncomments lines */ 370 #define CK_PrtScr 16412 371 367 372 /* 368 373 Process a block through a shell command: CK_Pipe_Block(i) executes shell_cmd[i]. 369 374 shell_cmd[i] must process the file ~/cooledit.block and output ~/cooledit.block … … 377 382 #define SHELL_COMMANDS_i {"/edit.indent.rc", "/edit.spell.rc", /* and so on */ 0 } 378 383 #define CK_Macro(i) (2000+(i)) 379 384 #define CK_Last_Macro CK_Macro(0x7FFF) 380 #else381 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))386 385 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)) 387 391 #endif /* MC_CMD_DEF_H */