summaryrefslogtreecommitdiffstats
path: root/vi/vim-7.2/7.2.109
blob: 8c3866cf97e2653787946dcbd9f3ca85d9a23587 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
To: vim-dev@vim.org
Subject: Patch 7.2.109
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 7.2.109
Problem:    'langmap' does not work for multi-byte characters.
Solution:   Add a list of mapped multi-byte characters. (based on work by
            Konstantin Korikov, Agathoklis Hatzimanikas)
Files:      runtime/doc/options.txt, src/edit.c, src/getchar.c, src/macros.h,
            src/normal.c, src/option.c, src/proto/option.pro, src/window.c
    

*** ../vim-7.2.108/runtime/doc/options.txt	Fri Nov 28 10:59:57 2008
--- runtime/doc/options.txt	Wed Feb 11 18:59:34 2009
***************
*** 4175,4183 ****
  	be able to execute Normal mode commands.
  	This is the opposite of the 'keymap' option, where characters are
  	mapped in Insert mode.
- 	This only works for 8-bit characters.  The value of 'langmap' may be
- 	specified with multi-byte characters (e.g., UTF-8), but only the lower
- 	8 bits of each character will be used.
  
  	Example (for Greek, in UTF-8):				*greek*  >
  	    :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
--- 4188,4193 ----
*** ../vim-7.2.108/src/edit.c	Wed Feb  4 11:19:40 2009
--- src/edit.c	Sat Feb 21 19:54:03 2009
***************
*** 7703,7711 ****
       */
      ++no_mapping;
      regname = plain_vgetc();
- #ifdef FEAT_LANGMAP
      LANGMAP_ADJUST(regname, TRUE);
- #endif
      if (regname == Ctrl_R || regname == Ctrl_O || regname == Ctrl_P)
      {
  	/* Get a third key for literal register insertion */
--- 7703,7709 ----
***************
*** 7714,7722 ****
  	add_to_showcmd_c(literally);
  #endif
  	regname = plain_vgetc();
- #ifdef FEAT_LANGMAP
  	LANGMAP_ADJUST(regname, TRUE);
- #endif
      }
      --no_mapping;
  
--- 7712,7718 ----
*** ../vim-7.2.108/src/macros.h	Wed Aug 15 20:41:07 2007
--- src/macros.h	Sat Feb 21 19:55:38 2009
***************
*** 127,141 ****
  #ifdef FEAT_LANGMAP
  /*
   * Adjust chars in a language according to 'langmap' option.
!  * NOTE that there is NO overhead if 'langmap' is not set; but even
!  * when set we only have to do 2 ifs and an array lookup.
   * Don't apply 'langmap' if the character comes from the Stuff buffer.
   * The do-while is just to ignore a ';' after the macro.
   */
! # define LANGMAP_ADJUST(c, condition) do { \
! 	if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0 && (c) < 256) \
! 	    c = langmap_mapchar[c]; \
      } while (0)
  #endif
  
  /*
--- 127,157 ----
  #ifdef FEAT_LANGMAP
  /*
   * Adjust chars in a language according to 'langmap' option.
!  * NOTE that there is no noticeable overhead if 'langmap' is not set.
!  * When set the overhead for characters < 256 is small.
   * Don't apply 'langmap' if the character comes from the Stuff buffer.
   * The do-while is just to ignore a ';' after the macro.
   */
! # ifdef FEAT_MBYTE
! #  define LANGMAP_ADJUST(c, condition) \
!     do { \
!         if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0) \
! 	{ \
! 	    if ((c) < 256) \
! 		c = langmap_mapchar[c]; \
! 	    else \
! 		c = langmap_adjust_mb(c); \
! 	} \
      } while (0)
+ # else
+ #  define LANGMAP_ADJUST(c, condition) \
+     do { \
+         if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0 && (c) < 256) \
+             c = langmap_mapchar[c]; \
+     } while (0)
+ # endif
+ #else
+ # define LANGMAP_ADJUST(c, condition) /* nop */
  #endif
  
  /*
*** ../vim-7.2.108/src/normal.c	Wed Feb  4 11:45:28 2009
--- src/normal.c	Sat Feb 21 19:55:17 2009
***************
*** 651,660 ****
       * Get the command character from the user.
       */
      c = safe_vgetc();
- 
- #ifdef FEAT_LANGMAP
      LANGMAP_ADJUST(c, TRUE);
- #endif
  
  #ifdef FEAT_VISUAL
      /*
--- 651,657 ----
***************
*** 744,752 ****
  	    }
  	    ++no_zero_mapping;		/* don't map zero here */
  	    c = plain_vgetc();
