Hi Roland!

On Sa, 16 Feb 2013, Roland Eggner wrote:

> On 2013-02-06 Wednesday at 23:08 +0100 Bram Moolenaar wrote:
> > Roland Eggner wrote:
> > > > > :mksession writes wrong column number of cursor position in presence 
> > > > > of 
> > > > > multibyte characters.
> > > > > 
> > > > > I have been using vim-7.3.135 with this patch applied for several
> > > > > months  … it works for me:
> > > > 
> > > > I do not see the problem.  How to reproduce?
> > > > 
> > > > Your patch can't be right, the "l" command moves over characters, not
> > > > columns.
> > > 
> > > Session files created with :mksession restore cursor line and column,
> > > as long as there is no multibyte character between start of line and
> > > cursor.  Otherwise, without my patch restored column is off by the
> > > difference between character position and byte position counted from
> > > start of line.
> > > 
> > > With my patch applied, cursor line and column is restored correctly,
> > > with and without multibyte characters, with and without changing of
> > > options fileencoding or binary, even with files preprocessed by
> > > BufRead autocommands gzip -dc, bzip -dc, xz -dc, pdftotext, elinks
> > > -dump, antiword, … which I find pretty cool, use and enjoy it nearly
> > > every day.
> > 
> > I asked how to reproduce.  I suspect your 'encoding' matters.
> > Please start with "vim -u NONE" and check what the default value of
> > 'encoding' is then.
> > 
> > Note that your patch most likely is wrong when there is a Tab before the
> > cursor, try that.
> 
> Indeed, you are right:  my patch beeing wrong was hidden by autocommands 
> restoring cursor positions based on textmarks.
> 
> For investigation of the problem I have created test{91,92}.
> In my environment (TERM=linux, unicode-mode) and with locale 
> en_US.ISO-8859-1 both succeed, whereas with locale en_US.utf8 both fail:
> 
> 
> pushd vim-7.3.816
> patch -p1 -N -u -i my.patch.provided.below
> pushd src/testdir
> rm -f test{91,92}.{out,failed,messages}
> env {LANG,LC_CTYPE,LC_MESSAGES}=en_US.ISO-8859-1 make -j1
> 
>   Test results:
>   ALL DONE
> 
> grep '[=.]' test91.messages
>   LANG=en_US.ISO-8859-1
>   LC_MESSAGES=en_US.ISO-8859-1
>   LC_ALL=
>   test91.in
>     fileencoding=utf-8
>     termencoding=
>     encoding=latin1
> 
> grep '[=.]' test92.messages
>   LANG=en_US.ISO-8859-1
>   LC_MESSAGES=en_US.ISO-8859-1
>   LC_ALL=
>   test92.in
>     fileencoding=latin1
>     termencoding=
>     encoding=latin1
> 
> 
> rm -f test{91,92}.{out,failed,messages}
> env {LANG,LC_CTYPE,LC_MESSAGES}=en_US.utf8 make -j1
> 
>   Test results:
>   test91 FAILED
>   test92 FAILED

I see the error. The problem is, curwin->w_cursor.col is the byteindex 
in the buffer and not the screen-index (which is by what 'l' moves)

I think, the attached patch fixes it.

Mit freundlichen Grüßen
Christian

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


diff --git a/src/ex_docmd.c b/src/ex_docmd.c
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -10829,14 +10829,26 @@
 			    (long)wp->w_cursor.col) < 0
 			|| put_eol(fd) == FAIL
 			|| put_line(fd, "else") == FAIL
-			|| fprintf(fd, "  normal! 0%dl", wp->w_cursor.col) < 0
+			|| fprintf(fd, "  normal! 0%dl",
+#ifdef FEAT_MBYTE
+			    mb_string2cells(ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE), wp->w_cursor.col)
+#else
+			    wp->w_cursor.col
+#endif
+			     ) < 0
 			|| put_eol(fd) == FAIL
 			|| put_line(fd, "endif") == FAIL)
 		    return FAIL;
 	    }
 	    else
 	    {
-		if (fprintf(fd, "normal! 0%dl", wp->w_cursor.col) < 0
+		if (fprintf(fd, "normal! 0%dl",
+#ifdef FEAT_MBYTE
+			    mb_string2cells(ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE), wp->w_cursor.col)
+#else
+			    wp->w_cursor.col
+#endif
+			    ) < 0
 			|| put_eol(fd) == FAIL)
 		    return FAIL;
 	    }

Raspunde prin e-mail lui