On 4 July 2014, ZyX <[email protected]> wrote:
> Given recent discussion around matchaddpos() and the fact that
> converting virtual column to byte offset has a larger variety of use
> cases (I personally needed this to get <C-v>-selected block without
> altering marks, registers, cursor position, etc) I propose the new
> function colnr():
>
>     colnr :: (string, number, options) -> col
>
> This function accepts number: generic index and translates it to byte
> offset according to given options which may be one of the following:
> 
> 1. `'col'`: returns `number` or length of the string plus one,
> whichever is smaller. Alias to {'unicode': 0, 'tabstop': 1,
> 'fixed_width_tab': 1}
>
> 2. `'codepoint'`: returns byte offset of Unicode codepoint with
> index given as `number` (here and below index starts from 1). Alias
> to {'tabstop': 1, 'fixed_width_tab': 1, 'ambiwidth': 'single',
> 'fullwidth_len': 1, 'diacritics_len': 1, 'invalid_unicode':
> 'error'}. Is opposite of `strchars()`.
>
> 3. `'virtcol'`: alias to {} which is the same as {'tabstop': &tabstop,
> 'fixed_width_tab': 0, 'ambiwidth': &ambiwidth, 'fullwidth_len': 2,
> 'diacritics_len': 0, 'diacritics_start_len': 1, 'unicode': 1,
> 'invalid_unicode': 'strtrans'}.
>
> 4. A dictionary with the following keys:
> 
>     - tabstop: effective value of &tabstop. All defaults are listed in 3.
>     - fixed_width_tab: if non-zero, makes every tab be assumed to
>       occupy `tabstop` columns.
>     - ambiwidth: effective value of &ambiwidth.
>     - fullwidth_len: number of indexes fullwidth characters occupy.
>     - diacritics_len: number of indexes diacritics characters occupy.
>     - diacritics_start_len: length of the one diacritic character that
>       is at the start of the string.
>     - unicode: if non-zero, recognizes one unicode character as
>       occupying one index. Disables `ambiwidth`, `fullwidth_len`,
>       `diacritics_len`, `diacritics_start_len` and `invalid_unicode`
>       options.
>     - invalid_unicode: determines how to treat bytes that are not
>       valid unicode. Valid values are
>     - strtrans: use length of the `strtrans` result. error: fail with
>     - error, return zero. single: treat as occupying one index.
[...]

    This seems useful, but do you _have_ to do all that in a single
function?  Perhaps 2. and 3. could be split into separate functions?

    Also, I'd say 4. should just use the actual settings rather than
parse them from a Christmas tree of options.  Vim tradition seems to be
to leave it to the user to save and restore the context before doing the
job.

    /lcd

-- 
-- 
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/d/optout.

Raspunde prin e-mail lui