- #ifdef FEAT_LANGMAP
  	    LANGMAP_ADJUST(c, TRUE);
- #endif
  	    --no_zero_mapping;
  	    if (ctrl_w)
  	    {
--- 741,747 ----
***************
*** 769,777 ****
  	    ++no_mapping;
  	    ++allow_keys;		/* no mapping for nchar, but keys */
  	    c = plain_vgetc();		/* get next character */
- #ifdef FEAT_LANGMAP
  	    LANGMAP_ADJUST(c, TRUE);
- #endif
  	    --no_mapping;
  	    --allow_keys;
  #ifdef FEAT_CMDL_INFO
--- 764,770 ----
***************
*** 959,967 ****
  	     * "gr", "g'" and "g`".
  	     */
  	    ca.nchar = plain_vgetc();
- #ifdef FEAT_LANGMAP
  	    LANGMAP_ADJUST(ca.nchar, TRUE);
- #endif
  #ifdef FEAT_CMDL_INFO
  	    need_flushbuf |= add_to_showcmd(ca.nchar);
  #endif
--- 952,958 ----
***************
*** 1062,1071 ****
  		}
  #endif
  
- #ifdef FEAT_LANGMAP
  		/* adjust chars > 127, except after "tTfFr" commands */
  		LANGMAP_ADJUST(*cp, !lang);
- #endif
  #ifdef FEAT_RIGHTLEFT
  		/* adjust Hebrew mapped char */
  		if (p_hkmap && lang && KeyTyped)
--- 1053,1060 ----
***************
*** 4630,4638 ****
  	    ++no_mapping;
  	    ++allow_keys;   /* no mapping for nchar, but allow key codes */
  	    nchar = plain_vgetc();
- #ifdef FEAT_LANGMAP
  	    LANGMAP_ADJUST(nchar, TRUE);
- #endif
  	    --no_mapping;
  	    --allow_keys;
  #ifdef FEAT_CMDL_INFO
--- 4619,4625 ----
***************
*** 4988,4996 ****
  		++no_mapping;
  		++allow_keys;   /* no mapping for nchar, but allow key codes */
  		nchar = plain_vgetc();
- #ifdef FEAT_LANGMAP
  		LANGMAP_ADJUST(nchar, TRUE);
- #endif
  		--no_mapping;
  		--allow_keys;
  #ifdef FEAT_CMDL_INFO
--- 4975,4981 ----
*** ../vim-7.2.108/src/option.c	Wed Feb 11 22:47:32 2009
--- src/option.c	Sat Feb 21 19:46:13 2009
***************
*** 10153,10177 ****
  
  #ifdef FEAT_LANGMAP
  /*
!  * Any character has an equivalent character.  This is used for keyboards that
!  * have a special language mode that sends characters above 128 (although
!  * other characters can be translated too).
   */
  
  /*
!  * char_u langmap_mapchar[256];
!  * Normally maps each of the 128 upper chars to an <128 ascii char; used to
!  * "translate" native lang chars in normal mode or some cases of
!  * insert mode without having to tediously switch lang mode back&forth.
   */
  
      static void
  langmap_init()
  {
      int i;
  
!     for (i = 0; i < 256; i++)		/* we init with a-one-to one map */
! 	langmap_mapchar[i] = i;
  }
  
  /*
--- 10153,10262 ----
  
  #ifdef FEAT_LANGMAP
  /*
!  * Any character has an equivalent 'langmap' character.  This is used for
!  * keyboards that have a special language mode that sends characters above
!  * 128 (although other characters can be translated too).  The "to" field is a
!  * Vim command character.  This avoids having to switch the keyboard back to
!  * ASCII mode when leaving Insert mode.
!  *
!  * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
!  * commands.
!  * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
!  * langmap_entry_T.  This does the same as langmap_mapchar[] for characters >=
!  * 256.
!  */
! # ifdef FEAT_MBYTE
! /*
!  * With multi-byte support use growarray for 'langmap' chars >= 256
   */
