Comments (3)
This is fixed in 0.4.10. There is now a :how-to-ns
style which will give you what you want. Required a bit of development, sorry it took so long.
from zprint.
Good question! The answer is yes, in some environments, you can get what you want. It depends on how you are using zprint. Specifically, if you invoke zprint with {:list {:wrap? false :indent-arg 1}}
you will get the output you want for the (ns ...)
macro.
(zprint i46 {:parse-string? true :list {:hang? false :indent-arg 1}})
(ns com.example.my-application.server
"Example application HTTP server and routing."
(:refer-clojure :exclude [send])
(:require
[clojure.core.async :as async :refer [<! <!! >! >!!]]
[com.example.my-application.base]
[com.example.my-application.server.sse :as server.sse]
[io.pedestal.http :as http]
[io.pedestal.http.sse :as http.sse]
[ring.util.response :as response])
(:import
(java.nio.file Files LinkOption)
(org.apache.commons.io FileUtils)))
But if you format a whole file that way, you won't get uniform 2 space indents for all function arguments and without hang, it will look awful. However, if you use lein-zprint, you can put this line before your ns macro:
;!zprint {:format :next :list {:indent-arg 1 :hang? false}}
and just the ns macro will be formatted in that way, and the rest of the file will be formatted the default way. Of course, you may not want a comment at the top of the file. Note that the comment doesn't have to be immediately before the ns macro -- it can be separated by whitespace from the ns macro.
Alternatively, if you use the zprint-filter with your editor/ide, and use it to format individual functions while editing, the answer there is to invoke the zprint-filter with different arguments. The zprint-filter will read its first argument as an options map, so that you can define editor commands to invoke it with (or without) the above option map. Then you use the invocation with the above options for ns macros, and the other one for everything else.
Those are the two things you can do today to get the output you want.
I've thought about two enhancements, either of which would give you exactly what you want, just from setting the configuration.
- Connect an options map to a function in the
:fn-map
, so that you could change the options for:list
when zprint recognized:require
or:import
. That is easy to implement in the formatter, but a bit more work in the options map validator. - Extend a recent feature I added for vectors, where you can configure a function which will be called with the first element of every vector, and return nil or an options map to be used to format that vector. I could implement the same thing for lists. Certainly that would affect the performance, as there are a lot of lists, but it would easily give you what you want with a trivial function to recognize
:require
and:import
.
Let me know, if you would, how you a using zprint -- lein-zprint, zprint-filter, or some other way, and if the suggestions I've offered that work in today's code meet your needs. If not, I'll look into one of the other options I've suggested above.
from zprint.
Thanks for the quick response! I'm still evaluating zprint. I haven't adopted it yet into my workflow (though I'd like to) because of this (and other issues I'm still trying to nail down). My intent is to use it both via boot-fmt
and in Emacs/Cider.
I'm definitely interested in an option that would be available in configuration. I'm glad there's an option for overriding the configuration via comments, but I wouldn't want to add that to the top of every file.
from zprint.
Related Issues (20)
- Rest argument can be split from ampersand (&) HOT 4
- Version `1.2.4` with Babashka throws an exception HOT 3
- Minor bad interaction between :how-to-ns and :sall HOT 7
- Unexpected newline for def* forms HOT 2
- How to specify custom functions that can be justified, force-nl'ed HOT 1
- Ensuring that the second argument to `is` resides in its own line HOT 3
- Keeps running forever for a specific file HOT 8
- Hang vs flow vs third thing HOT 10
- -> formatting HOT 4
- Empty vectors are removed when using {:format :off} HOT 8
- [IDEA] Apply sorting (or other options) only to some key of a map HOT 2
- Backtranslate inline anonymous function reader macro HOT 7
- Problem with comment ;; and key-value-options both present HOT 3
- Is it possible to disallow trailing parens while using :respect-nl HOT 4
- Need to format twice to get to the end formatted state HOT 3
- How to force-nl on -> only when exceeds the width HOT 3
- Wired justify in bindings with map on the left HOT 14
- Indentation inside namespaced maps is wrong HOT 2
- `;!zprint {:format :off}` deletes the outer key from namespaced maps HOT 3
- Aliasing a function to another in :fn-map does not work on namespaced function calls HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zprint.