Ruby indenting in jEdit

J

Jay Levitt

For some reason, jEdit 4.3pre2 (JRE5, Windows XP SP2) wants to indent
any "end" statements with the rest of the block, which of course throws
off every succeeding line. I've downloaded Karl von Laudermann's
ruby.xml 0.6, but this hasn't made a difference. In fact, now that I
notice, if/then/else has a problem too. Anyone have any ideas how to
troubleshoot this?

Example:

if blah
puts "hi"
else
puts "bye"
end
 
R

Rob .

Jay, by just typing your example line by line in a blank .rb file the
indenting is correct for me in jEdit 4.2final with v0.6.6 of the Ruby
Editor Plugin:
http://www.jedit.org/ruby/download/

I'll try this out under 4.3pre2. I know some changes were made for
indenting in 4.3 that might be stuffing things up for Ruby code.

In the meantime, some questions:
1) What version of the Ruby plugin are you running?
2) Is you example from a otherwise empty file, if not can you sent me
the complete file.
3) What order did you type the example in?

Cheers,
Rob
 
J

Jay Levitt

rob.02004 said:
I'll try this out under 4.3pre2. I know some changes were made for
indenting in 4.3 that might be stuffing things up for Ruby code.

In the meantime, some questions:
1) What version of the Ruby plugin are you running?
0.6.5 or 0.6.6; both do the same.
2) Is you example from a otherwise empty file, if not can you sent me
the complete file.
Utterly empty buffer, which I switch to Ruby mode via Buffer Options.
3) What order did you type the example in?
Exactly as shown, start to finish.

I just resurrected 4.2 from the recycle bin (with RubyPlugin 0.5), and
discovered something interesting: As I type the example in, the "else"
that I type and the automatic "end" show up in the correct columns.
(The automatic "end" doesn't show up for me with 0.6.6 and 4.3pre2.)

BUT - if I then use TAB (mapped to "Indent Selected Lines") to reindent
the code, I end up with the same forever-indenting result as 4.3.3. So
maybe this bug has existed forever, but nobody's noticed because they're
not reindenting?

I should also point out that the increasing left margin I see is
*exactly* what happens whenever I try to write with a pencil on a piece
of paper, much to the dismay of my fourth-grade teacher. However, I
don't know for sure that this bug is related.
 
R

Rob .

Jay, thanks for your detailed description of the steps you followed. I
can see the problem now:
Utterly empty buffer, which I switch to Ruby mode via Buffer Options.

If you first save the file to a "something.rb" file name, then
indenting should work properly for you. Currently the plugin is using
the file extension to determine if the file is "ruby" or not. I'll fix
it to also look at the buffer options setting in a future release.

Thanks for the feedback!

Cheers,
Rob
 
J

Jay Levitt

rob.02004 said:
If you first save the file to a "something.rb" file name, then
indenting should work properly for you. Currently the plugin is using
the file extension to determine if the file is "ruby" or not. I'll fix
it to also look at the buffer options setting in a future release.

Hmm.. nope, there's more to it than that. This turns on the plugin's
pre- and re-indenting of "else" and "end", but if I then select
Edit | Indent | Indent Lines, it still messes up the spacing.

I suspect the problem is in the ruby.xml file or the parser itself, but
I don't know enough about any of this to troubleshoot... can you
duplicate that on your end?
 
R

Rob .

but if I then select
Edit | Indent | Indent Lines, it still messes up the spacing.

The Edit->Indent->Indent Lines action is implemented as part of the
core jEdit editor, and it was designed for languages that have blocks
enclosed in a start and end token, e.g. '{' and '}'. There is no logic
in the core jEdit codebase to support indenting languages like Ruby
and Python, so Edit->Indent->Indent Lines won't work for Ruby.

For Ruby indenting I recommend you use the 'enter' key bound as a
shortcut to the Ruby plugin "Auto-indent and insert end" action. This
will for the most part indent your code appropriately as you type it.
Indenting discrepances will require you to make manual alterations,
the Edit->Indent->Indent Lines action won't work.

Cheers,
Rob
 
J

Jay Levitt

rob.02004 said:
The Edit->Indent->Indent Lines action is implemented as part of the
core jEdit editor, and it was designed for languages that have blocks
enclosed in a start and end token, e.g. '{' and '}'. There is no logic
in the core jEdit codebase to support indenting languages like Ruby
and Python, so Edit->Indent->Indent Lines won't work for Ruby.

For Ruby indenting I recommend you use the 'enter' key bound as a
shortcut to the Ruby plugin "Auto-indent and insert end" action. This
will for the most part indent your code appropriately as you type it.
Indenting discrepances will require you to make manual alterations,
the Edit->Indent->Indent Lines action won't work.

Ah hah! That explains it. I'm coming from the emacs world, where the
mode itself controls the indentation. Thanks... seems like I should be
fine just letting the Ruby plugin do the auto-indentation.

One suggestion: Since I have TAB bound to "Indent Lines", which is
useful in the more C-like languages, it makes manual tab tweaking a bit
of a pain. (I do have ESC-TAB bound to normal tabbing.) One workaround
would be if the Ruby plugin offered a "Smart Indent Lines" function,
which would either go to the standard routine for most buffers, or your
own plugin for Ruby buffers. You could even get super-smart, and if I
hit tab twice in a row on a line, start adding normal tabs so I could
override the default...
 
K

Karl von Laudermann

Jay said:
One suggestion: Since I have TAB bound to "Indent Lines", which is
useful in the more C-like languages, it makes manual tab tweaking a bit
of a pain. (I do have ESC-TAB bound to normal tabbing.) One workaround
would be if the Ruby plugin offered a "Smart Indent Lines" function,
which would either go to the standard routine for most buffers, or your
own plugin for Ruby buffers.

My solution is to have C+[ and C+] mapped to Shift Indent Left/Right.
This makes it easy to increase/decrease the current line indentation.
 
B

Belorion

My solution is to have C+[ and C+] mapped to Shift Indent Left/Right.
This makes it easy to increase/decrease the current line indentation.

In jEdit one can increase/decrease indent using ALT+(left arrow) or
ALT+(right arrow). I think this is set by default. Works on multiple
lines as well (so if you have more than 1 line highlighted, the indent
will be applied to all of them).

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,474
Latest member
AntoniaDea

Latest Threads

Top