+ typedef struct
+ {
+     int	    from;
+     int     to;
+ } langmap_entry_T;
+ 
+ static garray_T langmap_mapga;
+ static void langmap_set_entry __ARGS((int from, int to));
+ 
+ /*
+  * Search for an entry in "langmap_mapga" for "from".  If found set the "to"
+  * field.  If not found insert a new entry at the appropriate location.
+  */
+     static void
+ langmap_set_entry(from, to)
+     int    from;
+     int    to;
+ {
+     langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
+     int             a = 0;
+     int             b = langmap_mapga.ga_len;
+ 
+     /* Do a binary search for an existing entry. */
+     while (a != b)
+     {
+ 	int i = (a + b) / 2;
+ 	int d = entries[i].from - from;
+ 
+ 	if (d == 0)
+ 	{
+ 	    entries[i].to = to;
+ 	    return;
+ 	}
+ 	if (d < 0)
+ 	    a = i + 1;
+ 	else
+ 	    b = i;
+     }
+ 
+     if (ga_grow(&langmap_mapga, 1) != OK)
+ 	return;  /* out of memory */
+ 
+     /* insert new entry at position "a" */
+     entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
+     mch_memmove(entries + 1, entries,
+ 			(langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
+     ++langmap_mapga.ga_len;
+     entries[0].from = from;
+     entries[0].to = to;
+ }
  
  /*
!  * Apply 'langmap' to multi-byte character "c" and return the result.
   */
+     int
+ langmap_adjust_mb(c)
+     int c;
+ {
+     langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
+     int a = 0;
+     int b = langmap_mapga.ga_len;
+ 
+     while (a != b)
+     {
+ 	int i = (a + b) / 2;
+ 	int d = entries[i].from - c;
+ 
+ 	if (d == 0)
+ 	    return entries[i].to;  /* found matching entry */
+ 	if (d < 0)
+ 	    a = i + 1;
+ 	else
+ 	    b = i;
+     }
+     return c;  /* no entry found, return "c" unmodified */
+ }
+ # endif
  
      static void
  langmap_init()
  {
      int i;
  
!     for (i = 0; i < 256; i++)
! 	langmap_mapchar[i] = i;	 /* we init with a one-to-one map */
! # ifdef FEAT_MBYTE
!     ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
! # endif
  }
  
  /*
***************
*** 10185,10191 ****
      char_u  *p2;
      int	    from, to;
  
!     langmap_init();			    /* back to one-to-one map first */
  
      for (p = p_langmap; p[0] != NUL; )
      {
--- 10270,10279 ----
      char_u  *p2;
      int	    from, to;
  
! #ifdef FEAT_MBYTE
!     ga_clear(&langmap_mapga);		    /* clear the previous map first */
! #endif
!     langmap_init();			    /* back to one-to-one map */
  
      for (p = p_langmap; p[0] != NUL; )
      {
***************
*** 10235,10241 ****
  							     transchar(from));
  		return;
  	    }
! 	    langmap_mapchar[from & 255] = to;
  
  	    /* Advance to next pair */
  	    mb_ptr_adv(p);
--- 10323,10335 ----
  							     transchar(from));
  		return;
  	    }
! 
! #ifdef FEAT_MBYTE
! 	    if (from >= 256)
! 		langmap_set_entry(from, to);
! 	    else
! #endif
! 		langmap_mapchar[from & 255] = to;
  
  	    /* Advance to next pair */
  	    mb_ptr_adv(p);
*** ../vim-7.2.108/src/proto/option.pro	Sat May  5 19:28:04 2007
--- src/proto/option.pro	Wed Feb 11 21:21:05 2009
***************
*** 44,49 ****
--- 44,50 ----
  void set_context_in_set_cmd __ARGS((expand_T *xp, char_u *arg, int opt_flags));
  int ExpandSettings __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file));
  int ExpandOldSetting __ARGS((int *num_file, char_u ***file));
+ int langmap_adjust_mb __ARGS((int c));
  int has_format_option __ARGS((int x));
  int shortmess __ARGS((int x));
  void vimrc_found __ARGS((char_u *fname, char_u *envname));
*** ../vim-7.2.108/src/window.c	Fri Nov 28 21:26:50 2008
--- src/window.c	Sat Feb 21 19:55:25 2009
***************
*** 594,602 ****
  		++allow_keys;   /* no mapping for xchar, but allow key codes */
  		if (xchar == NUL)
  		    xchar = plain_vgetc();
- #ifdef FEAT_LANGMAP
  		LANGMAP_ADJUST(xchar, TRUE);
- #endif
  		--no_mapping;
  		--allow_keys;
  #ifdef FEAT_CMDL_INFO
--- 594,600 ----
*** ../vim-7.2.108/src/version.c	Wed Feb 11 22:47:32 2009
--- src/version.c	Sat Feb 21 19:34:28 2009
***************
*** 678,679 ****
--- 678,681 ----
  {   /* Add new patch number below this line */
+ /**/
+     109,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
99. The hum of a cooling fan and the click of keys is comforting to you.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///