* bug#10786: 24.0.93; ruby-mode improperly handles symbols with keyword names in JS-style hashes
@ 2012-02-11 0:27 Dmitry Gutov
2012-02-11 1:50 ` Dmitry Gutov
2012-03-21 18:33 ` Stefan Monnier
0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Gutov @ 2012-02-11 0:27 UTC (permalink / raw
To: 10786
[-- Attachment #1: Type: text/plain, Size: 719 bytes --]
Ruby 1.9 introduced the new syntax for hashes:
{key1: value1, key2: value2}
which is synonymous to {:key1 => value1, :key2 => value2}
The latest ruby-mode highlights the keywords in the new-style hashes
properly, but fails to account for the case when the symbol's name is an
otherwise reserved keyword. Examples:
link_to("root", root_path, class: "pink")
before_filter :do_stuff, if: :not_busy?
announce("The end is near!", end: "2012-12-31")
In all examples, the symbol (class, if, end) is being highlighted as a
reserved keyword, and the indentation becomes broken on all lines below it.
There's a similar bug on the Ruby bug tracker:
http://bugs.ruby-lang.org/issues/5140
See attachment for the patch.
[-- Attachment #2: ruby-keyword-symbols-patch.diff --]
[-- Type: text/plain, Size: 2236 bytes --]
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index a0a6509..8818911 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -96,7 +96,7 @@
(regexp-opt (append ruby-modifier-beg-keywords ruby-block-op-keywords))
"Regexp to match hanging block modifiers.")
-(defconst ruby-block-end-re "\\<end\\>")
+(defconst ruby-block-end-re "\\_<end\\_>")
(eval-and-compile
(defconst ruby-here-doc-beg-re
@@ -115,9 +115,9 @@ This should only be called after matching against `ruby-here-doc-beg-re'."
(match-string 6)))))
(defconst ruby-delimiter
- (concat "[?$/%(){}#\"'`.:]\\|<<\\|\\[\\|\\]\\|\\<\\("
+ (concat "[?$/%(){}#\"'`.:]\\|<<\\|\\[\\|\\]\\|\\_<\\("
ruby-block-beg-re
- "\\)\\>\\|" ruby-block-end-re
+ "\\)\\_>\\|" ruby-block-end-re
"\\|^=begin\\|" ruby-here-doc-beg-re))
(defconst ruby-negative
@@ -166,6 +166,7 @@ This should only be called after matching against `ruby-here-doc-beg-re'."
(modify-syntax-entry ?$ "." table)
(modify-syntax-entry ?? "_" table)
(modify-syntax-entry ?_ "_" table)
+ (modify-syntax-entry ?: "_" table)
(modify-syntax-entry ?< "." table)
(modify-syntax-entry ?> "." table)
(modify-syntax-entry ?& "." table)
@@ -565,7 +566,7 @@ and `\\' when preceded by `?'."
(setq nest (cons (cons nil pnt) nest))
(setq depth (1+ depth))))
(goto-char (match-end 0)))
- ((looking-at (concat "\\<\\(" ruby-block-beg-re "\\)\\>"))
+ ((looking-at (concat "\\_<\\(" ruby-block-beg-re "\\)\\_>"))
(and
(save-match-data
(or (not (looking-at (concat "do" ruby-keyword-end-re)))
@@ -864,7 +865,7 @@ move backward."
;; It seems like it should move to the line where indentation should deepen,
;; but ruby-indent-beg-re only accounts for whitespace before class, module and def,
;; so this will only match other block beginners at the beginning of the line.
- (and (re-search-backward (concat "^\\(" ruby-indent-beg-re "\\)\\b") nil 'move)
+ (and (re-search-backward (concat "^\\(" ruby-indent-beg-re "\\)\\_>") nil 'move)
(beginning-of-line)))
(defun ruby-move-to-block (n)
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#10786: 24.0.93; ruby-mode improperly handles symbols with keyword names in JS-style hashes
2012-02-11 0:27 bug#10786: 24.0.93; ruby-mode improperly handles symbols with keyword names in JS-style hashes Dmitry Gutov
@ 2012-02-11 1:50 ` Dmitry Gutov
2012-03-21 18:33 ` Stefan Monnier
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Gutov @ 2012-02-11 1:50 UTC (permalink / raw
To: 10786
Correction:
>> The latest ruby-mode highlights the keywords in the new-style hashes
properly
Should be "highlights the symbols", not keywords.
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#10786: 24.0.93; ruby-mode improperly handles symbols with keyword names in JS-style hashes
2012-02-11 0:27 bug#10786: 24.0.93; ruby-mode improperly handles symbols with keyword names in JS-style hashes Dmitry Gutov
2012-02-11 1:50 ` Dmitry Gutov
@ 2012-03-21 18:33 ` Stefan Monnier
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2012-03-21 18:33 UTC (permalink / raw
To: Dmitry Gutov; +Cc: 10786-done
Thanks, installed,
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-03-21 18:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-11 0:27 bug#10786: 24.0.93; ruby-mode improperly handles symbols with keyword names in JS-style hashes Dmitry Gutov
2012-02-11 1:50 ` Dmitry Gutov
2012-03-21 18:33 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.