Skip to content

Instantly share code, notes, and snippets.

@nchapon
Last active May 16, 2023 16:15
Show Gist options
  • Save nchapon/3e70128725f2782195333a411c8c5241 to your computer and use it in GitHub Desktop.
Save nchapon/3e70128725f2782195333a411c8c5241 to your computer and use it in GitHub Desktop.
Convert Plant UML VSCode Snippets to Emacs Yasnippets with Babashka
(require '[babashka.http-client :as http])
(require '[cheshire.core :as json])
(require '[clojure.string :as str])
(require '[babashka.fs :as fs])
(defn get-url
"Get URL"
[url]
(println "Downloading url:" url)
(http/get url))
(defn get-vscode-snippets []
(json/parse-string
(:body
(get-url "https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/.vscode/C4.code-snippets")) true))
(defn vscode->emacs-snippets
"Creating emacs snippets from vscode"
[yasnippet-dir]
(println "Creating Emacs Snippets into " yasnippet-dir)
(doseq [[k v] (get-vscode-snippets)]
(let [s-key (name k)
s-name (:description v)
body (str/join (:body v))
content (str "# -*- mode: snippet -*-\n"
"# name: " s-key " - " s-name "\n"
"# key: " s-key "\n"
"# -- \n"
body)]
(println "Creating " s-key "file")
(spit (str yasnippet-dir "/" s-key)
content))))
(if-let [yasnippet-dir (first *command-line-args*)]
(if (fs/directory? yasnippet-dir)
(vscode->emacs-snippets yasnippet-dir)
(println (format "Yasnippet target dir %s does not exist !" yasnippet-dir)))
(println "Please set yasnippet directory"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment