ruby-mode indent frustration

Ask a Question related to Ruby, Design and Development.

  1. #1

    Default ruby-mode indent frustration

    -----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/rZh9tvhXVvuQ3oQRAvRhAJ9wDdgb8EiJGjB3MUkGF9k6Gr6Ltg CaAhlH
    40nnYD3o/zZuNSQZCT1IeOA=
    =ttYY
    -----END PGP SIGNATURE-----


    Neil Spring Guest

  2. Similar Questions and Discussions

    1. Left indent affecting right indent in TOC
      RobMW, In the TOC style, change the tab character to a normal tab, and make sure you set the right-aligning tab in a style definition. Updating...
    2. ruby-mode breaks in ruby-calculate-indent after "#{}"
      I was trying to write the following code with ruby-mode on: MyClass.foo("Quoted text #{bar}", more, arguments, here) When I went to hit TAB on...
    3. Ruby mode indentation bug
      In this version of XEmacs: XEmacs 21.4 (patch 12) "Portable Code" (i386-redhat-linux, Mule) of Thu Feb 20 2003 on porky.devel.redhat.com ...
    4. Official source for ruby-mode.el?
      Hi there, Along with the development I'm doing comes the need to do some coding in Windows. I already have Emacs set up there, but now I need to...
    5. No colors with ruby-mode
      Saluton! * Björn Lindström; 2003-07-21, 12:06 UTC: Does this problem only occur when you edit a Ruby program and what happens if you enter...
  3. #2

    Default Re: ruby-mode indent frustration

    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 Guest

  4. #3

    Default Re: ruby-mode indent frustration

    * Jonas Lindström <jonas.li@chello.se> [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: [url]www.pcppopper.org[/url] :: fun atm: gf,lps,ruby,lisp,war3 :::
    main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}

    Nikolai Weibull Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139