Komodo is really designed for scripting/interpreted languages. However, I quite like it (although it’s a bit sluggish, but that may be me), and I’d like to use it for the small amount of compiled stuff I do.
For instance, I had cause to decompile, edit and recompile a Java application. I was able to edit it using Komodo IDE, however the debugger doesn’t work, and it doesn’t execute.
I did come up with the following command that will check the modified dates on the source and target files, if necessary compile the source to byte code, and then execute the program. This is for Java only at this stage, however, I’m planning to extend it.
if test "%F" -nt "%b.class"; then
{
echo Compiling %F; javac "%F" ;
if test "$?" == "0"; then
echo Executing %b.class; java -classpath . "%b";
fi;
} else {
echo Compiled file %b.class is up to date;
echo Executing %b.class; java -classpath . "%b";
} fi
This was all on one line in the Add Command… box:
if test "%F" -nt "%b.class"; then { echo Compiling %F; javac "%F" ; if test "$?" == "0"; then echo Executing %b.class; java -classpath . "%b"; fi; } else echo Compiled file %b.class is up to date; echo Executing %b.class; java -classpath . "%b"; fi
I’m actually going to go a bit further and create a toolbar for compiling programs, which may take the form of language extensions, or GUI extensions, or just plain macros and commands.
The other thing I really liked about SubEthaEdit was that you can get the source code as HTML, that is, code that keeps the syntax colouring, which can be cut and pasted into your blogging client/whatever. I’ll have to try to build this too. There is already an extension out there, called Clipboard Helper Extension, that puts a new contextual menuitem into the mix that allows for copying as encoded HTML entities, or as a URL. This could be used as a basis for Copy as XHTML Source.
Basically what I need to be able to do is get the editor’s data about syntax highlighting (preferably with the class names, such as string, and so on), and them mark up the plain text using this. Then escape the HTML entities (or do this first), and place into the clipboard.
Finally, back onto Java source code. I can get it so that double-clicking on a Java Source file will cause it to be edited by Komodo, but only if Komodo is already running. It seems that on startup, it checks the filetype being passed to it, or something, and fails to load properly if it isn’t a predetermined type. It works with the predefined python, perl and so on, but not Java. Strange.
Well, styled HTML source, showing Syntax Highlighting is simple. Create a new macro, make it use Python, and:
import komodokomodo.view.setFocus()
komodo.doCommand("cmd_exportHTML")
or
import komodokomodo.view.setFocus()
komodo.doCommand("cmd_exportHTMLSelection")
It’s defaults are a bit ordinary, but I’m still working on tweaking it. I generally don’t want it to be saved, but that might do for now.
12 hours, 8 minutes after the fact.
Further on to HTML styling:
This should work, however at the moment it causes a freeze. Still hacking away, however.
13 hours, 28 minutes after the fact.
Hmm. Seems to be some sort of an infinite loop, but I can’t figure out why.
13 hours, 59 minutes after the fact.
Bada Bing!
from xpcom.server import UnwrapObject ch = components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(components.interfaces.nsIClipboardHelper) buf = UnwrapObject(document.ciBuf) ch.copyString(buf.to_html(False,False,None,True,True))
14 hours, 34 minutes after the fact.
Further improved to clean code up a bit:
from xpcom.server import UnwrapObject
import re buf = UnwrapObject(document.ciBuf)
html = buf.to_html(False,False,None,True,True)
html = html.replace('onmouseover="show_class(event.target);"','')
html = html.replace("'","'")
html = re.sub('SCE_P_.*? ','',html) ch = components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(components.interfaces.nsIClipboardHelper)
ch.copyString(html)
It now removes a heap of excess fluff that I don’t require.
17 hours, 6 minutes after the fact.
Ignore the last one, there seems to be some issues with it.
1 day, 14 hours after the fact.
Aha, because it’s python code generating HTML from python code, it’s not working on the re.sub() properly. I’ll have to hand edit that code then.
1 day, 14 hours after the fact.
All fixxed, the code in the comment three above this one is the latest code. I’ll write a new post later about it.
The problem I was having was that the re.sub() code was matching itself, since it was operating on itself. So, I had to re-add it back in.
1 day, 14 hours after the fact.