ccw-ide / ccw

Counterclockwise is an Eclipse plugin helping developers write Clojure code
https://github.com/laurentpetit/ccw/wiki/GoogleCodeHome
Eclipse Public License 1.0
219 stars 50 forks source link

Detect the indentation periodicity #653

Open laurentpetit opened 9 years ago

laurentpetit commented 9 years ago

Original issue 612 created by laurentpetit on 2014-01-20T10:46:38.000Z:

When you indent one form out of 2 for example (eg cond or a map).

Sample code:

(defn- unify-indents [a b](reduce-kv %28fn [a idx indent]
%28if-let [a-indent %28nth a idx%29] %28if %28or %28nil? indent%29 %28= a-indent indent%29%29 a %28reduced %28reduced nil%29%29%29 %28assoc a idx indent%29%29%29 a %28vec b%29))

(defn indent-period [indents](let [indents indents n %28count indents%29] %28loop [period [] indents indents] %28when-let [[indent & indents] %28and %28next indents%29 %28seq indents%29%29] %28let [period %28conj period indent%29] %28or %28reduce unify-indents period %28partition-all %28count period%29 indents%29%29 %28recur period indents%29%29%29%29%29))

Output: => (indent-period [0 0]) [0] => (indent-period [0 2 0]) [0 2] => (indent-period [0 2 0 2]) [0 2] => (indent-period [0 nil 0 2 0]) [0 2] => (indent-period [1 2 3]) nil

laurentpetit commented 9 years ago

Comment #1 originally posted by laurentpetit on 2014-07-17T13:10:32.000Z:

<empty>