Discussion:
[9fans] com: comments toggle in acme
(too old to reply)
Jacek Masiulaniec
2012-11-13 23:13:27 UTC
Permalink
My latest addition to the acme column tag, alongside |a-, |a+, and |fmt.

#!/usr/bin/env rc

fn f {
n=$1
if(! cat $f | cut -c1-$n | 9 grep -v '^[ ]+$' >/dev/null){
x=`{f `{expr $n + 1}}
echo '.'$"x
}
}

f=/tmp/com.$pid
cat >$f

switch($%){
case *.go *.c
c='//'
case *
c='#'
}

# Remove comment?
if(cat $f | 9 grep '^[ ]*'$c' ' >/dev/null){
cat $f | 9 sed 's|'$c' ||'
rm $f
exit
}

# Add comment.
s=`{f 1}
if(~ $#s 0)
cat $f | 9 sed 's|^|'$c' |'
if not
cat $f | 9 sed 's|^('$"s')|\1'$c' |'

rm $f

I name this |com. The original motivation was to avoid manual keying in of
the comment characters, which I found myself doing quite frequently for
short line ranges.

It also works well with Go's "imported and not used" error. Once plumbed to
the offending import line, it only takes one click to temporarily disable
an import.
6***@sneakemail.com
2012-11-16 04:16:44 UTC
Permalink
Nice. Thanks.

BTW, I know what fmt is, but what do a- and a+ do?

On 11/13/2012 3:13 PM, Jacek Masiulaniec jacekm-at-dobremiasto.net
Post by Jacek Masiulaniec
My latest addition to the acme column tag, alongside |a-, |a+, and |fmt.
#!/usr/bin/env rc
fn f {
n=$1
if(! cat $f | cut -c1-$n | 9 grep -v '^[ ]+$' >/dev/null){
x=`{f `{expr $n + 1}}
echo '.'$"x
}
}
f=/tmp/com.$pid
cat >$f
switch($%){
case *.go *.c
c='//'
case *
c='#'
}
# Remove comment?
if(cat $f | 9 grep '^[ ]*'$c' ' >/dev/null){
cat $f | 9 sed 's|'$c' ||'
rm $f
exit
}
# Add comment.
s=`{f 1}
if(~ $#s 0)
cat $f | 9 sed 's|^|'$c' |'
if not
cat $f | 9 sed 's|^('$"s')|\1'$c' |'
rm $f
I name this |com. The original motivation was to avoid manual keying
in of the comment characters, which I found myself doing quite
frequently for short line ranges.
It also works well with Go's "imported and not used" error. Once
plumbed to the offending import line, it only takes one click to
temporarily disable an import.
Martin Kühl
2012-11-16 08:15:37 UTC
Permalink
Post by 6***@sneakemail.com
BTW, I know what fmt is, but what do a- and a+ do?
indentation and un-indentation.
http://9fans.net/archive/2008/09/71
Mark van Atten
2012-11-16 09:55:16 UTC
Permalink
Thanks, indeed!

I added two lines so it can be used with Latex files too:

case *.tex
c='%'

Mark.

Loading...