Re: [9fans] Acme Edit scriptlets

2013-04-05 Thread David Arroyo
I took the template.awk script from werc[0] and use it in acme all the
time. I've a collection of template files beginning with

Edit ,|tpl
% var1=val1
% var2=val2
...

I can execute line 1 to generate stuff like Makefiles, man pages, puppet
manifests, etc.[1]

[0]: http://hg.cat-v.org/werc/file/50a9b770bb43/bin/template.awk#l1
[1]: http://aqwari.us/notes/werctpl


On Thu, Apr 4, 2013 at 9:01 AM, Bence Fábián beg...@gmail.com wrote:

 whoa. nice job.



 2013/4/4 erik quanstrom quans...@quanstro.net

 On Thu Apr  4 08:17:13 EDT 2013, beg...@gmail.com wrote:

  Cool.
 
 
  Here's a script i use to generate case
  insensitive regexes. It turns
 
  FooBar
 
  into
 
  [Ff][Oo][Oo][Bb][Aa][Rr]

 see also rune(1), http://9atom.org/magic/man2html/1/rune
 which generalizes this idea to all of unicode (rune/case),
 and also to diacritical and other markers (rune/fold; rune/unfold).
 for the latter also see grep(1)'s -I flag,
 http://9atom.org/magic/man2html/1/grep

 - erik





Re: [9fans] Acme Edit scriptlets

2013-04-04 Thread Mark van Atten
On Friday, 29 March 2013 01:38:06 UTC+1, Bence Fábián  wrote:

 I did a quick writeup on little Edit scripts

Many thanks, this thread is very useful.

There is also Jason Catena's list of Edit idioms at
https://raw.github.com/catenate/acme-fonts/master/test/1/acme/Edit/sam

When editing and re-editing latex, I regularly pipe selections
through a simple-minded script called `chunk' which does most of
the work for obtaining semantic linebreaks. That goes back to a
recommendation by Kernighan in his paper `Unix for beginners' of
1974; see the quotation, comments and link at [1].



#!/usr/local/plan9/bin/rc 
# chunk up (to prepare) for semantic linebreaks

# do  not break within \cite 
# do not break within $$ math 
# break after closing parentheses ),] 
# break before an opening parentheses (,[

