clojure-mode-like syntax highlighting for the SLIME REPL

43 views
Skip to first unread message

Michał Marczyk

unread,
Mar 19, 2010, 2:08:06 AM3/19/10
to clo...@googlegroups.com
Hi Group,

there was a Stack Overflow question recently re: syntax highlighting
Clojure REPLs. This got me thinking that since I was going to tweak
SLIME REPL font-lock for quite some time now (I find the default a bit
too aggressive), I might as well do it now and have it use
clojure-mode's font-lock settings too.

Here's what I came up with:
http://gist.github.com/337280

I've got some questions in connection with this. Firstly, I'd love to
know whether this could be done in a simpler way. If not, then I
wonder if clojure-mode could move the font-lock setup from the
clojure-mode function itself to something like my
clojure-font-lock-setup function and then just call that from
clojure-mode? That way a usable syntax highlighting SLIME REPL would
become a one hook affair.

Then there's one thing I didn't try to tackle for now (because it
would actually require me to write font-lock code, which is something
that scares me to death), namely prompt highlighting ("namespace>"
appears in plain text for now). Is there a simple way to add this on
top of clojure-mode font-lock settings?

All the best,
Michał

Rick Moynihan

unread,
Mar 19, 2010, 7:58:21 AM3/19/10
to clo...@googlegroups.com
On 19 March 2010 06:08, Michał Marczyk <michal....@gmail.com> wrote:
> Hi Group,
>
> there was a Stack Overflow question recently re: syntax highlighting
> Clojure REPLs. This got me thinking that since I was going to tweak
> SLIME REPL font-lock for quite some time now (I find the default a bit
> too aggressive), I might as well do it now and have it use
> clojure-mode's font-lock settings too.
>
> Here's what I came up with:
> http://gist.github.com/337280

Very cute! I'd love to see this integrated into clojure-mode!

R.

Phil Hagelberg

unread,
Mar 19, 2010, 1:12:57 PM3/19/10
to clo...@googlegroups.com
On Thu, Mar 18, 2010 at 11:08 PM, Michał Marczyk
<michal....@gmail.com> wrote:
> there was a Stack Overflow question recently re: syntax highlighting
> Clojure REPLs. This got me thinking that since I was going to tweak
> SLIME REPL font-lock for quite some time now (I find the default a bit
> too aggressive), I might as well do it now and have it use
> clojure-mode's font-lock settings too.
>
> Here's what I came up with:
> http://gist.github.com/337280
>
> I've got some questions in connection with this. Firstly, I'd love to
> know whether this could be done in a simpler way. If not, then I
> wonder if clojure-mode could move the font-lock setup from the
> clojure-mode function itself to something like my
> clojure-font-lock-setup function and  then just call that from
> clojure-mode? That way a usable syntax highlighting SLIME REPL would
> become a one hook affair.

Awesome. Yeah, that sounds great. Could you submit an issue to
clojure-mode to do this?

http://github.com/technomancy/clojure-mode/issues

A patch would be even better, of course.

> Then there's one thing I didn't try to tackle for now (because it
> would actually require me to write font-lock code, which is something
> that scares me to death), namely prompt highlighting ("namespace>"
> appears in plain text for now). Is there a simple way to add this on
> top of clojure-mode font-lock settings?

This would belong in swank-clojure actually. clojure-mode doesn't with
slime at all by itself; it's just for highlighting, indentation, etc.
(though it can spawn simplistic repl subprocesses.)

-Phil

Michał Marczyk

unread,
Mar 19, 2010, 7:43:06 PM3/19/10
to clo...@googlegroups.com
On 19 March 2010 18:12, Phil Hagelberg <ph...@hagelb.org> wrote:
> On Thu, Mar 18, 2010 at 11:08 PM, Michał Marczyk
> Awesome. Yeah, that sounds great. Could you submit an issue to
> clojure-mode to do this?
>
> http://github.com/technomancy/clojure-mode/issues
>
> A patch would be even better, of course.

Sure thing, I'll send you a patch / pull request sometime this weekend. :-)

>> Then there's one thing I didn't try to tackle for now (because it
>> would actually require me to write font-lock code, which is something
>> that scares me to death), namely prompt highlighting ("namespace>"
>> appears in plain text for now). Is there a simple way to add this on
>> top of clojure-mode font-lock settings?
>
> This would belong in swank-clojure actually. clojure-mode doesn't with
> slime at all by itself; it's just for highlighting, indentation, etc.
> (though it can spawn simplistic repl subprocesses.)

Yes, I realise that's not something to put in clojure-mode. What I
meant is that I haven't yet investigated how slime-repl &
swank-clojure (?) go about putting those custom text properties on
things captured on the standard output of the Lisp process (so things
like (doc foo) or the output of (println :foo) have their own subdued
colour). Basically I'd like to try to use whatever mechanism is in
place for distinguishing printouts from return values and combine that
with clojure-mode highlighting for the perfect Clojure-oriented SLIME
REPL experience. ;-)

Hopefully I'll be able to do that in the next few days; I'll post it
for your consideration as soon as I have it ready.

(Note that as far as font-lock is concerned, I hardly know what I'm
doing. Perhaps someone who knows what they're doing will post the
elisp incantation to accomplish the above before I get started on it.
:-))

All the best,
Michał

Michał Marczyk

unread,
Mar 19, 2010, 7:43:57 PM3/19/10
to clo...@googlegroups.com
On 19 March 2010 12:58, Rick Moynihan <rick.m...@gmail.com> wrote:
> Very cute!  I'd love to see this integrated into clojure-mode!

Glad you like it! As mentioned above, I'll try to polish it a bit further.

Sincerely,
Michał

Michał Marczyk

unread,
Mar 22, 2010, 6:17:38 PM3/22/10
to clo...@googlegroups.com
Phil,

I've sent you a pull request with the refactoring of clojure-mode. If
it looks ok to you, I was wondering if you might perhaps like a second
one to include instructions to setup Clojure highlighting in
swank-clojure's readme?

Sincerely,
Michał

Michał Marczyk

unread,
Mar 27, 2010, 10:18:46 PM3/27/10
to clo...@googlegroups.com
I think I've managed to make SLIME REPL keep highlighting prompts and
printouts on *out* properly while using clojure-mode syntax
highlighting for everything else. This is accomplished by means of
advising two slime-repl functions.

Both pieces of advice (hm... advices?) are now included in the gist:

http://gist.github.com/337280

I'm not altogether sure whether I'm breaking anything by thus advising
those functions... So, I'd love to hear whether it works for anyone
but me. :-)

(I also happen to use the latest SLIME; however, the relevant portions
of slime-repl.el don't seem to change at all, so ELPA users should
experience no problems.)

Sincerely,
Michał

Reply all
Reply to author
Forward
0 new messages