Quick toggle of file type in editor pane


#1

Unfortunately the Komodo UDL does not have support for code folding based on indent or blocks that do not end with a non-space character. This is a significant limitation for markup languages. I wrote a custom markup language (once) that colors syntax and sometimes I also need code folding because the documents are long. The YAML file type code folding works for my custom language but it does not color my syntax.

My workaround is a macro for each language, shown below, that can be run with keyboard shortcuts or buttons. If I want to fold the code I view it as a YAML file type. If I need syntax coloring I view it as a once file type. The folded state is retained between language toggling.

Python or JS can be used for the macro.

language 1 (macro in JS)

komodo.assertMacroVersion(5);
if (komodo.view) { komodo.view.setFocus();}

var curs1 = ko.views.manager.currentView.scimoz.currentPos;
ko.views.manager.currentView.koDoc.language ="once";
ko.views.manager.currentView.scimoz.gotoPos(curs1);

language 2 (macro written in Python)

import eollib
from xpcom import components
viewSvc = components.classes["@activestate.com/koViewService;1"].getService(components.interfaces.koIViewService)
view = viewSvc.currentView
view = view.queryInterface(components.interfaces.koIScintillaView)
sm = view.scimoz
curs1 = sm.currentPos 
view.koDoc.language ="YAML"
sm.gotoPos(curs1)

#2

Here is an example that toggles the language:

komodo.assertMacroVersion(5);
if (komodo.view) { komodo.view.setFocus();}

var curs1 = ko.views.manager.currentView.scimoz.currentPos;

if (ko.views.manager.currentView.koDoc.language == "once") {
        ko.views.manager.currentView.koDoc.language = "YAML";}
   else {
        ko.views.manager.currentView.koDoc.language = "once";}

ko.views.manager.currentView.scimoz.gotoPos(curs1);

#3

@rholland thanks for contributing! You could also do this with the new SDK.

var view = require("ko/views").current().get();
var koDoc = view.koDoc
var sci = view.scimoz;
var curPos = sci.currentPos;

if (koDoc.language == "once") 
    koDoc.language = "YAML";
else
    koDoc.language = "once";

sci.gotoPos(curPos);

No different than your code functionally, just using the new SDK we released in Komodo 9 and have been iterating on since.

Also, I really like variables I guess.

  • Carey