1
0
forked from aniani/vim

patch 7.4.1981

Problem:    No testing for Farsi code.
Solution:   Add a minimal test.  Clean up Farsi code.
This commit is contained in:
Bram Moolenaar 2016-07-02 18:25:34 +02:00
parent 361c8f0e51
commit ee2615af64
8 changed files with 278 additions and 291 deletions

View File

@ -2022,6 +2022,7 @@ test_arglist \
test_expand_dllpath \ test_expand_dllpath \
test_expr \ test_expr \
test_expr_utf8 \ test_expr_utf8 \
test_farsi \
test_feedkeys \ test_feedkeys \
test_file_perm \ test_file_perm \
test_fnamemodify \ test_fnamemodify \

View File

@ -571,7 +571,7 @@ transchar(int c)
(c >= ' ' && c <= '~') (c >= ' ' && c <= '~')
#endif #endif
#ifdef FEAT_FKMAP #ifdef FEAT_FKMAP
|| F_ischar(c) || (p_altkeymap && F_ischar(c))
#endif #endif
)) || (c < 256 && vim_isprintc_strict(c))) )) || (c < 256 && vim_isprintc_strict(c)))
{ {

View File

@ -35,7 +35,7 @@ static int toF_ending(int c);
static void lrswapbuf(char_u *buf, int len); static void lrswapbuf(char_u *buf, int len);
/* /*
** Convert the given Farsi character into a _X or _X_ type * Convert the given Farsi character into a _X or _X_ type
*/ */
static int static int
toF_Xor_X_(int c) toF_Xor_X_(int c)
@ -44,61 +44,35 @@ toF_Xor_X_(int c)
switch (c) switch (c)
{ {
case BE: case BE: return _BE;
return _BE; case PE: return _PE;
case PE: case TE: return _TE;
return _PE; case SE: return _SE;
case TE: case JIM: return _JIM;
return _TE; case CHE: return _CHE;
case SE: case HE_J: return _HE_J;
return _SE; case XE: return _XE;
case JIM: case SIN: return _SIN;
return _JIM; case SHIN: return _SHIN;
case CHE: case SAD: return _SAD;
return _CHE; case ZAD: return _ZAD;
case HE_J: case AYN: return _AYN;
return _HE_J; case AYN_: return _AYN_;
case XE: case GHAYN: return _GHAYN;
return _XE; case GHAYN_: return _GHAYN_;
case SIN: case FE: return _FE;
return _SIN; case GHAF: return _GHAF;
case SHIN: case KAF: return _KAF;
return _SHIN; case GAF: return _GAF;
case SAD: case LAM: return _LAM;
return _SAD; case MIM: return _MIM;
case ZAD: case NOON: return _NOON;
return _ZAD;
case AYN:
return _AYN;
case AYN_:
return _AYN_;
case GHAYN:
return _GHAYN;
case GHAYN_:
return _GHAYN_;
case FE:
return _FE;
case GHAF:
return _GHAF;
case KAF:
return _KAF;
case GAF:
return _GAF;
case LAM:
return _LAM;
case MIM:
return _MIM;
case NOON:
return _NOON;
case YE: case YE:
case YE_: case YE_: return _YE;
return _YE;
case YEE: case YEE:
case YEE_: case YEE_: return _YEE;
return _YEE;
case IE: case IE:
case IE_: case IE_: return _IE;
return _IE;
case F_HE: case F_HE:
tempc = _HE; tempc = _HE;
@ -128,86 +102,58 @@ toF_Xor_X_(int c)
} }
/* /*
** Convert the given Farsi character into Farsi capital character . * Convert the given Farsi character into Farsi capital character.
*/ */
int static int
toF_TyA(int c ) toF_TyA(int c)
{ {
switch (c) switch (c)
{ {
case ALEF_: case ALEF_: return ALEF;
return ALEF; case ALEF_U_H_: return ALEF_U_H;
case ALEF_U_H_: case _BE: return BE;
return ALEF_U_H; case _PE: return PE;
case _BE: case _TE: return TE;
return BE; case _SE: return SE;
case _PE: case _JIM: return JIM;
return PE; case _CHE: return CHE;
case _TE: case _HE_J: return HE_J;
return TE; case _XE: return XE;
case _SE: case _SIN: return SIN;
return SE; case _SHIN: return SHIN;
case _JIM: case _SAD: return SAD;
return JIM; case _ZAD: return ZAD;
case _CHE:
return CHE;
case _HE_J:
return HE_J;
case _XE:
return XE;
case _SIN:
return SIN;
case _SHIN:
return SHIN;
case _SAD:
return SAD;
case _ZAD:
return ZAD;
case _AYN: case _AYN:
case AYN_: case AYN_:
case _AYN_: case _AYN_: return AYN;
return AYN;
case _GHAYN: case _GHAYN:
case GHAYN_: case GHAYN_:
case _GHAYN_: case _GHAYN_: return GHAYN;
return GHAYN; case _FE: return FE;
case _FE: case _GHAF: return GHAF;
return FE; /* I am not sure what it is !!! case _KAF_H: */
case _GHAF: case _KAF: return KAF;
return GHAF; case _GAF: return GAF;
/* I am not sure what it is !!! case _KAF_H: */ case _LAM: return LAM;
case _KAF: case _MIM: return MIM;
return KAF; case _NOON: return NOON;
case _GAF:
return GAF;
case _LAM:
return LAM;
case _MIM:
return MIM;
case _NOON:
return NOON;
case _YE: case _YE:
case YE_: case YE_: return YE;
return YE;
case _YEE: case _YEE:
case YEE_: case YEE_: return YEE;
return YEE; case TEE_: return TEE;
case TEE_:
return TEE;
case _IE: case _IE:
case IE_: case IE_: return IE;
return IE;
case _HE: case _HE:
case _HE_: case _HE_: return F_HE;
return F_HE;
} }
return c; return c;
} }
/* /*
** Is the character under the cursor+offset in the given buffer a join type. * Is the character under the cursor+offset in the given buffer a join type.
** That is a character that is combined with the others. * That is a character that is combined with the others.
** Note: the offset is used only for command line buffer. * Note: the offset is used only for command line buffer.
*/ */
static int static int
F_is_TyB_TyC_TyD(int src, int offset) F_is_TyB_TyC_TyD(int src, int offset)
@ -258,7 +204,7 @@ F_is_TyB_TyC_TyD(int src, int offset)
} }
/* /*
** Is the Farsi character one of the terminating only type. * Is the Farsi character one of the terminating only type.
*/ */
static int static int
F_is_TyE(int c) F_is_TyE(int c)
@ -281,7 +227,7 @@ F_is_TyE(int c)
} }
/* /*
** Is the Farsi character one of the none leading type. * Is the Farsi character one of the none leading type.
*/ */
static int static int
F_is_TyC_TyD(int c) F_is_TyC_TyD(int c)
@ -305,7 +251,7 @@ F_is_TyC_TyD(int c)
} }
/* /*
** Convert a none leading Farsi char into a leading type. * Convert a none leading Farsi char into a leading type.
*/ */
static int static int
toF_TyB(int c) toF_TyB(int c)
@ -313,7 +259,7 @@ toF_TyB(int c)
switch (c) switch (c)
{ {
case ALEF_: return ALEF; case ALEF_: return ALEF;
case ALEF_U_H_: return ALEF_U_H; case ALEF_U_H_: return ALEF_U_H;
case _AYN_: return _AYN; case _AYN_: return _AYN;
case AYN_: return AYN; /* exception - there are many of them */ case AYN_: return AYN; /* exception - there are many of them */
case _GHAYN_: return _GHAYN; case _GHAYN_: return _GHAYN;
@ -328,7 +274,7 @@ toF_TyB(int c)
} }
/* /*
** Overwrite the current redo and cursor characters + left adjust * Overwrite the current redo and cursor characters + left adjust.
*/ */
static void static void
put_curr_and_l_to_X(int c) put_curr_and_l_to_X(int c)
@ -373,7 +319,7 @@ put_and_redo(int c)
} }
/* /*
** Change the char. under the cursor to a X_ or X type * Change the char. under the cursor to a X_ or X type
*/ */
static void static void
chg_c_toX_orX(void) chg_c_toX_orX(void)
@ -497,7 +443,7 @@ chg_c_toX_orX(void)
} }
/* /*
** Change the char. under the cursor to a _X_ or X_ type * Change the char. under the cursor to a _X_ or X_ type
*/ */
static void static void
@ -549,7 +495,7 @@ chg_c_to_X_orX_(void)
} }
/* /*
** Change the char. under the cursor to a _X_ or _X type * Change the char. under the cursor to a _X_ or _X type
*/ */
static void static void
chg_c_to_X_or_X (void) chg_c_to_X_or_X (void)
@ -580,10 +526,10 @@ chg_c_to_X_or_X (void)
} }
/* /*
** Change the character left to the cursor to a _X_ or X_ type * Change the character left to the cursor to a _X_ or X_ type
*/ */
static void static void
chg_l_to_X_orX_ (void) chg_l_to_X_orX_(void)
{ {
int tempc; int tempc;
@ -648,7 +594,7 @@ chg_l_to_X_orX_ (void)
} }
/* /*
** Change the character left to the cursor to a X or _X type * Change the character left to the cursor to a X or _X type
*/ */
static void static void
@ -717,7 +663,7 @@ chg_l_toXor_X (void)
} }
/* /*
** Change the character right to the cursor to a _X or _X_ type * Change the character right to the cursor to a _X or _X_ type
*/ */
static void static void
@ -742,7 +688,7 @@ chg_r_to_Xor_X_(void)
} }
/* /*
** Map Farsi keyboard when in fkmap mode. * Map Farsi keyboard when in fkmap mode.
*/ */
int int
@ -899,8 +845,8 @@ fkmap(int c)
if (p_ri && c == NL && curwin->w_cursor.col) if (p_ri && c == NL && curwin->w_cursor.col)
{ {
/* /*
** If the char before the cursor is _X_ or X_ do not change * If the char before the cursor is _X_ or X_ do not change
** the one under the cursor with X type. * the one under the cursor with X type.
*/ */
dec_cursor(); dec_cursor();
@ -914,8 +860,7 @@ fkmap(int c)
inc_cursor(); inc_cursor();
} }
if (!p_ri) if (!p_ri && !curwin->w_cursor.col)
if (!curwin->w_cursor.col)
{ {
switch (c) switch (c)
{ {
@ -1154,43 +1099,42 @@ fkmap(int c)
case 'a': case 'a':
tempc = _SHIN; tempc = _SHIN;
break; break;
case 'A': case 'A':
tempc = WAW_H; tempc = WAW_H;
break; break;
case 'b': case 'b':
tempc = ZAL; tempc = ZAL;
break; break;
case 'c': case 'c':
tempc = ZE; tempc = ZE;
break; break;
case 'C': case 'C':
tempc = JE; tempc = JE;
break; break;
case 'd': case 'd':
tempc = _YE; tempc = _YE;
break; break;
case 'D': case 'D':
tempc = _YEE; tempc = _YEE;
break; break;
case 'e': case 'e':
tempc = _SE; tempc = _SE;
break; break;
case 'f': case 'f':
tempc = _BE; tempc = _BE;
break; break;
case 'g': case 'g':
tempc = _LAM; tempc = _LAM;
break; break;
case 'G': case 'G':
if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{ {
if (gchar_cursor() == _LAM) if (gchar_cursor() == _LAM)
chg_c_toX_orX (); chg_c_toX_orX ();
else else if (p_ri)
if (p_ri) chg_c_to_X_or_X ();
chg_c_to_X_or_X ();
} }
if (!p_ri) if (!p_ri)
@ -1204,16 +1148,15 @@ fkmap(int c)
{ {
chg_c_toX_orX (); chg_c_toX_orX ();
chg_l_toXor_X (); chg_l_toXor_X ();
tempc = ALEF_U_H; tempc = ALEF_U_H;
}
else if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
{
tempc = ALEF_U_H_;
chg_l_toXor_X ();
} }
else else
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) tempc = ALEF_U_H;
{
tempc = ALEF_U_H_;
chg_l_toXor_X ();
}
else
tempc = ALEF_U_H;
if (!p_ri) if (!p_ri)
inc_cursor(); inc_cursor();
@ -1249,11 +1192,11 @@ fkmap(int c)
{ {
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
{ {
tempc = ALEF_; tempc = ALEF_;
chg_l_toXor_X (); chg_l_toXor_X ();
} }
else else
tempc = ALEF; tempc = ALEF;
} }
if (!p_ri) if (!p_ri)
@ -1261,8 +1204,8 @@ fkmap(int c)
return tempc; return tempc;
case 'i': case 'i':
if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{ {
if (!p_ri && !F_is_TyE(tempc)) if (!p_ri && !F_is_TyE(tempc))
chg_c_to_X_orX_ (); chg_c_to_X_orX_ ();
if (p_ri) if (p_ri)
@ -1277,9 +1220,9 @@ fkmap(int c)
dec_cursor(); dec_cursor();
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
tempc = _HE_; tempc = _HE_;
else else
tempc = _HE; tempc = _HE;
if (!p_ri) if (!p_ri)
inc_cursor(); inc_cursor();
@ -1289,7 +1232,7 @@ fkmap(int c)
break; break;
case 'J': case 'J':
if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{ {
if (p_ri) if (p_ri)
chg_c_to_X_or_X (); chg_c_to_X_or_X ();
@ -1304,11 +1247,11 @@ fkmap(int c)
if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))
{ {
tempc = TEE_; tempc = TEE_;
chg_l_toXor_X (); chg_l_toXor_X ();
} }
else else
tempc = TEE; tempc = TEE;
if (!p_ri) if (!p_ri)
inc_cursor(); inc_cursor();
@ -1385,7 +1328,7 @@ fkmap(int c)
break; break;
case 'y': case 'y':
if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{ {
if (!p_ri && !F_is_TyE(tempc)) if (!p_ri && !F_is_TyE(tempc))
chg_c_to_X_orX_ (); chg_c_to_X_orX_ ();
if (p_ri) if (p_ri)
@ -1434,7 +1377,7 @@ fkmap(int c)
if ((F_isalpha(tempc) || F_isdigit(tempc))) if ((F_isalpha(tempc) || F_isdigit(tempc)))
{ {
if (!curwin->w_cursor.col && STRLEN(ml_get_curline())) if (!curwin->w_cursor.col && STRLEN(ml_get_curline()))
{ {
if (!p_ri && !F_is_TyE(tempc)) if (!p_ri && !F_is_TyE(tempc))
chg_c_to_X_orX_ (); chg_c_to_X_orX_ ();
if (p_ri) if (p_ri)
@ -1461,7 +1404,7 @@ fkmap(int c)
} }
/* /*
** Convert a none leading Farsi char into a leading type. * Convert a none leading Farsi char into a leading type.
*/ */
static int static int
toF_leading(int c) toF_leading(int c)
@ -1515,7 +1458,7 @@ toF_leading(int c)
} }
/* /*
** Convert a given Farsi char into right joining type. * Convert a given Farsi char into right joining type.
*/ */
static int static int
toF_Rjoin(int c) toF_Rjoin(int c)
@ -1571,7 +1514,7 @@ toF_Rjoin(int c)
} }
/* /*
** Can a given Farsi character join via its left edj. * Can a given Farsi character join via its left edj.
*/ */
static int static int
canF_Ljoin(int c) canF_Ljoin(int c)
@ -1645,7 +1588,7 @@ canF_Ljoin(int c)
} }
/* /*
** Can a given Farsi character join via its right edj. * Can a given Farsi character join via its right edj.
*/ */
static int static int
canF_Rjoin(int c) canF_Rjoin(int c)
@ -1673,7 +1616,7 @@ canF_Rjoin(int c)
} }
/* /*
** is a given Farsi character a terminating type. * is a given Farsi character a terminating type.
*/ */
static int static int
F_isterm(int c) F_isterm(int c)
@ -1700,86 +1643,54 @@ F_isterm(int c)
} }
/* /*
** Convert the given Farsi character into a ending type . * Convert the given Farsi character into a ending type .
*/ */
static int static int
toF_ending(int c) toF_ending(int c)
{ {
switch (c) switch (c)
{ {
case _BE: case _BE: return BE;
return BE; case _PE: return PE;
case _PE: case _TE: return TE;
return PE; case _SE: return SE;
case _TE: case _JIM: return JIM;
return TE; case _CHE: return CHE;
case _SE: case _HE_J: return HE_J;
return SE; case _XE: return XE;
case _JIM: case _SIN: return SIN;
return JIM; case _SHIN: return SHIN;
case _CHE: case _SAD: return SAD;
return CHE; case _ZAD: return ZAD;
case _HE_J: case _AYN: return AYN;
return HE_J; case _AYN_: return AYN_;
case _XE: case _GHAYN: return GHAYN;
return XE; case _GHAYN_: return GHAYN_;
case _SIN: case _FE: return FE;
return SIN; case _GHAF: return GHAF;
case _SHIN:
return SHIN;
case _SAD:
return SAD;
case _ZAD:
return ZAD;
case _AYN:
return AYN;
case _AYN_:
return AYN_;
case _GHAYN:
return GHAYN;
case _GHAYN_:
return GHAYN_;
case _FE:
return FE;
case _GHAF:
return GHAF;
case _KAF_H: case _KAF_H:
case _KAF: case _KAF: return KAF;
return KAF; case _GAF: return GAF;
case _GAF: case _LAM: return LAM;
return GAF; case _MIM: return MIM;
case _LAM: case _NOON: return NOON;
return LAM; case _YE: return YE_;
case _MIM: case YE_: return YE;
return MIM; case _YEE: return YEE_;
case _NOON: case YEE_: return YEE;
return NOON; case TEE: return TEE_;
case _YE: case _IE: return IE_;
return YE_; case IE_: return IE;
case YE_:
return YE;
case _YEE:
return YEE_;
case YEE_:
return YEE;
case TEE:
return TEE_;
case _IE:
return IE_;
case IE_:
return IE;
case _HE: case _HE:
case _HE_: case _HE_: return F_HE;
return F_HE;
} }
return c; return c;
} }
/* /*
** Convert the Farsi 3342 standard into Farsi VIM. * Convert the Farsi 3342 standard into Farsi VIM.
*/ */
void static void
conv_to_pvim(void) conv_to_pvim(void)
{ {
char_u *ptr; char_u *ptr;
@ -1791,7 +1702,7 @@ conv_to_pvim(void)
llen = (int)STRLEN(ptr); llen = (int)STRLEN(ptr);
for ( i = 0; i < llen-1; i++) for (i = 0; i < llen-1; i++)
{ {
if (canF_Ljoin(ptr[i]) && canF_Rjoin(ptr[i+1])) if (canF_Ljoin(ptr[i]) && canF_Rjoin(ptr[i+1]))
{ {
@ -1817,8 +1728,8 @@ conv_to_pvim(void)
* Following lines contains Farsi encoded character. * Following lines contains Farsi encoded character.
*/ */
do_cmdline_cmd((char_u *)"%s/\202\231/\232/g"); do_cmdline_cmd((char_u *)"%s/\202\231/\232/ge");
do_cmdline_cmd((char_u *)"%s/\201\231/\370\334/g"); do_cmdline_cmd((char_u *)"%s/\201\231/\370\334/ge");
/* Assume the screen has been messed up: clear it and redraw. */ /* Assume the screen has been messed up: clear it and redraw. */
redraw_later(CLEAR); redraw_later(CLEAR);
@ -1828,7 +1739,7 @@ conv_to_pvim(void)
/* /*
* Convert the Farsi VIM into Farsi 3342 standard. * Convert the Farsi VIM into Farsi 3342 standard.
*/ */
void static void
conv_to_pstd(void) conv_to_pstd(void)
{ {
char_u *ptr; char_u *ptr;
@ -1837,20 +1748,15 @@ conv_to_pstd(void)
/* /*
* Following line contains Farsi encoded character. * Following line contains Farsi encoded character.
*/ */
do_cmdline_cmd((char_u *)"%s/\232/\202\231/ge");
do_cmdline_cmd((char_u *)"%s/\232/\202\231/g");
for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum)
{ {
ptr = ml_get((linenr_T)lnum); ptr = ml_get((linenr_T)lnum);
llen = (int)STRLEN(ptr); llen = (int)STRLEN(ptr);
for ( i = 0; i < llen; i++) for (i = 0; i < llen; i++)
{
ptr[i] = toF_TyA(ptr[i]); ptr[i] = toF_TyA(ptr[i]);
}
} }
/* Assume the screen has been messed up: clear it and redraw. */ /* Assume the screen has been messed up: clear it and redraw. */
@ -2148,7 +2054,7 @@ cmdl_fkmap(int c)
case 'f': return _BE; case 'f': return _BE;
case 'g': return _LAM; case 'g': return _LAM;
case 'G': case 'G':
if (cmd_gchar(AT_CURSOR) == _LAM ) if (cmd_gchar(AT_CURSOR) == _LAM)
{ {
cmd_pchar(LAM, AT_CURSOR); cmd_pchar(LAM, AT_CURSOR);
return ALEF_U_H; return ALEF_U_H;
@ -2159,7 +2065,7 @@ cmdl_fkmap(int c)
else else
return ALEF_U_H; return ALEF_U_H;
case 'h': case 'h':
if (cmd_gchar(AT_CURSOR) == _LAM ) if (cmd_gchar(AT_CURSOR) == _LAM)
{ {
cmd_pchar(LA, AT_CURSOR); cmd_pchar(LA, AT_CURSOR);
redrawcmdline(); redrawcmdline();
@ -2215,9 +2121,9 @@ cmdl_fkmap(int c)
case ',': return WAW; case ',': return WAW;
case '[': return _JIM; case '[': return _JIM;
case ']': return _CHE; case ']': return _CHE;
} }
return c; return c;
} }
/* /*
@ -2226,7 +2132,7 @@ cmdl_fkmap(int c)
int int
F_isalpha(int c) F_isalpha(int c)
{ {
return (( c >= TEE_ && c <= _YE) return ((c >= TEE_ && c <= _YE)
|| (c >= ALEF_A && c <= YE) || (c >= ALEF_A && c <= YE)
|| (c >= _IE && c <= YE_)); || (c >= _IE && c <= YE_));
} }
@ -2246,45 +2152,40 @@ F_isdigit(int c)
int int
F_ischar(int c) F_ischar(int c)
{ {
return (c >= TEE_ && c <= YE_); return (c >= TEE_ && c <= YE_);
} }
void void
farsi_fkey( farsi_f8(cmdarg_T *cap UNUSED)
cmdarg_T *cap)
{ {
int c = cap->cmdchar; if (p_altkeymap)
if (c == K_F8)
{ {
if (p_altkeymap) if (curwin->w_farsi & W_R_L)
{ {
if (curwin->w_farsi & W_R_L) p_fkmap = 0;
{ do_cmdline_cmd((char_u *)"set norl");
p_fkmap = 0; MSG("");
do_cmdline_cmd((char_u *)"set norl");
MSG("");
}
else
{
p_fkmap = 1;
do_cmdline_cmd((char_u *)"set rl");
MSG("");
}
curwin->w_farsi = curwin->w_farsi ^ W_R_L;
} }
} else
if (c == K_F9)
{
if (p_altkeymap && curwin->w_p_rl)
{ {
curwin->w_farsi = curwin->w_farsi ^ W_CONV; p_fkmap = 1;
if (curwin->w_farsi & W_CONV) do_cmdline_cmd((char_u *)"set rl");
conv_to_pvim(); MSG("");
else
conv_to_pstd();
} }
curwin->w_farsi = curwin->w_farsi ^ W_R_L;
}
}
void
farsi_f9(cmdarg_T *cap UNUSED)
{
if (p_altkeymap && curwin->w_p_rl)
{
curwin->w_farsi = curwin->w_farsi ^ W_CONV;
if (curwin->w_farsi & W_CONV)
conv_to_pvim();
else
conv_to_pstd();
} }
} }

View File

@ -414,8 +414,8 @@ static const struct nv_cmd
{K_TABMENU, nv_tabmenu, 0, 0}, {K_TABMENU, nv_tabmenu, 0, 0},
#endif #endif
#ifdef FEAT_FKMAP #ifdef FEAT_FKMAP
{K_F8, farsi_fkey, 0, 0}, {K_F8, farsi_f8, 0, 0},
{K_F9, farsi_fkey, 0, 0}, {K_F9, farsi_f9, 0, 0},
#endif #endif
#ifdef FEAT_NETBEANS_INTG #ifdef FEAT_NETBEANS_INTG
{K_F21, nv_nbcmd, NV_NCH_ALW, 0}, {K_F21, nv_nbcmd, NV_NCH_ALW, 0},

View File

@ -10,10 +10,7 @@ void time_msg(char *mesg, void *tv_start);
void server_to_input_buf(char_u *str); void server_to_input_buf(char_u *str);
char_u *eval_client_expr_to_string(char_u *expr); char_u *eval_client_expr_to_string(char_u *expr);
char_u *serverConvert(char_u *client_enc, char_u *data, char_u **tofree); char_u *serverConvert(char_u *client_enc, char_u *data, char_u **tofree);
int toF_TyA(int c);
int fkmap(int c); int fkmap(int c);
void conv_to_pvim(void);
void conv_to_pstd(void);
char_u *lrswap(char_u *ibuf); char_u *lrswap(char_u *ibuf);
char_u *lrFswap(char_u *cmdbuf, int len); char_u *lrFswap(char_u *cmdbuf, int len);
char_u *lrF_sub(char_u *ibuf); char_u *lrF_sub(char_u *ibuf);
@ -21,6 +18,7 @@ int cmdl_fkmap(int c);
int F_isalpha(int c); int F_isalpha(int c);
int F_isdigit(int c); int F_isdigit(int c);
int F_ischar(int c); int F_ischar(int c);
void farsi_fkey(cmdarg_T *cap); void farsi_f8(cmdarg_T *cap);
void farsi_f9(cmdarg_T *cap);
int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1, int next_c); int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1, int next_c);
/* vim: set ft=c : */ /* vim: set ft=c : */

View File

@ -168,6 +168,7 @@ NEW_TESTS = test_arglist.res \
test_cdo.res \ test_cdo.res \
test_channel.res \ test_channel.res \
test_cmdline.res \ test_cmdline.res \
test_farsi.res \
test_hardcopy.res \ test_hardcopy.res \
test_history.res \ test_history.res \
test_increment.res \ test_increment.res \

View File

@ -0,0 +1,84 @@
" Simplistic testing of Farsi mode.
if !has('farsi')
finish
endif
" Farsi uses a single byte encoding.
set enc=latin1
func Test_farsi_toggle()
new
set altkeymap
call assert_equal(0, &fkmap)
call assert_equal(0, &rl)
call feedkeys("\<F8>", 'x')
call assert_equal(1, &fkmap)
call assert_equal(1, &rl)
call feedkeys("\<F8>", 'x')
call assert_equal(0, &fkmap)
call assert_equal(0, &rl)
set rl
" conversion from Farsi 3342 to Farsi VIM.
call setline(1, join(map(range(0x80, 0xff), 'nr2char(v:val)'), ''))
call feedkeys("\<F9>", 'x')
let exp = [0xfc, 0xf8, 0xc1, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
\ 0xc8, 0xc9, 0xca, 0xd0, 0xd1, 0xd2, 0xd3, 0xd6,
\ 0xd6, 0xd6, 0xd7, 0xd7, 0xd7, 0xd8, 0xd9, 0xda,
\ 0xdb, 0xdc, 0xdc, 0xc1, 0xdd, 0xde, 0xe0, 0xe0,
\ 0xe1, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6,
\ 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae,
\ 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
\ 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe,
\ 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6,
\ 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce,
\ 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6,
\ 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde,
\ 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6,
\ 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xfb, 0xfb, 0xfe,
\ 0xfe, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6,
\ 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xe1,
\ ]
call assert_equal(join(map(exp, 'nr2char(v:val)'), ''), getline(1))
" conversion from Farsi VIM to Farsi 3342.
call setline(1, join(map(range(0x80, 0xff), 'nr2char(v:val)'), ''))
call feedkeys("\<F9>", 'x')
let exp = [0xfc, 0xf8, 0xc1, 0x83, 0x84, 0x85, 0x86, 0x87,
\ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x90,
\ 0x90, 0x90, 0x92, 0x93, 0x93, 0x95, 0x96, 0x97,
\ 0x98, 0xdc, 0x9a, 0x9b, 0x9c, 0x9e, 0x9e, 0xff,
\ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
\ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
\ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
\ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
\ 0xc0, 0xc1, 0xc2, 0x83, 0x84, 0x85, 0x86, 0x87,
\ 0x88, 0x89, 0x8a, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
\ 0x8b, 0x8c, 0x8d, 0x8e, 0xd4, 0xd5, 0x90, 0x93,
\ 0x95, 0x96, 0x97, 0x98, 0x99, 0x9b, 0x9c, 0xdf,
\ 0x9d, 0xff, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
\ 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xec, 0xee, 0xef,
\ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
\ 0xf8, 0xf9, 0xfa, 0xec, 0x80, 0xfd, 0xee, 0xff,
\ ]
call assert_equal(join(map(exp, 'nr2char(v:val)'), ''), getline(1))
bwipe!
endfunc
func Test_farsi_map()
new
set altkeymap
set rl
" RHS of mapping is reversed.
imap xyz abc
call feedkeys("axyz\<Esc>", 'tx')
call assert_equal('cba', getline(1))
set norl
iunmap xyz
set noaltkeymap
bwipe!
endfunc

View File

@ -758,6 +758,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1981,
/**/ /**/
1980, 1980,
/**/ /**/