Keyloop #276

Closed
wants to merge 5 commits into
from

Projects

None yet

3 participants

@mattn
Contributor
mattn commented Sep 12, 2012

CtrlP has mapping to ASCII or control characters. So we can't type multi-byte characters into CtrlP's prompt. This patch provides key event loop to handle multi-byte characters with IME(input method editor).
If set g:ctrlp_key_loop = 1, enable this feature.
I guess this is awesome useful for users who using multi-byte characters. (me too)

@kien kien commented on an outdated diff Sep 12, 2012
autoload/ctrlp.vim
@@ -529,6 +535,20 @@ fu! s:BuildPrompt(upd)
exe 'echoh' hibase '| echon "_" | echoh None'
en
endf
+
+fu! s:KeyLoop()
+ wh exists('s:focus') && s:focus
+ redraw
+ let n = getchar()
+ let c = type(n) == 0 ? nr2char(n) : n
+ if n >=# 0x20
+ cal s:PrtFocusMap(c)
+ el
+ exe "keepj normal" c
@kien
kien Sep 12, 2012 Owner

Is this supposed to be normal! with an !?

Edit: nvm, should have read it more carefully instead of reflexively asking where the ! went.

@kien
Owner
kien commented Sep 12, 2012

OK, since I can't really test this, I'll trust you on it. I'll merge and push it out soon.

@d11wtq
d11wtq commented Sep 12, 2012

If I understand what it's supposed to do, I can probably test it. I work with some romance and Nordic languages that include accented vowels like é and è and Nordic characters like ð, þ and æ. Not sure if the idea is to allow those characters to be typed in ctrlp or not though. Currently they don't type correctly, at least on OS X's Terminal.app.

@d11wtq
d11wtq commented Sep 12, 2012

Holy crap it works :) I can type all those characters from European languages just fine with this patch merged in. I can't type Japanese Hiragana (こんにちわ) or Katakana (コンニチワ) using the Kotoeri keyboard on OS X, but that does some weird stuff where you have to type sequences of English characters in order to type a single Japanese character.

@d11wtq
d11wtq commented Sep 12, 2012

The fuzzy search doesn't trip on the multibyte characters neither.

@mattn
Contributor
mattn commented Sep 12, 2012

Chris, Can you explain what's wrong?
And please let me know the code point of them.
You can make sure the code point with:

:echo getchar()

On 9/13/12, Chris 'Chippie' Corbyn notifications@github.com wrote:

If I understand what it's supposed to do, I can probably test it. I work
with some romance and Nordic languages that include accented vowels like é
and è and Nordic characters like ð, þ and æ. Not sure if the idea is to
allow those characters to be typed in ctrlp or not though. Currently they
don't type correctly, at least on OS X's Terminal.app.


Reply to this email directly or view it on GitHub:
#276 (comment)

  • Yasuhiro Matsumoto
@d11wtq
d11wtq commented Sep 12, 2012

@mattn I was saying that without your patch the characters can't be typed. With your patch (which I only tried after writing that first comment) I can confirm that the characters are typed as expected. I think it should be merged, since it's definitely a big improvement in the i18n department :)

@kien
Owner
kien commented Sep 12, 2012

That's awesome. Thanks, @d11wtq!

I encountered a few problems with the control mappings. For example, pressing <tab> (9) throws an E471, and pressing <c-\> (28) or <c-o> (15) does nothing.

@d11wtq
d11wtq commented Sep 12, 2012

@kien, no problem. I just tried the mappings you mention and got different behaviour. Tab does nothing (might be because I also have supertab installed), but <c-\> brings up "Insert: c[w]ord/c[f]ile/[s]earch/[v]isual/[c]lipboard/[r]egister?" and <c-o> brings up the "Open:" prompt. I wonder if it makes a difference what Terminal is used.

@mattn
Contributor
mattn commented Sep 13, 2012

I modified code to handle few mapped key codes.

@d11wtq
d11wtq commented Sep 13, 2012

@mattn @kien tested the update, tab now works, as do <c-o> and <c-\>. The multibyte chars still work too.

@kien
Owner
kien commented Sep 13, 2012

Yep, that seems to fix it. But I just noticed, this stops working after toggling the focus with <s-tab> then back again. I tried adding another s:KeyLoop() call after toggling but this in turn causes errors when closing ctrlp. Any idea?

@mattn
Contributor
mattn commented Sep 13, 2012

@kein could you please show me the code you modified? and please let me know way to reproduce.

@kien
Owner
kien commented Sep 13, 2012

This solves the above problem for me, not sure if there's any side effect yet:

+++ b/autoload/ctrlp.vim
@@ -561,7 +561,7 @@ fu! s:BuildPrompt(upd)
 endf

 fu! s:KeyLoop()
-   wh exists('s:focus') && s:focus
+   wh exists('s:init')
        redr
        let n = getchar()
        let c = type(n) == 0 ? nr2char(n) : n
@@ -739,7 +739,7 @@ fu! s:PrtSelectJump(char)
            let npos = match(lines, smartcs.'^'.chr, s:jmpchr[1] + 1)
            let [jmpln, s:jmpchr] = [npos == -1 ? pos : npos, [chr, npos]]
        en
-       keepj exe jmpln + 1
+       exe 'keepj norm!' ( jmpln + 1 ).'G'
        if s:nolim != 1 | let s:cline = line('.') | en
        if line('$') > winheight(0) | cal s:BuildPrompt(0) | en
    en
@mattn
Contributor
mattn commented Sep 13, 2012

I don't get any problems with your changes.

kien++

@kien kien added a commit that closed this pull request Sep 15, 2012
@mattn @kien mattn + Option for typing multi-byte and accented characters
Closes #276
6089090
@kien kien closed this in 6089090 Sep 15, 2012
@kien
Owner
kien commented Sep 15, 2012

Merged. Thanks, @mattn! This is a very nice addition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment