Skip to content

Commit cdb70b1

Browse files
committed
Adjustments to font-locking based on @non-Jedi's valuable comments
Change-Id: Ifbc57655cb7bbe397a8d34796be70a0bef919e7c
1 parent 123155d commit cdb70b1

File tree

4 files changed

+97
-91
lines changed

4 files changed

+97
-91
lines changed

julia-ts-mode.el

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,17 @@ Otherwise, the indentation is:
122122
'((t :inherit font-lock-constant-face))
123123
"Face for quoted Julia symbols in `julia-ts-mode', e.g. :foo.")
124124

125+
(defface julia-ts-keyword-argument-face
126+
'((t :inherit font-lock-constant-face))
127+
"Face for keyword argument names in `julia-ts-mode'.")
128+
125129
(defface julia-ts-interpolation-expression-face
126130
'((t :inherit font-lock-constant-face))
127-
"Face for interpolation expressions in `julia-ts-mode', e.g. :foo.")
131+
"Face for interpolation expressions in `julia-ts-mode', e.g. $foo.")
128132

129133
(defface julia-ts-string-interpolation-face
130134
'((t :inherit font-lock-constant-face :weight bold))
131-
"Face for string interpolations in `julia-ts-mode', e.g. :foo.")
135+
"Face for string interpolations in `julia-ts-mode', e.g. \"$foo\".")
132136

133137
(defvar julia-ts--keywords
134138
'("baremodule" "begin" "catch" "const" "do" "else" "elseif" "end" "export"
@@ -140,7 +144,7 @@ Otherwise, the indentation is:
140144
(treesit-font-lock-rules
141145
:language 'julia
142146
:feature 'assignment
143-
`((assignment (identifier) @font-lock-variable-name-face (_))
147+
`((assignment :anchor [(identifier) (operator)] @font-lock-variable-name-face)
144148
(assignment
145149
:anchor
146150
(field_expression
@@ -156,15 +160,15 @@ Otherwise, the indentation is:
156160
((let_statement _ @comma :anchor (identifier) @font-lock-variable-name-face)
157161
(:equal "," @comma))
158162
(let_binding :anchor (identifier) @font-lock-variable-name-face)
159-
(global_statement (identifier) @font-lock-variable-name-face))
163+
(global_statement (identifier) @font-lock-variable-name-face)
164+
(named_argument (identifier) @julia-ts-keyword-argument-face (operator)))
160165

161166
:language 'julia
162167
:feature 'constant
163-
`((named_argument (identifier) @julia-ts-quoted-symbol-face (operator))
164-
((identifier) @font-lock-builtin-face
168+
`(((identifier) @font-lock-constant-face
165169
(:match
166-
"^\\(:?NaN\\|NaN16\\|NaN32\\|NaN64\\|Inf\\|Inf16\\|Inf32\\|Inf64\\|nothing\\|missing\\|undef\\)$"
167-
@font-lock-builtin-face)))
170+
"^\\(NaN\\|NaN16\\|NaN32\\|NaN64\\|Inf\\|Inf16\\|Inf32\\|Inf64\\|nothing\\|missing\\|undef\\)$"
171+
@font-lock-constant-face)))
168172

169173
:language 'julia
170174
:feature 'comment
@@ -225,6 +229,11 @@ Otherwise, the indentation is:
225229
(assignment
226230
:anchor
227231
(call_expression [(identifier) (operator)] @font-lock-function-name-face))
232+
(assignment
233+
:anchor
234+
(call_expression
235+
(parenthesized_expression
236+
[(identifier) (operator)] @font-lock-function-name-face)))
228237
(assignment
229238
:anchor
230239
(call_expression
@@ -239,7 +248,10 @@ Otherwise, the indentation is:
239248
(where_expression
240249
(call_expression
241250
(field_expression
242-
value: (identifier) "." (identifier) @font-lock-function-name-face)))))
251+
value: (identifier) "." (identifier) @font-lock-function-name-face))))
252+
(assignment
253+
:anchor
254+
(binary_expression _ (operator) @font-lock-function-name-face)))
243255

