Mercurial > vim
comparison src/misc1.c @ 7160:accd3a0e9bf4 v7.4.891
commit https://github.com/vim/vim/commit/089af18d1fd0961ff504ee72db0156bbfe509cdf
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Oct 7 11:41:49 2015 +0200
patch 7.4.891
Problem: Indentation of array initializer is wrong.
Solution: Avoid that calling find_start_rawstring() changes the position
returned by find_start_comment(), add a test. (Hirohito Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 07 Oct 2015 11:45:06 +0200 |
parents | 6bc1695b7f11 |
children | d3c57e7f489a |
comparison
equal
deleted
inserted
replaced
7159:1f1b4b6581d2 | 7160:accd3a0e9bf4 |
---|---|
5343 * "CORS" -> Comment Or Raw String | 5343 * "CORS" -> Comment Or Raw String |
5344 */ | 5344 */ |
5345 static pos_T * | 5345 static pos_T * |
5346 ind_find_start_CORS() /* XXX */ | 5346 ind_find_start_CORS() /* XXX */ |
5347 { | 5347 { |
5348 pos_T *comment_pos = find_start_comment(curbuf->b_ind_maxcomment); | 5348 static pos_T comment_pos_copy; |
5349 pos_T *rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment); | 5349 pos_T *comment_pos; |
5350 pos_T *rs_pos; | |
5351 | |
5352 comment_pos = find_start_comment(curbuf->b_ind_maxcomment); | |
5353 if (comment_pos != NULL) | |
5354 { | |
5355 /* Need to make a copy of the static pos in findmatchlimit(), | |
5356 * calling find_start_rawstring() may change it. */ | |
5357 comment_pos_copy = *comment_pos; | |
5358 comment_pos = &comment_pos_copy; | |
5359 } | |
5360 rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment); | |
5350 | 5361 |
5351 /* If comment_pos is before rs_pos the raw string is inside the comment. | 5362 /* If comment_pos is before rs_pos the raw string is inside the comment. |
5352 * If rs_pos is before comment_pos the comment is inside the raw string. */ | 5363 * If rs_pos is before comment_pos the comment is inside the raw string. */ |
5353 if (comment_pos == NULL || (rs_pos != NULL && lt(*rs_pos, *comment_pos))) | 5364 if (comment_pos == NULL || (rs_pos != NULL && lt(*rs_pos, *comment_pos))) |
5354 return rs_pos; | 5365 return rs_pos; |
8332 } | 8343 } |
8333 | 8344 |
8334 if (terminated == 0 || (lookfor != LOOKFOR_UNTERM | 8345 if (terminated == 0 || (lookfor != LOOKFOR_UNTERM |
8335 && terminated == ',')) | 8346 && terminated == ',')) |
8336 { | 8347 { |
8337 if (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '[') | 8348 if (lookfor != LOOKFOR_ENUM_OR_INIT && |
8349 (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '[')) | |
8338 amount += ind_continuation; | 8350 amount += ind_continuation; |
8339 /* | 8351 /* |
8340 * if we're in the middle of a paren thing, | 8352 * if we're in the middle of a paren thing, |
8341 * go back to the line that starts it so | 8353 * go back to the line that starts it so |
8342 * we can get the right prevailing indent | 8354 * we can get the right prevailing indent |
8574 * 100 + | 8586 * 100 + |
8575 * -> here; | 8587 * -> here; |
8576 */ | 8588 */ |
8577 l = ml_get_curline(); | 8589 l = ml_get_curline(); |
8578 amount = cur_amount; | 8590 amount = cur_amount; |
8579 if (*skipwhite(l) == ']' || l[STRLEN(l) - 1] == ']') | 8591 |
8592 n = (int)STRLEN(l); | |
8593 if (terminated == ',' && (*skipwhite(l) == ']' | |
8594 || (n >=2 && l[n - 2] == ']'))) | |
8580 break; | 8595 break; |
8581 | 8596 |
8582 /* | 8597 /* |
8583 * If previous line ends in ',', check whether we | 8598 * If previous line ends in ',', check whether we |
8584 * are in an initialization or enum | 8599 * are in an initialization or enum |