Project

General

Profile

Actions

Bug #4546

closed

ruby-indent-beg-re の値が壊れている

Added by mrkn (Kenta Murata) almost 13 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
ruby -v:
trunk
Backport:
[ruby-dev:43375]

Description

vim-ruby の indent/ruby.vim を修正しようと思い ruby-mode.el を読んでいたところ
ruby-indent-beg-re の値が壊れているような気がしたので報告します。

r19205 で regexp-opt を使って正規表現を最適化するよう改善されていますが、
そのときに \| が抜けてしまっています。

r19204 の 場合:
"\(\s *\(class\|module\|def\)\)\|if\|unless\|case\|while\|until\|for\|begin"

r19205 の場合:
"\(\s *\(class\|def\|module\)\)\(?:begin\|case\|for\|if\|un\(?:less\|til\)\|while\)"

このように class, def, module を囲む括弧の直後にあった \| が落ちています。

それでも、なぜか適切にインデントできていて不思議だったので少しだけ調査してみました。
r19205 以降では、ruby-beginning-of-indent が classif や defbegin のような不適切な語をインデントの開始として
判断してしまいますが、このような語が存在しない場合はバッファの先頭まで戻っていました。
ですから、以下のパッチを当ててこの間違いを修正すると、長いファイルのインデント計算が
若干高速化されるかもしれません。

diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index c799d8c..9023b77 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -72,7 +72,7 @@
"Regexp to match")

(defconst ruby-indent-beg-re

  • (concat "\(\s *" (regexp-opt '("class" "module" "def") t) "\)"
  • (concat "\(\s *" (regexp-opt '("class" "module" "def") t) "\)\|"
    (regexp-opt '("if" "unless" "case" "while" "until" "for" "begin")))
    "Regexp to match where the indentation gets deeper.")

Updated by mrkn (Kenta Murata) almost 13 years ago

=begin
新しい Redmine に慣れてなくて、patch が崩れてしまいました。
以下に再掲します。

diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index c799d8c..9023b77 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -72,7 +72,7 @@
"Regexp to match")

(defconst ruby-indent-beg-re

  • (concat "\(\s *" (regexp-opt '("class" "module" "def") t) "\)"
  • (concat "\(\s *" (regexp-opt '("class" "module" "def") t) "\)\|"
    (regexp-opt '("if" "unless" "case" "while" "until" "for" "begin")))
    "Regexp to match where the indentation gets deeper.")

=end

Updated by naruse (Yui NARUSE) almost 13 years ago

  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)

Updated by nahi (Hiroshi Nakamura) almost 13 years ago

  • Target version changed from 2.0.0 to 1.9.3

Updated by nobu (Nobuyoshi Nakada) over 12 years ago

  • Assignee changed from nobu (Nobuyoshi Nakada) to mrkn (Kenta Murata)

いれといてください。

Actions #5

Updated by mrkn (Kenta Murata) over 12 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r32338.
Kenta, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • misc/ruby-mode.el (ruby-indent-beg-re): Fix broken regular
    expression. Fixes #4546
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0