How to create a function like vim's ^u, but keeping parens balanced
sooheon opened this issue · comments
So I quite like ^u in vim, which is like C-a C-k
in emacs but without deleting the stuff after your cursor. Essentially CMD-backspace in your general editors. But we're dealing with parens so we need to keep pairs intact. When outside of parens, I want it to behave exactly like ^u does in vim. Within parens, I want it to behave like cc
using lispyville, but only deleting sexps which are before point.
((foo) (bar|) (baz))
should turn into((|) (baz))
((foo) (b|ar) (baz))
should turn into((|ar) (baz))
((foo) |(bar) (baz))
should turn into(|(bar) (baz))
Any ideas on how to achieve this?
I've been meaning to add a safe version of C-w
/evil-delete-backward-word
. As for C-u
, in vim it only deletes inserted text (not necessarily to the beginning of the line). If you just want to delete to the beginning of the line, there are various ways you could do it depending on whether you want it to behave like an operator or not (yank to the specified register). I'm guessing you wouldn't want it to copy the text, so you could just put something like (lispyville--safe-manipulate (line-beginning-position) (point) t)
in the command.
Ah my mistake, I think I meant C-u in terminals.
lispyville--safe-manipulate
works, is there a way to also indent properly afterwards? Essentially, is there an equivalent to (line-beginning-position) which returns where your cursor would be after _
in normal state?
You could use skip-chars-forward
for whitespace at (line-beginning-position)
(edit: this is what back-to-indentation
does; you could just use that). It would probably be simpler to just put an indentation function afterwards (e.g. (indent-for-tab-command)
).
Thanks! Yeah, indent-for-tab-command works exactly as intended.