1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
;; fnl/alphabaster/init.fnl
;;
;; Alphabaster: A minimal colorscheme based on Tonsky's Alabaster philosophy.
;; https://tonsky.me/blog/syntax-highlighting/
;;
;; Core insight: If everything is highlighted, nothing stands out.
;; Your eye adapts and considers it a new norm.
;;
;; Only 4 semantic categories get color:
;;   1. Comments   — secondary, subdued so code stays prominent
;;   2. Strings    — reference points, easy to scan for
;;   3. Constants  — numbers, booleans, symbols (logic starts from constants)
;;   4. Definitions — where functions/types/classes are defined (not called)
;;
;; Everything else (keywords, punctuation, variables, function calls)
;; uses the default foreground. This is intentional.

(local {: colors : semantic} (require :alphabaster.palette))
(local api vim.api)

;; :sp is dropped because cterm has no underline color, and nvim_set_hl would
;; read a slot number there as an RGB integer.
(fn hi [group opts]
  (api.nvim_set_hl 0 group
                   (collect [k v (pairs opts)]
                     (case k
                       :fg (values :ctermfg v)
                       :bg (values :ctermbg v)
                       :sp nil
                       _ (values k v)))))

(fn link [group target]
  (api.nvim_set_hl 0 group {:link target}))

