On Thu, Mar 17, 2011 at 6:22 PM, Laurent PETIT <[email protected]> wrote:
> Lee, while we're at it.
>
> I decided to finally give it a try, and so I implemented an alternate
> behaviour for smart indent for ccw : the version of the gist does the
> following : it uses the following function to test whether we should indent
> by 2 or align with the first call argument :
>
> (def lisp-forms (into #{} (map str '(let fn binding proxy reify extend
> extend-protocol extend-type bound-fn
> if if-not if-let when when-not when-let
> when-first condp case loop dotimes
> for while do doto try catch locking dosync doseq
> dorun doall
> -> -?> >> future ns clojure.core/ns gen-class
> gen-interface))))
> (defn ^{:doc "Returns logical true if the String probably names a special
> form or macro var"}
> lisp-form? [s]
> (or
> (.startsWith s "def")
> (.startsWith s "with")
> (lisp-forms s)))
>
> The gist is here : https://gist.github.com/875245
>
> To test it with CCW 0.2.0.RC08, you just need to replace the content of the
> file :
> /path/to/your/eclipse/plugins/paredit.clj_0.12.5.STABLE01/paredit/core.clj
> with the content of the gist.
>
> Hope you'll like it, and, as usual, open to feedback (it passes paredit's
> automated test suite, but I haven't played a lot with it from ccw).
Nice, but let's exploit symbol metadata and naming conventions FTW:
1. If it's a { or a [ instead of a (, indent one space past the open
delimiter.
2. If it's a true special form (e.g., the operator is unqualified 'fn*,
'loop*, 'let*, 'def, or etc.) that takes a body, and we're in the
body, indent two spaces.
3. If it's a known macro that takes a body not named 'body, e.g.
clojure.core/fn, and we're in the body, indent two spaces.
4. If (=
(try
(let [v (first (:arglists (meta (resolve the-operator))))]
(subvec v (- (count v) 2)))
(catch IndexOutOfBoundsException _))
'[& body]), and we're in the body (count the args in the
arglist and in the form we're indenting), indent two spaces.
5. Otherwise, indent to the first parameter.
Note:
user=> (=
(try
(let [v (first (:arglists (meta (resolve 'loop))))]
(subvec v (- (count v) 2)))
(catch IndexOutOfBoundsException _))
'[& body])
true
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en