Setting Komodo preferences through a Macro

Komodo uses a number of preferences to control how the program is run. Most preferences are modified through the Komodo preferences dialog, though there are some that are not exposed through the UI.

The preferences are based on a default “prefs.xml” which can be found inside your Komodo installation directory, and then any preference changes to the base preferences are stored into your Komodo profile directory. Here is the default preferences file that Komodo starts out with:

The preferences can either be manually edited (whilst Komodo is shutdown), or can be changed (at runtime) using the Komodo API, such as through a JavaScript macro.

Some example JavaScript macros (which can be added to your Komodo toolbox) for changing preferences are listed below:

Getting a boolean preference

var pref_name = ko.interpolate.interpolateStrings(["%(ask: Boolean pref name)"]);
if (pref_name) {
    if (ko.prefs.hasBoolean(pref_name)) {
    alert("'" + pref_name + "': " + ko.prefs.getBoolean(pref_name));
    } else {
        alert("No boolean pref exists for '" + pref_name + "'");
    }
}

Setting a boolean preference

var pref_name = ko.interpolate.interpolateStrings(["%(ask: Pref name)"]);
if (pref_name) {
    var pref_value = ko.interpolate.interpolateStrings(["%(ask: Value: 1)"]);
    if (pref_value !== null) {
        if (pref_value == "1" || pref_value.toLowerCase() == "true") {
            ko.prefs.setBoolean(pref_name, true);
        } else {
            ko.prefs.setBoolean(pref_name, false);
        }
    }
}

Setting a string preference

var pref_name = ko.interpolate.interpolateStrings(["%(ask: Pref name)"]);
if (pref_name) {
    var pref_value = ko.interpolate.interpolateStrings(["%(ask: Value)"]);
    if (pref_value !== null) {
        ko.prefs.setString(pref_name, pref_value);
    }
}

Setting a number preference

var pref_name = ko.interpolate.interpolateStrings(["%(ask: Pref name)"]);
if (pref_name) {
    var pref_value = ko.interpolate.interpolateStrings(["%(ask: Value)"]);
    if (pref_value !== null) {
        ko.prefs.setLong(pref_name, parseInt(pref_value));
    }
}
1 Like

Nice! But I don’t see any point to change preferences via macro. Also it’s a little bit hackable, because I can change a lot of preferences and user just doesn’t know it because there are no alerts after changing a preference.
Also it will be good if somebody (e.g. you, Todd) show all available preferences to change (hidden and not).

Not all Komodo preferences are exposed in the preferences UI (the ones that are not are what we called “hidden” preferences). You can browse the prefs.p.xml file (linked above) for most of Komodo’s preferences.

It is sometimes useful to toggle a Komodo feature by manipulating a preference (e.g. disable code intelligence) - and it’s much faster to change a preference with a macro than through the preferences dialog.

You can also use the preference APIs for writing more powerful macros (or extensions) - as preferences will persist state between Komodo sessions.

2 Likes