Skip to content

Commit 531a2b3

Browse files
committed
Merge pull request #179 from rranelli/highlight-all-modules-equally
Modify syntax highlighting so there is no differentiating between built-in and user-defined modules.
2 parents a0ec0ee + 60047aa commit 531a2b3

File tree

2 files changed

+59
-36
lines changed

2 files changed

+59
-36
lines changed

elixir-mode.el

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -201,25 +201,6 @@ for the Elixir programming language."
201201
"defexception" "defstruct" "defimpl"
202202
"defcallback")
203203
symbol-end))
204-
(builtin-modules . ,(rx symbol-start
205-
(or "Agent" "Application" "Atom" "Base"
206-
"Behaviour" "Bitwise" "Builtin" "Code" "Dict"
207-
"EEx" "Elixir" "Enum" "ExUnit" "Exception"
208-
"File" "File.Stat" "File.Stream" "Float"
209-
"Function" "GenEvent" "GenServer" "GenTCP"
210-
"HashDict" "HashSet" "IO" "IO.ANSI"
211-
"IO.Stream" "Inspect.Algebra" "Inspect.Opts"
212-
"Integer" "Kernel" "Kernel.ParallelCompiler"
213-
"Kernel.ParallelRequire" "Kernel.SpecialForms"
214-
"Kernel.Typespec" "Keyword" "List" "Macro"
215-
"Macro.Env" "Map" "Math" "Module" "Node"
216-
"OptionParser" "OrdDict" "Path" "Port"
217-
"Process" "Protocol" "Range" "Record" "Regex"
218-
"Set" "Stream" "String" "StringIO"
219-
"Supervisor" "Supervisor.Spec" "System" "Task"
220-
"Task.Supervisor" "Tuple" "URI"
221-
"UnboundMethod" "Version")
222-
symbol-end))
223204
(builtin-namespace . ,(rx symbol-start
224205
(or "import" "require" "use" "alias")
225206
symbol-end))
@@ -229,8 +210,8 @@ for the Elixir programming language."
229210
anything
230211
symbol-end))
231212
(function-declaration . ,(rx symbol-start
232-
(or "def" "defp")
233-
symbol-end))
213+
(or "def" "defp")
214+
symbol-end))
234215
;; Match `@doc' or `@moduledoc' syntax, with or without triple quotes.
235216
(heredocs . ,(rx symbol-start
236217
(or "@doc" "@moduledoc" "~s")
@@ -259,7 +240,7 @@ for the Elixir programming language."
259240
(zero-or-more
260241
(and "."
261242
(one-or-more (any "A-Z" "_"))
262-
(zero-or-more (any "A-Z" "a-z" "_" "0-9"))))
243+
(zero-or-more (any "A-Z" "a-z" "_" "0-9"))))
263244
(optional (or "!" "?"))
264245
symbol-end))
265246
(operators1 . ,(rx symbol-start
@@ -296,12 +277,6 @@ for the Elixir programming language."
296277
;; String interpolation
297278
(elixir-match-interpolation 0 font-lock-variable-name-face t)
298279

299-
;; Module-defining & namespace builtins
300-
(,(elixir-rx (or builtin-declaration builtin-namespace)
301-
space
302-
(group module-names))
303-
1 font-lock-type-face)
304-
305280
;; Module attributes
306281
(,(elixir-rx (group (or heredocs
307282
(and "@" (1+ identifiers)))))
@@ -330,6 +305,33 @@ for the Elixir programming language."
330305
(,(elixir-rx (group sigils))
331306
1 font-lock-builtin-face)
332307

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+
333335
;; Regex patterns. Elixir has support for eight different regex delimiters.
334336
;; This isn't a very DRY approach here but it gets the job done.
335337
(,(elixir-rx "~r"
@@ -357,6 +359,10 @@ for the Elixir programming language."
357359
(and "<" (group (one-or-more (not (any ">")))) ">"))
358360
1 font-lock-string-face)
359361

362+
;; Modules
363+
(,(elixir-rx (group module-names))
364+
1 font-lock-type-face)
365+
360366
;; Atoms and singleton-like words like true/false/nil.
361367
(,(elixir-rx (group atoms))
362368
1 elixir-atom-face)
@@ -365,8 +371,8 @@ for the Elixir programming language."
365371
(,(elixir-rx (group (and (one-or-more identifiers) ":")))
366372
1 elixir-atom-face)
367373

368-
;; Built-in modules and pseudovariables
369-
(,(elixir-rx (group (or builtin-modules pseudo-var)))
374+
;; Pseudovariables
375+
(,(elixir-rx (group pseudo-var))
370376
1 font-lock-constant-face)
371377

372378
;; Code points
@@ -407,8 +413,7 @@ Argument FILE-NAME ."
407413

408414
(defun elixir-quoted--initialize-buffer (quoted)
409415
(pop-to-buffer elixir-quoted--buffer-name)
410-
(setq buffer-undo-list nil) ; Get rid of undo information from
411-
; previous expansions
416+
(setq buffer-undo-list nil) ; Get rid of undo information from previous expansions
412417
(let ((inhibit-read-only t)
413418
(buffer-undo-list t)) ; Ignore undo information
414419
(erase-buffer)

test/elixir-mode-font-test.el

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,23 @@ 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
3445
"defmodule Application.Behavior do
35-
use Application.Behaviour"
46+
use Application.Behaviour
47+
Stand.Alone.call"
3648
(should (eq (elixir-test-face-at 1) 'font-lock-keyword-face))
3749
(should (eq (elixir-test-face-at 11) 'font-lock-type-face))
3850
(should (eq (elixir-test-face-at 22) 'font-lock-type-face))
@@ -41,7 +53,11 @@ buffer."
4153
(should (eq (elixir-test-face-at 37) 'font-lock-keyword-face))
4254
(should (eq (elixir-test-face-at 41) 'font-lock-type-face))
4355
(should (eq (elixir-test-face-at 52) 'font-lock-type-face))
44-
(should (eq (elixir-test-face-at 53) 'font-lock-type-face))))
56+
(should (eq (elixir-test-face-at 53) 'font-lock-type-face))
57+
(should (eq (elixir-test-face-at 68) 'font-lock-type-face))
58+
(should (eq (elixir-test-face-at 72) 'font-lock-type-face))
59+
;; no face for function call
60+
(should (eq (elixir-test-face-at 79) nil))))
4561

4662
(ert-deftest elixir-mode-syntax-table/fontify-regex-with-quote ()
4763
"https://github.com/elixir-lang/emacs-elixir/issues/23"
@@ -125,13 +141,15 @@ end"
125141
(elixir-test-with-temp-buffer
126142
":oriole
127143
:andale
128-
:ms2pid"
144+
:ms2pid
145+
:CapitalizedAtom"
129146
(should (eq (elixir-test-face-at 3) 'elixir-atom-face))
130147
(should (eq (elixir-test-face-at 5) 'elixir-atom-face))
131148
(should (eq (elixir-test-face-at 10) 'elixir-atom-face))
132149
(should (eq (elixir-test-face-at 13) 'elixir-atom-face))
133150
(should (eq (elixir-test-face-at 18) 'elixir-atom-face))
134-
(should (eq (elixir-test-face-at 23) 'elixir-atom-face))))
151+
(should (eq (elixir-test-face-at 23) 'elixir-atom-face))
152+
(should (eq (elixir-test-face-at 26) 'elixir-atom-face))))
135153

136154
(ert-deftest elixir-mode-syntax-table/fontify-map-keys ()
137155
:tags '(fontification map syntax-table)

0 commit comments

Comments
 (0)