Skip to content

Commit c2920f4

Browse files
committed
Update lispwords
Besides expanding the definitions into an easily maintainable style, we update the set of words for Clojure 1.5 using a simple rule: A function should only be indented specially if its first argument is special. This generally includes: * Definitions * Binding forms * Constructs that branch from a predicate What it does not include are functions/macros that accept a flat list of arguments (arglist: [& body]). Omissions include: clojure.core/dosync [& exprs] clojure.core/future [& body] clojure.core/gen-class [& options] clojure.core/gen-interface [& options] clojure.core/with-out-str [& body] Also added some symbols from clojure.test, since this namespace is present in many projects. Interestingly, clojure-mode.el includes "assoc" and "struct-map" in the special indent list, which makes a good deal of sense: (assoc my-map :foo "foo" :bar "bar") If we were to include this in lispwords, the following functions/macros should also be considered since they also take optional key value pairs at the end of the arglist: clojure.core/agent [state & options] clojure.core/assoc … [map key val & kvs] clojure.core/assoc! … [coll key val & kvs] clojure.core/atom … [x & options] clojure.core/ref [x] [x & options] clojure.core/refer [ns-sym & filters] clojure.core/restart-agent [a new-state & options] clojure.core/slurp [f & opts] clojure.core/sorted-map-by [comparator & keyvals] clojure.core/spit [f content & options] clojure.core/struct-map [s & inits]
1 parent 24110ac commit c2920f4

1 file changed

Lines changed: 80 additions & 19 deletions

File tree

indent/clojure.vim

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -314,26 +314,87 @@ else
314314

315315
endif
316316

317-
" Defintions:
318-
setlocal lispwords=def,def-,defn,defn-,defmacro,defmacro-,defmethod,defmulti
319-
setlocal lispwords+=defonce,defvar,defvar-,defunbound,let,fn,letfn,binding,proxy
320-
setlocal lispwords+=defnk,definterface,defprotocol,deftype,defrecord,reify
321-
setlocal lispwords+=extend,extend-protocol,extend-type,bound-fn
322-
323-
" Conditionals and Loops:
324-
setlocal lispwords+=if,if-not,if-let,when,when-not,when-let,when-first
325-
setlocal lispwords+=condp,case,loop,dotimes,for,while
326-
327-
" Blocks:
328-
setlocal lispwords+=doto,try,catch,locking,with-in-str,with-out-str,with-open
329-
setlocal lispwords+=dosync,with-local-vars,doseq,dorun,doall,future
317+
" Specially indented symbols from clojure.core and clojure.test.
318+
"
319+
" Clojure symbols are indented in the defn style when they:
320+
"
321+
" * Define vars and anonymous functions
322+
" * Create new lexical scopes or scopes with altered environments
323+
" * Create conditional branches from a predicate function or value
324+
"
325+
" The arglists for these functions are generally in the form of [x & body];
326+
" Functions that accept a flat list of forms do not treat the first argument
327+
" specially and hence are not indented specially.
328+
"
329+
" We make an exception for exception handling, since it is exceptional. :)
330+
331+
" Definitions
332+
setlocal lispwords=
333+
setlocal lispwords+=bound-fn
334+
setlocal lispwords+=def
335+
setlocal lispwords+=definline
336+
setlocal lispwords+=definterface
337+
setlocal lispwords+=defmacro
338+
setlocal lispwords+=defmethod
339+
setlocal lispwords+=defmulti
340+
setlocal lispwords+=defn
341+
setlocal lispwords+=defn-
342+
setlocal lispwords+=defonce
343+
setlocal lispwords+=defprotocol
344+
setlocal lispwords+=defrecord
345+
setlocal lispwords+=defstruct
346+
setlocal lispwords+=deftest " clojure.test
347+
setlocal lispwords+=deftest- " clojure.test
348+
setlocal lispwords+=deftype
349+
setlocal lispwords+=extend
350+
setlocal lispwords+=extend-protocol
351+
setlocal lispwords+=extend-type
352+
setlocal lispwords+=fn
353+
setlocal lispwords+=ns
354+
setlocal lispwords+=proxy
355+
setlocal lispwords+=reify
356+
setlocal lispwords+=set-test " clojure.test
357+
358+
" Binding forms
359+
setlocal lispwords+=as->
360+
setlocal lispwords+=binding
361+
setlocal lispwords+=doall
362+
setlocal lispwords+=dorun
363+
setlocal lispwords+=doseq
364+
setlocal lispwords+=dotimes
365+
setlocal lispwords+=doto
366+
setlocal lispwords+=for
367+
setlocal lispwords+=if-let
368+
setlocal lispwords+=let
369+
setlocal lispwords+=letfn
370+
setlocal lispwords+=locking
371+
setlocal lispwords+=loop
372+
setlocal lispwords+=testing " clojure.test
373+
setlocal lispwords+=when-first
374+
setlocal lispwords+=when-let
330375
setlocal lispwords+=with-bindings
331-
332-
" Namespaces:
333-
setlocal lispwords+=ns,clojure.core/ns
334-
335-
" Java Classes:
336-
setlocal lispwords+=gen-class,gen-interface
376+
setlocal lispwords+=with-in-str
377+
setlocal lispwords+=with-local-vars
378+
setlocal lispwords+=with-open
379+
setlocal lispwords+=with-precision
380+
setlocal lispwords+=with-redefs
381+
setlocal lispwords+=with-redefs-fn
382+
setlocal lispwords+=with-test " clojure.test
383+
384+
" Conditional branching
385+
setlocal lispwords+=case
386+
setlocal lispwords+=cond->
387+
setlocal lispwords+=cond->>
388+
setlocal lispwords+=condp
389+
setlocal lispwords+=if
390+
setlocal lispwords+=if-not
391+
setlocal lispwords+=when
392+
setlocal lispwords+=when-not
393+
setlocal lispwords+=while
394+
395+
" Exception handling
396+
setlocal lispwords+=catch
397+
setlocal lispwords+=try " For aesthetics when enclosing single line
337398

338399
let &cpo = s:save_cpo
339400

0 commit comments

Comments
 (0)