Mercurial > vim
comparison src/misc1.c @ 10516:09bb1836cdb5 v8.0.0148
commit https://github.com/vim/vim/commit/c6aa475a27e3ed1645446b014c32ebf68d005d49
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 7 15:39:43 2017 +0100
patch 8.0.0148: wrong indent in C preprocessor with line continuation
Problem: When a C preprocessor statement has two line continuations the
following line does not have the right indent. (Ken Takata)
Solution: Add the indent of the previous continuation line. (Hirohito
Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 07 Jan 2017 15:45:03 +0100 |
parents | 0bbbe99c8432 |
children | b726d3ea70bc |
comparison
equal
deleted
inserted
replaced
10515:9eca508ac61f | 10516:09bb1836cdb5 |
---|---|
5420 static int get_indent_nolabel(linenr_T lnum); | 5420 static int get_indent_nolabel(linenr_T lnum); |
5421 static int skip_label(linenr_T, char_u **pp); | 5421 static int skip_label(linenr_T, char_u **pp); |
5422 static int cin_first_id_amount(void); | 5422 static int cin_first_id_amount(void); |
5423 static int cin_get_equal_amount(linenr_T lnum); | 5423 static int cin_get_equal_amount(linenr_T lnum); |
5424 static int cin_ispreproc(char_u *); | 5424 static int cin_ispreproc(char_u *); |
5425 static int cin_ispreproc_cont(char_u **pp, linenr_T *lnump); | |
5426 static int cin_iscomment(char_u *); | 5425 static int cin_iscomment(char_u *); |
5427 static int cin_islinecomment(char_u *); | 5426 static int cin_islinecomment(char_u *); |
5428 static int cin_isterminated(char_u *, int, int); | 5427 static int cin_isterminated(char_u *, int, int); |
5429 static int cin_isinit(void); | 5428 static int cin_isinit(void); |
5430 static int cin_isfuncdecl(char_u **, linenr_T, linenr_T); | 5429 static int cin_isfuncdecl(char_u **, linenr_T, linenr_T); |
6000 | 5999 |
6001 /* | 6000 /* |
6002 * Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a | 6001 * Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a |
6003 * continuation line of a preprocessor statement. Decrease "*lnump" to the | 6002 * continuation line of a preprocessor statement. Decrease "*lnump" to the |
6004 * start and return the line in "*pp". | 6003 * start and return the line in "*pp". |
6004 * Put the amount of indent in "*amount". | |
6005 */ | 6005 */ |
6006 static int | 6006 static int |
6007 cin_ispreproc_cont(char_u **pp, linenr_T *lnump) | 6007 cin_ispreproc_cont(char_u **pp, linenr_T *lnump, int *amount) |
6008 { | 6008 { |
6009 char_u *line = *pp; | 6009 char_u *line = *pp; |
6010 linenr_T lnum = *lnump; | 6010 linenr_T lnum = *lnump; |
6011 int retval = FALSE; | 6011 int retval = FALSE; |
6012 int candidate_amount = *amount; | |
6013 | |
6014 if (*line != NUL && line[STRLEN(line) - 1] == '\\') | |
6015 candidate_amount = get_indent_lnum(lnum); | |
6012 | 6016 |
6013 for (;;) | 6017 for (;;) |
6014 { | 6018 { |
6015 if (cin_ispreproc(line)) | 6019 if (cin_ispreproc(line)) |
6016 { | 6020 { |
6025 break; | 6029 break; |
6026 } | 6030 } |
6027 | 6031 |
6028 if (lnum != *lnump) | 6032 if (lnum != *lnump) |
6029 *pp = ml_get(*lnump); | 6033 *pp = ml_get(*lnump); |
6034 if (retval) | |
6035 *amount = candidate_amount; | |
6030 return retval; | 6036 return retval; |
6031 } | 6037 } |
6032 | 6038 |
6033 /* | 6039 /* |
6034 * Recognize the start of a C or C++ comment. | 6040 * Recognize the start of a C or C++ comment. |
7388 for (lnum = cur_curpos.lnum - 1; lnum > our_paren_pos.lnum; --lnum) | 7394 for (lnum = cur_curpos.lnum - 1; lnum > our_paren_pos.lnum; --lnum) |
7389 { | 7395 { |
7390 l = skipwhite(ml_get(lnum)); | 7396 l = skipwhite(ml_get(lnum)); |
7391 if (cin_nocode(l)) /* skip comment lines */ | 7397 if (cin_nocode(l)) /* skip comment lines */ |
7392 continue; | 7398 continue; |
7393 if (cin_ispreproc_cont(&l, &lnum)) | 7399 if (cin_ispreproc_cont(&l, &lnum, &amount)) |
7394 continue; /* ignore #define, #if, etc. */ | 7400 continue; /* ignore #define, #if, etc. */ |
7395 curwin->w_cursor.lnum = lnum; | 7401 curwin->w_cursor.lnum = lnum; |
7396 | 7402 |
7397 /* Skip a comment or raw string. XXX */ | 7403 /* Skip a comment or raw string. XXX */ |
7398 if ((trypos = ind_find_start_CORS()) != NULL) | 7404 if ((trypos = ind_find_start_CORS()) != NULL) |
7801 * If we went all the way back to the start of our scope, line | 7807 * If we went all the way back to the start of our scope, line |
7802 * up with it. | 7808 * up with it. |
7803 */ | 7809 */ |
7804 if (curwin->w_cursor.lnum <= ourscope) | 7810 if (curwin->w_cursor.lnum <= ourscope) |
7805 { | 7811 { |
7806 /* we reached end of scope: | 7812 /* We reached end of scope: |
7807 * if looking for a enum or structure initialization | 7813 * If looking for a enum or structure initialization |
7808 * go further back: | 7814 * go further back: |
7809 * if it is an initializer (enum xxx or xxx =), then | 7815 * If it is an initializer (enum xxx or xxx =), then |
7810 * don't add ind_continuation, otherwise it is a variable | 7816 * don't add ind_continuation, otherwise it is a variable |
7811 * declaration: | 7817 * declaration: |
7812 * int x, | 7818 * int x, |
7813 * here; <-- add ind_continuation | 7819 * here; <-- add ind_continuation |
7814 */ | 7820 */ |
7843 } | 7849 } |
7844 | 7850 |
7845 /* | 7851 /* |
7846 * Skip preprocessor directives and blank lines. | 7852 * Skip preprocessor directives and blank lines. |
7847 */ | 7853 */ |
7848 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)) | 7854 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, |
7855 &amount)) | |
7849 continue; | 7856 continue; |
7850 | 7857 |
7851 if (cin_nocode(l)) | 7858 if (cin_nocode(l)) |
7852 continue; | 7859 continue; |
7853 | 7860 |
7960 curwin->w_cursor.col = 0; | 7967 curwin->w_cursor.col = 0; |
7961 continue; | 7968 continue; |
7962 } | 7969 } |
7963 | 7970 |
7964 /* Skip preprocessor directives and blank lines. */ | 7971 /* Skip preprocessor directives and blank lines. */ |
7965 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)) | 7972 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, |
7973 &amount)) | |
7966 continue; | 7974 continue; |
7967 | 7975 |
7968 /* Finally the actual check for "namespace". */ | 7976 /* Finally the actual check for "namespace". */ |
7969 if (cin_is_cpp_namespace(l)) | 7977 if (cin_is_cpp_namespace(l)) |
7970 { | 7978 { |
8136 * Ignore comment and empty lines. | 8144 * Ignore comment and empty lines. |
8137 * (need to get the line again, cin_islabel() may have | 8145 * (need to get the line again, cin_islabel() may have |
8138 * unlocked it) | 8146 * unlocked it) |
8139 */ | 8147 */ |
8140 l = ml_get_curline(); | 8148 l = ml_get_curline(); |
8141 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum) | 8149 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount) |
8142 || cin_nocode(l)) | 8150 || cin_nocode(l)) |
8143 continue; | 8151 continue; |
8144 | 8152 |
8145 /* | 8153 /* |
8146 * Are we at the start of a cpp base class declaration or | 8154 * Are we at the start of a cpp base class declaration or |
8857 } | 8865 } |
8858 | 8866 |
8859 /* | 8867 /* |
8860 * Skip preprocessor directives and blank lines. | 8868 * Skip preprocessor directives and blank lines. |
8861 */ | 8869 */ |
8862 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)) | 8870 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)) |
8863 continue; | 8871 continue; |
8864 | 8872 |
8865 if (cin_nocode(l)) | 8873 if (cin_nocode(l)) |
8866 continue; | 8874 continue; |
8867 | 8875 |
8958 | 8966 |
8959 while (curwin->w_cursor.lnum > 1) | 8967 while (curwin->w_cursor.lnum > 1) |
8960 { | 8968 { |
8961 look = ml_get(--curwin->w_cursor.lnum); | 8969 look = ml_get(--curwin->w_cursor.lnum); |
8962 if (!(cin_nocode(look) || cin_ispreproc_cont( | 8970 if (!(cin_nocode(look) || cin_ispreproc_cont( |
8963 &look, &curwin->w_cursor.lnum))) | 8971 &look, &curwin->w_cursor.lnum, &amount))) |
8964 break; | 8972 break; |
8965 } | 8973 } |
8966 if (curwin->w_cursor.lnum > 0 | 8974 if (curwin->w_cursor.lnum > 0 |
8967 && cin_ends_in(look, (char_u *)"}", NULL)) | 8975 && cin_ends_in(look, (char_u *)"}", NULL)) |
8968 break; | 8976 break; |