<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Wolfmans Howlings: JEdit - Textmate for the rest of us?</title>
    <link>http://blog.wolfman.com/articles/2006/11/21/jedit-textmate-for-the-rest-of-us</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>A programmers Blog about Ruby, Rails and a few other issues</description>
    <item>
      <title>JEdit - Textmate for the rest of us?</title>
      <description>&lt;p&gt;OK after
&lt;a href="http://blog.wolfman.com/articles/2006/09/30/epsilon-programmers-editor"&gt;expounding&lt;/a&gt;
on how much I like Epsilon as an editor, I finally hit a wall with it.
I wanted tabs of the currently open files, and it simply does not
provide that facility yet. (I know all modern editors do!). On X11 (IE
Linux and OS/X) Epsilon is not really a graphical app, it does open an
X11 window, but within it most dialogs and lists (like buffer lists
etc) are text, a little like a curses app. The advantage is it opens
really fast, and loads huge files pretty fast. The downside is you
don't get all those nice windowing facilities like movable pop-up
windows, dialogs, trees and tabs!&lt;/p&gt;

&lt;p&gt;So after hearing so much about JEdit, I bit the bullet and gave it a
whirl. Following the instructions from a number of blogs (too numerous
to mention) I installed it on my KUbuntu Linux box, with all the
plugins people recommend, and of course the Ruby plugin and
SupperAbbrevs (The beta version), so I have my snippets!&lt;/p&gt;

&lt;p&gt;Being used to an Emacs like editor I had to fuss around remapping all
my keys (or at least some of them), then map the new plugins to
reasonable key-bindings (called shortcuts in JEdit lingo).&lt;/p&gt;

&lt;p&gt;I have to say I am pretty impressed, it does everything I want (or
almost). It has a plugin for tabs, it has a project manager, and
HTML/XML modes. The Ruby mode is pretty good, modeled after Textmate.&lt;/p&gt;

&lt;p&gt;So the things that were missing that I had become accustomed to were.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Expanding #{} in a string when you type # - &lt;em&gt;Wrote a macro to do that&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Being able to select a snippet (called abbreviation in the lingo)
from a list rather than having to remember the abbreviation. - &lt;em&gt;wrote a macro to do it&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Some Emacs like behavior like control-K etc. - &lt;em&gt;found it in the macros manager&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Toggling between view and controller (and model) in a rails project - &lt;em&gt;Wrote one, but found a better one in macros&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Being able to use snippets (OK abbreviations!) from a different
language mode. eg I'm in rhtml but I want an HTML abbreviation, or
vice versa. - &lt;em&gt;wrote a macro to do it&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Running ruby scripts into a local buffer - &lt;em&gt;the console plugin solved this&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Running Focused Ruby Unit tests - &lt;em&gt;wrote a macro to do it&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So at first I thought I would have to hack the various plugins, but
then I discovered the beanShell macros are extremely powerful,
basically they are java syntax, but have full access to the JEdit
internals and most of the plugins internals too. As Java is my second
favorite language, this was a nice surprise. (You should guess by now
Ruby is my current favorite language).&lt;/p&gt;

&lt;p&gt;So I went about writing macros to fill in the gaps, to see if I could
switch to JEdit.&lt;/p&gt;

&lt;p&gt;As a side note I will not buy a Mac so I can use Textmate! as awesome
as Textmate is, it is not enough to get me to switch, so I will get
JEdit as close to it as I can, maybe even further. (I worked on a
MacBook Pro Intel for 3+ months, and was not sold).&lt;/p&gt;

&lt;p&gt;Yes JEdit actually has intellisense-like completion for Ruby. A
&lt;a href="http://blog.wolfman.com/articles/2006/08/09/experiences-with-komodo-pro-and-ruby"&gt;previous blog entry&lt;/a&gt;
of mine explained how I tried Komodo to get this, but it was not very
good, however the JEdit version found in the latest RubyPlugin, works
pretty well, I think it uses parsing from the JRuby project, so no
surprise it works. &lt;/p&gt;

