4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: virtcol([123, '$']) doesn't work. (Michael Schaap)
12 Solution: When '$' is used for the column number get the last column.
13 Files: runtime/doc/eval.txt, src/eval.c
16 *** ../vim-7.1.030/runtime/doc/eval.txt Tue Jun 19 17:23:46 2007
17 --- runtime/doc/eval.txt Wed Jul 11 21:21:28 2007
20 ! *eval.txt* For Vim version 7.1. Last change: 2007 Jun 09
23 VIM REFERENCE MANUAL by Bram Moolenaar
25 ! *eval.txt* For Vim version 7.1. Last change: 2007 Jul 11
28 VIM REFERENCE MANUAL by Bram Moolenaar
32 number of characters in the cursor line plus one)
33 'x position of mark x (if the mark is not set, 0 is
35 + Additionally {expr} can be [lnum, col]: a |List| with the line
36 + and column number. Most useful when the column is "$", to get
37 + the las column of a specific line. When "lnum" or "col" is
38 + out of range then col() returns zero.
39 To get the line number use |line()|. To get both use
41 For the screen column position use |virtcol()|.
44 position, the returned Number will be the column at the end of
45 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
46 set to 8, it returns 8.
47 ! For the use of {expr} see |col()|. Additionally you can use
48 ! [lnum, col]: a |List| with the line and column number. When
49 ! "lnum" or "col" is out of range then virtcol() returns zero.
50 ! When 'virtualedit' is used it can be [lnum, col, off], where
51 "off" is the offset in screen columns from the start of the
52 character. E.g., a position within a <Tab> or after the last
54 - For the byte position use |col()|.
55 When Virtual editing is active in the current mode, a position
56 beyond the end of the line can be returned. |'virtualedit'|
57 The accepted positions are:
59 position, the returned Number will be the column at the end of
60 the <Tab>. For example, for a <Tab> in column 1, with 'ts'
61 set to 8, it returns 8.
62 ! For the byte position use |col()|.
63 ! For the use of {expr} see |col()|.
64 ! When 'virtualedit' is used {expr} can be [lnum, col, off], where
65 "off" is the offset in screen columns from the start of the
66 character. E.g., a position within a <Tab> or after the last
68 When Virtual editing is active in the current mode, a position
69 beyond the end of the line can be returned. |'virtualedit'|
70 The accepted positions are:
71 *** ../vim-7.1.030/src/eval.c Tue Jul 10 13:27:46 2007
72 --- src/eval.c Wed Jul 11 19:50:27 2007
75 static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv));
77 static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump));
78 ! static pos_T *var2fpos __ARGS((typval_T *varp, int lnum, int *fnum));
79 static int get_env_len __ARGS((char_u **arg));
80 static int get_id_len __ARGS((char_u **arg));
81 static int get_name_len __ARGS((char_u **arg, char_u **alias, int evaluate, int verbose));
83 static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv));
85 static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump));
86 ! static pos_T *var2fpos __ARGS((typval_T *varp, int dollar_lnum, int *fnum));
87 static int get_env_len __ARGS((char_u **arg));
88 static int get_id_len __ARGS((char_u **arg));
89 static int get_name_len __ARGS((char_u **arg, char_u **alias, int evaluate, int verbose));
92 * Returns NULL when there is an error.
95 ! var2fpos(varp, lnum, fnum)
97 ! int lnum; /* TRUE when $ is last line */
98 int *fnum; /* set to fnum for '0, 'A, etc. */
102 * Returns NULL when there is an error.
105 ! var2fpos(varp, dollar_lnum, fnum)
107 ! int dollar_lnum; /* TRUE when $ is last line */
108 int *fnum; /* set to fnum for '0, 'A, etc. */
119 l = varp->vval.v_list;
126 len = (long)STRLEN(ml_get(pos.lnum));
128 + /* We accept "$" for the column number: last column. */
129 + li = list_find(l, 1L);
130 + if (li != NULL && li->li_tv.v_type == VAR_STRING
131 + && li->li_tv.vval.v_string != NULL
132 + && STRCMP(li->li_tv.vval.v_string, "$") == 0)
135 /* Accept a position up to the NUL after the line. */
136 if (pos.col == 0 || (int)pos.col > len + 1)
137 return NULL; /* invalid column number */
143 ! if (name[0] == 'w' && lnum)
146 if (name[1] == '0') /* "w0": first visible line */
151 ! if (name[0] == 'w' && dollar_lnum)
154 if (name[1] == '0') /* "w0": first visible line */
158 else if (name[0] == '$') /* last column or line */
162 pos.lnum = curbuf->b_ml.ml_line_count;
166 else if (name[0] == '$') /* last column or line */
170 pos.lnum = curbuf->b_ml.ml_line_count;
172 *** ../vim-7.1.030/src/version.c Tue Jul 17 14:32:07 2007
173 --- src/version.c Tue Jul 17 16:24:54 2007
177 { /* Add new patch number below this line */
184 ARTHUR: The Knights Who Say GNU!
185 CRONE: Aaaagh! (she looks around in rear) No! We have no licenses here.
186 "Monty Python and the Holy editor wars" PYTHON (MONTY) SOFTWARE LTD
188 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
189 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
190 \\\ download, build and distribute -- http://www.A-A-P.org ///
191 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///