Skip to content

Commit 0de4e3e

Browse files
committed
Merge pull request #87 from elixir-lang/heredoc
Add syntax highlighting for heredocs & failing tests for indentation.
2 parents c9d492d + 99c54ff commit 0de4e3e

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

elixir-mode.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@
226226
(eval-when-compile
227227
(defconst elixir-rx-constituents
228228
`(
229+
;; Match `@doc' or `@moduledoc' syntax, with or without triple quotes.
230+
(heredocs . ,(rx symbol-start
231+
(or "@doc" "@moduledoc" "~s")
232+
symbol-end))
229233
(keywords . ,(rx symbol-start
230234
(or "->" "bc" "lc" "in" "inbits" "inlist" "quote"
231235
"unquote" "unquote_splicing" "var" "do" "after" "for"
@@ -328,6 +332,10 @@
328332
(group module-names))
329333
1 font-lock-type-face)
330334

335+
;; Heredoc
336+
(,(elixir-rx (group heredocs))
337+
1 font-lock-builtin-face)
338+
331339
;; Keywords
332340
(,(elixir-rx (group keywords))
333341
1 font-lock-keyword-face)

elixir-smie.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
(modify-syntax-entry ?\[ "(]" table)
3131
(modify-syntax-entry ?\] ")[" table)
3232
(modify-syntax-entry ?\: "'" table)
33-
(modify-syntax-entry ?\@ "'" table)
33+
(modify-syntax-entry ?@ "_" table)
3434
table)
3535
"Elixir mode syntax table.")
3636

test/elixir-mode-font-tests.el

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,28 @@ end"
9999
end"
100100
(should (eq (elixir-test-face-at 5) 'font-lock-function-name-face))
101101
(should (eq (elixir-test-face-at 8) 'font-lock-function-name-face))))
102+
103+
(ert-deftest elixir-mode-syntax-table/fontify-heredoc/1 ()
104+
:tags '(fontification heredoc syntax-table)
105+
(elixir-test-with-temp-buffer
106+
"@doc \"\"\""
107+
(should (eq (elixir-test-face-at 1) 'font-lock-builtin-face))
108+
(should (eq (elixir-test-face-at 2) 'font-lock-builtin-face))
109+
(should (eq (elixir-test-face-at 6) 'font-lock-string-face))))
110+
111+
(ert-deftest elixir-mode-syntax-table/fontify-heredoc/2 ()
112+
:tags '(fontification heredoc syntax-table)
113+
(elixir-test-with-temp-buffer
114+
"@moduledoc \"\"\""
115+
(should (eq (elixir-test-face-at 1) 'font-lock-builtin-face))
116+
(should (eq (elixir-test-face-at 2) 'font-lock-builtin-face))
117+
(should (eq (elixir-test-face-at 12) 'font-lock-string-face))))
118+
119+
(ert-deftest elixir-mode-syntax-table/fontify-heredoc/3 ()
120+
:tags '(fontification heredoc syntax-table)
121+
(elixir-test-with-temp-buffer
122+
"~s\"\"\""
123+
(should (eq (elixir-test-face-at 1) 'font-lock-builtin-face))
124+
(should (eq (elixir-test-face-at 2) 'font-lock-builtin-face))
125+
(should (eq (elixir-test-face-at 3) 'font-lock-string-face))))
126+

test/elixir-mode-indentation-tests.el

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,28 @@ end"
437437
end
438438
end
439439
end")
440+
441+
(elixir-def-indentation-test indent-heredoc
442+
(:expected-result :failed)
443+
"
444+
defmodule Foo do
445+
@doc \"\"\"
446+
this is a heredoc string
447+
448+
\"\"\"
449+
def convert do
450+
x = 15
451+
end
452+
end
453+
"
454+
"
455+
defmodule Foo do
456+
@doc \"\"\"
457+
this is a heredoc string
458+
459+
\"\"\"
460+
def convert do
461+
x = 15
462+
end
463+
end
464+
")

0 commit comments

Comments
 (0)