Monday, January 16, 2017

Re: Set cusror position from inside function

Hi, Tihomir.

Looking at your message I can't see from were the 'a:line' and 'a:column'
variables did come from. The way you are calling the set of "Key_*()"
functions, you are not passing any information through parameters. So I'm
assuming you are discovering these values inside the function. Which is a
little bit strange since local variables are prefixed with "l:". "a:" prefix
is used for function arguments.

Could you send a message with the code that doesn't work? I think it would be
more easy to find an issue if we could see the function. Or a bigger snippet.


2017-01-15 10:15 GMT-02:00 Tihomir Mitkov <mitkovtihomir@gmail.com>:
Since vim doesn't support having some lines editable and others not, I figured it out that I can simulate this by keeping meta data about lines and remapping all keys to a function which checks cursor position and decides whether to put the character in question or not. So far so good, now I need to prohibit the cursor from going to certain locations. I remapped h,j,k,l keys like this:

map <expr> h Key_h()
map <expr> j Key_j()
map <expr> k Key_k()
map <expr> l Key_l()

That also works like a charm. Somewhere in the those functions I call setpos() like this:


call setpos(".", [0, a:line, a:column, 0])

Unfortunately the only thing this does is to send cursor the first column at the line it is currently in. Further movement with h,j,k,l does nothing. From inside the mapped functions Key_h(), Key_j() I return nothing, since cursor movement is already performed.

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: