On 1/3/2016 3:35 PM, Bram Moolenaar wrote:
Roland Puntaier wrote:

On 12/31/2015 6:22 PM, Bram Moolenaar (Vim Github Repository) wrote:
No, the langmap and keymap options relate to the keyboard. Replaying a
register does not involve the keyboard. When replaying a register one
doesn't know where the characters came from, they might be typed or the
result of something else, e.g. a yank operation.

I wonder how you managed to get characters into a register that
you want to
apply 'keymap' or 'langmap' to. This translation should have
already happened
when typing the characters.
- do ":help russian"
- use the keymap as described there
- insert some russian text
- record a macro @a that inserts some russian text
- play the macor @a
This is a bit vague... Perhaps the problem is that when recording into
a register the keymap/langmap is not applied, resulting in the wrong
characters in the register?

I look at keymap/langmap as a low level operation, which is applied when
typing on the keyboard, before it goes to the rest of Vim, which is
unaware of this filtering.

It's possible that this interferes with other things, such as terminal
codes and other mappings. It's quite complicated. Many changes in this
area are not backwards compatible and break someone's carefully tuned
setup. I have thought of re-implementing this, but haven't found the
time to dive into it.

Dear Bram,

Of course a cleaner implementation would be desirable
and that could store to a register after applying keymap.
But as of now the typed chars are stored into the register before
applying keymap,
i.e.

      //getchar.c:2515
      if (keylen > typebuf.tb_maplen)
          gotchars(typebuf.tb_buf + typebuf.tb_off
                                        + typebuf.tb_maplen,
                                keylen - typebuf.tb_maplen);

is before

      //getchar.c:2610
      i = ins_typebuf(s, noremap,

So my patch fits to the current implementation by applying the keymap to
chars in the register.
I also added tests for keymap. There haven't been any so far.

Regarding applying langmap to ':'-CMDLINE
I've found that only patch v7.4.773 had removed the langmap mapping from
CMDLINE.
For / and ? commands that is good. langmap shouldn't apply, because you
want to find text.
So it should be like for the insert mode, i.e keyboard layout should be
used.

But for :-commands, if langmap is intended to enable russians or greeks
to use vim without the need to switch to an english keyboard layout,
langmap should apply.  Otherwise you cannot enter :q, :w, :e,... commands.

To enter non-english letters in :-commands, e.g. for :s,
one can first search via / or yank and then do ^R/ or ^R".

So this pull request is a modification and not an undo of patch 773.

langmap now also is a better opposite to keymap.
keymap does not apply to :-commands, so langmap should.

I adapted the tests for langmap to fit the changes.

I have also updated the documentation to mention:
- langmap applies to ':'-CMDLINE mode (new)
- keymap applies to non-':'-CMDLINE mode (current)


  From my side pull request

      https://github.com/vim/vim/pull/543

is ready now.
Sorry, but this is not the right solution.

Did you see the change that Christian Brabandt made, sent to the vim-dev
list on July 25 last year?  This also indicates what is wrong: need to
apply langmap before checking for matching mappings.

So, what needs to be done is in vgetorpeek() to apply langmap to the
head of the typeahead buffer and put the result in a copy-buffer.  Then
use this copy-buffer to check for mappings and otherwise get the
character from.  Then gotchars() will record the characters after
applying langmap and replaying the register will work.
The calls to LANGMAP_ADJUST() in other places of the code have to be
removed.
This also fixes the problem with multi-byte characters that Christian
solved.

This is not easy, but we need to do this properly, otherwise we'll get a
sequence of slightly incompatible changes that is annoying for users.
I've now looked into the vim-dev entry by Christian Brabandt you've mentioned.

https://groups.google.com/forum/#!topic/vim_dev/cqYj7seoEWg

It references

    https://github.com/vim/vim/issues/297
https://groups.google.com/forum/#!msg/vim_dev/5D1WSL2gj-A/OgCBNZQEHNEJ

I also browsed through langmap search results.

From this I have added some test to test_mapping.in. Changes are between
CHANGED_START and CHANGED_END

    Test for mappings and abbreviations

    STARTTEST
    :so small.vim
    :so mbyte.vim
    :set encoding=utf-8
    : " abbreviations with р (0x80) should work
    :inoreab чкпр   vim
    GAчкпр
:" mapping of ctrl-c in Insert mode
    :set cpo-=< cpo-=k
    :inoremap <c-c> <ctrl-c>
    :cnoremap <c-c> dummy
    :cunmap <c-c>
    GA
    TEST2: CTRL-C | A|
:unmap <c-c>
    :unmap! <c-c>
    :"
    :" mapping of ctrl-c in Visual mode
    :vnoremap <c-c> :<C-u>$put ='vmap works'
GV :vunmap <c-c>
    :"
    :" CHANGED_START
    :" ============= langmap =============
    :" langmap should apply in normal mode
    :set langmap=öc,üi langnoremap
    :call append(line('$'), "FAIL_nlangmap")
G0öfpOK :" langmap should apply in normal mode with motion
    :call append(line('$'), "FAIL_nlangmap_motion")
    qüG0f_öüwOK q
    :" langmap should apply in normal mode with registers
    :call append(line('$'), "FAIL_nlangmap_registers")
    @ü
    :" langmap should act before mappings
    :call append(line('$'), "FAIL_nlangmap_mapping")
    :map col :%g/FAIL_nlangmap_mapping/normal ddOOK
    Göol
    :unmap col
    :" langmap should not get remapped
    :call append(line('$'), "FAIL_nlangmap_noremap")
    :set langmap=:>,ö: langnoremap
    ömap , :
    G0,s/FAIL_nlangmap_noremap/OK
    öunmap ,
    öset langmap=
    :%g/FAIL_nlangmap_mapping/normal ddOOK
    :" langmap should not apply in Insert mode
    :inoremap { FAIL_ilangmap
    :set langmap=+{ langnoremap
o+ :" also no Insert-mode expr mapping with langmap
    :inoremap <expr> { "FAIL_iexplangmap"
o+ :" langmap should not get mapped in non-':'-Command-line mode
    ?+
:call append(line('$'), getline('.')==" /"?"OK":"FAIL_clangmap_non_colon")
    :" langmap should get mapped in ':'-Command-line mode
    :cnoremap  / FAIL_clangmap_colon
    :call append(line('$'), '+')
    :cunmap  /
    :" in non-:-Command-line expr mapping is not applied
    :cnoremap <expr> { "FAIL_cexplangmap_no_colon"
    :cnoremap <expr>  / "OK"
    /+
    :cunmap {
    :cunmap  /
:call append(line('$'), getline('.')=="OK"?"OK":"FAIL_cexplangmap_no_colon")
    :" in :-Command-line expr mapping is applied
    :cnoremap <expr>  / "FAIL_cexplangmap_colon"
    :cnoremap <expr> { "OK"
    :call append(line('$'), '+')
    :cunmap  /
    :cunmap {
    :" langmap should map multi-byte in ':'-Command-line mode
    :set langmap=ф+;a{
    :set lфngmфp=
    :cnoremap { FAIL_clangmap_colon_multibyte
    :call append(line('$'), '+')
    :cunmap {
    :"
    :" ============= keymap =============
    :" keymap should apply to insert mode, but not to normal mode
    :set keymap=russian-jcukenwin
    Gqao. q
    :call append(line('$'), getline('.')=="ю"?"OK":"FAIL_keymap")
    :" keymap should apply to non-':'-command mode
    gg/.
    :call append(line('$'), " /"=="ю"?"OK":"FAIL_keymap_search")
    :" with keymap @a has same result as direct typing
    G@a
    :call append(line('$'), getline('.')=="ю"?"OK":"FAIL_keymap_register")
    :" keymap does not apply to ':'-command mode
    :set keymap=
    :" without keymap @a produces the unmapped keys
    G@a
    :call append(line('$'), getline('.')=="."?"OK":"FAIL_keymap_non")
    :" CHANGED_END
    :"
    :" issue #212 (feedkeys insert mapping at current position)
    :nnoremap . :call feedkeys(".", "in")<cr>
    :/^a b
    0qqdw.ifoo qj0@q :unmap .

    :" <c-g>U<cursor> works only within a single line
    :imapclear
    :imap ( ()<c-g>U<left>
    G2o ki
    Test1: text with a (here some more text k.
    :" test undo
    G2o ki
    Test2: text wit a (here some more text [und undo] u k.u
    :"
    :imapclear
    :set whichwrap=<,>,[,]
    G3o 2k
:exe ":norm! iTest3: text with a (parenthesis here\<C-G>U\<Right>new line here\<esc>\<up>\<up>."



    :/^test/,$w! test.out
    :qa!
    ENDTEST

    test starts here:

    a b c d
    a b c d


Here is the output of the current upstream vim


    test starts here:

    fooc d
    fooc d
    vim
    TEST2: CTRL-C |<ctrl-c>A|

    vmap works
    OK
    OK
    FAIL_nlangmap_registers
    OK
    +
    FAIL_nlangmap_noremap
    +
    OK
    FAIL_clangmap_colon
    OK
    OK
    OK
    ю
    OK
    OK
    .
    FAIL_keymap_register
    .
    OK

    Test1: text with a (here some more text)
    Test1: text with a (here some more text)


    Test2: text wit a (here some more text [und undo])

    new line here
    Test3: text with a (parenthesis here
    new line here

Correcting FAIL_keymap_register was the goal of this pull request.
I have an english keyboard layout. I'm interested in the keymap feature,
not in the langmap feature.

But since I'm at it I can also tackle the langmap issues.
It will probably take some time to finish, though,
depending on how much time I will have available for it.

Please confirm that the above test_mapping.in is the objective.

Regards, Roland

--
--
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