]>
Commit | Line | Data |
---|---|---|
d57b4abe ER |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 7.1.215 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.1.215 | |
11 | Problem: It is difficult to figure out what syntax items are nested at a | |
12 | certain position. | |
13 | Solution: Add the synstack() function. | |
14 | Files: runtime/doc/eval.txt, src/eval.c, src/proto/syntax.pro, | |
15 | src/syntax.c | |
16 | ||
17 | ||
18 | *** ../vim-7.1.214/runtime/doc/eval.txt Sun Jan 6 20:05:36 2008 | |
19 | --- runtime/doc/eval.txt Thu Jan 10 22:20:31 2008 | |
20 | *************** | |
21 | *** 1,4 **** | |
22 | ! *eval.txt* For Vim version 7.1. Last change: 2008 Jan 06 | |
23 | ||
24 | ||
25 | VIM REFERENCE MANUAL by Bram Moolenaar | |
26 | --- 1,4 ---- | |
27 | ! *eval.txt* For Vim version 7.1. Last change: 2008 Jan 10 | |
28 | ||
29 | ||
30 | VIM REFERENCE MANUAL by Bram Moolenaar | |
31 | *************** | |
32 | *** 1786,1791 **** | |
33 | --- 1786,1792 ---- | |
34 | synIDattr( {synID}, {what} [, {mode}]) | |
35 | String attribute {what} of syntax ID {synID} | |
36 | synIDtrans( {synID}) Number translated syntax ID of {synID} | |
37 | + synstack({lnum}, {col}) List stack of syntax IDs at {lnum} and {col} | |
38 | system( {expr} [, {input}]) String output of shell command/filter {expr} | |
39 | tabpagebuflist( [{arg}]) List list of buffer numbers in tab page | |
40 | tabpagenr( [{arg}]) Number number of current or last tab page | |
41 | *************** | |
42 | *** 4962,4967 **** | |
43 | --- 4966,4989 ---- | |
44 | highlight the character. Highlight links given with | |
45 | ":highlight link" are followed. | |
46 | ||
47 | + synstack({lnum}, {col}) *synstack()* | |
48 | + Return a |List|, which is the stack of syntax items at the | |
49 | + position {lnum} and {col} in the current window. Each item in | |
50 | + the List is an ID like what |synID()| returns. | |
51 | + The stack is the situation in between the character at "col" | |
52 | + and the next character. Note that a region of only one | |
53 | + character will not show up, it only exists inside that | |
54 | + character, not in between characters. | |
55 | + The first item in the List is the outer region, following are | |
56 | + items contained in that one. The last one is what |synID()| | |
57 | + returns, unless not the whole item is highlighted or it is a | |
58 | + transparent item. | |
59 | + This function is useful for debugging a syntax file. | |
60 | + Example that shows the syntax stack under the cursor: > | |
61 | + for id in synstack(line("."), col(".")) | |
62 | + echo synIDattr(id, "name") | |
63 | + endfor | |
64 | + | |
65 | system({expr} [, {input}]) *system()* *E677* | |
66 | Get the output of the shell command {expr}. | |
67 | When {input} is given, this string is written to a file and | |
68 | *** ../vim-7.1.214/src/eval.c Sun Jan 6 20:05:36 2008 | |
69 | --- src/eval.c Wed Jan 9 13:42:56 2008 | |
70 | *************** | |
71 | *** 651,656 **** | |
72 | --- 651,657 ---- | |
73 | static void f_synID __ARGS((typval_T *argvars, typval_T *rettv)); | |
74 | static void f_synIDattr __ARGS((typval_T *argvars, typval_T *rettv)); | |
75 | static void f_synIDtrans __ARGS((typval_T *argvars, typval_T *rettv)); | |
76 | + static void f_synstack __ARGS((typval_T *argvars, typval_T *rettv)); | |
77 | static void f_system __ARGS((typval_T *argvars, typval_T *rettv)); | |
78 | static void f_tabpagebuflist __ARGS((typval_T *argvars, typval_T *rettv)); | |
79 | static void f_tabpagenr __ARGS((typval_T *argvars, typval_T *rettv)); | |
80 | *************** | |
81 | *** 7252,7257 **** | |
82 | --- 7253,7259 ---- | |
83 | {"synID", 3, 3, f_synID}, | |
84 | {"synIDattr", 2, 3, f_synIDattr}, | |
85 | {"synIDtrans", 1, 1, f_synIDtrans}, | |
86 | + {"synstack", 2, 2, f_synstack}, | |
87 | {"system", 1, 2, f_system}, | |
88 | {"tabpagebuflist", 0, 1, f_tabpagebuflist}, | |
89 | {"tabpagenr", 0, 1, f_tabpagenr}, | |
90 | *************** | |
91 | *** 15843,15848 **** | |
92 | --- 15845,15890 ---- | |
93 | id = 0; | |
94 | ||
95 | rettv->vval.v_number = id; | |
96 | + } | |
97 | + | |
98 | + /* | |
99 | + * "synstack(lnum, col)" function | |
100 | + */ | |
101 | + /*ARGSUSED*/ | |
102 | + static void | |
103 | + f_synstack(argvars, rettv) | |
104 | + typval_T *argvars; | |
105 | + typval_T *rettv; | |
106 | + { | |
107 | + #ifdef FEAT_SYN_HL | |
108 | + long lnum; | |
109 | + long col; | |
110 | + int i; | |
111 | + int id; | |
112 | + #endif | |
113 | + | |
114 | + rettv->v_type = VAR_LIST; | |
115 | + rettv->vval.v_list = NULL; | |
116 | + | |
117 | + #ifdef FEAT_SYN_HL | |
118 | + lnum = get_tv_lnum(argvars); /* -1 on type error */ | |
119 | + col = get_tv_number(&argvars[1]) - 1; /* -1 on type error */ | |
120 | + | |
121 | + if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count | |
122 | + && col >= 0 && col < (long)STRLEN(ml_get(lnum)) | |
123 | + && rettv_list_alloc(rettv) != FAIL) | |
124 | + { | |
125 | + (void)syn_get_id(curwin, lnum, (colnr_T)col, FALSE, NULL); | |
126 | + for (i = 0; ; ++i) | |
127 | + { | |
128 | + id = syn_get_stack_item(i); | |
129 | + if (id < 0) | |
130 | + break; | |
131 | + if (list_append_number(rettv->vval.v_list, id) == FAIL) | |
132 | + break; | |
133 | + } | |
134 | + } | |
135 | + #endif | |
136 | } | |
137 | ||
138 | /* | |
139 | *** ../vim-7.1.214/src/proto/syntax.pro Tue Jul 24 14:32:44 2007 | |
140 | --- src/proto/syntax.pro Wed Jan 9 13:38:20 2008 | |
141 | *************** | |
142 | *** 13,18 **** | |
143 | --- 13,19 ---- | |
144 | void set_context_in_syntax_cmd __ARGS((expand_T *xp, char_u *arg)); | |
145 | char_u *get_syntax_name __ARGS((expand_T *xp, int idx)); | |
146 | int syn_get_id __ARGS((win_T *wp, long lnum, colnr_T col, int trans, int *spellp)); | |
147 | + int syn_get_stack_item __ARGS((int i)); | |
148 | int syn_get_foldlevel __ARGS((win_T *wp, long lnum)); | |
149 | void init_highlight __ARGS((int both, int reset)); | |
150 | int load_colors __ARGS((char_u *name)); | |
151 | *** ../vim-7.1.214/src/syntax.c Sun Oct 7 15:21:31 2007 | |
152 | --- src/syntax.c Wed Jan 9 15:17:47 2008 | |
153 | *************** | |
154 | *** 6104,6109 **** | |
155 | --- 6102,6123 ---- | |
156 | ||
157 | return (trans ? current_trans_id : current_id); | |
158 | } | |
159 | + | |
160 | + #if defined(FEAT_EVAL) || defined(PROTO) | |
161 | + /* | |
162 | + * Return the syntax ID at position "i" in the current stack. | |
163 | + * The caller must have called syn_get_id() before to fill the stack. | |
164 | + * Returns -1 when "i" is out of range. | |
165 | + */ | |
166 | + int | |
167 | + syn_get_stack_item(i) | |
168 | + int i; | |
169 | + { | |
170 | + if (i >= current_state.ga_len ) | |
171 | + return -1; | |
172 | + return CUR_STATE(i).si_id; | |
173 | + } | |
174 | + #endif | |
175 | ||
176 | #if defined(FEAT_FOLDING) || defined(PROTO) | |
177 | /* | |
178 | *** ../vim-7.1.214/src/version.c Wed Jan 9 22:39:55 2008 | |
179 | --- src/version.c Thu Jan 10 22:17:38 2008 | |
180 | *************** | |
181 | *** 668,669 **** | |
182 | --- 668,671 ---- | |
183 | { /* Add new patch number below this line */ | |
184 | + /**/ | |
185 | + 215, | |
186 | /**/ | |
187 | ||
188 | -- | |
189 | TALL KNIGHT: We are now no longer the Knights Who Say Ni! | |
190 | ONE KNIGHT: Ni! | |
191 | OTHERS: Sh! | |
192 | ONE KNIGHT: (whispers) Sorry. | |
193 | "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD | |
194 | ||
195 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
196 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
197 | \\\ download, build and distribute -- http://www.A-A-P.org /// | |
198 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |