PDA

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



KLyonawesome
09-28-2015,
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?

KristopherMcDougall
09-29-2015,
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.

kygiacomo
09-29-2015,
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.

Lakusus
10-01-2015,
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.