ruby-mode indent frustration

Discussion in 'Ruby' started by Neil Spring, Nov 9, 2003.

  1. Neil Spring

    Neil Spring Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Hello,

    I am used to c-mode indents and I find ruby-mode.el's indenting
    frustrating. Has anyone configured, modified, or rewritten
    ruby-mode.el to indent statements in a way more like c-mode does? I
    found Jim Weirich's code to properly reformat comments without
    reformatting code as c-mode does using M-q on rubygarden.

    The code below includes some examples of lines I would like indented
    differently, though the expressions are short. Because ruby's parser
    considers any statement that could be finished on a line finished,
    there are only a few ways to break up complex statements. Operators
    like "||", "+", and "%" all cause ruby-mode to indent the next line
    directly beneath where it would be anyway -- making it useless to try
    to split these expressions across lines. Placing a {} block as a
    parameter to a function somehow causes the indenting to
    counter-intuitively start over at the left. And the "?" conditional
    assignment operator gets no indenting for the next line at all.

    # the following statement should line up false beneath true,
    # as c-mode does.
    if ( true ||
    false ) then

    # the following statement should line up "baz" either
    # under "foo" or ruby-indent from the left edge.
    puts "foo bar %s" %
    "baz"
    # same as above.
    puts "Foo" +
    "Bar"

    # the second line should be indented somehow.
    puts use_celsius ?
    100 : 212;

    # the second line should be indented somehow,
    # preferably at least as far in as the "("
    puts( [ "a", "b", "c" ].map { |c|
    c + c }.join()
    )

    # are fine:
    puts "Foo",
    "Bar"
    puts "foo bar %s" % [
    "baz"
    ]
    end

    I don't know how to configure or improve ruby-mode.el to handle these
    statements, and I realize c-mode has it easy since all it has to do is
    wait for semicolons, but I think improving the formatting will make
    code more readable.

    thoughts?
    - -neil
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.3 (Darwin)

    iD8DBQE/rZh9tvhXVvuQ3oQRAvRhAJ9wDdgb8EiJGjB3MUkGF9k6Gr6LtgCaAhlH
    40nnYD3o/zZuNSQZCT1IeOA=
    =ttYY
    -----END PGP SIGNATURE-----
    Neil Spring, Nov 9, 2003
    #1
    1. Advertising

  2. Neil Spring wrote:
    > Hello,
    >
    > I am used to c-mode indents and I find ruby-mode.el's indenting
    > frustrating.


    I agree with you about ruby-mode's indenting being frustrating. I think
    a good thing would be to make the indentation more configurable.
    C-mode's way of configuring indentation is arguably too complex, but
    adding a few more user options would be a step in the right direction.

    > I don't know how to configure or improve ruby-mode.el to handle these
    > statements, and I realize c-mode has it easy since all it has to do is
    > wait for semicolons, but I think improving the formatting will make code
    > more readable.


    If you think that c-mode has it easy, you should have a look at the
    1100-line function c-guess-basic-syntax :) While you are at it, read
    the amusing comment in font-lock.el.

    Jonas Lindström
    Jonas Lindström, Nov 9, 2003
    #2
    1. Advertising

  3. * Jonas Lindström <> [Nov, 10 2003 16:31]:
    > If you think that c-mode has it easy, you should have a look at the
    > 1100-line function c-guess-basic-syntax :) While you are at it, read
    > the amusing comment in font-lock.el.

    perhaps switch to Vim and use its great Ruby indenting facilities?
    nikolai

    --
    ::: name: Nikolai Weibull :: aliases: pcp / lone-star / aka :::
    ::: born: Chicago, IL USA :: loc atm: Gothenburg, Sweden :::
    ::: page: www.pcppopper.org :: fun atm: gf,lps,ruby,lisp,war3 :::
    main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
    Nikolai Weibull, Nov 10, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. G.A.
    Replies:
    2
    Views:
    971
    Skip Montanaro
    Nov 11, 2003
  2. John Fouhy

    Emacs python mode indent levels

    John Fouhy, Jul 15, 2004, in forum: Python
    Replies:
    2
    Views:
    837
    John Lenton
    Jul 15, 2004
  3. dt
    Replies:
    4
    Views:
    468
    CBFalconer
    Dec 31, 2006
  4. Steven W. Orr
    Replies:
    4
    Views:
    301
    Carl Banks
    Apr 1, 2008
  5. Mike Shire
    Replies:
    6
    Views:
    243
    Carlo E. Prelz
    Apr 20, 2005
Loading...

Share This Page