Wolfmans Howlings

A programmers Blog about Programming solutions and a few other issues

JEdit - Textmate for the rest of us?

Posted by Jim Morris on Tue Nov 21 23:20:07 -0800 2006

OK after expounding 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!

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!

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).

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.

So the things that were missing that I had become accustomed to were.

  • Expanding #{} in a string when you type # - Wrote a macro to do that
  • Being able to select a snippet (called abbreviation in the lingo) from a list rather than having to remember the abbreviation. - wrote a macro to do it
  • Some Emacs like behavior like control-K etc. - found it in the macros manager
  • Toggling between view and controller (and model) in a rails project - Wrote one, but found a better one in macros
  • 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. - wrote a macro to do it
  • Running ruby scripts into a local buffer - the console plugin solved this
  • Running Focused Ruby Unit tests - wrote a macro to do it

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).

So I went about writing macros to fill in the gaps, to see if I could switch to JEdit.

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).

Yes JEdit actually has intellisense-like completion for Ruby. A previous blog entry 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.

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 here.

All this and JEdit is free!

Back to the macro writing.

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.

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).

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. Download from here

UPDATE I have found a much better implementation with all the bells and whistles of the Textmate version here.

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.

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.

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.

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.

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.

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.

The RubyPlugin is available from the plugin manager, the latest version of superAbbrevs is not however, I got it from this link explained here

These were the most useful howtos I found ruby-rails-jedit, and jedit-for-ruby-rails-development.

but there are literally hundreds around.

Another idea taken from Textmate is a macro that runs the current Ruby Unit Test case, download from here. It will run a focused test only on the testcase the cursor is currently in.

Here is the download link for the biggest Macro I have done to date, it is the one that allows you to select a SuperAbbrev snippet.

Posted in JEdit,Rails,Ruby  |  Tags ruby,rails,jedit,textmate  |  6 comments

Comments

  1. Vovan said on Mon Nov 27 02:38:42 -0800 2006
    Great work!
    Very usefull things for any ror developer that uses jedit :-)
  2. Sune Simonsen said on Wed Dec 06 05:56:33 -0800 2006
    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
  3. testrails said on Tue May 01 10:06:36 -0700 2007
    for ruby source code beautification you could use this ruby beautify snippet and that macro using the console plugin for jedit

    http://www.arachnoid.com/ruby/rbeautify.rb.txt

    void beautifyRubyCode(Buffer buffer)
    {
      Registers.setRegister('$',buffer.getPath());
      
      runCommandInConsole(view,"System","ruby beauty.rb " + buffer.getPath() );

    }

    beautifyRubyCode(buffer);
  4. Dave said on Thu Jul 26 10:34:11 -0700 2007
    Great job. I have a couple of questions:
    Where would you place the "Expand Pound" macro, and how would you use it?

    What keystroke do you find most comfortable to tie to your SuperAbbrev Snippet Selection macro?
  5. wolfmanjm said on Thu Jul 26 11:39:31 -0700 2007
    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 #{}.

    I use ALT-SPACE for the shortcut to the snippet selection macro
  6. sickill said on Sun Jan 25 05:58:35 -0800 2009
    Kudos for promoting JEdit! If you are intereseted in making your JEdit a little prettier I've written converter from Textmate's colour scheme format to JEdit's format. Please check my post at http://sickill.net/blog/2009/01/20/textmate-to-jedit-colour-theme-converter.html . You can grab there the converter and/or already converted 16 schemes.

(leave email »)