emacs regexp, adding a space between parenthesis in (i)

Would like to add a space between any character and an opening or closing parenthesis. But don’t add one if there is already one!

a) shows the openning and b) for the closing.

If you have more than one, like (()), you’ll need to run both (opening and closing) replacements twice, and another for three ‘(((‘!

Alt-x repl[TAB]reg[TAB][ENTER] or (C-M-%) to get:
M-x replace-regexp

a) Replace regexp in region: \((\)\([^[:space:]]\)
with: \1 \2

b) Replace regexp in region: \([^[:space:]]\)\()\)
with: \1 \2

Adding a ‘ // ‘ after every ‘}’ to do: if ( 1 ) { help(); } // if

C-M-%
Query replace regexp: \(}\)\([^[:space:]]\)
Query replace regexp \(}\)\([^[:space:]]\) with: \1 // \2

Advertisements

~ by nambabwe on 2013/03/08.

 
%d bloggers like this: