(adjust-comments blocks)adds additional newlines after comments
(->> (adjust-comments [(construct/comment ";hello") :a])
(mapv str))
=> [";hello" "
" ":a"]
adds additional newlines after comments
(->> (adjust-comments [(construct/comment ";hello") :a])
(mapv str))
=> [";hello" "\
" ":a"](grid container anchor {:keys [rules scope] :as opts})formats lines given indentation rules and scope
(-> (construct/block ^:list ['if-let (construct/newline) (construct/newline) (construct/block '[i (pos? 0)]) (construct/newline) (construct/block '(+ i 1))]) (grid 1 {:rules {'if-let {:indent 1 :bind 1}}}) (construct/contents))
formats lines given indentation rules and scope
(-> (construct/block ^:list ['if-let
(construct/newline)
(construct/newline) (construct/block '[i (pos? 0)])
(construct/newline) (construct/block '(+ i 1))])
(grid 1 {:rules {'if-let {:indent 1
:bind 1}}})
(construct/contents))(grid-rules tag sym pscope rules)creates indentation rules for current block
(grid-rules :list nil nil nil) => {:indent 0, :bind 0, :scope []}
(grid-rules :vector nil nil nil) => {:indent 0, :bind 0, :scope [0]}
(grid-rules :list 'add [1] nil) => {:indent 1, :bind 0, :scope [0]}
(grid-rules :list 'if nil '{if {:indent 1}}) => {:indent 1, :bind 0, :scope []}
creates indentation rules for current block
(grid-rules :list nil nil nil)
=> {:indent 0, :bind 0, :scope []}
(grid-rules :vector nil nil nil)
=> {:indent 0, :bind 0, :scope [0]}
(grid-rules :list 'add [1] nil)
=> {:indent 1, :bind 0, :scope [0]}
(grid-rules :list 'if nil '{if {:indent 1}})
=> {:indent 1, :bind 0, :scope []}(grid-scope pscope)calculates the grid scope for child nodes
(grid-scope [{0 1} 1]) => [{0 1} 0]
calculates the grid scope for child nodes
(grid-scope [{0 1} 1])
=> [{0 1} 0](indent-bind lines bind)returns the number of lines indentation
(indent-bind [[(construct/token 'if-let)] [(construct/newline)] [(construct/newline) (construct/block '[i (pos? 0)])] [(construct/newline) (construct/block '(+ i 1))]] 1) => 2
returns the number of lines indentation
(indent-bind [[(construct/token 'if-let)]
[(construct/newline)]
[(construct/newline) (construct/block '[i (pos? 0)])]
[(construct/newline) (construct/block '(+ i 1))]]
1)
=> 2(indent-lines [start & more :as lines]
anchor
{:keys [indent bind scope] :as rule})indent lines given an anchor and rule
(-> (indent-lines [[(construct/token 'if-let)] [(construct/newline)] [(construct/newline) (construct/block '[i (pos? 0)])] [(construct/newline) (construct/block '(+ i 1))]] 1 {:indent 1 :bind 1}) (construct/contents))
indent lines given an anchor and rule
(-> (indent-lines [[(construct/token 'if-let)]
[(construct/newline)]
[(construct/newline) (construct/block '[i (pos? 0)])]
[(construct/newline) (construct/block '(+ i 1))]]
1
{:indent 1
:bind 1})
(construct/contents))(remove-extra-linebreaks lines)removes extra linebreaks
(remove-extra-linebreaks [[:a] [(construct/newline)] [(construct/newline)] [(construct/newline)] [:b]]) => [[:a] [(construct/newline)] [:b]]
removes extra linebreaks
(remove-extra-linebreaks [[:a]
[(construct/newline)]
[(construct/newline)]
[(construct/newline)]
[:b]])
=> [[:a]
[(construct/newline)]
[:b]](remove-starting-spaces lines)removes extra spaces from the start of the line
(remove-starting-spaces [[(construct/newline) (construct/space) (construct/space) :a :b] [(construct/newline) (construct/space) :c :d]]) => [[(construct/newline) :a :b] [(construct/newline) :c :d]]
removes extra spaces from the start of the line
(remove-starting-spaces [[(construct/newline)
(construct/space)
(construct/space) :a :b]
[(construct/newline) (construct/space) :c :d]])
=> [[(construct/newline) :a :b]
[(construct/newline) :c :d]](split-lines blocks)splits the nodes, retaining the linebreak nodes
(split-lines [:a :b (construct/newline) :c :d]) => [[:a :b] [(construct/newline) :c :d]]
splits the nodes, retaining the linebreak nodes
(split-lines [:a :b (construct/newline) :c :d])
=> [[:a :b]
[(construct/newline) :c :d]](trim-left blocks)removes whitespace nodes on the left
(->> (trim-left [(construct/space) :a (construct/space)]) (mapv str)) => [":a" "␣"]
removes whitespace nodes on the left
(->> (trim-left [(construct/space)
:a
(construct/space)])
(mapv str))
=> [":a" "␣"](trim-right blocks)removes whitespace nodes on the right
(->> (trim-right [(construct/space) :a (construct/space)]) (mapv str)) => ["␣" ":a"]
removes whitespace nodes on the right
(->> (trim-right [(construct/space)
:a
(construct/space)])
(mapv str))
=> ["␣" ":a"]cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |