]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/ruby-mode.el
; Merge from origin/emacs-25
[gnu-emacs] / lisp / progmodes / ruby-mode.el
index df07083eaefbc4f310002ba0fc4ee1c4f6395360..fb942b34ddc7a0095d82bfec83fb44c7f3e3dfd0 100644 (file)
@@ -1,6 +1,6 @@
 ;;; ruby-mode.el --- Major mode for editing Ruby files
 
-;; Copyright (C) 1994-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1994-2016 Free Software Foundation, Inc.
 
 ;; Authors: Yukihiro Matsumoto
 ;;     Nobuyoshi Nakada
@@ -32,7 +32,7 @@
 ;; file after putting it on your load path:
 ;;
 ;;    (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))
 ;;
 ;; Still needs more docstrings; search below for TODO.
 
 (eval-and-compile
   (defconst ruby-here-doc-beg-re
-  "\\(<\\)<\\(-\\)?\\(\\([a-zA-Z0-9_]+\\)\\|[\"]\\([^\"]+\\)[\"]\\|[']\\([^']+\\)[']\\)"
+  "\\(<\\)<\\([~-]\\)?\\(\\([a-zA-Z0-9_]+\\)\\|[\"]\\([^\"]+\\)[\"]\\|[']\\([^']+\\)[']\\)"
   "Regexp to match the beginning of a heredoc.")
 
   (defconst ruby-expression-expansion-re
@@ -188,9 +188,10 @@ This should only be called after matching against `ruby-here-doc-beg-re'."
     (modify-syntax-entry ?# "<" 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)
@@ -1830,7 +1831,7 @@ It will be properly highlighted even when the call omits parens.")
      "\\)\\s *")
     "Regexp to match text that can be followed by a regular expression."))
 
-(defun ruby-syntax-propertize-function (start end)
+(defun ruby-syntax-propertize (start end)
   "Syntactic keywords for Ruby mode.  See `syntax-propertize-function'."
   (let (case-fold-search)
     (goto-char start)
@@ -1856,6 +1857,12 @@ It will be properly highlighted even when the call omits parens.")
                           (zerop (skip-syntax-backward "w_")))
                         (memq (preceding-char) '(?@ ?$))))
             (string-to-syntax "_"))))
+      ;; Backtick method redefinition.
+      ("^[ \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.
       ("\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*\\(/\\)"
        (1 (let ((state (save-excursion (syntax-ppss (match-beginning 1)))))
@@ -1891,6 +1898,9 @@ It will be properly highlighted even when the call omits parens.")
        (1 (prog1 "|" (ruby-syntax-propertize-percent-literal end)))))
      (point) end)))
 
+(define-obsolete-function-alias
+  'ruby-syntax-propertize-function 'ruby-syntax-propertize "25.1")
+
 (defun ruby-syntax-propertize-heredoc (limit)
   (let ((ppss (syntax-ppss))
         (res '()))
@@ -2018,7 +2028,7 @@ It will be properly highlighted even when the call omits parens.")
   "The syntax table to use for fontifying Ruby mode buffers.
 See `font-lock-syntax-table'.")
 
-(defconst ruby-font-lock-keyword-beg-re "\\(?:^\\|[^.@$]\\|\\.\\.\\)")
+(defconst ruby-font-lock-keyword-beg-re "\\(?:^\\|[^.@$:]\\|\\.\\.\\)")
 
 (defconst ruby-font-lock-keywords
   `(;; Functions.
@@ -2191,7 +2201,7 @@ See `font-lock-syntax-table'.")
     ("\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+"
      0 font-lock-variable-name-face)
     ;; Constants.
-    ("\\(?:\\_<\\|::\\)\\([A-Z]+\\(\\w\\|_\\)*\\)"
+    ("\\_<\\([A-Z]+\\(\\w\\|_\\)*\\)"
      1 (unless (eq ?\( (char-after)) font-lock-type-face))
     ;; Ruby 1.9-style symbol hash keys.
     ("\\(?:^\\s *\\|[[{(,]\\s *\\|\\sw\\s +\\)\\(\\(\\sw\\|_\\)+:\\)[^:]"
@@ -2252,7 +2262,7 @@ See `font-lock-syntax-table'.")
   (setq-local font-lock-keywords ruby-font-lock-keywords)
   (setq-local font-lock-syntax-table ruby-font-lock-syntax-table)
 
-  (setq-local syntax-propertize-function #'ruby-syntax-propertize-function))
+  (setq-local syntax-propertize-function #'ruby-syntax-propertize))
 
 ;;; Invoke ruby-mode when appropriate