diff options
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 108 |
1 files changed, 75 insertions, 33 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 0292e40b986..0b83921504b 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el | |||
| @@ -990,13 +990,14 @@ calculating indentation on the lines after it." | |||
| 990 | (defun ruby-move-to-block (n) | 990 | (defun ruby-move-to-block (n) |
| 991 | "Move to the beginning (N < 0) or the end (N > 0) of the | 991 | "Move to the beginning (N < 0) or the end (N > 0) of the |
| 992 | current block, a sibling block, or an outer block. Do that (abs N) times." | 992 | current block, a sibling block, or an outer block. Do that (abs N) times." |
| 993 | (back-to-indentation) | ||
| 993 | (let ((signum (if (> n 0) 1 -1)) | 994 | (let ((signum (if (> n 0) 1 -1)) |
| 994 | (backward (< n 0)) | 995 | (backward (< n 0)) |
| 995 | (depth (or (nth 2 (ruby-parse-region (line-beginning-position) | 996 | (depth (or (nth 2 (ruby-parse-region (point) (line-end-position))) 0)) |
| 996 | (line-end-position))) | ||
| 997 | 0)) | ||
| 998 | case-fold-search | 997 | case-fold-search |
| 999 | down done) | 998 | down done) |
| 999 | (when (looking-at ruby-block-mid-re) | ||
| 1000 | (setq depth (+ depth signum))) | ||
| 1000 | (when (< (* depth signum) 0) | 1001 | (when (< (* depth signum) 0) |
| 1001 | ;; Moving end -> end or beginning -> beginning. | 1002 | ;; Moving end -> end or beginning -> beginning. |
| 1002 | (setq depth 0)) | 1003 | (setq depth 0)) |
| @@ -1033,22 +1034,16 @@ current block, a sibling block, or an outer block. Do that (abs N) times." | |||
| 1033 | (unless (car state) ; Line ends with unfinished string. | 1034 | (unless (car state) ; Line ends with unfinished string. |
| 1034 | (setq depth (+ (nth 2 state) depth)))) | 1035 | (setq depth (+ (nth 2 state) depth)))) |
| 1035 | (cond | 1036 | (cond |
| 1036 | ;; Deeper indentation, we found a block. | 1037 | ;; Increased depth, we found a block. |
| 1037 | ;; FIXME: We can't recognize empty blocks this way. | ||
| 1038 | ((> (* signum depth) 0) | 1038 | ((> (* signum depth) 0) |
| 1039 | (setq down t)) | 1039 | (setq down t)) |
| 1040 | ;; Block found, and same indentation as when started, stop. | 1040 | ;; We're at the same depth as when we started, and we've |
| 1041 | ;; encountered a block before. Stop. | ||
| 1041 | ((and down (zerop depth)) | 1042 | ((and down (zerop depth)) |
| 1042 | (setq done t)) | 1043 | (setq done t)) |
| 1043 | ;; Shallower indentation, means outer block, can stop now. | 1044 | ;; Lower depth, means outer block, can stop now. |
| 1044 | ((< (* signum depth) 0) | 1045 | ((< (* signum depth) 0) |
| 1045 | (setq done t))))) | 1046 | (setq done t))))))) |
| 1046 | (if done | ||
| 1047 | (save-excursion | ||
| 1048 | (back-to-indentation) | ||
| 1049 | ;; Not really at the first or last line of the block, move on. | ||
| 1050 | (if (looking-at (concat "\\<\\(" ruby-block-mid-re "\\)\\>")) | ||
| 1051 | (setq done nil)))))) | ||
| 1052 | (back-to-indentation))) | 1047 | (back-to-indentation))) |
| 1053 | 1048 | ||
| 1054 | (defun ruby-beginning-of-block (&optional arg) | 1049 | (defun ruby-beginning-of-block (&optional arg) |
| @@ -1356,7 +1351,7 @@ If the result is do-end block, it will always be multiline." | |||
| 1356 | (progn | 1351 | (progn |
| 1357 | (eval-and-compile | 1352 | (eval-and-compile |
| 1358 | (defconst ruby-percent-literal-beg-re | 1353 | (defconst ruby-percent-literal-beg-re |
| 1359 | "\\(%\\)[qQrswWx]?\\([[:punct:]]\\)" | 1354 | "\\(%\\)[qQrswWxIi]?\\([[:punct:]]\\)" |
| 1360 | "Regexp to match the beginning of percent literal.") | 1355 | "Regexp to match the beginning of percent literal.") |
| 1361 | 1356 | ||
| 1362 | (defconst ruby-syntax-methods-before-regexp | 1357 | (defconst ruby-syntax-methods-before-regexp |
| @@ -1392,7 +1387,7 @@ It will be properly highlighted even when the call omits parens.") | |||
| 1392 | (funcall | 1387 | (funcall |
| 1393 | (syntax-propertize-rules | 1388 | (syntax-propertize-rules |
| 1394 | ;; $' $" $` .... are variables. | 1389 | ;; $' $" $` .... are variables. |
| 1395 | ;; ?' ?" ?` are ascii codes. | 1390 | ;; ?' ?" ?` are character literals (one-char strings in 1.9+). |
| 1396 | ("\\([?$]\\)[#\"'`]" | 1391 | ("\\([?$]\\)[#\"'`]" |
| 1397 | (1 (unless (save-excursion | 1392 | (1 (unless (save-excursion |
| 1398 | ;; Not within a string. | 1393 | ;; Not within a string. |
| @@ -1523,7 +1518,7 @@ It will be properly highlighted even when the call omits parens.") | |||
| 1523 | (save-match-data | 1518 | (save-match-data |
| 1524 | (save-excursion | 1519 | (save-excursion |
| 1525 | (goto-char (nth 8 parse-state)) | 1520 | (goto-char (nth 8 parse-state)) |
| 1526 | (looking-at "%\\(?:[QWrx]\\|\\W\\)"))))))) | 1521 | (looking-at "%\\(?:[QWrxI]\\|\\W\\)"))))))) |
| 1527 | 1522 | ||
| 1528 | (defun ruby-syntax-propertize-expansions (start end) | 1523 | (defun ruby-syntax-propertize-expansions (start end) |
| 1529 | (save-excursion | 1524 | (save-excursion |
| @@ -1726,7 +1721,7 @@ See `font-lock-syntax-table'.") | |||
| 1726 | (defconst ruby-font-lock-keywords | 1721 | (defconst ruby-font-lock-keywords |
| 1727 | (list | 1722 | (list |
| 1728 | ;; functions | 1723 | ;; functions |
| 1729 | '("^\\s *def\\s +\\([^( \t\n]+\\)" | 1724 | '("^\\s *def\\s +\\(?:[^( \t\n.]*\\.\\)?\\([^( \t\n]+\\)" |
| 1730 | 1 font-lock-function-name-face) | 1725 | 1 font-lock-function-name-face) |
| 1731 | (list (concat | 1726 | (list (concat |
| 1732 | "\\(^\\|[^.@$]\\|\\.\\.\\)\\(" | 1727 | "\\(^\\|[^.@$]\\|\\.\\.\\)\\(" |
| @@ -1767,31 +1762,66 @@ See `font-lock-syntax-table'.") | |||
| 1767 | "yield") | 1762 | "yield") |
| 1768 | 'symbols) | 1763 | 'symbols) |
| 1769 | "\\|" | 1764 | "\\|" |
| 1770 | ;; keyword-like methods on Kernel and Module | ||
| 1771 | (regexp-opt | 1765 | (regexp-opt |
| 1772 | '("alias_method" | 1766 | ;; built-in methods on Kernel |
| 1767 | '("__callee__" | ||
| 1768 | "__dir__" | ||
| 1769 | "__method__" | ||
| 1770 | "abort" | ||
| 1771 | "at_exit" | ||
| 1773 | "autoload" | 1772 | "autoload" |
| 1773 | "autoload?" | ||
| 1774 | "binding" | ||
| 1775 | "block_given?" | ||
| 1776 | "caller" | ||
| 1777 | "catch" | ||
| 1778 | "eval" | ||
| 1779 | "exec" | ||
| 1780 | "exit" | ||
| 1781 | "exit!" | ||
| 1782 | "fail" | ||
| 1783 | "fork" | ||
| 1784 | "format" | ||
| 1785 | "lambda" | ||
| 1786 | "load" | ||
| 1787 | "loop" | ||
| 1788 | "open" | ||
| 1789 | "p" | ||
| 1790 | "print" | ||
| 1791 | "printf" | ||
| 1792 | "proc" | ||
| 1793 | "putc" | ||
| 1794 | "puts" | ||
| 1795 | "raise" | ||
| 1796 | "rand" | ||
| 1797 | "readline" | ||
| 1798 | "readlines" | ||
| 1799 | "require" | ||
| 1800 | "require_relative" | ||
| 1801 | "sleep" | ||
| 1802 | "spawn" | ||
| 1803 | "sprintf" | ||
| 1804 | "srand" | ||
| 1805 | "syscall" | ||
| 1806 | "system" | ||
| 1807 | "throw" | ||
| 1808 | "trap" | ||
| 1809 | "warn" | ||
| 1810 | ;; keyword-like private methods on Module | ||
| 1811 | "alias_method" | ||
| 1774 | "attr" | 1812 | "attr" |
| 1775 | "attr_accessor" | 1813 | "attr_accessor" |
| 1776 | "attr_reader" | 1814 | "attr_reader" |
| 1777 | "attr_writer" | 1815 | "attr_writer" |
| 1778 | "catch" | ||
| 1779 | "define_method" | 1816 | "define_method" |
| 1780 | "extend" | 1817 | "extend" |
| 1781 | "fail" | ||
| 1782 | "include" | 1818 | "include" |
| 1783 | "lambda" | ||
| 1784 | "loop" | ||
| 1785 | "module_function" | 1819 | "module_function" |
| 1820 | "prepend" | ||
| 1786 | "private" | 1821 | "private" |
| 1787 | "proc" | ||
| 1788 | "protected" | 1822 | "protected" |
| 1789 | "public" | 1823 | "public" |
| 1790 | "raise" | ||
| 1791 | "refine" | 1824 | "refine" |
| 1792 | "require" | ||
| 1793 | "require_relative" | ||
| 1794 | "throw" | ||
| 1795 | "using") | 1825 | "using") |
| 1796 | 'symbols) | 1826 | 'symbols) |
| 1797 | "\\)") | 1827 | "\\)") |
| @@ -1799,12 +1829,16 @@ See `font-lock-syntax-table'.") | |||
| 1799 | '(if (match-beginning 4) | 1829 | '(if (match-beginning 4) |
| 1800 | font-lock-builtin-face | 1830 | font-lock-builtin-face |
| 1801 | font-lock-keyword-face)) | 1831 | font-lock-keyword-face)) |
| 1832 | ;; Perl-ish keywords | ||
| 1833 | "\\_<\\(?:BEGIN\\|END\\)\\_>\\|^__END__$" | ||
| 1802 | ;; here-doc beginnings | 1834 | ;; here-doc beginnings |
| 1803 | `(,ruby-here-doc-beg-re 0 (unless (ruby-singleton-class-p (match-beginning 0)) | 1835 | `(,ruby-here-doc-beg-re 0 (unless (ruby-singleton-class-p (match-beginning 0)) |
| 1804 | 'font-lock-string-face)) | 1836 | 'font-lock-string-face)) |
| 1805 | ;; variables | 1837 | ;; variables |
| 1806 | '("\\(^\\|[^.@$]\\|\\.\\.\\)\\_<\\(nil\\|self\\|true\\|false\\)\\>" | 1838 | '("\\(^\\|[^.@$]\\|\\.\\.\\)\\_<\\(nil\\|self\\|true\\|false\\)\\>" |
| 1807 | 2 font-lock-variable-name-face) | 1839 | 2 font-lock-variable-name-face) |
| 1840 | ;; keywords that evaluate to certain values | ||
| 1841 | '("\\_<__\\(?:LINE\\|ENCODING\\|FILE\\)__\\_>" 0 font-lock-variable-name-face) | ||
| 1808 | ;; symbols | 1842 | ;; symbols |
| 1809 | '("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\|@?\\(\\w\\|_\\)+\\([!?=]\\|\\b_*\\)\\|#{[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\)\\)" | 1843 | '("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\|@?\\(\\w\\|_\\)+\\([!?=]\\|\\b_*\\)\\|#{[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\)\\)" |
| 1810 | 2 font-lock-constant-face) | 1844 | 2 font-lock-constant-face) |
| @@ -1815,14 +1849,22 @@ See `font-lock-syntax-table'.") | |||
| 1815 | 0 font-lock-variable-name-face) | 1849 | 0 font-lock-variable-name-face) |
| 1816 | ;; constants | 1850 | ;; constants |
| 1817 | '("\\(?:\\_<\\|::\\)\\([A-Z]+\\(\\w\\|_\\)*\\)" | 1851 | '("\\(?:\\_<\\|::\\)\\([A-Z]+\\(\\w\\|_\\)*\\)" |
| 1818 | 1 font-lock-type-face) | 1852 | 1 (unless (eq ?\( (char-after)) font-lock-type-face)) |
| 1819 | '("\\(^\\s *\\|[\[\{\(,]\\s *\\|\\sw\\s +\\)\\(\\(\\sw\\|_\\)+\\):[^:]" 2 font-lock-constant-face) | 1853 | '("\\(^\\s *\\|[\[\{\(,]\\s *\\|\\sw\\s +\\)\\(\\(\\sw\\|_\\)+\\):[^:]" 2 font-lock-constant-face) |
| 1854 | ;; conversion methods on Kernel | ||
| 1855 | (list (concat "\\(?:^\\|[^.@$]\\|\\.\\.\\)" | ||
| 1856 | (regexp-opt '("Array" "Complex" "Float" "Hash" | ||
| 1857 | "Integer" "Rational" "String") 'symbols)) | ||
| 1858 | 1 font-lock-builtin-face) | ||
| 1820 | ;; expression expansion | 1859 | ;; expression expansion |
| 1821 | '(ruby-match-expression-expansion | 1860 | '(ruby-match-expression-expansion |
| 1822 | 2 font-lock-variable-name-face t) | 1861 | 2 font-lock-variable-name-face t) |
| 1823 | ;; warn lower camel case | 1862 | ;; negation char |
| 1824 | ;'("\\<[a-z]+[a-z0-9]*[A-Z][A-Za-z0-9]*\\([!?]?\\|\\>\\)" | 1863 | '("[^[:alnum:]_]\\(!\\)[^=]" |
| 1825 | ; 0 font-lock-warning-face) | 1864 | 1 font-lock-negation-char-face) |
| 1865 | ;; character literals | ||
| 1866 | ;; FIXME: Support longer escape sequences. | ||
| 1867 | '("\\?\\\\?\\S " 0 font-lock-string-face) | ||
| 1826 | ) | 1868 | ) |
| 1827 | "Additional expressions to highlight in Ruby mode.") | 1869 | "Additional expressions to highlight in Ruby mode.") |
| 1828 | 1870 | ||