244256
:language 'julia
245257
:feature 'error
@@ -270,24 +282,24 @@ Otherwise, the indentation is:
270282

271283
:language 'julia
272284
:feature 'operator
273-
`((adjoint_expression "'" @font-lock-type-face)
274-
(let_binding (operator) @font-lock-type-face)
275-
((for_binding (operator) @font-lock-type-face)
276-
(:match "^\\[=∈\\]$" @font-lock-type-face))
277-
(arrow_function_expression "->" @font-lock-type-face)
278-
(operator) @font-lock-type-face
279-
(splat_expression "..." @font-lock-type-face)
280-
(ternary_expression ["?" ":"] @font-lock-type-face)
281-
(["." "::"] @font-lock-type-face))
285+
`((adjoint_expression "'" @font-lock-keyword-face)
286+
(let_binding (operator) @font-lock-keyword-face)
287+
((for_binding (operator) @font-lock-keyword-face)
288+
(:match "^\\[=∈\\]$" @font-lock-keyword-face))
289+
(arrow_function_expression "->" @font-lock-keyword-face)
290+
(operator) @font-lock-keyword-face
291+
(splat_expression "..." @font-lock-keyword-face)
292+
(ternary_expression ["?" ":"] @font-lock-keyword-face)
293+
(["." "::"] @font-lock-keyword-face))
282294

283295
:language 'julia
284296
:feature 'interpolation
285297
:override 'keep
286298
`((interpolation_expression
287-
"$" @julia-ts-interpolation-expression-face
299+
"$" @julia-ts-interpolation-expression-face)
300+
(interpolation_expression
288301
(identifier) @default)
289302
(interpolation_expression
290-
"$" @julia-ts-interpolation-expression-face
291303
(parenthesized_expression
292304
"(" @julia-ts-interpolation-expression-face
293305
_ @default
@@ -333,13 +345,7 @@ Otherwise, the indentation is:
333345
(curly_expression "{" (identifier) @font-lock-type-face))
334346
(where_expression
335347
"where"
336-
(curly_expression "{" (binary_expression (identifier) @font-lock-type-face))))
337-
338-
:language 'julia
339-
:feature 'keyword
340-
:override t
341-
'((((identifier) @font-lock-keyword-face)
342-
(:equal "new" @font-lock-keyword-face))))
348+
(curly_expression "{" (binary_expression (identifier) @font-lock-type-face)))))
343349

344350
"Tree-sitter font-lock settings for `julia-ts-mode'.")
345351

test/ArgTools.jl.faceup

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This restriction may be relaxed in the future, which would not break any working
3232
"""»
3333

3434
«k:if» VERSION ≥ «s:v"1.5"»
35-
«f:open_nolock»(args...; kws...) = open(args...; kws..., «:julia-ts-quoted-symbol-face:lock»=«c:false»)
35+
«f:open_nolock»(args...; kws...) = open(args...; kws..., «:julia-ts-keyword-argument-face:lock»=«c:false»)
3636
«k:else»
3737
«f:open_nolock»(args...; kws...) = open(args...; kws...)
3838
«k:end»
@@ -100,30 +100,30 @@ temporary path generated when `arg` is `nothing`.
100100
»«:julia-ts-string-interpolation-face:$(»«D:nolock_docstring»«:julia-ts-string-interpolation-face:)»«s:
101101
"""»
102102
«k:function» «f:arg_write»(f::«t:Function», arg::«t:AbstractString»)
103-
«k:try» open_nolock(f, arg, «:julia-ts-quoted-symbol-face:write»=«c:true»)
103+
«k:try» open_nolock(f, arg, «:julia-ts-keyword-argument-face:write»=«c:true»)
104104
«k:catch»
105-
rm(arg, «:julia-ts-quoted-symbol-face:force»=«c:true»)
105+
rm(arg, «:julia-ts-keyword-argument-face:force»=«c:true»)
106106
rethrow()
107107
«k:end»
108108
«k:return» arg
109109
«k:end»
110110

111111
«k:function» «f:arg_write»(f::«t:Function», arg::«t:AbstractCmd»)
112-
open(f, arg, «:julia-ts-quoted-symbol-face:write»=«c:true»)
112+
open(f, arg, «:julia-ts-keyword-argument-face:write»=«c:true»)
113113
«k:return» arg
114114
«k:end»
115115