ssam -e 'x/(^[^%].+\n)+/  y/\\cite[^{]*{(\n|.)*}/ y/\$.*\$/
x/(([^A-Z]\.)|[,;:!?]|\)|\]) | (\(|\[)/ s/ /\n/' \ | 9 fmt -w 60
-j


For batch processing probably something more sophisticated would
be needed to leave various environments unchunked. But I don't use
it that way, and just apply it to selections where I know its use
makes sense. Usually these are areas where I have just been doing
a lot of rewriting.

There's no point in chunking up commented material, and sometimes
it is actually convenient to have a place where I can keep things
unchunked for reference.

The original chunk command in Writer's Workbench [2], for troff not
latex, was  based on a parser for English, I think. I find I don't
want that (because I write in other languages as well), and that
even in English I don't need it (because the chunking based on
interpunction is always fine with me, and where I care about the
remaining cases, I prefer to do it myself; but see [3]).

Mark.


[1] http://rhodesmill.org/brandon/2012/one-sentence-per-line/

[2] http://man.cat-v.org/unix_WWB/1/chunk

[3] https://github.com/waldir/semantic-linebreaker



Re: [9fans] Acme Edit scriptlets

2013-04-04 Thread dexen deVries
On Thursday 04 of April 2013 10:19:23 Mark van Atten wrote:
 On Friday, 29 March 2013 01:38:06 UTC+1, Bence Fábián  wrote:
  I did a quick writeup on little Edit scripts


(p9p specific)

attached is my dirty hack for automagic grepping of $% file or recursively %s 
dir or pipe.

a funky goodie:
automatically supplies `.' (dot) between arguments, so for example:

$ G some token here

becomes `grep some.token.here'


-- 
dexen deVries

[[[↓][→]]]


``we, the humanity'' is the greatest experiment we, the humanity, ever 
undertook. 
#!/usr/bin/env rc


. 9.rc


s=()
arg=()

fn addS {
if (~ $#s 0)
s=$1
if not
s=$s.$1
}

while (! ~ $#* 0) {
if (~ $1 -*)
arg=($arg $1)
if not
addS $1
shift
}


if (u test -p /dev/stdin) {
grep -n $arg $s
exit
}
if (test -f $%)
grep -n $arg $s /dev/null `{basename $%}
if not
find . -type f | grep -v 
'[.]/share/doc/doxygen/|/[.]git/|/[.]svn/|[.](mo|pot)$' | xargs grep -n $arg $s 
/dev/null


Re: [9fans] Acme Edit scriptlets

2013-04-04 Thread Bence Fábián
Cool.


Here's a script i use to generate case
insensitive regexes. It turns

FooBar

into

[Ff][Oo][Oo][Bb][Aa][Rr]

term% cat /bin/uncase
#!/bin/rc

exec awk '{
lower = tolower($0)
upper = toupper($0)
len = length($0)

for( i = 1 ; i = len ; i++ )
printf [ substr(upper, i, 1) substr(lower, i, 1) ]
printf \n
}'




2013/4/4 Mark van Atten vanattenm...@gmail.com

 On Friday, 29 March 2013 01:38:06 UTC+1, Bence Fábián  wrote:

  I did a quick writeup on little Edit scripts

 Many thanks, this thread is very useful.

 There is also Jason Catena's list of Edit idioms at
 https://raw.github.com/catenate/acme-fonts/master/test/1/acme/Edit/sam

 When editing and re-editing latex, I regularly pipe selections
 through a simple-minded script called `chunk' which does most of
 the work for obtaining semantic linebreaks. That goes back to a
 recommendation by Kernighan in his paper `Unix for beginners' of
 1974; see the quotation, comments and link at [1].



 #!/usr/local/plan9/bin/rc
 # chunk up (to prepare) for semantic linebreaks

 # do  not break within \cite
 # do not break within $$ math
 # break after closing parentheses ),]
 # break before an opening parentheses (,[

 ssam -e 'x/(^[^%].+\n)+/  y/\\cite[^{]*{(\n|.)*}/ y/\$.*\$/
 x/(([^A-Z]\.)|[,;:!?]|\)|\]) | (\(|\[)/ s/ /\n/' \ | 9 fmt -w 60
 -j


 For batch processing probably something more sophisticated would
 be needed to leave various environments unchunked. But I don't use
 it that way, and just apply it to selections where I know its use
 makes sense. Usually these are areas where I have just been doing
 a lot of rewriting.

 There's no point in chunking up commented material, and sometimes
 it is actually convenient to have a place where I can keep things
 unchunked for reference.

 The original chunk command in Writer's Workbench [2], for troff not
 latex, was  based on a parser for English, I think. I find I don't
 want that (because I write in other languages as well), and that
 even in English I don't need it (because the chunking based on
 interpunction is always fine with me, and where I care about the
 remaining cases, I prefer to do it myself; but see [3]).

 Mark.


 [1] http://rhodesmill.org/brandon/2012/one-sentence-per-line/

 [2] http://man.cat-v.org/unix_WWB/1/chunk

 [3] https://github.com/waldir/semantic-linebreaker




Re: [9fans] Acme Edit scriptlets

2013-04-04 Thread erik quanstrom
On Thu Apr  4 08:17:13 EDT 2013, beg...@gmail.com wrote:

 Cool.
 
 
 Here's a script i use to generate case
 insensitive regexes. It turns
 
 FooBar
 
 into
 
 [Ff][Oo][Oo][Bb][Aa][Rr]

see also rune(1), http://9atom.org/magic/man2html/1/rune
which generalizes this idea to all of unicode (rune/case),
and also to diacritical and other markers (rune/fold; rune/unfold).
for the latter also see grep(1)'s -I flag, 
http://9atom.org/magic/man2html/1/grep

- erik



Re: [9fans] Acme Edit scriptlets

2013-04-04 Thread Bence Fábián
whoa. nice job.



2013/4/4 erik quanstrom quans...@quanstro.net

 On Thu Apr  4 08:17:13 EDT 2013, beg...@gmail.com wrote:

  Cool.
 
 
  Here's a script i use to generate case
  insensitive regexes. It turns
 
  FooBar
 
  into
 
  [Ff][Oo][Oo][Bb][Aa][Rr]

 see also rune(1), http://9atom.org/magic/man2html/1/rune
 which generalizes this idea to all of unicode (rune/case),
 and also to diacritical and other markers (rune/fold; rune/unfold).
 for the latter also see grep(1)'s -I flag,
 http://9atom.org/magic/man2html/1/grep

 - erik




Re: [9fans] Acme Edit scriptlets

2013-03-29 Thread dexen deVries
On Friday 29 of March 2013 01:38:06 Bence Fábián wrote:
 I did a quick writeup on little Edit scripts
 (well basicly sam(1) scripts)
 If anyone have more feel free to contribute.
 Maybe someone could put them on the wiki even.

stuff i use:

# clear whole window -- usefull with +Errors
Edit ,d 

# decrease TAB indentation of selection
Edit s,^TAB,,g


# increase TAB indentation of selection
# the ^. part ensures we indent only lines with content
# and leave empty lines undisturbed
Edit s,^.,TAB,g

-- 
dexen deVries

[[[↓][→]]]




Re: [9fans] Acme Edit scriptlets

2013-03-29 Thread Peter A. Cejchan
Thanks, very nice, mates!
I humbly add some of minebelow.
Best, ++pac

#
## Latin
äëïñöüÿÄÅËÏÖÜ

## Greek
αβγδεζηθλμνξπρστφψωΓΔΘΛΞΠΣΦΨΩ

## select text

:;# select all text
:;25# select from start to line 25 (inclusive)
:25;# select from line 25 (inclusive) to EOF
Edit /;[ ]*\/\//# select from ; to // comments


## edit text
Edit s/^//g# increase indentation
Edit s,^,,g# decrease indentation
Edit s/^/\/\/ /g#comment out using //

Edit s/\n\n\n+/\n\n/g# remove redundant newlines, keep max two
Edit s/^[ ]+//g# remove leading whitespace
Edit s/[ ]+$//g# remove trailing whitespace
Edit s/ +/ /g# remove multiple spaces
Edit s/;$//g# remove trailing semicolon
Edit s/\*+\///g# comments
Edit s/\/\*+/\/\//g
Edit s/[\(\)]/ /g# remove ()
Edit s/.*/()/g# add ()
Edit s/.*/float64()/g# float64()
Edit s/.*/}  {/g# add }  {
Edit s/^/\/\/ /g# // comment out
Edit /;[ ]*\/\// Edit s/;//# find and remove semicolon before //
comments
Edit s/\+\+[a-zA-Z]+[0-9a-zA-Z]*/++/ Edit s/\+\+/d# NOT WORKING prefix
to postfix operator
Edit s/-/./g# struct pointer

Edit ,s/\+\+([A-Za-z]+[A-Za-z0-9]*)/\1++/g# prefix to postfix operator: ++
Edit ,s/\-\-([A-Za-z]+[A-Za-z0-9]*)/\1--/g# prefix to postfix operator: --

# prefix to postfix operator: ++i -- i++
Edit /\+\+[a-zA-Z_]+[0-9a-zA-Z_]*/{
x/\+\+/d
a/++/
}

Edit s/\+\+([A-Za-z]+[A-Za-z0-9]*)/\1++/ # prefix to postfix operator: ++i
-- i++

| 9 sed 's/\(//; s/(.*)\)/\1/' # remove outermost pair of parentheses
Edit s:\((.*)\):\1:g# remove outermost pair of parentheses





On Fri, Mar 29, 2013 at 2:19 AM, phineas.p...@gmail.com wrote:

  Hi!
 
  I did a quick writeup on little Edit scripts
  (well basicly sam(1) scripts)
  If anyone have more feel free to contribute.
  Maybe someone could put them on the wiki even.

 Nice idea...

 Here's a simple awk bit I use in Acme for centering text (its name is
 the center-line rune: ℄)

 #!/bin/rc
 # Center text
 awk '{l=length();s=int((70-l)/2); printf %(s+l)s\n,$0}'

 It doesn't seem to be common practice, but I like to name editing
 commands with unicode runes to save room: i.e.  ← and → for
 indentation (used with code), or ⇐ and ⇒ for indentation + a reformat
 (used for natural language next).  I find they serve a bit like icons.





Re: [9fans] Acme Edit scriptlets

2013-03-29 Thread Peter A. Cejchan
Maybe it's time for an Acme wiki page?
Also, could you share the plumbing rules you use (for my
inspiration/learning)?

Happy Easter, folks!
++pac

On Fri, Mar 29, 2013 at 9:20 AM, dexen deVries dexen.devr...@gmail.comwrote:

 On Friday 29 of March 2013 01:38:06 Bence Fábián wrote:
  I did a quick writeup on little Edit scripts
  (well basicly sam(1) scripts)
  If anyone have more feel free to contribute.
  Maybe someone could put them on the wiki even.

 stuff i use:

 # clear whole window -- usefull with +Errors
 Edit ,d

 # decrease TAB indentation of selection
 Edit s,^TAB,,g


 # increase TAB indentation of selection
 # the ^. part ensures we indent only lines with content
 # and leave empty lines undisturbed
 Edit s,^.,TAB,g

 --
 dexen deVries

 [[[↓][→]]]





Re: [9fans] Acme Edit scriptlets

2013-03-29 Thread dexen deVries
On Friday 29 of March 2013 09:25:47 Peter A. Cejchan wrote:
 Also, could you share the plumbing rules you use (for my
 inspiration/learning)?


1) re-format PHP's strange error mesages into standard 
FILE_PATHNAME:LINE_NUMBER


# ... called in FILE_PATHNAME on line LINE_NUMBER and defined in FILE_PATHNAME 
on line LINE_NUMBER

data matchesmultiline '.*rror.*called in ([^ ]+) on line ([0-9]+) and defined 
in ([^ ]+) on line ([0-9]+).*'
arg isfile $1
data set $file
attr add addr=$2
type is text
plumb to edit


#file / line in PHP format
data matchesmultiline '(.+) on line ([0-9]+).*'
arg isfile $1
data set $file
attr add addr=$2
type is text
plumb to edit


2) display php's function prototypes on right-click on a function name with an 
opening parenthesis. the `W' script greps a flat text file list of functions 
(with arguments and return types) and outputs to +Errors window.


type is text
data matches '[a-zA-Z_][a-zA-Z_0-9]*[(]'
plumb start W --wdir $wdir $data


* * *

a half-hearted support for displaying SQL table schema; again, `Wtable' is a 
script outputting definition of indicated table.

type is text
data matches '.*(FROM|JOIN)[ ]+([^ ]+).*'
data set $2
plumb start Wtable --wdir $wdir $data

-- 
dexen deVries

[[[↓][→]]]




Re: [9fans] Acme Edit scriptlets

2013-03-29 Thread Richard Miller
 # increase TAB indentation of selection
 # the ^. part ensures we indent only lines with content
 # and leave empty lines undisturbed
 Edit s,^.,TAB,g

Very nice.




Re: [9fans] Acme Edit scriptlets

2013-03-29 Thread Skip Tavakkolian
this also works:

# indent
Edit ,x/^./ y/./ c/ /

# outdent
Edit ,x/^   / c//

-Skip

On Fri, Mar 29, 2013 at 2:50 AM, Richard Miller 9f...@hamnavoe.com wrote:
 # increase TAB indentation of selection
 # the ^. part ensures we indent only lines with content
 # and leave empty lines undisturbed
 Edit s,^.,TAB,g

 Very nice.





[9fans] Acme Edit scriptlets

2013-03-28 Thread Bence Fábián
Hi!

I did a quick writeup on little Edit scripts
(well basicly sam(1) scripts)
If anyone have more feel free to contribute.
Maybe someone could put them on the wiki even.

http://bencef.com/blog/4/

bencef


Re: [9fans] Acme Edit scriptlets

2013-03-28 Thread phineas . pett
 Hi!
 
 I did a quick writeup on little Edit scripts
 (well basicly sam(1) scripts)
 If anyone have more feel free to contribute.
 Maybe someone could put them on the wiki even.

Nice idea...

Here's a simple awk bit I use in Acme for centering text (its name is
the center-line rune: ℄)

#!/bin/rc
# Center text
awk '{l=length();s=int((70-l)/2); printf %(s+l)s\n,$0}'

It doesn't seem to be common practice, but I like to name editing
commands with unicode runes to save room: i.e.  ← and → for
indentation (used with code), or ⇐ and ⇒ for indentation + a reformat
(used for natural language next).  I find they serve a bit like icons.