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 authored and bbatsov committed Jun 25, 2021
1 parent 9f3ebb8 commit 09a690d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

## Unreleased

* [clojure-emacs/clj-refactor.el#459](https://github.com/clojure-emacs/clj-refactor.el/issues/459): `clean-ns` should conform to the style guide: `(:require` in the ns form should be followed by a newline.
* [#294](https://github.com/clojure-emacs/refactor-nrepl/pull/294): Properly skip uneval nodes when looking for the first/last sexp
* From now on, if you set the `clojure.tools.namespace.repl/refresh-dirs`, files outside said `refresh-dirs` won't be analyzed, resulting in safer, more efficient analysis.


## 2.5.1 (2021-02-16)

### Bugs fixed
Expand Down
2 changes: 1 addition & 1 deletion src/refactor_nrepl/ns/pprint.clj
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 09a690d

Please sign in to comment.