Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Command to Delete Up to Non-Whitespace Character

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?

like image 713
Cristian Avatar asked Jan 15 '09 00:01

Cristian


People also ask

How do you delete text chunks in Emacs?

Move your cursor directly before the region you want to delete. Set a mark by pressing Ctrl-6 or Ctrl-^ . Move the cursor to the end of the region you want to delete and press Ctrl-k .

How do I remove spaces in emacs?

To delete trailing whitespace from the entire buffer, use 'M-x delete-trailing-whitespace' .

How do you delete words in Emacs?

Emacs provides many ways to delete text. The simplest way to delete text is to press the DEL key, which deletes the character immediately to the left of the cursor. See Figure 2-3 for possible locations of the DEL key on your keyboard. DEL is easiest to define by what it does: it deletes the previous character.


1 Answers

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.

like image 56
Bill White Avatar answered Sep 20 '22 14:09

Bill White