Skip to content

Commit

Permalink
Small tweak to keymap generator script
Browse files Browse the repository at this point in the history
  • Loading branch information
carlobaldassi committed Dec 11, 2018
1 parent b644d80 commit b81e148
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 168 deletions.
45 changes: 28 additions & 17 deletions keymap/generate_L2U_keymap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,28 @@ function table_entries(completions::Dict{String,String}, unicode_dict)
end

open("$filename.vim","w") do f
println(f, "\" This file is autogenerated from the script '$(basename(Base.source_path()))'")
println(f, "\" The full script can be found in the comments at the bottom of this file")
println(f, "\" The symbols are based on Julia version $VERSION")
println(f)
println(f, "scriptencoding utf-8")
println(f)
println(f, "let b:keymap_name = \"L2U\"")
println(f, "loadkeymap")
println(f)
print(f, """
" This file is autogenerated from the script '$(basename(Base.source_path()))'
" The symbols are based on Julia version $VERSION
" The full generating script can be found in the comments at the bottom of this file,
" and it can be extracted with:
"
" \$ grep '^\">' $filename.vim | cut -c4- > $(basename(Base.source_path()))'
"
" To produce this keymap file you need to have Julia compilied from source, and
" to run `make UnicodeData.txt` inside Julia's `doc` directory.
" Then you can run:
"
" \$ julia $(basename(Base.source_path())).jl
"
scriptencoding utf-8
let b:keymap_name = "L2U"
loadkeymap
""")

col_headers = ["\" Tab completion sequence", "Code point", "Character", "Unicode name"]

latex, code, unicode, desc =
Expand All @@ -108,15 +121,13 @@ open("$filename.vim","w") do f
end
print_padded("\" " * "-"^(lw-2), "-"^cw, "-"^uw, "-"^dw)

println(f)
println(f, "\"\" Below here is the script that was used to produce this file.")
println(f, "\"\" You can copy it to a file called 'generate_L2U_keymap.jl', removing the initial quotes, and run:")
println(f, "\"\"")
println(f, "\"\" \$ julia generate_L2U_keymap.jl")
println(f, "\"\"")
println(f)
print(f, """
" Below here is the script that was used to produce this file.
""")
for l in readlines(Base.source_path())
println(f, "\" ", l)
println(f, "\"> ", l)
end
println(f)
end
296 changes: 145 additions & 151 deletions keymap/latex2unicode_utf-8.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
" This file is autogenerated from the script 'generate_L2U_keymap.jl'
" The full script can be found in the comments at the bottom of this file
" The symbols are based on Julia version 1.1.0-DEV.695
" The full generating script can be found in the comments at the bottom of this file,
" and it can be extracted with:
"
" $ grep '^">' latex2unicode_utf-8.vim | cut -c4- > generate_L2U_keymap.jl'
"
" To produce this keymap file you need to have Julia compilied from source, and
" to run `make UnicodeData.txt` inside Julia's `doc` directory.
" Then you can run:
"
" $ julia generate_L2U_keymap.jl.jl
"

scriptencoding utf-8

Expand Down Expand Up @@ -7069,155 +7079,139 @@ loadkeymap
\\zeta <char-0x003B6> " ζ : GREEK SMALL LETTER ZETA
" --------------------------------- ---------------------------- " ---------- : --------------------------------------------------------------------------------------------------------

"" Below here is the script that was used to produce this file.
"" You can copy it to a file called 'generate_L2U_keymap.jl', removing the initial quotes, and run:
""
"" $ julia generate_L2U_keymap.jl
""
" Below here is the script that was used to produce this file.

