-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Justin Smestad edited this page Apr 24, 2017
·
2 revisions
Unfortunately the ruby-mode
that ships with Emacs 25.x, highlights self
like a keyword instead of matching nil
, true
, and false
. It also uses the wrong color to highlight symbols. To fix this when using this theme, add the following to your config:
(defvar ruby-symbol-face 'ruby-symbol-face)
(defface ruby-symbol-face
'((t (:inherit ruby-constant-face)))
"Syntax highlighting for Ruby symbol."
:group 'ruby)
(defvar ruby-constant-face 'ruby-constant-face)
(defface ruby-constant-face
'((t (:inherit font-lock-constant-face)))
"Syntax highlighting for Ruby constant."
:group 'ruby)
(defun ruby-syntax-highlight-overrides ()
(font-lock-add-keywords nil
'(;; Singleton objects.
("\\(?:^\\|[^.@$:]\\|\\.\\.\\)\\_<\\(self\\|nil\\|true\\|false\\)\\_>"
1 ruby-constant-face)
;; Symbols.
("\\(^\\|[^:]\\)\\(:@\\{0,2\\}\\(?:\\sw\\|\\s_\\)+\\)"
(2 ruby-symbol-face)
(3 (unless (and (eq (char-before (match-end 3)) ?=)
(eq (char-after (match-end 3)) ?>))
;; bug#18644
ruby-symbol-face)
nil t))
;; Ruby 1.9-style symbol hash keys.
("\\(?:^\\s *\\|[[{(,]\\s *\\|\\sw\\s +\\)\\(\\(\\sw\\|_\\)+:\\)[^:]"
(1 (progn (forward-char -1) ruby-symbol-face)))
))
)
(add-hook 'ruby-mode-hook 'ruby-syntax-highlight-overrides)
Spacemacs Users: the above code only works when placed inside the dotspacemacs/user-init
function.