forked from JuliaEditorSupport/julia-emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-julia-latexsubs.jl
34 lines (29 loc) · 1.05 KB
/
make-julia-latexsubs.jl
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
#####
##### Generate the file julia-latexsubs.el. Invoke from the shell as
#####
##### julia make-julia-latexsubs.jl
#####
@assert VERSION ≥ v"1" # use a recent Julia version
import REPL
"""
Write Emacs lisp code that populates the hash table named `varname` to `dest`, using
key-value pairs from `src`.
"""
function write_latexsubs_hashtable(src, dest::IO, varname::AbstractString)
for (k, v) in sort!(collect(src), by = last)
ks = escape_string(k)
vs = escape_string(v)
if occursin(r"^\\U[0-9A-Fa-f]+$", vs)
# codepoints outside the BMP can be problematic in older Emacsen
cp = vs[3:end]
println(dest, "(let ((c (decode-char 'ucs #x$cp)))\n",
" (if c (puthash \"$ks\" (char-to-string c) $(varname))))")
else
println(dest, "(puthash \"$ks\" \"$vs\" $(varname))")
end
end
end
open("julia-latexsubs.el", "w") do io
write_latexsubs_hashtable(REPL.REPLCompletions.latex_symbols, io, "julia-latexsubs")
end
@info "generated latex substitutions"