jEdit Mode for Clojure

173 views
Skip to first unread message

Daniel Spiewak

unread,
Nov 5, 2008, 7:35:08 PM11/5/08
to Clojure
Just thought it was about time I gave someone a heads up about this...

Mostly for amusement, I created a jEdit mode for Clojure a while
back. I don't get a chance to play with Clojure all that much, so it
hasn't been heavily tested ("go-to" *is* a Clojure "keyword",
right?). ;-) It's primarily based upon the Vim mode in terms of what
keywords it supports and how. Auto-indentation was something I looked
at, but it isn't something I actually bothered to support due to time
constraints (jEdit is capable of some pretty slick auto-indenting
where Lisp-like languages are concerned).

You can get the mode here: http://github.com/djspiewak/jedit-modes/tree/master/clojure.xml
Feedback is always welcome and I am willing to make changes to the
mode per request (hint: patches/pull requests not required, but
appreciated from those who know how to edit jEdit modes). You guys
use this language, not me, so you're a much better judge of what the
editor support should be like. Enjoy!

Daniel

tkosan

unread,
Nov 6, 2008, 12:41:29 PM11/6/08
to Clojure
Daniel wrote

> Mostly for amusement, I created a jEdit mode for Clojure a while
> back.  I don't get a chance to play with Clojure all that much, so it
> hasn't been heavily tested ("go-to" *is* a Clojure "keyword",
> right?).  ;-)  It's primarily based upon the Vim mode in terms of what
> keywords it supports and how.  Auto-indentation was something I looked
> at, but it isn't something I actually bothered to support due to time
> constraints (jEdit is capable of some pretty slick auto-indenting
> where Lisp-like languages are concerned).

This is good timing for me. I am in the process of integrating
clojure into a jEdit-based Mathematics Computing Environment I am
creating called MathRider:

http://mathrider.org

MathRider currently includes clojure but syntax highlighting is not
complete yet. I will look at your jEdit mode to see if it is more
functional than what MathRider is currently using. If you have time
to add auto-indentation, that would be great.

If anyone wants to experiment with clojure in MathRider, there is a
file called clojure_examples.mrw in the "mathrider/examples"
directory.

Ted Kosan

Daniel Spiewak

unread,
Nov 6, 2008, 3:17:41 PM11/6/08
to Clojure
After I posted this, I realized that it was a little silly to talk
about a Lisp editor mode without auto-indentation. It has been
added! The main caveat is it doesn't seem to handle multiple
unindents with the correctness I would like. For example:

(defn say-hi [n]
(println
(str "Hello, " n)))

; more code here

Obviously, the third line should result in two levels of
undindenting. However, due to limitations in the way that jEdit
handles auto-indenting, I don't think I can do both levels at once.
Specifically, the auto-indenting would assume that the "; more code
here" line should be indented at level 1, despite the fact that all
parens are closed by that point. It's possible that I may be able to
leverage jEdit's brace matching to unindent properly, but that will
require some more experimentation.

Daniel

Patrick Wright

unread,
Nov 23, 2008, 8:31:47 AM11/23/08
to Clojure
FYI, another developer has been working on an edit mode for clojure.
You can download it from
http://sourceforge.net/tracker/?func=detail&atid=300588&aid=2201893&group_id=588

See also this thread
http://www.nabble.com/Edit-mode-for-Clojure-ts20168077.html#a20168077

Note that the version in the jEdit tracker appears to be newer than
the one posted on the mailing list thread.

I haven't tried comparing them yet, but at some point I guess we
should pull them together into one.


Patrick

Daniel Spiewak

unread,
Dec 11, 2008, 1:34:37 PM12/11/08
to Clojure
It's been too long since I've looked at this thread...

I took a look at the mode you linked. My mode is quite a bit more
powerful, particularly with the changes I added today. The linked
mode does do some highlighting of special forms like @[...] that mine
doesn't do yet, mainly because I didn't know about them. Also, the
linked mode seems to be a bit inconsistent about which keyword levels
are used for what forms. Finally, the linked mode has very limited
support for comments (highlighting only). Using my mode, C+e C+c and C
+e C+k both work as expected, inserting ; and (comment ... ) as
necessary.

Daniel

On Nov 23, 7:31 am, Patrick Wright <pdoubl...@gmail.com> wrote:
> FYI, another developer has been working on an edit mode for clojure.
> You can download it fromhttp://sourceforge.net/tracker/?func=detail&atid=300588&aid=2201893&g...
>
> See also this threadhttp://www.nabble.com/Edit-mode-for-Clojure-ts20168077.html#a20168077
>
> Note that the version in thejEdittracker appears to be newer than

Daniel Spiewak

unread,
Dec 11, 2008, 1:37:09 PM12/11/08
to Clojure
Oh, also I should mention that I found the magic incantation to make
auto-indentation work perfectly. It handles multiple unindents just
fine now.

Daniel

Randall R Schulz

