Skip to content

Commit

Permalink
Merge pull request #9024 from Wilfred/highlight_symbols
Browse files Browse the repository at this point in the history
Highlighting for macro calls and quoted symbols
  • Loading branch information
JeffBezanson committed Nov 30, 2014
2 parents a2716c0 + 2886ab5 commit 90b6c54
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion contrib/julia-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@

(defvar julia-basic-offset)

(defface julia-macro-face
'((t :inherit font-lock-preprocessor-face))
"Face for Julia macro invocations."
:group 'julia-mode)

(defface julia-quoted-symbol-face
'((t :inherit font-lock-preprocessor-face))
"Face for quoted Julia symbols, e.g. :foo."
:group 'julia-mode)


;;;###autoload
(add-to-list 'auto-mode-alist '("\\.jl\\'" . julia-mode))

Expand Down Expand Up @@ -191,11 +202,22 @@ This function provides equivalent functionality, but makes no efforts to optimis
"DataType" "Symbol" "Function" "Vector" "Matrix" "Union" "Type" "Any" "Complex" "None" "String" "Ptr" "Void" "Exception" "Task" "Signed" "Unsigned" "Associative" "Dict" "IO" "IOStream" "Ranges" "Rational" "Regex" "RegexMatch" "Set" "IntSet" "Expr" "WeakRef" "Nothing" "ObjectIdDict")
'symbols))

(defconst julia-quoted-symbol-regex
;; :foo and :foo2 are valid, but :123 is not.
(rx (or whitespace "(" "[" ",")
(group ":" (or letter (syntax symbol)) (0+ (or word (syntax symbol))))))

(defconst julia-font-lock-keywords
(list
;; Ensure :: and <: aren't highlighted, so we don't confuse ::Foo with :foo.
;; (in Emacs, keywords don't overlap).
(cons (rx (or "::" "<:")) ''default)
;; Highlight quoted symbols before keywords, so :function is not
;; highlighted as a keyword.
(list julia-quoted-symbol-regex 1 ''julia-quoted-symbol-face)
(cons julia-builtin-types-regex 'font-lock-type-face)
(cons julia-keyword-regex 'font-lock-keyword-face)
(cons julia-macro-regex 'font-lock-keyword-face)
(cons julia-macro-regex ''julia-macro-face)
(cons
(julia--regexp-opt
'("true" "false" "C_NULL" "Inf" "NaN" "Inf32" "NaN32" "nothing")
Expand Down

0 comments on commit 90b6c54

Please sign in to comment.