To: vim_dev@googlegroups.com Subject: Patch 8.0.0999 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.0999 Problem: Indenting raw C++ strings is wrong. Solution: Add special handling of raw strings. (Christian Brabandt) Files: src/misc1.c, src/testdir/test_cindent.vim *** ../vim-8.0.0998/src/misc1.c 2017-08-06 18:15:40.349643148 +0200 --- src/misc1.c 2017-08-26 17:42:25.789536680 +0200 *************** *** 5221,5227 **** static char_u *skip_string(char_u *p); static pos_T *ind_find_start_comment(void); ! static pos_T *ind_find_start_CORS(void); static pos_T *find_start_rawstring(int ind_maxcomment); /* --- 5221,5227 ---- static char_u *skip_string(char_u *p); static pos_T *ind_find_start_comment(void); ! static pos_T *ind_find_start_CORS(linenr_T *is_raw); static pos_T *find_start_rawstring(int ind_maxcomment); /* *************** *** 5272,5282 **** * Find the start of a comment or raw string, not knowing if we are in a * comment or raw string right now. * Search starts at w_cursor.lnum and goes backwards. * Return NULL when not inside a comment or raw string. * "CORS" -> Comment Or Raw String */ static pos_T * ! ind_find_start_CORS(void) /* XXX */ { static pos_T comment_pos_copy; pos_T *comment_pos; --- 5272,5283 ---- * Find the start of a comment or raw string, not knowing if we are in a * comment or raw string right now. * Search starts at w_cursor.lnum and goes backwards. + * If is_raw is given and returns start of raw_string, sets it to true. * Return NULL when not inside a comment or raw string. * "CORS" -> Comment Or Raw String */ static pos_T * ! ind_find_start_CORS(linenr_T *is_raw) /* XXX */ { static pos_T comment_pos_copy; pos_T *comment_pos; *************** *** 5296,5302 **** --- 5297,5307 ---- * If rs_pos is before comment_pos the comment is inside the raw string. */ if (comment_pos == NULL || (rs_pos != NULL && LT_POS(*rs_pos, *comment_pos))) + { + if (is_raw != NULL && rs_pos != NULL) + *is_raw = rs_pos->lnum; return rs_pos; + } return comment_pos; } *************** *** 5641,5647 **** * it. */ curwin->w_cursor.col = 0; ! if ((trypos = ind_find_start_CORS()) != NULL) /* XXX */ curwin->w_cursor = *trypos; line = ml_get_curline(); --- 5646,5652 ---- * it. */ curwin->w_cursor.col = 0; ! if ((trypos = ind_find_start_CORS(NULL)) != NULL) /* XXX */ curwin->w_cursor = *trypos; line = ml_get_curline(); *************** *** 6768,6774 **** pos = NULL; /* ignore the { if it's in a // or / * * / comment */ if ((colnr_T)cin_skip2pos(trypos) == trypos->col ! && (pos = ind_find_start_CORS()) == NULL) /* XXX */ break; if (pos != NULL) curwin->w_cursor.lnum = pos->lnum; --- 6773,6779 ---- pos = NULL; /* ignore the { if it's in a // or / * * / comment */ if ((colnr_T)cin_skip2pos(trypos) == trypos->col ! && (pos = ind_find_start_CORS(NULL)) == NULL) /* XXX */ break; if (pos != NULL) curwin->w_cursor.lnum = pos->lnum; *************** *** 6819,6825 **** pos_copy = *trypos; /* copy trypos, findmatch will change it */ trypos = &pos_copy; curwin->w_cursor = *trypos; ! if ((trypos_wk = ind_find_start_CORS()) != NULL) /* XXX */ { ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum - trypos_wk->lnum); --- 6824,6830 ---- pos_copy = *trypos; /* copy trypos, findmatch will change it */ trypos = &pos_copy; curwin->w_cursor = *trypos; ! if ((trypos_wk = ind_find_start_CORS(NULL)) != NULL) /* XXX */ { ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum - trypos_wk->lnum); *************** *** 7189,7194 **** --- 7194,7200 ---- int original_line_islabel; int added_to_amount = 0; int js_cur_has_key = 0; + linenr_T raw_string_start = 0; cpp_baseclass_cache_T cache_cpp_baseclass = { FALSE, { MAXLNUM, 0 } }; /* make a copy, value is changed below */ *************** *** 7491,7497 **** curwin->w_cursor.lnum = lnum; /* Skip a comment or raw string. XXX */ ! if ((trypos = ind_find_start_CORS()) != NULL) { lnum = trypos->lnum + 1; continue; --- 7497,7503 ---- curwin->w_cursor.lnum = lnum; /* Skip a comment or raw string. XXX */ ! if ((trypos = ind_find_start_CORS(NULL)) != NULL) { lnum = trypos->lnum + 1; continue; *************** *** 7932,7938 **** * If we're in a comment or raw string now, skip to * the start of it. */ ! trypos = ind_find_start_CORS(); if (trypos != NULL) { curwin->w_cursor.lnum = trypos->lnum + 1; --- 7938,7944 ---- * If we're in a comment or raw string now, skip to * the start of it. */ ! trypos = ind_find_start_CORS(NULL); if (trypos != NULL) { curwin->w_cursor.lnum = trypos->lnum + 1; *************** *** 8052,8058 **** /* If we're in a comment or raw string now, skip * to the start of it. */ ! trypos = ind_find_start_CORS(); if (trypos != NULL) { curwin->w_cursor.lnum = trypos->lnum + 1; --- 8058,8064 ---- /* If we're in a comment or raw string now, skip * to the start of it. */ ! trypos = ind_find_start_CORS(NULL); if (trypos != NULL) { curwin->w_cursor.lnum = trypos->lnum + 1; *************** *** 8090,8096 **** * If we're in a comment or raw string now, skip to the start * of it. */ /* XXX */ ! if ((trypos = ind_find_start_CORS()) != NULL) { curwin->w_cursor.lnum = trypos->lnum + 1; curwin->w_cursor.col = 0; --- 8096,8102 ---- * If we're in a comment or raw string now, skip to the start * of it. */ /* XXX */ ! if ((trypos = ind_find_start_CORS(&raw_string_start)) != NULL) { curwin->w_cursor.lnum = trypos->lnum + 1; curwin->w_cursor.col = 0; *************** *** 8657,8663 **** curwin->w_cursor.lnum); if (lookfor != LOOKFOR_TERM && lookfor != LOOKFOR_JS_KEY ! && lookfor != LOOKFOR_COMMA) lookfor = LOOKFOR_UNTERM; } } --- 8663,8670 ---- curwin->w_cursor.lnum); if (lookfor != LOOKFOR_TERM && lookfor != LOOKFOR_JS_KEY ! && lookfor != LOOKFOR_COMMA ! && raw_string_start != curwin->w_cursor.lnum) lookfor = LOOKFOR_UNTERM; } } *************** *** 8938,8944 **** * If we're in a comment or raw string now, skip to the start * of it. */ /* XXX */ ! if ((trypos = ind_find_start_CORS()) != NULL) { curwin->w_cursor.lnum = trypos->lnum + 1; curwin->w_cursor.col = 0; --- 8945,8951 ---- * If we're in a comment or raw string now, skip to the start * of it. */ /* XXX */ ! if ((trypos = ind_find_start_CORS(NULL)) != NULL) { curwin->w_cursor.lnum = trypos->lnum + 1; curwin->w_cursor.col = 0; *** ../vim-8.0.0998/src/testdir/test_cindent.vim 2017-03-08 22:19:21.717870787 +0100 --- src/testdir/test_cindent.vim 2017-08-26 17:42:25.789536680 +0200 *************** *** 68,76 **** call assert_equal(pair[2], getline(len(lines) + 1), 'Failed for "' . string(lines) . '"') endfor - - bwipe! endfunc " vim: shiftwidth=2 sts=2 expandtab --- 68,85 ---- call assert_equal(pair[2], getline(len(lines) + 1), 'Failed for "' . string(lines) . '"') endfor bwipe! endfunc + func! Test_cindent_rawstring() + new + setl cindent + call feedkeys("i" . + \ "int main() {\" . + \ "R\"(\" . + \ ")\";\" . + \ "statement;\", "x") + call assert_equal("\tstatement;", getline(line('.'))) + bw! + endfunction " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.0.0998/src/version.c 2017-08-26 16:25:28.747075616 +0200 --- src/version.c 2017-08-26 17:45:13.336449327 +0200 *************** *** 771,772 **** --- 771,774 ---- { /* Add new patch number below this line */ + /**/ + 999, /**/ -- I have a drinking problem -- I can't afford it. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///