Why autocomplete on codemirror not work alwayes when I press “.”?

I want to do autocomplete when I press the character “.” so I write :
CodeMirror.commands.autocomplete = function(cm) {
CodeMirror.showHint(cm, CodeMirror.hint.anyword);

  var editor = CodeMirror.fromTextArea(document.getElementById("area"), {
        lineNumbers: true,
            "'.'": "autocomplete",
            "'.'" : function(cm) { 
             setTimeout(function(){cm.execCommand("autocomplete");}, 10);
            throw CodeMirror.Pass; // tell CodeMirror we didn't handle the key 
            CodeMirror.showHint(cm, CodeMirror.hint.anyword); // I try to add it and remove this instraction but the same result 

the autocomplete work fine when I press “.” … but sometime the autocomplete not trigger when I press “.” (when that happen I remove the “.” and type “.” again then autocomplete work ) so My question Why sometime the autocomplete not work when I type “.” ? and in this case Why when I remove the “.” and type it again it work ?

The code you pasted looks like it is trying to include key bindings in the main options object, and the same binding twice too. It’d help if you could provide code that is more coherent.

Given the timeout, I’d guess this is some kind of race condition. A larger time would probably make it occur less. You might be able to get some useful input from this demo.