emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Small improvements to ruby-mode


From: Dmitry Gutov
Subject: Re: Small improvements to ruby-mode
Date: Sat, 13 Jul 2013 00:31:03 +0400
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7

On 11.07.2013 15:23, Bozhidar Batsov wrote:
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.

Fixed, among other things, see the patch at the bottom. We don't highlight method calls, so I just disabled highlighting in this case.

> 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.

Function calls can be identified by having a paren after the name (no luck with parenless calls).

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.

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]