comparison src/indent.c @ 28942:6cdf55afaae9 v8.2.4993

patch 8.2.4993: smart/C/lisp indenting is optional Commit: https://github.com/vim/vim/commit/8e145b82464a21ee4fdf7948f04e2a1d505f8bfa Author: Bram Moolenaar <Bram@vim.org> Date: Sat May 21 20:17:31 2022 +0100 patch 8.2.4993: smart/C/lisp indenting is optional Problem: smart/C/lisp indenting is optional, which makes the code more complex, while it only reduces the executable size a bit. Solution: Graduate FEAT_CINDENT, FEAT_SMARTINDENT and FEAT_LISP.
author Bram Moolenaar <Bram@vim.org>
date Sat, 21 May 2022 21:30:04 +0200
parents 3942ea75b4c0
children 45c182c4f7e9
comparison
equal deleted inserted replaced
28941:f17de8647585 28942:6cdf55afaae9
1053 return TRUE; 1053 return TRUE;
1054 else 1054 else
1055 return FALSE; 1055 return FALSE;
1056 } 1056 }
1057 1057
1058 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO)
1059 /* 1058 /*
1060 * op_reindent - handle reindenting a block of lines. 1059 * op_reindent - handle reindenting a block of lines.
1061 */ 1060 */
1062 void 1061 void
1063 op_reindent(oparg_T *oap, int (*how)(void)) 1062 op_reindent(oparg_T *oap, int (*how)(void))
1090 && oap->line_count > p_report) 1089 && oap->line_count > p_report)
1091 smsg(_("%ld lines to indent... "), i); 1090 smsg(_("%ld lines to indent... "), i);
1092 1091
1093 // Be vi-compatible: For lisp indenting the first line is not 1092 // Be vi-compatible: For lisp indenting the first line is not
1094 // indented, unless there is only one line. 1093 // indented, unless there is only one line.
1095 # ifdef FEAT_LISP
1096 if (i != oap->line_count - 1 || oap->line_count == 1 1094 if (i != oap->line_count - 1 || oap->line_count == 1
1097 || how != get_lisp_indent) 1095 || how != get_lisp_indent)
1098 # endif
1099 { 1096 {
1100 l = skipwhite(ml_get_curline()); 1097 l = skipwhite(ml_get_curline());
1101 if (*l == NUL) // empty or blank line 1098 if (*l == NUL) // empty or blank line
1102 amount = 0; 1099 amount = 0;
1103 else 1100 else
1140 // set '[ and '] marks 1137 // set '[ and '] marks
1141 curbuf->b_op_start = oap->start; 1138 curbuf->b_op_start = oap->start;
1142 curbuf->b_op_end = oap->end; 1139 curbuf->b_op_end = oap->end;
1143 } 1140 }
1144 } 1141 }
1145 #endif // defined(FEAT_LISP) || defined(FEAT_CINDENT) 1142
1146
1147 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) || defined(PROTO)
1148 /* 1143 /*
1149 * Return TRUE if lines starting with '#' should be left aligned. 1144 * Return TRUE if lines starting with '#' should be left aligned.
1150 */ 1145 */
1151 int 1146 int
1152 preprocs_left(void) 1147 preprocs_left(void)
1153 { 1148 {
1154 return 1149 return
1155 # ifdef FEAT_SMARTINDENT
1156 # ifdef FEAT_CINDENT
1157 (curbuf->b_p_si && !curbuf->b_p_cin) || 1150 (curbuf->b_p_si && !curbuf->b_p_cin) ||
1158 # else
1159 curbuf->b_p_si
1160 # endif
1161 # endif
1162 # ifdef FEAT_CINDENT
1163 (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE) 1151 (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE)
1164 && curbuf->b_ind_hash_comment == 0) 1152 && curbuf->b_ind_hash_comment == 0)
1165 # endif
1166 ; 1153 ;
1167 } 1154 }
1168 #endif 1155
1169
1170 #ifdef FEAT_SMARTINDENT
1171 /* 1156 /*
1172 * Return TRUE if the conditions are OK for smart indenting. 1157 * Return TRUE if the conditions are OK for smart indenting.
1173 */ 1158 */
1174 int 1159 int
1175 may_do_si() 1160 may_do_si()
1176 { 1161 {
1177 return curbuf->b_p_si 1162 return curbuf->b_p_si
1178 # ifdef FEAT_CINDENT
1179 && !curbuf->b_p_cin 1163 && !curbuf->b_p_cin
1180 # endif
1181 # ifdef FEAT_EVAL 1164 # ifdef FEAT_EVAL
1182 && *curbuf->b_p_inde == NUL 1165 && *curbuf->b_p_inde == NUL
1183 # endif 1166 # endif
1184 && !p_paste; 1167 && !p_paste;
1185 } 1168 }
1261 1244
1262 // Adjust ai_col, the char at this position can be deleted. 1245 // Adjust ai_col, the char at this position can be deleted.
1263 if (ai_col > curwin->w_cursor.col) 1246 if (ai_col > curwin->w_cursor.col)
1264 ai_col = curwin->w_cursor.col; 1247 ai_col = curwin->w_cursor.col;
1265 } 1248 }
1266 #endif
1267 1249
1268 /* 1250 /*
1269 * Insert an indent (for <Tab> or CTRL-T) or delete an indent (for CTRL-D). 1251 * Insert an indent (for <Tab> or CTRL-T) or delete an indent (for CTRL-D).
1270 * Keep the cursor on the same character. 1252 * Keep the cursor on the same character.
1271 * type == INDENT_INC increase indent (for CTRL-T or <Tab>) 1253 * type == INDENT_INC increase indent (for CTRL-T or <Tab>)
1863 coladvance(curwin->w_curswant); 1845 coladvance(curwin->w_curswant);
1864 1846
1865 u_clearline(); 1847 u_clearline();
1866 } 1848 }
1867 1849
1868 #if (defined(FEAT_CINDENT) && defined(FEAT_EVAL)) || defined(PROTO) 1850 #if defined(FEAT_EVAL) || defined(PROTO)
1869 /* 1851 /*
1870 * Get indent level from 'indentexpr'. 1852 * Get indent level from 'indentexpr'.
1871 */ 1853 */
1872 int 1854 int
1873 get_expr_indent(void) 1855 get_expr_indent(void)
1930 indent = get_indent(); 1912 indent = get_indent();
1931 1913
1932 return indent; 1914 return indent;
1933 } 1915 }
1934 #endif 1916 #endif
1935
1936 #if defined(FEAT_LISP) || defined(PROTO)
1937 1917
1938 static int 1918 static int
1939 lisp_match(char_u *p) 1919 lisp_match(char_u *p)
1940 { 1920 {
1941 char_u buf[LSIZE]; 1921 char_u buf[LSIZE];
2148 2128
2149 curwin->w_cursor = realpos; 2129 curwin->w_cursor = realpos;
2150 2130
2151 return amount; 2131 return amount;
2152 } 2132 }
2153 #endif // FEAT_LISP 2133
2154
2155 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO)
2156 /* 2134 /*
2157 * Re-indent the current line, based on the current contents of it and the 2135 * Re-indent the current line, based on the current contents of it and the
2158 * surrounding lines. Fixing the cursor position seems really easy -- I'm very 2136 * surrounding lines. Fixing the cursor position seems really easy -- I'm very
2159 * confused what all the part that handles Control-T is doing that I'm not. 2137 * confused what all the part that handles Control-T is doing that I'm not.
2160 * "get_the_indent" should be get_c_indent, get_expr_indent or get_lisp_indent. 2138 * "get_the_indent" should be get_c_indent, get_expr_indent or get_lisp_indent.
2179 void 2157 void
2180 fix_indent(void) 2158 fix_indent(void)
2181 { 2159 {
2182 if (p_paste) 2160 if (p_paste)
2183 return; 2161 return;
2184 # ifdef FEAT_LISP
2185 if (curbuf->b_p_lisp && curbuf->b_p_ai) 2162 if (curbuf->b_p_lisp && curbuf->b_p_ai)
2186 fixthisline(get_lisp_indent); 2163 fixthisline(get_lisp_indent);
2187 # endif
2188 # if defined(FEAT_LISP) && defined(FEAT_CINDENT)
2189 else 2164 else
2190 # endif
2191 # ifdef FEAT_CINDENT
2192 if (cindent_on()) 2165 if (cindent_on())
2193 do_c_expr_indent(); 2166 do_c_expr_indent();
2194 # endif 2167 }
2195 }
2196 #endif
2197 2168
2198 #if defined(FEAT_EVAL) || defined(PROTO) 2169 #if defined(FEAT_EVAL) || defined(PROTO)
2199 /* 2170 /*
2200 * "indent()" function 2171 * "indent()" function
2201 */ 2172 */
2222 * "lispindent(lnum)" function 2193 * "lispindent(lnum)" function
2223 */ 2194 */
2224 void 2195 void
2225 f_lispindent(typval_T *argvars UNUSED, typval_T *rettv) 2196 f_lispindent(typval_T *argvars UNUSED, typval_T *rettv)
2226 { 2197 {
2227 # ifdef FEAT_LISP
2228 pos_T pos; 2198 pos_T pos;
2229 linenr_T lnum; 2199 linenr_T lnum;
2230 2200
2231 if (in_vim9script() && check_for_lnum_arg(argvars, 0) == FAIL) 2201 if (in_vim9script() && check_for_lnum_arg(argvars, 0) == FAIL)
2232 return; 2202 return;
2240 curwin->w_cursor = pos; 2210 curwin->w_cursor = pos;
2241 } 2211 }
2242 else if (in_vim9script()) 2212 else if (in_vim9script())
2243 semsg(_(e_invalid_line_number_nr), lnum); 2213 semsg(_(e_invalid_line_number_nr), lnum);
2244 else 2214 else
2245 # endif
2246 rettv->vval.v_number = -1; 2215 rettv->vval.v_number = -1;
2247 } 2216 }
2248 #endif 2217 #endif