* Alexey I. Froloff <raorn@> [061021 17:53]:
> Vim should _support_ Meta-Sends-Escape mode which is A Must Have
> for non-ascii 8-bit locales
Patch attached.

New option - 'eightbitmeta' ('em'), default on.  If unset, two
things happen:

1. "<M-x>" is stored internaly as "<Esc>x" sequence (was (x |
0x80)).

2. Alt+key puts "<Esc>key" to input buffer (GUI only).


It's up to user to keep this option in sync with terminal/console
settings, it's not set by Vim and default behavior is unchanged.

This makes sense for UNIX platform only, however WIN32 and Photon
GUI's also support 2) (untested).

-- 
Regards,
Sir Raorn.
diff -ur ../vim70-orig/runtime/doc/options.txt runtime/doc/options.txt
--- ../vim70-orig/runtime/doc/options.txt       2006-10-21 17:53:35 +0400
+++ runtime/doc/options.txt     2006-10-21 21:17:09 +0400
@@ -2320,6 +2320,16 @@
        also 'gdefault' option.
        Switching this option on is discouraged!
 
+                          *'em'* *'eightbitmeta'* *'noem'* *'noeightbitmeta'*
+'eightbitmeta' 'em'    boolean (default on)
+                       global
+                       {not in Vi}
+       When set, handles Meta (Alt) + keypress to set the 8th bit.  When
+       unset, handles Meta (Alt) + keypress as an escape prefix.
+
+       You should keep this option in sync with "meta8" (aterm/rxvt) and
+       "eightBitInput" (xterm) resources.  See |:map-alt-keys|.
+
                                        *'encoding'* *'enc'* *E543*
 'encoding' 'enc'       string (default: "latin1" or value from $LANG)
                        global
