Skip to content

Commit

Permalink
Improve pretty-printing of namespaces
Browse files Browse the repository at this point in the history
This makes the pretty-printed namespace form more in line with the
clojure style guide.

Specifically we go from:

```
(ns foo.bar
  (:require [this.library :as lib]))
```

To:

```
(ns foo.bar
  (:require
    [this.library :as lib]))
```

This commit closes clojure-emacs/clj-refactor.el#459
  • Loading branch information
expez committed Jun 24, 2021
1 parent e0accea commit 40aaf72
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/refactor_nrepl/ns/pprint.clj
Expand Up @@ -36,7 +36,7 @@

(defn pprint-require-form
[[_ & libspecs]]
(print "(:require ")
(print "(:require\n")
(dorun
(map-indexed
(fn [idx libspec]
Expand Down
23 changes: 12 additions & 11 deletions test/resources/artifacts_pprinted
@@ -1,13 +1,14 @@
(ns refactor-nrepl.artifacts
(:require [clojure
[edn :as edn]
[string :as str]]
[clojure.data.json :as json]
[clojure.java.io :as io]
[nrepl
[middleware :refer [set-descriptor!]]
[misc :refer [response-for]]
[transport :as transport]]
[org.httpkit.client :as http]
[refactor-nrepl.externs :refer [add-dependencies]])
(:require
[clojure
[edn :as edn]
[string :as str]]
[clojure.data.json :as json]
[clojure.java.io :as io]
[nrepl
[middleware :refer [set-descriptor!]]
[misc :refer [response-for]]
[transport :as transport]]
[org.httpkit.client :as http]
[refactor-nrepl.externs :refer [add-dependencies]])
(:import java.util.Date))
12 changes: 5 additions & 7 deletions test/resources/ns1_cleaned_and_pprinted
Expand Up @@ -8,13 +8,11 @@
:name com.domain.tiny
:extends java.lang.Exception
:methods [[binomial [int int] double]])
(:require [clojure data edn xml
[instant :as inst :reload true]
[pprint :refer [cl-format formatter get-pretty-writer]]
[string :refer :all :reload-all true]
[test :refer :all]
[walk :refer [postwalk prewalk]]]
clojure.test.junit)
(:require
[clojure data edn xml
[pprint :refer [cl-format formatter get-pretty-writer]]
[walk :refer [postwalk prewalk]]]
clojure.test.junit)
(:import [java.io Closeable FilenameFilter PushbackReader]
[java.util Calendar Date Random]
[refactor.nrepl SomeClass$InnerClass$InnerInnerClassOne SomeClass$InnerClass$InnerInnerClassTwo]))
3 changes: 2 additions & 1 deletion test/resources/ns_with_gen_class_methods_meta_clean.clj
Expand Up @@ -4,4 +4,5 @@
^:test [bar [String] String]
^{:other "text"} [baz [String] String]]
:name Name)
(:require [clojure.pprint :refer [fresh-line]]))
(:require
[clojure.pprint :refer [fresh-line]]))
3 changes: 2 additions & 1 deletion test/resources/ns_with_lots_of_meta_clean.clj
Expand Up @@ -6,4 +6,5 @@
^:test [bar [String] String]
^{:other "text"} [baz [String] String]]
:name Name)
(:require [clojure.pprint :refer [fresh-line]]))
(:require
[clojure.pprint :refer [fresh-line]]))

0 comments on commit 40aaf72

Please sign in to comment.