|
From: | Bozhidar Batsov |
Subject: | Re: Small improvements to ruby-mode |
Date: | Sat, 13 Jul 2013 13:24:34 +0300 |
On 12 July 2013 23:31, Dmitry Gutov <address@hidden> wrote:
On 11.07.2013 15:23, Bozhidar Batsov wrote:Fixed, among other things, see the patch at the bottom. We don't highlight method calls, so I just disabled highlighting in this case.
Still, we should consider functions with names like Float. Currently
they are not highlighted correctly - Something(test) is highlighted as a
constant, when obviously it's not.
Great! Btw, shouldn't we highlight the conversion methods from Kernel (Float, Integer, etc) as built-ins?Function calls can be identified by having a paren after the name (no luck with parenless calls).
> I guess classes, constants and
functions like this could be font-locked after the first character
that's not part of the identifier name appears, to avoid the changing of
the face after the initial character.
But there's really nothing that would distinguish a Math::E reference from Foo::C. Or from GC, IO, DL, IRB, URI, XML, HTML, etc.Yep, I'm aware we can't distinguish all cases without the use of a proper parser, but I guess we should handle accordingly at least the scenarios which are deterministic.
=== modified file 'lisp/progmodes/ruby-mode.el'
--- lisp/progmodes/ruby-mode.el 2013-07-09 01:17:48 +0000
+++ lisp/progmodes/ruby-mode.el 2013-07-12 20:07:57 +0000
@@ -1351,7 +1351,7 @@
(progn
(eval-and-compile
(defconst ruby-percent-literal-beg-re
- "\\(%\\)[qQrswWx]?\\([[:punct:]]\\)"
+ "\\(%\\)[qQrswWxIi]?\\([[:punct:]]\\)"
"Regexp to match the beginning of percent literal.")
(defconst ruby-syntax-methods-before-regexp
@@ -1387,7 +1387,7 @@
(funcall
(syntax-propertize-rules
;; $' $" $` .... are variables.
- ;; ?' ?" ?` are ascii codes.
+ ;; ?' ?" ?` are character literals (one-char strings in 1.9+).
("\\([?$]\\)[#\"'`]"
(1 (unless (save-excursion
;; Not within a string.
@@ -1518,7 +1518,7 @@
(save-match-data
(save-excursion
(goto-char (nth 8 parse-state))
- (looking-at "%\\(?:[QWrx]\\|\\W\\)")))))))
+ (looking-at "%\\(?:[QWrxI]\\|\\W\\)")))))))
(defun ruby-syntax-propertize-expansions (start end)
(save-excursion
@@ -1848,8 +1848,11 @@
'("\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+"
0 font-lock-variable-name-face)
;; constants
- '("\\(?:\\_<\\|::\\)\\([A-Z]+\\(\\w\\|_\\)*\\)"
- 1 font-lock-type-face)
+ '("\\(?:\\_<\\|::\\)\\([A-Z]+\\(\\w\\|_\\)*\\)\\(?:\\_>[^\(]\\|::\\|\\'\\)"
+ 1 (progn
+ (when (eq ?: (char-before))
+ (forward-char -2))
+ font-lock-type-face))
'("\\(^\\s *\\|[\[\{\(,]\\s *\\|\\sw\\s +\\)\\(\\(\\sw\\|_\\)+\\):[^:]" 2 font-lock-constant-face)
;; _expression_ expansion
'(ruby-match-_expression_-expansion
@@ -1857,6 +1860,9 @@
;; negation char
'("[^[:alnum:]_]\\(!\\)[^=]"
1 font-lock-negation-char-face)
+ ;; character literals
+ ;; FIXME: Support longer escape sequences.
+ '("\\?\\\\?\\S " 0 font-lock-string-face)
)
"Additional expressions to highlight in Ruby mode.")
[Prev in Thread] | Current Thread | [Next in Thread] |