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

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

Inserting spaces after/before braces...


From: luca . spinacci
Subject: Inserting spaces after/before braces...
Date: Tue, 19 Apr 2005 11:14:22 +0200

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)
        (replace-match "( " nil t))
      (goto-char start)
      (while (re-search-forward ")" nil t)
        (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?

Thank you very much.
Luca.





reply via email to

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