Is it possible to include multiple hint sources for autoplete? I tried this:
CodeMirrormands.autoplete = function(cm) {
CodeMirror.showHint(cm, CodeMirror.hint.xml);
CodeMirror.showHint(cm, CodeMirror.hint.html);
CodeMirror.showHint(cm, CodeMirror.hint.css);
CodeMirror.showHint(cm, CodeMirror.hint.javascript);
};
but it seems to just include the last source file that is referenced and ignore the rest. Is there any easy way of doing this?
Is it possible to include multiple hint sources for autoplete? I tried this:
CodeMirror.mands.autoplete = function(cm) {
CodeMirror.showHint(cm, CodeMirror.hint.xml);
CodeMirror.showHint(cm, CodeMirror.hint.html);
CodeMirror.showHint(cm, CodeMirror.hint.css);
CodeMirror.showHint(cm, CodeMirror.hint.javascript);
};
but it seems to just include the last source file that is referenced and ignore the rest. Is there any easy way of doing this?
Share Improve this question asked Oct 22, 2013 at 14:36 JeffJenkJeffJenk 2,6653 gold badges23 silver badges29 bronze badges2 Answers
Reset to default 10I found the answer to my question in another question so please excuse me if that makes this question a little redundant. What I needed to do is find out what mode is currently active (i am using a mixed mode) at the time autoplete is called. To do this first I needed the mode:
var mode = CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(POS).state).mode.name;
which I found here. For my situation I wanted to do that whenever the autoplete was called so my function looks like this:
CodeMirror.mands.autoplete = function(cm) {
var doc = cm.getDoc();
var POS = doc.getCursor();
var mode = CodeMirror.innerMode(cm.getMode(), cm.getTokenAt(POS).state).mode.name;
if (mode == 'xml') { //html depends on xml
CodeMirror.showHint(cm, CodeMirror.hint.html);
} else if (mode == 'javascript') {
CodeMirror.showHint(cm, CodeMirror.hint.javascript);
} else if (mode == 'css') {
CodeMirror.showHint(cm, CodeMirror.hint.css);
}
};
Now whenever the autoplete is called it checks what mode the editor is in at that specific point in the document.
A feature that handles this is already present in (recent versions of) CodeMirror, where you can define language-specific helper functions with defineHelper, and the standard pleter (show-hint.js) will, if you don't give it an explicit pletion function, use the one defined for the language. The standard pleter addons do register themselves as applicable to their languages, so it should work 'out of the box'.