" #!/bin/env julia
"
" const filename = "latex2unicode_utf-8"
"
" function unambiguous_completions(completions::Dict{String,String})
" return completions
" allinputs = sort!(collect(keys(completions)))
" new_completions = copy(completions)
"
" for input in allinputs
" chars = completions[input]
" l = length(input)
" for i = 2:(l-1)
" n = length(filter(x->startswith(x, input[1:i]), allinputs))
" @assert n ≥ 1
" n > 1 && continue
" for j = i:(l-1)
" # new_completions[input[1:j] * "<Tab>"] = chars
" new_completions[input[1:j]] = chars
" end
" break
" end
" # new_completions[input * "<Tab>"] = chars
" end
" return new_completions
" end
"
" # We want to avoid situations in which the user types e.g. \delt and pauses,
" # and the result is "∇t" because "\del" gets recognized and then there is some leftover "t".
" # This allows us to get completions with <Tab> for example.
" function fix_completions(completions::Dict{String,String})
" allinputs = sort!(collect(keys(completions)))
" new_completions = copy(completions)
"
" for input in allinputs
" chars = completions[input]
" l = length(input)
" longer = filter(x->startswith(x, input)&&length(x)>l, allinputs)
" n = length(longer)
" n == 0 && continue
" new_completions[input * "<Tab>"] = chars
" for other in longer
" for j = (l+1):(length(other)-1)
" haskey(new_completions, other[1:j]) && continue
" new_completions[other[1:j]] = other[1:j]
" end
" end
" end
" return new_completions
" end
"
" function unicode_data()
" file = normpath(Sys.BINDIR, "..", "..", "doc", "UnicodeData.txt")
" names = Dict{UInt32, String}()
" open(file) do unidata
" for line in readlines(unidata)
" id, name, desc = split(line, ";")[[1, 2, 11]]
" codepoint = parse(UInt32, "0x$id")
" names[codepoint] = (name == "" ? desc : desc == "" ? name : "$name / $desc")
" end
" end
" return names
" end
"
" # Prepend a dotted circle ('◌' i.e. '\u25CC') to combining characters
" function fix_combining_chars(char)
" cat = Base.Unicode.category_code(char)
" return string(cat == 6 || cat == 8 ? "◌" : "", char)
" end
"
" function table_entries(completions::Dict{String,String}, unicode_dict)
" latex = String[]
" code = String[]
" unicode = String[]
" desc = String[]
"
" for (input, chars) in sort!(collect(completions))
" code_points, unicode_names, characters = String[], String[], String[]
" if startswith(chars, "\\")
" push!(code_points, replace(chars, "\\" => "\\\\"))
" push!(unicode_names, "(Incomplete sequence)")
" push!(characters, "")
" else
" for char in chars
" push!(code_points, "<char-0x$(uppercase(string(UInt32(char), base = 16, pad = 5)))>")
" push!(unicode_names, get(unicode_dict, UInt32(char), "(No Unicode name)"))
" push!(characters, isempty(characters) ? fix_combining_chars(char) : "$char")
" end
" end
" push!(latex, replace(input, "\\"=>"\\\\"))
" push!(code, join(code_points))
" push!(unicode, join(characters))
" push!(desc, join(unicode_names, " + "))
" end
" return latex, code, unicode, desc
" end
"
" open("$filename.vim","w") do f
" println(f, "\" This file is autogenerated from the script '$(basename(Base.source_path()))'")
" println(f, "\" The full script can be found in the comments at the bottom of this file")
" println(f, "\" The symbols are based on Julia version $VERSION")
" println(f)
" println(f, "scriptencoding utf-8")
" println(f)
" println(f, "let b:keymap_name = \"L2U\"")
" println(f, "loadkeymap")
" println(f)
" col_headers = ["\" Tab completion sequence", "Code point", "Character", "Unicode name"]
"
" latex, code, unicode, desc =
" table_entries(
" fix_completions(merge(
" REPL.REPLCompletions.latex_symbols,
" REPL.REPLCompletions.emoji_symbols
" )),
" unicode_data()
" )
"
" lw = max(length(col_headers[3]), maximum(map(length, latex)))
" cw = max(length(col_headers[1]), maximum(map(length, code)))
" uw = max(length(col_headers[2]), maximum(map(length, unicode)))
" dw = max(length(col_headers[4]), maximum(map(length, desc)))
"
" print_padded(l, c, u, d) = println(f, rpad(l, lw), " ", rpad(c, cw), " \" ", rpad(u, uw), " : ", d)
"
" print_padded(col_headers...)
" print_padded("\" " * "-"^(lw-2), "-"^cw, "-"^uw, "-"^dw)
"
" for (l, c, u, d) in zip(latex, code, unicode, desc)
" print_padded(l, c, u, d)
" end
" print_padded("\" " * "-"^(lw-2), "-"^cw, "-"^uw, "-"^dw)
"
" println(f)
" println(f, "\"\" Below here is the script that was used to produce this file.")
" println(f, "\"\" You can copy it to a file called 'generate_L2U_keymap.jl', removing the initial quotes, and run:")
" println(f, "\"\"")
" println(f, "\"\" \$ julia generate_L2U_keymap.jl")
" println(f, "\"\"")
" println(f)
" for l in readlines(Base.source_path())
" println(f, "\" ", l)
" end
" println(f)
" end
"> #!/bin/env julia
">
"> const filename = "latex2unicode_utf-8"
">
"> # We want to avoid situations in which the user types e.g. \delt and pauses,
"> # and the result is "∇t" because "\del" gets recognized and then there is some leftover "t".
"> # This allows us to get completions with <Tab> for example.
"> function fix_completions(completions::Dict{String,String})
"> allinputs = sort!(collect(keys(completions)))
"> new_completions = copy(completions)
">
"> for input in allinputs
"> chars = completions[input]
"> l = length(input)
"> longer = filter(x->startswith(x, input)&&length(x)>l, allinputs)
"> n = length(longer)
"> n == 0 && continue
"> new_completions[input * "<Tab>"] = chars
"> for other in longer
"> for j = (l+1):(length(other)-1)
"> haskey(new_completions, other[1:j]) && continue
"> new_completions[other[1:j]] = other[1:j]
"> end
"> end
"> end
"> return new_completions
"> end
">
"> function unicode_data()
"> file = normpath(Sys.BINDIR, "..", "..", "doc", "UnicodeData.txt")
"> names = Dict{UInt32, String}()
"> open(file) do unidata
"> for line in readlines(unidata)
"> id, name, desc = split(line, ";")[[1, 2, 11]]
"> codepoint = parse(UInt32, "0x$id")
"> names[codepoint] = (name == "" ? desc : desc == "" ? name : "$name / $desc")
"> end
"> end
"> return names
"> end
">
"> # Prepend a dotted circle ('◌' i.e. '\u25CC') to combining characters
"> function fix_combining_chars(char)
"> cat = Base.Unicode.category_code(char)
"> return string(cat == 6 || cat == 8 ? "◌" : "", char)
"> end
">
"> function table_entries(completions::Dict{String,String}, unicode_dict)
"> latex = String[]
"> code = String[]
"> unicode = String[]
"> desc = String[]
">
"> for (input, chars) in sort!(collect(completions))
"> code_points, unicode_names, characters = String[], String[], String[]
"> if startswith(chars, "\\")
"> push!(code_points, replace(chars, "\\" => "\\\\"))
"> push!(unicode_names, "(Incomplete sequence)")
"> push!(characters, "")
"> else
"> for char in chars
"> push!(code_points, "<char-0x$(uppercase(string(UInt32(char), base = 16, pad = 5)))>")
"> push!(unicode_names, get(unicode_dict, UInt32(char), "(No Unicode name)"))
"> push!(characters, isempty(characters) ? fix_combining_chars(char) : "$char")
"> end
"> end
"> push!(latex, replace(input, "\\"=>"\\\\"))
"> push!(code, join(code_points))
"> push!(unicode, join(characters))
"> push!(desc, join(unicode_names, " + "))
"> end
"> return latex, code, unicode, desc
"> end
">
"> open("$filename.vim","w") do f
"> print(f, """
"> " This file is autogenerated from the script '$(basename(Base.source_path()))'
"> " The symbols are based on Julia version $VERSION
"> " The full generating script can be found in the comments at the bottom of this file,
"> " and it can be extracted with:
"> "
"> " \$ grep '^\">' $filename.vim | cut -c4- > $(basename(Base.source_path()))'
"> "
"> " To produce this keymap file you need to have Julia compilied from source, and
"> " to run `make UnicodeData.txt` inside Julia's `doc` directory.
"> " Then you can run:
"> "
"> " \$ julia $(basename(Base.source_path())).jl
"> "
">
"> scriptencoding utf-8
">
"> let b:keymap_name = "L2U"
"> loadkeymap
">
"> """)
">
"> col_headers = ["\" Tab completion sequence", "Code point", "Character", "Unicode name"]
">
"> latex, code, unicode, desc =
"> table_entries(
"> fix_completions(merge(
"> REPL.REPLCompletions.latex_symbols,
"> REPL.REPLCompletions.emoji_symbols
"> )),
"> unicode_data()
"> )
">
"> lw = max(length(col_headers[3]), maximum(map(length, latex)))
"> cw = max(length(col_headers[1]), maximum(map(length, code)))
"> uw = max(length(col_headers[2]), maximum(map(length, unicode)))
"> dw = max(length(col_headers[4]), maximum(map(length, desc)))
">
"> print_padded(l, c, u, d) = println(f, rpad(l, lw), " ", rpad(c, cw), " \" ", rpad(u, uw), " : ", d)
">
"> print_padded(col_headers...)
"> print_padded("\" " * "-"^(lw-2), "-"^cw, "-"^uw, "-"^dw)
">
"> for (l, c, u, d) in zip(latex, code, unicode, desc)
"> print_padded(l, c, u, d)
"> end
"> print_padded("\" " * "-"^(lw-2), "-"^cw, "-"^uw, "-"^dw)
">
"> print(f, """
">
"> " Below here is the script that was used to produce this file.
">
"> """)
"> for l in readlines(Base.source_path())
"> println(f, "\"> ", l)
"> end
"> println(f)
"> end

0 comments on commit b81e148

Please sign in to comment.