Skip to content

Commit 877310a

Browse files
committed
Fontify sigil contents with font-lock-string-face
1 parent 43a0905 commit 877310a

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

elixir-mode.el

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,33 @@ for the Elixir programming language."
305305
(,(elixir-rx (group sigils))
306306
1 font-lock-builtin-face)
307307

308+
;; Sigil patterns. Elixir has support for eight different sigil delimiters.
309+
;; This isn't a very DRY approach here but it gets the job done.
310+
(,(elixir-rx sigils
311+
(and "/" (group (one-or-more (not (any "/")))) "/"))
312+
1 font-lock-string-face)
313+
(,(elixir-rx sigils
314+
(and "[" (group (one-or-more (not (any "]")))) "]"))
315+
1 font-lock-string-face)
316+
(,(elixir-rx sigils
317+
(and "{" (group (one-or-more (not (any "}")))) "}"))
318+
1 font-lock-string-face)
319+
(,(elixir-rx sigils
320+
(and "(" (group (one-or-more (not (any ")")))) ")"))
321+
1 font-lock-string-face)
322+
(,(elixir-rx sigils
323+
(and "|" (group (one-or-more (not (any "|")))) "|"))
324+
1 font-lock-string-face)
325+
(,(elixir-rx sigils
326+
(and "\"" (group (one-or-more (not (any "\"")))) "\""))
327+
1 font-lock-string-face)
328+
(,(elixir-rx sigils
329+
(and "'" (group (one-or-more (not (any "'")))) "'"))
330+
1 font-lock-string-face)
331+
(,(elixir-rx sigils
332+
(and "<" (group (one-or-more (not (any ">")))) ">"))
333+
1 font-lock-string-face)
334+
308335
;; Regex patterns. Elixir has support for eight different regex delimiters.
309336
;; This isn't a very DRY approach here but it gets the job done.
310337
(,(elixir-rx "~r"
@@ -387,7 +414,7 @@ Argument FILE-NAME ."
387414
(defun elixir-quoted--initialize-buffer (quoted)
388415
(pop-to-buffer elixir-quoted--buffer-name)
389416
(setq buffer-undo-list nil) ; Get rid of undo information from
390-
; previous expansions
417+
; previous expansions
391418
(let ((inhibit-read-only t)
392419
(buffer-undo-list t)) ; Ignore undo information
393420
(erase-buffer)

test/elixir-mode-font-test.el

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ buffer."
2828
;; no face for regex delimiters
2929
(should (eq (elixir-test-face-at 15) nil))))
3030

31+
(ert-deftest elixir-mode-syntax-table/sigils ()
32+
:tags '(fontification syntax-table)
33+
(elixir-test-with-temp-buffer
34+
"asdfg = ~s{Capitalized noncapitalized}"
35+
(should (eq (elixir-test-face-at 1) 'font-lock-variable-name-face))
36+
(should (eq (elixir-test-face-at 9) 'elixir-attribute-face))
37+
(should (eq (elixir-test-face-at 12) 'font-lock-string-face))
38+
(should (eq (elixir-test-face-at 26) 'font-lock-string-face))
39+
;; no face for regex delimiters
40+
(should (eq (elixir-test-face-at 38) nil))))
41+
3142
(ert-deftest elixir-mode-syntax-table/fontify-modules-and-types ()
3243
:tags '(fontification syntax-table)
3344
(elixir-test-with-temp-buffer

0 commit comments

Comments
 (0)