You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a Question because I don't know if it's already possible, but it could very easily be just a thought experiment or puzzle for you, @kkinnear. Apologies for the vague title, you're far better at naming than I am!
Given:
(defsrcabcdfoobarqcdfooabaqfooacdbar
)
I'd like:
(defsrcabcdfoobarqcdfooabaqfooacdbar
)
I'm not sure if it's showing up correctly on GitHub, but the idea should hopefully be evident: without messing about with newlines (unless configured I suppose), insert whitespace between symbols on each line such that tokens are separated by no less than the spacing between their corresponding* pair on any other line.
*Corresponding = by appearance order on line, ie by column
Variable length rows are matched as much as possible, but otherwise use a single space between remaining columns or something.
This is only ever intended to be done with grids of symbols, and rarely with function calls - at best those would be very short and not multiline, but it would be user error if weird formatting arises aside those limits.
The context:
This actually isn't even for clojure - its for a pseudo lisp config dsl mostly shared between two very cool keyboard-remapping projects : kanata and kmonad. So it's almost certainly out of actual scope for zprint - though that's not to say someone out there might not benefit from it in clj 🤷.
Still, if you're interested in sharing how I might leverage zprint, or how I might attempt to implement it myself with rewrite-clj or something, that would be cool!!
Continuing, the use case is for the defsrc and deflayer forms, which expect just a sequence of symbols. However, it's common practice to grid-align the symbols so that they somewhat resemble a(n ortholinear) keyboard. Here's a sample config file which illustrates it perfectly.
I personally wanted to both experiment with and even suggest zprint as a formatter for those .kbd files, which in my estimation - at least for Kanata's more simple syntax - look like zprint-able files. Most forms are simple def-like or cond-like in structure and desired formatting, with the exception of the aforementioned defsrc/deflayer fns, which are structured like :force-nl and :arg1-force-nl respectively. That is, in addition to my envisioned grid rule.
Bonus:
If you've seen the sample file I linked above, you might already see this one coming:
Take:
(defsrcabcdfoobarqcdfooabarqfooacdbar
)
(hoping formatting is correct. This is a properly grid-aligned form, but there's been intentional whitespace between certain pairs of symbols such that they exceed their corresponding pair's spacing, yet still position the symbols along "valid" grid columns)
Given the above, I'd like the formatting to remain as-is.
The scenario is one where I've inputted the first, unformatted, example snippet above, ran zprint which produced the second, formatted snippet above, and then I added additional spacing to taste (eg like in the sample file, where spc is usually sorta-centered in the grid).
Then, at some later point, my IDE auto-formatting feature formats the whole file on save or something, but zprint preserves my other correct spacing in that particular form.
That was a mouthful, but hopefully this is at least somewhat interesting for you. Otherwise, apologies for the noise!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
This is a Question because I don't know if it's already possible, but it could very easily be just a thought experiment or puzzle for you, @kkinnear. Apologies for the vague title, you're far better at naming than I am!
Given:
I'd like:
I'm not sure if it's showing up correctly on GitHub, but the idea should hopefully be evident: without messing about with newlines (unless configured I suppose), insert whitespace between symbols on each line such that tokens are separated by no less than the spacing between their corresponding* pair on any other line.
*Corresponding = by appearance order on line, ie by column
Variable length rows are matched as much as possible, but otherwise use a single space between remaining columns or something.
This is only ever intended to be done with grids of symbols, and rarely with function calls - at best those would be very short and not multiline, but it would be user error if weird formatting arises aside those limits.
The context:
This actually isn't even for
clojure
- its for a pseudo lisp config dsl mostly shared between two very cool keyboard-remapping projects : kanata and kmonad. So it's almost certainly out of actual scope forzprint
- though that's not to say someone out there might not benefit from it inclj
🤷.Still, if you're interested in sharing how I might leverage
zprint
, or how I might attempt to implement it myself withrewrite-clj
or something, that would be cool!!Continuing, the use case is for the
defsrc
anddeflayer
forms, which expect just a sequence of symbols. However, it's common practice to grid-align the symbols so that they somewhat resemble a(n ortholinear) keyboard. Here's a sample config file which illustrates it perfectly.I personally wanted to both experiment with and even suggest
zprint
as a formatter for those.kbd
files, which in my estimation - at least forKanata
's more simple syntax - look like zprint-able files. Most forms are simpledef
-like orcond
-like in structure and desired formatting, with the exception of the aforementioneddefsrc/deflayer
fns, which are structured like:force-nl
and:arg1-force-nl
respectively. That is, in addition to my envisioned grid rule.Bonus:
If you've seen the sample file I linked above, you might already see this one coming:
Take:
(hoping formatting is correct. This is a properly grid-aligned form, but there's been intentional whitespace between certain pairs of symbols such that they exceed their corresponding pair's spacing, yet still position the symbols along "valid" grid columns)
Given the above, I'd like the formatting to remain as-is.
The scenario is one where I've inputted the first, unformatted, example snippet above, ran
zprint
which produced the second, formatted snippet above, and then I added additional spacing to taste (eg like in the sample file, wherespc
is usually sorta-centered in the grid).Then, at some later point, my IDE auto-formatting feature formats the whole file on save or something, but
zprint
preserves my other correct spacing in that particular form.That was a mouthful, but hopefully this is at least somewhat interesting for you. Otherwise, apologies for the noise!
Beta Was this translation helpful? Give feedback.
All reactions