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-backspace-function, passing it the prefix argument, if any.)
c-electric-backspacewhen it doesn't do an “electric” deletion of the preceding whitespace. The default value is
backward-delete-char-untabify(see Deletion, the function which deletes a single character.
c-electric-backspacebut 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-functionwith the prefix argument.)
c-electric-delete-forwardwhen it doesn't do an “electric” deletion of the following whitespace. The default value is
c-hungry-delete-forwarddirectly through their key sequences rather than using the minor mode toggling.
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
When this variable is non-
c-electric-delete will do
forward deletion with
c-electric-delete-forward, otherwise it
does backward deletion with
C-c <Delete> and C-c C-<Delete> are bound to
c-hungry-delete which is controlled in the same way by
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, might be helpful if you're having trouble with this in GNU Emacs.