I'm writing an IntelliJ-style "smart backspace" function which does the following:
- If the whole of the line up to the point is whitespace
- Join the line to the previous line, killing that whitespace
- Indent the line
- Otherwise, just delete a char as normal
I've got the smart backspace working, but the as normal part is proving difficult.
(defun smart-backspace ()
(interactive)
(if (beginning-of-line-text-p)
(progn (join-line)
(indent-according-to-mode))
(delete-backward-char 1)))
The problem is most language modes provide their own version of delete-backward-char
, so overriding backspace like this doesn't do handy (or crucial!) stuff such as paredit
/smartparens
' sp-backward-delete-char
, which keeps the sexp tree intact when you backspace over a closing delimiter.
What I'm asking is: is there a way to call the "default" binding for a key or mode from inside a function such as mine?