From: "rgb" <rbielaws@i1.net>
Subject: Re: Inserting spaces after/before braces...
Date: 19 Apr 2005 13:49:30 -0700 [thread overview]
Message-ID: <1113943770.855982.54150@o13g2000cwo.googlegroups.com> (raw)
In-Reply-To: mailman.1968.1113902138.2895.help-gnu-emacs@gnu.org
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.
next parent reply other threads:[~2005-04-19 20:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1968.1113902138.2895.help-gnu-emacs@gnu.org>
2005-04-19 20:49 ` rgb [this message]
2005-04-19 20:49 ` Inserting spaces after/before braces rgb
2005-04-19 9:14 luca.spinacci
2005-04-19 10:05 ` Peter Dyballa
2005-04-19 10:46 ` Peter Dyballa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1113943770.855982.54150@o13g2000cwo.googlegroups.com \
--to=rbielaws@i1.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).