From 3b472e55b327dc1c4fc034c665398e70d0f7dc77 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Tue, 3 Nov 2015 22:04:15 +0100 Subject: vim-patch:7.4.803 Problem: C indent does not support C11 raw strings. (Mark Lodato) Solution: Do not change indent inside the raw string. https://github.com/vim/vim/commit/f7bb86dc593913d055e4cce16cec43f6271adda3 --- src/nvim/search.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 9 deletions(-) (limited to 'src/nvim/search.c') diff --git a/src/nvim/search.c b/src/nvim/search.c index fb7dfa350b..fa078dfcbf 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1442,20 +1442,69 @@ static int check_prevcol(char_u *linep, int col, int ch, int *prevcol) return (col >= 0 && linep[col] == ch) ? TRUE : FALSE; } +/* + * Raw string start is found at linep[startpos.col - 1]. + * Return TRUE if the matching end can be found between startpos and endpos. + */ + static int +find_rawstring_end(linep, startpos, endpos) + char_u *linep; + pos_T *startpos; + pos_T *endpos; +{ + char_u *p; + char_u *delim_copy; + size_t delim_len; + linenr_T lnum; + int found = FALSE; + + for (p = linep + startpos->col + 1; *p && *p != '('; ++p) + ; + delim_len = (p - linep) - startpos->col - 1; + delim_copy = vim_strnsave(linep + startpos->col + 1, delim_len); + if (delim_copy == NULL) + return FALSE; + for (lnum = startpos->lnum; lnum <= endpos->lnum; ++lnum) + { + char_u *line = ml_get(lnum); + + for (p = line + (lnum == startpos->lnum + ? startpos->col + 1 : 0); *p; ++p) + { + if (lnum == endpos->lnum && (colnr_T)(p - line) >= endpos->col) + break; + if (*p == ')' && p[delim_len + 1] == '"' + && STRNCMP(delim_copy, p + 1, delim_len) == 0) + { + found = TRUE; + break; + } + } + if (found) + break; + } + xfree(delim_copy); + return found; +} + /* * findmatchlimit -- find the matching paren or brace, if it exists within - * maxtravel lines of here. A maxtravel of 0 means search until falling off - * the edge of the file. + * maxtravel lines of the cursor. A maxtravel of 0 means search until falling + * off the edge of the file. * * "initc" is the character to find a match for. NUL means to find the - * character at or after the cursor. + * character at or after the cursor. Special values: + * '*' look for C-style comment / * + * '/' look for C-style comment / *, ignoring comment-end + * '#' look for preprocessor directives + * 'R' look for raw string start: R"delim(text)delim" (only backwards) * * flags: FM_BACKWARD search backwards (when initc is '/', '*' or '#') * FM_FORWARD search forwards (when initc is '/', '*' or '#') * FM_BLOCKSTOP stop at start/end of block ({ or } in column 0) * FM_SKIPCOMM skip comments (not implemented yet!) * - * "oap" is only used to set oap->motion_type for a linewise motion, it be + * "oap" is only used to set oap->motion_type for a linewise motion, it can be * NULL */ @@ -1466,6 +1515,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) int c; int count = 0; /* cumulative number of braces */ int backwards = FALSE; /* init for gcc */ + int raw_string = FALSE; /* search for raw string */ int inquote = FALSE; /* TRUE when inside quotes */ char_u *linep; /* pointer to current line */ char_u *ptr; @@ -1506,22 +1556,23 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) * When '/' is used, we ignore running backwards into a star-slash, for * "[*" command, we just want to find any comment. */ - if (initc == '/' || initc == '*') { + if (initc == '/' || initc == '*' || initc == 'R') { comment_dir = dir; if (initc == '/') ignore_cend = TRUE; backwards = (dir == FORWARD) ? FALSE : TRUE; + raw_string = (initc == 'R'); initc = NUL; } else if (initc != '#' && initc != NUL) { find_mps_values(&initc, &findc, &backwards, TRUE); if (findc == NUL) return NULL; } - /* - * Either initc is '#', or no initc was given and we need to look under the - * cursor. - */ else { + /* + * Either initc is '#', or no initc was given and we need to look + * under the cursor. + */ if (initc == '#') { hash_dir = dir; } else { @@ -1766,6 +1817,26 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) */ if (pos.col == 0) continue; + else if (raw_string) + { + if (linep[pos.col - 1] == 'R' + && linep[pos.col] == '"' + && vim_strchr(linep + pos.col + 1, '(') != NULL) + { + /* Possible start of raw string. Now that we have the + * delimiter we can check if it ends before where we + * started searching, or before the previously found + * raw string start. */ + if (!find_rawstring_end(linep, &pos, + count > 0 ? &match_pos : &curwin->w_cursor)) + { + count++; + match_pos = pos; + match_pos.col--; + } + linep = ml_get(pos.lnum); /* may have been released */ + } + } else if ( linep[pos.col - 1] == '/' && linep[pos.col] == '*' && (int)pos.col < comment_col) { -- cgit From c3ac16cfebde54c32b6d900743b413d460523dfb Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Wed, 4 Nov 2015 02:31:17 +0100 Subject: Solve warnings. --- src/nvim/search.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/nvim/search.c') diff --git a/src/nvim/search.c b/src/nvim/search.c index fa078dfcbf..7dd3a5d219 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1444,13 +1444,9 @@ static int check_prevcol(char_u *linep, int col, int ch, int *prevcol) /* * Raw string start is found at linep[startpos.col - 1]. - * Return TRUE if the matching end can be found between startpos and endpos. + * Return true if the matching end can be found between startpos and endpos. */ - static int -find_rawstring_end(linep, startpos, endpos) - char_u *linep; - pos_T *startpos; - pos_T *endpos; +static int find_rawstring_end(char_u *linep, pos_T *startpos, pos_T *endpos) { char_u *p; char_u *delim_copy; -- cgit From ad34a376eb164852d2983341a9137a1e06a24bb9 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Wed, 4 Nov 2015 02:44:45 +0100 Subject: Fix linting errors. --- src/nvim/search.c | 78 +++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 40 deletions(-) (limited to 'src/nvim/search.c') diff --git a/src/nvim/search.c b/src/nvim/search.c index 7dd3a5d219..18a72524cb 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1448,39 +1448,39 @@ static int check_prevcol(char_u *linep, int col, int ch, int *prevcol) */ static int find_rawstring_end(char_u *linep, pos_T *startpos, pos_T *endpos) { - char_u *p; - char_u *delim_copy; - size_t delim_len; - linenr_T lnum; - int found = FALSE; - - for (p = linep + startpos->col + 1; *p && *p != '('; ++p) - ; - delim_len = (p - linep) - startpos->col - 1; - delim_copy = vim_strnsave(linep + startpos->col + 1, delim_len); - if (delim_copy == NULL) - return FALSE; - for (lnum = startpos->lnum; lnum <= endpos->lnum; ++lnum) + char_u *p; + char_u *delim_copy; + size_t delim_len; + linenr_T lnum; + int found = false; + + for (p = linep + startpos->col + 1; *p && *p != '('; ++p) {} + + delim_len = (p - linep) - startpos->col - 1; + delim_copy = vim_strnsave(linep + startpos->col + 1, delim_len); + if (delim_copy == NULL) + return false; + for (lnum = startpos->lnum; lnum <= endpos->lnum; ++lnum) + { + char_u *line = ml_get(lnum); + + for (p = line + (lnum == startpos->lnum + ? startpos->col + 1 : 0); *p; ++p) { - char_u *line = ml_get(lnum); - - for (p = line + (lnum == startpos->lnum - ? startpos->col + 1 : 0); *p; ++p) - { - if (lnum == endpos->lnum && (colnr_T)(p - line) >= endpos->col) - break; - if (*p == ')' && p[delim_len + 1] == '"' - && STRNCMP(delim_copy, p + 1, delim_len) == 0) - { - found = TRUE; - break; - } - } - if (found) - break; + if (lnum == endpos->lnum && (colnr_T)(p - line) >= endpos->col) + break; + if (*p == ')' && p[delim_len + 1] == '"' + && STRNCMP(delim_copy, p + 1, delim_len) == 0) + { + found = true; + break; + } } - xfree(delim_copy); - return found; + if (found) + break; + } + xfree(delim_copy); + return found; } /* @@ -1510,9 +1510,9 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) int findc = 0; /* matching brace */ int c; int count = 0; /* cumulative number of braces */ - int backwards = FALSE; /* init for gcc */ - int raw_string = FALSE; /* search for raw string */ - int inquote = FALSE; /* TRUE when inside quotes */ + int backwards = false; /* init for gcc */ + int raw_string = false; /* search for raw string */ + int inquote = false; /* true when inside quotes */ char_u *linep; /* pointer to current line */ char_u *ptr; int do_quotes; /* check for quotes in current line */ @@ -1555,16 +1555,15 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) if (initc == '/' || initc == '*' || initc == 'R') { comment_dir = dir; if (initc == '/') - ignore_cend = TRUE; - backwards = (dir == FORWARD) ? FALSE : TRUE; + ignore_cend = true; + backwards = (dir == FORWARD) ? false : true; raw_string = (initc == 'R'); initc = NUL; } else if (initc != '#' && initc != NUL) { find_mps_values(&initc, &findc, &backwards, TRUE); if (findc == NUL) return NULL; - } - else { + } else { /* * Either initc is '#', or no initc was given and we need to look * under the cursor. @@ -1832,8 +1831,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) } linep = ml_get(pos.lnum); /* may have been released */ } - } - else if ( linep[pos.col - 1] == '/' + } else if ( linep[pos.col - 1] == '/' && linep[pos.col] == '*' && (int)pos.col < comment_col) { count++; -- cgit