2011/3/18 Ken Wesson <kwess...@gmail.com> > On Thu, Mar 17, 2011 at 6:22 PM, Laurent PETIT <laurent.pe...@gmail.com> > 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. >
This is indeed the expected behaviour and what CCW is currently doing. The source code extract I put in the above thread was just a "delta" wrt the current behaviour. > 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. > Sure, this is the target solution. More complex than what I've done, though. And the gathering of the metadata is not easy, also. If we go the static analysis road, then some deps may not be distributed as source code and we may not be able to get the info. If we go the dynamic road, then the smart identation may behave differently depending on whether a REPL for the project is loaded or not, and if it is loaded, which parts of the application are in memory. But it's indeed a goal I'm willing to pursue sooner or later, since I have not forgotten the idea of CCW maintaining for the project a "background JVM" with all the project's code loaded (of course this should be configurable, since some projects with heavy macro doing IO or being cpu-intensive may not be appropriate for that). Cheers, -- Laurent > 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 clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en