Propertize character literals and special global variables differently

* lisp/progmodes/ruby-mode.el (ruby-syntax-propertize): Propertize
character literals and global variables with special names with
prefix and symbol syntax classes, for SMIE to tokenize them
together automatically.
(ruby-font-lock-keywords): Fix an old regression in highlighting
character literals.
This commit is contained in:
Dmitry Gutov 2016-03-10 04:13:25 +02:00
parent a7d6f39d8a
commit 28532a91a9
2 changed files with 8 additions and 3 deletions

View file

@ -1844,13 +1844,15 @@ It will be properly highlighted even when the call omits parens.")
(syntax-propertize-rules (syntax-propertize-rules
;; $' $" $` .... are variables. ;; $' $" $` .... are variables.
;; ?' ?" ?` are character literals (one-char strings in 1.9+). ;; ?' ?" ?` are character literals (one-char strings in 1.9+).
("\\([?$]\\)[#\"'`]" ("\\([?$]\\)[#\"'`:?]"
(1 (if (save-excursion (1 (if (save-excursion
(nth 3 (syntax-ppss (match-beginning 0)))) (nth 3 (syntax-ppss (match-beginning 0))))
;; Within a string, skip. ;; Within a string, skip.
(ignore (ignore
(goto-char (match-end 1))) (goto-char (match-end 1)))
(string-to-syntax "\\")))) (put-text-property (match-end 1) (match-end 0)
'syntax-table (string-to-syntax "_"))
(string-to-syntax "'"))))
;; Symbols with special characters. ;; Symbols with special characters.
("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\)\\)" ("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\)\\)"
(3 (string-to-syntax "_"))) (3 (string-to-syntax "_")))
@ -2222,7 +2224,7 @@ See `font-lock-syntax-table'.")
1 font-lock-negation-char-face) 1 font-lock-negation-char-face)
;; Character literals. ;; Character literals.
;; FIXME: Support longer escape sequences. ;; FIXME: Support longer escape sequences.
("\\_<\\?\\\\?\\S " 0 font-lock-string-face) ("\\?\\\\?\\_<.\\_>" 0 font-lock-string-face)
;; Regexp options. ;; Regexp options.
("\\(?:\\s|\\|/\\)\\([imxo]+\\)" ("\\(?:\\s|\\|/\\)\\([imxo]+\\)"
1 (when (save-excursion 1 (when (save-excursion

View file

@ -174,6 +174,9 @@ def test2 (arg)
bar, bar,
:a :a
b = $:
c = ??
# Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html # Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
d = 4 + 5 + # no '\' needed d = 4 + 5 + # no '\' needed
6 + 7 6 + 7