Skip to content

Commit 72370db

Browse files
committed
Fix highlighting for macros prefixed by "!"
Closes #201. Checked other regexes for similar issues involving "!" and did not discover any of significance. The Julia manual specifically calls out "!" as being special in this way and no other symbols, so just including "!" as a special-case in regexes is sufficient.
1 parent 7a8c868 commit 72370db

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

julia-mode-tests.el

+7
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,13 @@ var = func(begin
768768
(julia--should-font-lock string 22 nil) ; =
769769
))
770770

771+
(ert-deftest julia--test-!-font-lock ()
772+
(let ((string "!@macro foo()"))
773+
(julia--should-font-lock string 1 nil)
774+
(julia--should-font-lock string 2 'julia-macro-face)
775+
(julia--should-font-lock string 7 'julia-macro-face)
776+
(julia--should-font-lock string 8 nil)))
777+
771778
;;; Movement
772779
(ert-deftest julia--test-beginning-of-defun-assn-1 ()
773780
"Point moves to beginning of single-line assignment function."

julia-mode.el

+8-2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ partial match for LaTeX completion, or `nil' when not applicable."
115115
(let ((table (make-syntax-table)))
116116
(modify-syntax-entry ?_ "_" table)
117117
(modify-syntax-entry ?@ "_" table)
118+
119+
;; "!" can be part of both operators (!=) and variable names (append!). Here, we treat
120+
;; it as being part of a variable name. Care must be taken to account for the special
121+
;; case where "!" prefixes a variable name and acts as an operator (e.g. !any(...)).
118122
(modify-syntax-entry ?! "_" table)
119123
(modify-syntax-entry ?# "< 14" table) ; # single-line and multiline start
120124
(modify-syntax-entry ?= ". 23bn" table)
@@ -267,6 +271,8 @@ partial match for LaTeX completion, or `nil' when not applicable."
267271
;; The function name itself
268272
(group (1+ (or word (syntax symbol))))))
269273

274+
;; TODO: function definitions of form "x + y = 5" or "!x = true" not currently highlighted
275+
270276
;; functions of form "f(x) = nothing"
271277
(defconst julia-function-assignment-regex
272278
(rx line-start (* (or space "@inline" "@noinline")) symbol-start
@@ -302,7 +308,7 @@ partial match for LaTeX completion, or `nil' when not applicable."
302308
(rx "<:" (0+ space) (group (1+ (or word (syntax symbol)))) (0+ space) (or "\n" "{" "}" "end" ",")))
303309

304310
(defconst julia-macro-regex
305-
(rx symbol-start (group "@" (1+ (or word (syntax symbol))))))
311+
(rx symbol-start (0+ ?!) (group "@" (1+ (or word (syntax symbol))))))
306312

307313
(defconst julia-keyword-regex
308314
(regexp-opt
@@ -329,7 +335,7 @@ partial match for LaTeX completion, or `nil' when not applicable."
329335
;; highlighted as a keyword.
330336
(list julia-quoted-symbol-regex 1 ''julia-quoted-symbol-face)
331337
(cons julia-keyword-regex 'font-lock-keyword-face)
332-
(cons julia-macro-regex ''julia-macro-face)
338+
(list julia-macro-regex 1 ''julia-macro-face)
333339
(cons
334340
(regexp-opt
335341
;; constants defined in Core plus true/false

0 commit comments

Comments
 (0)