-
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
import Std.Data.HashMap
import Lean.Data.Json.Parser
def ofHex a b :=
let f (x : Char) := x.toNat - (if x.toNat ≤ '9'.toNat then '0'.toNat else 'a'.toNat - 10)
16 * f a + f b |> Char.ofNat
def main := do
let keysym :=
(← IO.FS.lines "keysymdef.h") |>.map
(fun l : String ↦
(ofHex (String.Pos.Raw.get! l ⟨45⟩) (String.Pos.Raw.get! l ⟨46⟩),
Substring.Raw.mk l ⟨11⟩ ⟨30⟩ |>.takeWhile (· ≠ ' ') |>.toString)) |>
Std.HashMap.ofArray
IO.println "# Generated by https://git.unnamed.website/miscelleaneous/tree/Compose.lean"
IO.println "include \"%L\""
let raw_abbrs ←
IO.Process.run
{ cmd := "curl",
args :=
#["https://raw.githubusercontent.com/leanprover/vscode-lean4/refs/heads/master/lean4-unicode-input/src/abbreviations.json"] }
match Lean.Json.parse raw_abbrs with
| .ok (.obj abbrs) =>
for abbr in abbrs do
match abbr.2 with
| .str s =>
if !(s.contains '$') then
-- XCompose doesn't like sequences to be prefixes of other sequences, so append enter to the end
IO.println
s!"<Multi_key> <{(abbr.1.toList.map (keysym.get! ·) |>
"> <".intercalate)}> <Return> : \"{s.replace "\\" "\\\\"}\""
| _ =>
pure ()
| _ =>
IO.println "parse failure"