2017-05-28 8:57 GMT+03:00 Bram Moolenaar <Bram@moolenaar.net>:
>
> Nikolay Pavlov wrote:
>
> [..]
>
>> >> Enable, disable, query, execute plus two callbacks. *Four* functions
>> >> and two callbacks in place of just two simple functions, mostly using
>> >> the functionality that is already there. Five if you remember about
>> >> :mkvimrc and that somebody may want to replace that on top of new API:
>> >> query will need a mirror function for creating a mapping then.
>> >
>> > You are completely missing the point: those two functions don't provide
>> > the functionality we are talking about here.
>>
>> Why do you think so? They provide everything what is needed to
>> implement the functionality we are talking about here in VimL.
>
> This whole discussion started about the difficutly of using the result
> of maparg(). As far as I can see you only provide a function to get more
> mappings, it doesn't help with disabling and restoring mappings.
> Dealing with that is not easy at all (dealing with modes,
> escaping/unescaping, etc). I would not want every plugin writer to
> re-invent the wheel.
>
> The basic discussion first need to be held is whether to refer to a
> mapping just by its LHS (plus mode) or a unique handle can be used. The
> latter is useful if we disable a mapping but not delete it, it can then
> be shadowed by another mapping.
>
> We probably also need some kind of re-enable or restore function, that
> takes the result of maparg() and defines a mapping with it. That avoids
> string manipulation and using :exe (this is tricky because of the way
> mappings need some characters to be escaped).
Three functions:
1. Get mappings: mappings_dump(). Needs to output lhs and rhs in some
canonical form. Takes an argument which allows some basic filtering:
e.g. select only mappings belonging to buffer with number N or
globals, select only mappings with given modes and select only
mappings starting with some prefix.
2. Create mappings: mappings_load(). Takes output from
mappings_dump(), with the help of mappings_canonicalize() it should be
possible to create your own mappings.
2.1. Something to delete mappings: mappings_load() with missing rhs or
mappings_clear() which takes output of mappings_dump() and deteletes
those mappings.
3. Create string for lhs or rhs in canonical form given something like
`"\<F1>"` or `"<F1>"` (not sure what would be better) as the input:
mappings_canonicalize().
So "disabling" is
let disabled_mappings = mappings_dump(some_filter)
call filter(disabled_mappings, some_more_complex_filter_if_needed)
call mappings_load(map(deepcopy(disabled_mappings),
\'[remove(v:val, "rhs"), v:val][-1]'))
"Enabling" is
call mappings_load(disabled_mappings)
One of the key points is that mappings_dump() and mappings_load() need
to work with canonical form of lhs and rhs strings and thus
dictionaries returned by them are not entirely compatible with
maparg() results. Canonical form needs to be independent of
&cpoptions, allow distinguishing `<LT>F1>` and `<F1>` and
`mappings_canonicalize(mappings_canonicalize(x))` should be identical
to `mappings_canonicalize(x)`.
---
You may also ask Brett Stahlman whether my proposal is enough, it does
not look like he thinks it is not, just that it may be less
convenient.
---
And why do you think that "do not make plugins reinwent the wheel" is
the same statement as "write needed functionality in C code"? You can
always add a new file to `autoload`, writing VimL code is easier then
writing C code.
>
> --
> A village. Sound of chanting of Latin canon, punctuated by short, sharp
> cracks. It comes nearer. We see it is a line of MONKS ala SEVENTH SEAL
> flagellation scene, chanting and banging themselves on the foreheads with
> wooden boards.
> "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
>
> /// Bram Moolenaar -- Bram@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_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.
Sunday, May 28, 2017
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment