diff options
| author | Dmitry Gutov | 2012-09-07 08:15:56 +0400 |
|---|---|---|
| committer | Dmitry Gutov | 2012-09-07 08:15:56 +0400 |
| commit | 0ba2d4b6465b0b66d34e6ef47c151bd5920fbe54 (patch) | |
| tree | adb7447fb81dd81374d12a3765716b8d60e01fe6 /lisp/progmodes/ruby-mode.el | |
| parent | 1d43a35f49f7403f7f50f36dddf88167a7c81f11 (diff) | |
| download | emacs-0ba2d4b6465b0b66d34e6ef47c151bd5920fbe54.tar.gz emacs-0ba2d4b6465b0b66d34e6ef47c151bd5920fbe54.zip | |
* lisp/progmodes/ruby-mode.el (ruby-indent-beg-re): Add pieces from
ruby-beginning-of-indent, simplify, allow all keywords to have
indentation before them.
(ruby-beginning-of-indent): Adjust for above. Search until the
found point is not inside a string or comment.
(ruby-font-lock-keywords): Allow symbols to start with "@"
character, give them higher priority than variables.
(ruby-syntax-propertize-function)
(ruby-font-lock-syntactic-keywords): Remove the "not comments"
matchers. Expression expansions are not comments when inside a
string, and there comment syntax status is irrelevant.
(ruby-match-expression-expansion): New function. Check that
expression expansion is inside a string, and it's not escaped.
(ruby-font-lock-keywords): Use it.
* test/automated/ruby-mode-tests.el: New tests (Bug#11613).
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 3f93ffa84ba..bcebada5e86 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el | |||
| @@ -64,8 +64,8 @@ | |||
| 64 | "Regexp to match keywords that nest without blocks.") | 64 | "Regexp to match keywords that nest without blocks.") |
| 65 | 65 | ||
| 66 | (defconst ruby-indent-beg-re | 66 | (defconst ruby-indent-beg-re |
| 67 | (concat "\\(\\s *" (regexp-opt '("class" "module" "def") t) "\\)\\|" | 67 | (concat "^\\s *" (regexp-opt '("class" "module" "def" "if" "unless" "case" |
| 68 | (regexp-opt '("if" "unless" "case" "while" "until" "for" "begin"))) | 68 | "while" "until" "for" "begin")) "\\_>") |
| 69 | "Regexp to match where the indentation gets deeper.") | 69 | "Regexp to match where the indentation gets deeper.") |
| 70 | 70 | ||
| 71 | (defconst ruby-modifier-beg-keywords | 71 | (defconst ruby-modifier-beg-keywords |
| @@ -848,19 +848,18 @@ move forward." | |||
| 848 | With ARG, move forward multiple defuns. Negative ARG means | 848 | With ARG, move forward multiple defuns. Negative ARG means |
| 849 | move backward." | 849 | move backward." |
| 850 | (interactive "p") | 850 | (interactive "p") |
| 851 | (and (re-search-forward (concat "^\\(" ruby-block-end-re "\\)\\($\\|\\b[^_]\\)") | 851 | (and (re-search-forward ruby-indent-beg-re nil 'move (or arg 1)) |
| 852 | nil 'move (or arg 1)) | ||
| 853 | (beginning-of-line)) | 852 | (beginning-of-line)) |
| 854 | (forward-line 1)) | 853 | (forward-line 1)) |
| 855 | 854 | ||
| 856 | (defun ruby-beginning-of-indent () | 855 | (defun ruby-beginning-of-indent () |
| 857 | "TODO: document" | 856 | "Backtrack to a line which can be used as a reference for |
| 858 | ;; I don't understand this function. | 857 | calculating indentation on the lines after it." |
| 859 | ;; It seems like it should move to the line where indentation should deepen, | 858 | (while (and (re-search-backward ruby-indent-beg-re nil 'move) |
| 860 | ;; but ruby-indent-beg-re only accounts for whitespace before class, module and def, | 859 | (if (ruby-in-ppss-context-p 'anything) |
| 861 | ;; so this will only match other block beginners at the beginning of the line. | 860 | t |
| 862 | (and (re-search-backward (concat "^\\(" ruby-indent-beg-re "\\)\\_>") nil 'move) | 861 | ;; We can stop, then. |
| 863 | (beginning-of-line))) | 862 | (beginning-of-line))))) |
| 864 | 863 | ||
| 865 | (defun ruby-move-to-block (n) | 864 | (defun ruby-move-to-block (n) |
| 866 | "Move to the beginning (N < 0) or the end (N > 0) of the current block | 865 | "Move to the beginning (N < 0) or the end (N > 0) of the current block |
| @@ -1171,8 +1170,6 @@ It will be properly highlighted even when the call omits parens.")) | |||
| 1171 | (ruby-syntax-enclosing-percent-literal end) | 1170 | (ruby-syntax-enclosing-percent-literal end) |
| 1172 | (funcall | 1171 | (funcall |
| 1173 | (syntax-propertize-rules | 1172 | (syntax-propertize-rules |
| 1174 | ;; #{ }, #$hoge, #@foo are not comments. | ||
| 1175 | ("\\(#\\)[{$@]" (1 ".")) | ||
| 1176 | ;; $' $" $` .... are variables. | 1173 | ;; $' $" $` .... are variables. |
| 1177 | ;; ?' ?" ?` are ascii codes. | 1174 | ;; ?' ?" ?` are ascii codes. |
| 1178 | ("\\([?$]\\)[#\"'`]" | 1175 | ("\\([?$]\\)[#\"'`]" |
| @@ -1304,8 +1301,7 @@ This should only be called after matching against `ruby-here-doc-end-re'." | |||
| 1304 | (concat "-?\\([\"']\\|\\)" contents "\\1")))))) | 1301 | (concat "-?\\([\"']\\|\\)" contents "\\1")))))) |
| 1305 | 1302 | ||
| 1306 | (defconst ruby-font-lock-syntactic-keywords | 1303 | (defconst ruby-font-lock-syntactic-keywords |
| 1307 | `( ;; #{ }, #$hoge, #@foo are not comments | 1304 | `( |
| 1308 | ("\\(#\\)[{$@]" 1 (1 . nil)) | ||
| 1309 | ;; the last $', $", $` in the respective string is not variable | 1305 | ;; the last $', $", $` in the respective string is not variable |
| 1310 | ;; the last ?', ?", ?` in the respective string is not ascii code | 1306 | ;; the last ?', ?", ?` in the respective string is not ascii code |
| 1311 | ("\\(^\\|[\[ \t\n<+\(,=]\\)\\(['\"`]\\)\\(\\\\.\\|\\2\\|[^'\"`\n\\\\]\\)*?\\\\?[?$]\\(\\2\\)" | 1307 | ("\\(^\\|[\[ \t\n<+\(,=]\\)\\(['\"`]\\)\\(\\\\.\\|\\2\\|[^'\"`\n\\\\]\\)*?\\\\?[?$]\\(\\2\\)" |
| @@ -1527,6 +1523,9 @@ See `font-lock-syntax-table'.") | |||
| 1527 | ;; variables | 1523 | ;; variables |
| 1528 | '("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\>" | 1524 | '("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\>" |
| 1529 | 2 font-lock-variable-name-face) | 1525 | 2 font-lock-variable-name-face) |
| 1526 | ;; symbols | ||
| 1527 | '("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\|@?\\(\\w\\|_\\)+\\([!?=]\\|\\b_*\\)\\|#{[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\)\\)" | ||
| 1528 | 2 font-lock-reference-face) | ||
| 1530 | ;; variables | 1529 | ;; variables |
| 1531 | '("\\(\\$\\([^a-zA-Z0-9 \n]\\|[0-9]\\)\\)\\W" | 1530 | '("\\(\\$\\([^a-zA-Z0-9 \n]\\|[0-9]\\)\\)\\W" |
| 1532 | 1 font-lock-variable-name-face) | 1531 | 1 font-lock-variable-name-face) |
| @@ -1535,12 +1534,9 @@ See `font-lock-syntax-table'.") | |||
| 1535 | ;; constants | 1534 | ;; constants |
| 1536 | '("\\(^\\|[^_]\\)\\b\\([A-Z]+\\(\\w\\|_\\)*\\)" | 1535 | '("\\(^\\|[^_]\\)\\b\\([A-Z]+\\(\\w\\|_\\)*\\)" |
| 1537 | 2 font-lock-type-face) | 1536 | 2 font-lock-type-face) |
| 1538 | ;; symbols | ||
| 1539 | '("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\|\\(\\w\\|_\\)+\\([!?=]\\|\\b_*\\)\\|#{[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\)\\)" | ||
| 1540 | 2 font-lock-reference-face) | ||
| 1541 | '("\\(^\\s *\\|[\[\{\(,]\\s *\\|\\sw\\s +\\)\\(\\(\\sw\\|_\\)+\\):[^:]" 2 font-lock-reference-face) | 1537 | '("\\(^\\s *\\|[\[\{\(,]\\s *\\|\\sw\\s +\\)\\(\\(\\sw\\|_\\)+\\):[^:]" 2 font-lock-reference-face) |
| 1542 | ;; expression expansion | 1538 | ;; expression expansion |
| 1543 | '("#\\({[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\|\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+\\)" | 1539 | '(ruby-match-expression-expansion |
| 1544 | 0 font-lock-variable-name-face t) | 1540 | 0 font-lock-variable-name-face t) |
| 1545 | ;; warn lower camel case | 1541 | ;; warn lower camel case |
| 1546 | ;'("\\<[a-z]+[a-z0-9]*[A-Z][A-Za-z0-9]*\\([!?]?\\|\\>\\)" | 1542 | ;'("\\<[a-z]+[a-z0-9]*[A-Z][A-Za-z0-9]*\\([!?]?\\|\\>\\)" |
| @@ -1548,6 +1544,10 @@ See `font-lock-syntax-table'.") | |||
| 1548 | ) | 1544 | ) |
| 1549 | "Additional expressions to highlight in Ruby mode.") | 1545 | "Additional expressions to highlight in Ruby mode.") |
| 1550 | 1546 | ||
| 1547 | (defun ruby-match-expression-expansion (limit) | ||
| 1548 | (when (re-search-forward "[^\\]\\(\\\\\\\\\\)*\\(#\\({[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\|\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+\\)\\)" limit 'move) | ||
| 1549 | (ruby-in-ppss-context-p 'string))) | ||
| 1550 | |||
| 1551 | ;;;###autoload | 1551 | ;;;###autoload |
| 1552 | (define-derived-mode ruby-mode prog-mode "Ruby" | 1552 | (define-derived-mode ruby-mode prog-mode "Ruby" |
| 1553 | "Major mode for editing Ruby scripts. | 1553 | "Major mode for editing Ruby scripts. |