#!/usr/bin/env julia

import REPL: REPLCompletions

const snipmate_dir = "snippets"
const snipmate_filename = "_.snippets"
const ultisnips_dir = "UltiSnips"
const ultisnips_filename = "all_unicode.snippets"

mkpath(snipmate_dir)
mkpath(ultisnips_dir)

snipmate_file = open("$(snipmate_dir)/$(snipmate_filename)", "w")
ultisnips_file = open("$(ultisnips_dir)/$(ultisnips_filename)", "w")

for file in (snipmate_file, ultisnips_file)
    println(file,
            "# This file was generated by `$(basename(Base.source_path()))`")
    println(file, "# using Julia $VERSION")
    println(file)
end

for (keyword, unicode) in sort!(collect(Iterators.flatten(
        (REPLCompletions.latex_symbols,
         REPLCompletions.emoji_symbols))),
        by=x -> x[2])
    println(snipmate_file, "snippet ", keyword, " ", unicode)
    println(snipmate_file, "\t", unicode)

    println(ultisnips_file, "snippet ", keyword, " \"", unicode, "\" i")
    println(ultisnips_file, unicode)
    println(ultisnips_file, "endsnippet")
end

close(snipmate_file)
close(ultisnips_file)
