help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inserting spaces after/before braces...


From: rgb
Subject: Re: Inserting spaces after/before braces...
Date: 19 Apr 2005 13:49:31 -0700
User-agent: G2/0.2

luca.spinacci@seleniacomms.com wrote:
> I wrote a function to insert a space after an open brace and before a
close
> brace
> in a selection. I would like it to work better skipping those
occurences
> where
> I already have a space before or after the brace.
>
> (defun brace-and-space(start end)
>  (interactive "*r")
>   (save-excursion
>     (save-restriction
>       (narrow-to-region start end)
>       (goto-char start)
>       (while (re-search-forward "(" nil t)

You could use this for your search string "\((\)\S-"
Then use (replace-match "( " nil t nil 1)

>         (replace-match "( " nil t))
>       (goto-char start)
>       (while (re-search-forward ")" nil t)

Like above, using "\S-\()\)" and (replace-match " )" nil t nil 1)

>         (replace-match " )" nil t)))))
>
> So, for instance
>
> if((a==1)) => if(_(_a==1_)_) as expected
>
> if(_(_a==1_)_ ) => if(__(__a==1__ ) __ ) as expected but I would like
it to
> skip
>
> the replace operation having a space
>
> after/before the brace
>
> Any suggestions?

If you use skeleton-pair for your parens you may want to look at
rgb-doublespace-maybe on www.emacswiki.org
It puts 2 spaces with the cursor between them if you type space
after typing a skeleton pair.  So (_ gives you (_^_) where _ are
spaces and ^ is the position of point.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]