-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
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.readFile "keysymdef.h").splitOn "\n" |>.map (fun l : String ↦ (ofHex (String.Pos.Raw.get! l ⟨45⟩) (String.Pos.Raw.get! l ⟨46⟩), Substring.mk l ⟨11⟩ ⟨30⟩ |>.takeWhile (· ≠ ' ') |>.toString)) |> Std.HashMap.ofList
IO.println "include \"%L\""
let raw_abbrs ← IO.Process.run { cmd := "curl", args := #["https://raw.githubusercontent.com/vasnesterov/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
pure ()
else
-- 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"