It's good that ctrl-backspace in emacs will delete all whitespace. However, it doesn't stop there! It seems to only stop after it's deleted at least one word. This means, for example, that using it here:
foo(bar)
<cursor>
Results in
foo(<cursor>
Which is really dumb (IMHO)! The behavior I would want is something akin to the following:
This seems like a much more reasonable Ctrl-Backspace, but honestly, if I could just get (1), it would be a huge improvement. Is there a package for this, or a setting? I don't really know emacs lisp but maybe pointing me to where the relevant APIs are...
I use following intellij-style smart backward-kill-word
(defun aborn/backward-kill-word ()
"Customize/Smart backward-kill-word."
(interactive)
(let* ((cp (point))
(backword)
(end)
(space-pos)
(backword-char (if (bobp)
"" ;; cursor in begin of buffer
(buffer-substring cp (- cp 1)))))
(if (equal (length backword-char) (string-width backword-char))
(progn
(save-excursion
(setq backword (buffer-substring (point) (progn (forward-word -1) (point)))))
(setq ab/debug backword)
(save-excursion
(when (and backword ;; when backword contains space
(s-contains? " " backword))
(setq space-pos (ignore-errors (search-backward " ")))))
(save-excursion
(let* ((pos (ignore-errors (search-backward-regexp "\n")))
(substr (when pos (buffer-substring pos cp))))
(when (or (and substr (s-blank? (s-trim substr)))
(s-contains? "\n" backword))
(setq end pos))))
(if end
(kill-region cp end)
(if space-pos
(kill-region cp space-pos)
(backward-kill-word 1))))
(kill-region cp (- cp 1))) ;; word is non-english word
))
(global-set-key [C-backspace]
'aborn/backward-kill-word)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With