View Full Version : Possible to determine syntax highlighting token type at current editor position?

Is is possible, in a JavaScript macro in Komodo, to determine the syntax token type (e.g., M_DEFAULT, M_STRING or the SCE_ equivalents) at the current editor position? If so, how?

Hi, you can use something like this:
var scimoz = require('ko/editor').scimoz();
if (scimoz.getStyleAt(pos) == scimoz.SCE_UDL_M_STRING) {
// Do something
}Note the SCE_UDL_ prefix before a style constant name.

Is the scimoz object in that example the same scimoz object that is described in the current Komodo help? I haven't seen a reference to the getStyleAt() method before; is it documented somewhere? It may be and I've probably just missed it.

I threw together a quick macro to play with this:
try {
var e = require('ko/editor');
var s = e.getSelection();
var p = e.getCursorPosition('absolute');
var t = e.scimoz().getStyleAt(p);
alert('[selection]@position(type): [' + s + ']@' + p + '(' + t + ')');
catch(e) {
ko.dialogs.internalError(e, "Error: " + e);
}For instance, if I have the word "absolute" selected and run the macro on its own source, it alerts with the appropriate selection and position, but it returns a 7 for the style. In the above-linked version of the SCE_UDL_ constants, 7 is SCE_UDL_M_EMP_TAGC.