Skip to content

Commit 79f9907

Browse files
First draft to generate YASnippet files
1 parent f662872 commit 79f9907

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed
Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
(ns algorithm-mnemonics-emacs.core
2+
(:require [clojure.xml :as xml]
3+
[clojure.string :as str])
24
(:gen-class))
35

6+
(def url "https://raw.githubusercontent.com/tommybennett/algorithm-mnemonics/master/algorithm_mnemonics.xml")
7+
8+
(def directory "c++-algorithm/")
9+
10+
(defn -parse [s]
11+
(xml/parse
12+
(java.io.ByteArrayInputStream. (.getBytes s))))
13+
14+
(defn- snippet-name [mnemonic]
15+
"Name of the mnemonic"
16+
(get-in mnemonic [:attrs :n]))
17+
18+
(defn- snippet-code [mnemonic]
19+
"C++ code of the mnemonic"
20+
(get-in mnemonic [:content 0 :content 0]))
21+
22+
(defn- snippet-write [filename snippet]
23+
"Write the snippet <str> in a file <filenamed>"
24+
(spit (str directory filename) snippet))
25+
26+
(defn- snippet-data [name code]
27+
(str "# -*- mode: snippet -*-\n"
28+
"# name: " name "\n"
29+
"# key: " name "\n"
30+
"# --"
31+
code))
32+
33+
(defn- snippet [mnemonic]
34+
(let [name (snippet-name mnemonic)
35+
code (str/replace (snippet-code mnemonic) "\t" "")]
36+
(snippet-write name (snippet-data name code))))
37+
438
(defn -main
5-
"I don't do a whole lot ... yet."
39+
"Convert the algorithm mnemonic XML file to YASnippet files"
640
[& args]
7-
(println "Hello, World!"))
41+
(let [mnemonics (parse (slurp url))]
42+
(.mkdir (java.io.File. "c++-algorithm"))
43+
(map snippet (get-in mnemonics [:content]))))

0 commit comments

Comments
 (0)