diff -ur ../vim70-orig/runtime/doc/tags runtime/doc/tags
--- ../vim70-orig/runtime/doc/tags      2006-10-21 17:53:35 +0400
+++ runtime/doc/tags    2006-10-22 00:22:17 +0400
@@ -174,7 +174,9 @@
 'ef'   options.txt     /*'ef'*
 'efm'  options.txt     /*'efm'*
 'ei'   options.txt     /*'ei'*
+'eightbitmeta' options.txt     /*'eightbitmeta'*
 'ek'   options.txt     /*'ek'*
+'em'   options.txt     /*'em'*
 'enc'  options.txt     /*'enc'*
 'encoding'     options.txt     /*'encoding'*
 'endofline'    options.txt     /*'endofline'*
@@ -486,7 +488,9 @@
 'noeb' options.txt     /*'noeb'*
 'noed' options.txt     /*'noed'*
 'noedcompatible'       options.txt     /*'noedcompatible'*
+'noeightbitmeta'       options.txt     /*'noeightbitmeta'*
 'noek' options.txt     /*'noek'*
+'noem' options.txt     /*'noem'*
 'noendofline'  options.txt     /*'noendofline'*
 'noeol'        options.txt     /*'noeol'*
 'noequalalways'        options.txt     /*'noequalalways'*
diff -ur ../vim70-orig/runtime/optwin.vim runtime/opwin.vim
--- ../vim70-orig/runtime/optwin.vim    2006-10-21 17:53:36 +0400
+++ runtime/optwin.vim  2006-10-22 00:35:57 +0400
@@ -500,6 +500,8 @@
 call <SID>BinOptionG("wiv", &wiv)
 call append("$", "esckeys\trecognize keys that start with <Esc> in Insert 
mode")
 call <SID>BinOptionG("ek", &ek)
+call append("$", "eightbitmeta\tassume that Alt+Key sends <Esc>Key sequence")
+call <SID>BinOptionG("em", &em)
 call append("$", "scrolljump\tminimal number of lines to scroll at a time")
 call append("$", " \tset sj=" . &sj)
 call append("$", "ttyscroll\tmaximum number of lines to use scrolling instead 
of redrawing")
diff -ur ../vim70-orig/src/gui_gtk_x11.c src/gui_gtk_x11.c
--- ../vim70-orig/src/gui_gtk_x11.c     2006-10-21 17:53:34 +0400
+++ src/gui_gtk_x11.c   2006-10-21 23:40:53 +0400
@@ -1098,6 +1098,7 @@
 #ifdef FEAT_MBYTE
            && !enc_dbcs
 #endif
+           && p_em
            )
     {
        string[0] |= 0x80;
@@ -1151,9 +1152,11 @@
            || key_sym == GDK_Return || key_sym == GDK_Linefeed
            || key_sym == GDK_Escape || key_sym == GDK_KP_Tab
            || key_sym == GDK_ISO_Enter || key_sym == GDK_3270_Enter
+           || ((!p_em
 #ifdef FEAT_MBYTE
-           || (enc_dbcs && len == 1 && (state & GDK_MOD1_MASK))
+               || enc_dbcs
 #endif
+               ) && len == 1 && (state & GDK_MOD1_MASK))
            )
     {
        modifiers = modifiers_gdk2vim(state);
@@ -1170,25 +1173,31 @@
        key = simplify_key(key, &modifiers);
        if (key == CSI)
            key = K_CSI;
-       if (IS_SPECIAL(key))
+
+       len = 0;
+
+       if (!p_em && modifiers & MOD_MASK_ALT)
        {
-           string[0] = CSI;
-           string[1] = K_SECOND(key);
-           string[2] = K_THIRD(key);
-           len = 3;
+           modifiers &= ~MOD_MASK_ALT;
+           string[len++] = ESC;
        }
-       else
+
+       if (modifiers != 0)
        {
-           string[0] = key;
-           len = 1;
+           string[len++] = CSI;
+           string[len++] = KS_MODIFIER;
+           string[len++] = modifiers;
        }
 
-       if (modifiers != 0)
+       if (IS_SPECIAL(key))
+       {
+           string[len++] = CSI;
+           string[len++] = K_SECOND(key);
+           string[len++] = K_THIRD(key);
+       }
+       else
        {
-           string2[0] = CSI;
-           string2[1] = KS_MODIFIER;
-           string2[2] = modifiers;
-           add_to_input_buf(string2, 3);
+           string[len++] = key;
        }
     }
 
diff -ur ../vim70-orig/src/gui_photon.c src/gui_photon.c
--- ../vim70-orig/src/gui_photon.c      2006-04-16 14:09:04 +0400
+++ src/gui_photon.c    2006-10-22 00:09:14 +0400
@@ -571,7 +571,7 @@
                            modifiers |= MOD_MASK_CTRL;
                    }
 
-                   if( modifiers & MOD_MASK_ALT )
+                   if( p_em && modifiers & MOD_MASK_ALT )
                    {
                        ch = Meta( ch );
                        modifiers &= ~MOD_MASK_ALT;
@@ -587,6 +587,13 @@
        }
 
        ch = simplify_key( ch, &modifiers );
+
+       if (!p_em && modifiers && MOD_MASK_ALT)
+       {
+           modifiers &= ~MOD_MASK_ALT;
+           string[ len++ ] = ESC;
+       }
+
        if( modifiers )
        {
            string[ len++ ] = CSI;
diff -ur ../vim70-orig/src/gui_x11.c src/gui_x11.c
--- ../vim70-orig/src/gui_x11.c 2006-05-03 00:04:15 +0400
+++ src/gui_x11.c       2006-10-21 23:38:31 +0400
@@ -917,6 +917,7 @@
 #ifdef FEAT_MBYTE
            && !enc_dbcs
 #endif
+           && p_em
            )
     {
 #if defined(FEAT_MENU) && defined(FEAT_GUI_MOTIF)
@@ -996,9 +997,11 @@
     if (len == -3 || key_sym == XK_space || key_sym == XK_Tab
            || key_sym == XK_Return || key_sym == XK_Linefeed
            || key_sym == XK_Escape
+           || ((!p_em
 #ifdef FEAT_MBYTE
-           || (enc_dbcs && len == 1 && (ev_press->state & Mod1Mask))
+               || enc_dbcs
 #endif
+               ) && len == 1 && (ev_press->state & Mod1Mask))
        )
     {
        modifiers = 0;
@@ -1022,25 +1025,31 @@
        key = simplify_key(key, &modifiers);
        if (key == CSI)
            key = K_CSI;
-       if (IS_SPECIAL(key))
+
+       len = 0;
+
+       if (!p_em && modifiers == MOD_MASK_ALT)
        {
-           string[0] = CSI;
-           string[1] = K_SECOND(key);
-           string[2] = K_THIRD(key);
-           len = 3;
+           modifiers &= ~MOD_MASK_ALT;
+           string[len++] = ESC;
        }
-       else
+
+       if (modifiers != 0)
        {
-           string[0] = key;
-           len = 1;
+           string[len++] = CSI;
+           string[len++] = KS_MODIFIER;
+           string[len++] = modifiers;
        }
 
-       if (modifiers != 0)
+       if (IS_SPECIAL(key))
+       {
+           string[len++] = CSI;
+           string[len++] = K_SECOND(key);
+           string[len++] = K_THIRD(key);
+       }
+       else
        {
-           string2[0] = CSI;
-           string2[1] = KS_MODIFIER;
-           string2[2] = modifiers;
-           add_to_input_buf(string2, 3);
+           string[len++] = key;
        }
     }
 
diff -ur ../vim70-orig/src/misc2.c src/misc2.c
--- ../vim70-orig/src/misc2.c   2006-10-21 17:53:35 +0400
+++ src/misc2.c 2006-10-21 23:30:25 +0400
@@ -2409,7 +2409,8 @@
     {
        if (table_idx < 0
                && (!vim_isprintc(c) || (c & 0x7f) == ' ')
-               && (c & 0x80))
+               && (c & 0x80)
+               && p_em)
        {
            c &= 0x7f;
            modifiers |= MOD_MASK_ALT;
@@ -2494,6 +2495,12 @@
        return 0;
 
     /* Put the appropriate modifier in a string */
+    if (!p_em && modifiers & MOD_MASK_ALT)
+    {
+       modifiers &= ~MOD_MASK_ALT;
+       dst[dlen++] = ESC;
+    }
+
     if (modifiers != 0)
     {
        dst[dlen++] = K_SPECIAL;
@@ -2681,6 +2688,7 @@
 #ifdef FEAT_MBYTE
            && !enc_dbcs                /* avoid creating a lead byte */
 #endif
+           && p_em
            )
     {
        key |= 0x80;
diff -ur ../vim70-orig/src/option.c src/option.c
--- ../vim70-orig/src/option.c  2006-10-21 17:53:35 +0400
+++ src/option.c        2006-10-22 00:15:00 +0400
@@ -959,6 +959,9 @@
     {"edcompatible","ed",   P_BOOL|P_VI_DEF,
                            (char_u *)&p_ed, PV_NONE,
                            {(char_u *)FALSE, (char_u *)0L}},
+    {"eightbitmeta","em",   P_BOOL|P_VI_DEF,
+                           (char_u *)&p_em, PV_NONE,
+                           {(char_u *)TRUE, (char_u *)0L}},
     {"encoding",    "enc",  P_STRING|P_VI_DEF|P_RCLR,
 #ifdef FEAT_MBYTE
                            (char_u *)&p_enc, PV_NONE,
diff -ur ../vim70-orig/src/option.h src/option.h
--- ../vim70-orig/src/option.h  2006-10-21 17:53:35 +0400
+++ src/option.h        2006-10-21 20:41:27 +0400
@@ -421,6 +421,7 @@
 #define DY_LASTLINE            0x001
 #define DY_UHEX                        0x002
 EXTERN int     p_ed;           /* 'edcompatible' */
+EXTERN int     p_em;           /* 'eightbitmeta' */
 #ifdef FEAT_VERTSPLIT
 EXTERN char_u  *p_ead;         /* 'eadirection' */
 #endif
diff -ur ../vim70-orig/src/os_win32.c src/os_win32.c
--- ../vim70-orig/src/os_win32.c        2006-10-21 17:53:35 +0400
+++ src/os_win32.c      2006-10-22 00:08:53 +0400
@@ -1519,12 +1519,21 @@
 #ifdef FEAT_MBYTE
                        && !enc_dbcs
 #endif
+                       && p_em
                   )
                {
                    typeahead[typeaheadlen] |= 0x80;
                    modifiers &= ~MOD_MASK_ALT;
                }
 
+               if ( n == 1 && !p_em && modifiers & MOD_MASK_ALT)
+               {
+                   modifiers &= ~MOD_MASK_ALT;
+                   mch_memmove(typeahead + typeaheadlen + 1,
+                                                typeahead + typeaheadlen, n);
+                   typeahead[typeaheadlen++] = ESC;
+               }
+
                if (modifiers != 0)
                {
                    /* Prepend modifiers to the character. */

Attachment: signature.asc
Description: Digital signature

Reply via email to