comparison src/syntax.c @ 1624:18ee39301b82 v7.2a

updated for version 7.2a
author vimboss
date Tue, 24 Jun 2008 22:58:06 +0000
parents cc4fe241baa3
children 2f9308b31181
comparison
equal deleted inserted replaced
1623:53938adac247 1624:18ee39301b82
3014 synpat_T *spp; /* matched pattern */ 3014 synpat_T *spp; /* matched pattern */
3015 int idx; /* index of offset */ 3015 int idx; /* index of offset */
3016 int extra; /* extra chars for offset to start */ 3016 int extra; /* extra chars for offset to start */
3017 { 3017 {
3018 int col; 3018 int col;
3019 int len; 3019 int off;
3020 char_u *base;
3021 char_u *p;
3020 3022
3021 if (spp->sp_off_flags & (1 << idx)) 3023 if (spp->sp_off_flags & (1 << idx))
3022 { 3024 {
3023 result->lnum = regmatch->startpos[0].lnum; 3025 result->lnum = regmatch->startpos[0].lnum;
3024 col = regmatch->startpos[0].col + extra; 3026 col = regmatch->startpos[0].col;
3027 off = spp->sp_offsets[idx] + extra;
3025 } 3028 }
3026 else 3029 else
3027 { 3030 {
3028 result->lnum = regmatch->endpos[0].lnum; 3031 result->lnum = regmatch->endpos[0].lnum;
3029 col = regmatch->endpos[0].col; 3032 col = regmatch->endpos[0].col;
3030 } 3033 off = spp->sp_offsets[idx];
3031 col += spp->sp_offsets[idx]; 3034 }
3032 if (col < 0) 3035 /* Don't go past the end of the line. Matters for "rs=e+2" when there
3033 result->col = 0; 3036 * is a matchgroup. Watch out for match with last NL in the buffer. */
3034 else 3037 if (result->lnum > syn_buf->b_ml.ml_line_count)
3035 { 3038 col = 0;
3036 /* Don't go past the end of the line. Matters for "rs=e+2" when there 3039 else if (off != 0)
3037 * is a matchgroup. Watch out for match with last NL in the buffer. */ 3040 {
3038 if (result->lnum > syn_buf->b_ml.ml_line_count) 3041 base = ml_get_buf(syn_buf, result->lnum, FALSE);
3039 len = 0; 3042 p = base + col;
3040 else 3043 if (off > 0)
3041 len = (int)STRLEN(ml_get_buf(syn_buf, result->lnum, FALSE)); 3044 {
3042 if (col > len) 3045 while (off-- > 0 && *p != NUL)
3043 result->col = len; 3046 mb_ptr_adv(p);
3044 else 3047 }
3045 result->col = col; 3048 else if (off < 0)
3046 } 3049 {
3050 while (off++ < 0 && base < p)
3051 mb_ptr_back(base, p);
3052 }
3053 col = (int)(p - base);
3054 }
3055 result->col = col;
3047 } 3056 }
3048 3057
3049 /* 3058 /*
3050 * Add offset to matched text for start of match or highlight. 3059 * Add offset to matched text for start of match or highlight.
3051 * Avoid resulting column to become negative. 3060 * Avoid resulting column to become negative.
3057 synpat_T *spp; 3066 synpat_T *spp;
3058 int idx; 3067 int idx;
3059 int extra; /* extra chars for offset to end */ 3068 int extra; /* extra chars for offset to end */
3060 { 3069 {
3061 int col; 3070 int col;
3071 int off;
3072 char_u *base;
3073 char_u *p;
3062 3074
3063 if (spp->sp_off_flags & (1 << (idx + SPO_COUNT))) 3075 if (spp->sp_off_flags & (1 << (idx + SPO_COUNT)))
3064 { 3076 {
3065 result->lnum = regmatch->endpos[0].lnum; 3077 result->lnum = regmatch->endpos[0].lnum;
3066 col = regmatch->endpos[0].col + extra; 3078 col = regmatch->endpos[0].col;
3079 off = spp->sp_offsets[idx] + extra;
3067 } 3080 }
3068 else 3081 else
3069 { 3082 {
3070 result->lnum = regmatch->startpos[0].lnum; 3083 result->lnum = regmatch->startpos[0].lnum;
3071 col = regmatch->startpos[0].col; 3084 col = regmatch->startpos[0].col;
3072 } 3085 off = spp->sp_offsets[idx];
3073 col += spp->sp_offsets[idx]; 3086 }
3074 if (col < 0) 3087 if (off != 0)
3075 result->col = 0; 3088 {
3076 else 3089 base = ml_get_buf(syn_buf, result->lnum, FALSE);
3077 result->col = col; 3090 p = base + col;
3091 if (off > 0)
3092 {
3093 while (off-- && *p != NUL)
3094 mb_ptr_adv(p);
3095 }
3096 else if (off < 0)
3097 {
3098 while (off++ && base < p)
3099 mb_ptr_back(base, p);
3100 }
3101 col = (int)(p - base);
3102 }
3103 result->col = col;
3078 } 3104 }
3079 3105
3080 /* 3106 /*
3081 * Get current line in syntax buffer. 3107 * Get current line in syntax buffer.
3082 */ 3108 */