AmaiKinono / puni

Structured editing (soft deletion, expression navigating & manipulating) that supports many major modes out of the box.
GNU General Public License v3.0
403 stars 21 forks source link

puni-kill-line removing the indentation after deleting empty lines #44

Closed vifon closed 1 year ago

vifon commented 1 year ago

Hello. I've noticed the following behavior in puni-kill-line:

(foo bar
|
     baz)
;; call `puni-kill-line'
(foo bar
|baz)

My expectation would be:

(foo bar
|
     baz)
;; call `puni-kill-line'
(foo bar
|    baz)

This code makes it look quite deliberate, but I don't see any good rationale for this behavior. It's neither consistent with the stock Emacs, nor useful in any common workflow I can think of. On the contrary, it seems to actively disrupt my workflow.

After investigating with git blame, I've found this commit. Is this possible this part is just a remnant of an older functionality that's no longer supported and should be removed?

This behavior is consistent in every major mode I've tried. Removing the indicated expression seems to fix it, but I don't know puni well enough to tell if it's intended after all or if there are any edge cases to consider.

AmaiKinono commented 1 year ago

Sorry for the late response.

This code makes it look quite deliberate, but I don't see any good rationale for this behavior. It's neither consistent with the stock Emacs, nor useful in any common workflow I can think of.

It is actually useful for me. See the discussion in https://github.com/AmaiKinono/puni/issues/16

Now i know there are people who likes and dislikes the behavior (thank you). I'll think about how to make both happy.

The solution proposed here seems to do a good job:

(define-advice puni-kill-line (:before (&rest _))
  "Go back to indentation before killing the line if it makes sense to."
  (when (looking-back "^[[:space:]]*")
    (back-to-indentation)))
vifon commented 1 year ago

Ah, it makes sense. Yes, I can see how you use this. This snippet probably won't work unless the empty line contains the indent already (I prefer them truly empty, just a newline), so for a time being I'll just maintain my own patch for myself, since I already have it working.

Thanks for the explanation!

hrehfeld commented 1 year ago

I also think the behavior is quite annoying :+1: . How do I disable it if the advice wont work?

vifon commented 1 year ago

If you're willing to edit the copy of puni on your disk, you can apply this commit: https://github.com/vifon/puni/commit/c3dbebc8b007691c36d1b1c89f71292c410feca4

AmaiKinono commented 1 year ago

I've redesigned the behavior to (hopefully) make everyone happy. Feel free to reopen this if you still find it inconvenient.