116116
«k:function» «f:arg_write»(f::«t:Function», arg::«t:Nothing»)
117117
«:julia-ts-macro-face:@static» «k:if» VERSION ≥ «s:v"1.5"»
118118
«v:file» = tempname()
119-
«v:io» = open_nolock(file, «:julia-ts-quoted-symbol-face:write»=«c:true»)
119+
«v:io» = open_nolock(file, «:julia-ts-keyword-argument-face:write»=«c:true»)
120120
«k:else»
121121
«v:file», «v:io» = mktemp()
122122
«k:end»
123123
«k:try» f(io)
124124
«k:catch»
125125
close(io)
126-
rm(file, «:julia-ts-quoted-symbol-face:force»=«c:true»)
126+
rm(file, «:julia-ts-keyword-argument-face:force»=«c:true»)
127127
rethrow()
128128
«k:end»
129129
close(io)
@@ -168,7 +168,7 @@ but was empty, it will be emptied; if it did not exist it will be deleted.
168168
"""»
169169
«k:function» «f:arg_mkdir»(f::«t:Function», arg::«t:Union»{«t:AbstractString», «t:Nothing»})
170170
«v:existed» = «c:false»
171-
«k:if» arg === «b:nothing»
171+
«k:if» arg === «c:nothing»
172172
«v:arg» = mktempdir()
173173
«k:else»
174174
«v:st» = stat(arg)
@@ -188,11 +188,11 @@ but was empty, it will be emptied; if it did not exist it will be deleted.
188188
«k:for» name «k:in» readdir(arg)
189189
«v:path» = joinpath(arg, name)
190190
prepare_for_deletion(path)
191-
rm(path, «:julia-ts-quoted-symbol-face:force»=«c:true», «:julia-ts-quoted-symbol-face:recursive»=«c:true»)
191+
rm(path, «:julia-ts-keyword-argument-face:force»=«c:true», «:julia-ts-keyword-argument-face:recursive»=«c:true»)
192192
«k:end»
193193
«k:else»
194194
prepare_for_deletion(arg)
195-
rm(arg, «:julia-ts-quoted-symbol-face:force»=«c:true», «:julia-ts-quoted-symbol-face:recursive»=«c:true»)
195+
rm(arg, «:julia-ts-keyword-argument-face:force»=«c:true», «:julia-ts-keyword-argument-face:recursive»=«c:true»)
196196
«k:end»
197197
rethrow()
198198
«k:end»
@@ -213,8 +213,8 @@ but was empty, it will be emptied; if it did not exist it will be deleted.
213213
String => path -> f -> f(path)
214214
Cmd => path -> f -> f(«s:`tee »«:julia-ts-string-interpolation-face:$»«D:path»«s:`»)
215215
CmdRedirect => path -> f -> f(pipeline(«s:`cat`», path))
216-
IOStream => path -> f -> open(f, path, «:julia-ts-quoted-symbol-face:write»=«c:true»)
217-
Process => path -> f -> open(f, pipeline(«s:`cat`», path), «:julia-ts-quoted-symbol-face:write»=«c:true»)
216+
IOStream => path -> f -> open(f, path, «:julia-ts-keyword-argument-face:write»=«c:true»)
217+
Process => path -> f -> open(f, pipeline(«s:`cat`», path), «:julia-ts-keyword-argument-face:write»=«c:true»)
218218
]
219219

220220
«:julia-ts-macro-face:@assert» all(t <: ArgRead «k:for» t «k:in» map(first, ARG_READERS))
@@ -300,7 +300,7 @@ the path is not an argument to the do block in this form.
300300
«v:path» = tempname()
301301
«k:try» body(path, writer(path))
302302
«k:finally»
303-
rm(path, «:julia-ts-quoted-symbol-face:force»=«c:true»)
303+
rm(path, «:julia-ts-keyword-argument-face:force»=«c:true»)
304304
«k:end»
305305
«k:end»
306306
«k:end»

0 commit comments

Comments
 (0)