Fork me on GitHub
#calva
<
2023-03-02
>
lspector19:03:15

Using tab to reindent a definition doesn't pull the start of a top level expression to the left margin. Is this intentional? Could it be changed? What I mean is that if I have for example a defn at the top level of my file, but the first line has for some reason been indented, then (assuming the definition is complete, with balanced brackets) tab will make the indention consistent with the top line, but not first pull that top line all the way to the left. I would prefer it to do so.

pez19:03:55

It’s not intentional, but an effect of how the formatter works. Could be fixed, of course. I think it happens quite seldom. When it happens to me I move the start of the form to column zero and format it.

lspector02:03:45

Happens seldom for me too in general, but lately I've seen and had to manually fix it (doing what you said, not just tab) in student code on several occasions. One situation that makes it happen is moving a definition from inside to outside of a rich comment. Interestingly, if I cut/paste a bunch of definitions that are all indented (maybe because I cut them from inside a rich comment but I'm pasting them outside) all but the first are correctly moved to the left margin when I paste. It's true that one can always fix it manually, but if there's an easy way to make pasting work for the only/first expression too, and for tab to do the right thing, that would be nice.

lspector03:03:41

Thinking about this a bit more, I bet the several instances of this that I saw in student code were a small fraction of the instances that happened, a bunch of which they probably didn't notice and hence were working in weirdly indented code that tab wasn't fixing. Students bring all sorts of unexpected typing/cutting/pasting habits with them, and it'd be great if tab would fix the indentation no matter what, ideally even if the brackets don't yet match.

pez05:03:50

You are welcome to file an issue.

skylize01:03:32

Easiest workaround is Shift+Tab with cursor directly in front of top-level form, repeated until reaching the margin, then format again. Reliable (and fast if you remember what keys to press) way to position the cursor correctly from anywhere within the form is Select Current Top Level Form (`Ctrl+Alt+A`) then Left-arrow.

lspector01:03:16

Actually I think for my students and me, if we need a workaround, it's easier to position by clicking and to move the first line to the margin by with a click (maybe click-drag to select) and delete. That doesn't require any specialized new knowledge. But the goal here is not to have a workaround; it's for tab to properly re-indent everything.

skylize02:03:24

> That doesn't require any specialized new knowledge. The part about positioning the cursor with the keyboard is specialized. That is why I set it in its own paragraph. Certainly using the mouse is a perfectly good alternative. But`Shift+Tab` is common across numerous editors for de-indent. It even works in Google Chrome Dev Tools. Good very-basic productivity knowledge for any developer to pick up as soon as you can come across any-reason-at-all to pick it up. Easy to learn and easy to remember because it's "add the Shift modifier do do the opposite of indenting with`Tab`". Outside of Clojure, it is wildly common to highlight a block of code and use either Tab or Shift+Tab for alignment. Calva (except for some mild bugs) takes that out of your hands by applying indent automatically with standardized formatting. That is why it is mostly-okay the Tab key is hijacked for applying formatting. > But the goal here is not to have a workaround; it's for tab to properly re-indent everything. The word "workaround" inherently implies not being a proper "solution". I was just offering ideas for hopefully reducing the pain while the issue is not solved. Take what you want from it.

lspector02:03:32

Thanks. I appreciate the help and am sorry if my phrasing implied otherwise. On "add the Shift modifier to do the opposite," I don't think that quite works here since we're using Tab for "fix up all of the indentation," not for "indent."

lspector03:03:26

Also FWIW the issue for beginners here, in my experience, isn't so much that they don't know how to move the first line back to the left margin, or that they want a better way to do that. The problem is that they don't realize that the indentation is wrong in the first place, and their code becomes a mess as a result. If Tab reliably fixes all of the indentation, then hitting Tab from time to time will clean things up in a really helpful way.