Skip to content

bloomventures/cljfmtns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cljfmtns (Clojure Format Namespace)

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.

To Build

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

Using

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 {} \;

Using with editors

Vim:

autocmd BufWritePost *.clj* !~/path/to/cljfmtns %:p

Emacs:

(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)

VSCode:

Install: https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave Then, in settings.json:

"emeraldwalk.runonsave": {
  "commands": [
    {
      "match": "\\.clj*",
      "isAsync": true,
      "cmd": "cljfmtns ${file}"
    }
  ]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •