comparison src/search.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 b5c46d447518
children 485619e7f836
comparison
equal deleted inserted replaced
28941:f17de8647585 28942:6cdf55afaae9
2114 int cpo_match; // vi compatible matching 2114 int cpo_match; // vi compatible matching
2115 int cpo_bsl; // don't recognize backslashes 2115 int cpo_bsl; // don't recognize backslashes
2116 int match_escaped = 0; // search for escaped match 2116 int match_escaped = 0; // search for escaped match
2117 int dir; // Direction to search 2117 int dir; // Direction to search
2118 int comment_col = MAXCOL; // start of / / comment 2118 int comment_col = MAXCOL; // start of / / comment
2119 #ifdef FEAT_LISP
2120 int lispcomm = FALSE; // inside of Lisp-style comment 2119 int lispcomm = FALSE; // inside of Lisp-style comment
2121 int lisp = curbuf->b_p_lisp; // engage Lisp-specific hacks ;) 2120 int lisp = curbuf->b_p_lisp; // engage Lisp-specific hacks ;)
2122 #endif
2123 2121
2124 pos = curwin->w_cursor; 2122 pos = curwin->w_cursor;
2125 pos.coladd = 0; 2123 pos.coladd = 0;
2126 linep = ml_get(pos.lnum); 2124 linep = ml_get(pos.lnum);
2127 2125
2346 do_quotes = -1; 2344 do_quotes = -1;
2347 start_in_quotes = MAYBE; 2345 start_in_quotes = MAYBE;
2348 CLEAR_POS(&match_pos); 2346 CLEAR_POS(&match_pos);
2349 2347
2350 // backward search: Check if this line contains a single-line comment 2348 // backward search: Check if this line contains a single-line comment
2351 if ((backwards && comment_dir) 2349 if ((backwards && comment_dir) || lisp)
2352 #ifdef FEAT_LISP
2353 || lisp
2354 #endif
2355 )
2356 comment_col = check_linecomment(linep); 2350 comment_col = check_linecomment(linep);
2357 #ifdef FEAT_LISP
2358 if (lisp && comment_col != MAXCOL && pos.col > (colnr_T)comment_col) 2351 if (lisp && comment_col != MAXCOL && pos.col > (colnr_T)comment_col)
2359 lispcomm = TRUE; // find match inside this comment 2352 lispcomm = TRUE; // find match inside this comment
2360 #endif 2353
2361 while (!got_int) 2354 while (!got_int)
2362 { 2355 {
2363 /* 2356 /*
2364 * Go to the next position, forward or backward. We could use 2357 * Go to the next position, forward or backward. We could use
2365 * inc() and dec() here, but that is much slower 2358 * inc() and dec() here, but that is much slower
2366 */ 2359 */
2367 if (backwards) 2360 if (backwards)
2368 { 2361 {
2369 #ifdef FEAT_LISP
2370 // char to match is inside of comment, don't search outside 2362 // char to match is inside of comment, don't search outside
2371 if (lispcomm && pos.col < (colnr_T)comment_col) 2363 if (lispcomm && pos.col < (colnr_T)comment_col)
2372 break; 2364 break;
2373 #endif
2374 if (pos.col == 0) // at start of line, go to prev. one 2365 if (pos.col == 0) // at start of line, go to prev. one
2375 { 2366 {
2376 if (pos.lnum == 1) // start of file 2367 if (pos.lnum == 1) // start of file
2377 break; 2368 break;
2378 --pos.lnum; 2369 --pos.lnum;
2384 pos.col = (colnr_T)STRLEN(linep); // pos.col on trailing NUL 2375 pos.col = (colnr_T)STRLEN(linep); // pos.col on trailing NUL
2385 do_quotes = -1; 2376 do_quotes = -1;
2386 line_breakcheck(); 2377 line_breakcheck();
2387 2378
2388 // Check if this line contains a single-line comment 2379 // Check if this line contains a single-line comment
2389 if (comment_dir 2380 if (comment_dir || lisp)
2390 #ifdef FEAT_LISP
2391 || lisp
2392 #endif
2393 )
2394 comment_col = check_linecomment(linep); 2381 comment_col = check_linecomment(linep);
2395 #ifdef FEAT_LISP
2396 // skip comment 2382 // skip comment
2397 if (lisp && comment_col != MAXCOL) 2383 if (lisp && comment_col != MAXCOL)
2398 pos.col = comment_col; 2384 pos.col = comment_col;
2399 #endif
2400 } 2385 }
2401 else 2386 else
2402 { 2387 {
2403 --pos.col; 2388 --pos.col;
2404 if (has_mbyte) 2389 if (has_mbyte)
2407 } 2392 }
2408 else // forward search 2393 else // forward search
2409 { 2394 {
2410 if (linep[pos.col] == NUL 2395 if (linep[pos.col] == NUL
2411 // at end of line, go to next one 2396 // at end of line, go to next one
2412 #ifdef FEAT_LISP 2397 // For lisp don't search for match in comment
2413 // don't search for match in comment
2414 || (lisp && comment_col != MAXCOL 2398 || (lisp && comment_col != MAXCOL
2415 && pos.col == (colnr_T)comment_col) 2399 && pos.col == (colnr_T)comment_col))
2416 #endif
2417 )
2418 { 2400 {
2419 if (pos.lnum == curbuf->b_ml.ml_line_count // end of file 2401 if (pos.lnum == curbuf->b_ml.ml_line_count // end of file
2420 #ifdef FEAT_LISP
2421 // line is exhausted and comment with it, 2402 // line is exhausted and comment with it,
2422 // don't search for match in code 2403 // don't search for match in code
2423 || lispcomm 2404 || lispcomm)
2424 #endif
2425 )
2426 break; 2405 break;
2427 ++pos.lnum; 2406 ++pos.lnum;
2428 2407
2429 if (maxtravel && traveled++ > maxtravel) 2408 if (maxtravel && traveled++ > maxtravel)
2430 break; 2409 break;
2431 2410
2432 linep = ml_get(pos.lnum); 2411 linep = ml_get(pos.lnum);
2433 pos.col = 0; 2412 pos.col = 0;
2434 do_quotes = -1; 2413 do_quotes = -1;
2435 line_breakcheck(); 2414 line_breakcheck();
2436 #ifdef FEAT_LISP
2437 if (lisp) // find comment pos in new line 2415 if (lisp) // find comment pos in new line
2438 comment_col = check_linecomment(linep); 2416 comment_col = check_linecomment(linep);
2439 #endif
2440 } 2417 }
2441 else 2418 else
2442 { 2419 {
2443 if (has_mbyte) 2420 if (has_mbyte)
2444 pos.col += (*mb_ptr2len)(linep + pos.col); 2421 pos.col += (*mb_ptr2len)(linep + pos.col);
2677 } 2654 }
2678 } 2655 }
2679 // FALLTHROUGH 2656 // FALLTHROUGH
2680 2657
2681 default: 2658 default:
2682 #ifdef FEAT_LISP
2683 /* 2659 /*
2684 * For Lisp skip over backslashed (), {} and []. 2660 * For Lisp skip over backslashed (), {} and [].
2685 * (actually, we skip #\( et al) 2661 * (actually, we skip #\( et al)
2686 */ 2662 */
2687 if (curbuf->b_p_lisp 2663 if (curbuf->b_p_lisp
2688 && vim_strchr((char_u *)"(){}[]", c) != NULL 2664 && vim_strchr((char_u *)"(){}[]", c) != NULL
2689 && pos.col > 1 2665 && pos.col > 1
2690 && check_prevcol(linep, pos.col, '\\', NULL) 2666 && check_prevcol(linep, pos.col, '\\', NULL)
2691 && check_prevcol(linep, pos.col - 1, '#', NULL)) 2667 && check_prevcol(linep, pos.col - 1, '#', NULL))
2692 break; 2668 break;
2693 #endif
2694 2669
2695 // Check for match outside of quotes, and inside of 2670 // Check for match outside of quotes, and inside of
2696 // quotes when the start is also inside of quotes. 2671 // quotes when the start is also inside of quotes.
2697 if ((!inquote || start_in_quotes == TRUE) 2672 if ((!inquote || start_in_quotes == TRUE)
2698 && (c == initc || c == findc)) 2673 && (c == initc || c == findc))
2737 check_linecomment(char_u *line) 2712 check_linecomment(char_u *line)
2738 { 2713 {
2739 char_u *p; 2714 char_u *p;
2740 2715
2741 p = line; 2716 p = line;
2742 #ifdef FEAT_LISP
2743 // skip Lispish one-line comments 2717 // skip Lispish one-line comments
2744 if (curbuf->b_p_lisp) 2718 if (curbuf->b_p_lisp)
2745 { 2719 {
2746 if (vim_strchr(p, ';') != NULL) // there may be comments 2720 if (vim_strchr(p, ';') != NULL) // there may be comments
2747 { 2721 {
2771 } 2745 }
2772 else 2746 else
2773 p = NULL; 2747 p = NULL;
2774 } 2748 }
2775 else 2749 else
2776 #endif 2750 while ((p = vim_strchr(p, '/')) != NULL)
2777 while ((p = vim_strchr(p, '/')) != NULL) 2751 {
2778 { 2752 // Accept a double /, unless it's preceded with * and followed by
2779 // Accept a double /, unless it's preceded with * and followed by *, 2753 // *, because * / / * is an end and start of a C comment. Only
2780 // because * / / * is an end and start of a C comment. 2754 // accept the position if it is not inside a string.
2781 // Only accept the position if it is not inside a string. 2755 if (p[1] == '/' && (p == line || p[-1] != '*' || p[2] != '*')
2782 if (p[1] == '/' && (p == line || p[-1] != '*' || p[2] != '*')
2783 && !is_pos_in_string(line, (colnr_T)(p - line))) 2756 && !is_pos_in_string(line, (colnr_T)(p - line)))
2784 break; 2757 break;
2785 ++p; 2758 ++p;
2786 } 2759 }
2787 2760
2788 if (p == NULL) 2761 if (p == NULL)
2789 return MAXCOL; 2762 return MAXCOL;
2790 return (int)(p - line); 2763 return (int)(p - line);
2791 } 2764 }
3115 showmode(); 3088 showmode();
3116 3089
3117 return OK; 3090 return OK;
3118 } 3091 }
3119 3092
3120 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(FEAT_TEXTOBJ) \
3121 || defined(PROTO)
3122 /* 3093 /*
3123 * return TRUE if line 'lnum' is empty or has white chars only. 3094 * return TRUE if line 'lnum' is empty or has white chars only.
3124 */ 3095 */
3125 int 3096 int
3126 linewhite(linenr_T lnum) 3097 linewhite(linenr_T lnum)
3128 char_u *p; 3099 char_u *p;
3129 3100
3130 p = skipwhite(ml_get(lnum)); 3101 p = skipwhite(ml_get(lnum));
3131 return (*p == NUL); 3102 return (*p == NUL);
3132 } 3103 }
3133 #endif
3134 3104
3135 /* 3105 /*
3136 * Add the search count "[3/19]" to "msgbuf". 3106 * Add the search count "[3/19]" to "msgbuf".
3137 * See update_search_stat() for other arguments. 3107 * See update_search_stat() for other arguments.
3138 */ 3108 */