refactor: use fennel case, as it’s a bit safer

This commit is contained in:
Clément Joly 2023-04-09 21:41:59 +01:00
parent 090b4fdb16
commit c019760081
2 changed files with 16 additions and 12 deletions

View File

@ -43,7 +43,7 @@
https://fennel-lang.org/reference#compiler-environment)" https://fennel-lang.org/reference#compiler-environment)"
(fn fun-to-mods [fun] (fn fun-to-mods [fun]
"Converts a function to the modes it sets mappings for" "Converts a function to the modes it sets mappings for"
(match (tostring fun) (case (tostring fun)
:map-text-object :ox :map-text-object :ox
:map-visual :x :map-visual :x
:map-normal :n :map-normal :n

View File

@ -37,11 +37,12 @@
(local mapping-struct-header {:bepo :Bepo :modes :Modes :qwerty :Qwerty}) (local mapping-struct-header {:bepo :Bepo :modes :Modes :qwerty :Qwerty})
(fn print-mapping-struct [struct] (fn print-mapping-struct [struct]
(match struct (case struct
{: bepo : modes : qwerty} (let [qw (if (= ">" qwerty) "> " qwerty)] {: bepo : modes : qwerty}
(print (.. (right-align modes 6) " " (let [qw (if (= ">" qwerty) "> " qwerty)]
(left-align bepo 4) " " qw))) (print (.. (right-align modes 6) " " (left-align bepo 4) " " qw)))
_ (error (.. "Received an invalid struct" (fennel.view struct))))) _
(error (.. "Received an invalid struct" (fennel.view struct)))))
(fn print-lua-import [name] (fn print-lua-import [name]
(->> (values (left-align (string.format "require(\"bepo\").%s()" name) 46) (->> (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) (= (type docstruct) :table) (values name docstruct)
(error (.. "Invalid type for " name)))) (error (.. "Invalid type for " name))))
tbl_keys (icollect [name docstructy (pairs tbl)] tbl_keys (icollect [name docstructy (pairs tbl)]
name)] name)]
(do (do
(table.sort tbl_keys) (table.sort tbl_keys)
(each [_ name (pairs tbl_keys)] (each [_ name (pairs tbl_keys)]
(do (do
(local docstruct (. tbl name)) (local docstruct (. tbl name))
(var need-header true) (var need-header true)
(fn print-header [] (fn print-header []
(do (do
(print-mapping-struct mapping-struct-header) (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)) (print-header))
(each [i mapping-struct (pairs docstruct.body)] (each [i mapping-struct (pairs docstruct.body)]
(if need-header (print-hedear)) (if need-header (print-hedear))
(match mapping-struct (case mapping-struct
{:comment c} (do {:comment c}
(print (.. "\n" c)) (do
(set need-header true)) (print (.. "\n" c))
_ (print-mapping-struct mapping-struct))) (set need-header true))
_
(print-mapping-struct mapping-struct)))
(print ""))))) (print "")))))
;; We split the vim and the : to prevent vim from picking up that for the fennel file ;; We split the vim and the : to prevent vim from picking up that for the fennel file