aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/ruby-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
-rw-r--r--lisp/progmodes/ruby-mode.el43
1 files changed, 20 insertions, 23 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 0b83921504b..c8fae7ba1e6 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -46,11 +46,6 @@
46 :prefix "ruby-" 46 :prefix "ruby-"
47 :group 'languages) 47 :group 'languages)
48 48
49(defconst ruby-keyword-end-re
50 (if (string-match "\\_>" "ruby")
51 "\\_>"
52 "\\>"))
53
54(defconst ruby-block-beg-keywords 49(defconst ruby-block-beg-keywords
55 '("class" "module" "def" "if" "unless" "case" "while" "until" "for" "begin" "do") 50 '("class" "module" "def" "if" "unless" "case" "while" "until" "for" "begin" "do")
56 "Keywords at the beginning of blocks.") 51 "Keywords at the beginning of blocks.")
@@ -60,7 +55,7 @@
60 "Regexp to match the beginning of blocks.") 55 "Regexp to match the beginning of blocks.")
61 56
62(defconst ruby-non-block-do-re 57(defconst ruby-non-block-do-re
63 (concat (regexp-opt '("while" "until" "for" "rescue") t) ruby-keyword-end-re) 58 (regexp-opt '("while" "until" "for" "rescue") 'symbols)
64 "Regexp to match keywords that nest without blocks.") 59 "Regexp to match keywords that nest without blocks.")
65 60
66(defconst ruby-indent-beg-re 61(defconst ruby-indent-beg-re
@@ -696,7 +691,7 @@ Can be one of `heredoc', `modifier', `expr-qstr', `expr-re'."
696 ((looking-at (concat "\\_<\\(" ruby-block-beg-re "\\)\\_>")) 691 ((looking-at (concat "\\_<\\(" ruby-block-beg-re "\\)\\_>"))
697 (and 692 (and
698 (save-match-data 693 (save-match-data
699 (or (not (looking-at (concat "do" ruby-keyword-end-re))) 694 (or (not (looking-at "do\\_>"))
700 (save-excursion 695 (save-excursion
701 (back-to-indentation) 696 (back-to-indentation)
702 (not (looking-at ruby-non-block-do-re))))) 697 (not (looking-at ruby-non-block-do-re)))))
@@ -1718,14 +1713,16 @@ See the definition of `ruby-font-lock-syntactic-keywords'."
1718 "The syntax table to use for fontifying Ruby mode buffers. 1713 "The syntax table to use for fontifying Ruby mode buffers.
1719See `font-lock-syntax-table'.") 1714See `font-lock-syntax-table'.")
1720 1715
1716(defconst ruby-font-lock-keyword-beg-re "\\(?:^\\|[^.@$]\\|\\.\\.\\)")
1717
1721(defconst ruby-font-lock-keywords 1718(defconst ruby-font-lock-keywords
1722 (list 1719 (list
1723 ;; functions 1720 ;; functions
1724 '("^\\s *def\\s +\\(?:[^( \t\n.]*\\.\\)?\\([^( \t\n]+\\)" 1721 '("^\\s *def\\s +\\(?:[^( \t\n.]*\\.\\)?\\([^( \t\n]+\\)"
1725 1 font-lock-function-name-face) 1722 1 font-lock-function-name-face)
1723 ;; keywords
1726 (list (concat 1724 (list (concat
1727 "\\(^\\|[^.@$]\\|\\.\\.\\)\\(" 1725 ruby-font-lock-keyword-beg-re
1728 ;; keywords
1729 (regexp-opt 1726 (regexp-opt
1730 '("alias" 1727 '("alias"
1731 "and" 1728 "and"
@@ -1760,11 +1757,14 @@ See `font-lock-syntax-table'.")
1760 "when" 1757 "when"
1761 "while" 1758 "while"
1762 "yield") 1759 "yield")
1763 'symbols) 1760 'symbols))
1764 "\\|" 1761 1 'font-lock-keyword-face)
1762 ;; some core methods
1763 (list (concat
1764 ruby-font-lock-keyword-beg-re
1765 (regexp-opt 1765 (regexp-opt
1766 ;; built-in methods on Kernel 1766 '(;; built-in methods on Kernel
1767 '("__callee__" 1767 "__callee__"
1768 "__dir__" 1768 "__dir__"
1769 "__method__" 1769 "__method__"
1770 "abort" 1770 "abort"
@@ -1823,20 +1823,17 @@ See `font-lock-syntax-table'.")
1823 "public" 1823 "public"
1824 "refine" 1824 "refine"
1825 "using") 1825 "using")
1826 'symbols) 1826 'symbols))
1827 "\\)") 1827 1 'font-lock-builtin-face)
1828 2
1829 '(if (match-beginning 4)
1830 font-lock-builtin-face
1831 font-lock-keyword-face))
1832 ;; Perl-ish keywords 1828 ;; Perl-ish keywords
1833 "\\_<\\(?:BEGIN\\|END\\)\\_>\\|^__END__$" 1829 "\\_<\\(?:BEGIN\\|END\\)\\_>\\|^__END__$"
1834 ;; here-doc beginnings 1830 ;; here-doc beginnings
1835 `(,ruby-here-doc-beg-re 0 (unless (ruby-singleton-class-p (match-beginning 0)) 1831 `(,ruby-here-doc-beg-re 0 (unless (ruby-singleton-class-p (match-beginning 0))
1836 'font-lock-string-face)) 1832 'font-lock-string-face))
1837 ;; variables 1833 ;; variables
1838 '("\\(^\\|[^.@$]\\|\\.\\.\\)\\_<\\(nil\\|self\\|true\\|false\\)\\>" 1834 `(,(concat ruby-font-lock-keyword-beg-re
1839 2 font-lock-variable-name-face) 1835 "\\_<\\(nil\\|self\\|true\\|false\\)\\>")
1836 1 font-lock-variable-name-face)
1840 ;; keywords that evaluate to certain values 1837 ;; keywords that evaluate to certain values
1841 '("\\_<__\\(?:LINE\\|ENCODING\\|FILE\\)__\\_>" 0 font-lock-variable-name-face) 1838 '("\\_<__\\(?:LINE\\|ENCODING\\|FILE\\)__\\_>" 0 font-lock-variable-name-face)
1842 ;; symbols 1839 ;; symbols
@@ -1852,7 +1849,7 @@ See `font-lock-syntax-table'.")
1852 1 (unless (eq ?\( (char-after)) font-lock-type-face)) 1849 1 (unless (eq ?\( (char-after)) font-lock-type-face))
1853 '("\\(^\\s *\\|[\[\{\(,]\\s *\\|\\sw\\s +\\)\\(\\(\\sw\\|_\\)+\\):[^:]" 2 font-lock-constant-face) 1850 '("\\(^\\s *\\|[\[\{\(,]\\s *\\|\\sw\\s +\\)\\(\\(\\sw\\|_\\)+\\):[^:]" 2 font-lock-constant-face)
1854 ;; conversion methods on Kernel 1851 ;; conversion methods on Kernel
1855 (list (concat "\\(?:^\\|[^.@$]\\|\\.\\.\\)" 1852 (list (concat ruby-font-lock-keyword-beg-re
1856 (regexp-opt '("Array" "Complex" "Float" "Hash" 1853 (regexp-opt '("Array" "Complex" "Float" "Hash"
1857 "Integer" "Rational" "String") 'symbols)) 1854 "Integer" "Rational" "String") 'symbols))
1858 1 font-lock-builtin-face) 1855 1 font-lock-builtin-face)
@@ -1864,7 +1861,7 @@ See `font-lock-syntax-table'.")
1864 1 font-lock-negation-char-face) 1861 1 font-lock-negation-char-face)
1865 ;; character literals 1862 ;; character literals
1866 ;; FIXME: Support longer escape sequences. 1863 ;; FIXME: Support longer escape sequences.
1867 '("\\?\\\\?\\S " 0 font-lock-string-face) 1864 '("\\_<\\?\\\\?\\S " 0 font-lock-string-face)
1868 ) 1865 )
1869 "Additional expressions to highlight in Ruby mode.") 1866 "Additional expressions to highlight in Ruby mode.")
1870 1867