Skip to content

Instantly share code, notes, and snippets.

@andrewzhurov
Forked from joshkh/indentation.clj
Created April 6, 2020 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewzhurov/4f9463fdb2b8fe4735db73fe36b98de8 to your computer and use it in GitHub Desktop.
Save andrewzhurov/4f9463fdb2b8fe4735db73fe36b98de8 to your computer and use it in GitHub Desktop.
Clojure Indentation
(defn some-generic-function
"Demonstrate Clojure indentation and styles.
This doc string spans multiple lines, and the beginning of each line
is inline with the opening quotation mark"
[]
; ns :require values are aligned
; ns :import values are aligned
; but :require values do not align with :import values
(ns project.namespace
(:require [project-one.library]
[project-two.library])
(:import (java.util UUID)
(java.io Bits
StringBuffer
ByteArrayInputStream)))
; new lines in s-expression are indented by two spaces
'indented-by-two-spaces
; same-line comments are prepended with one space
:some-keyword ; and a comment here
; rest of arguments are aligned with first argument
(some-function :arg-a
:arg-b
:arg-c)
; map values are aligned
{:first-value 12345
:second-value 67
:and-the-third-value 890}
; let values are aligned
(let [the-first-result "first result"
another "second result"])
; case values align with case
(case :b
:is-b :b
:is-not-b (not :b))
; cond values are not aligned with function
(cond
(true? false) :a
(some? (not-empty [] :b))
:else nil)
; thread first macro arguments are aligned
(-> :value-one
:function-one
:function-two)
; thread second marco arguments are aligned
(->> :value-one
:function-one
:function-two)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment