Coder Social home page Coder Social logo

Comments (3)

kkinnear avatar kkinnear commented on July 18, 2024 1

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.

kkinnear avatar kkinnear commented on July 18, 2024

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.

grzm avatar grzm commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.