Skip to content

Commit 0e825ac

Browse files
committed
Merge pull request #73 from elixir-lang/failing-highlight-tests
Fix buggy syntax highlighting behavior involving "?"
2 parents 6ff1db2 + 9649022 commit 0e825ac

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

elixir-mode.el

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@
213213
"For use with operators."
214214
:group 'font-lock-faces)
215215

216+
(defvar elixir-negation-face 'elixir-negation-face)
217+
(defface elixir-negation-face
218+
'((((class color) (min-colors 88) (background light))
219+
:foreground "#ff4500")
220+
(((class color) (background dark))
221+
(:foreground "#ff4500"))
222+
(t nil))
223+
"For use with escape characters."
224+
:group 'font-lock-faces)
225+
216226
(eval-when-compile
217227
(defconst elixir-rx-constituents
218228
`(
@@ -285,7 +295,7 @@
285295
(one-or-more (any "a-z" "A-Z" "0-9" "_"))
286296
(and "\"" (one-or-more (not (any "\""))) "\"")
287297
(and "'" (one-or-more (not (any "'"))) "'"))))
288-
(code-point . ,(rx "?" anything))))
298+
(code-point . ,(rx "?" (zero-or-one anything)))))
289299

290300
(defmacro elixir-rx (&rest sexps)
291301
(let ((rx-constituents (append elixir-rx-constituents rx-constituents)))
@@ -366,7 +376,11 @@
366376

367377
;; Atoms and singleton-like words like true/false/nil.
368378
(,(elixir-rx (group (or atoms bool-and-nil)))
369-
1 font-lock-reference-face)))
379+
1 font-lock-reference-face)
380+
381+
;; Code points
382+
(,(elixir-rx (group code-point))
383+
1 elixir-negation-face)))
370384

371385
(defun elixir-mode-cygwin-path (expanded-file-name)
372386
"Elixir mode get Cygwin absolute path name.
@@ -536,8 +550,6 @@ Argument END End of the region."
536550
(set (make-local-variable 'comment-use-syntax) t)
537551
(set (make-local-variable 'tab-width) elixir-basic-offset)
538552
(set (make-local-variable 'imenu-generic-expression) elixir-imenu-generic-expression)
539-
(if (boundp 'syntax-propertize-function)
540-
(set (make-local-variable 'syntax-propertize-function) 'elixir-syntax-propertize))
541553
(smie-setup elixir-smie-grammar 'verbose-elixir-smie-rules ; 'elixir-smie-rules
542554
:forward-token 'elixir-smie-forward-token
543555
:backward-token 'elixir-smie-backward-token))

elixir-smie.el

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,6 @@
3434
table)
3535
"Elixir mode syntax table.")
3636

37-
(defun elixir-syntax-propertize (start end)
38-
(save-excursion
39-
(goto-char start)
40-
;; The ? character on its own is supposed to escape whatever comes
41-
;; after it (including any escaped chars. Examples: ?\# and ?".
42-
(while (search-forward "?" end t)
43-
(let ((start (1- (point))))
44-
(unless (or (= (char-syntax (char-before (- (point) 1))) ?w)
45-
(= (char-syntax (char-before (- (point) 1))) ?_))
46-
(put-text-property (1- (point))
47-
(point)
48-
'syntax-table
49-
'(?|))
50-
(when (= (char-after) ?\\)
51-
(forward-char)
52-
(put-text-property (1- (point))
53-
(point)
54-
'syntax-table
55-
'(?\s)))
56-
(forward-char)
57-
(put-text-property (1- (point))
58-
(point)
59-
'syntax-table
60-
'(?|))
61-
(put-text-property start (point) 'font-lock-face 'font-lock-string-face))))))
62-
6337
(defmacro elixir-smie-debug (message &rest format-args)
6438
`(progn
6539
(when elixir-smie-verbose-p

test/elixir-mode-font-tests.el

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,29 @@ buffer."
4646
(should (eq (elixir-test-face-at 41) 'font-lock-type-face))
4747
(should (eq (elixir-test-face-at 52) 'font-lock-type-face))
4848
(should (eq (elixir-test-face-at 53) 'font-lock-type-face))))
49+
50+
(ert-deftest elixir-mode-syntax-table/fontify-regex-with-quote ()
51+
"https://github.com/elixir-lang/emacs-elixir/issues/23"
52+
:tags '(fontification syntax-table)
53+
:expected-result :failed
54+
(elixir-test-with-temp-buffer
55+
"~r/\"/
56+
x = 15"
57+
(should (eq (elixir-test-face-at 7) 'font-lock-variable-name-face))))
58+
59+
(ert-deftest elixir-mode-syntax-table/fontify-regex-with-question/1 ()
60+
"https://github.com/elixir-lang/emacs-elixir/issues/36"
61+
:tags '(fontification syntax-table)
62+
(elixir-test-with-temp-buffer
63+
"~r/^matt: (?<ct>\d+)$/mg
64+
x = 15"
65+
(should (eq (elixir-test-face-at 4) 'font-lock-string-face))
66+
(should (eq (elixir-test-face-at 25) 'font-lock-variable-name-face))))
67+
68+
(ert-deftest elixir-mode-syntax-table/fontify-regex-with-question/2 ()
69+
"https://github.com/elixir-lang/emacs-elixir/issues/29"
70+
:tags '(fontification syntax-table)
71+
(elixir-test-with-temp-buffer
72+
"a = \"\" <> \"?\"
73+
x = 15"
74+
(should (eq (elixir-test-face-at 15) 'font-lock-variable-name-face))))

0 commit comments

Comments
 (0)