all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Inserting spaces after/before braces...
@ 2005-04-19  9:14 luca.spinacci
  2005-04-19 10:05 ` Peter Dyballa
  0 siblings, 1 reply; 5+ messages in thread
From: luca.spinacci @ 2005-04-19  9:14 UTC (permalink / raw)



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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Inserting spaces after/before braces...
  2005-04-19  9:14 Inserting spaces after/before braces luca.spinacci
@ 2005-04-19 10:05 ` Peter Dyballa
  2005-04-19 10:46   ` Peter Dyballa
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Dyballa @ 2005-04-19 10:05 UTC (permalink / raw)
  Cc: help-gnu-emacs


Am 19.04.2005 um 11:14 schrieb luca.spinacci@seleniacomms.com:

> I wrote a function to insert a space after an open brace and before a 
> close
> brace in a selection.

What about: (replace-regexp "\([()]\) *" "\1 ")?

Replace any occurance of a member of the set [()] followed by 0 or more 
SPC with that set's member plus a SPC. You can add to the set more 
members ...

--
Greetings

   Pete




--
Mit friedvollen Grüßen

   Pete

Linux bietet Lösungen für Probleme unter Windows, die mit Mac OS X gar 
nicht erst auftreten.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Inserting spaces after/before braces...
  2005-04-19 10:05 ` Peter Dyballa
@ 2005-04-19 10:46   ` Peter Dyballa
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Dyballa @ 2005-04-19 10:46 UTC (permalink / raw)
  Cc: emacs help


Am 19.04.2005 um 12:05 schrieb Peter Dyballa:

> What about: (replace-regexp "\([()]\) *" "\1 ")?
>

I think this is not exact, since "x)" wouldn't become "x )" -- maybe 
this is it:

	(replace-regexp " *\([()]\) *" " \1 " )

which is better, but ") )" would become ")  )": two stages/cases then?

Either	(replace-regexp " *\([()]\) *" " \1 " ) + (replace-regexp " *" " 
" )
or		(replace-regexp "( *" "( " )  + (replace-regexp " *)" " )" )

which is: either expand + run length compression, or expand this + 
expand that too.

--
Greetings

   Pete

"One person with a belief is a social power equal to ninety-nine who 
have only interests." - John Stuart Mill

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Inserting spaces after/before braces...
       [not found] <mailman.1968.1113902138.2895.help-gnu-emacs@gnu.org>
@ 2005-04-19 20:49 ` rgb
  2005-04-19 20:49 ` rgb
  1 sibling, 0 replies; 5+ messages in thread
From: rgb @ 2005-04-19 20:49 UTC (permalink / raw)



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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Inserting spaces after/before braces...
       [not found] <mailman.1968.1113902138.2895.help-gnu-emacs@gnu.org>
  2005-04-19 20:49 ` rgb
@ 2005-04-19 20:49 ` rgb
  1 sibling, 0 replies; 5+ messages in thread
From: rgb @ 2005-04-19 20:49 UTC (permalink / raw)



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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-04-19 20:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-19  9:14 Inserting spaces after/before braces luca.spinacci
2005-04-19 10:05 ` Peter Dyballa
2005-04-19 10:46   ` Peter Dyballa
     [not found] <mailman.1968.1113902138.2895.help-gnu-emacs@gnu.org>
2005-04-19 20:49 ` rgb
2005-04-19 20:49 ` rgb

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.