~technomancy/fennel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] fennelview: remove sequential-length and associative-length options

Details
Message ID
<20210127172143.1492933-1-andreyorst@gmail.com>
DKIM signature
pass
Download raw message
Patch: +14 -31
---
 fennelview.lua      | 10 ++--------
 src/fennel/view.fnl | 11 +----------
 test/core.fnl       | 24 +++++++++++-------------
 3 files changed, 14 insertions(+), 31 deletions(-)

diff --git a/fennelview.lua b/fennelview.lua
index 586da79..7c1c25d 100644
--- a/fennelview.lua
+++ b/fennelview.lua
@@ -115,13 +115,7 @@ local function concat_table_lines(elements, options, multiline_3f, indent, table
    close = "}"
  end
  local oneline = (open .. table.concat(elements, " ") .. close)
  local _4_
  if (table_type == "seq") then
    _4_ = options["sequential-length"]
  else
    _4_ = options["associative-length"]
  end
  if (not options["one-line?"] and (multiline_3f or (#elements > _4_) or ((indent + #oneline) > options["line-length"]))) then
  if (not options["one-line?"] and (multiline_3f or ((indent + #oneline) > options["line-length"]))) then
    return (open .. table.concat(elements, indent_str) .. close)
  else
    return oneline
@@ -322,7 +316,7 @@ local function colon_string_3f(s)
  return s:find("^[-%w?\\^_!$%&*+./@:|<=>]+$")
end
local function make_options(t, options)
  local defaults = {["associative-length"] = 4, ["detect-cycles?"] = true, ["empty-as-sequence?"] = false, ["line-length"] = 80, ["metamethod?"] = true, ["one-line?"] = false, ["sequential-length"] = 10, ["utf8?"] = true, depth = 128}
  local defaults = {["detect-cycles?"] = true, ["empty-as-sequence?"] = false, ["line-length"] = 80, ["metamethod?"] = true, ["one-line?"] = false, ["utf8?"] = true, depth = 128}
  local overrides = {appearances = count_table_appearances(t, {}), level = 0, seen = {len = 0}}
  for k, v in pairs((options or {})) do
    defaults[k] = v
diff --git a/src/fennel/view.fnl b/src/fennel/view.fnl
index 63f9df5..b37a533 100644
--- a/src/fennel/view.fnl
+++ b/src/fennel/view.fnl
@@ -99,9 +99,6 @@
        oneline (.. open (table.concat elements " ") close)]
    (if (and (not options.one-line?)
             (or multiline?
                 (> (length elements) (if (= table-type :seq)
                                          options.sequential-length
                                          options.associative-length))
                 (> (+ indent (length oneline)) options.line-length)))
        (.. open (table.concat elements indent-str) close)
        oneline)))
@@ -196,9 +193,7 @@

(fn make-options [t options]
  (let [;; defaults are used when options are not provided
        defaults {:sequential-length 10
                  :associative-length 4
                  :line-length 80
        defaults {:line-length 80
                  :one-line? false
                  :depth 128
                  :detect-cycles? true
@@ -243,10 +238,6 @@ Can take an options table with these keys:
* :detect-cycles? (boolean, default: true) don't try to traverse a looping table
* :metamethod? (boolean: default: true) use the __fennelview metamethod if found
* :empty-as-sequence? (boolean, default: false) render empty tables as []
* :sequential-length (number, default: 10) amount of elements at which
  multi-line sequence ouptut is produced
* :associative-length (number, default: 4) amount of elements at which
  multi-line table ouptut is produced
* :line-length (number, default: 80) length of the line at which
  multi-line output for tables is forced
* :utf8? (boolean, default true) whether to use utf8 module to compute string
diff --git a/test/core.fnl b/test/core.fnl
index daecd0d..08586da 100644
--- a/test/core.fnl
+++ b/test/core.fnl
@@ -320,8 +320,6 @@
               "{}"
               "((require :fennel.view) [1 2 3])"
               "[1 2 3]"
               "((require :fennel.view) [0 1 2 3 4 5 6 7 8 9 10])"
               "[0\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n 10]"
               "((require :fennel.view) {:a 1 \"a b\" 2})"
               "{:a 1 \"a b\" 2}"
               "((require :fennel.view) [])"
@@ -330,13 +328,13 @@
               "[]"
               "((require :fennel.view) [1 2 3])"
               "[1 2 3]"
               "((require :fennel.view) [0 1 2 3 4 5 6 7 8 9 10])"
               "((require :fennel.view) [0 1 2 3 4 5 6 7 8 9 10] {:line-length 5})"
               "[0\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n 10]"
               "((require :fennel.view) {:a 1 \"a b\" 2})"
               "{:a 1 \"a b\" 2}"
               "((require :fennel.view) {:a 1 :b 52} {:associative-length 1})"
               "((require :fennel.view) {:a 1 :b 52} {:line-length 1})"
               "{:a 1\n :b 52}"
               "((require :fennel.view) {:a 1 :b 5} {:one-line? true :associative-length 1})"
               "((require :fennel.view) {:a 1 :b 5} {:one-line? true :line-length 1})"
               "{:a 1 :b 5}"
               ;; nesting
               "((require :fennel.view) (let [t {}] [t t]) {:detect-cycles? false})"
@@ -349,29 +347,29 @@
               "{[{}] {}}"
               "((require :fennel.view) {[[]] {[[]] [[[]]]}} {:empty-as-sequence? true})"
               "{[[]] {[[]] [[[]]]}}"
               "((require :fennel.view) [1 2 [3 4]] {:sequential-length 2})"
               "((require :fennel.view) [1 2 [3 4]] {:line-length 7})"
               "[1\n 2\n [3 4]]"
               "((require :fennel.view) {[1] [2 [3]] :data {4 {:data 5} 6 [0 1 2 3]}} {:sequential-length 3})"
               "((require :fennel.view) {[1] [2 [3]] :data {4 {:data 5} 6 [0 1 2 3]}} {:line-length 15})"
               "{:data {4 {:data 5}\n        6 [0\n           1\n           2\n           3]}\n [1] [2 [3]]}"
               "((require :fennel.view) {{:a 1} {:b 2 :c 3}})"
               "{{:a 1} {:b 2 :c 3}}"
               "((require :fennel.view) [{:aaa [1 2 3]}] {:sequential-length 2})"
               "((require :fennel.view) [{:aaa [1 2 3]}] {:line-length 0})"
               "[{:aaa [1\n        2\n        3]}]"
               "((require :fennel.view) {:a [1 2 3 4 5 6 7] :b [1 2 3 4 5 6 7] :c [1 2 3 4 5 6 7] :d [1 2 3 4 5 6 7]})"
               "{:a [1 2 3 4 5 6 7] :b [1 2 3 4 5 6 7] :c [1 2 3 4 5 6 7] :d [1 2 3 4 5 6 7]}"
               "((require :fennel.view) {:a [1 2] :b [1 2] :c [1 2] :d [1 2]} {:line-length 3})"
               "((require :fennel.view) {:a [1 2] :b [1 2] :c [1 2] :d [1 2]} {:line-length 0})"
               "{:a [1\n     2]\n :b [1\n     2]\n :c [1\n     2]\n :d [1\n     2]}"
               "((require :fennel.view)  {:a [1 2 3 4 5 6 7 8] :b [1 2 3 4 5 6 7 8] :c [1 2 3 4 5 6 7 8] :d [1 2 3 4 5 6 7 8]})"
               "{:a [1 2 3 4 5 6 7 8]\n :b [1 2 3 4 5 6 7 8]\n :c [1 2 3 4 5 6 7 8]\n :d [1 2 3 4 5 6 7 8]}"
               ;; Unicode
               "((require :fennel.view) \"ваыв\")"
               "\"ваыв\""
               "((require :fennel.view) {[1] [2 [3]] :ваыв {4 {:ваыв 5} 6 [0 1 2 3]}} {:sequential-length 3})"
               "((require :fennel.view) {[1] [2 [3]] :ваыв {4 {:ваыв 5} 6 [0 1 2 3]}} {:line-length 15})"
               (if _G.utf8
                   "{\"ваыв\" {4 {\"ваыв\" 5}\n         6 [0\n            1\n            2\n            3]}\n [1] [2 [3]]}"
                   "{\"ваыв\" {4 {\"ваыв\" 5}\n             6 [0\n                1\n                2\n                3]}\n [1] [2 [3]]}")
               ;; the next one may look incorrect in some editors, but is actually correct
               "((require :fennel.view) {:ǍǍǍ {} :ƁƁƁ {:ǍǍǍ {} :ƁƁƁ {}}} {:associative-length 1})"
               "((require :fennel.view) {:ǍǍǍ {} :ƁƁƁ {:ǍǍǍ {} :ƁƁƁ {}}} {:line-length 1})"
               (if _G.utf8 ; older versions of Lua can't indent this correctly
                   "{\"ƁƁƁ\" {\"ƁƁƁ\" {}\n        \"ǍǍǍ\" {}}\n \"ǍǍǍ\" {}}"
                   "{\"ƁƁƁ\" {\"ƁƁƁ\" {}\n           \"ǍǍǍ\" {}}\n \"ǍǍǍ\" {}}")
@@ -384,9 +382,9 @@
               "@1[@1[...]]"
               "(local t1 {}) (local t2 {:t1 t1}) (tset t1 :t2 t2) ((require :fennel.view) t1)"
               "@1{:t2 {:t1 @1{...}}}"
               "(local t1 {:a 1 :c 2}) (local v1 [1 2 3]) (tset t1 :b v1) (table.insert v1 2 t1) ((require :fennel.view) t1 {:sequential-length 1})"
               "(local t1 {:a 1 :c 2}) (local v1 [1 2 3]) (tset t1 :b v1) (table.insert v1 2 t1) ((require :fennel.view) t1 {:line-length 1})"
               "@1{:a 1\n   :b [1\n       @1{...}\n       2\n       3]\n   :c 2}"
               "(local v1 [1 2 3]) (local v2 [1 2 v1]) (local v3 [1 2 v2]) (table.insert v1 v2) (table.insert v1 v3) ((require :fennel.view) v1 {:sequential-length 1})"
               "(local v1 [1 2 3]) (local v2 [1 2 v1]) (local v3 [1 2 v2]) (table.insert v1 v2) (table.insert v1 v3) ((require :fennel.view) v1 {:line-length 1})"
               "@1[1\n   2\n   3\n   @2[1\n      2\n      @1[...]]\n   [1\n    2\n    @2[...]]]"
               "(local v1 []) (table.insert v1 v1) ((require :fennel.view) v1 {:detect-cycles? false :one-line? true :depth 10})"
               "[[[[[[[[[[...]]]]]]]]]]"
-- 
2.29.2
Details
Message ID
<87h7n1zuka.fsf@whirlwind>
In-Reply-To
<20210127172143.1492933-1-andreyorst@gmail.com> (view parent)
DKIM signature
missing
Download raw message
Thanks; applied and pushed.

-Phil
Reply to thread Export thread (mbox)