Ticket #3664: 002-3664-don-t-hardcode-plus-minus-etc--v2.patch

File 002-3664-don-t-hardcode-plus-minus-etc--v2.patch, 8.1 KB (added by mooffie, 5 years ago)

(Note: comment #9 explains why this patch is a dud.)

  • lib/tty/key.c

    From 097c1d3a9b0ff0ce895d2c8589765455390c8824 Mon Sep 17 00:00:00 2001
    From: Mooffie <mooffie@gmail.com>
    Date: Sun, 17 Jul 2016 20:32:50 +0300
    Subject: [PATCH] Ticket #3664: (midnight_callback): don't hardcode +, -, \, *.
    
    ---
     lib/tty/key.c              | 33 +++++++++++++++++++++++++++++
     lib/tty/key.h              |  1 +
     misc/mc.default.keymap     |  6 +++---
     misc/mc.emacs.keymap       |  6 +++---
     src/filemanager/midnight.c | 53 +++++++++++++++++++++-------------------------
     src/keybind-defaults.c     |  7 +++---
     src/setup.c                |  5 +++--
     7 files changed, 71 insertions(+), 40 deletions(-)
    
    diff --git a/lib/tty/key.c b/lib/tty/key.c
    index 344141c..4a9afdf 100644
    a b application_keypad_mode (void) 
    22752275 
    22762276/* --------------------------------------------------------------------------------------------- */ 
    22772277 
     2278/** 
     2279 * Returns TRUE if a user has asked to prefer the keypad version of a key. 
     2280 * 
     2281 * That is, if the user has asked for "+ - / *" to be effective (in some 
     2282 * situations) only if typed via the keypad. 
     2283 * 
     2284 * @see application_keypad_mode(), numeric_keypad_mode(). 
     2285 */ 
     2286gboolean 
     2287tty_has_alternate_key_representation (int keycode) 
     2288{ 
     2289    if (mc_global.tty.alternate_plus_minus 
     2290        && (mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) 
     2291    { 
     2292        /* Yes, "application mode" is active. The following keys have a 
     2293         * different representation when typed via the keypad. */ 
     2294        switch (keycode) 
     2295        { 
     2296        case '+': 
     2297        case '-': 
     2298        case '/': /* Note: This is slash. It's not the *backslash* used (by default) to Unselect files. */ 
     2299        case '*': 
     2300            return TRUE; 
     2301        default: 
     2302            break; 
     2303        } 
     2304    } 
     2305 
     2306    return FALSE; 
     2307} 
     2308 
     2309/* --------------------------------------------------------------------------------------------- */ 
     2310 
    22782311void 
    22792312enable_bracketed_paste (void) 
    22802313{ 
  • lib/tty/key.h

    diff --git a/lib/tty/key.h b/lib/tty/key.h
    index 7b866ac..b050924 100644
    a b int get_key_code (int nodelay); 
    106106/* Set keypad mode (xterm and linux console only) */ 
    107107void numeric_keypad_mode (void); 
    108108void application_keypad_mode (void); 
     109gboolean tty_has_alternate_key_representation (int keycode); 
    109110 
    110111/* Bracketed paste mode */ 
    111112void enable_bracketed_paste (void); 
  • misc/mc.default.keymap

    diff --git a/misc/mc.default.keymap b/misc/mc.default.keymap
    index 7d61ff8..877b879 100644
    a b PutOtherPath = alt-shift-a 
    3535PutCurrentSelected = alt-enter; ctrl-enter 
    3636PutCurrentFullSelected = ctrl-shift-enter 
    3737ViewFiltered = alt-exclamation 
    38 Select = kpplus 
    39 Unselect = kpminus 
    40 SelectInvert = kpasterisk 
     38Select = kpplus; plus 
     39Unselect = kpminus; minus; backslash 
     40SelectInvert = kpasterisk; asterisk 
    4141ScreenList = alt-prime 
    4242# OptionsLayout = 
    4343# OptionsAppearance = 
  • misc/mc.emacs.keymap

    diff --git a/misc/mc.emacs.keymap b/misc/mc.emacs.keymap
    index 8b4842a..7d7ba18 100644
    a b PutOtherPath = alt-shift-a 
    3535PutCurrentSelected = alt-enter; ctrl-enter 
    3636PutCurrentFullSelected = ctrl-shift-enter 
    3737ViewFiltered = alt-exclamation 
    38 Select = kpplus 
    39 Unselect = kpminus 
    40 SelectInvert = kpasterisk 
     38Select = kpplus; plus 
     39Unselect = kpminus; minus; backslash 
     40SelectInvert = kpasterisk; asterisk 
    4141ScreenList = alt-prime 
    4242# OptionsLayout = 
    4343# OptionsAppearance = 
  • src/filemanager/midnight.c

    diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c
    index e312b2c..edf2e54 100644
    a b midnight_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void 
    14911491            cmdline->point = 0; 
    14921492        } 
    14931493 
    1494         if ((!mc_global.tty.alternate_plus_minus 
    1495              || !(mc_global.tty.console_flag != '\0' || mc_global.tty.xterm_flag)) && !quote 
    1496             && !current_panel->searching) 
     1494        /* 
     1495         * Handle '+' (Select), '-' '\\' (Unselect), '*' (SelectInvert), and 
     1496         * possibly other punctuation keys, "when they're typed as the first 
     1497         * character on the command-line". 
     1498         */ 
     1499        if ((parm < 128) && g_ascii_ispunct ((char) parm)       /* "< 128" because g_ascii_ispunct() accepts char, not int. */ 
     1500            && !tty_has_alternate_key_representation (parm) && !quote && !current_panel->searching) 
    14971501        { 
    1498             if (!only_leading_plus_minus) 
     1502            /* 
     1503             * The idea here is that punctuation marks are unlikely to start 
     1504             * a shell command. Therefore we only activate them when the 
     1505             * command-line is still empty. Or when the user (by turning off the 
     1506             * 'only_leading_plus_minus' option) asks to make them dominant. 
     1507             */ 
     1508            if (!only_leading_plus_minus || !command_prompt || input_is_empty (cmdline)) 
    14991509            { 
    1500                 /* Special treatement, since the input line will eat them */ 
    1501                 if (parm == '+') 
    1502                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Select, NULL); 
     1510                command = keybind_lookup_keymap_command (main_map, parm); 
     1511                if (command != CK_IgnoreKey) 
     1512                { 
     1513                    cb_ret_t res; 
    15031514 
    1504                 if (parm == '\\' || parm == '-') 
    1505                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Unselect, 
    1506                                          NULL); 
     1515                    /* First try the panel, then the filemanager. */ 
     1516                    res = send_message (current_panel, NULL, MSG_ACTION, command, NULL); 
     1517                    if (res == MSG_NOT_HANDLED) 
     1518                       res = midnight_execute_cmd (NULL, command); 
    15071519 
    1508                 if (parm == '*') 
    1509                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_SelectInvert, 
    1510                                          NULL); 
    1511             } 
    1512             else if (!command_prompt || cmdline->buffer[0] == '\0') 
    1513             { 
    1514                 /* Special treatement '+', '-', '\', '*' only when this is 
    1515                  * first char on input line 
    1516                  */ 
    1517                 if (parm == '+') 
    1518                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Select, NULL); 
    1519  
    1520                 if (parm == '\\' || parm == '-') 
    1521                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_Unselect, 
    1522                                          NULL); 
    1523  
    1524                 if (parm == '*') 
    1525                     return send_message (current_panel, midnight_dlg, MSG_ACTION, CK_SelectInvert, 
    1526                                          NULL); 
     1520                    return res; 
     1521                } 
    15271522            } 
    15281523        } 
    15291524        return MSG_NOT_HANDLED; 
  • src/keybind-defaults.c

    diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c
    index 38b4afb..8b2561f 100644
    a b static const global_keymap_ini_t default_main_keymap[] = { 
    127127    {"SplitVertHoriz", "alt-comma"}, 
    128128    {"ExtendedKeyMap", "ctrl-x"}, 
    129129    /* Select/unselect group */ 
    130     {"Select", "kpplus"}, 
    131     {"Unselect", "kpminus"}, 
    132     {"SelectInvert", "kpasterisk"}, 
     130    /* Note: ASCII punctuation keys (like plus, but unlike kpplus) are only effective when they're the first char typed on the command-line. */ 
     131    {"Select", "kpplus; plus"}, 
     132    {"Unselect", "kpminus; minus; backslash"}, 
     133    {"SelectInvert", "kpasterisk; asterisk"}, 
    133134    /* List of screens */ 
    134135    {"ScreenList", "alt-prime"}, 
    135136    {NULL, NULL} 
  • src/setup.c

    diff --git a/src/setup.c b/src/setup.c
    index 951edb8..f707af8 100644
    a b int easy_patterns = 1; 
    153153/* It true saves the setup when quitting */ 
    154154int auto_save_setup = 1; 
    155155 
    156 /* If true, then the +, - and \ keys have their special meaning only if the 
    157  * command line is emtpy, otherwise they behave like regular letters 
     156/* If true, then the +, -, \ and * keys have their special meaning only if the 
     157 * command line is empty, otherwise they're *always* special (and you'll have 
     158 * to quote them (C-q) whenever you want to use them in the command line. 
    158159 */ 
    159160int only_leading_plus_minus = 1; 
    160161