unread,
Dec 11, 2008, 1:44:30 PM12/11/08
to clo...@googlegroups.com
On Thursday 11 December 2008 10:34, Daniel Spiewak wrote:
> It's been too long since I've looked at this thread...
>
> I took a look at the mode you linked. My mode is quite a bit more
> powerful, particularly with the changes I added today. ...

Where do we find your latest version? Or do you want / need to refine it
further?

I never really thought I'd go back to jEdit, but Enclojure's still
broken and Peter's just getting started on his IDEA plug-in.


> Daniel


Randall Schulz

David Moss

unread,
Dec 11, 2008, 2:32:16 PM12/11/08
to clo...@googlegroups.com
Hi, just saw this thread. I had made some modifications to the edit mode and uploaded it for inclusion (as a patch) here: http://sourceforge.net/tracker/index.php?func=detail&aid=2201893&group_id=588&atid=300588.

I haven't checked the status in a while as my internet is very intermittent ATM. Please let me know if there is anything missing from it or if I can in any way enhance the mode.

Kind Regards,

David.

2008/12/11 Randall R Schulz <rsc...@sonic.net>

Daniel Spiewak

unread,
Dec 11, 2008, 3:54:34 PM12/11/08
to Clojure
> Where do we find your latest version? Or do you want / need to refine it
> further?

I'm constantly messing around with it and trying to make it a little
better. The very latest version is always here:
http://github.com/djspiewak/jedit-modes/tree/master/clojure.xml

Daniel

Randall R Schulz

unread,
Dec 11, 2008, 3:58:08 PM12/11/08
to clo...@googlegroups.com

Thanks. Is there any particular jEdit version requirement? I'm currently
running 4.3pre14


> Daniel


Randall Schulz

Daniel Spiewak

unread,
Dec 11, 2008, 3:58:29 PM12/11/08
to Clojure
> Hi, just saw this thread. I had made some modifications to the edit mode and
> uploaded it for inclusion (as a patch) here:http://sourceforge.net/tracker/index.php?func=detail&aid=2201893&grou...
> .
>
> I haven't checked the status in a while as my internet is very intermittent
> ATM. Please let me know if there is anything missing from it or if I can in
> any way enhance the mode.

I'll have to take a closer look at your new version. We probably
should merge our efforts. Your mode does do some things that mine
doesn't, and it doesn't really benefit anyone to have three competing
Clojure modes. :-) My mode is pretty convoluted in the way it uses
some <RULES/> tricks to highlight things like (def blah), so it's
probably easier if I steal your improvements and merge them into
mine. I'll give that a try later today and post back with the
results.

Daniel

Randall R Schulz

unread,
Dec 11, 2008, 4:39:51 PM12/11/08
to clo...@googlegroups.com
On Thursday 11 December 2008 12:54, Daniel Spiewak wrote:

Works in 4.3pre14 and looks great.

Thanks!


> Daniel


Randall Schulz

Daniel Spiewak

unread,
Dec 11, 2008, 8:30:37 PM12/11/08
to Clojure
I merged in all the interesting stuff from David Moss's Clojure jEdit
mode. We do highlight things in very different colors, but all of the
elements that his recognizes are also recognized by mine now. Also, I
fixed the annoying issue with def:

(def this)(def that)

The above now highlights correctly.

Feedback is welcome. I'm certainly willing to change the way things
are highlighted, add highlighting or remove it.

Daniel

blackdog

unread,
Dec 12, 2008, 6:10:20 AM12/12/08
to clo...@googlegroups.com

If anyone on this thread is interested I uploaded clj-jedit.tar.gz to
the group file section on an incomplete jedit plugin for clojure. It
has the hilighting, repl, and namespace browser (courtesy of enclojure)
- anyone want to take it on and improve it, I don't have time right
now?? It was based on the scheme plugin.

bd
--
None are more hopelessly enslaved than those who falsely believe they
are free — Goethe

Daniel Spiewak

unread,
Dec 12, 2008, 12:48:12 PM12/12/08
to Clojure
Which highlighting does it use?

Daniel

On Dec 12, 5:10 am, blackdog <black...@ipowerhouse.com> wrote:
> If anyone on this thread is interested I uploaded clj-jedit.tar.gz to
> the group file section on an incompletejeditplugin for clojure. It

David Moss

unread,
Dec 12, 2008, 2:15:18 PM12/12/08
to clo...@googlegroups.com
Daniel,

To be honest, the colours are the least important, much more relevant is that structures are recursed properly and that the base language is defined.

Let me know how you get on refining your mode and I'll have a look. When we have agreed on something I can update the jedit patch so we have the best superset in the editor.

Does it sound like a plan?

Kind Regards,

David.

2008/12/12 Daniel Spiewak <djsp...@gmail.com>

Daniel Spiewak

unread,
Dec 12, 2008, 2:26:06 PM12/12/08
to Clojure
Sounds like a good plan. :-) At the moment, I think that what's in
the mode is pretty solid, meaning I don't have anything planned to
refine it further. (except for regexp syntax, which I don't know
anything about) So, if you want to evaluate it now, that'd be great!

