Mercurial > vim
comparison src/misc1.c @ 11087:242e0617aa51 v8.0.0431
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
commit https://github.com/vim/vim/commit/7720ba8599162fbbb8f7fc034f674a2ccd3ca7f1
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Mar 8 22:19:26 2017 +0100
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Problem: 'cinoptions' cannot set indent for extern block.
Solution: Add the "E" flag in 'cinoptions'. (Hirohito Higashi)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 08 Mar 2017 22:30:05 +0100 |
parents | 814126a34c9d |
children | 778c10516955 |
comparison
equal
deleted
inserted
replaced
11086:f283d02368ac | 11087:242e0617aa51 |
---|---|
5808 } | 5808 } |
5809 return FALSE; | 5809 return FALSE; |
5810 } | 5810 } |
5811 | 5811 |
5812 /* | 5812 /* |
5813 * Recognize a `extern "C"` or `extern "C++"` linkage specifications. | |
5814 */ | |
5815 static int | |
5816 cin_is_cpp_extern_c(char_u *s) | |
5817 { | |
5818 char_u *p; | |
5819 int has_string_literal = FALSE; | |
5820 | |
5821 s = cin_skipcomment(s); | |
5822 if (STRNCMP(s, "extern", 6) == 0 && (s[6] == NUL || !vim_iswordc(s[6]))) | |
5823 { | |
5824 p = cin_skipcomment(skipwhite(s + 6)); | |
5825 while (*p != NUL) | |
5826 { | |
5827 if (vim_iswhite(*p)) | |
5828 { | |
5829 p = cin_skipcomment(skipwhite(p)); | |
5830 } | |
5831 else if (*p == '{') | |
5832 { | |
5833 break; | |
5834 } | |
5835 else if (p[0] == '"' && p[1] == 'C' && p[2] == '"') | |
5836 { | |
5837 if (has_string_literal) | |
5838 return FALSE; | |
5839 has_string_literal = TRUE; | |
5840 p += 3; | |
5841 } | |
5842 else if (p[0] == '"' && p[1] == 'C' && p[2] == '+' && p[3] == '+' | |
5843 && p[4] == '"') | |
5844 { | |
5845 if (has_string_literal) | |
5846 return FALSE; | |
5847 has_string_literal = TRUE; | |
5848 p += 5; | |
5849 } | |
5850 else | |
5851 { | |
5852 return FALSE; | |
5853 } | |
5854 } | |
5855 return has_string_literal ? TRUE : FALSE; | |
5856 } | |
5857 return FALSE; | |
5858 } | |
5859 | |
5860 /* | |
5813 * Return a pointer to the first non-empty non-comment character after a ':'. | 5861 * Return a pointer to the first non-empty non-comment character after a ':'. |
5814 * Return NULL if not found. | 5862 * Return NULL if not found. |
5815 * case 234: a = b; | 5863 * case 234: a = b; |
5816 * ^ | 5864 * ^ |
5817 */ | 5865 */ |
6650 static int | 6698 static int |
6651 cin_skip2pos(pos_T *trypos) | 6699 cin_skip2pos(pos_T *trypos) |
6652 { | 6700 { |
6653 char_u *line; | 6701 char_u *line; |
6654 char_u *p; | 6702 char_u *p; |
6703 char_u *new_p; | |
6655 | 6704 |
6656 p = line = ml_get(trypos->lnum); | 6705 p = line = ml_get(trypos->lnum); |
6657 while (*p && (colnr_T)(p - line) < trypos->col) | 6706 while (*p && (colnr_T)(p - line) < trypos->col) |
6658 { | 6707 { |
6659 if (cin_iscomment(p)) | 6708 if (cin_iscomment(p)) |
6660 p = cin_skipcomment(p); | 6709 p = cin_skipcomment(p); |
6661 else | 6710 else |
6662 { | 6711 { |
6663 p = skip_string(p); | 6712 new_p = skip_string(p); |
6664 ++p; | 6713 if (new_p == p) |
6714 ++p; | |
6715 else | |
6716 p = new_p; | |
6665 } | 6717 } |
6666 } | 6718 } |
6667 return (int)(p - line); | 6719 return (int)(p - line); |
6668 } | 6720 } |
6669 | 6721 |
6974 * while(). */ | 7026 * while(). */ |
6975 buf->b_ind_if_for_while = 0; | 7027 buf->b_ind_if_for_while = 0; |
6976 | 7028 |
6977 /* indentation for # comments */ | 7029 /* indentation for # comments */ |
6978 buf->b_ind_hash_comment = 0; | 7030 buf->b_ind_hash_comment = 0; |
7031 | |
7032 /* Handle C++ extern "C" or "C++" */ | |
7033 buf->b_ind_cpp_extern_c = 0; | |
6979 | 7034 |
6980 for (p = buf->b_p_cino; *p; ) | 7035 for (p = buf->b_p_cino; *p; ) |
6981 { | 7036 { |
6982 l = p++; | 7037 l = p++; |
6983 if (*p == '-') | 7038 if (*p == '-') |
7049 case 'J': buf->b_ind_js = n; break; | 7104 case 'J': buf->b_ind_js = n; break; |
7050 case 'l': buf->b_ind_keep_case_label = n; break; | 7105 case 'l': buf->b_ind_keep_case_label = n; break; |
7051 case '#': buf->b_ind_hash_comment = n; break; | 7106 case '#': buf->b_ind_hash_comment = n; break; |
7052 case 'N': buf->b_ind_cpp_namespace = n; break; | 7107 case 'N': buf->b_ind_cpp_namespace = n; break; |
7053 case 'k': buf->b_ind_if_for_while = n; break; | 7108 case 'k': buf->b_ind_if_for_while = n; break; |
7109 case 'E': buf->b_ind_cpp_extern_c = n; break; | |
7054 } | 7110 } |
7055 if (*p == ',') | 7111 if (*p == ',') |
7056 ++p; | 7112 ++p; |
7057 } | 7113 } |
7058 } | 7114 } |
7762 amount += curbuf->b_ind_open_imag; | 7818 amount += curbuf->b_ind_open_imag; |
7763 | 7819 |
7764 l = skipwhite(ml_get_curline()); | 7820 l = skipwhite(ml_get_curline()); |
7765 if (cin_is_cpp_namespace(l)) | 7821 if (cin_is_cpp_namespace(l)) |
7766 amount += curbuf->b_ind_cpp_namespace; | 7822 amount += curbuf->b_ind_cpp_namespace; |
7823 else if (cin_is_cpp_extern_c(l)) | |
7824 amount += curbuf->b_ind_cpp_extern_c; | |
7767 } | 7825 } |
7768 else | 7826 else |
7769 { | 7827 { |
7770 /* Compensate for adding b_ind_open_extra later. */ | 7828 /* Compensate for adding b_ind_open_extra later. */ |
7771 amount -= curbuf->b_ind_open_extra; | 7829 amount -= curbuf->b_ind_open_extra; |
7985 | 8043 |
7986 /* Finally the actual check for "namespace". */ | 8044 /* Finally the actual check for "namespace". */ |
7987 if (cin_is_cpp_namespace(l)) | 8045 if (cin_is_cpp_namespace(l)) |
7988 { | 8046 { |
7989 amount += curbuf->b_ind_cpp_namespace | 8047 amount += curbuf->b_ind_cpp_namespace |
8048 - added_to_amount; | |
8049 break; | |
8050 } | |
8051 else if (cin_is_cpp_extern_c(l)) | |
8052 { | |
8053 amount += curbuf->b_ind_cpp_extern_c | |
7990 - added_to_amount; | 8054 - added_to_amount; |
7991 break; | 8055 break; |
7992 } | 8056 } |
7993 | 8057 |
7994 if (cin_nocode(l)) | 8058 if (cin_nocode(l)) |