From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <12284-1353039400-461956@sneakemail.com> Date: Thu, 15 Nov 2012 20:16:44 -0800 From: 6o205zd02@sneakemail.com User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 MIME-Version: 1.0 To: 9fans@9fans.net References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------070101040906010605010108" Subject: Re: [9fans] com: comments toggle in acme Topicbox-Message-UUID: d6dbbe68-ead7-11e9-9d60-3106f5b1d025 This is a multi-part message in MIME format. --------------070101040906010605010108 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 |9fans| wrote: > 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. --------------070101040906010605010108 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 |9fans| wrote:
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.

--------------070101040906010605010108--