&lt;p&gt;In addition it also has a pretty good ruby and rails help, that is
linked to the autocomplete, it is missing a few rails entries, but is
very handy. Features of this clever plugin are found
&lt;a href="http://rubyjedit.org/features/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;All this and JEdit is free!&lt;/p&gt;

&lt;p&gt;Back to the macro writing.&lt;/p&gt;

&lt;p&gt;The first hack, er I mean Macro, was to expand # to #{} when it is in
a string. This was relatively easy, as shown below. I just has to make
sure I was actually in a string, and take into account escaped quotes
and escaped #. Anyway the macro works quite well, I think it would be
better off in the RubyPlugin, but never mind.&lt;/p&gt;

&lt;p&gt;It took me a while to think of beanshell as Java, I kept wanting to
leave off ; and other scripting language things, but it really is
Java, just scripted, very impressive language, I have no idea how they
do it, if they compile on the fly or interpret, but it works, and you
have full access to Swing, and as I have written many thousands of
lines of Java/Swing code over the years, I was back in business. (It
did take me a while to remember that stuff though as my Swing Feng was
a few years old).&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_java "&gt;// Expand # to #{} if in quotes
boolean escaped() {
  pos= textArea.getCaretPosition();
  str= textArea.getText(pos-1, 1);
  return(str.equals(&amp;quot;\\&amp;quot;));
}

boolean inQuotes() {
  cl= textArea.getCaretLine();
  str= textArea.getLineText(cl);
  pos= (textArea.getCaretPosition() - textArea.getLineStartOffset(cl))-1;
  cnt= 0;
  do{
    off= str.lastIndexOf(&amp;quot;\&amp;quot;&amp;quot;, pos);
    if(off &amp;lt; 0)
      break;
    else if(off == 0 || str.charAt(off-1) != '\\')
      cnt++;
    pos= off-1;
  }while(pos &amp;gt;= 0);
  return (cnt &amp;amp; 1) != 0;
}

