smartparens icon indicating copy to clipboard operation
smartparens copied to clipboard

[ruby-mode] Unmatched expression in a method definition when passing `do` to a for loop within that method.

Open zeroDivisible opened this issue 9 years ago • 3 comments

Hi guys. I had stumbled across a method definition similar to the one below:

def make_noise
  for count in 1..10 do
    puts "meow"
  end
end

After putting the cursor on d in def, smartparens prints the following error:

Search failed. This means there is unmatched expression somewhere or we are at the beginning/end of file.

If the for loop didn't had do at the end, things are highlighted correctly.

zeroDivisible avatar Oct 21 '15 12:10 zeroDivisible

I think it gets confused because do also starts the ruby block thing? I'm not really an expert in ruby.

Fuco1 avatar Oct 21 '15 19:10 Fuco1

I'm not an expert either, however I think both versions (with & without do) are valid ruby code and appear to be executed correctly. It might be the case that in Ruby you can pass a block to any method, so I think that a for loop wouldn't be an exception.

The proper way of writing that code would be something like:

def make_noise
  1..10.each do |x|
    puts "meow"
  end
end

but sadly that's a part of the code which I can't change :( I've been wondering if there's something which could be improved how smartparens would handle this case and that's why I created this issue.

zeroDivisible avatar Oct 21 '15 20:10 zeroDivisible

Something surely can be done and I thank you for taking the time to report this. However, since I'm not a ruby user this is not a very high priority task for me (at the moment)

One solution would be to add an exception for the do if it is after for, there are similar skip-conditions in smartparens-ruby.el (maybe there is one already and you aren't loading that file?). You can look there and see if there isn't some fix or similar code already.

Fuco1 avatar Oct 21 '15 20:10 Fuco1