diff options
author | Bram Moolenaar <Bram@vim.org> | 2010-07-25 12:46:44 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2010-07-25 12:46:44 +0200 |
commit | 7510fe74337599f70ae2044aef4f186b1f1c1bf9 (patch) | |
tree | b61a49e70685408de65b6d6833e72ba2fcc33c3b /src | |
parent | e6dc573b6e0e8eb59eda14be6f94476e72fd82ca (diff) | |
download | vim-git-7510fe74337599f70ae2044aef4f186b1f1c1bf9.tar.gz |
Add the synconcealed() function and use it for :TOhtml. (Benjamin Fritz)
Diffstat (limited to 'src')
-rw-r--r-- | src/eval.c | 64 | ||||
-rw-r--r-- | src/syntax.c | 7 |
2 files changed, 71 insertions, 0 deletions
diff --git a/src/eval.c b/src/eval.c index 33be998e0..4f1be3fa2 100644 --- a/src/eval.c +++ b/src/eval.c @@ -718,6 +718,7 @@ static void f_synID __ARGS((typval_T *argvars, typval_T *rettv)); static void f_synIDattr __ARGS((typval_T *argvars, typval_T *rettv)); static void f_synIDtrans __ARGS((typval_T *argvars, typval_T *rettv)); static void f_synstack __ARGS((typval_T *argvars, typval_T *rettv)); +static void f_synconcealed __ARGS((typval_T *argvars, typval_T *rettv)); static void f_system __ARGS((typval_T *argvars, typval_T *rettv)); static void f_tabpagebuflist __ARGS((typval_T *argvars, typval_T *rettv)); static void f_tabpagenr __ARGS((typval_T *argvars, typval_T *rettv)); @@ -7876,6 +7877,7 @@ static struct fst {"synID", 3, 3, f_synID}, {"synIDattr", 2, 3, f_synIDattr}, {"synIDtrans", 1, 1, f_synIDtrans}, + {"synconcealed", 2, 2, f_synconcealed}, {"synstack", 2, 2, f_synstack}, {"system", 1, 2, f_system}, {"tabpagebuflist", 0, 1, f_tabpagebuflist}, @@ -17132,6 +17134,68 @@ f_synIDtrans(argvars, rettv) } /* + * "synconcealed(lnum, col)" function + */ + static void +f_synconcealed(argvars, rettv) + typval_T *argvars UNUSED; + typval_T *rettv; +{ +#if defined(FEAT_SYN_HL) && defined(FEAT_CONCEAL) + long lnum; + long col; + int syntax_flags = 0; + int cchar; + int matchid = 0; + char_u str[NUMBUFLEN]; +#endif + + rettv->v_type = VAR_LIST; + rettv->vval.v_list = NULL; + +#if defined(FEAT_SYN_HL) && defined(FEAT_CONCEAL) + lnum = get_tv_lnum(argvars); /* -1 on type error */ + col = get_tv_number(&argvars[1]) - 1; /* -1 on type error */ + + vim_memset(str, NUL, sizeof(str)); + + if (rettv_list_alloc(rettv) != FAIL) + { + if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count + && col >= 0 && col <= (long)STRLEN(ml_get(lnum)) + && curwin->w_p_cole > 0) + { + (void)syn_get_id(curwin, lnum, col, FALSE, NULL, FALSE); + syntax_flags = get_syntax_info(&matchid); + + /* get the conceal character */ + if ((syntax_flags & HL_CONCEAL) && curwin->w_p_cole < 3) + { + cchar = syn_get_sub_char(); + if (cchar == NUL && curwin->w_p_cole == 1 && lcs_conceal != NUL) + cchar = lcs_conceal; + if (cchar != NUL) + { +# ifdef FEAT_MBYTE + if (has_mbyte) + (*mb_char2bytes)(cchar, str); + else +# endif + str[0] = cchar; + } + } + } + + list_append_number(rettv->vval.v_list, + (syntax_flags & HL_CONCEAL) != 0); + /* -1 to auto-determine strlen */ + list_append_string(rettv->vval.v_list, str, -1); + list_append_number(rettv->vval.v_list, matchid); + } +#endif +} + +/* * "synstack(lnum, col)" function */ static void diff --git a/src/syntax.c b/src/syntax.c index 099e0a7c0..cb87a0202 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -474,6 +474,10 @@ syntax_start(wp, lnum) int dist; static int changedtick = 0; /* remember the last change ID */ +#ifdef FEAT_CONCEAL + current_sub_char = NUL; +#endif + /* * After switching buffers, invalidate current_state. * Also do this when a change was made, the current state may be invalid @@ -1787,6 +1791,9 @@ get_syntax_attr(col, can_spell, keep_state) current_id = 0; current_trans_id = 0; #endif +#ifdef FEAT_CONCEAL + current_flags = 0; +#endif return 0; } |