ruby-changes:7684
From: matz <ko1@a...>
Date: Sun, 7 Sep 2008 07:35:02 +0900 (JST)
Subject: [ruby-changes:7684] Ruby:r19205 (trunk): * misc/ruby-mode.el, misc/ruby-electric.el: use regexp-opt where
matz 2008-09-07 07:34:46 +0900 (Sun, 07 Sep 2008) New Revision: 19205 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19205 Log: * misc/ruby-mode.el, misc/ruby-electric.el: use regexp-opt where possible for more efficient regexps. Modified files: trunk/ChangeLog trunk/misc/ruby-electric.el trunk/misc/ruby-mode.el Index: ChangeLog =================================================================== --- ChangeLog (revision 19204) +++ ChangeLog (revision 19205) @@ -11,6 +11,9 @@ * misc/ruby-mode.el: don't highlight keywords when they're the beginning of non-keyword symbols. + * misc/ruby-mode.el, misc/ruby-electric.el: use regexp-opt where + possible for more efficient regexps. + Sun Sep 7 06:31:51 2008 Yukihiro Matsumoto <matz@r...> * file.c (file_expand_path): applied a patch from Nobuhiro Tachino Index: misc/ruby-mode.el =================================================================== --- misc/ruby-mode.el (revision 19204) +++ misc/ruby-mode.el (revision 19205) @@ -13,37 +13,50 @@ (substring ruby-mode-revision (match-beginning 0) (match-end 0))) "Ruby mode version number.") +(defconst ruby-block-beg-keywords + '("class" "module" "def" "if" "unless" "case" "while" "until" "for" "begin" "do") + "Keywords at the beginning of blocks.") + (defconst ruby-block-beg-re - "class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin\\|do" - "Regexp to match the beginning of blocks in ruby-mode.") + (regexp-opt ruby-block-beg-keywords) + "Regexp to match the beginning of blocks.") (defconst ruby-non-block-do-re - "\\(while\\|until\\|for\\|rescue\\)\\>[^_]" + (concat (regexp-opt '("while" "until" "for" "rescue") t) "\\_>") "Regexp to match") (defconst ruby-indent-beg-re - "\\(\\s *\\(class\\|module\\|def\\)\\)\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin" + (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.") +(defconst ruby-modifier-beg-keywords + '("if" "unless" "while" "until") + "Modifiers that are the same as the beginning of blocks.") + (defconst ruby-modifier-beg-re - "if\\|unless\\|while\\|until" + (regexp-opt ruby-modifier-beg-keywords) "Regexp to match modifiers same as the beginning of blocks.") (defconst ruby-modifier-re - (concat ruby-modifier-beg-re "\\|rescue") + (regexp-opt (cons "rescue" ruby-modifier-beg-keywords)) "Regexp to match modifiers.") +(defconst ruby-block-mid-keywords + '("then" "else" "elsif" "when" "rescue" "ensure") + "Keywords where the indentation gets shallower in middle of block statements.") + (defconst ruby-block-mid-re - "then\\|else\\|elsif\\|when\\|rescue\\|ensure" + (regexp-opt ruby-block-mid-keywords) "Regexp to match where the indentation gets shallower in middle of block statements.") -(defconst ruby-block-op-re - "and\\|or\\|not" - "Regexp to match ") +(defconst ruby-block-ops + '("and" "or" "not") + "Block operators.") (defconst ruby-block-hanging-re - (concat ruby-modifier-beg-re "\\|" ruby-block-op-re) - ) + (regexp-opt (append ruby-modifier-beg-keywords ruby-block-op-keywords)) + "Regexp to match hanging block modifiers.") (defconst ruby-block-end-re "\\<end\\>") @@ -395,9 +408,11 @@ (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 "\\)\\>"))) + ((looking-at (regexp-opt + (append ruby-block-beg-keywords + ruby-block-op-keywords + ruby-block-mid-keywords) + 'words)) (goto-char (match-end 0)) (not (looking-at "\\s_"))) ((eq option 'expr-qstr) @@ -556,7 +571,7 @@ ((looking-at (concat "\\<\\(" ruby-block-beg-re "\\)\\>")) (and (save-match-data - (or (not (looking-at "do\\>[^_]")) + (or (not (looking-at "do\\_>")) (save-excursion (back-to-indentation) (not (looking-at ruby-non-block-do-re))))) Index: misc/ruby-electric.el =================================================================== --- misc/ruby-electric.el (revision 19204) +++ misc/ruby-electric.el (revision 19205) @@ -67,8 +67,8 @@ (?\` . ?\`) (?\" . ?\"))) -(defcustom ruby-electric-simple-keywords-re - "\\(def\\|if\\|class\\|module\\|unless\\|case\\|while\\|do\\|until\\|for\\|begin\\)" +(defcustom ruby-electric-simple-keywords-re + (regexp-opt '("def" "if" "class" "module" "unless" "case" "while" "do" "until" "for" "begin") t) "*Regular expresion matching keywords for which closing 'end' is to be inserted." :type 'regexp :group 'ruby-electric) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/