if((buffer.getMode().getName().equals(&amp;quot;ruby&amp;quot;) || buffer.getMode().getName().equals(&amp;quot;rhtml&amp;quot;)) &amp;amp;&amp;amp; inQuotes() &amp;amp;&amp;amp; !escaped()){
  textArea.setSelectedText(&amp;quot;#{}&amp;quot;);
  textArea.goToPrevCharacter(false);
}else{
    textArea.setSelectedText(&amp;quot;#&amp;quot;);
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The next one was recreating my Epsilon Hack that toggles between view
and controller. I found a great starting macro which toggled between
model and controller, so I just modified that a bit, using the same
basic technique, and within a few hours I had my view/controller
toggle. It may not be as robust as my Epsilon version, as it does a
pretty naive search to find what method it is in, in the controller,
but it seems to work. Of course, as with Textmates version, it only works
if the rails naming conventions are followed. 
&lt;a href="http://blog.wolfman.com/files/toggle_view_controller.bsh"&gt;Download from here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;UPDATE&lt;/em&gt; I have found a much better implementation with all the bells
and whistles of the Textmate version
&lt;a href="http://community.jedit.org/?q=node/view/3246"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The big one was getting a list up to show the SupperAbbrevs snippets
for any given mode, and selecting the one you want. This took a good
part of a day, I had to study the SupperAbbrevs code, and I found a
good starting point with a macro that lists abbreviations from the
built-in JEdit abbreviations. I use a good part of that, and just
changed it so you can select one of the abbreviations and use that to
insert the snippet. I ran into a few quirks with JTable and selection,
but that was because I was pretty rusty, I have solved those problems
before, I had just forgotten how to.&lt;/p&gt;

&lt;p&gt;So now I can type a portion or just one letter of an abbreviation, hit
Alt-Space and I get a pop-up with all the abbreviations of the current
mode, and the first one that matches what I have typed so far already
selected. Hitting enter will insert that one, or I can select the one
I want, and hit enter or click Expand, and it does its magic. I need
this as I can never remember all those abbreviations, for all the
rails and ruby snippets. (Not even Textmate can do that!) Of course I
can still type in the whole abbreviation and hit TAB to get the quick
expansion as before.&lt;/p&gt;

&lt;p&gt;Now something that Textmate does that I like is you can click on an
icon and you get a list of all the modes then you can select a snippet
from any mode and insert it. I don't think macros will let you do
exactly that, (I think that would require a plugin), but the next best
thing is hitting Alt-Space with nothing in front of it, and I get a
pop up. I can select the mode I want then the snippet from the table,
and click insert, and it does the same thing. Just a few extra mouse
clicks than Textmate, but close enough for me.&lt;/p&gt;

&lt;p&gt;Now I just have to figure out how to contribute these macros to the
Textmate community, the Wiki is closed to registered users only, and I
got no reply when I tried to register.&lt;/p&gt;

&lt;p&gt;I'll put all my macros here for now, until they register me. Then you
will be able to download these macros from the nice MacroManager
plugin they have in JEdit. So far there seems to be a plugin or macro
for almost everything. The other macros are all available via the
macroManager plugin, including the toggle between model and controller
one. The Emacs macros are also available from the same utility.&lt;/p&gt;

&lt;p&gt;I should say I am using the 4.2stable version of JEdit, I played with
4.3pre8 but it was throwing a lot of exceptions on the screen,
although none fatal, but it did seem to be a little slower, I'll wait
for it become more stable before trying again.&lt;/p&gt;

&lt;p&gt;The RubyPlugin is available from the plugin manager, the latest
version of superAbbrevs is not however, I got it from this 
&lt;a href="http://community.jedit.org/?q=filestore/download/2761"&gt;link&lt;/a&gt; explained 
&lt;a href="http://community.jedit.org/?q=node/view/2761"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These were the most useful howtos I found
&lt;a href="http://www.eadz.co.nz/blog/article/ruby-rails-jedit.html"&gt;ruby-rails-jedit&lt;/a&gt;,
and &lt;a href="http://saimonmoore.net/2006/1/24/jedit-for-ruby-rails-development"&gt;jedit-for-ruby-rails-development&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;but there are literally hundreds around.&lt;/p&gt;

&lt;p&gt;Another idea taken from Textmate is a macro that runs the current Ruby
Unit Test case, download from &lt;a href="http://blog.wolfman.com/files/Run_Test_Case.bsh"&gt;here&lt;/a&gt;.
It will run a focused test only on the testcase the cursor is currently in.&lt;/p&gt;

&lt;p&gt;Here is the &lt;a href="http://blog.wolfman.com/files/Select_Super_Abbrevs.bsh"&gt;download link&lt;/a&gt;
for the biggest Macro I have done to date, it is the
one that allows you to select a SuperAbbrev snippet.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://technorati.com/tag/jedit+rails" rel="tag"&gt;&lt;/a&gt;
&lt;a href="http://technorati.com/tag/jedit+ruby" rel="tag"&gt;&lt;/a&gt;
&lt;a href="http://technorati.com/tag/superabbrevs+rails" rel="tag"&gt;&lt;/a&gt;
&lt;a href="http://technorati.com/tag/superabbrevs+ruby" rel="tag"&gt;&lt;/a&gt;
&lt;a href="http://technorati.com/tag/jedit+macros" rel="tag"&gt;&lt;/a&gt;
&lt;a href="http://technorati.com/tag/jedit+ruby+completion" rel="tag"&gt;&lt;/a&gt;
&lt;a href="http://technorati.com/tag/jedit+snippets" rel="tag"&gt;&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 21 Nov 2006 23:20:07 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:0d889ce0-4501-4f05-ac18-e41bb19d80b8</guid>
      <author>Jim Morris</author>
      <link>http://blog.wolfman.com/articles/2006/11/21/jedit-textmate-for-the-rest-of-us</link>
      <category>Rails</category>
      <category>Ruby</category>
      <category>JEdit</category>
      <category>ruby</category>
      <category>rails</category>
      <category>jedit</category>
      <category>textmate</category>
      <trackback:ping>http://blog.wolfman.com/articles/trackback/74</trackback:ping>
    </item>
    <item>
      <title>"JEdit - Textmate for the rest of us?" by wolfmanjm</title>
      <description>&lt;p&gt;You can put the macro anywhere in the .jedit/macros folder. Then reload macros to see it. Then you assign the # key as a shortcut to it, and so whenever you are in ruby mode and in a string typing # will generate #{}.&lt;/p&gt;

&lt;p&gt;I use ALT-SPACE for the shortcut to the snippet selection macro&lt;/p&gt;</description>
      <pubDate>Thu, 26 Jul 2007 11:39:31 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:b1249bcd-d191-4a78-867c-e8f407754eda</guid>
      <link>http://blog.wolfman.com/articles/2006/11/21/jedit-textmate-for-the-rest-of-us#comment-113</link>
    </item>
    <item>
      <title>"JEdit - Textmate for the rest of us?" by Dave</title>
      <description>&lt;p&gt;Great job.  I have a couple of questions:
Where would you place the "Expand Pound" macro, and how would you use it?&lt;/p&gt;

&lt;p&gt;What keystroke do you find most comfortable to tie to your SuperAbbrev Snippet Selection macro?&lt;/p&gt;</description>
      <pubDate>Thu, 26 Jul 2007 10:34:11 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:d6d2a9d9-0333-41ab-8967-ade4ee3704bb</guid>
      <link>http://blog.wolfman.com/articles/2006/11/21/jedit-textmate-for-the-rest-of-us#comment-112</link>
    </item>
    <item>
      <title>"JEdit - Textmate for the rest of us?" by testrails</title>
      <description>&lt;p&gt;for ruby source code beautification you could use this ruby beautify snippet and that macro using the console plugin for jedit&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.arachnoid.com/ruby/rbeautify.rb.txt" rel="nofollow"&gt;http://www.arachnoid.com/ruby/rbeautify.rb.txt&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;void beautifyRubyCode(Buffer buffer)
{
  Registers.setRegister('$',buffer.getPath());&lt;/p&gt;

&lt;p&gt;runCommandInConsole(view,"System","ruby beauty.rb " + buffer.getPath() );&lt;/p&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;beautifyRubyCode(buffer);&lt;/p&gt;</description>
      <pubDate>Tue, 01 May 2007 10:06:36 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:0e6b8328-b544-4e23-a412-e6ff89cab763</guid>
      <link>http://blog.wolfman.com/articles/2006/11/21/jedit-textmate-for-the-rest-of-us#comment-70</link>
    </item>
    <item>
      <title>"JEdit - Textmate for the rest of us?" by Sune Simonsen</title>
      <description>&lt;p&gt;Hey Wolfmans Howlings
Your snippet selection macro is very nice, I was planing to make this in the feature. This really shows the power of jedit, it lets you avoid waiting for the lazy author of the plugin :-D&lt;/p&gt;</description>
      <pubDate>Wed, 06 Dec 2006 05:56:33 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:bef85462-cac6-4d19-9be0-adf0ac9771c3</guid>
      <link>http://blog.wolfman.com/articles/2006/11/21/jedit-textmate-for-the-rest-of-us#comment-15</link>
    </item>
    <item>
      <title>"JEdit - Textmate for the rest of us?" by Vovan</title>
      <description>&lt;p&gt;Great work!
Very usefull things for any ror developer that uses jedit :-)&lt;/p&gt;</description>
      <pubDate>Mon, 27 Nov 2006 02:38:42 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:53ed121d-e5df-4631-99b4-e1a0f8b1c47d</guid>
      <link>http://blog.wolfman.com/articles/2006/11/21/jedit-textmate-for-the-rest-of-us#comment-2</link>
    </item>
  </channel>
</rss>