As a minor aside, I don't actually recursively parse S-expressions.
It's not a bad idea, but jEdit's weird treatment of eager-vs-lazy
matching sometimes gets in the way. Instead, I just define <SEQ
TYPE="OPERATOR">(</SEQ> and <SEQ TYPE="OPERATOR">)</SEQ>. I don't
really know when I'm in an S-exp, but I don't think that's too much of
a limitation. The only exception to the above is my highlighting of
"blah" in (def blah 123). That's done with an EOL_SPAN_REGEXP which
delegates to a new ruleset. This ruleset then in turn delegates back
to main in the case where the S-exp is closed prior to the end-of-
line. It's not a normal idiom for jEdit highlighting modes, but it
seems to work fine. At least I didn't have to resort to *really*
bizarre tricks like I did in my SASyLF and ReST modes (opening a SPAN
that terminates on an assumed non-existent character, etc).

Daniel

On Dec 12, 1:15 pm, "David Moss" <dsm...@gmail.com> wrote:
> Daniel,
>
> To be honest, the colours are the least important, much more relevant is
> that structures are recursed properly and that the base language is defined.
>
> Let me know how you get on refining your mode and I'll have a look. When we
> have agreed on something I can update the jedit patch so we have the best
> superset in the editor.
>
> Does it sound like a plan?
>
> Kind Regards,
>
> David.
>
> 2008/12/12 Daniel Spiewak <djspie...@gmail.com>

David Moss

unread,
Dec 13, 2008, 10:01:37 AM12/13/08
to clo...@googlegroups.com
I've had a really quick look at your mode, it looks good, and I like the regularity in keyword highlighting. I'm going to have a proper look sometime later on the weekend and will get back to you when I have done.

Kind Regards,

David.


2008/12/12 Daniel Spiewak <djsp...@gmail.com>

David Moss

unread,
Dec 15, 2008, 4:36:22 PM12/15/08
to clo...@googlegroups.com
I been thinking about this during the weekend, and I think I prefer the mode to be aware of nesting (unless you can cause it to blow the stack on a large file or something, which I think would be unlikely anyway), so I'm going to take the keywords from your mode and bolt on the set structures I had in my mode, maybe changing them all to the same colouring.

Will let you know when done (sometime later this week or so) so that you can have a look. I'm also thinking that regexps should have some highlighting... I may even push that into the Perl mode as it pisses me off greatly that regexps don't even know about variable substitution.

Kind Regards,

David.

2008/12/13 David Moss <dsm...@gmail.com>

Daniel Spiewak

unread,
Dec 16, 2008, 2:22:05 AM12/16/08
to Clojure
> I been thinking about this during the weekend, and I think I prefer the mode
> to be aware of nesting (unless you can cause it to blow the stack on a large

Well, this would be my question: why? :-) Auto-indent needs to be
aware of nesting, but that's already handled in a separate pass from
the highlighting. Besides that, there really isn't anything that
requires this sort of complexity. Also, as you say, it does tend
toward far less efficient highlighting in more deeply-nested S-
expressions.

> Will let you know when done (sometime later this week or so) so that you can
> have a look. I'm also thinking that regexps should have some highlighting...
> I may even push that into the Perl mode as it pisses me off greatly that
> regexps don't even know about variable substitution.

Proper regexp highlighting would be nice, but as I mentioned, I'm not
sure what the "correct" way to handle this may be. Are regular
expressions actually handled specially in the reader? If not, then we
should probably just reuse the string highlighting semantics.

Daniel

Daniel Spiewak

unread,
Dec 16, 2008, 2:42:36 AM12/16/08
to Clojure
Also, it's worth noting that my trick to highlight def-initions
probably isn't going to work if we have hierarchical parsing of S-
expressions. I'm not entirely sure how jEdit is going to handle
certain cases if we try to merge the two. It might be possible to
make it work, but I suspect that jEdit's greedy matching will get in
the way.

Daniel

Chouser

unread,
Dec 22, 2008, 10:22:31 AM12/22/08
to clo...@googlegroups.com
On Tue, Dec 16, 2008 at 2:22 AM, Daniel Spiewak <djsp...@gmail.com> wrote:
>
> Proper regexp highlighting would be nice, but as I mentioned, I'm not
> sure what the "correct" way to handle this may be. Are regular
> expressions actually handled specially in the reader? If not, then we
> should probably just reuse the string highlighting semantics.

#"pattern" is handled by a different reader function than "string".
Both are terminated by the first unescaped double-quote, so simple
highlighting of the whole expression in a single color would be the
same. However, the set of internal escape sequences recognized by
each are different. For example \w means 'whitespace' in a regex (and
is colored differently from the rest of the regex by vim in perl code)
but is currently illegal in a Clojure string.

--Chouser

Reply all
Reply to author
Forward
0 new messages