[Question]
  [
I like golfing in [tinylisp](https://github.com/dloscutoff/Esolangs/tree/master/tinylisp):
```
(d M(q((x)(i x(i(disp x)0(M x))0
```
But I also like posting explanations with nicely formatted code:
```
(d M
 (q
  ((x)
   (i x
    (i (disp x) 0 (M x))
    0))))
```
Can you help me generate the ungolfed code for my explanations?
## The task
Given a line of tinylisp code, return or output the same code, formatted to the following specifications:
### Input syntax
Tokens in tinylisp are `(`, `)`, or any string of one or more printable ASCII characters excluding parentheses or space. (I.e. the following regex: `[()]|[^() ]+`.) A non-parenthesis token is called an *atom*. Spaces are ignored, except insofar as they separate tokens.
For this challenge, the input code will consist of a single parenthesized list containing 0 or more items. The items in the list may be either (arbitrarily deeply nested) lists or single-token atoms (or a mixture). Two items may be separated by a single space; the space may also be omitted, unless it is necessary to separate two adjacent atoms. There will not be spaces anywhere else in the input; in particular, there will never be spaces immediately after an opening parenthesis or immediately before a closing parenthesis. Closing parentheses at the end of the expression may be omitted.
Some examples:
```
()
(1 2 3)
(1 2 3
(1 (2))
(1(2))
(1(2
(1((2 3))4
(((((xyz)))))
(((((
```
### Nesting levels
We define a *nesting level* for a tinylisp expression as follows:
* Atoms and the empty list `()` have a nesting level of 0.
* A nonempty list has nesting level N+1, where N is the maximum nesting level of its items.
Some examples:
```
Expression   Nesting level
()           0
(1 2 3)      1
(1 2 ())     1
(1 (2))      2
(1 ((2)) 3)  3
((((()))))   4
```
### How to ungolf
To ungolf a tinylisp expression, first **supply any missing closing parentheses**. Then, **add newlines and whitespace** according to the following rules:
* For an expression of nesting level 0, do not add any whitespace.
* For a list of nesting level 1 or 2, make sure the elements of the list are separated by a single space.
* Lists of nesting level 3 or higher must be broken across multiple lines:
	+ The first element of the list should be on the same line as the opening parenthesis, with no whitespace in between.
		- More specifically, the first element should *begin* on the same line. If the first item itself has nesting level 3 or higher, it will of course be spread over multiple lines itself.
	+ IF the second element of the list has nesting level 0 or 1, place it on the same line as the first, with a space in between; otherwise, if its nesting level is 2 or higher, place it on its own line.
	+ The third and subsequent elements of the list must each be on their own line.
* Elements on their own line must be indented by a number of spaces equal to how deeply they are nested in the expression. The top-level list should be indented 0 spaces, its elements 1 space, their elements 2 spaces, etc.
* The closing parenthesis at the end of a list should immediately follow the last element of the list, with no whitespace in between.
### A worked example
Suppose this is our input:
```
(d E(q((n)(i(l n 2)(s 1 n)(E(s n 2
```
First, supply missing close-parens:
```
(d E(q((n)(i(l n 2)(s 1 n)(E(s n 2))))))
```
The outermost list has nesting level 6, so it must be split over multiple lines. Its second element is `E` (nesting level 0), so we keep that on the same line. We place the third element on its own line, indented by one space.
```
(d E
 (q((n)(i(l n 2)(s 1 n)(E(s n 2))))))
```
The next list has nesting level 5. Its second element has nesting level 4, so it goes on its own line, indented by two spaces.
```
(d E
 (q
  ((n)(i(l n 2)(s 1 n)(E(s n 2))))))
```
The next list has nesting level 4. Its second element has nesting level 3, so it goes on its own line, indented by three spaces.
```
(d E
 (q
  ((n)
   (i(l n 2)(s 1 n)(E(s n 2))))))
```
The next list has nesting level 3. Its second element has nesting level 1, so it goes on the same line as the first element, separated by a space. We place the third and fourth elements on their own lines, indented by four spaces.
```
(d E
 (q
  ((n)
   (i (l n 2)
    (s 1 n)
    (E(s n 2))))))
```
The list `(s 1 n)` has nesting level 1 and thus goes on one line. It has spaces between its elements, so it is already ungolfed.
The list `(E(s n 2))` has nesting level 2 and thus goes on one line. It needs spaces between its elements.
Final result:
```
(d E
 (q
  ((n)
   (i (l n 2)
    (s 1 n)
    (E (s n 2))))))
```
## I/O requirements and clarifications
Your solution may be a program or function. You may use any of the [default I/O methods](https://codegolf.meta.stackexchange.com/q/2447/16766).
Input must be a string, a list of characters, or the nearest equivalent in your language. You may not take input as a nested list; parsing the input is part of the challenge.
Output may be a multiline string; it may also be a list of strings, each string representing one line. It may optionally contain trailing spaces and/or leading or trailing newlines. It may not contain extra leading spaces.
The input will always represent a single (possibly nested) list. Thus, it will always start with `(`, never an atom. The number of opening parentheses will be greater than or equal to the number of closing parentheses. The input will not have any leading or trailing whitespace. The input will consist only of printable ASCII characters; in particular, it will not contain newlines or tabs.
## Reference solution
Here's a reference solution in Python 3: [Try it online!](https://tio.run/##dVHBasMwDL3nK0ROMh0l7W5l3aWnwS5l0EuaQUoV6tV1MscdK@zfM8mxS1fYzdZ7enp66i7@0NrHYdCnrnUeHGWZb49kX3XvYcn/aaPtvjYG8/IdFVSTn@1b/gDadmePSmXZnhroatcThsYXT04tMvCOiAXKKgNDX2T4XWTQtA4CjQXgymc66CYCyyXkKpcS7BzVx3sMR6w/7@KI@@GCppGn@hvD@yE1lEUFE5gFVhCYsMmIsVcg09PiH4m7rjCSexz5s7NQBpaoC4NzvLWn2Rleky1niyplx5Gcao/Cllj3ZP0y5wjYhOx96ShgCnQPhnvFnKP@bOQ@nEYWsmD9Uy95Rzn5Jzl2JIIhfKmH7CUKdlHFeGMyzzAPy3PJkI2DU/GPn3JeBUu29cEWyGXHugg9pZ7klQNLNscTsKWRcOP@ymBn4cjUyZJbm3PDuMztiSIchOIR0jTBph@ttpg0lcxUTE3tsWM8Vue09XhzC6WGAfewwk/ENWwUalijRgNrKFTBvw3WuMKeqweGFTNW/PbyVoVSs18)
## Test cases
```
()
=>
()
(load library
=>
(load library)
(q(1 2
=>
(q (1 2))
(q((1)(2
=>
(q
 ((1) (2)))
(q '"""\
=>
(q '"""\)
(((((
=>
((((()))))
(d C(q((Q V)(i Q(i(l Q 0)0(i V(a(C(s Q(h V))V)(C Q(t V)))0))1
=>
(d C
 (q
  ((Q V)
   (i Q
    (i (l Q 0)
     0
     (i V
      (a
       (C
        (s Q (h V))
        V)
       (C Q (t V)))
      0))
    1))))
((q (g (c (c (q q) g) (c (c (q q) g) ())))) (q (g (c (c (q q) g) (c (c (q q) g) ())))))
=>
((q
  (g
   (c
    (c (q q) g)
    (c
     (c (q q) g)
     ()))))
 (q
  (g
   (c
    (c (q q) g)
    (c
     (c (q q) g)
     ())))))
(d f(q((x y z p)(i p(i(l p 0)(f(s x p)y(a z p)0)(i x(f(s x 1)(a y 1)z(s p 1))(i y(f x(s y 1)(a z 1)(s p 1))(f x y z 0))))(c x(c y(c z(
=>
(d f
 (q
  ((x y z p)
   (i p
    (i (l p 0)
     (f (s x p) y (a z p) 0)
     (i x
      (f (s x 1) (a y 1) z (s p 1))
      (i y
       (f x (s y 1) (a z 1) (s p 1))
       (f x y z 0))))
    (c x
     (c y (c z ())))))))
(def even? (lambda (num) (divides? 2 num)))
=>
(def even?
 (lambda (num) (divides? 2 num)))
(def odd? (lambda (num) (not (divides? 2 num))))
=>
(def odd?
 (lambda (num)
  (not (divides? 2 num))))
(def divides? (lambda (divisor multiple) (if (negative? divisor) (divides? (neg divisor) multiple) (if (negative? multiple) (divides? divisor (neg multiple)) (if (less? multiple divisor) (zero? multiple) (divides? divisor (sub2 multiple divisor)))))))
=>
(def divides?
 (lambda (divisor multiple)
  (if (negative? divisor)
   (divides? (neg divisor) multiple)
   (if (negative? multiple)
    (divides? divisor (neg multiple))
    (if (less? multiple divisor)
     (zero? multiple)
     (divides? divisor (sub2 multiple divisor)))))))
```
This is code-golf; the shortest answer in each language (in bytes) wins.
  
[Answer]
# [tinylisp](https://github.com/dloscutoff/Esolangs/tree/master/tinylisp), 1022 bytes
```
(load library
(d ? contains?
(d r reverse
(d O last
(d _(q((S T C)(i S(i(e(h S)32)(_(t S)(i C(c(r C)T)T)())(i(?(q(40 41))(h S))(_(t S)(c(h S)(i C(c(r C)T)T))())(_(t S)T(c(h S)C))))(r(i C(c(r C)T)T
(d @(q((T A D)(i T(@(t T)(c(+(w T)D)A)(+(w T)D))(r(c(+(w T)D)A
(d w(q((T)(-(e(h T)40)(e(h T)41
(d #(q((T A)(i A(#(c 41 T)(- A 1))(r T
(d E(q((T)(max(@ T()0
(d p(q((L A)(i A(p(c 32 L)(- A 1))L
(d n(q((D T A)(i(l 0(h D))(n(t D)(t T)(c(h T)A))(r(c(h T)A
(d N(q((T)(n(@ T()0)T(
(d H(q((T A)(i T(i(*(e(h T)40)(e(cadr T)41))(H(t(t T))(c(q(40 41))A))(H(t T)(c(h T)A)))(r A
(d W(q((L)(i(c()L)L(c L(
(d :(q((I L)(i I(:(- I 1)(t L))L
(d ;(q((L)(:(s(last-index(r(@(r L)()0))1)1)L
(d }(q((D T)(i(l 0(h D))(}(t D)(t T))(t T
(d f(q((T S P)(i T(f(t T)(concat S(i(e(h T)41)(c 41())(i(+(l(E(N(concat(; P)T)))3)(*(not((q((T)(}(@ T()0)T)))(t(; P))))(l(E(N T))2)))(p(W(h T))(- 1(?(q(()40))(O P))))(i(e(O P)40)(W(h T))(c 10(p(W(h T))(O(@ P()0))))))))(insert-end(h T)P))S
(d F(q((S)(string(f(H((q((T)(#(r T)(last(@ T()0)))))(_(chars S)()()))())()(
```
[Try it online!](https://tio.run/##zVVNT@MwEL3zKyxxGe@qku2mJYEDrfgQSBUgNRJHlE3LEqmk3TRa4MBv786M7XwUaLuLVrsttOPxzHvzxuO0zPKXWbZcrFYwmycTMcu@FUnxsgcTcSzSeV4mWb48pmUhiunPabGc0uJazJJlSdYd/AAYi1icSMjEGDKYwoMYy66RcAclWug@gRQKjIjxDRI9cIxpgRKBxhWFV8EpL9dyOMkGxC7iROILinYgFTSggmIxFKeEEsMA02LC/QpPaJzKoaxMAmhsUPoTp0vosI5YBkp6S9P@voMn8CHsQ4oaCL@DjCSmEFzFmYN5TJ5hgFVIRd4FeUc@eYHJXSNGVfKIYnKKORWWAmZCITlVmqMOlOTEUEFDVz/blHrlSHNHic0i90Wj5Bgxv7SkpcmkYHWIdgElExBDdT5Du9HiJZ1MecuKqNIU5EiOUNKISQ9p45LEZeISDlHiJUpEmJHTeeQyD2EJNEydLJ9Mn1HQALHRj@VLjW8OfnVNabfktW4Jf1LkvRU7FjdW7r2rfJ6nSVnNJ@vls7Pj@BVmcAZXLgyOMBsxZVdis/J5Ca6xr1VjqQU2jixOpioMrRZwyxR0rponHajXEq5dONVANh2AD02FVo3Ma2S64R7YF@A1nBZlZ5pPOAKBxiT3nK@fhGVZZPl3VHvha92nUZTcWl81A91B@pAUS7pkdK34aklYUevmxSP26Fzu7e2BWzhgAfiQKIWbCPnxtlah0FqL6ABNRePNHtUTEW0EvIFf2mzB0V1miwiip3aK5XC8jWjskIG4XUQP3F9kNmY0/ihuUwNYdf@gXVmoyRv2XX3UEFpXC9c668PPIOTIsBncp0XEwB6@hRI0KHTNhbF1kO63ghyHNaLNyuq@MZu3omjdcFEsXtsR8NYfxNeF6tr5HxRiL8L2SdDKtEdBG@s3lsIYy2nao8GO9dkgZz0cqsa2KQ7YQhG@nZe3LOEal1EfolVXygPp2kuojQRXXOQb1MCvqm2w6d4bwPV6K@8mCtPU3mpqPdo@2h61q8AvWjtmpxuula6YydSh@8brVk9maB@DET/7lNfGcujf7tUzrWzDLFiv5kHtFrTnzreVXI3izgVr7VyfKZad2j9QPlm@v0y793wb1xZJ6/m659QEFj5yJYYs0Ib4n7LmY4i5TbMnXGTX/sz1GyTaFbaJ@jdGYY1uJ@C/K2tn7G3SthzOe8q3cn8kTYUVebOAzXg7n6LxT4eAN/9Jp3pMhhfA3b5Pa3vvZ3D1Cw "tinylisp – Try It Online")
This took several ~~hours~~ days, but now it actually works.
This emits a couple of errors, which I think are unavoidable, and now a lot more which are avoidable.
-18 thanks to DLosc.
Because tinylisp doesn't have string literals, you'll need to pass your input through [this python script](https://tio.run/##hY1BDoIwEEX3nGLChpmNC9254SgGaMEx0JJ2IEHj2bEIAokxdtX8@e/9dpCrNadxVLoEsRdhM9TsW/Ti2FR0jgDAaemcgTJeUsBQEXgkkBxuls0Uo3UKC6LSOiiADSyCJ1EcRW34C@79MU6LintW2qfBmDW5ygCnxAdH09XCba0JkEtAo6tMuNcpLAWaqzMcrlv@k9wdVvQz91ashQWttfcbtlu@a2f/@HyXH7/R@cVE4/gC).
[Ungolfed](https://tio.run/##zVhLb@M2EL77V7CnSl0YEOVHrF6C3nvsvWBkOhIiS67EbJJfnw7JITmUZMvpomgBryORw5lvPs7Lq@r2o6mHy@dn0nTiyJr6qRf9R7pKyu58lq1aMaa6F9myQQklf2W/gcigWHdiyaD6un222wMrX/se5NfmNYVjf4gXOTDh5ctK9AN7kqV4HSRTVQffopdMiqGWPahhb13/wt5qVaWrVXKUJ/Yn6k4acX46CmOS2gvGkvoECHt4ss8Av1WibodHOKwBbHLGs5QllRZLUyNoRYMiXIRlb1gZcaMO3nr5XfYAm9hGOCDilc6cd69pZHkCcpuxLZ@AvApzaohsMQe6mu6wOxwa6Yrer/FTUW9T6u4NTqKjBIg77EAuXNmiQ17UOagNYJyVR3lRVYgzxGZXRVmmDGPMblhc/pTyHjMH8hueTd6quqzWFwj0dswsQr4paozP86BPB/fvMcistuA3lR35bj1eW8vyr1fRPOrwhHuKlPotTrcos9350kglJ9yKc/faKk@sfXXE@kOGIlDuQ2qNkoyPaCHG0fY109YmMTLSoOUhGf39IuDMxHNQL98v/Xo2bkxBOnXNsWFn8Z6jF9mixgsUYK@q8RRNGWKJETVqobA1s8To5XAPrXxXaw15PsgHExpoKWmYuWm743imKkLEwyOK@diHgiZ7kGyPJCZoIN8Q8ICv4jUgCRZXRua4tfw6CirRHhu5butmGozBeZrh9cn59EvINIx4gnybpdPtUhz7IMFD1kc4FOHSl1HaCwJt06P@DlwJjamM0yOm91lipx5oxGFmBCsrrDQ2U1ajSt7ojmY4joh@68Xlp0itiyv1cZGP@tjv4KHF1yDVxufGpS8OHyyJcGqR4oEVB1YUmh94huj3r1AmNM/@vk9dfxZqctd6hqjbo1Z/AXLWJKwm1z972zzchzMR7oL07BDlgCzqwZCsiICnsweIOYqRDA8k4GBgkj3tzo0c9EhBCxRJJwiWUmMemrqUkfpQQtkmavdPnaricaAe1oMETccxh/fC8DGfx0PCDUaZx@4mPb9uyiHGXTU/wRjW@WiJTWewxOQz9oCI/DSegb65O5yvCJHs/Vf7FQ7Y6E5OUaeeOjDmY5EwU1d4xqaszRM@7pzEemh2ETFiJhHu4wv1mEHZpfw44zHp3C@VwCwtK/Z3idGjL9/hRJUmS9anvjtHrVmjfnc1w7zYkkHFlWvMZt/3ZduW9ROxMCmXRJErkYPvsJrltdUawiYeD@MJ1TUBDSijcznSzmmf7OW5@w7lf2FiWJgWplrmhgaUVtPpbQmFnQMmUrfGgXTltYf6Nae27ZTmbOoAFk1SEW53K8hDzje6S20KttmaT65X4ftQwAcUfIIGF5cuUMkEABaubvPsAPq5boQ8y@xvXFjJdropcr41G/CH5wt6AKO2VmgVu@wuWSOuW252z4mIAcCV3zxBPgv@G6f3DzGwAzf87hGe5kO/@xdkzq7p@zgYyQMV3uOAAd9OfaRlS0zwYGv/QIT4PhJCG/ahWCIAWTPG3FNRjB9QyvjObQC4p38gH3DysPg/AOLGOpdoqqoH1rXy54G9QBkUrHp9hgkXshnK3AfUW3k61WVt//tqKXp4lsfhw3O7nltceW6B5nE4mYVxPOnFEFBZ0G2PoGKrSuv3Q@zIymFkK8@uavNZ6BTxsKq1kgMIrnCsEv0eLbHGdxOFY7x@9ZaJnPoekRrSwUnb@EAE7iXayW1RSFe3ywLPuDetH/kB/0KOhng@2NJZmHqZOeeMP/qf3QuZkFnGrLJdsAPOW6U7vODosA/guwFzjks/AtYscleFfhD@JAVFM3Qm7b5wDUvmF7wcn@c7dHBr1ReI@mB8tiKuI9J6ZmznlCYDcmO75Z4Y4QjslukvRMfI3F2K/1237ta95NrC5cx5vmj7mmvZwRunAG7ru/sWc1cwtmbzP2FqZ4xBAmBC/rBvc/00/fwb).
I only sorta understand this, but here's the basic algorithm the code follows:
* Convert the string to a list of characters for easier manipulation.
* Parse the string into a list of tokens
	+ Parentheses are left on their own, other tokens are grouped into lists.
* Iterate through the string, keeping a list of the previous tokens:
	+ If it's a `)`, immediately append it. Else:
	+ If:
		- Backtrack through the previous tokens to the start of the parent expression.
		- Use this index to get the depth of the parent expression, is it less than 3?
	+ *or*:
		- Backtrack to the parent expression
		- Remove the first parenthesis and remove the first expression after that.
		- Is it empty?
		- *and*:
			* is the current expression depth less than 2?
	+ If so, this token should go on the same line, possibly with a space.
	+ Else, it should be on a new line - get the depth of the current expression and indent by that.
* Finally, return the string.
[Answer]
# Python3, 629 bytes:
```
import re
d=lambda x,c=0:c if type(x)!=list or not x else max(d(i,c+1)for i in x)
def p(s):
 r=[];S=str.lstrip
 while s:
  if(c:=s[0])==')':s=S(s[1:]);break
  if c=='(':s=(l:=p(s[1:]))[1];r+=[l[0]]
  else:r+=[l:=re.findall('[^() ]+',s)[0]];s=S(s[len(l):])
 return r,S(s)
def f(r,t=0):
 j=lambda x:x if type(x)!=list else'()'
 k,s=[],0
 if all(d(i)<2 for i in r):k=[f(i,t+1)if d(i)else j(i)for i in r]
 else:
  for i,a in enumerate(r):
   D=d(a);F=f(a,t+1)if D else j(a)
   if not i:k+=[F]
   elif i==1 and D<2:k+=[F]
   else:k+=['\n'+' '*(t+1)+F]
 return'('+' '.join(k)+')'
g=lambda x:f(p(x+')'*((c:=x.count)('(')-c(')')))[0][0])
```
[Try it online!](https://tio.run/##jVNNb9pAEL37V0xz8UwgyNBLZbLKIVHuUaRegEoLXpMNi212TWr483TGfKVCJbXA9r735uutt9rUb2Xx/Ufldzu7rEpfgzdRppxeTjMNTXemknQGNod6Uxls6JtyNtRQeijKGhowLhhY6gYztN1Zp085UxZsAQ1FmcmhwkBpBF6NJsNXFWrfc3yzVQS/36wzEJjk/DhLVRglE1IqpjgN6hXDqJ9OaDj1Ri9aDcyYRCHRpao6CGjUnwx9R40ch09YKC2lLZAqb3q5LTLtHMajX0gw6cTdQKIc7ms4U6AjzsM9mnrtC/BdxvfN5@i7tUpkgPeTJ2lz6YfUjJHiCBbdwKN2k0hEUpeNofsBnHzxlC7UKGe7araLRSJobXznl7OMR2kn4YlasKsFNsV6abyuDXrpCuBJZahp@Kxy1MeMT3DIp0kkjMhm2XTBpjyLRcwzaJXqgy4yeLof/MVxVVnG4yLuxBDfouTtCLu3iDdB8N57aQtcUId3LJqf/cmxwkbAW5RtbXqzcl3UhBxGdzO@xUSyBbLdu8rbosY5intE0X4Z38W3g@S4EtKVOgNnp177zTXdCvswuC7APuF1CYzjm5ub8fiaSK5rfAaPUusFfhJaeEGLDl4goYRXP1HjIwZG35gmVjzyey3vlBD1r9ZdAc4BZ@1vBSuCOV0sSS74fyldnySXSRrYwBYqmaZqp6l4Gsx5jIbRDeqWTYRvDjAbrTmqT1teVvwUcoM5C0KLt0H8OLLMtFUS6YnbbPi/4f/2utV8Us2HKR4AD98g8inh2TL7YTMTHmAAAnwxJmcps@wiiRydy0xfpjpFnNIJEvgkL9eutpUznJsPIRZmrmv7YR7gIPjcuLBn/J@Rn4hT6LFcm@IkOIQ6E8I57FPlrfHlF/nCejq4DD19R7s/)
[Answer]
# Python 3, 388 bytes
Basically a golfed version of the reference solution @DLosc gave
```
import re
k=" "
def p(e,*t,l=0):
 for n in e:
  if")"==n:break
  if")">n:z=p(e);l=max(l,z[0]+1);t+=z,
  else:l=max(l,1);t+=n,
 return[l,*t]
t=p(iter(re.findall("[^() ]+|\S",input())[1:]))
def f(t,d=k):
 if[*t]==t:
  r="(";s=[f(i,d+k)for i in t[1:]]
  if t[0]>2:
   if len(t)>2and""in t[2]or t[2][0]<2:r+=s[0]+k;s=s[1:]
   q="\n"+d
  else:q=k
  return r+q.join(s)+")"
 return t
print(f(t))
```
[Try it online!](https://tio.run/##NVHNboMwDL7zFFZO9kAVZTe69CV2pExiJWgZaQghlQDt3ZnDBhfj78fxl7glfA32ddv0ww0@gFdJLwWIpFUdOFTZS8iMzKlMoBs8WNAWFDegO0FCSlt@etX0B3C15SrZRhcjH82MJlurvE7PdAmpXDOWKTOp8iD/cMu4V@HpbWX4vDoJPEIH5dGrU6dt2xiDovpAgjr9ub2LTFv3DEhUncuaaN@1w5C1so@L6q7iKVKGuKeXAsVlklWHOmvTnmIMHWOE6K73zfk/r69F1MfOKIuBrkVjWyF2ZVGzKxbWvRWlT@UUc/U8eIpjonGU4mZF2h4hRxmv5S8Y@HQ8fQ/a4kQp39MRGELivLYBeX2ibcOWg4yIMyywgiPU/AgaDTjIiUUTzIwu2OxsHvn5Hz4TowuXlVvHNZILdiyYdnw3cTlYZvZTcuIP76y7s/4OK/4C)
The regex used in the code `[^() ]+|\S` is the a shorter way of writing the regex `[()]|[^() ]+` given in the question by 2 bytes
`[*t]==t` is a sneaky trick to cut back 6 bytes instead of `type(t)==list`
`""in t[2]` is another trick to cut down 7 bytes instead of `type(t[2])!=list`
-3 thx to @pxeger
-1 thx to @aidenchow
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 330 bytes
```
^((\()|(?<-2>\))|[^()])+
$&$#2$*)
[^ (](?=\()|\)(?=[^) ])
$& 
{%`^(( *)\(+?([^() ]+ |((\()|(?<-5>\))|[^()])+(?(5)^) )+)(\(([^() ]+ |\(\) )*\([^)])
$1¶$2 $6
 ¶
¶
%+`^(( *)\(([^() ]+|((\()|(?<-5>\))|[^()])+(?(5)^))( [^() ]+| \([^()]+\))+)( [^() ]+| \([^()]+\))+$
$1¶$2$7
%+`^(( *)\(([^() ]+|((\()|(?<-5>\))|[^()])+(?(5)^))\)) 
$1¶$2
```
[Try it online!](https://tio.run/##nVDNjpswEL77KUYpaWeCKgHStpe2HHLoOZe9xETrFJNaIoEAiUKa59oH2BdLZyghkdLVVrVAtr@/@aCyjduY8xi/P50XiBrphPGXj9E3TXSaL5AS8pX33nsXeRNS8wVggvFXkWniw3xBkBALQP0aP3EATEijH6NYIfHhdM18uM3EGB@IzeQTC65yjZrBiWaEJDh8efYi8D4peHlW/Iz9YcrF9MYIQrgIQXeexGeV/xru9UO9z/8zjCHoA85nJIV5YVLI3bIyVatwiyFEsmFIKAf4MBqNtEJZClOYCjeDR0IHM3SYwwwCCvj2iAanWDP6k2lixZTPjZwpIAo5Ywu4AvzRPVvYEqzo7kqy4N@lJK0yaXWAFo5QSrOya1ZyM8y40oHRFk3HBsIfepg/0rArpCNfS96FbDFjQd3hnYm3C8tMNyWQyVzmwG/L71F@js3A7u0mBszNepkawM1uzT1Tt3eprWOIQICuMmuLNL2TbormL/reMOCDSZC6qGC9yxtX5pYTXMYpdmUat7cx9ILbEsJe8VedN8RgvYzrIgZBb81tXV9tN5OPtireyKt3y@je@mf9Bg "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
^((\()|(?<-2>\))|[^()])+
$&$#2$*)
```
Use a .NET balancing group to count how many extra `(`s there are and append that many trailing `)`s.
```
[^ (](?=\()|\)(?=[^) ])
$& 
```
Insert spaces before `(`s and after `)`s where necessary.
```
{`
```
Repeat until no more transforms can be made.
```
%`^(( *)\(+?([^() ]+ |((\()|(?<-5>\))|[^()])+(?(5)^) )+)(\(([^() ]+ |\(\) )*\([^)])
$1¶$2 $6
 ¶
¶
```
Split lists of nesting level 3 or more.
```
%+`^(( *)\(([^() ]+|((\()|(?<-5>\))|[^()])+(?(5)^))( [^() ]+| \([^()]+\))+)( [^() ]+| \([^()]+\))+$
$1¶$2$7
```
For those lists, where there are only lists of nesting level 0 or 1 left, put all but the first on their own line. (We need to check explicitly to ensure that the list was in fact split in the first place.)
```
%+`^(( *)\(([^() ]+|((\()|(?<-5>\))|[^()])+(?(5)^))\)) 
$1¶$2
```
Lists of nesting level 0 or 1 after a list of nesting level 2 or more also need to go on their own line. (We know they can't have also nesting level 2 or more because they would have been split off earlier, so we don't actually need to check their nesting level.)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 166 bytes
```
⊞υ⟦⟧≔ωηＦ⁺θ×)⁻№θ(№θ)«Ｆ№( )ιＦ›ηω«⊞§υ±¹⟦η¹⟧≔ωη»≡ι ω(⊞υ⟦⟧)«≔∨⊟υ⟦⟦ω⁰⟧⟧ι≔∧⊖Ｌι›³§§ι¹±¹δ≔⌈Ｅι⊕⊟κζＦ›⁴ζ≔⊖Ｌιδ≔Ｅ§ι⁰⁺§ (¬λκεＦδ⊞ε⁺⁺⊟ε ⊟§ι⊕κＦΦι›λδＦκ⊞ε⁺ λ⊞ε⁺⊟ε)⊞εζ⊞§υ±¹ε»≔⁺ηιη»✂⊟⊟υ⁰±¹
```
[Try it online!](https://tio.run/##dVLBbqMwED3DV4w4jSVWIto9tadoV60qbdtI21uUAzImWHGAYmgIVb@dzhhYoFI5YPnNm3lvxiOzuJJFbPp@19gMmxD2B3Hrb63VxxwvIWR0S4sKcGcai68hvOizshiIIIRHnRP2u2jymiMBoSHMVxEI/uDd91yFIRIgcK6mgEPvKxXXqsIshMtA9pyVbf2QJ6plS0/qSBTcCCq/J96GLXre2qT34Xv2omuZAWpXR8ZWQQDBDewqTcoXZg0gMrhseMQF4e9z6ecKd0WJDevuSSc6HARbX6hv8wT/KFmps8prleBflR/rjBwQcWrtZwhTN9OpqQux7Iz5ybLwY9zqc3Oms2T2Qz5rsKfTkNK5lNUgfzEqYCzznbcvWuXSWURx99wTFgDSkz0VNRrOPfFPzcqJGIapxrThRyYV8egBuFyxUlh24zqZi91pw13oeXyG3U7rcvqiReVDMEP@2sSkz2u4jHbz7ZsdU@M6JSqNG1PfTLN0dTNegP8r9@EPu/XPaKmc5rAwxIhWz3vb95hAiq@ILVyhg1KgBnpaNFDSxDFFCy2hV4xdNOJ4O8IbQeiVjo6uJZ0cvGJKBOtwl0THFKWIU4l4tiiJJ4kvoUO///FmPgE "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
⊞υ⟦⟧
```
Add a dummy container to the predefined empty list to hold the final result.
```
≔ωη
```
Start off with no atom.
```
Ｆ⁺θ×)⁻№θ(№θ)«
```
Append enough trailing `)`s to balance the input and loop over its characters.
```
Ｆ№( )ιＦ›ηω«⊞§υ±¹⟦η¹⟧≔ωη»
```
If the current character is one of `( )` then push any current token to the most recent expression. (Note that my nesting levels are one greater than those used by the question, because the nesting level of `()` evaluates to `1`.)
```
≡ι ω
```
If the current character is a space then do nothing more at this point.
```
(⊞υ⟦⟧
```
If the current character is a `(` then start a new subexpression.
```
)«
```
If the current character is a `)`:
```
≔∨⊟υ⟦⟦ω⁰⟧⟧ι
```
Get the latest expression, or an empty token if there wasn't one. (Since this makes `()` contain an empty token with a nesting level of `0`, its nesting level evaluates to `1`.)
```
≔∧⊖Ｌι›³§§ι¹±¹δ
```
Calculate whether the second term should be concatenated to the end of the first.
```
≔⌈Ｅι⊕⊟κζ
```
Calculate the depth of this term.
```
Ｆ›⁴ζ≔⊖Ｌιδ
```
If this term is shallow enough then concatenate all the terms together.
```
≔Ｅ§ι⁰⁺§ (¬λκε
```
Indent the first term, except for the first line, which is prefixed with a leading `(` instead.
```
Ｆδ⊞ε⁺⁺⊟ε ⊟§ι⊕κ
```
Concatenate the desired number of terms to the first term.
```
ＦΦι›λδＦκ⊞ε⁺ λ
```
Indent and append any remaining terms.
```
⊞ε⁺⊟ε)
```
Append a final `)` to the last line.
```
⊞εζ
```
Append the nesting level to this term.
```
⊞§υ±¹ε
```
Append this term to its parent expression.
```
»≔⁺ηιη
```
For any other character, append it to the current token.
```
»✂⊟⊟υ⁰±¹
```
Output the pretty-printed expression, excluding its nesting depth.
]