emacs ruby-mode statement modifier indent problem?

M

Mike Shire

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!
 
B

Brian Schröder

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
 
C

Carlo E. Prelz

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

Quoting Brian Schröder ([email protected]):
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
 
B

Brian Schröder

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

Quoting Brian Schröder ([email protected]):


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
 
M

Mike Shire

Mike said:
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))))))))
 
N

nobu.nokada

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

Carlo E. Prelz

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

Quoting (e-mail address removed) ([email protected]):
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
 

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
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top