/// Overwrite the current redo and cursor characters + left adjust /// /// @param c static void put_curr_and_l_to_X(char_u c) { int tempc; if (curwin->w_p_rl && p_ri) { return; } if ((curwin->w_cursor.col < (colnr_T)STRLEN(get_cursor_line_ptr()))) { if (!p_ri || curwin->w_cursor.col) { if (p_ri) { dec_cursor(); } else { inc_cursor(); } if (F_is_TyC_TyD((tempc = gchar_cursor()))) { pchar_cursor(toF_TyB(tempc)); AppendCharToRedobuff(K_BS); AppendCharToRedobuff(tempc); } if (p_ri) { inc_cursor(); } else { dec_cursor(); } } } put_and_redo(c); }
// When extra == 0: Return true if the cursor is before or on the first // non-blank in the line. // When extra == 1: Return true if the cursor is before the first non-blank in // the line. int inindent(int extra) { char_u *ptr; colnr_T col; for (col = 0, ptr = get_cursor_line_ptr(); vim_iswhite(*ptr); ++col) { ptr++; } if (col >= curwin->w_cursor.col + extra) { return true; } else { return false; } }
/// Change the character left to the cursor to a X or _X type static void chg_l_toXor_X(void) { char_u tempc; if ((curwin->w_cursor.col != 0) && (curwin->w_cursor.col + 1 == (colnr_T)STRLEN(get_cursor_line_ptr()))) { return; } if (!curwin->w_cursor.col && p_ri) { return; } if (p_ri) { dec_cursor(); } else { inc_cursor(); } switch (gchar_cursor()) { case ALEF_ : tempc = ALEF ; break; case ALEF_U_H_ : tempc = ALEF_U_H ; break; case _AYN_ : tempc = _AYN ; break; case AYN_ : tempc = AYN ; break; case _GHAYN_ : tempc = _GHAYN ; break; case GHAYN_ : tempc = GHAYN ; break; case _HE_ : tempc = _HE ; break; case YE_ : tempc = YE ; break; case IE_ : tempc = IE ; break; case TEE_ : tempc = TEE ; break; case YEE_ : tempc = YEE ; break; default : tempc = 0 ; } if (tempc) { put_and_redo(tempc); } if (p_ri) { inc_cursor(); } else { dec_cursor(); } }
/// Change the char. under the cursor to a _X_ or _X type static void chg_c_to_X_or_X(void) { int tempc; tempc = gchar_cursor(); if (curwin->w_cursor.col + 1 < (colnr_T)STRLEN(get_cursor_line_ptr())) { inc_cursor(); if ((tempc == F_HE) && (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR))) { tempc = _HE_; dec_cursor(); put_and_redo((char_u)tempc); return; } dec_cursor(); } if ((tempc = toF_Xor_X_(tempc)) != 0) { put_and_redo((char_u)tempc); } }
// Set the indent of the current line. // Leaves the cursor on the first non-blank in the line. // Caller must take care of undo. // "flags": // SIN_CHANGED: call changed_bytes() if the line was changed. // SIN_INSERT: insert the indent in front of the line. // SIN_UNDO: save line for undo before changing it. // @param size measured in spaces // Returns true if the line was changed. int set_indent(int size, int flags) { char_u *p; char_u *newline; char_u *oldline; char_u *s; int todo; int ind_len; // Measured in characters. int line_len; int doit = false; int ind_done = 0; // Measured in spaces. int tab_pad; int retval = false; // Number of initial whitespace chars when 'et' and 'pi' are both set. int orig_char_len = -1; // First check if there is anything to do and compute the number of // characters needed for the indent. todo = size; ind_len = 0; p = oldline = get_cursor_line_ptr(); // Calculate the buffer size for the new indent, and check to see if it // isn't already set. // If 'expandtab' isn't set: use TABs; if both 'expandtab' and // 'preserveindent' are set count the number of characters at the // beginning of the line to be copied. if (!curbuf->b_p_et || (!(flags & SIN_INSERT) && curbuf->b_p_pi)) { // If 'preserveindent' is set then reuse as much as possible of // the existing indent structure for the new indent. if (!(flags & SIN_INSERT) && curbuf->b_p_pi) { ind_done = 0; // Count as many characters as we can use. while (todo > 0 && vim_iswhite(*p)) { if (*p == TAB) { tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); // Stop if this tab will overshoot the target. if (todo < tab_pad) { break; } todo -= tab_pad; ind_len++; ind_done += tab_pad; } else { todo--; ind_len++; ind_done++; } p++; } // Set initial number of whitespace chars to copy if we are // preserving indent but expandtab is set. if (curbuf->b_p_et) { orig_char_len = ind_len; } // Fill to next tabstop with a tab, if possible. tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); if ((todo >= tab_pad) && (orig_char_len == -1)) { doit = true; todo -= tab_pad; ind_len++; // ind_done += tab_pad; } } // Count tabs required for indent. while (todo >= (int)curbuf->b_p_ts) { if (*p != TAB) { doit = true; } else { p++; } todo -= (int)curbuf->b_p_ts; ind_len++; // ind_done += (int)curbuf->b_p_ts; } } // Count spaces required for indent. while (todo > 0) { if (*p != ' ') { doit = true; } else { p++; } todo--; ind_len++; // ind_done++; } // Return if the indent is OK already. if (!doit && !vim_iswhite(*p) && !(flags & SIN_INSERT)) { return false; } // Allocate memory for the new line. if (flags & SIN_INSERT) { p = oldline; } else { p = skipwhite(p); } line_len = (int)STRLEN(p) + 1; // If 'preserveindent' and 'expandtab' are both set keep the original // characters and allocate accordingly. We will fill the rest with spaces // after the if (!curbuf->b_p_et) below. if (orig_char_len != -1) { newline = xmalloc(orig_char_len + size - ind_done + line_len); todo = size - ind_done; // Set total length of indent in characters, which may have been // undercounted until now. ind_len = orig_char_len + todo; p = oldline; s = newline; while (orig_char_len > 0) { *s++ = *p++; orig_char_len--; } // Skip over any additional white space (useful when newindent is less // than old). while (vim_iswhite(*p)) { p++; } } else { todo = size; newline = xmalloc(ind_len + line_len); s = newline; } // Put the characters in the new line. // if 'expandtab' isn't set: use TABs if (!curbuf->b_p_et) { // If 'preserveindent' is set then reuse as much as possible of // the existing indent structure for the new indent. if (!(flags & SIN_INSERT) && curbuf->b_p_pi) { p = oldline; ind_done = 0; while (todo > 0 && vim_iswhite(*p)) { if (*p == TAB) { tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); // Stop if this tab will overshoot the target. if (todo < tab_pad) { break; } todo -= tab_pad; ind_done += tab_pad; } else { todo--; ind_done++; } *s++ = *p++; } // Fill to next tabstop with a tab, if possible. tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); if (todo >= tab_pad) { *s++ = TAB; todo -= tab_pad; } p = skipwhite(p); } while (todo >= (int)curbuf->b_p_ts) { *s++ = TAB; todo -= (int)curbuf->b_p_ts; } } while (todo > 0) { *s++ = ' '; todo--; } memmove(s, p, (size_t)line_len); // Replace the line (unless undo fails). if (!(flags & SIN_UNDO) || (u_savesub(curwin->w_cursor.lnum) == OK)) { ml_replace(curwin->w_cursor.lnum, newline, false); if (flags & SIN_CHANGED) { changed_bytes(curwin->w_cursor.lnum, 0); } // Correct saved cursor position if it is in this line. if (saved_cursor.lnum == curwin->w_cursor.lnum) { if (saved_cursor.col >= (colnr_T)(p - oldline)) { // Cursor was after the indent, adjust for the number of // bytes added/removed. saved_cursor.col += ind_len - (colnr_T)(p - oldline); } else if (saved_cursor.col >= (colnr_T)(s - newline)) { // Cursor was in the indent, and is now after it, put it back // at the start of the indent (replacing spaces with TAB). saved_cursor.col = (colnr_T)(s - newline); } } retval = true; } else { free(newline); } curwin->w_cursor.col = ind_len; return retval; }
// TODO(unknown): // Findmatch() should be adapted for lisp, also to make showmatch // work correctly: now (v5.3) it seems all C/C++ oriented: // - it does not recognize the #\( and #\) notations as character literals // - it doesn't know about comments starting with a semicolon // - it incorrectly interprets '(' as a character literal // All this messes up get_lisp_indent in some rare cases. // Update from Sergey Khorev: // I tried to fix the first two issues. int get_lisp_indent(void) { pos_T *pos, realpos, paren; int amount; char_u *that; colnr_T col; colnr_T firsttry; int parencount; int quotecount; int vi_lisp; // Set vi_lisp to use the vi-compatible method. vi_lisp = (vim_strchr(p_cpo, CPO_LISP) != NULL); realpos = curwin->w_cursor; curwin->w_cursor.col = 0; if ((pos = findmatch(NULL, '(')) == NULL) { pos = findmatch(NULL, '['); } else { paren = *pos; pos = findmatch(NULL, '['); if ((pos == NULL) || ltp(pos, &paren)) { pos = &paren; } } if (pos != NULL) { // Extra trick: Take the indent of the first previous non-white // line that is at the same () level. amount = -1; parencount = 0; while (--curwin->w_cursor.lnum >= pos->lnum) { if (linewhite(curwin->w_cursor.lnum)) { continue; } for (that = get_cursor_line_ptr(); *that != NUL; ++that) { if (*that == ';') { while (*(that + 1) != NUL) { that++; } continue; } if (*that == '\\') { if (*(that + 1) != NUL) { that++; } continue; } if ((*that == '"') && (*(that + 1) != NUL)) { while (*++that && *that != '"') { // Skipping escaped characters in the string if (*that == '\\') { if (*++that == NUL) { break; } if (that[1] == NUL) { that++; break; } } } } if ((*that == '(') || (*that == '[')) { parencount++; } else if ((*that == ')') || (*that == ']')) { parencount--; } } if (parencount == 0) { amount = get_indent(); break; } } if (amount == -1) { curwin->w_cursor.lnum = pos->lnum; curwin->w_cursor.col = pos->col; col = pos->col; that = get_cursor_line_ptr(); if (vi_lisp && (get_indent() == 0)) { amount = 2; } else { char_u *line = that; amount = 0; while (*that && col) { amount += lbr_chartabsize_adv(line, &that, (colnr_T)amount); col--; } // Some keywords require "body" indenting rules (the // non-standard-lisp ones are Scheme special forms): // (let ((a 1)) instead (let ((a 1)) // (...)) of (...)) if (!vi_lisp && ((*that == '(') || (*that == '[')) && lisp_match(that + 1)) { amount += 2; } else { that++; amount++; firsttry = amount; while (vim_iswhite(*that)) { amount += lbr_chartabsize(line, that, (colnr_T)amount); that++; } if (*that && (*that != ';')) { // Not a comment line. // Test *that != '(' to accommodate first let/do // argument if it is more than one line. if (!vi_lisp && (*that != '(') && (*that != '[')) { firsttry++; } parencount = 0; quotecount = 0; if (vi_lisp || ((*that != '"') && (*that != '\'') && (*that != '#') && ((*that < '0') || (*that > '9')))) { while (*that && (!vim_iswhite(*that) || quotecount || parencount) && (!((*that == '(' || *that == '[') && !quotecount && !parencount && vi_lisp))) { if (*that == '"') { quotecount = !quotecount; } if (((*that == '(') || (*that == '[')) && !quotecount) { parencount++; } if (((*that == ')') || (*that == ']')) && !quotecount) { parencount--; } if ((*that == '\\') && (*(that + 1) != NUL)) { amount += lbr_chartabsize_adv(line, &that, (colnr_T)amount); } amount += lbr_chartabsize_adv(line, &that, (colnr_T)amount); } } while (vim_iswhite(*that)) { amount += lbr_chartabsize(line, that, (colnr_T)amount); that++; } if (!*that || (*that == ';')) { amount = firsttry; } } } } } } else { amount = 0; // No matching '(' or '[' found, use zero indent. } curwin->w_cursor = realpos; return amount; }
// Copy the indent from ptr to the current line (and fill to size). // Leaves the cursor on the first non-blank in the line. // @return true if the line was changed. int copy_indent(int size, char_u *src) { char_u *p = NULL; char_u *line = NULL; char_u *s; int todo; int ind_len; int line_len = 0; int tab_pad; int ind_done; int round; // Round 1: compute the number of characters needed for the indent // Round 2: copy the characters. for (round = 1; round <= 2; ++round) { todo = size; ind_len = 0; ind_done = 0; s = src; // Count/copy the usable portion of the source line. while (todo > 0 && vim_iswhite(*s)) { if (*s == TAB) { tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); // Stop if this tab will overshoot the target. if (todo < tab_pad) { break; } todo -= tab_pad; ind_done += tab_pad; } else { todo--; ind_done++; } ind_len++; if (p != NULL) { *p++ = *s; } s++; } // Fill to next tabstop with a tab, if possible. tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); if ((todo >= tab_pad) && !curbuf->b_p_et) { todo -= tab_pad; ind_len++; if (p != NULL) { *p++ = TAB; } } // Add tabs required for indent. while (todo >= (int)curbuf->b_p_ts && !curbuf->b_p_et) { todo -= (int)curbuf->b_p_ts; ind_len++; if (p != NULL) { *p++ = TAB; } } // Count/add spaces required for indent. while (todo > 0) { todo--; ind_len++; if (p != NULL) { *p++ = ' '; } } if (p == NULL) { // Allocate memory for the result: the copied indent, new indent // and the rest of the line. line_len = (int)STRLEN(get_cursor_line_ptr()) + 1; line = xmalloc(ind_len + line_len); p = line; } } // Append the original line memmove(p, get_cursor_line_ptr(), (size_t)line_len); // Replace the line ml_replace(curwin->w_cursor.lnum, line, false); // Put the cursor after the indent. curwin->w_cursor.col = ind_len; return true; }
// Count the size (in window cells) of the indent in the current line. int get_indent(void) { return get_indent_str(get_cursor_line_ptr(), (int)curbuf->b_p_ts, false); }
/// Convert the given Farsi character into a _X or _X_ type /// /// @param c The character to convert. /// /// @return Farsi character converted to a _X or _X_ type. static char_u toF_Xor_X_(int c) { char_u tempc; switch (c) { case BE : tempc = _BE ; break; case PE : tempc = _PE ; break; case TE : tempc = _TE ; break; case SE : tempc = _SE ; break; case JIM : tempc = _JIM ; break; case CHE : tempc = _CHE ; break; case HE_J : tempc = _HE_J ; break; case XE : tempc = _XE ; break; case SIN : tempc = _SIN ; break; case SHIN : tempc = _SHIN ; break; case SAD : tempc = _SAD ; break; case ZAD : tempc = _ZAD ; break; case AYN : tempc = _AYN ; break; case AYN_ : tempc = _AYN_ ; break; case GHAYN : tempc = _GHAYN ; break; case GHAYN_ : tempc = _GHAYN_ ; break; case FE : tempc = _FE ; break; case GHAF : tempc = _GHAF ; break; case KAF : tempc = _KAF ; break; case GAF : tempc = _GAF ; break; case LAM : tempc = _LAM ; break; case MIM : tempc = _MIM ; break; case NOON : tempc = _NOON ; break; case YE : case YE_ : tempc = _YE ; break; case YEE : case YEE_ : tempc = _YEE ; break; case IE : case IE_ : tempc = _IE ; break; case F_HE : tempc = _HE; if (p_ri && (curwin->w_cursor.col + 1 < (colnr_T)STRLEN(get_cursor_line_ptr()))) { inc_cursor(); if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = _HE_; } dec_cursor(); } if (!p_ri && STRLEN(get_cursor_line_ptr())) { dec_cursor(); if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = _HE_; } inc_cursor(); } break; default: tempc = 0; } return tempc; }
/// Map Farsi keyboard when in fkmap mode. int fkmap(int c) { int tempc; static int revins; if (IS_SPECIAL(c)) { return c; } if (ascii_isdigit(c) || ((c == '.' || c == '+' || c == '-' || c == '^' || c == '%' || c == '#' || c == '=') && revins)) { if (!revins) { if (curwin->w_cursor.col) { if (!p_ri) { dec_cursor(); } chg_c_toX_orX(); chg_l_toXor_X(); if (!p_ri) { inc_cursor(); } } } arrow_used = TRUE; (void)stop_arrow(); if (!curwin->w_p_rl && revins) { inc_cursor(); } revins++; p_ri = 1; } else { if (revins) { arrow_used = TRUE; (void)stop_arrow(); revins = 0; if (curwin->w_p_rl) { while ((F_isdigit(gchar_cursor()) || (gchar_cursor() == F_PERIOD || gchar_cursor() == F_PLUS || gchar_cursor() == F_MINUS || gchar_cursor() == F_MUL || gchar_cursor() == F_DIVIDE || gchar_cursor() == F_PERCENT || gchar_cursor() == F_EQUALS)) && gchar_cursor() != NUL) { curwin->w_cursor.col++; } } else { if (curwin->w_cursor.col) { while ((F_isdigit(gchar_cursor()) || (gchar_cursor() == F_PERIOD || gchar_cursor() == F_PLUS || gchar_cursor() == F_MINUS || gchar_cursor() == F_MUL || gchar_cursor() == F_DIVIDE || gchar_cursor() == F_PERCENT || gchar_cursor() == F_EQUALS)) && --curwin->w_cursor.col) { } } if (!F_isdigit(gchar_cursor())) { ++curwin->w_cursor.col; } } } } if (!revins) { if (curwin->w_p_rl) { p_ri = 0; } if (!curwin->w_p_rl) { p_ri = 1; } } if ((c < 0x100) && (isalpha(c) || (c == '&') || (c == '^') || (c == ';') || (c == '\'') || (c == ',') || (c == '[') || (c == ']') || (c == '{') || (c == '}'))) { chg_r_to_Xor_X_(); } tempc = 0; switch (c) { case '`': case ' ': case '.': case '!': case '"': case '$': case '%': case '^': case '&': case '/': case '(': case ')': case '=': case '\\': case '?': case '+': case '-': case '_': case '*': case ':': case '#': case '~': case '@': case '<': case '>': case '{': case '}': case '|': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'B': case 'E': case 'F': case 'H': case 'I': case 'K': case 'L': case 'M': case 'O': case 'P': case 'Q': case 'R': case 'T': case 'U': case 'W': case 'Y': case NL: case TAB: if (p_ri && (c == NL) && curwin->w_cursor.col) { // If the char before the cursor is _X_ or X_ do not change // the one under the cursor with X type. dec_cursor(); if (F_isalpha(gchar_cursor())) { inc_cursor(); return NL; } inc_cursor(); } if (!p_ri) { if (!curwin->w_cursor.col) { switch (c) { case '0' : return FARSI_0 ; case '1' : return FARSI_1 ; case '2' : return FARSI_2 ; case '3' : return FARSI_3 ; case '4' : return FARSI_4 ; case '5' : return FARSI_5 ; case '6' : return FARSI_6 ; case '7' : return FARSI_7 ; case '8' : return FARSI_8 ; case '9' : return FARSI_9 ; case 'B' : return F_PSP ; case 'E' : return JAZR_N ; case 'F' : return ALEF_D_H ; case 'H' : return ALEF_A ; case 'I' : return TASH ; case 'K' : return F_LQUOT ; case 'L' : return F_RQUOT ; case 'M' : return HAMZE ; case 'O' : return '[' ; case 'P' : return ']' ; case 'Q' : return OO ; case 'R' : return MAD_N ; case 'T' : return OW ; case 'U' : return MAD ; case 'W' : return OW_OW ; case 'Y' : return JAZR ; case '`' : return F_PCN ; case '!' : return F_EXCL ; case '@' : return F_COMMA ; case '#' : return F_DIVIDE ; case '$' : return F_CURRENCY ; case '%' : return F_PERCENT ; case '^' : return F_MUL ; case '&' : return F_BCOMMA ; case '*' : return F_STAR ; case '(' : return F_LPARENT ; case ')' : return F_RPARENT ; case '-' : return F_MINUS ; case '_' : return F_UNDERLINE ; case '=' : return F_EQUALS ; case '+' : return F_PLUS ; case '\\' : return F_BSLASH ; case '|' : return F_PIPE ; case ':' : return F_DCOLON ; case '"' : return F_SEMICOLON ; case '.' : return F_PERIOD ; case '/' : return F_SLASH ; case '<' : return F_LESS ; case '>' : return F_GREATER ; case '?' : return F_QUESTION ; case ' ' : return F_BLANK ; } break; } } if (!p_ri) { dec_cursor(); } switch ((tempc = gchar_cursor())) { case _BE: case _PE: case _TE: case _SE: case _JIM: case _CHE: case _HE_J: case _XE: case _SIN: case _SHIN: case _SAD: case _ZAD: case _FE: case _GHAF: case _KAF: case _KAF_H: case _GAF: case _LAM: case _MIM: case _NOON: case _HE: case _HE_: case _TA: case _ZA: put_curr_and_l_to_X(toF_TyA((char_u)tempc)); break; case _AYN: case _AYN_: if (!p_ri) { if (!curwin->w_cursor.col) { put_curr_and_l_to_X(AYN); break; } } if (p_ri) { inc_cursor(); } else { dec_cursor(); } if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = AYN_; } else { tempc = AYN; } if (p_ri) { dec_cursor(); } else { inc_cursor(); } put_curr_and_l_to_X((char_u)tempc); break; case _GHAYN: case _GHAYN_: if (!p_ri) { if (!curwin->w_cursor.col) { put_curr_and_l_to_X(GHAYN); break; } } if (p_ri) { inc_cursor(); } else { dec_cursor(); } if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = GHAYN_; } else { tempc = GHAYN; } if (p_ri) { dec_cursor(); } else { inc_cursor(); } put_curr_and_l_to_X((char_u)tempc); break; case _YE: case _IE: case _YEE: if (!p_ri) { if (!curwin->w_cursor.col) { put_curr_and_l_to_X( (tempc == _YE ? YE : tempc == _IE ? IE : YEE)); break; } } if (p_ri) { inc_cursor(); } else { dec_cursor(); } if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = (tempc == _YE ? YE_ : tempc == _IE ? IE_ : YEE_); } else { tempc = (tempc == _YE ? YE : tempc == _IE ? IE : YEE); } if (p_ri) { dec_cursor(); } else { inc_cursor(); } put_curr_and_l_to_X((char_u)tempc); break; } if (!p_ri) { inc_cursor(); } tempc = 0; switch (c) { case '0' : return FARSI_0 ; case '1' : return FARSI_1 ; case '2' : return FARSI_2 ; case '3' : return FARSI_3 ; case '4' : return FARSI_4 ; case '5' : return FARSI_5 ; case '6' : return FARSI_6 ; case '7' : return FARSI_7 ; case '8' : return FARSI_8 ; case '9' : return FARSI_9 ; case 'B' : return F_PSP ; case 'E' : return JAZR_N ; case 'F' : return ALEF_D_H ; case 'H' : return ALEF_A ; case 'I' : return TASH ; case 'K' : return F_LQUOT ; case 'L' : return F_RQUOT ; case 'M' : return HAMZE ; case 'O' : return '[' ; case 'P' : return ']' ; case 'Q' : return OO ; case 'R' : return MAD_N ; case 'T' : return OW ; case 'U' : return MAD ; case 'W' : return OW_OW ; case 'Y' : return JAZR ; case '`' : return F_PCN ; case '!' : return F_EXCL ; case '@' : return F_COMMA ; case '#' : return F_DIVIDE ; case '$' : return F_CURRENCY ; case '%' : return F_PERCENT ; case '^' : return F_MUL ; case '&' : return F_BCOMMA ; case '*' : return F_STAR ; case '(' : return F_LPARENT ; case ')' : return F_RPARENT ; case '-' : return F_MINUS ; case '_' : return F_UNDERLINE ; case '=' : return F_EQUALS ; case '+' : return F_PLUS ; case '\\' : return F_BSLASH ; case '|' : return F_PIPE ; case ':' : return F_DCOLON ; case '"' : return F_SEMICOLON ; case '.' : return F_PERIOD ; case '/' : return F_SLASH ; case '<' : return F_LESS ; case '>' : return F_GREATER ; case '?' : return F_QUESTION ; case ' ' : return F_BLANK ; } break; case 'a' : tempc = _SHIN ; break; case 'A' : tempc = WAW_H ; break; case 'b' : tempc = ZAL ; break; case 'c' : tempc = ZE ; break; case 'C' : tempc = JE ; break; case 'd' : tempc = _YE ; break; case 'D' : tempc = _YEE ; break; case 'e' : tempc = _SE ; break; case 'f' : tempc = _BE ; break; case 'g' : tempc = _LAM ; break; case 'G': if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { if (gchar_cursor() == _LAM) { chg_c_toX_orX(); } else if (p_ri) { chg_c_to_X_or_X(); } } if (!p_ri) { if (!curwin->w_cursor.col) { return ALEF_U_H; } dec_cursor(); } if (gchar_cursor() == _LAM) { chg_c_toX_orX(); chg_l_toXor_X(); tempc = ALEF_U_H; } else if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = ALEF_U_H_; chg_l_toXor_X(); } else { tempc = ALEF_U_H; } if (!p_ri) { inc_cursor(); } return tempc; case 'h': if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { if (p_ri) { chg_c_to_X_or_X(); } } if (!p_ri) { if (!curwin->w_cursor.col) { return ALEF; } dec_cursor(); } if (gchar_cursor() == _LAM) { chg_l_toXor_X(); del_char(FALSE); AppendCharToRedobuff(K_BS); if (!p_ri) { dec_cursor(); } tempc = LA; } else { if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = ALEF_; chg_l_toXor_X(); } else { tempc = ALEF; } } if (!p_ri) { inc_cursor(); } return tempc; case 'i': if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { if (!p_ri && !F_is_TyE(tempc)) { chg_c_to_X_orX_(); } if (p_ri) { chg_c_to_X_or_X(); } } if (!p_ri && !curwin->w_cursor.col) { return _HE; } if (!p_ri) { dec_cursor(); } if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = _HE_; } else { tempc = _HE; } if (!p_ri) { inc_cursor(); } break; case 'j': tempc = _TE; break; case 'J': if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { if (p_ri) { chg_c_to_X_or_X(); } } if (!p_ri) { if (!curwin->w_cursor.col) { return TEE; } dec_cursor(); } if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = TEE_; chg_l_toXor_X(); } else { tempc = TEE; } if (!p_ri) { inc_cursor(); } return tempc; case 'k' : tempc = _NOON ; break; case 'l' : tempc = _MIM ; break; case 'm' : tempc = _PE ; break; case 'n' : case 'N' : tempc = DAL ; break; case 'o' : tempc = _XE ; break; case 'p' : tempc = _HE_J ; break; case 'q' : tempc = _ZAD ; break; case 'r' : tempc = _GHAF ; break; case 's' : tempc = _SIN ; break; case 'S' : tempc = _IE ; break; case 't' : tempc = _FE ; break; case 'u': if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { if (!p_ri && !F_is_TyE(tempc)) { chg_c_to_X_orX_(); } if (p_ri) { chg_c_to_X_or_X(); } } if (!p_ri && !curwin->w_cursor.col) { return _AYN; } if (!p_ri) { dec_cursor(); } if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = _AYN_; } else { tempc = _AYN; } if (!p_ri) { inc_cursor(); } break; case 'v' : case 'V' : tempc = RE ; break; case 'w' : tempc = _SAD ; break; case 'x' : case 'X' : tempc = _TA ; break; case 'y': if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { if (!p_ri && !F_is_TyE(tempc)) { chg_c_to_X_orX_(); } if (p_ri) { chg_c_to_X_or_X(); } } if (!p_ri && !curwin->w_cursor.col) { return _GHAYN; } if (!p_ri) { dec_cursor(); } if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = _GHAYN_; } else { tempc = _GHAYN; } if (!p_ri) { inc_cursor(); } break; case 'z' : tempc = _ZA ; break; case 'Z' : tempc = _KAF_H ; break; case ';' : tempc = _KAF ; break; case '\'' : tempc = _GAF ; break; case ',' : tempc = WAW ; break; case '[' : tempc = _JIM ; break; case ']' : tempc = _CHE ; break; } if ((F_isalpha(tempc) || F_isdigit(tempc))) { if (!curwin->w_cursor.col && STRLEN(get_cursor_line_ptr())) { if (!p_ri && !F_is_TyE(tempc)) { chg_c_to_X_orX_(); } if (p_ri) { chg_c_to_X_or_X(); } } if (curwin->w_cursor.col) { if (!p_ri) { dec_cursor(); } if (F_is_TyE(tempc)) { chg_l_toXor_X(); } else { chg_l_to_X_orX_(); } if (!p_ri) { inc_cursor(); } } } if (tempc) { return tempc; } return c; }
/// Convert the given Farsi character into a _X or _X_ type /// /// @param c The character to convert. /// /// @return Farsi character converted to a _X or _X_ type. static int toF_Xor_X_(int c) { int tempc; switch (c) { case BE: return _BE; case PE: return _PE; case TE: return _TE; case SE: return _SE; case JIM: return _JIM; 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: 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_: return _YE; case YEE: case YEE_: return _YEE; case IE: case IE_: return _IE; case F_HE: tempc = _HE; if (p_ri && (curwin->w_cursor.col + 1 < (colnr_T)STRLEN(get_cursor_line_ptr()))) { inc_cursor(); if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = _HE_; } dec_cursor(); } if (!p_ri && STRLEN(get_cursor_line_ptr())) { dec_cursor(); if (F_is_TyB_TyC_TyD(SRC_EDT, AT_CURSOR)) { tempc = _HE_; } inc_cursor(); } return tempc; } return 0; }