Mercurial > vim
comparison src/ex_getln.c @ 164:8b0ee9d57d7f
updated for version 7.0050
author | vimboss |
---|---|
date | Sat, 12 Feb 2005 14:29:27 +0000 |
parents | 6df0106fc595 |
children | 4d9eabb1396e |
comparison
equal
deleted
inserted
replaced
163:06bc859d1a32 | 164:8b0ee9d57d7f |
---|---|
203 | 203 |
204 /* | 204 /* |
205 * set some variables for redrawcmd() | 205 * set some variables for redrawcmd() |
206 */ | 206 */ |
207 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); | 207 ccline.cmdfirstc = (firstc == '@' ? 0 : firstc); |
208 ccline.cmdindent = indent; | 208 ccline.cmdindent = (firstc > 0 ? indent : 0); |
209 alloc_cmdbuff(exmode_active ? 250 : 0); /* alloc initial ccline.cmdbuff */ | 209 |
210 /* alloc initial ccline.cmdbuff */ | |
211 alloc_cmdbuff(exmode_active ? 250 : indent + 1); | |
210 if (ccline.cmdbuff == NULL) | 212 if (ccline.cmdbuff == NULL) |
211 return NULL; /* out of memory */ | 213 return NULL; /* out of memory */ |
212 ccline.cmdlen = ccline.cmdpos = 0; | 214 ccline.cmdlen = ccline.cmdpos = 0; |
213 ccline.cmdbuff[0] = NUL; | 215 ccline.cmdbuff[0] = NUL; |
216 | |
217 /* autoindent for :insert and :append */ | |
218 if (firstc <= 0) | |
219 { | |
220 copy_spaces(ccline.cmdbuff, indent); | |
221 ccline.cmdbuff[indent] = NUL; | |
222 ccline.cmdpos = indent; | |
223 ccline.cmdspos = indent; | |
224 ccline.cmdlen = indent; | |
225 } | |
214 | 226 |
215 ExpandInit(&xpc); | 227 ExpandInit(&xpc); |
216 | 228 |
217 #ifdef FEAT_RIGHTLEFT | 229 #ifdef FEAT_RIGHTLEFT |
218 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' | 230 if (curwin->w_p_rl && *curwin->w_p_rlc == 's' |
1876 int indent; /* indent for inside conditionals */ | 1888 int indent; /* indent for inside conditionals */ |
1877 { | 1889 { |
1878 garray_T line_ga; | 1890 garray_T line_ga; |
1879 int len; | 1891 int len; |
1880 int off = 0; | 1892 int off = 0; |
1881 char_u *p; | 1893 char_u *pend; |
1882 int finished = FALSE; | 1894 int finished = FALSE; |
1883 #if defined(FEAT_GUI) || defined(NO_COOKED_INPUT) | 1895 #if defined(FEAT_GUI) || defined(NO_COOKED_INPUT) |
1884 int startcol = 0; | 1896 int startcol = 0; |
1885 int c1; | 1897 int c1; |
1886 int escaped = FALSE; /* CTRL-V typed */ | 1898 int escaped = FALSE; /* CTRL-V typed */ |
1895 compute_cmdrow(); | 1907 compute_cmdrow(); |
1896 if (msg_col) | 1908 if (msg_col) |
1897 msg_putchar('\n'); | 1909 msg_putchar('\n'); |
1898 if (c == ':') | 1910 if (c == ':') |
1899 { | 1911 { |
1912 /* indent that is only displayed, not in the line itself */ | |
1900 msg_putchar(':'); | 1913 msg_putchar(':'); |
1901 while (indent-- > 0) | 1914 while (indent-- > 0) |
1902 msg_putchar(' '); | 1915 msg_putchar(' '); |
1903 #if defined(FEAT_GUI) || defined(NO_COOKED_INPUT) | 1916 #if defined(FEAT_GUI) || defined(NO_COOKED_INPUT) |
1904 startcol = msg_col; | 1917 startcol = msg_col; |
1905 #endif | 1918 #endif |
1906 } | 1919 } |
1907 | 1920 |
1908 ga_init2(&line_ga, 1, 30); | 1921 ga_init2(&line_ga, 1, 30); |
1909 | 1922 |
1923 /* autoindent for :insert and :append is in the line itself */ | |
1924 if (c <= 0) | |
1925 { | |
1926 #if defined(FEAT_GUI) || defined(NO_COOKED_INPUT) | |
1927 vcol = indent; | |
1928 #endif | |
1929 while (indent >= 8) | |
1930 { | |
1931 ga_append(&line_ga, TAB); | |
1932 msg_puts((char_u *)" "); | |
1933 indent -= 8; | |
1934 } | |
1935 while (indent-- > 0) | |
1936 { | |
1937 ga_append(&line_ga, ' '); | |
1938 msg_putchar(' '); | |
1939 } | |
1940 } | |
1941 | |
1910 /* | 1942 /* |
1911 * Get the line, one character at a time. | 1943 * Get the line, one character at a time. |
1912 */ | 1944 */ |
1913 got_int = FALSE; | 1945 got_int = FALSE; |
1914 while (!got_int && !finished) | 1946 while (!got_int && !finished) |
1915 { | 1947 { |
1916 if (ga_grow(&line_ga, 40) == FAIL) | 1948 if (ga_grow(&line_ga, 40) == FAIL) |
1917 break; | 1949 break; |
1918 p = (char_u *)line_ga.ga_data + line_ga.ga_len; | 1950 pend = (char_u *)line_ga.ga_data + line_ga.ga_len; |
1919 | 1951 |
1920 /* Get one character (inchar gets a third of maxlen characters!) */ | 1952 /* Get one character (inchar gets a third of maxlen characters!) */ |
1921 len = inchar(p + off, 3, -1L, 0); | 1953 len = inchar(pend + off, 3, -1L, 0); |
1922 if (len < 0) | 1954 if (len < 0) |
1923 continue; /* end of input script reached */ | 1955 continue; /* end of input script reached */ |
1924 /* for a special character, we need at least three characters */ | 1956 /* for a special character, we need at least three characters */ |
1925 if ((*p == K_SPECIAL || *p == CSI) && off + len < 3) | 1957 if ((*pend == K_SPECIAL || *pend == CSI) && off + len < 3) |
1926 { | 1958 { |
1927 off += len; | 1959 off += len; |
1928 continue; | 1960 continue; |
1929 } | 1961 } |
1930 len += off; | 1962 len += off; |
1945 break; | 1977 break; |
1946 } | 1978 } |
1947 | 1979 |
1948 while (len > 0) | 1980 while (len > 0) |
1949 { | 1981 { |
1950 c1 = *p++; | 1982 c1 = *pend++; |
1951 --len; | 1983 --len; |
1952 if ((c1 == K_SPECIAL | 1984 if ((c1 == K_SPECIAL |
1953 # if !defined(NO_COOKED_INPUT) || defined(FEAT_GUI) | 1985 # if !defined(NO_COOKED_INPUT) || defined(FEAT_GUI) |
1954 || c1 == CSI | 1986 || c1 == CSI |
1955 # endif | 1987 # endif |
1956 ) && len >= 2) | 1988 ) && len >= 2) |
1957 { | 1989 { |
1958 c1 = TO_SPECIAL(p[0], p[1]); | 1990 c1 = TO_SPECIAL(pend[0], pend[1]); |
1959 p += 2; | 1991 pend += 2; |
1960 len -= 2; | 1992 len -= 2; |
1961 } | 1993 } |
1962 | 1994 |
1963 if (!escaped) | 1995 if (!escaped) |
1964 { | 1996 { |
2004 msg_clr_eos(); | 2036 msg_clr_eos(); |
2005 line_ga.ga_len = 0; | 2037 line_ga.ga_len = 0; |
2006 continue; | 2038 continue; |
2007 } | 2039 } |
2008 | 2040 |
2041 if (c1 == Ctrl_T) | |
2042 c1 = TAB; /* very simplistic... */ | |
2043 | |
2044 if (c1 == Ctrl_D) | |
2045 { | |
2046 char_u *p; | |
2047 | |
2048 /* Delete one shiftwidth. */ | |
2049 p = (char_u *)line_ga.ga_data; | |
2050 p[line_ga.ga_len] = NUL; | |
2051 indent = get_indent_str(p, 8); | |
2052 --indent; | |
2053 indent -= indent % 8; | |
2054 while (get_indent_str(p, 8) > indent) | |
2055 { | |
2056 char_u *s = skipwhite(p); | |
2057 | |
2058 mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1); | |
2059 --line_ga.ga_len; | |
2060 } | |
2061 msg_col = startcol; | |
2062 for (vcol = 0; *p != NUL; ++p) | |
2063 { | |
2064 if (*p == TAB) | |
2065 { | |
2066 do | |
2067 { | |
2068 msg_putchar(' '); | |
2069 } while (++vcol % 8); | |
2070 } | |
2071 else | |
2072 { | |
2073 msg_outtrans_len(p, 1); | |
2074 vcol += char2cells(*p); | |
2075 } | |
2076 } | |
2077 msg_clr_eos(); | |
2078 continue; | |
2079 } | |
2080 | |
2009 if (c1 == Ctrl_V) | 2081 if (c1 == Ctrl_V) |
2010 { | 2082 { |
2011 escaped = TRUE; | 2083 escaped = TRUE; |
2012 continue; | 2084 continue; |
2013 } | 2085 } |
2044 #ifndef NO_COOKED_INPUT | 2116 #ifndef NO_COOKED_INPUT |
2045 { | 2117 { |
2046 line_ga.ga_len += len; | 2118 line_ga.ga_len += len; |
2047 } | 2119 } |
2048 #endif | 2120 #endif |
2049 p = (char_u *)(line_ga.ga_data) + line_ga.ga_len; | 2121 pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len; |
2050 if (line_ga.ga_len && p[-1] == '\n') | 2122 if (line_ga.ga_len && pend[-1] == '\n') |
2051 { | 2123 { |
2052 finished = TRUE; | 2124 finished = TRUE; |
2053 --line_ga.ga_len; | 2125 --line_ga.ga_len; |
2054 --p; | 2126 --pend; |
2055 *p = NUL; | 2127 *pend = NUL; |
2056 } | 2128 } |
2057 } | 2129 } |
2058 | 2130 |
2059 /* note that cursor has moved, because of the echoed <CR> */ | 2131 /* note that cursor has moved, because of the echoed <CR> */ |
2060 screen_down(); | 2132 screen_down(); |