~ubuntu-branches/debian/sid/neovim/sid

« back to all changes in this revision

Viewing changes to src/nvim/indent_c.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2016-04-18 21:42:19 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20160418214219-1e6d4o1fwqarzk46
Tags: 0.1.3-1
* New upstream release.  (Closes: #820562)
* debian/control:
  + Remove unnecessary luarocks Build-Depends
  + Add libkvm-dev Build-Depends for kfreebsd-*
  + Add python(3)-neovim to Recommends.  (Closes: #812737)
  + Declare compiance with policy 3.9.8, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
  return pos;
70
70
}
71
71
 
72
 
/*
73
 
 * Find the start of a comment or raw string, not knowing if we are in a
74
 
 * comment or raw string right now.
75
 
 * Search starts at w_cursor.lnum and goes backwards.
76
 
 * Return NULL when not inside a comment or raw string.
77
 
 * "CORS" -> Comment Or Raw String
78
 
 */
 
72
/// Find the start of a comment or raw string, not knowing if we are in a
 
73
/// comment or raw string right now.
 
74
/// Search starts at w_cursor.lnum and goes backwards.
 
75
///
 
76
/// @returns NULL when not inside a comment or raw string.
 
77
///
 
78
/// @note "CORS" -> Comment Or Raw String
79
79
static pos_T *ind_find_start_CORS(void)
80
 
{ /* XXX */
81
 
    pos_T *comment_pos = find_start_comment(curbuf->b_ind_maxcomment);
82
 
    pos_T *rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment);
83
 
 
84
 
    /* If comment_pos is before rs_pos the raw string is inside the comment.
85
 
     * If rs_pos is before comment_pos the comment is inside the raw string. */
86
 
    if (comment_pos == NULL || (rs_pos != NULL && lt(*rs_pos, *comment_pos)))
87
 
        return rs_pos;
88
 
    return comment_pos;
 
80
{
 
81
  // XXX
 
82
  static pos_T comment_pos_copy;
 
83
 
 
84
  pos_T *comment_pos = find_start_comment(curbuf->b_ind_maxcomment);
 
85
  if (comment_pos != NULL) {
 
86
    // Need to make a copy of the static pos in findmatchlimit(),
 
87
    // calling find_start_rawstring() may change it.
 
88
    comment_pos_copy = *comment_pos;
 
89
    comment_pos = &comment_pos_copy;
 
90
  }
 
91
  pos_T *rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment);
 
92
 
 
93
  // If comment_pos is before rs_pos the raw string is inside the comment.
 
94
  // If rs_pos is before comment_pos the comment is inside the raw string.
 
95
  if (comment_pos == NULL || (rs_pos != NULL && lt(*rs_pos, *comment_pos))) {
 
96
    return rs_pos;
 
97
  }
 
98
  return comment_pos;
89
99
}
90
100
 
91
101
/*
847
857
    return FALSE;
848
858
 
849
859
  while (*s && *s != '(' && *s != ';' && *s != '\'' && *s != '"') {
850
 
    if (cin_iscomment(s))       /* ignore comments */
 
860
    // ignore comments
 
861
    if (cin_iscomment(s)) {
851
862
      s = cin_skipcomment(s);
852
 
    else
853
 
      ++s;
854
 
  }
855
 
  if (*s != '(')
856
 
    return FALSE;               /* ';', ' or "  before any () or no '(' */
 
863
    } else if (*s == ':') {
 
864
      if (*(s + 1) == ':') {
 
865
        s += 2;
 
866
      } else {
 
867
        // To avoid a mistake in the following situation:
 
868
        // A::A(int a, int b)
 
869
        //     : a(0)  // <--not a function decl
 
870
        //     , b(0)
 
871
        // {...
 
872
        return false;
 
873
      }
 
874
    } else {
 
875
      s++;
 
876
    }
 
877
  }
 
878
  if (*s != '(') {
 
879
    return false;  // ';', ' or "  before any () or no '('
 
880
  }
857
881
 
