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.
This commit is contained in:
parent
9b16bc2a01
commit
1b9d6163b0
2 changed files with 17 additions and 22 deletions
|
@ -431,17 +431,11 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
|
||||||
(not (or (bolp)
|
(not (or (bolp)
|
||||||
(memq (char-before) '(?\[ ?\())
|
(memq (char-before) '(?\[ ?\())
|
||||||
(and (memq (char-before)
|
(and (memq (char-before)
|
||||||
'(?\; ?- ?+ ?* ?/ ?: ?. ?, ?\\ ?& ?> ?< ?% ?~ ?^))
|
'(?\; ?- ?+ ?* ?/ ?: ?. ?, ?\\ ?& ?> ?< ?% ?~ ?^ ?= ??))
|
||||||
;; Not a binary operator symbol.
|
;; Not a binary operator symbol like :+ or :[]=.
|
||||||
(not (eq (char-before (1- (point))) ?:))
|
;; Or a (method or symbol) name ending with ?.
|
||||||
;; Not the end of a regexp or a percent literal.
|
;; Or the end of a regexp or a percent literal.
|
||||||
(not (memq (car (syntax-after (1- (point)))) '(7 15))))
|
(not (memq (car (syntax-after (1- (point)))) '(3 7 15))))
|
||||||
(and (eq (char-before) ?\?)
|
|
||||||
(equal (save-excursion (ruby-smie--backward-token)) "?"))
|
|
||||||
(and (eq (char-before) ?=)
|
|
||||||
;; Not a symbol :==, :!=, or a foo= method.
|
|
||||||
(string-match "\\`\\s." (save-excursion
|
|
||||||
(ruby-smie--backward-token))))
|
|
||||||
(and (eq (char-before) ?|)
|
(and (eq (char-before) ?|)
|
||||||
(member (save-excursion (ruby-smie--backward-token))
|
(member (save-excursion (ruby-smie--backward-token))
|
||||||
'("|" "||")))
|
'("|" "||")))
|
||||||
|
@ -485,7 +479,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
|
||||||
"else" "elsif" "do" "end" "and")
|
"else" "elsif" "do" "end" "and")
|
||||||
'symbols))))
|
'symbols))))
|
||||||
(memq (car (syntax-after pos)) '(7 15))
|
(memq (car (syntax-after pos)) '(7 15))
|
||||||
(looking-at "[([]\\|[-+!~]\\sw\\|:\\(?:\\sw\\|\\s.\\)")))))
|
(looking-at "[([]\\|[-+!~:]\\(?:\\sw\\|\\s_\\)")))))
|
||||||
|
|
||||||
(defun ruby-smie--at-dot-call ()
|
(defun ruby-smie--at-dot-call ()
|
||||||
(and (eq ?w (char-syntax (following-char)))
|
(and (eq ?w (char-syntax (following-char)))
|
||||||
|
@ -511,8 +505,6 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(ruby-smie--args-separator-p (prog1 (point) (goto-char pos)))))
|
(ruby-smie--args-separator-p (prog1 (point) (goto-char pos)))))
|
||||||
" @ ")
|
" @ ")
|
||||||
((looking-at ":\\s.+")
|
|
||||||
(goto-char (match-end 0)) (match-string 0)) ;bug#15208.
|
|
||||||
((looking-at "\\s\"") "") ;A string.
|
((looking-at "\\s\"") "") ;A string.
|
||||||
(t
|
(t
|
||||||
(let ((dot (ruby-smie--at-dot-call))
|
(let ((dot (ruby-smie--at-dot-call))
|
||||||
|
@ -562,8 +554,6 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
|
||||||
(dot (ruby-smie--at-dot-call)))
|
(dot (ruby-smie--at-dot-call)))
|
||||||
(when dot
|
(when dot
|
||||||
(setq tok (concat "." tok)))
|
(setq tok (concat "." tok)))
|
||||||
(when (and (eq ?: (char-before)) (string-match "\\`\\s." tok))
|
|
||||||
(forward-char -1) (setq tok (concat ":" tok))) ;; bug#15208.
|
|
||||||
(cond
|
(cond
|
||||||
((member tok '("unless" "if" "while" "until"))
|
((member tok '("unless" "if" "while" "until"))
|
||||||
(if (ruby-smie--bosp)
|
(if (ruby-smie--bosp)
|
||||||
|
@ -1861,11 +1851,13 @@ It will be properly highlighted even when the call omits parens.")
|
||||||
(ignore
|
(ignore
|
||||||
(goto-char (match-end 1)))
|
(goto-char (match-end 1)))
|
||||||
(string-to-syntax "\\"))))
|
(string-to-syntax "\\"))))
|
||||||
;; Part of symbol when at the end of a method name.
|
;; Symbols with special characters.
|
||||||
|
("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\)\\)"
|
||||||
|
(3 (string-to-syntax "_")))
|
||||||
|
;; Part of method name when at the end of it.
|
||||||
("[!?]"
|
("[!?]"
|
||||||
(0 (unless (save-excursion
|
(0 (unless (save-excursion
|
||||||
(or (nth 8 (syntax-ppss (match-beginning 0)))
|
(or (nth 8 (syntax-ppss (match-beginning 0)))
|
||||||
(eq (char-before) ?:)
|
|
||||||
(let (parse-sexp-lookup-properties)
|
(let (parse-sexp-lookup-properties)
|
||||||
(zerop (skip-syntax-backward "w_")))
|
(zerop (skip-syntax-backward "w_")))
|
||||||
(memq (preceding-char) '(?@ ?$))))
|
(memq (preceding-char) '(?@ ?$))))
|
||||||
|
@ -2183,7 +2175,7 @@ See `font-lock-syntax-table'.")
|
||||||
;; Keywords that evaluate to certain values.
|
;; Keywords that evaluate to certain values.
|
||||||
("\\_<__\\(?:LINE\\|ENCODING\\|FILE\\)__\\_>"
|
("\\_<__\\(?:LINE\\|ENCODING\\|FILE\\)__\\_>"
|
||||||
(0 font-lock-builtin-face))
|
(0 font-lock-builtin-face))
|
||||||
;; Symbols with symbol characters.
|
;; Symbols.
|
||||||
("\\(^\\|[^:]\\)\\(:@?\\(?:\\w\\|_\\)+\\)\\([!?=]\\)?"
|
("\\(^\\|[^:]\\)\\(:@?\\(?:\\w\\|_\\)+\\)\\([!?=]\\)?"
|
||||||
(2 font-lock-constant-face)
|
(2 font-lock-constant-face)
|
||||||
(3 (unless (and (eq (char-before (match-end 3)) ?=)
|
(3 (unless (and (eq (char-before (match-end 3)) ?=)
|
||||||
|
@ -2191,9 +2183,6 @@ See `font-lock-syntax-table'.")
|
||||||
;; bug#18644
|
;; bug#18644
|
||||||
font-lock-constant-face)
|
font-lock-constant-face)
|
||||||
nil t))
|
nil t))
|
||||||
;; Symbols with special characters.
|
|
||||||
("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\)\\)"
|
|
||||||
2 font-lock-constant-face)
|
|
||||||
;; Special globals.
|
;; Special globals.
|
||||||
(,(concat "\\$\\(?:[:\"!@;,/\\._><\\$?~=*&`'+0-9]\\|-[0adFiIlpvw]\\|"
|
(,(concat "\\$\\(?:[:\"!@;,/\\._><\\$?~=*&`'+0-9]\\|-[0adFiIlpvw]\\|"
|
||||||
(regexp-opt '("LOAD_PATH" "LOADED_FEATURES" "PROGRAM_NAME"
|
(regexp-opt '("LOAD_PATH" "LOADED_FEATURES" "PROGRAM_NAME"
|
||||||
|
|
|
@ -168,6 +168,12 @@ def test2 (arg)
|
||||||
something
|
something
|
||||||
end
|
end
|
||||||
|
|
||||||
|
qux :+,
|
||||||
|
bar,
|
||||||
|
:[]=,
|
||||||
|
bar,
|
||||||
|
:a
|
||||||
|
|
||||||
# Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
|
# Example from http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html
|
||||||
d = 4 + 5 + # no '\' needed
|
d = 4 + 5 + # no '\' needed
|
||||||
6 + 7
|
6 + 7
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue