Emacs Command to Delete Up to Non-Whitespace Character

Cristian picture Cristian · Jan 15, 2009 · Viewed 16k times · Source

I often want to make a multiline function call and reduce it down to one line. For example, convert...

function_call(
     'first_arg',
     'second')

to

function_call('first_arg', 'second')

Does emacs have some commands to help with this. Specifically, is there a command that will delete all whitespace from the point to the first non-whitespace character?

Answer

Bill White picture Bill White · Jan 15, 2009

You might try delete-indentation, my favorite command for joining multiple lines into one line. In your example, put the cursor on the line with "second" and hit M-^ twice. Here are the docs:

M-^ runs the command delete-indentation, which is an interactive compiled Lisp function in simple.el.

It is bound to M-^.

(delete-indentation &optional arg)

Join this line to previous and fix up whitespace at join. If there is a fill prefix, delete it from the beginning of this line. With argument, join this line to following line.