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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0