Re: setpos() and up = wrong position
Christian Brabandt wrote: On Mo, 19 Aug 2013, Christian Brabandt wrote: May be another optional parameter to the setpos() function, that if given specifies the desired cursor position? Like the attached patch does. Hmm, I wonder if the extra list elements are going to cause a problem in some existing script. -- hundred-and-one symptoms of being an internet addict: 107. When using your phone you forget that you don't have to use your keyboard. /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ ///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org/// \\\help me help AIDS victims -- http://ICCF-Holland.org/// -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: setpos() and up = wrong position
On Thu, August 22, 2013 17:23, Bram Moolenaar wrote: Christian Brabandt wrote: On Mo, 19 Aug 2013, Christian Brabandt wrote: May be another optional parameter to the setpos() function, that if given specifies the desired cursor position? Like the attached patch does. Hmm, I wonder if the extra list elements are going to cause a problem in some existing script. I don't think, it will make a difference for the optional list-argument of the setpos() call. It might only make a difference for the list returned by the getpos() call now having 5 elements. If you're worried about that, simply let getpos('.') always return 4 elements (though this makes it harder to determine the prefered column). regards, 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: setpos() and up = wrong position
On Aug 22, 2013 8:05 PM, Christian Brabandt cbli...@256bit.org wrote: On Thu, August 22, 2013 17:23, Bram Moolenaar wrote: Christian Brabandt wrote: On Mo, 19 Aug 2013, Christian Brabandt wrote: May be another optional parameter to the setpos() function, that if given specifies the desired cursor position? Like the attached patch does. Hmm, I wonder if the extra list elements are going to cause a problem in some existing script. I don't think, it will make a difference for the optional list-argument of the setpos() call. It might only make a difference for the list returned by the getpos() call now having 5 elements. If you're worried about that, simply let getpos('.') always return 4 elements (though this makes it harder to determine the prefered column). I bet there is a bunch of scripts using 4-variable lets. Simple grep over the mess in $HOME/.vam (I hold all but my plugins there) found at least LaTeX_box plugin (ftplugin/latex-box/common.vim) and python-mode-klen (autoload/pymode/lint.vim, though it should have used line() and not getpos()). I do not know how many plugins do let pos=getpos('.') ... let [a,b,c,d]=pos , use negative indices or something else. Why not use optional argumet to getpos() then? Note: optional argument should make it return a dictionary. 5 indistinguishable numbers are way too much. Also check out winsaveview(), particularly .curswant key. Maybe there is no need to modify getpos(). regards, 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: setpos() and up = wrong position
On Do, 22 Aug 2013, Nikolay Pavlov wrote: I bet there is a bunch of scripts using 4-variable lets. Simple grep over What do you mean with 4-variable lets? the mess in $HOME/.vam (I hold all but my plugins there) found at least LaTeX_box plugin (ftplugin/latex-box/common.vim) and python-mode-klen (autoload/pymode/lint.vim, though it should have used line() and not getpos()). I do not know how many plugins do let pos=getpos('.') ... let [a,b,c,d]=pos , use negative indices or something else. Why not use optional argumet to getpos() then? Note: optional argument should make it return a dictionary. 5 indistinguishable numbers are way too much. Probably not. There not much difference to winsaveview() anymore. It was only a suggestion, though. regards, Christian -- Frage an Radio Eriwan: Gibt es bei uns mehr Humor als anderswo? Radio Eriwan antwortet: Im Prinzip ja. Aber wir haben ihn auch nötig. -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: setpos() and up = wrong position
On Aug 22, 2013 10:24 PM, Christian Brabandt cbli...@256bit.org wrote: On Do, 22 Aug 2013, Nikolay Pavlov wrote: I bet there is a bunch of scripts using 4-variable lets. Simple grep over What do you mean with 4-variable lets? let [a,b,c,d]=e the mess in $HOME/.vam (I hold all but my plugins there) found at least LaTeX_box plugin (ftplugin/latex-box/common.vim) and python-mode-klen (autoload/pymode/lint.vim, though it should have used line() and not getpos()). I do not know how many plugins do let pos=getpos('.') ... let [a,b,c,d]=pos , use negative indices or something else. Why not use optional argumet to getpos() then? Note: optional argument should make it return a dictionary. 5 indistinguishable numbers are way too much. Probably not. There not much difference to winsaveview() anymore. It was only a suggestion, though. regards, Christian -- Frage an Radio Eriwan: Gibt es bei uns mehr Humor als anderswo? Radio Eriwan antwortet: Im Prinzip ja. Aber wir haben ihn auch nötig. -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: setpos() and up = wrong position
Nikolay Pavlov wrote: On Aug 22, 2013 8:05 PM, Christian Brabandt cbli...@256bit.org wrote: On Thu, August 22, 2013 17:23, Bram Moolenaar wrote: Christian Brabandt wrote: On Mo, 19 Aug 2013, Christian Brabandt wrote: May be another optional parameter to the setpos() function, that if given specifies the desired cursor position? Like the attached patch does. Hmm, I wonder if the extra list elements are going to cause a problem in some existing script. I don't think, it will make a difference for the optional list-argument of the setpos() call. It might only make a difference for the list returned by the getpos() call now having 5 elements. If you're worried about that, simply let getpos('.') always return 4 elements (though this makes it harder to determine the prefered column). I bet there is a bunch of scripts using 4-variable lets. Simple grep over the mess in $HOME/.vam (I hold all but my plugins there) found at least LaTeX_box plugin (ftplugin/latex-box/common.vim) and python-mode-klen (autoload/pymode/lint.vim, though it should have used line() and not getpos()). I do not know how many plugins do let pos=getpos('.') ... let [a,b,c,d]=pos , use negative indices or something else. Why not use optional argumet to getpos() then? Note: optional argument should make it return a dictionary. 5 indistinguishable numbers are way too much. Also check out winsaveview(), particularly .curswant key. Maybe there is no need to modify getpos(). Yes, in complicated cases winsaveview() can be used. I think that in most cases the original problem applies: setpos() does not set the curswant position. I think the best way to fix this is by adding a separate set_curswant() function. Without argument it uses the current cursor position, and otherwise it sets the position to a column number. -- FIXME and XXX are two common keywords used to mark broken or incomplete code not only since XXX as a sex reference would grab everybody's attention but simply due to the fact that Vim would highlight these words. -- Hendrik Scholz /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ ///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org/// \\\help me help AIDS victims -- http://ICCF-Holland.org/// -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: setpos() and up = wrong position
On Aug 23, 2013 1:07 AM, Bram Moolenaar b...@moolenaar.net wrote: Nikolay Pavlov wrote: On Aug 22, 2013 8:05 PM, Christian Brabandt cbli...@256bit.org wrote: On Thu, August 22, 2013 17:23, Bram Moolenaar wrote: Christian Brabandt wrote: On Mo, 19 Aug 2013, Christian Brabandt wrote: May be another optional parameter to the setpos() function, that if given specifies the desired cursor position? Like the attached patch does. Hmm, I wonder if the extra list elements are going to cause a problem in some existing script. I don't think, it will make a difference for the optional list-argument of the setpos() call. It might only make a difference for the list returned by the getpos() call now having 5 elements. If you're worried about that, simply let getpos('.') always return 4 elements (though this makes it harder to determine the prefered column). I bet there is a bunch of scripts using 4-variable lets. Simple grep over the mess in $HOME/.vam (I hold all but my plugins there) found at least LaTeX_box plugin (ftplugin/latex-box/common.vim) and python-mode-klen (autoload/pymode/lint.vim, though it should have used line() and not getpos()). I do not know how many plugins do let pos=getpos('.') ... let [a,b,c,d]=pos , use negative indices or something else. Why not use optional argumet to getpos() then? Note: optional argument should make it return a dictionary. 5 indistinguishable numbers are way too much. Also check out winsaveview(), particularly .curswant key. Maybe there is no need to modify getpos(). Yes, in complicated cases winsaveview() can be used. I think that in most cases the original problem applies: setpos() does not set the curswant position. I think the best way to fix this is by adding a separate set_curswant() function. Without argument it uses the current cursor position, and otherwise it sets the position to a column number. I think that winrestview() should be officially allowed to accept custom dictionary: call winrestview({'curswant': 3}) seems to work fine. No If you have changed the values the result is unpredictable., but say what can be set this way and what combinations of keys should not be used. -- FIXME and XXX are two common keywords used to mark broken or incomplete code not only since XXX as a sex reference would grab everybody's attention but simply due to the fact that Vim would highlight these words. -- Hendrik Scholz /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ ///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/\\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\help me help AIDS victims -- http://ICCF-Holland.org /// -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
setpos() and up = wrong position
Hi all, I will use the following text as an example: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure [d]olor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. My cursor is on [d] as shown above: Now try :ec getpos('.') - [0, 4, 17, 0] Move away and :call setpos('.',[0,4,17,0]) If you use up down k or j you will not move just above/below the char but in some weird location Regards Dimitar --- GPG Key: 2048R/160C6FA8 2012-10-11 Dimitar Dimitrov (kurkale6ka) mitk...@yahoo.fr -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: setpos() and up = wrong position
On Monday, August 19, 2013 8:16:23 PM UTC+12, Dimitar DIMITROV wrote: If you use up down k or j you will not move just above/below the char but in some weird location My vim 7.4 doesn't do this, but 7.3.547 does, so it looks like a bug that's been fixed. Regards, John Little -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: setpos() and up = wrong position
If you use up down k or j you will not move just above/below the char but in some weird location My vim 7.4 doesn't do this, but 7.3.547 does, so it looks like a bug that's been fixed. I used version 7.4 with Included patches: 1-5 so not sure how come you're not seing it. Also used: vim -nNX -u NONE Regards, John Little Dimitar -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
RE: setpos() and up = wrong position
Dimitar DIMITROV wrote: Now try :ec getpos('.') - [0, 4, 17, 0] Move away and :call setpos('.',[0,4,17,0]) If you use up down k or j you will not move just above/below the char but in some weird location Say the cursor is in column 20, then setpos() is used to jump to [d], then k is pressed. The result is that the cursor goes to column 20. That is possibly not very helpful, but it's compatible with :help k: The first two commands [k and j] put the cursor in the same column (if possible) as it was after the last command that changed the column In other words, calling setpos() is not regarded as a command. John -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
RE: setpos() and up = wrong position
On Mon, August 19, 2013 11:30, John Beckett wrote: Dimitar DIMITROV wrote: Now try :ec getpos('.') - [0, 4, 17, 0] Move away and :call setpos('.',[0,4,17,0]) If you use up down k or j you will not move just above/below the char but in some weird location Say the cursor is in column 20, then setpos() is used to jump to [d], then k is pressed. The result is that the cursor goes to column 20. That is possibly not very helpful, but it's compatible with :help k: The first two commands [k and j] put the cursor in the same column (if possible) as it was after the last command that changed the column In other words, calling setpos() is not regarded as a command. May be another optional parameter to the setpos() function, that if given specifies the desired cursor position? Or should we rather fix setpos() in that it always set's the desired cursor position to the actual position? regards, 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: setpos() and up = wrong position
On Mon, Aug 19, 2013 at 10:16 AM, Dimitar DIMITROV mitk...@yahoo.fr wrote: I will use the following text as an example: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure [d]olor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. My cursor is on [d] as shown above: Now try :ec getpos('.') - [0, 4, 17, 0] Move away and :call setpos('.',[0,4,17,0]) If you use up down k or j you will not move just above/below the char but in some weird location Not a bug. See: https://groups.google.com/d/msg/vim_dev/o9GRXaJMwHg/9g8INNnNB9YJ -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: setpos() and up = wrong position
On Mo, 19 Aug 2013, Christian Brabandt wrote: May be another optional parameter to the setpos() function, that if given specifies the desired cursor position? Like the attached patch does. regards, Christian -- Es gehört viel dazu, eine Brücke hinter sich abzureißen, wenn man auch keine vor sich hat. -- Karlheinz Deschner -- -- 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 vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -4409,8 +4409,8 @@ *getpos()* getpos({expr}) Get the position for {expr}. For possible values of {expr} see |line()|. - The result is a |List| with four numbers: - [bufnum, lnum, col, off] + The result is a |List| with five numbers: + [bufnum, lnum, col, off, curswant] bufnum is zero, unless a mark like '0 or 'A is used, then it is the buffer number of the mark. lnum and col are the position in the buffer. The first @@ -4419,6 +4419,9 @@ it is the offset in screen columns from the start of the character. E.g., a position within a Tab or after the last character. + The curswant number is the prefered column for moving + vertically. + This can be used to save and restore the cursor position: let save_cursor = getpos(.) MoveTheCursorAround @@ -5224,7 +5227,7 @@ 'x mark x {list} must be a |List| with four numbers: - [bufnum, lnum, col, off] + [bufnum, lnum, col, off[, curswant]] bufnum is the buffer number. Zero can be used for the current buffer. Setting the cursor is only possible for @@ -5242,14 +5245,15 @@ character. E.g., a position within a Tab or after the last character. + The optional argument curswant is the preferred column for + moving vertically (matters only when setting the cursor + position). + Returns 0 when the position could be set, -1 otherwise. An error message is given if {expr} is invalid. Also see |getpos()| - This does not restore the preferred column for moving - vertically. See |winrestview()| for that. - setqflist({list} [, {action}])*setqflist()* Create or replace or add to the quickfix list using the items diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -11690,6 +11690,7 @@ (fp != NULL) ? (varnumber_T)fp-coladd : #endif (varnumber_T)0); + list_append_number(l, (varnumber_T)curwin-w_curswant + 1); } else rettv-vval.v_number = FALSE; @@ -16583,6 +16584,7 @@ pos_T pos; int fnum; char_u *name; +colnr_T curswant = curwin-w_curswant; rettv-vval.v_number = -1; name = get_tv_string_chk(argvars); @@ -16604,14 +16606,18 @@ else EMSG(_(e_invarg)); } - else if (name[0] == '\'' name[1] != NUL name[2] == NUL) - { - /* set mark */ - if (setmark_pos(name[1], pos, fnum) == OK) - rettv-vval.v_number = 0; - } - else - EMSG(_(e_invarg)); + else + { + curwin-w_curswant = curswant; /* might have been reset by list2fpos */ + if (name[0] == '\'' name[1] != NUL name[2] == NUL) + { + /* set mark */ + if (setmark_pos(name[1], pos, fnum) == OK) + rettv-vval.v_number = 0; + } + else + EMSG(_(e_invarg)); + } } } } @@ -19149,7 +19155,7 @@ if (arg-v_type != VAR_LIST || l == NULL || l-lv_len (fnump == NULL ? 2 : 3) - || l-lv_len (fnump == NULL ? 3 : 4)) + || l-lv_len (fnump == NULL ? 4 : 5)) return FAIL; if (fnump != NULL) @@ -19180,6 +19186,13 @@ posp-coladd = n; #endif +n = list_find_nr(l, ++i, NULL); /* w_set_curswant */ +if (n 0) +{ + curwin-w_curswant = n-1; + curwin-w_set_curswant = FALSE; +} + return OK; }