-
Notifications
You must be signed in to change notification settings - Fork 136
Fix #45: Thread first changes the indentation of the inner forms #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
1dfbc99
65e8156
b400730
e3c2e78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,10 +280,22 @@ | |
| (or (symbol-matches-key? (fully-qualified-symbol possible-sym context) key) | ||
| (symbol-matches-key? (remove-namespace possible-sym) key)))) | ||
|
|
||
| (defn- parent-is-thread-first? [zloc context] | ||
| (some #(form-matches-key? zloc % context) #{'-> 'as-> 'some-> 'cond->})) | ||
|
|
||
| (defn- is-first-parameter? [zloc] | ||
| (= (z/right (z/leftmost zloc)) zloc)) | ||
|
lambdank marked this conversation as resolved.
Outdated
|
||
|
|
||
| (defn- adjust-idx [zloc idx context] | ||
| (cond-> idx | ||
| (and (parent-is-thread-first? zloc context) (not (is-first-parameter? zloc))) | ||
| (some-> dec (max 0)))) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of (defn- in-thread-macro? [zloc context]
(and (form-matches-thread-macro? zloc) (not (first-argument? zloc))))Then we could write: (cond-> idx (in-thread-macro? zloc context) dec)I'm unsure why you have
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The index is the position of the child in the parent form, IIRC. So, come to thing about it, we could change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't the index come from the :indents as specified here? I also oversaw the Hope it makes sense.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes, I believe you're right. I need to refresh myself on the indentation logic as it's been a while since I've looked at it. |
||
|
|
||
| (defn- inner-indent [zloc key depth idx context] | ||
| (let [top (nth (iterate z/up zloc) depth)] | ||
| (let [top (nth (iterate z/up zloc) depth) | ||
| adjusted-idx (adjust-idx (z/up zloc) idx context)] | ||
| (when (and (form-matches-key? top key context) | ||
| (or (nil? idx) (index-matches-top-argument? zloc depth idx))) | ||
| (or (nil? idx) (index-matches-top-argument? zloc depth adjusted-idx))) | ||
| (let [zup (z/up zloc)] | ||
| (+ (margin zup) (indent-width zup)))))) | ||
|
|
||
|
|
@@ -302,9 +314,10 @@ | |
|
|
||
| (defn- block-indent [zloc key idx context] | ||
| (when (form-matches-key? zloc key context) | ||
| (let [zloc-after-idx (some-> zloc (nth-form (inc idx)))] | ||
| (let [adjusted-idx (adjust-idx (z/up zloc) idx context) | ||
| zloc-after-idx (some-> zloc (nth-form (inc adjusted-idx)))] | ||
| (if (and (or (nil? zloc-after-idx) (first-form-in-line? zloc-after-idx)) | ||
| (> (index-of zloc) idx)) | ||
| (> (index-of zloc) adjusted-idx)) | ||
| (inner-indent zloc key 0 nil context) | ||
| (list-indent zloc context))))) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.