lime icon

Phosphorus and Lime

A Developer's Broadsheet

This blog has been deprecated. Please visit my new blog at klenwell.com/press.
Komodo Edit Macros
Well, as soon as I had settled upon gvim as my new editor de riguer, a friend at work pointed me to Komodo Edit. Now this is what I was looking for. What a weight off my mind.

Never been a big macro-head, but there's a couple things I wanted to do that you can't do through the preferences menu alone. So I figured out a couple tricks and wrote the following macros. (What is cool is that you can use either javascript or python for the macros. Sweet!)

add html comment
// comment_html: <!-- {|} -->
// author: klenwell@gmail.com
komodo.assertMacroVersion(2);

var addLeft = '<!-- ';
var addRight = ' -->';
var currentPos = komodo.editor.currentPos;
var selText = komodo.editor.selText;
var newText = addLeft + selText + addRight;
var selTextPos = currentPos - selText.length + newText.length;
var noSelTextPos = currentPos + newText.length - addRight.length;
var newPos = ( selText != '' ) ? selTextPos : noSelTextPos;


if (komodo.view.scintilla) { komodo.view.scintilla.focus(); }
//if (komodo.view) { komodo.view.setFocus() };

komodo.view.selection = newText;
komodo.editor.gotoPos(newPos);
komodo.view.selection = '';


this will wrap any select text like so: <!-- {select text} --> or add an empty wrapper with the cursor in the middle: <!-- | -->

The same principle can be applied to many situations:

echo php inline
// echo_php_inline: <?php echo {|} ?>
// author: klenwell@gmail.com
komodo.assertMacroVersion(2);

var pcmd = 'echo'; // echo or print
var addLeft = '<?php '+pcmd+' ';
var addRight = '; ?>';
var currentPos = komodo.editor.currentPos;
var selText = komodo.editor.selText;
var newText = addLeft + selText + addRight;
var selTextPos = currentPos - selText.length + newText.length -3;
var noSelTextPos = currentPos + newText.length - addRight.length;
var newPos = ( selText != '' ) ? selTextPos : noSelTextPos;


if (komodo.view.scintilla) { komodo.view.scintilla.focus(); }
//if (komodo.view) { komodo.view.setFocus() };

komodo.view.selection = newText;
komodo.editor.gotoPos(newPos);
komodo.view.selection = '';


Add a key-binding through the properties menu and you're a rockstar.
You should also check out Toolbox snippets and the 'Abbreviations functionality:

http://aspn.activestate.com/ASPN/docs/Komodo/4.3/abbreviations.html

It will do a lot of the same things you are doing in your code, but it is already built into Komodo.
Thanks for the heads up.