A utility to rewrite the ns declarations in clojure(script) files.
Notably, instead of just alphabetical order, it organizes requires into 3 groups:
clojure.*- everything else
current.project.*
For example:
(ns a.project.core
(:require
[a.project.stuff :as stuff]
[cheshire.core :as json]
[clojure.string :as string]
[com.rpl.specter :as x]
[a.project.other :as other]
[clojure.set :as set]))becomes:
(ns a.project.core
(:require
[clojure.set :as set]
[clojure.string :as string]
[cheshire.core :as json]
[com.rpl.specter :as x]
[a.project.other :as other]
[a.project.stuff :as stuff]))It handles meta and comments. See the comprehensive test's input and output.
See instructions for GRAAL here: https://github.com/taylorwood/lein-native-image
Run lein native-image to generate target/cljfmtns, which you can then move to /usr/bin/ or elsewhere
two arguments, in-file and out-file:
cljfmtns ./path/to/in-file.clj ./path/to/out-file.clj
one argument (overwrites the file):
cljfmtns ./path/to/file.clj
apply to every .clj, .cljs, .cljc file in a directory:
find ./ -type f -regex ".*\.clj(s|c)?" -exec ./path/to/cljfmtns {} \;
autocmd BufWritePost *.clj* !~/path/to/cljfmtns %:p
(defun cljfmtns ()
(make-process
:name "*cljfmtns*"
:command (list "~/path/to/cljfmtns" buffer-file-name)))
(defun add-cljfmt-hook ()
(add-hook 'after-save-hook #'cljfmtns nil t))
(add-hook 'clojure-mode-hook #'add-cljfmt-hook)
Install: https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave
Then, in settings.json:
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.clj*",
"isAsync": true,
"cmd": "cljfmtns ${file}"
}
]
}