858
882
  while (*s && *s != ';' && *s != '\'' && *s != '"') {
859
883
    if (*s == ')' && cin_nocode(s + 1)) {
1122
1146
 
1123
1147
  pos->lnum = lnum;
1124
1148
  line = ml_get(lnum);
1125
 
  s = cin_skipcomment(line);
 
1149
  s = line;
1126
1150
  for (;; ) {
1127
1151
    if (*s == NUL) {
1128
 
      if (lnum == curwin->w_cursor.lnum)
 
1152
      if (lnum == curwin->w_cursor.lnum) {
1129
1153
        break;
1130
 
      /* Continue in the cursor line. */
 
1154
      }
 
1155
      // Continue in the cursor line.
1131
1156
      line = ml_get(++lnum);
 
1157
      s = line;
 
1158
    }
 
1159
    if (s == line) {
 
1160
      // don't recognize "case (foo):" as a baseclass */
 
1161
      if (cin_iscase(s, false)) {
 
1162
        break;
 
1163
      }
1132
1164
      s = cin_skipcomment(line);
1133
1165
      if (*s == NUL)
1134
1166
        continue;
2707
2739
 
2708
2740
          if (terminated == 0 || (lookfor != LOOKFOR_UNTERM
2709
2741
                                  && terminated == ',')) {
2710
 
            if (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '[') {
 
2742
            if (lookfor != LOOKFOR_ENUM_OR_INIT
 
2743
                && (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '[')) {
2711
2744
              amount += ind_continuation;
2712
2745
            }
2713
2746
            // If we're in the middle of a paren thing, Go back to the line
2915
2948
                  continue;
2916
2949
                }
2917
2950
 
2918
 
                /* Ignore unterminated lines in between, but
2919
 
                 * reduce indent. */
2920
 
                if (amount > cur_amount)
 
2951
                // Ignore unterminated lines in between, but
 
2952
                // reduce indent.
 
2953
                if (amount > cur_amount) {
2921
2954
                  amount = cur_amount;
 
2955
                }
2922
2956
              } else {
2923
 
                /*
2924
 
                 * Found first unterminated line on a row, may
2925
 
                 * line up with this line, remember its indent
2926
 
                 *          100 +
2927
 
                 * ->       here;
2928
 
                 */
 
2957
                // Found first unterminated line on a row, may
 
2958
                // line up with this line, remember its indent
 
2959
                //          100 +  //  NOLINT(whitespace/tab)
 
2960
                // ->       here;  //  NOLINT(whitespace/tab)
2929
2961
                l = get_cursor_line_ptr();
2930
2962
                amount = cur_amount;
2931
 
                if (*skipwhite(l) == ']' || l[STRLEN(l) - 1] == ']') {
 
2963
 
 
2964
                n = (int)STRLEN(l);
 
2965
                if (terminated == ','
 
2966
                    && (*skipwhite(l) == ']'
 
2967
                        || (n >=2 && l[n - 2] == ']'))) {
2932
2968
                  break;
2933
2969
                }
2934
2970
 
2935
 
                /*
2936
 
                 * If previous line ends in ',', check whether we
2937
 
                 * are in an initialization or enum
2938
 
                 * struct xxx =
2939
 
                 * {
2940
 
                 *      sizeof a,
2941
 
                 *      124 };
2942
 
                 * or a normal possible continuation line.
2943
 
                 * but only, of no other statement has been found
2944
 
                 * yet.
2945
 
                 */
 
2971
                // If previous line ends in ',', check whether we
 
2972
                // are in an initialization or enum
 
2973
                // struct xxx =
 
2974
                // {
 
2975
                //      sizeof a,
 
2976
                //      124 };
 
2977
                // or a normal possible continuation line.
 
2978
                // but only, of no other statement has been found
 
2979
                // yet.
2946
2980
                if (lookfor == LOOKFOR_INITIAL && terminated == ',') {
2947
2981
                  if (curbuf->b_ind_js) {
2948
2982
                    // Search for a line ending in a comma