4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: 'langmap' does not work for multi-byte characters.
12 Solution: Add a list of mapped multi-byte characters. (based on work by
13 Konstantin Korikov, Agathoklis Hatzimanikas)
14 Files: runtime/doc/options.txt, src/edit.c, src/getchar.c, src/macros.h,
15 src/normal.c, src/option.c, src/proto/option.pro, src/window.c
18 *** ../vim-7.2.108/runtime/doc/options.txt Fri Nov 28 10:59:57 2008
19 --- runtime/doc/options.txt Wed Feb 11 18:59:34 2009
22 be able to execute Normal mode commands.
23 This is the opposite of the 'keymap' option, where characters are
24 mapped in Insert mode.
25 - This only works for 8-bit characters. The value of 'langmap' may be
26 - specified with multi-byte characters (e.g., UTF-8), but only the lower
27 - 8 bits of each character will be used.
29 Example (for Greek, in UTF-8): *greek* >
30 :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
32 *** ../vim-7.2.108/src/edit.c Wed Feb 4 11:19:40 2009
33 --- src/edit.c Sat Feb 21 19:54:03 2009
38 regname = plain_vgetc();
40 LANGMAP_ADJUST(regname, TRUE);
42 if (regname == Ctrl_R || regname == Ctrl_O || regname == Ctrl_P)
44 /* Get a third key for literal register insertion */
48 add_to_showcmd_c(literally);
50 regname = plain_vgetc();
52 LANGMAP_ADJUST(regname, TRUE);
58 *** ../vim-7.2.108/src/macros.h Wed Aug 15 20:41:07 2007
59 --- src/macros.h Sat Feb 21 19:55:38 2009
64 * Adjust chars in a language according to 'langmap' option.
65 ! * NOTE that there is NO overhead if 'langmap' is not set; but even
66 ! * when set we only have to do 2 ifs and an array lookup.
67 * Don't apply 'langmap' if the character comes from the Stuff buffer.
68 * The do-while is just to ignore a ';' after the macro.
70 ! # define LANGMAP_ADJUST(c, condition) do { \
71 ! if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0 && (c) < 256) \
72 ! c = langmap_mapchar[c]; \
80 * Adjust chars in a language according to 'langmap' option.
81 ! * NOTE that there is no noticeable overhead if 'langmap' is not set.
82 ! * When set the overhead for characters < 256 is small.
83 * Don't apply 'langmap' if the character comes from the Stuff buffer.
84 * The do-while is just to ignore a ';' after the macro.
87 ! # define LANGMAP_ADJUST(c, condition) \
89 ! if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0) \
92 ! c = langmap_mapchar[c]; \
94 ! c = langmap_adjust_mb(c); \
98 + # define LANGMAP_ADJUST(c, condition) \
100 + if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0 && (c) < 256) \
101 + c = langmap_mapchar[c]; \
105 + # define LANGMAP_ADJUST(c, condition) /* nop */
109 *** ../vim-7.2.108/src/normal.c Wed Feb 4 11:45:28 2009
110 --- src/normal.c Sat Feb 21 19:55:17 2009
113 * Get the command character from the user.
117 - #ifdef FEAT_LANGMAP
118 LANGMAP_ADJUST(c, TRUE);
127 ++no_zero_mapping; /* don't map zero here */
129 - #ifdef FEAT_LANGMAP
130 LANGMAP_ADJUST(c, TRUE);
139 ++allow_keys; /* no mapping for nchar, but keys */
140 c = plain_vgetc(); /* get next character */
141 - #ifdef FEAT_LANGMAP
142 LANGMAP_ADJUST(c, TRUE);
146 #ifdef FEAT_CMDL_INFO
150 * "gr", "g'" and "g`".
152 ca.nchar = plain_vgetc();
153 - #ifdef FEAT_LANGMAP
154 LANGMAP_ADJUST(ca.nchar, TRUE);
156 #ifdef FEAT_CMDL_INFO
157 need_flushbuf |= add_to_showcmd(ca.nchar);
165 - #ifdef FEAT_LANGMAP
166 /* adjust chars > 127, except after "tTfFr" commands */
167 LANGMAP_ADJUST(*cp, !lang);
169 #ifdef FEAT_RIGHTLEFT
170 /* adjust Hebrew mapped char */
171 if (p_hkmap && lang && KeyTyped)
176 ++allow_keys; /* no mapping for nchar, but allow key codes */
177 nchar = plain_vgetc();
178 - #ifdef FEAT_LANGMAP
179 LANGMAP_ADJUST(nchar, TRUE);
183 #ifdef FEAT_CMDL_INFO
188 ++allow_keys; /* no mapping for nchar, but allow key codes */
189 nchar = plain_vgetc();
190 - #ifdef FEAT_LANGMAP
191 LANGMAP_ADJUST(nchar, TRUE);
195 #ifdef FEAT_CMDL_INFO
197 *** ../vim-7.2.108/src/option.c Wed Feb 11 22:47:32 2009
198 --- src/option.c Sat Feb 21 19:46:13 2009
204 ! * Any character has an equivalent character. This is used for keyboards that
205 ! * have a special language mode that sends characters above 128 (although
206 ! * other characters can be translated too).
210 ! * char_u langmap_mapchar[256];
211 ! * Normally maps each of the 128 upper chars to an <128 ascii char; used to
212 ! * "translate" native lang chars in normal mode or some cases of
213 ! * insert mode without having to tediously switch lang mode back&forth.
221 ! for (i = 0; i < 256; i++) /* we init with a-one-to one map */
222 ! langmap_mapchar[i] = i;
230 ! * Any character has an equivalent 'langmap' character. This is used for
231 ! * keyboards that have a special language mode that sends characters above
232 ! * 128 (although other characters can be translated too). The "to" field is a
233 ! * Vim command character. This avoids having to switch the keyboard back to
234 ! * ASCII mode when leaving Insert mode.
236 ! * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
238 ! * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
239 ! * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
244 ! * With multi-byte support use growarray for 'langmap' chars >= 256
252 + static garray_T langmap_mapga;
253 + static void langmap_set_entry __ARGS((int from, int to));
256 + * Search for an entry in "langmap_mapga" for "from". If found set the "to"
257 + * field. If not found insert a new entry at the appropriate location.
260 + langmap_set_entry(from, to)
264 + langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
266 + int b = langmap_mapga.ga_len;
268 + /* Do a binary search for an existing entry. */
271 + int i = (a + b) / 2;
272 + int d = entries[i].from - from;
276 + entries[i].to = to;
285 + if (ga_grow(&langmap_mapga, 1) != OK)
286 + return; /* out of memory */
288 + /* insert new entry at position "a" */
289 + entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
290 + mch_memmove(entries + 1, entries,
291 + (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
292 + ++langmap_mapga.ga_len;
293 + entries[0].from = from;
294 + entries[0].to = to;
298 ! * Apply 'langmap' to multi-byte character "c" and return the result.
301 + langmap_adjust_mb(c)
304 + langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
306 + int b = langmap_mapga.ga_len;
310 + int i = (a + b) / 2;
311 + int d = entries[i].from - c;
314 + return entries[i].to; /* found matching entry */
320 + return c; /* no entry found, return "c" unmodified */
329 ! for (i = 0; i < 256; i++)
330 ! langmap_mapchar[i] = i; /* we init with a one-to-one map */
332 ! ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
342 ! langmap_init(); /* back to one-to-one map first */
344 for (p = p_langmap; p[0] != NUL; )
351 ! ga_clear(&langmap_mapga); /* clear the previous map first */
353 ! langmap_init(); /* back to one-to-one map */
355 for (p = p_langmap; p[0] != NUL; )
362 ! langmap_mapchar[from & 255] = to;
364 /* Advance to next pair */
373 ! langmap_set_entry(from, to);
376 ! langmap_mapchar[from & 255] = to;
378 /* Advance to next pair */
380 *** ../vim-7.2.108/src/proto/option.pro Sat May 5 19:28:04 2007
381 --- src/proto/option.pro Wed Feb 11 21:21:05 2009
385 void set_context_in_set_cmd __ARGS((expand_T *xp, char_u *arg, int opt_flags));
386 int ExpandSettings __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file));
387 int ExpandOldSetting __ARGS((int *num_file, char_u ***file));
388 + int langmap_adjust_mb __ARGS((int c));
389 int has_format_option __ARGS((int x));
390 int shortmess __ARGS((int x));
391 void vimrc_found __ARGS((char_u *fname, char_u *envname));
392 *** ../vim-7.2.108/src/window.c Fri Nov 28 21:26:50 2008
393 --- src/window.c Sat Feb 21 19:55:25 2009
396 ++allow_keys; /* no mapping for xchar, but allow key codes */
398 xchar = plain_vgetc();
399 - #ifdef FEAT_LANGMAP
400 LANGMAP_ADJUST(xchar, TRUE);
404 #ifdef FEAT_CMDL_INFO
406 *** ../vim-7.2.108/src/version.c Wed Feb 11 22:47:32 2009
407 --- src/version.c Sat Feb 21 19:34:28 2009
411 { /* Add new patch number below this line */
417 hundred-and-one symptoms of being an internet addict:
418 99. The hum of a cooling fan and the click of keys is comforting to you.
420 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
421 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
422 \\\ download, build and distribute -- http://www.A-A-P.org ///
423 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///