diff options
| author | Dmitry Gutov | 2016-03-09 16:43:51 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2016-03-09 17:22:56 +0200 |
| commit | 1b9d6163b023aaefd15d38ea28e968a113202402 (patch) | |
| tree | 7a1823db56e0f353388a7c25ae03a6824bfb1a88 /lisp/progmodes/ruby-mode.el | |
| parent | 9b16bc2a01a3554feb9577c507bcc874f863ad81 (diff) | |
| download | emacs-1b9d6163b023aaefd15d38ea28e968a113202402.tar.gz emacs-1b9d6163b023aaefd15d38ea28e968a113202402.zip | |
Propertize operator symbol names with symbol syntax class
* lisp/progmodes/ruby-mode.el (ruby-syntax-propertize):
Do it here.
(ruby-font-lock-keywords): Instead of handling them here. Leave
highlighting them to the "normal" matcher, because now we can.
(ruby-smie--forward-token, ruby-smie--backward-token):
Likewise, don't special-case operator symbols anymore.
(ruby-smie--args-separator-p): Simplify the regexp, match operator
names with \s_.
(ruby-smie--implicit-semi-p): Handle the special cases of ? and =
at EOL the same way: check if the character has been assigned the
symbol syntax class by syntax-propertize.
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 914703d5f1b..0c5e8fe8054 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el | |||
| @@ -431,17 +431,11 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." | |||
| 431 | (not (or (bolp) | 431 | (not (or (bolp) |
| 432 | (memq (char-before) '(?\[ ?\()) | 432 | (memq (char-before) '(?\[ ?\()) |
| 433 | (and (memq (char-before) | 433 | (and (memq (char-before) |
| 434 | '(?\; ?- ?+ ?* ?/ ?: ?. ?, ?\\ ?& ?> ?< ?% ?~ ?^)) | 434 | '(?\; ?- ?+ ?* ?/ ?: ?. ?, ?\\ ?& ?> ?< ?% ?~ ?^ ?= ??)) |
| 435 | ;; Not a binary operator symbol. | 435 | ;; Not a binary operator symbol like :+ or :[]=. |
| 436 | (not (eq (char-before (1- (point))) ?:)) | 436 | ;; Or a (method or symbol) name ending with ?. |
| 437 | ;; Not the end of a regexp or a percent literal. | 437 | ;; Or the end of a regexp or a percent literal. |
| 438 | (not (memq (car (syntax-after (1- (point)))) '(7 15)))) | 438 | (not (memq (car (syntax-after (1- (point)))) '(3 7 15)))) |
| 439 | (and (eq (char-before) ?\?) | ||
| 440 | (equal (save-excursion (ruby-smie--backward-token)) "?")) | ||
| 441 | (and (eq (char-before) ?=) | ||
| 442 | ;; Not a symbol :==, :!=, or a foo= method. | ||
| 443 | (string-match "\\`\\s." (save-excursion | ||
| 444 | (ruby-smie--backward-token)))) | ||
| 445 | (and (eq (char-before) ?|) | 439 | (and (eq (char-before) ?|) |
| 446 | (member (save-excursion (ruby-smie--backward-token)) | 440 | (member (save-excursion (ruby-smie--backward-token)) |
| 447 | '("|" "||"))) | 441 | '("|" "||"))) |
| @@ -485,7 +479,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." | |||
| 485 | "else" "elsif" "do" "end" "and") | 479 | "else" "elsif" "do" "end" "and") |
| 486 | 'symbols)))) | 480 | 'symbols)))) |
| 487 | (memq (car (syntax-after pos)) '(7 15)) | 481 | (memq (car (syntax-after pos)) '(7 15)) |
| 488 | (looking-at "[([]\\|[-+!~]\\sw\\|:\\(?:\\sw\\|\\s.\\)"))))) | 482 | (looking-at "[([]\\|[-+!~:]\\(?:\\sw\\|\\s_\\)"))))) |
| 489 | 483 | ||
| 490 | (defun ruby-smie--at-dot-call () | 484 | (defun ruby-smie--at-dot-call () |
| 491 | (and (eq ?w (char-syntax (following-char))) | 485 | (and (eq ?w (char-syntax (following-char))) |
| @@ -511,8 +505,6 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." | |||
| 511 | (save-excursion | 505 | (save-excursion |
| 512 | (ruby-smie--args-separator-p (prog1 (point) (goto-char pos))))) | 506 | (ruby-smie--args-separator-p (prog1 (point) (goto-char pos))))) |
| 513 | " @ ") | 507 | " @ ") |
| 514 | ((looking-at ":\\s.+") | ||
| 515 | (goto-char (match-end 0)) (match-string 0)) ;bug#15208. | ||
| 516 | ((looking-at "\\s\"") "") ;A string. | 508 | ((looking-at "\\s\"") "") ;A string. |
| 517 | (t | 509 | (t |
| 518 | (let ((dot (ruby-smie--at-dot-call)) | 510 | (let ((dot (ruby-smie--at-dot-call)) |
| @@ -562,8 +554,6 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'." | |||
| 562 | (dot (ruby-smie--at-dot-call))) | 554 | (dot (ruby-smie--at-dot-call))) |
| 563 | (when dot | 555 | (when dot |
| 564 | (setq tok (concat "." tok))) | 556 | (setq tok (concat "." tok))) |
| 565 | (when (and (eq ?: (char-before)) (string-match "\\`\\s." tok)) | ||
| 566 | (forward-char -1) (setq tok (concat ":" tok))) ;; bug#15208. | ||
| 567 | (cond | 557 | (cond |
| 568 | ((member tok '("unless" "if" "while" "until")) | 558 | ((member tok '("unless" "if" "while" "until")) |
| 569 | (if (ruby-smie--bosp) | 559 | (if (ruby-smie--bosp) |
| @@ -1861,11 +1851,13 @@ It will be properly highlighted even when the call omits parens.") | |||
| 1861 | (ignore | 1851 | (ignore |
| 1862 | (goto-char (match-end 1))) | 1852 | (goto-char (match-end 1))) |
| 1863 | (string-to-syntax "\\")))) | 1853 | (string-to-syntax "\\")))) |
| 1864 | ;; Part of symbol when at the end of a method name. | 1854 | ;; Symbols with special characters. |
| 1855 | ("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\)\\)" | ||
| 1856 | (3 (string-to-syntax "_"))) | ||
| 1857 | ;; Part of method name when at the end of it. | ||
| 1865 | ("[!?]" | 1858 | ("[!?]" |
| 1866 | (0 (unless (save-excursion | 1859 | (0 (unless (save-excursion |
| 1867 | (or (nth 8 (syntax-ppss (match-beginning 0))) | 1860 | (or (nth 8 (syntax-ppss (match-beginning 0))) |
| 1868 | (eq (char-before) ?:) | ||
| 1869 | (let (parse-sexp-lookup-properties) | 1861 | (let (parse-sexp-lookup-properties) |
| 1870 | (zerop (skip-syntax-backward "w_"))) | 1862 | (zerop (skip-syntax-backward "w_"))) |
| 1871 | (memq (preceding-char) '(?@ ?$)))) | 1863 | (memq (preceding-char) '(?@ ?$)))) |
| @@ -2183,7 +2175,7 @@ See `font-lock-syntax-table'.") | |||
| 2183 | ;; Keywords that evaluate to certain values. | 2175 | ;; Keywords that evaluate to certain values. |
| 2184 | ("\\_<__\\(?:LINE\\|ENCODING\\|FILE\\)__\\_>" | 2176 | ("\\_<__\\(?:LINE\\|ENCODING\\|FILE\\)__\\_>" |
| 2185 | (0 font-lock-builtin-face)) | 2177 | (0 font-lock-builtin-face)) |
| 2186 | ;; Symbols with symbol characters. | 2178 | ;; Symbols. |
| 2187 | ("\\(^\\|[^:]\\)\\(:@?\\(?:\\w\\|_\\)+\\)\\([!?=]\\)?" | 2179 | ("\\(^\\|[^:]\\)\\(:@?\\(?:\\w\\|_\\)+\\)\\([!?=]\\)?" |
| 2188 | (2 font-lock-constant-face) | 2180 | (2 font-lock-constant-face) |
| 2189 | (3 (unless (and (eq (char-before (match-end 3)) ?=) | 2181 | (3 (unless (and (eq (char-before (match-end 3)) ?=) |
| @@ -2191,9 +2183,6 @@ See `font-lock-syntax-table'.") | |||
| 2191 | ;; bug#18644 | 2183 | ;; bug#18644 |
| 2192 | font-lock-constant-face) | 2184 | font-lock-constant-face) |
| 2193 | nil t)) | 2185 | nil t)) |
| 2194 | ;; Symbols with special characters. | ||
| 2195 | ("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\)\\)" | ||
| 2196 | 2 font-lock-constant-face) | ||
| 2197 | ;; Special globals. | 2186 | ;; Special globals. |
| 2198 | (,(concat "\\$\\(?:[:\"!@;,/\\._><\\$?~=*&`'+0-9]\\|-[0adFiIlpvw]\\|" | 2187 | (,(concat "\\$\\(?:[:\"!@;,/\\._><\\$?~=*&`'+0-9]\\|-[0adFiIlpvw]\\|" |
| 2199 | (regexp-opt '("LOAD_PATH" "LOADED_FEATURES" "PROGRAM_NAME" | 2188 | (regexp-opt '("LOAD_PATH" "LOADED_FEATURES" "PROGRAM_NAME" |