sam-fans - fans of the sam editor
 help / color / mirror / Atom feed
* shorter struct regex?
@ 2000-03-18  5:24 James A. Robinson
  0 siblings, 0 replies; 4+ messages in thread
From: James A. Robinson @ 2000-03-18  5:24 UTC (permalink / raw)
  To: sam Fans

I'm starting to develop some mild RSI problems, and am trying to move away
from the mouse. This leads me to look at editors like vi or sam instead
of wily. In wily I end up using a pipe to sam half the time anyway, so
I'm working through using structured regular expressions while editing
my code in sam.

I just worked through a problem, and am wondering if there was a shorter
way to solve it.  I had a bunch of arrays defined in a java file:

...
public Hashtable return()
throws MissingRequiredValueException
{
	String[] req =
	{
		"order-id", "amount"
	};

	String[] opt =
	{
		"card-number", "card-exp", "card-name", "card-address", "card-city",
		"card-zip"
	};
	return processRequest("return", req, opt);
}
...

I wanted to expand the elements of the arrays to one per line. This is
what I used:

,x/{\n([^}]+\n)+	}/x/, +[^\n]/x/ +/c/\n		/

Is there way I could of done this with less work?


Jim

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
James A. Robinson                       jim.robinson@stanford.edu
Stanford University HighWire Press      http://highwire.stanford.edu/
650-723-7294 (W) 650-725-9335 (F)   


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

* Re: shorter struct regex?
       [not found] ` <200003230026.TAA06530@smtp3.fas.harvard.edu>
@ 2000-03-23 15:19   ` James A. Robinson
  0 siblings, 0 replies; 4+ messages in thread
From: James A. Robinson @ 2000-03-23 15:19 UTC (permalink / raw)
  To: sam Fans

> 	,x/{\n([^}]+\n)+	}/x/, +[^\n]/x/ +/c/\n		/
> 
> 	Is there way I could of done this with less work?
> 
> > In sam, highlight the suspect arrays and then ,s/, */,\n	/g
> would work.  This is a case where I think using the mouse
> makes more sense than typing all the gook.  

Ah, but the point was to do this without the mouse. =) Not because I'm
perverse, but because I had about 30 of these arrays in my program. Plus
I'm writing it in noweb, so I had a mix of latex documentation mixed in
with the code (which about doubles the size of the file).

> But if you want
> to type the gook, can't you just say
> 
> 	,x/{([^}]|\n)+}/,s/, */,\n	/g

The extra ',' in there before s/// would mess things up. But with a few
tweaks, like making sure it doesn't add a newline if one already exists:

	,x/{([^}]|\n)+}/s/, *[^\n]/,\n		/g

It works and would have saved 8 characters. Thank you!


Jim


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

* Re: shorter struct regex?
@ 2000-03-23  9:51 Bengt Kleberg
  0 siblings, 0 replies; 4+ messages in thread
From: Bengt Kleberg @ 2000-03-23  9:51 UTC (permalink / raw)
  To: sam-fans

> From: "James A. Robinson" <jim.robinson@stanford.edu>

> I wanted to expand the elements of the arrays to one per line.

> ,x/{\n([^}]+\n)+	}/x/, +[^\n]/x/ +/c/\n		/
This might be totally wrong, but I assume that since you have 'hard coded'
the 2 #\tab in the final c// expression I am allowed the same kind of
works-for-this-problem solution :-).
Presumable there is a way to get hold of the amount of #\tab and then use t to
copy it to the right place...

Anyway, my suggestion would be:
,x/	+".+\n/ x/ +/ c/\n		/


Best Wishes, Bengt
===============================================================
Everything aforementioned should be regarded as totally private
opinions, and nothing else. bengt@softwell.se
``His great strength is that he is uncompromising. It would make
him physically ill to think of programming in C++.''


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

* Re: shorter struct regex?
@ 2000-03-23  0:05 Byron Rakitzis
  0 siblings, 0 replies; 4+ messages in thread
From: Byron Rakitzis @ 2000-03-23  0:05 UTC (permalink / raw)
  To: jim.robinson; +Cc: sam-fans

> public Hashtable return()
> throws MissingRequiredValueException
> {
> 	String[] req =
> 	{
> 		"order-id", "amount"
> 	};
>
> 	String[] opt =
> 	{
> 		"card-number", "card-exp", "card-name", "card-address", "card-city",
> 		"card-zip"
> 	};
> 	return processRequest("return", req, opt);
> }
> ....
>
> I wanted to expand the elements of the arrays to one per line. This is
> what I used:
>
> ,x/{\n([^}]+\n)+	}/x/, +[^\n]/x/ +/c/\n		/
>
> Is there way I could of done this with less work?
>
>
> Jim

Jim,

One of my favorite tricks is a pipe to fmt. Fmt will preserve leading
whitespace (well, it can be trickier than that since fmt tries to do
pharagraph indentation as well). To force one-column output, you only
need to do "fmt -1", which strictly speaking denotes one-CHARACTER output,
but fmt does the right thing.

So:

 		"card-number", "card-exp", "card-name", "card-address", "card-city",
 		"card-zip"

piped through "fmt -1" gives (at least on this linux machine):

		"card-number",
		"card-exp",
		"card-name",
		"card-address",
		"card-city",
		"card-zip"

Of course, you still have the problem about selecting the braced-in
regions without using the mouse. Perhaps another out-of-the-box approach
is to pipe your entire code through a C beautifier. "indent" has so
many options, I would be surprised if array initializers one-per-line
was not one of them.

Byron.


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

end of thread, other threads:[~2000-03-23 21:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-18  5:24 shorter struct regex? James A. Robinson
2000-03-23  0:05 Byron Rakitzis
2000-03-23  9:51 Bengt Kleberg
     [not found] <rsc@plan9.bell-labs.com>
     [not found] ` <200003230026.TAA06530@smtp3.fas.harvard.edu>
2000-03-23 15:19   ` James A. Robinson

sam-fans - fans of the sam editor

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/sam-fans

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 sam-fans sam-fans/ http://inbox.vuxu.org/sam-fans \
		sam-fans@hawkwind.utcs.toronto.edu
	public-inbox-index sam-fans

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.sam-fans


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git