calva icon indicating copy to clipboard operation
calva copied to clipboard

Paredit auto collapsing whitespace left of the cursor is disorienting

Open skylize opened this issue 3 years ago • 1 comments

I propose an (optional?) special case rule to block Paredit from removing any whitespace (or at least newlines) directly to the left of the cursor. Bonus if manually triggering format ignores the special case.


Why

Example cases ( | represents cursor, not pipe char.) :

(defn foo (|))
;; type backspace
;; ==>
(defn foo|)
(defn foo
  (|))
;; type backspace
;; ==>
(defn foo|)

My next action in these examples will be typing [ in place of an accidentally typed (. But whitespace gets collapsed, so instead of ( I must type Space> [ or Enter [.

The extra keystroke is of minimal importance. The problem here is the jarring movement of the cursor and loss of immediate context. This is especially disorienting in cases that collapse empty line(s).

Another example :

(let [fooooooooooooooooo {:a "a"}
      bar                [|]])
;; type backspace
;; ==>      
(let [fooooooooooooooooo {:a "a"}
      bar|])      

In this example the added keystrokes are important. I have already done extra work to carefully align the left bracket with the brace above it. Pressing Backspace wipes all that away. (Plus I have to use Space to fix it, because Calva hijacked Tab.)

skylize avatar Sep 12 '22 16:09 skylize

Thanks!

Iirc there is some code used by the backspace Paredit function that possibly can be put in use for this purpose as well. It might be a matter of recognizing the situation and skip post-edit formatting.

As for the bonus. If it is ”just” skipping post-edit, then we'll get the bonus for free. And if it is a matter of tweaking the formatting, it today considers if the formatting is happening as-you-type or on-demand, so this case can probably be handled there.

PEZ avatar Sep 12 '22 17:09 PEZ