Skip to content

Commit

Permalink
Fix highlighting for macros prefixed by "!"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
non-Jedi committed Jan 19, 2024
1 parent 7a8c868 commit 72370db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions julia-mode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,13 @@ var = func(begin
(julia--should-font-lock string 22 nil) ; =
))

(ert-deftest julia--test-!-font-lock ()
(let ((string "!@macro foo()"))
(julia--should-font-lock string 1 nil)
(julia--should-font-lock string 2 'julia-macro-face)
(julia--should-font-lock string 7 'julia-macro-face)
(julia--should-font-lock string 8 nil)))

;;; Movement
(ert-deftest julia--test-beginning-of-defun-assn-1 ()
"Point moves to beginning of single-line assignment function."
Expand Down
10 changes: 8 additions & 2 deletions julia-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ partial match for LaTeX completion, or `nil' when not applicable."
(let ((table (make-syntax-table)))
(modify-syntax-entry ?_ "_" table)
(modify-syntax-entry ?@ "_" table)

;; "!" can be part of both operators (!=) and variable names (append!). Here, we treat
;; it as being part of a variable name. Care must be taken to account for the special
;; case where "!" prefixes a variable name and acts as an operator (e.g. !any(...)).
(modify-syntax-entry ?! "_" table)
(modify-syntax-entry ?# "< 14" table) ; # single-line and multiline start
(modify-syntax-entry ?= ". 23bn" table)
Expand Down Expand Up @@ -267,6 +271,8 @@ partial match for LaTeX completion, or `nil' when not applicable."
;; The function name itself
(group (1+ (or word (syntax symbol))))))

;; TODO: function definitions of form "x + y = 5" or "!x = true" not currently highlighted

;; functions of form "f(x) = nothing"
(defconst julia-function-assignment-regex
(rx line-start (* (or space "@inline" "@noinline")) symbol-start
Expand Down Expand Up @@ -302,7 +308,7 @@ partial match for LaTeX completion, or `nil' when not applicable."
(rx "<:" (0+ space) (group (1+ (or word (syntax symbol)))) (0+ space) (or "\n" "{" "}" "end" ",")))

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

(defconst julia-keyword-regex
(regexp-opt
Expand All @@ -329,7 +335,7 @@ partial match for LaTeX completion, or `nil' when not applicable."
;; highlighted as a keyword.
(list julia-quoted-symbol-regex 1 ''julia-quoted-symbol-face)
(cons julia-keyword-regex 'font-lock-keyword-face)
(cons julia-macro-regex ''julia-macro-face)
(list julia-macro-regex 1 ''julia-macro-face)
(cons
(regexp-opt
;; constants defined in Core plus true/false
Expand Down

0 comments on commit 72370db

Please sign in to comment.