From c0197600811f7363a501affcf4d39f9e936d3b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Joly?= Date: Sun, 9 Apr 2023 21:41:59 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20use=20fennel=20`case`,=20as=20it?= =?UTF-8?q?=E2=80=99s=20a=20bit=20safer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fnl/bepo.fnl | 2 +- scripts/gen_doc.fnl | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/fnl/bepo.fnl b/fnl/bepo.fnl index 142f78e..7ce7631 100644 --- a/fnl/bepo.fnl +++ b/fnl/bepo.fnl @@ -43,7 +43,7 @@ https://fennel-lang.org/reference#compiler-environment)" (fn fun-to-mods [fun] "Converts a function to the modes it sets mappings for" - (match (tostring fun) + (case (tostring fun) :map-text-object :ox :map-visual :x :map-normal :n diff --git a/scripts/gen_doc.fnl b/scripts/gen_doc.fnl index 2a7eae5..8b50c50 100644 --- a/scripts/gen_doc.fnl +++ b/scripts/gen_doc.fnl @@ -37,11 +37,12 @@ (local mapping-struct-header {:bepo :Bepo :modes :Modes :qwerty :Qwerty}) (fn print-mapping-struct [struct] - (match struct - {: bepo : modes : qwerty} (let [qw (if (= ">" qwerty) "> " qwerty)] - (print (.. (right-align modes 6) " " - (left-align bepo 4) " " qw))) - _ (error (.. "Received an invalid struct" (fennel.view struct))))) + (case struct + {: bepo : modes : qwerty} + (let [qw (if (= ">" qwerty) "> " qwerty)] + (print (.. (right-align modes 6) " " (left-align bepo 4) " " qw))) + _ + (error (.. "Received an invalid struct" (fennel.view struct))))) (fn print-lua-import [name] (->> (values (left-align (string.format "require(\"bepo\").%s()" name) 46) @@ -104,13 +105,14 @@ in each group. “Modes” have the same meaning as in the |map-table|. (= (type docstruct) :table) (values name docstruct) (error (.. "Invalid type for " name)))) tbl_keys (icollect [name docstructy (pairs tbl)] - name)] + name)] (do (table.sort tbl_keys) (each [_ name (pairs tbl_keys)] (do (local docstruct (. tbl name)) (var need-header true) + (fn print-header [] (do (print-mapping-struct mapping-struct-header) @@ -124,11 +126,13 @@ in each group. “Modes” have the same meaning as in the |map-table|. (print-header)) (each [i mapping-struct (pairs docstruct.body)] (if need-header (print-hedear)) - (match mapping-struct - {:comment c} (do - (print (.. "\n" c)) - (set need-header true)) - _ (print-mapping-struct mapping-struct))) + (case mapping-struct + {:comment c} + (do + (print (.. "\n" c)) + (set need-header true)) + _ + (print-mapping-struct mapping-struct))) (print ""))))) ;; We split the vim and the : to prevent vim from picking up that for the fennel file