emacs ruby-mode statement modifier indent problem?

Discussion in 'Ruby' started by Mike Shire, Apr 18, 2005.

  1. Mike Shire

    Mike Shire Guest

    Greetings,

    New to the list, and relatively new to Ruby and loving it.

    After updating ruby-mode (ruby-elisp1.8.2 using Debian apt-get and
    emacs21) recently I'm having a problem with emacs indenting incorrectly
    with statement modifiers. E.g.

    puts "foo" if foo
    puts "next line is indented waaay out here"


    An hours search revealed this fix from 2002:
    http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/32352

    I changed out the the elisp ruby-expr-beg function and that seemed to
    solve that particular problem. However, the function I replaced I am
    sure had been updated since this referenced post and I'm sure replacing
    it has broken something else (and my elisp knowledge is practically nil).

    Has anyone encountered this or has this been fixed elsewhere that I can
    get it?

    Many thanks.

    mike!
     
    Mike Shire, Apr 18, 2005
    #1
    1. Advertising

  2. On 4/18/05, Mike Shire <> wrote:
    > Greetings,
    >
    > New to the list, and relatively new to Ruby and loving it.
    >
    > After updating ruby-mode (ruby-elisp1.8.2 using Debian apt-get and
    > emacs21) recently I'm having a problem with emacs indenting incorrectly
    > with statement modifiers. E.g.
    >
    > puts "foo" if foo
    > puts "next line is indented waaay out here"
    >
    > An hours search revealed this fix from 2002:
    > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/32352
    >
    > I changed out the the elisp ruby-expr-beg function and that seemed to
    > solve that particular problem. However, the function I replaced I am
    > sure had been updated since this referenced post and I'm sure replacing
    > it has broken something else (and my elisp knowledge is practically nil).
    >
    > Has anyone encountered this or has this been fixed elsewhere that I can
    > get it?
    >
    > Many thanks.
    >
    > mike!
    >
    >


    Hello Mike. The same has happened to me, and it even seems that this
    is not the only case where indentation is broken. I hope there will be
    a fix soon, because I have no time to investigate even which part of
    the system is broken. Good news that I'm not alone ;-/

    best regards,

    Brian

    --
    Brian Schröder
    http://ruby.brian-schroeder.de/
     
    Brian Schröder, Apr 18, 2005
    #2
    1. Advertising

  3. Subject: Re: emacs ruby-mode statement modifier indent problem?
    Date: mar, apr 19, 2005 at 05:43:41 +0900

    Quoting Brian Schröder ():

    > Hello Mike. The same has happened to me, and it even seems that this
    > is not the only case where indentation is broken. I hope there will be
    > a fix soon, because I have no time to investigate even which part of
    > the system is broken. Good news that I'm not alone ;-/


    I add that indentation is broken with slashes and percentages. With
    slashes, indentation is perfect if slashes are doubled (//) (but then,
    obviously, the program does not work). In some cases, indentation is
    wrong, and in others no indentation takes place at all after a slash.

    I have taken up ruby only in the past few weeks, and I reached the
    conclusion that a) no ruby coder used emacs, or b) there was an arcane
    intelligent way to perform divisions that did not make use of the
    slash (actually, I used >>1 to divide integers by two a handful of
    times)

    I thought about trying to find out why this is happening, but regexps
    plus emacs lisp is a mind-altering mix for me!

    Carlo

    --
    * Se la Strada e la sua Virtu' non fossero state messe da parte,
    * K * Carlo E. Prelz - che bisogno ci sarebbe
    * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)
     
    Carlo E. Prelz, Apr 18, 2005
    #3
  4. On 4/18/05, Carlo E. Prelz <> wrote:
    > Subject: Re: emacs ruby-mode statement modifier indent problem?
    > Date: mar, apr 19, 2005 at 05:43:41 +0900
    >
    > Quoting Brian Schröder ():
    >
    > > Hello Mike. The same has happened to me, and it even seems that this
    > > is not the only case where indentation is broken. I hope there will be
    > > a fix soon, because I have no time to investigate even which part of
    > > the system is broken. Good news that I'm not alone ;-/

    >
    > I add that indentation is broken with slashes and percentages. With
    > slashes, indentation is perfect if slashes are doubled (//) (but then,
    > obviously, the program does not work). In some cases, indentation is
    > wrong, and in others no indentation takes place at all after a slash.
    >
    > I have taken up ruby only in the past few weeks, and I reached the
    > conclusion that a) no ruby coder used emacs, or b) there was an arcane
    > intelligent way to perform divisions that did not make use of the
    > slash (actually, I used >>1 to divide integers by two a handful of
    > times)
    >
    > I thought about trying to find out why this is happening, but regexps
    > plus emacs lisp is a mind-altering mix for me!
    >
    > Carlo


    In fact I think there are enough emacs users, as far as I know even
    matz programs in emacs. So normally ruby support was very good. Only
    that for some time now it is broken. (And I even didn't help with a
    bugreport because I was on holidays in italy).

    best regards,

    Brian

    --
    Brian Schröder
    http://ruby.brian-schroeder.de/
     
    Brian Schröder, Apr 19, 2005
    #4
  5. Mike Shire

    Mike Shire Guest

    Mike Shire wrote:

    > Greetings,
    >
    > New to the list, and relatively new to Ruby and loving it.
    >
    > After updating ruby-mode (ruby-elisp1.8.2 using Debian apt-get and
    > emacs21) recently I'm having a problem with emacs indenting
    > incorrectly with statement modifiers. E.g.
    >
    > puts "foo" if foo
    > puts "next line is indented waaay out here"
    >
    >
    > An hours search revealed this fix from 2002:
    > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/32352
    >
    > I changed out the the elisp ruby-expr-beg function and that seemed to
    > solve that particular problem. However, the function I replaced I am
    > sure had been updated since this referenced post and I'm sure
    > replacing it has broken something else (and my elisp knowledge is
    > practically nil).
    >
    > Has anyone encountered this or has this been fixed elsewhere that I
    > can get it?
    >
    > Many thanks.
    >
    > mike!
    >


    Here is the code substitution that I made to ruby-mode.el that
    eliminates the statement modifier indentation problem (cut and paste
    from aforementioned post)...

    I apologise if this is not the proper place for this but in the hopes
    that someone with good elisp knowledge would happen to spot something
    obvious I thought it convenient to simply post them.

    ;; --- original function with broken statement modifier indent ---
    ;; (defun ruby-expr-beg (&optional option)
    ;; (save-excursion
    ;; (store-match-data nil)
    ;; (let ((start (point))
    ;; (space (skip-chars-backward " \t")))
    ;; (cond
    ;; ((bolp) t)
    ;; ((progn
    ;; (forward-char -1)
    ;; (and (looking-at "\\?")
    ;; (or (eq (char-syntax (char-before (point))) ?w)
    ;; (ruby-special-char-p))))
    ;; nil)
    ;; ((or (goto-char start)
    ;; (looking-at ruby-operator-re)
    ;; (looking-at "[\\[({,;]")
    ;; (and (or (not (eq option 'heredoc))
    ;; (< space 0))
    ;; (looking-at "[!?]")
    ;; (or (not (eq option 'modifier))
    ;; (bolp)
    ;; (save-excursion (forward-char -1) (looking-at "\\Sw"))))
    ;; (and (looking-at ruby-symbol-re)
    ;; (skip-chars-backward ruby-symbol-chars)
    ;; (cond
    ;; ((or (looking-at (concat "\\<\\(" ruby-block-beg-re
    ;; "|" ruby-block-op-re
    ;; "|" ruby-block-mid-re "\\)\\>")))
    ;; (goto-char (match-end 0))
    ;; (not (looking-at "\\s_")))
    ;; ((eq option 'expr-qstr)
    ;; (looking-at "[a-zA-Z][a-zA-z0-9_]* +%[^ \t]"))
    ;; ((eq option 'expr-re)
    ;; (looking-at "[a-zA-Z][a-zA-z0-9_]* +/[^ \t]"))
    ;; (t nil)))))))))


    ;; --- reverted function that works ---
    (defun ruby-expr-beg (&optional option)
    (save-excursion
    (store-match-data nil)
    (skip-chars-backward " \t")
    (cond
    ((bolp) t)
    ((looking-at "\\?")
    (or (bolp) (forward-char -1))
    (not (looking-at "\\sw")))
    (t
    (forward-char -1)
    (or (looking-at ruby-operator-re)
    (looking-at "[\\[({,;]")
    (and (not (eq option 'modifier))
    (looking-at "[!?]"))
    (and (looking-at ruby-symbol-re)
    (skip-chars-backward ruby-symbol-chars)
    (cond
    ((or (looking-at ruby-block-beg-re)
    (looking-at ruby-block-op-re)
    (looking-at ruby-block-mid-re))
    (goto-char (match-end 0))
    (looking-at "\\>"))
    ((eq option 'expr-qstr)
    (looking-at "[a-zA-Z][a-zA-z0-9_]* +%[^ \t]"))
    ((eq option 'expr-re)
    (looking-at "[a-zA-Z][a-zA-z0-9_]* +/[^ \t]"))
    (t nil))))))))
     
    Mike Shire, Apr 19, 2005
    #5
  6. Mike Shire

    Guest

    Hi,

    At Wed, 20 Apr 2005 00:20:41 +0900,
    Mike Shire wrote in [ruby-talk:138883]:
    > I apologise if this is not the proper place for this but in the hopes
    > that someone with good elisp knowledge would happen to spot something
    > obvious I thought it convenient to simply post them.


    It is OK here but unified diff will be welcomed.

    > ;; --- original function with broken statement modifier indent ---
    > ;; (defun ruby-expr-beg (&optional option)
    > ;; (save-excursion
    > ;; (store-match-data nil)
    > ;; (let ((start (point))
    > ;; (space (skip-chars-backward " \t")))


    Your original ruby-mode.el seems old. Try latest snapshot.

    --
    Nobu Nakada
     
    , Apr 19, 2005
    #6
  7. Subject: Re: emacs ruby-mode statement modifier indent problem?
    Date: mer, apr 20, 2005 at 07:11:46 +0900

    Quoting ():

    > Your original ruby-mode.el seems old. Try latest snapshot.


    I got revision 1.89 from www.ruby-lang.org (apparently modified only
    47 hours ago). with it, editing this file:

    class z
    @a=1.0
    @b=2.0

    def y
    c=@a/@b
    end
    end

    after the division, on line 6, indentation (with TAB) does not work
    anymore. Add spaces before any of the two 'end' lines, and try to
    type TAB on them: nothing happens. Same with modulo:

    class z
    @a=1
    @b=2

    def y
    c=@a%@b
    end
    end

    In the first case, if I double the slash:

    class z
    @a=1.0
    @b=2.0

    def y
    c=@a//@b
    end
    end

    emacs indents properly (but the code does not work). This is not true
    with %'s: a double percentage sign does not change the malfunction.

    I tried with the 'reverted' ruby-expr-beg function that was posted
    yesterday by Mike Shire, and both of the above examples indent OK!

    I have patched my ruby-mode.el with it. I will let you know if I
    notice something else is broken.

    Carlo

    --
    * Se la Strada e la sua Virtu' non fossero state messe da parte,
    * K * Carlo E. Prelz - che bisogno ci sarebbe
    * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)
     
    Carlo E. Prelz, Apr 20, 2005
    #7
    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:
    1,018
    Skip Montanaro
    Nov 11, 2003
  2. John Fouhy

    Emacs python mode indent levels

    John Fouhy, Jul 15, 2004, in forum: Python
    Replies:
    2
    Views:
    856
    John Lenton
    Jul 15, 2004
  3. dt
    Replies:
    4
    Views:
    517
    CBFalconer
    Dec 31, 2006
  4. Steven W. Orr
    Replies:
    4
    Views:
    319
    Carl Banks
    Apr 1, 2008
  5. Joe Peterson
    Replies:
    0
    Views:
    171
    Joe Peterson
    Dec 28, 2006
Loading...

Share This Page