Mercurial > vim
comparison src/misc1.c @ 12238:0066a7e178bc v8.0.0999
patch 8.0.0999: indenting raw C++ strings is wrong
commit https://github.com/vim/vim/commit/dde81312b031211752d1fcb8539d79f90f324a2e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 26 17:49:01 2017 +0200
patch 8.0.0999: indenting raw C++ strings is wrong
Problem: Indenting raw C++ strings is wrong.
Solution: Add special handling of raw strings. (Christian Brabandt)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 26 Aug 2017 18:00:04 +0200 |
parents | 0496ea4c5c2e |
children | 03e4be2e3d53 |
comparison
equal
deleted
inserted
replaced
12237:6dac7d6ad877 | 12238:0066a7e178bc |
---|---|
5219 | 5219 |
5220 #if defined(FEAT_CINDENT) || defined(FEAT_SYN_HL) | 5220 #if defined(FEAT_CINDENT) || defined(FEAT_SYN_HL) |
5221 | 5221 |
5222 static char_u *skip_string(char_u *p); | 5222 static char_u *skip_string(char_u *p); |
5223 static pos_T *ind_find_start_comment(void); | 5223 static pos_T *ind_find_start_comment(void); |
5224 static pos_T *ind_find_start_CORS(void); | 5224 static pos_T *ind_find_start_CORS(linenr_T *is_raw); |
5225 static pos_T *find_start_rawstring(int ind_maxcomment); | 5225 static pos_T *find_start_rawstring(int ind_maxcomment); |
5226 | 5226 |
5227 /* | 5227 /* |
5228 * Find the start of a comment, not knowing if we are in a comment right now. | 5228 * Find the start of a comment, not knowing if we are in a comment right now. |
5229 * Search starts at w_cursor.lnum and goes backwards. | 5229 * Search starts at w_cursor.lnum and goes backwards. |
5270 | 5270 |
5271 /* | 5271 /* |
5272 * Find the start of a comment or raw string, not knowing if we are in a | 5272 * Find the start of a comment or raw string, not knowing if we are in a |
5273 * comment or raw string right now. | 5273 * comment or raw string right now. |
5274 * Search starts at w_cursor.lnum and goes backwards. | 5274 * Search starts at w_cursor.lnum and goes backwards. |
5275 * If is_raw is given and returns start of raw_string, sets it to true. | |
5275 * Return NULL when not inside a comment or raw string. | 5276 * Return NULL when not inside a comment or raw string. |
5276 * "CORS" -> Comment Or Raw String | 5277 * "CORS" -> Comment Or Raw String |
5277 */ | 5278 */ |
5278 static pos_T * | 5279 static pos_T * |
5279 ind_find_start_CORS(void) /* XXX */ | 5280 ind_find_start_CORS(linenr_T *is_raw) /* XXX */ |
5280 { | 5281 { |
5281 static pos_T comment_pos_copy; | 5282 static pos_T comment_pos_copy; |
5282 pos_T *comment_pos; | 5283 pos_T *comment_pos; |
5283 pos_T *rs_pos; | 5284 pos_T *rs_pos; |
5284 | 5285 |
5294 | 5295 |
5295 /* If comment_pos is before rs_pos the raw string is inside the comment. | 5296 /* If comment_pos is before rs_pos the raw string is inside the comment. |
5296 * If rs_pos is before comment_pos the comment is inside the raw string. */ | 5297 * If rs_pos is before comment_pos the comment is inside the raw string. */ |
5297 if (comment_pos == NULL || (rs_pos != NULL | 5298 if (comment_pos == NULL || (rs_pos != NULL |
5298 && LT_POS(*rs_pos, *comment_pos))) | 5299 && LT_POS(*rs_pos, *comment_pos))) |
5300 { | |
5301 if (is_raw != NULL && rs_pos != NULL) | |
5302 *is_raw = rs_pos->lnum; | |
5299 return rs_pos; | 5303 return rs_pos; |
5304 } | |
5300 return comment_pos; | 5305 return comment_pos; |
5301 } | 5306 } |
5302 | 5307 |
5303 /* | 5308 /* |
5304 * Find the start of a raw string, not knowing if we are in one right now. | 5309 * Find the start of a raw string, not knowing if we are in one right now. |
5639 /* | 5644 /* |
5640 * If we're in a comment or raw string now, skip to the start of | 5645 * If we're in a comment or raw string now, skip to the start of |
5641 * it. | 5646 * it. |
5642 */ | 5647 */ |
5643 curwin->w_cursor.col = 0; | 5648 curwin->w_cursor.col = 0; |
5644 if ((trypos = ind_find_start_CORS()) != NULL) /* XXX */ | 5649 if ((trypos = ind_find_start_CORS(NULL)) != NULL) /* XXX */ |
5645 curwin->w_cursor = *trypos; | 5650 curwin->w_cursor = *trypos; |
5646 | 5651 |
5647 line = ml_get_curline(); | 5652 line = ml_get_curline(); |
5648 if (cin_ispreproc(line)) /* ignore #defines, #if, etc. */ | 5653 if (cin_ispreproc(line)) /* ignore #defines, #if, etc. */ |
5649 continue; | 5654 continue; |
6766 trypos = &pos_copy; | 6771 trypos = &pos_copy; |
6767 curwin->w_cursor = *trypos; | 6772 curwin->w_cursor = *trypos; |
6768 pos = NULL; | 6773 pos = NULL; |
6769 /* ignore the { if it's in a // or / * * / comment */ | 6774 /* ignore the { if it's in a // or / * * / comment */ |
6770 if ((colnr_T)cin_skip2pos(trypos) == trypos->col | 6775 if ((colnr_T)cin_skip2pos(trypos) == trypos->col |
6771 && (pos = ind_find_start_CORS()) == NULL) /* XXX */ | 6776 && (pos = ind_find_start_CORS(NULL)) == NULL) /* XXX */ |
6772 break; | 6777 break; |
6773 if (pos != NULL) | 6778 if (pos != NULL) |
6774 curwin->w_cursor.lnum = pos->lnum; | 6779 curwin->w_cursor.lnum = pos->lnum; |
6775 } | 6780 } |
6776 curwin->w_cursor = cursor_save; | 6781 curwin->w_cursor = cursor_save; |
6817 pos_T *trypos_wk; | 6822 pos_T *trypos_wk; |
6818 | 6823 |
6819 pos_copy = *trypos; /* copy trypos, findmatch will change it */ | 6824 pos_copy = *trypos; /* copy trypos, findmatch will change it */ |
6820 trypos = &pos_copy; | 6825 trypos = &pos_copy; |
6821 curwin->w_cursor = *trypos; | 6826 curwin->w_cursor = *trypos; |
6822 if ((trypos_wk = ind_find_start_CORS()) != NULL) /* XXX */ | 6827 if ((trypos_wk = ind_find_start_CORS(NULL)) != NULL) /* XXX */ |
6823 { | 6828 { |
6824 ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum | 6829 ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum |
6825 - trypos_wk->lnum); | 6830 - trypos_wk->lnum); |
6826 if (ind_maxp_wk > 0) | 6831 if (ind_maxp_wk > 0) |
6827 { | 6832 { |
7187 int lookfor_cpp_namespace = FALSE; | 7192 int lookfor_cpp_namespace = FALSE; |
7188 int cont_amount = 0; /* amount for continuation line */ | 7193 int cont_amount = 0; /* amount for continuation line */ |
7189 int original_line_islabel; | 7194 int original_line_islabel; |
7190 int added_to_amount = 0; | 7195 int added_to_amount = 0; |
7191 int js_cur_has_key = 0; | 7196 int js_cur_has_key = 0; |
7197 linenr_T raw_string_start = 0; | |
7192 cpp_baseclass_cache_T cache_cpp_baseclass = { FALSE, { MAXLNUM, 0 } }; | 7198 cpp_baseclass_cache_T cache_cpp_baseclass = { FALSE, { MAXLNUM, 0 } }; |
7193 | 7199 |
7194 /* make a copy, value is changed below */ | 7200 /* make a copy, value is changed below */ |
7195 int ind_continuation = curbuf->b_ind_continuation; | 7201 int ind_continuation = curbuf->b_ind_continuation; |
7196 | 7202 |
7489 if (cin_ispreproc_cont(&l, &lnum, &amount)) | 7495 if (cin_ispreproc_cont(&l, &lnum, &amount)) |
7490 continue; /* ignore #define, #if, etc. */ | 7496 continue; /* ignore #define, #if, etc. */ |
7491 curwin->w_cursor.lnum = lnum; | 7497 curwin->w_cursor.lnum = lnum; |
7492 | 7498 |
7493 /* Skip a comment or raw string. XXX */ | 7499 /* Skip a comment or raw string. XXX */ |
7494 if ((trypos = ind_find_start_CORS()) != NULL) | 7500 if ((trypos = ind_find_start_CORS(NULL)) != NULL) |
7495 { | 7501 { |
7496 lnum = trypos->lnum + 1; | 7502 lnum = trypos->lnum + 1; |
7497 continue; | 7503 continue; |
7498 } | 7504 } |
7499 | 7505 |
7930 | 7936 |
7931 /* | 7937 /* |
7932 * If we're in a comment or raw string now, skip to | 7938 * If we're in a comment or raw string now, skip to |
7933 * the start of it. | 7939 * the start of it. |
7934 */ | 7940 */ |
7935 trypos = ind_find_start_CORS(); | 7941 trypos = ind_find_start_CORS(NULL); |
7936 if (trypos != NULL) | 7942 if (trypos != NULL) |
7937 { | 7943 { |
7938 curwin->w_cursor.lnum = trypos->lnum + 1; | 7944 curwin->w_cursor.lnum = trypos->lnum + 1; |
7939 curwin->w_cursor.col = 0; | 7945 curwin->w_cursor.col = 0; |
7940 continue; | 7946 continue; |
8050 | 8056 |
8051 l = ml_get_curline(); | 8057 l = ml_get_curline(); |
8052 | 8058 |
8053 /* If we're in a comment or raw string now, skip | 8059 /* If we're in a comment or raw string now, skip |
8054 * to the start of it. */ | 8060 * to the start of it. */ |
8055 trypos = ind_find_start_CORS(); | 8061 trypos = ind_find_start_CORS(NULL); |
8056 if (trypos != NULL) | 8062 if (trypos != NULL) |
8057 { | 8063 { |
8058 curwin->w_cursor.lnum = trypos->lnum + 1; | 8064 curwin->w_cursor.lnum = trypos->lnum + 1; |
8059 curwin->w_cursor.col = 0; | 8065 curwin->w_cursor.col = 0; |
8060 continue; | 8066 continue; |
8088 | 8094 |
8089 /* | 8095 /* |
8090 * If we're in a comment or raw string now, skip to the start | 8096 * If we're in a comment or raw string now, skip to the start |
8091 * of it. | 8097 * of it. |
8092 */ /* XXX */ | 8098 */ /* XXX */ |
8093 if ((trypos = ind_find_start_CORS()) != NULL) | 8099 if ((trypos = ind_find_start_CORS(&raw_string_start)) != NULL) |
8094 { | 8100 { |
8095 curwin->w_cursor.lnum = trypos->lnum + 1; | 8101 curwin->w_cursor.lnum = trypos->lnum + 1; |
8096 curwin->w_cursor.col = 0; | 8102 curwin->w_cursor.col = 0; |
8097 continue; | 8103 continue; |
8098 } | 8104 } |
8655 /* XXX */ | 8661 /* XXX */ |
8656 cont_amount = cin_get_equal_amount( | 8662 cont_amount = cin_get_equal_amount( |
8657 curwin->w_cursor.lnum); | 8663 curwin->w_cursor.lnum); |
8658 if (lookfor != LOOKFOR_TERM | 8664 if (lookfor != LOOKFOR_TERM |
8659 && lookfor != LOOKFOR_JS_KEY | 8665 && lookfor != LOOKFOR_JS_KEY |
8660 && lookfor != LOOKFOR_COMMA) | 8666 && lookfor != LOOKFOR_COMMA |
8667 && raw_string_start != curwin->w_cursor.lnum) | |
8661 lookfor = LOOKFOR_UNTERM; | 8668 lookfor = LOOKFOR_UNTERM; |
8662 } | 8669 } |
8663 } | 8670 } |
8664 } | 8671 } |
8665 } | 8672 } |
8936 | 8943 |
8937 /* | 8944 /* |
8938 * If we're in a comment or raw string now, skip to the start | 8945 * If we're in a comment or raw string now, skip to the start |
8939 * of it. | 8946 * of it. |
8940 */ /* XXX */ | 8947 */ /* XXX */ |
8941 if ((trypos = ind_find_start_CORS()) != NULL) | 8948 if ((trypos = ind_find_start_CORS(NULL)) != NULL) |
8942 { | 8949 { |
8943 curwin->w_cursor.lnum = trypos->lnum + 1; | 8950 curwin->w_cursor.lnum = trypos->lnum + 1; |
8944 curwin->w_cursor.col = 0; | 8951 curwin->w_cursor.col = 0; |
8945 continue; | 8952 continue; |
8946 } | 8953 } |