From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 Date: Tue, 13 Nov 2012 23:13:27 +0000 Message-ID: From: Jacek Masiulaniec To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=f46d042fddd2c1ce2704ce6890a1 Subject: [9fans] com: comments toggle in acme Topicbox-Message-UUID: d65e456e-ead7-11e9-9d60-3106f5b1d025 --f46d042fddd2c1ce2704ce6890a1 Content-Type: text/plain; charset=ISO-8859-1 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. --f46d042fddd2c1ce2704ce6890a1 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
= My latest addition to the acme column tag, alongside |a-, |a+, and |fmt.

#!/usr/bin/env rc

fn f {
= n=3D$1
if(! cat $f | cut -c1-$n | 9 grep -v '= ;^[=A0 ]+$' >/dev/null){=
x=3D`{f `{expr $n + 1}}<= /div>
echo '.'$&q= uot;x
}
}<= /div>

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

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

# Remove comment?
if(cat $f | 9 g= rep '^[=A0 ]*'$c' &= #39; >/dev/null){
cat $f | 9 sed 's|'$c' ||'
rm $f
exit
}

# Add comment.
s=3D`{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 motiv= ation was to avoid manual keying in of the comment characters, which I foun= d 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.
--f46d042fddd2c1ce2704ce6890a1--