Make $, : and @ "prefix characters" in ruby-mode

* lisp/progmodes/ruby-mode.el (ruby-mode-syntax-table): Change the
syntax classes of $, : and @ to "prefix character"
(http://lists.gnu.org/archive/html/emacs-devel/2016-01/msg00272.html).
(ruby-syntax-propertize): Undo that specifically for colons
followed by an opening paren or bracket.
(ruby-font-lock-keyword-beg-re): Include colon character.
(ruby-font-lock-keywords): Adjust the constants matcher for `:'
not being a symbol constituent anymore.
This commit is contained in:
Dmitry Gutov 2016-02-23 02:27:49 +02:00
parent e72a26e009
commit c1ec7434c3

View file

@ -32,7 +32,7 @@
;; file after putting it on your load path: ;; file after putting it on your load path:
;; ;;
;; (autoload 'ruby-mode "ruby-mode" "Major mode for ruby files" t) ;; (autoload 'ruby-mode "ruby-mode" "Major mode for ruby files" t)
;; (add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode)) ;; (add-to-list 'auto-mode-alist '("\\.rb\\'" . ruby-mode))
;; (add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode)) ;; (add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode))
;; ;;
;; Still needs more docstrings; search below for TODO. ;; Still needs more docstrings; search below for TODO.
@ -188,9 +188,10 @@ This should only be called after matching against `ruby-here-doc-beg-re'."
(modify-syntax-entry ?# "<" table) (modify-syntax-entry ?# "<" table)
(modify-syntax-entry ?\n ">" table) (modify-syntax-entry ?\n ">" table)
(modify-syntax-entry ?\\ "\\" table) (modify-syntax-entry ?\\ "\\" table)
(modify-syntax-entry ?$ "." table) (modify-syntax-entry ?$ "'" table)
(modify-syntax-entry ?_ "_" table) (modify-syntax-entry ?_ "_" table)
(modify-syntax-entry ?: "_" table) (modify-syntax-entry ?: "'" table)
(modify-syntax-entry ?@ "'" table)
(modify-syntax-entry ?< "." table) (modify-syntax-entry ?< "." table)
(modify-syntax-entry ?> "." table) (modify-syntax-entry ?> "." table)
(modify-syntax-entry ?& "." table) (modify-syntax-entry ?& "." table)
@ -1859,6 +1860,10 @@ It will be properly highlighted even when the call omits parens.")
(string-to-syntax "_")))) (string-to-syntax "_"))))
;; Backtick method redefinition. ;; Backtick method redefinition.
("^[ \t]*def +\\(`\\)" (1 "_")) ("^[ \t]*def +\\(`\\)" (1 "_"))
;; Ternary operator colon followed by opening paren or bracket
;; (semi-important for indentation).
("\\(:\\)\\(?:[\({]\\|\\[[^]]\\)"
(1 (string-to-syntax ".")))
;; Regular expressions. Start with matching unescaped slash. ;; Regular expressions. Start with matching unescaped slash.
("\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*\\(/\\)" ("\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*\\(/\\)"
(1 (let ((state (save-excursion (syntax-ppss (match-beginning 1))))) (1 (let ((state (save-excursion (syntax-ppss (match-beginning 1)))))
@ -2024,7 +2029,7 @@ It will be properly highlighted even when the call omits parens.")
"The syntax table to use for fontifying Ruby mode buffers. "The syntax table to use for fontifying Ruby mode buffers.
See `font-lock-syntax-table'.") See `font-lock-syntax-table'.")
(defconst ruby-font-lock-keyword-beg-re "\\(?:^\\|[^.@$]\\|\\.\\.\\)") (defconst ruby-font-lock-keyword-beg-re "\\(?:^\\|[^.@$:]\\|\\.\\.\\)")
(defconst ruby-font-lock-keywords (defconst ruby-font-lock-keywords
`(;; Functions. `(;; Functions.
@ -2197,7 +2202,7 @@ See `font-lock-syntax-table'.")
("\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+" ("\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+"
0 font-lock-variable-name-face) 0 font-lock-variable-name-face)
;; Constants. ;; Constants.
("\\(?:\\_<\\|::\\)\\([A-Z]+\\(\\w\\|_\\)*\\)" ("\\_<\\([A-Z]+\\(\\w\\|_\\)*\\)"
1 (unless (eq ?\( (char-after)) font-lock-type-face)) 1 (unless (eq ?\( (char-after)) font-lock-type-face))
;; Ruby 1.9-style symbol hash keys. ;; Ruby 1.9-style symbol hash keys.
("\\(?:^\\s *\\|[[{(,]\\s *\\|\\sw\\s +\\)\\(\\(\\sw\\|_\\)+:\\)[^:]" ("\\(?:^\\s *\\|[[{(,]\\s *\\|\\sw\\s +\\)\\(\\(\\sw\\|_\\)+:\\)[^:]"