[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

emacs ruby-mode statement modifier indent problem?

Mike Shire

4/18/2005 4:57:00 PM

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-...

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!



6 Answers

Brian Schröder

4/18/2005 8:44:00 PM

0

On 4/18/05, Mike Shire <mshire@voicesignal.com> 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-...
>
> 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-sch...



Carlo E. Prelz

4/18/2005 9:06:00 PM

0

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

Quoting Brian Schröder (ruby.brian@gmail.com):

> 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 - fluido@fluido.as che bisogno ci sarebbe
* di parlare tanto di amore e di rettitudine? (Chuang-Tzu)


Brian Schröder

4/19/2005 8:20:00 AM

0

On 4/18/05, Carlo E. Prelz <fluido@fluido.as> wrote:
> Subject: Re: emacs ruby-mode statement modifier indent problem?
> Date: mar, apr 19, 2005 at 05:43:41 +0900
>
> Quoting Brian Schröder (ruby.brian@gmail.com):
>
> > 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-sch...



Mike Shire

4/19/2005 3:21:00 PM

0

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-...
>
> 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))))))))



nobu.nokada

4/19/2005 10:12:00 PM

0

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


Carlo E. Prelz

4/20/2005 6:34:00 AM

0

Subject: Re: emacs ruby-mode statement modifier indent problem?
Date: mer, apr 20, 2005 at 07:11:46 +0900

Quoting nobu.nokada@softhome.net (nobu.nokada@softhome.net):

> 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 - fluido@fluido.as che bisogno ci sarebbe
* di parlare tanto di amore e di rettitudine? (Chuang-Tzu)