If you want to delete an entire block of whitespace at point, you can use hungry deletion. This deletes all the contiguous whitespace either before point or after point in a single operation. “Whitespace” here includes tabs and newlines, but not comments or preprocessor commands. Hungry deletion can markedly cut down on the number of times you have to hit deletion keys when, for example, you've made a mistake on the preceding line and have already pressed C-j.
Hungry deletion is a simple feature that some people find extremely useful. In fact, you might find yourself wanting it in all your editing modes!
Loosely speaking, in what follows, <DEL> means “the backspace key” and <DELETE> means “the forward delete key”. This is discussed in more detail below.
There are two different ways you can use hungry deletion:
c-electric-backspace)c-backspace-function,
passing it the prefix argument, if any.)
c-backspace-functionc-electric-backspace when it doesn't
do an “electric” deletion of the preceding whitespace. The default
value is backward-delete-char-untabify
(see Deletion (GNU Emacs Lisp Reference Manual), the function which
deletes a single character.
c-electric-delete-forward)c-electric-backspace but in the forward direction. When it
doesn't do an “electric” deletion of the following whitespace, it
just does delete-char, more or less. (Strictly speaking, it
calls the function in c-delete-function with the prefix
argument.)
c-delete-functionc-electric-delete-forward when it
doesn't do an “electric” deletion of the following whitespace. The
default value is delete-char.
c-hungry-delete-backwards and
c-hungry-delete-forward directly through their key sequences
rather than using the minor mode toggling.
c-hungry-delete-backwards)2c-hungry-delete-forward)When we talk about <DEL>, and <DELETE> above, we actually do so without connecting them to the physical keys commonly known as <Backspace> and <Delete>. The default bindings to those two keys depends on the flavor of (X)Emacs you are using.
In XEmacs 20.3 and beyond, the <Backspace> key is bound to
c-electric-backspace and the <Delete> key is bound to
c-electric-delete. You control the direction it deletes in by
setting the variable delete-key-deletes-forward, a standard
XEmacs variable.
When this variable is non-nil, c-electric-delete will do
forward deletion with c-electric-delete-forward, otherwise it
does backward deletion with c-electric-backspace. Similarly,
C-c <Delete> and C-c C-<Delete> are bound to
c-hungry-delete which is controlled in the same way by
delete-key-deletes-forward.
Emacs 21 and later automatically binds <Backspace> and
<Delete> to DEL and C-d according to your environment,
and CC Mode extends those bindings to C-c C-<Backspace>
etc. If you need to change the bindings through
normal-erase-is-backspace-mode then CC Mode will also adapt
its extended bindings accordingly.
In earlier (X)Emacs versions, CC Mode doesn't bind either <Backspace> or <Delete> directly. Only the key codes DEL and C-d are bound, and it's up to the default bindings to map the physical keys to them. You might need to modify this yourself if the defaults are unsuitable.
Getting your <Backspace> and <Delete> keys properly set up can sometimes be tricky. The information in DEL Does Not Delete (GNU Emacs Manual), might be helpful if you're having trouble with this in GNU Emacs.