Subject: Re: bug#17057: 24.3.50; [ruby-mode] Font-locking of special global variables like $$ is broken(missing)

From: Dmitry Gutov <[email-masked]>
Date: Wed, 26 Mar 2014 14:35:13 +0200

On 24.03.2014 11:45, Bozhidar Batsov wrote:

> Yeah, seems that everything important is listed there. Here’s one a bit
> more extensive list, though:
>
> https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cop/style/global_vars.rb
>
> It features the JRuby-specific global vars in addition to the standard
> ones.

I see that you don't include the $(digit) globals, which reference the 
last regexp-matched groups. The patch below does.

Not sure if it's okay to install in 24.4, though: on the one hand it's 
low-risk, on the other hand it's not a bugfix.

=== modified file 'lisp/progmodes/ruby-mode.el'
--- lisp/progmodes/ruby-mode.el	2014-03-24 08:53:56 +0000
+++ lisp/progmodes/ruby-mode.el	2014-03-26 11:33:42 +0000
@@ -2108,13 +2108,28 @@
       1 font-lock-variable-name-face)
      ;; Keywords that evaluate to certain values.
      ("\\_<__\\(?:LINE\\|ENCODING\\|FILE\\)__\\_>"
-     (0 font-lock-variable-name-face))
+     (0 font-lock-builtin-face))
      ;; Symbols.
 
("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\|@?\\(\\w\\|_\\)+\\([!?=]\\|\\b_*\\)\\|#{[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\)\\)"
       2 font-lock-constant-face)
-    ;; Variables.
-    ("\\$[^a-zA-Z \n]"
-     0 font-lock-variable-name-face)
+    ;; Special variables.
+    (,(concat "\\$\\(?:[:\"!@;,/\\._><\\$?~=*&`'+0-9]\\|-[0adFiIlpvw]\\|"
+              (regexp-opt '("LOAD_PATH" "LOADED_FEATURES" "PROGRAM_NAME"
+                            "ERROR_INFO" "ERROR_POSITION"
+                            "FS" "FIELD_SEPARATOR"
+                            "OFS" "OUTPUT_FIELD_SEPARATOR"
+                            "RS" "INPUT_RECORD_SEPARATOR"
+                            "ORS" "OUTPUT_RECORD_SEPARATOR"
+                            "NR" "INPUT_LINE_NUMBER"
+                            "LAST_READ_LINE" "DEFAULT_OUTPUT" 
"DEFAULT_INPUT"
+                            "PID" "PROCESS_ID" "CHILD_STATUS"
+                            "LAST_MATCH_INFO" "IGNORECASE"
+                            "ARGV" "MATCH" "PREMATCH" "POSTMATCH"
+                            "LAST_PAREN_MATCH" "stdin" "stdout" "stderr"
+                            "DEBUG" "FILENAME" "VERBOSE" "SAFE" "CLASSPATH"
+                            "JRUBY_VERSION" "JRUBY_REVISION" "ENV_JAVA"))
+              "\\_>\\)")
+     0 font-lock-builtin-face)
      ("\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+"
       0 font-lock-variable-name-face)
      ;; Constants.