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

feature request: opt out from y/n when ending up with unbalanced region #13

Open terlar opened 2 years ago

terlar commented 2 years ago

Sometimes for various reasons I end up with characters that will thinks it will cause unbalanced region while it actually won't. Over time I have found it quite annoying with the y/n question when I just want to fix a miss-typed character or similar.

For example if I in an emacs-lisp buffer press \ by accident I have to type another \ to be able to kill it or select the character and then use C-w and then answer the question y/n. This also happens when if I press ] instead of [ (which will create a balanced []). How do you usually handle these issue do I have especially fat fingers? I think there are other cases as well where I sometimes end up with unbalanced characters.

Now when I think about it, I guess perhaps using undo is a better solution, I just have gotten used to the magic of puni and tend to rely on editing operations to fix typos instead.

Anyways it might still be useful to have a config option to disable the unbalanced warning.

terlar commented 2 years ago

Another example is when using nix-mode which has content like this:

{ pkgs }:

{
  script = pkgs.writeShellScriptBin "script" ''
    cd ${toString ./.}
    echo hello
  '';
}

If I try to kill the line with cd it will only kill to $ so usually then I select the whole line and kills it which will result in a balanced expression. But it will complain about unbalanced expression due to how nix-mode defines it's syntax. Inside the ${} it is like a totally new scope. What I can do is remove the whole ${ ... } but not only ${ for example.

AmaiKinono commented 2 years ago

How do you usually handle these issue

I use puni-force-delete (I bind it to C-h).

It's meaningful to support deleting a "broken part", but maybe it'll be very hard. Let me think about this.

About the problem in nix-mode, I'll try it myself later.

QiangF commented 2 years ago

I think this kind of option is very convenient. Especially when I mark a region to delete and get the prompt. Puni is deliberately disobeying the user.

AmaiKinono commented 2 years ago

Now puni-backward/forward-delete-char handles "dangling delimiters". A "dangling delimiter" is a single char opening/closing delimiter that doesn't have a matched delimiter. So when you accidentally typed \ or ), you can just press DEL ;)

I do have some thoughts about extending this for multiple chars (e.g. when deleting a selected region, or for other deleting commands) but that seems somewhat difficult.

For the other two items:

Please allow for some more time.

AmaiKinono commented 2 years ago

A user option puni-confirm-when-delete-unbalanced-active-region is added.

@terlar I tried your example in nix-mode and I'm not sure if it should be fixed... Here's the result of my experiment. I use forward-sexp and backward-sexp (not the puni versions, but the ones defined by nix-mode) to find out all sexps that's in the same level of cd. Here are the boundaries of them:

image

It looks very weird to me:

There are some major modes utilizing SMIE that behaves weird. SMIE is not easy to make good use of.

Maybe Puni can be patched to fix this problem. The reason for me to do this:

The reason for me to not do this:

Since I'm not familiar with nix I'm thinking whether you have some idea, but I guess it's hard to fix.