Komodo Macros for inserting CakePHP template hints

update #2: This is obsoleted by jeffg’s work here: http://community.activestate.com/node/2794

update: Incorporated Matt Curry‘s change below. I just wanted to let people know that I don’t use this and don’t suggest using it. I whipped it up in response to a similar trick for for another IDE. This is one area in which Komodo could really use some improvement.
A possible simple solution: ability to specify project-wide mappings of variable types? might determine appropriate context based on regex for filenames and/or considering current language context.

For most of my day-to-day editing I use Komodo (though vim is always rivaling it for the simpler things and some remote things — sshfs rocks).

While Komodo does a pretty good job with completion within Cake’s controllers and models it lacks a bit in views. It’s not capable of determining what classes the helpers are instances of. These macros provide it with the hinting needed.

These two Komodo macros allow you to insert arbitrary text to the end of a file and then remove it

The setup I have here is intended to add text to the end of CakePHP‘s ctp (view extension for 1.2 branch) files. I have the macros set to trigger on file save and after save, respectively.

add_text_to_eof:

var textToAdd =
''exit();n' +
'$ajax = new AjaxHelper();n' +
'$cache = new CacheHelper();n' +
'$form = new FormHelper();n' +
'$html = new HtmlHelper();n' +
'$javascript = new JavascriptHelper();n' +
'$number = new NumberHelper();n' +
'$session = new SessionHelper();n' +
'$text = new TextHelper();n' +
'$time = new TimeHelper();n' +
'?>';

komodo.view.setFocus();
try {
    var ke = ko.views.manager.currentView.scimoz;
    var fileName = ko.views.manager.currentView.document.baseName;
    var fileEligible = fileName.match(/.ctp$/);
    if (fileEligible) {
        ke.insertText(ke.textLength, textToAdd);
        komodo.window.add_text_to_eof_textAdded = textToAdd;
    }
} catch(e) {
    alert(e);
}

add_text_to_eof_undo:

komodo.view.setFocus();
try {
    var ke = ko.views.manager.currentView.scimoz;
    var fileName = ko.views.manager.currentView.document.baseName;
    var fileEligible = fileName.match(/.ctp$/);
    if (fileEligible) {
        if (typeof(komodo.window.add_text_to_eof_textAdded) !== 'undefined') {
            ke.text = ke.text.replace(komodo.window.add_text_to_eof_textAdded, '');
        }
    }
} catch(e) {
    alert(e);
}
  • http://www.openkomodo.com/blogs/jeffg JeffG

    Is it just me or is there no kpf file in the kpz archive?

  • tclineks

    Hi Jeff,
    when I manually extract the kpz I get the project.kpf

    I created it by simply selecting the two macros and exporting as package.

    I’m able to reimport it as well.

  • http://www.pseudocoder.com Matt Curry

    Thanks for this. I was having trouble where I was saving a file and the macro was removing what it thought was the hints, but was actually part of my code.

    I replaced the inside of the second if-statement with this:
    ke.text = ke.text.replace(komodo.window.add_text_to_eof_textAdded, “”);

  • http://www.viazanie.eu Expresné Viazanie Diplomoviek

    Thanks a lot for this article. Greetings from Slovakia :)

  • Pingback: traviscline.com » Komodo Macros for inserting CakePHP template hints | Source code bank