(fn setup []
  (vim.cmd "highlight clear")
  (set vim.g.colors_name :alphabaster)

  ;;; Base
  (hi :Normal {})
  ;; NormalNC matches Normal so inactive splits don't dim on their own;
  ;; the FocusLost autocmd in init.fnl dims both together when the whole
  ;; terminal pane loses focus.
  (hi :NormalNC {})
  (hi :NormalFloat {:bg colors.surface})
  (hi :FloatBorder {:fg colors.bright-black})

  ;;; === THE 4 SEMANTIC CATEGORIES ===

  ;; Comments are secondary. They explain code but shouldn't compete for
  ;; attention. Subdued color keeps focus on the code itself.
  (hi :Comment {:fg semantic.comment})

  ;; Strings are reference points. Logic often starts from string literals.
  ;; Highlighting them also makes unclosed strings immediately obvious.
  (hi :String {:fg semantic.string})

  ;; Constants (numbers, booleans, symbols) are also reference points.
  ;; These anchor your understanding of what code does.
  (hi :Constant {:fg semantic.constant})

  ;; Definitions mark where things are created, not where they're used.
  ;; Function calls are everywhere (~75% of code); definitions are rare
  ;; and worth highlighting.
  (hi :Function {:fg semantic.definition})

  ;;; === DELIBERATELY UNHIGHLIGHTED ===
  ;;
  ;; Keywords, operators, types, etc. are not highlighted.
  ;; They're structural scaffolding — you learn to parse them unconsciously.
  ;; Highlighting them adds noise without aiding comprehension.

  (link :Identifier :Normal)
  (link :Statement :Normal)
  (link :Keyword :Normal)
  (link :Operator :Normal)
  (link :Type :Normal)
  (link :PreProc :Normal)
  (link :Special :Normal)
  (link :Delimiter :Normal)

  ;;; Constants family (all inherit the constant color)
  (link :Number :Constant)
  (link :Boolean :Constant)
  (link :Float :Constant)
  (link :Character :Constant)

  ;;; UI elements
  (hi :Visual {:bg colors.selection-bg})
  (hi :CursorLine {:bg colors.surface})
  (hi :CursorLineNr {:fg semantic.definition :bg colors.surface})
  (hi :LineNr {:fg colors.bright-black})
  ;; No explicit bg — inherits from Normal/NormalNC so it dims with the window.
  (hi :SignColumn {})
  (hi :VertSplit {:fg colors.bright-black})
  (hi :WinSeparator {:fg colors.bright-black})
  (hi :StatusLine {:bg colors.surface})
  (hi :StatusLineNC {:bg colors.surface :fg semantic.comment})
  (hi :Pmenu {:bg colors.surface})
  (hi :PmenuSel {:bg colors.selection-bg})
  (hi :PmenuSbar {:bg colors.surface})
  (hi :PmenuThumb {:bg colors.bright-black})
  (hi :TabLine {:bg colors.surface})
  (hi :TabLineSel {:bg colors.selection-bg :bold true})
  (hi :TabLineFill {:bg colors.surface})

  ;;; Search — high contrast, needs to pop
  (hi :Search {:bg colors.selection-bg})
  (hi :IncSearch {:fg colors.bright-yellow :reverse true})
  (hi :CurSearch {:fg colors.bright-green :reverse true})

  ;;; Diagnostics — these are actionable, worth color
  (hi :DiagnosticError {:fg semantic.error})
  (hi :DiagnosticWarn {:fg semantic.warn})
  (hi :DiagnosticInfo {:fg semantic.info})
  (hi :DiagnosticHint {:fg semantic.hint})
  (hi :DiagnosticUnderlineError {:undercurl true :sp semantic.error})
  (hi :DiagnosticUnderlineWarn {:undercurl true :sp semantic.warn})
  (hi :DiagnosticUnderlineInfo {:undercurl true :sp semantic.info})
  (hi :DiagnosticUnderlineHint {:undercurl true :sp semantic.hint})

  ;;; Diff
  (hi :DiffAdd {:fg semantic.added})
  (hi :DiffDelete {:fg semantic.removed})
  (hi :DiffChange {:fg semantic.changed})
  (hi :DiffText {:fg semantic.changed :bold true})

  ;;; === TREESITTER ===
  ;;
  ;; Treesitter captures use @prefix. We apply the same 4-category rule:
  ;; comments, strings, constants, and definitions get color.
  ;; Everything else inherits Normal.

  ;; Comments
  (link "@comment" :Comment)
  (link "@comment.documentation" :Comment)

  ;; Strings
  (link "@string" :String)
  (link "@string.documentation" :String)
  (link "@string.escape" :Constant)  ;; escape sequences are constants
  (link "@string.regexp" :String)
  (link "@character" :String)

  ;; Constants
  (link "@constant" :Constant)
  (link "@constant.builtin" :Constant)   ;; true, false, nil
  (link "@constant.macro" :Constant)
  (link "@number" :Constant)
  (link "@number.float" :Constant)
  (link "@boolean" :Constant)

  ;; Definitions — only where things are *defined*, not used
  (link "@function" :Normal)              ;; function calls → no highlight
  (link "@function.call" :Normal)
  (link "@function.builtin" :Normal)
  (link "@function.method" :Normal)
  (link "@function.method.call" :Normal)
  (hi "@function.definition" {:fg semantic.definition})
  (hi "@type.definition" {:fg semantic.definition})
  (hi "@variable.definition" {:fg semantic.definition})
  (hi "@parameter" {:fg semantic.definition})  ;; parameter names in signatures

  ;; Deliberately unhighlighted (structural scaffolding)
  (link "@keyword" :Normal)
  (link "@keyword.function" :Normal)
  (link "@keyword.return" :Normal)
  (link "@keyword.operator" :Normal)
  (link "@keyword.conditional" :Normal)
  (link "@keyword.repeat" :Normal)
  (link "@keyword.import" :Normal)
  (link "@keyword.exception" :Normal)
  (link "@operator" :Normal)
  (link "@punctuation" :Normal)
  (link "@punctuation.bracket" :Normal)
  (link "@punctuation.delimiter" :Normal)
  (link "@punctuation.special" :Normal)
  (link "@variable" :Normal)
  (link "@variable.builtin" :Normal)
  (link "@variable.parameter" :Normal)
  (link "@variable.member" :Normal)
  (link "@type" :Normal)
  (link "@type.builtin" :Normal)
  (link "@attribute" :Normal)
  (link "@property" :Normal)
  (link "@field" :Normal)
  (link "@module" :Normal)
  (link "@label" :Normal)
  (link "@tag" :Normal)
  (link "@tag.attribute" :Normal)
  (link "@tag.delimiter" :Normal)

  ;; Markup (for markdown, etc.)
  (link "@markup.heading" :Normal)
  (link "@markup.strong" :Normal)
  (link "@markup.italic" :Normal)
  (link "@markup.link" :Constant)
  (link "@markup.link.url" :String)
  (link "@markup.raw" :String)           ;; code blocks

  ;;; === LSP SEMANTIC TOKENS ===
  ;;
  ;; LSP provides deeper semantic understanding than Treesitter.
  ;; Priority: semantic tokens (125) > treesitter (100).
  ;;
  ;; We mostly clear these to let our Treesitter rules dominate,
  ;; except for definition-related tokens where LSP is more accurate.

  ;; Clear type highlights — we don't want LSP overriding our choices
  (link "@lsp.type.class" :Normal)
  (link "@lsp.type.decorator" :Normal)
  (link "@lsp.type.enum" :Normal)
  (link "@lsp.type.enumMember" :Constant)
  (link "@lsp.type.function" :Normal)
  (link "@lsp.type.interface" :Normal)
  (link "@lsp.type.keyword" :Normal)
  (link "@lsp.type.macro" :Normal)
  (link "@lsp.type.method" :Normal)
  (link "@lsp.type.namespace" :Normal)
  (link "@lsp.type.operator" :Normal)
  (link "@lsp.type.parameter" :Normal)
  (link "@lsp.type.property" :Normal)
  (link "@lsp.type.struct" :Normal)
  (link "@lsp.type.type" :Normal)
  (link "@lsp.type.typeParameter" :Normal)
  (link "@lsp.type.variable" :Normal)

  ;; Strings and comments — let LSP confirm these
  (link "@lsp.type.string" :String)
  (link "@lsp.type.comment" :Comment)

  ;; Definitions — LSP knows exactly where things are defined
  ;; The "definition" modifier marks declaration sites
  (hi "@lsp.mod.definition" {:fg semantic.definition})
  (hi "@lsp.mod.declaration" {:fg semantic.definition})

  ;; Readonly/constant modifiers — these are constants
  (hi "@lsp.mod.readonly" {:fg semantic.constant})
  (hi "@lsp.typemod.variable.readonly" {:fg semantic.constant})
  (hi "@lsp.typemod.property.readonly" {:fg semantic.constant})

  ;; Documentation comments — still comments, still important
  (link "@lsp.type.comment.documentation" :Comment)

  ;;; === PLUGIN SUPPORT ===

  ;; indent-blankline
  ;; Indent guides should be subtle — they're structural, not semantic
  (hi :IblIndent {:fg colors.surface})
  (hi :IblScope {:fg colors.bright-black})  ;; current scope slightly brighter

  ;; treesitter-context
  ;; The sticky context header at top of window
  (hi :TreesitterContext {:bg colors.surface})
  (hi :TreesitterContextLineNumber {:fg semantic.definition :bg colors.surface})

  ;; fidget (LSP progress)
  (hi :FidgetTitle {:fg semantic.definition})
  (hi :FidgetTask {:fg colors.bright-black})

  ;; fzf.vim
  ;; Matched characters should stand out
  (hi :fzf1 {:bg colors.surface})
  (hi :fzf2 {:bg colors.surface})
  (hi :fzf3 {:bg colors.surface})

  ;; dirvish (file browser)
  (link :DirvishPathTail :Normal)
  (hi :DirvishArg {:fg semantic.definition})

  ;; git diff (for fugitive, dirvish-git, etc.)
  (hi :diffAdded {:fg semantic.added})
  (hi :diffRemoved {:fg semantic.removed})
  (hi :diffChanged {:fg semantic.changed})
  (hi :diffFile {:fg semantic.definition})
  (hi :diffLine {:fg colors.bright-black})

  ;; Spelling
  (hi :SpellBad {:undercurl true :sp semantic.error})
  (hi :SpellCap {:undercurl true :sp semantic.info})
  (hi :SpellRare {:undercurl true :sp semantic.hint})
  (hi :SpellLocal {:undercurl true :sp semantic.warn})

  ;; Misc UI
  (hi :MatchParen {:bg colors.selection-bg})
  (hi :Folded {:fg colors.bright-black})
  (hi :FoldColumn {:fg colors.bright-black})
  (hi :NonText {:fg colors.bright-black})
  (hi :SpecialKey {:fg colors.bright-black})
  (hi :Whitespace {:fg colors.surface})  ;; listchars (tabs, trailing spaces)
  (hi :Directory {:fg semantic.definition})
  (hi :Title {:fg semantic.definition})
  (hi :Question {:fg semantic.info})
  (hi :MoreMsg {:fg semantic.info})
  (hi :WarningMsg {:fg semantic.warn})
  (hi :ErrorMsg {:fg semantic.error :bold true})
  (hi :Todo {:fg semantic.comment :bold true})
  (hi :Underlined {:underline true})
  (hi :Ignore {:fg colors.surface})
  (hi :Error {:fg semantic.error :reverse true})
  (hi :Conceal {:fg colors.bright-black})
  (hi :CursorColumn {:bg colors.surface})
  (hi :ColorColumn {:bg colors.surface})
  (hi :QuickFixLine {:bg colors.surface}))

{: setup}