Hi Bram,

On Thu, Jan 7, 2021 at 1:04 PM Bram Moolenaar <[email protected]> wrote:

>
> Yegappan wrote:
>
> > The getpos(), col() and getcurpos() functions currently return the byte
> > index
> > in a line. The setpos() and cursor() functions use the byte index to
> > position
> > the cursor or to set a mark.
> >
> > The language server protocol uses character index instead of byte index
> > in a line. I see that the various LSP Vim plugins have created their own
> > utility functions to convert between the byte index and the character
> index.
> > It will be better to extend the built-in function to use character
> indexes,
> > so that multiple plugins can use this.
> >
> > What do you think about enhancing these functions like below?
> >
> > getpos({expr}, [charcol])
> > col({expr}, [charcol])
> > setpos({expr}, {list}, [charcol])
> > cursor({list}, [charcol])
> > getcurpos([{winid} [, charcoal]})
> >
> > In the above functions, if 'charcol' is set to true, then the returned
> > column
> > number will be a character index. If 'charcol' is false or not specified
> > (the default), then the returned column number will be a byte index.
>
> Using charidx() requires the string to be passed, so that would be a
> complicated workaround.
>
> Instead of adding a 0/1/true/false argument we could add new functions:
>
>         getcharpos()
>         charcol()
>         setcharpos()
>         getcursorcharpos()
>         setcursorcharpos()
>
> It's easier to see that "char" is used, compared to an argument that
> doesn't say what it's for.
>
>
Another option is to introduce two new functions to convert between
the byte index and the character index in a buffer line:

buf_byteidx(bufnr, lnum, charidx)
buf_charidx(bufnr, lnum, byteidx)

The buf_byteidx() function returns the byte index for the given character
index in the specified line and buf_charidx() does the opposite.

What do you think about this approach?

Thanks,
Yegappan

-- 
-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/CAAW7x7%3DxehqYtjcaVfjb7yw9hQ1USM2GL5S111PQw6%2B-yaSGZQ%40mail.gmail.com.

Raspunde prin e-mail lui