vim: vim-7.2-langmapmb.patch

File vim-7.2-langmapmb.patch, 6.7 KB (added by Ag. Hatzimanikas, 13 years ago)
  • runtime/doc/options.txt

    Submitted By: Hatzimanikas Agathoklis (ag dot hatzim at gmail dot com)
    Date: 2008-08-25
    Initial Package Version: 7.0
    Origin: http://lostclus.linux.kiev.ua/Other_Works/Patches
    Upstream Status: In the TODO list.
    Description: Allows to set the langmap option in multibyte locales.
    Details: http://tech.groups.yahoo.com/group/vim-multibyte/message/2232?l=1
    
    diff -Naur vim72.orig/runtime/doc/options.txt vim72/runtime/doc/options.txt
    old new  
    41754175        be able to execute Normal mode commands.
    41764176        This is the opposite of the 'keymap' option, where characters are
    41774177        mapped in Insert mode.
    4178         This only works for 8-bit characters.  The value of 'langmap' may be
    4179         specified with multi-byte characters (e.g., UTF-8), but only the lower
    4180         8 bits of each character will be used.
    41814178
    41824179        Example (for Greek, in UTF-8):                          *greek*  >
    41834180            :set langmap=ΑA,ΒB,ΨC,ΔD,ΕE,ΦF,ΓG,ΗH,ΙI,ΞJ,ΚK,ΛL,ΜM,ΝN,ΟO,ΠP,QQ,ΡR,ΣS,ΤT,ΘU,ΩV,WW,ΧX,ΥY,ΖZ,αa,βb,ψc,δd,εe,φf,γg,ηh,ιi,ξj,κk,λl,μm,νn,οo,πp,qq,ρr,σs,τt,θu,ωv,ςw,χx,υy,ζz
  • runtime/doc/todo.txt

    diff -Naur vim72.orig/runtime/doc/todo.txt vim72/runtime/doc/todo.txt
    old new  
    19841984    Support CTRL-K _{mnemonic}_
    198519857   In "-- INSERT (lang) --" show the name of the keymap used instead of
    19861986    "lang". (Ilya Dogolazky)
    1987 -   Make 'langmap' accept multi-byte characters.
    1988         Patch from Konstantin Korikov, 2006 Oct 15.
    19891987-   Make 'breakat' accept multi-byte characters.  Problem: can't use a lookup
    19901988    table anymore (breakat_flags[]).
    19911989    Simplistic solution: when 'formatoptions' contains "m" also break a line
  • src/globals.h

    diff -Naur vim72.orig/src/globals.h vim72/src/globals.h
    old new  
    10671067#endif
    10681068
    10691069#ifdef FEAT_LANGMAP
    1070 EXTERN char_u   langmap_mapchar[256];   /* mapping for language keys */
     1070/* mapping for language keys */
     1071#ifdef FEAT_MBYTE
     1072/* With multi-byte support use growarray of mapping entries */
     1073typedef struct langmap_entry {
     1074    int from;
     1075    char_u to;
     1076} langmap_entry_T;
     1077
     1078EXTERN garray_T langmap_mapchar;
     1079#else
     1080/* Without multi-byte support use single mapping array */
     1081EXTERN char_u   langmap_mapchar[256];
     1082#endif
    10711083#endif
    10721084
    10731085#ifdef FEAT_WILDMENU
  • src/macros.h

    diff -Naur vim72.orig/src/macros.h vim72/src/macros.h
    old new  
    127127#ifdef FEAT_LANGMAP
    128128/*
    129129 * Adjust chars in a language according to 'langmap' option.
    130  * NOTE that there is NO overhead if 'langmap' is not set; but even
    131  * when set we only have to do 2 ifs and an array lookup.
     130 * NOTE that there is NO overhead if 'langmap' is not set.
    132131 * Don't apply 'langmap' if the character comes from the Stuff buffer.
    133132 * The do-while is just to ignore a ';' after the macro.
    134133 */
     134#ifdef FEAT_MBYTE
    135135# define LANGMAP_ADJUST(c, condition) do { \
    136         if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0 && (c) < 256) \
    137             c = langmap_mapchar[c]; \
     136        if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0) { \
     137            langmap_entry_T *e = (langmap_entry_T*)(langmap_mapchar.ga_data); \
     138            int a = 0, b = langmap_mapchar.ga_len; \
     139            while (a != b) { \
     140                int i = (a + b) / 2; \
     141                int d = e[i].from - (c); \
     142                if (d == 0) { \
     143                    c = e[i].to; \
     144                    break; \
     145                } \
     146                if (d < 0) a = i + 1; else b = i; \
     147            } \
     148        } \
    138149    } while (0)
     150#else
     151# define LANGMAP_ADJUST(c, condition) do { \
     152        if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0 && (c) < 256) \
     153            c = langmap_mapchar[c]; \
     154    } while (0)
     155#endif
    139156#endif
    140157
    141158/*
  • src/option.c

    diff -Naur vim72.orig/src/option.c vim72/src/option.c
    old new  
    1009810098 * other characters can be translated too).
    1009910099 */
    1010010100
    10101 /*
     10101/* #ifdef FEAT_MBYTE
     10102 * garray_T langmap_mapchar;
     10103 * langmap_mapchar.ga_data is array of langmap_entry_T.
     10104 * Normally maps wide characters to an <128 ascii char; used to
     10105 * "translate" native lang chars in normal mode or some cases of
     10106 * insert mode without having to tediously switch lang mode back&forth.
     10107 * #else
    1010210108 * char_u langmap_mapchar[256];
    1010310109 * Normally maps each of the 128 upper chars to an <128 ascii char; used to
    1010410110 * "translate" native lang chars in normal mode or some cases of
    1010510111 * insert mode without having to tediously switch lang mode back&forth.
     10112 * #endif
    1010610113 */
    1010710114
    1010810115    static void
    1010910116langmap_init()
    1011010117{
     10118#ifdef FEAT_MBYTE
     10119    ga_init2(&langmap_mapchar, sizeof(langmap_entry_T), 8);
     10120#else
    1011110121    int i;
    1011210122
    1011310123    for (i = 0; i < 256; i++)           /* we init with a-one-to one map */
    1011410124        langmap_mapchar[i] = i;
     10125#endif
     10126}
     10127
     10128#ifdef FEAT_MBYTE
     10129/*
     10130 * Search for a entry in langmap_mapchar for `from'.
     10131 * if found set entry `to' field to `to'. if not found
     10132 * insert new entry with `from' and `to' fields set to
     10133 * `from' and `to' respectively.
     10134 */
     10135    static void
     10136langmap_set_entry(from, to)
     10137    int from;
     10138    char_u to;
     10139{
     10140    langmap_entry_T *entries = (langmap_entry_T*)(langmap_mapchar.ga_data);
     10141    int a = 0, b = langmap_mapchar.ga_len;
     10142
     10143    while (a != b)
     10144    {
     10145        int i = (a + b) / 2;
     10146        int d = entries[i].from - from;
     10147        if (d == 0)
     10148        {
     10149            entries[i].to = to;
     10150            return;
     10151        }
     10152        if (d < 0) a = i + 1; else b = i;
     10153    }
     10154
     10155    if (ga_grow(&langmap_mapchar, 1) != OK) {
     10156        EMSG(_("EXXX: 'langmap_set_entry': Out of memory"));
     10157        return;
     10158    }
     10159
     10160    /* insert new entry at position a */
     10161    entries = (langmap_entry_T*)(langmap_mapchar.ga_data) + a;
     10162    mch_memmove(entries + 1, entries,
     10163            (langmap_mapchar.ga_len - a) * sizeof(langmap_entry_T));
     10164    ++langmap_mapchar.ga_len;
     10165    entries[0].from = from;
     10166    entries[0].to = to;
    1011510167}
     10168#endif
    1011610169
    1011710170/*
    1011810171 * Called when langmap option is set; the language map can be
     
    1012510178    char_u  *p2;
    1012610179    int     from, to;
    1012710180
     10181#ifdef FEAT_MBYTE
     10182    ga_clear(&langmap_mapchar);             /* clear the previous map first */
     10183#else
    1012810184    langmap_init();                         /* back to one-to-one map first */
     10185#endif
    1012910186
    1013010187    for (p = p_langmap; p[0] != NUL; )
    1013110188    {
     
    1016810225#else
    1016910226                to = p2[0];
    1017010227#endif
     10228                if (to < 0 || to >= 128)
     10229                    MSG_ATTR(_("WXXX: 'langmap': Mapping to non-ASCII character"),
     10230                            hl_attr(HLF_W));
    1017110231            }
    1017210232            if (to == NUL)
    1017310233            {
     
    1017510235                                                             transchar(from));
    1017610236                return;
    1017710237            }
     10238
     10239#ifdef FEAT_MBYTE
     10240            langmap_set_entry(from, to);
     10241#else
    1017810242            langmap_mapchar[from & 255] = to;
     10243#endif
    1017910244
    1018010245            /* Advance to next pair */
    1018110246            mb_ptr_adv(p);