9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] com: comments toggle in acme
@ 2012-11-13 23:13 Jacek Masiulaniec
  2012-11-16  4:16 ` 6o205zd02
  2012-11-16  9:55 ` Mark van Atten
  0 siblings, 2 replies; 4+ messages in thread
From: Jacek Masiulaniec @ 2012-11-13 23:13 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 872 bytes --]

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.

[-- Attachment #2: Type: text/html, Size: 2251 bytes --]

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

* Re: [9fans] com: comments toggle in acme
  2012-11-13 23:13 [9fans] com: comments toggle in acme Jacek Masiulaniec
@ 2012-11-16  4:16 ` 6o205zd02
  2012-11-16  8:15   ` Martin Kühl
  2012-11-16  9:55 ` Mark van Atten
  1 sibling, 1 reply; 4+ messages in thread
From: 6o205zd02 @ 2012-11-16  4:16 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 1109 bytes --]

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.


[-- Attachment #2: Type: text/html, Size: 3389 bytes --]

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

* Re: [9fans] com: comments toggle in acme
  2012-11-16  4:16 ` 6o205zd02
@ 2012-11-16  8:15   ` Martin Kühl
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Kühl @ 2012-11-16  8:15 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On Fri, Nov 16, 2012 at 5:16 AM,  <6o205zd02@sneakemail.com> wrote:
> BTW, I know what fmt is, but what do a- and a+ do?

indentation and un-indentation.
http://9fans.net/archive/2008/09/71



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

* Re: [9fans] com: comments toggle in acme
  2012-11-13 23:13 [9fans] com: comments toggle in acme Jacek Masiulaniec
  2012-11-16  4:16 ` 6o205zd02
@ 2012-11-16  9:55 ` Mark van Atten
  1 sibling, 0 replies; 4+ messages in thread
From: Mark van Atten @ 2012-11-16  9:55 UTC (permalink / raw)
  To: 9fans

Thanks, indeed!

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

case *.tex
c='%'

Mark.



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

end of thread, other threads:[~2012-11-16  9:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-13 23:13 [9fans] com: comments toggle in acme Jacek Masiulaniec
2012-11-16  4:16 ` 6o205zd02
2012-11-16  8:15   ` Martin Kühl
2012-11-16  9:55 ` Mark van Atten

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).