Skip to content

Commit

Permalink
Format source.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkinnear committed Jun 7, 2023
1 parent c5947f1 commit d0bb27e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 64 deletions.
52 changes: 25 additions & 27 deletions src/zprint/comment.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@
style-vec]
#_(def wcsv style-vec)
(let [start-col (style-loc-vec (or (:indent options) 0) style-vec)
; We need this for top level comments.
top-level-border border
; We need this for top level comments.
top-level-border border
; If we are doing smart-wrap?, then use the border for smart-wrap.
; The smart-wrap border is used for the interior lines, and some
; very strange things can happen if a different border is used for
Expand All @@ -350,15 +350,16 @@
"fzprint-wrap-comments: style-vec:"
((:dzprint options) {:list {:wrap? true, :indent 1}} style-vec))
_ (dbg-s options #{:wrap} "fzprint-wrap-comments: start-col:" start-col)
; We need to special case top level comments here, and they aren't
; trivial to detect. Basically, if we have one element in the
; style-vec and it is a comment, we will consider it a top level
; comment. Then we will use top-level-border.
; We need to special case top level comments here, and they aren't
; trivial to detect. Basically, if we have one element in the
; style-vec and it is a comment, we will consider it a top level
; comment. Then we will use top-level-border.
wrap-style-vec
(if (and (= (count style-vec) 1)
(= (nth (first style-vec) 2) :comment))
(mapv (partial wrap-comment width top-level-border) style-vec start-col)

(if (and (= (count style-vec) 1)
(= (nth (first style-vec) 2) :comment))
(mapv (partial wrap-comment width top-level-border)
style-vec
start-col)
(mapv (partial wrap-comment width border) style-vec start-col))
#_(def wsv wrap-style-vec)
_ (dbg-s options
Expand Down Expand Up @@ -479,9 +480,7 @@
(and (= this-start-col start-col)
(= semi-count number-semis)
(= space-count current-spacing))
(if (match-regex-seq end-cg :end-cg nil s)
:end
:fit)
(if (match-regex-seq end-cg :end-cg nil s) :end :fit)
:else :next)))

(defn get-next-comment-group
Expand Down Expand Up @@ -629,14 +628,15 @@
idx)
end+start-cg
end+skip-cg
end-cg
end-cg
start-col
number-semis
current-spacing)]
(dbg-s options #{:fit-in-comment-group}
"get-next-comment-group: fit-in-comment-group:"
(pr-str s)
fit-return)
(dbg-s options
#{:fit-in-comment-group}
"get-next-comment-group: fit-in-comment-group:"
(pr-str s)
fit-return)
(cond
(= fit-return :fit)
; yes, this fits in the current group,
Expand All @@ -658,16 +658,14 @@
0 idx
1 number-semis
2 current-spacing)]

(= fit-return :end) [depth
; This one is in the cg
(assoc (conj out idx)
; The next one starts the
; next group
0 (inc idx)
1 number-semis
2 current-spacing)]

; This one is in the cg
(assoc (conj out idx)
; The next one starts the
; next group
0 (inc idx)
1 number-semis
2 current-spacing)]
:else
(throw
(#?(:clj Exception.
Expand Down
67 changes: 32 additions & 35 deletions src/zprint/config.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,14 @@
:border 0,
:smart-wrap? true,
:smart-wrap {:border 5,
; These regexes will end one comment group and
; start another comment group.
;
; These regexes need two groups at the begining,
; one to capture the semi's and one to capture
; whatever should be considered the spaces.
; These handle things like numbered and
; bulleted lists.
; These regexes will end one comment group and
; start another comment group.
;
; These regexes need two groups at the begining,
; one to capture the semi's and one to capture
; whatever should be considered the spaces.
; These handle things like numbered and
; bulleted lists.
:end+start-cg [; Line starts with single letter,
; but not a or I
#"^(;+)(\s*[b-zA-HJ-Z]\s+)"
Expand All @@ -537,32 +537,32 @@
; Line starts with two upper case
; chars
#"^(;+)(\s*)[A-Z][A-Z]"],
; These regexes will end the previous comment
; group and cause this line to be skipped and
; not included in the next comment group.
;
; These regexes should not have groups.
; These regexes will end the previous comment
; group and cause this line to be skipped and
; not included in the next comment group.
;
; These regexes should not have groups.
:end+skip-cg [; Blank line
#"^;+\s*$"
; Line where left paren is first
; and right paren last
; character in line.
;
; Unneeded given the one below that
; does a superset of this.
;
; Unneeded given the one below that
; does a superset of this.
#_#"^;+\s*\(.*\)$"
; Line containing only capitalized
; word followed by colon
#"^;+\s*[A-Z]\w+\:$"
; Line starting with any of ([{ or
; ending with any of }])
#"^;+\s*(\{|\(|\[|.*\)$|.*\}$|.*\]$)"]
; These regexes match lines which end a comment group
; but also remain in the comment group they are
; ending.
;
; These regexes should not have groups.
:end-cg []
; Line starting with any of ([{ or
; ending with any of }])
#"^;+\s*(\{|\(|\[|.*\)$|.*\}$|.*\]$)"],
; These regexes match lines which end a comment
; group but also remain in the comment group they
; are ending.
;
; These regexes should not have groups.
:end-cg [],
:max-variance 30,
:space-factor 3,
:last-max 5}},
Expand Down Expand Up @@ -974,16 +974,13 @@
:comment {:smart-wrap {:last-max 80,
:border 0,
:max-variance 200,
:space-factor 100


:end-cg [; If it ends with two lowercase alpha
; and a period, it ends a cg.
#"[a-z][a-z]\.$"]



}}},
:space-factor 100,
:end-cg [; If it ends with
; two lowercase
; alpha and a
; period, it ends
; a cg.
#"[a-z][a-z]\.$"]}}},
:moustache {:doc "Format moustache elements nicely",
:fn-map {"app" [:flow {:style :vector-pairs}]}},
:multi-lhs-hang {:doc "Allow multi-lhs-hang in all three places.",
Expand Down
4 changes: 2 additions & 2 deletions src/zprint/zprint.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4793,8 +4793,8 @@
(if (or changed? vector-fn-style?)
(fzprint-up-to-first-zloc caller options (+ ind l-str-len) zloc)
first-data)
; Get rid of the any vector surrounding the fn-style.
; Don't do this too soon, as multiple things are driven off of
; Get rid of the any vector surrounding the fn-style. Don't do
; this too soon, as multiple things are driven off of
; (vector? fn-style), above
fn-style (if (vector? fn-style) (first fn-style) fn-style)
; Finish finding all of the interesting stuff in the first two
Expand Down

0 comments on commit d0bb27e

Please sign in to comment.