liquid

mogenslund 2019-07-03T19:20:24.053700Z

Here is a proof-of-concept parinfer for Liquid, taking advantage of org.clojars.oakes/parinfer which is perinfer implemented in Kotlin. It is very rough and should not be applied on important files!! It is just to play with for fun and inspiration. Over time I will prefer translating parinfer to clojure. To use: add org.clojars.oakes/parinfer {:mvn/version "0.4.0"} to deps.edn and evalute the content below in Liquid. When typing "i" in normal mode a variant of insert mode with parinfer applied will be activated.

(ns dk.salza.liqscratch.parinferapp
  ( :require [dk.salza.liq.editor :as editor]
             [dk.salza.liq.slider :refer :all])
  (:import [com.oakmac.parinfer Parinfer]))

(defn forward-line-n
  [sl n]
  ((apply comp (repeat n forward-line)) sl)) 

(defn par-indent
  [sl]
  (let [col (get-visual-column sl 500)
        l (get-linenumber sl)
        p (get-point sl)
        t (get-content sl)
        t1 (.text (Parinfer/indentMode t (Integer. col) (Integer. (- l 1)) nil false))]
    (-> (create t1) (forward-line-n (- l 1)) (right col))))

(def parinfer-keymap
  (assoc ((@editor/editor ::editor/keymaps) "dk.salza.liq.keymappings.insert")
     :id "dk.salza.parinfer"
     " " #(-> % (insert " ") par-indent)
     "\n" #(-> % (insert "\n") par-indent)
     "backspace" #(-> % (delete 1) par-indent)))

(editor/add-keymap parinfer-keymap)
(editor/add-keybinding  "dk.salza.liq.keymappings.normal" "i" #(editor/set-keymap "dk.salza.parinfer"))

2💯1❤️