On Thu, Sep 06, 2012 at 10:36:46PM +0200, Bram Moolenaar wrote:
> Yes, it would be nice to keep this consistent. virtcol() also returns 1
> for the first column.
Updated patch with adapted screencol()/screenrow(), updated
testcase (needs Dominique's patch applied) and documentation
attached.
I hope that's enough to get Dominique's patch into Vim.
Regards,
Simon
---
runtime/doc/eval.txt | 18 ++++++++++
src/eval.c | 26 +++++++++++++++
src/screen.c | 19 +++++++++++
src/testdir/Makefile | 4 +-
src/testdir/
test88.in | 85 +++++++++++++++++++++++++++++++++++++++++++++++++
src/testdir/test88.ok | 23 +++++++++++++
6 files changed, 173 insertions(+), 2 deletions(-)
create mode 100644 src/testdir/
test88.in
create mode 100644 src/testdir/test88.ok
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 2ae65ff..4763fd0 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1903,6 +1903,8 @@ repeat( {expr}, {count}) String repeat {expr} {count} times
resolve( {filename}) String get filename a shortcut points to
reverse( {list}) List reverse {list} in-place
round( {expr}) Float round off {expr}
+screencol() Number current cursor column
+screenrow() Number current cursor row
search( {pattern} [, {flags} [, {stopline} [, {timeout}]]])
Number search for {pattern}
searchdecl( {name} [, {global} [, {thisblock}]])
@@ -4867,6 +4869,22 @@ round({expr}) *round()*
< -5.0
{only available when compiled with the |+float| feature}
+screencol() *screencol()*
+ The result is a Number, which is the current screen column of
+ the cursor. This function is mainly used for testing.
+
+ Note: Always returns the current screen column, thus if used
+ in a command (e.g. ":echo screencol()") it will return the
+ column inside the command line, which is 1 when the command is
+ executed. To get the cursor position in the file use a
+ mapping: >
+ nnoremap <expr> GG ":echom ".screencol()."\n"
+<
+screenrow() *screenrow()*
+ The result is a Number, which is the current screen row of the
+ the cursor. This function is mainly used for testing.
+
+ Note: Same restrictions as |screencol()|.
search({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *search()*
Search for regexp pattern {pattern}. The search starts at the
diff --git a/src/eval.c b/src/eval.c
index 98b2a33..5bdefda 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -668,6 +668,8 @@ static void f_reverse __ARGS((typval_T *argvars, typval_T *rettv));
#ifdef FEAT_FLOAT
static void f_round __ARGS((typval_T *argvars, typval_T *rettv));
#endif
+static void f_screencol __ARGS((typval_T *argvars, typval_T *rettv));
+static void f_screenrow __ARGS((typval_T *argvars, typval_T *rettv));
static void f_search __ARGS((typval_T *argvars, typval_T *rettv));
static void f_searchdecl __ARGS((typval_T *argvars, typval_T *rettv));
static void f_searchpair __ARGS((typval_T *argvars, typval_T *rettv));
@@ -8032,6 +8034,8 @@ static struct fst
#ifdef FEAT_FLOAT
{"round", 1, 1, f_round},
#endif
+ {"screencol", 0, 0, f_screencol},
+ {"screenrow", 0, 0, f_screenrow},
{"search", 1, 4, f_search},
{"searchdecl", 1, 3, f_searchdecl},
{"searchpair", 3, 7, f_searchpair},
@@ -15717,6 +15721,28 @@ f_round(argvars, rettv)
#endif
/*
+ * "screencol()" function
+ */
+ static void
+f_screencol(argvars, rettv)
+ typval_T *argvars;
+ typval_T *rettv;
+{
+ rettv->vval.v_number = screen_screencol() + 1;
+}
+
+/*
+ * "screenrow()" function
+ */
+ static void
+f_screenrow(argvars, rettv)
+ typval_T *argvars;
+ typval_T *rettv;
+{
+ rettv->vval.v_number = screen_screenrow() + 1;
+}
+
+/*
* "search()" function
*/
static void
diff --git a/src/screen.c b/src/screen.c
index 5dccbd7..6892203 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -10263,3 +10263,22 @@ number_width(wp)
return n;
}
#endif
+
+/*
+ * Return the current cursor column. This is the actual position on the
+ * screen.
+ */
+ int
+screen_screencol()
+{
+ return screen_cur_col;
+}
+
+/*
+ * Return the current cursor row. This is the actual position on the screen.
+ */
+ int
+screen_screenrow()
+{
+ return screen_cur_row;
+}
diff --git a/src/testdir/Makefile b/src/testdir/Makefile
index dfcc8c0..7403abc 100644
--- a/src/testdir/Makefile
+++ b/src/testdir/Makefile
@@ -13,7 +13,7 @@ VIMPROG = ../vim
SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
test7.out test8.out test9.out test10.out test11.out \
- test12.out test13.out test14.out test15.out test17.out \
+ test12.out test13.out test14.out test15.out test17.out \
test18.out test19.out test20.out test21.out test22.out \
test23.out test24.out test25.out test26.out test27.out \
test28.out test29.out test30.out test31.out test32.out \
@@ -27,7 +27,7 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
test69.out test70.out test71.out test72.out test73.out \
test74.out test75.out test76.out test77.out test78.out \
test79.out test80.out test81.out test82.out test83.out \
- test84.out test85.out test86.out test87.out
+ test84.out test85.out test86.out test87.out test88.out \
SCRIPTS_GUI = test16.out
diff --git a/src/testdir/
test88.in b/src/testdir/
test88.in
new file mode 100644
index 0000000..1536b3b
--- /dev/null
+++ b/src/testdir/
test88.in
@@ -0,0 +1,85 @@
+vim: set ft=vim
+
+Tests for correct display (cursor column position) with +conceal and
+tabulators.
+
+STARTTEST
+:so small.vim
+:if !has('conceal')
+ e! test.ok
+ wq! test.out
+:endif
+:" Conceal settings.
+:set conceallevel=2
+:set concealcursor=nc
+:syntax match test /|/ conceal
+:" Save current cursor position. Only works in <expr> mode, can't be used
+:" with :normal because it moves the cursor to the command line. Thanks to ZyX
+:" <
zyx...@gmail.com> for the idea to use an <expr> mapping.
index 0000000..e726258
--- /dev/null
+++ b/src/testdir/test88.ok
@@ -0,0 +1,23 @@
+end:
+2:1
+2:17
+2:20
+3:1
+3:17
+3:20
+5:8
+5:25
+5:28
+6:8
+6:25
+6:28
+8:1
+8:9
+8:17
+8:25
+8:27
+9:1
+9:9
+9:17
+9:25
+9:26