zsh-users
 help / color / mirror / code / Atom feed
* What would you say is the most-used way of indenting case labels
@ 2006-08-11 10:54 Nikolai Weibull
  2006-08-11 11:10 ` Peter Stephenson
  2006-08-11 14:22 ` Phil Pennock
  0 siblings, 2 replies; 9+ messages in thread
From: Nikolai Weibull @ 2006-08-11 10:54 UTC (permalink / raw)
  To: Zsh Users' List

That is, is this style:

case something in
(*ome*)
  ... ;;
esac

more common than

case something in
  (*ome*)
    ... ;;
esac

I'm trying to set a default for a shell-script indentation script.

Thanks.

  nikolai


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

* Re: What would you say is the most-used way of indenting case labels
  2006-08-11 10:54 What would you say is the most-used way of indenting case labels Nikolai Weibull
@ 2006-08-11 11:10 ` Peter Stephenson
  2006-08-11 12:47   ` Nikolai Weibull
  2006-08-11 14:22 ` Phil Pennock
  1 sibling, 1 reply; 9+ messages in thread
From: Peter Stephenson @ 2006-08-11 11:10 UTC (permalink / raw)
  To: Zsh Users' List

"Nikolai Weibull" wrote:
> That is, is this style:
> 
> case something in
> (*ome*)
>   ... ;;
> esac
> 
> more common than
> 
> case something in
>   (*ome*)
>     ... ;;
> esac

I use Emacs sh-script mode and I end up with things looking like this

case foo in
  (bar)
  do_foo_bar
  ;;

  (rod)
  do_foo_rod
  ;;
esac

which is pretty much your second option, except there's no additional
indentation after the test and the separate ;; serves
as a visual end marker (like a "break" in C).  The zsh code seems to be
full of things like:

case foo in
  (bar)
    do_foo_bar
    ;;
  (rod)
    do_foo_rod
    ;;
esac

sometimes with a space between the ;; and the next test, sometimes without,
sometimes with the ;; level with the test, sometimes indented as shown.
However, there are other variations, too, including having the ";:" on the
same line as the last chunk of code, which seems to be more common when
there's only one line of executable code (which then sometimes appears on
the line with the test).

The only consensus seems to be the "(bar)" test is indented from the
"case".

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


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

* Re: What would you say is the most-used way of indenting case labels
  2006-08-11 11:10 ` Peter Stephenson
@ 2006-08-11 12:47   ` Nikolai Weibull
  2006-08-11 12:48     ` Nikolai Weibull
  0 siblings, 1 reply; 9+ messages in thread
From: Nikolai Weibull @ 2006-08-11 12:47 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh Users' List

On 8/11/06, Peter Stephenson <pws@csr.com> wrote:
> "Nikolai Weibull" wrote:
> > That is, is this style:
> >
> > case something in
> > (*ome*)
> >   ... ;;
> > esac
> >
> > more common than
> >
> > case something in
> >   (*ome*)
> >     ... ;;
> > esac
>
> I use Emacs sh-script mode and I end up with things looking like this
>
> case foo in
>   (bar)
>   do_foo_bar
>   ;;
>
>   (rod)
>   do_foo_rod
>   ;;
> esac
>
> which is pretty much your second option, except there's no additional
> indentation after the test and the separate ;; serves
> as a visual end marker (like a "break" in C)

Hm, actually, my examples were a bit flawed.  It should have been:

case something in
  (*ome*)
    ...
  ;;
esac

But it seems that that kind of indenting is oncommon.  Argh, so many
choices, so little to gain.

> The only consensus seems to be the "(bar)" test is indented from the
> "case".

Actually, I found quite a few cases where "(bar)" wasn't indented from
the "case", so that's why I asked.


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

* Re: What would you say is the most-used way of indenting case labels
  2006-08-11 12:47   ` Nikolai Weibull
@ 2006-08-11 12:48     ` Nikolai Weibull
  0 siblings, 0 replies; 9+ messages in thread
From: Nikolai Weibull @ 2006-08-11 12:48 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh Users' List

On 8/11/06, Nikolai Weibull <now@bitwi.se> wrote:

> But it seems that that kind of indenting is oncommon.

Um, "oncommon"?  I mean "uncommon", of course.

  nikolai


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

* Re: What would you say is the most-used way of indenting case labels
  2006-08-11 10:54 What would you say is the most-used way of indenting case labels Nikolai Weibull
  2006-08-11 11:10 ` Peter Stephenson
@ 2006-08-11 14:22 ` Phil Pennock
  2006-08-11 19:37   ` Peter Stephenson
  1 sibling, 1 reply; 9+ messages in thread
From: Phil Pennock @ 2006-08-11 14:22 UTC (permalink / raw)
  To: Zsh Users' List

On 2006-08-11 at 12:54 +0200, Nikolai Weibull wrote:
> I'm trying to set a default for a shell-script indentation script.

Or, if you want to be puzzled, shove a function into zsh and look at
what "zsh -f" produces.  Valid, there's logic to it, but it doesn't
match the writing style of anyone I know.  ;^)

% function foo { case $1 in (a) print alpha; print second; print third;;
	(b) print beta;; (*) print omega;;esac }

% whence -f foo
foo () {
        case $1 in
                (a) print alpha
                        print second
                        print third ;;
                (b) print beta ;;
                (*) print omega ;;
        esac
}

The same output comes if you spread things out more when entering it.
So the first line of the action is always shown inline with the
conditional value and the subsequent lines are indented further.
-- 
VISTA: Viruses, Infections, Spyware, Trojans & Adware


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

* Re: What would you say is the most-used way of indenting case labels
  2006-08-11 14:22 ` Phil Pennock
@ 2006-08-11 19:37   ` Peter Stephenson
  2006-08-12 15:28     ` Bart Schaefer
  2006-08-12 16:44     ` Wayne Davison
  0 siblings, 2 replies; 9+ messages in thread
From: Peter Stephenson @ 2006-08-11 19:37 UTC (permalink / raw)
  To: Zsh Users' List

Phil Pennock wrote:
> % function foo { case $1 in (a) print alpha; print second; print third;;
> 	(b) print beta;; (*) print omega;;esac }
> 
> % whence -f foo
> foo () {
>         case $1 in
>                 (a) print alpha
>                         print second
>                         print third ;;
>                 (b) print beta ;;
>                 (*) print omega ;;
>         esac
> }

Time for some audience participation.  Do you prefer the following
style?

foo () {
        case $1 in
                (a) print alpha
                print second
                print third
                ;;
                (b) print beta
                ;;
                (*) print omega
                ;;
        esac
}

Vote now.  Lines are open.

Index: Src/text.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/text.c,v
retrieving revision 1.16
diff -u -r1.16 text.c
--- Src/text.c	10 Jan 2006 16:57:06 -0000	1.16
+++ Src/text.c	11 Aug 2006 19:33:59 -0000
@@ -530,14 +530,14 @@
 		    taddstr(ecgetstr(state, EC_NODUP, NULL));
 		    state->pc++;
 		    taddstr(") ");
-		    tindent++;
 		    n = tpush(code, 0);
 		    n->u._case.end = end;
 		    n->pop = (state->pc - 2 + WC_CASE_SKIP(code) >= end);
 		}
 	    } else if (state->pc < s->u._case.end) {
-		tindent--;
-		taddstr(WC_CASE_TYPE(code) == WC_CASE_OR ? " ;;" : ";&");
+		if (tnewlins)
+		    taddnl();
+		taddstr(WC_CASE_TYPE(code) == WC_CASE_OR ? ";;" : ";&");
 		if (tnewlins)
 		    taddnl();
 		else
@@ -547,13 +547,13 @@
 		taddstr(ecgetstr(state, EC_NODUP, NULL));
 		state->pc++;
 		taddstr(") ");
-		tindent++;
 		s->code = code;
 		s->pop = ((state->pc - 2 + WC_CASE_SKIP(code)) >=
 			  s->u._case.end);
 	    } else {
-		tindent--;
-		taddstr(WC_CASE_TYPE(code) == WC_CASE_OR ? " ;;" : ";&");
+		if (tnewlins)
+		    taddnl();
+		taddstr(WC_CASE_TYPE(code) == WC_CASE_OR ? ";;" : ";&");
 		tindent--;
 		if (tnewlins)
 		    taddnl();

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* Re: What would you say is the most-used way of indenting case labels
  2006-08-11 19:37   ` Peter Stephenson
@ 2006-08-12 15:28     ` Bart Schaefer
  2006-08-12 16:44     ` Wayne Davison
  1 sibling, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2006-08-12 15:28 UTC (permalink / raw)
  To: Zsh Users' List

On Aug 11,  8:37pm, Peter Stephenson wrote:
}
} Time for some audience participation.  Do you prefer the following
} style?
} 
} foo () {
}         case $1 in
}                 (a) print alpha
}                 print second
}                 print third
}                 ;;
}                 (b) print beta
}                 ;;
}                 (*) print omega
}                 ;;
}         esac
} }

No, I don't.  Case labels that short are pretty unusual, and with a
long label it'd be much harder to read.  And I prefer the second and
succeeding lines indented.  I also prefer the ;; indented, but that's
not so important.

The best thing IMO would be to use the line numbers that have already
been recorded (used in error messages and warnings) to decide when to
emit a newline, so that when you list a function or whatever you can
match the output to the error.  Lines with comments that were stripped
would be a bit of a problem; perhaps an option to print them as blank
lines, or to note the jump in line number as a comment like CPP:
# line 37

Next best (or when line numbers aren't available) would be to put the
first line on the same line as the case label only when the label is
less than N characters wide (for some value of N that makes sense,
maybe 7 if we're assuming 8-space tabs) and otherwise it goes on the
next line.  Then indent the way zsh currently does.

If that's prohibitively difficult (which I suspect it is) my next
choice is to never put anything on the same line as the case label.


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

* Re: What would you say is the most-used way of indenting case labels
  2006-08-11 19:37   ` Peter Stephenson
  2006-08-12 15:28     ` Bart Schaefer
@ 2006-08-12 16:44     ` Wayne Davison
  2006-08-13 14:17       ` Phil Pennock
  1 sibling, 1 reply; 9+ messages in thread
From: Wayne Davison @ 2006-08-12 16:44 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh Users' List

On Fri, Aug 11, 2006 at 08:37:41PM +0100, Peter Stephenson wrote:
> Time for some audience participation.  Do you prefer the following
> style? [...]

I like the case labels to be less indented than the code that follows.
I personally put them at the same level as the case, and only include a
statement on the same line if all the labels are really short and the
commands a one-liner, so in the general case I'd separate them:

foo () {
    case $1 in
    (a)
        print alpha
        print second
        print third
        ;;
    (b)
        print beta
        ;;
    (*)
        print omega
        ;;
    esac
}

I also like a 4-character indent.  That's my preference...

..wayne..


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

* Re: What would you say is the most-used way of indenting case labels
  2006-08-12 16:44     ` Wayne Davison
@ 2006-08-13 14:17       ` Phil Pennock
  0 siblings, 0 replies; 9+ messages in thread
From: Phil Pennock @ 2006-08-13 14:17 UTC (permalink / raw)
  To: Zsh Users' List

On 2006-08-12 at 09:44 -0700, Wayne Davison wrote:
> I like the case labels to be less indented than the code that follows.
> I personally put them at the same level as the case, and only include a
> statement on the same line if all the labels are really short and the
> commands a one-liner, so in the general case I'd separate them:

Speaking as an end-user, not the person writing the zsh internals code,
I agree with Wayne on general layout.  I'll avoid the religious war
about indent sizes and tab sizes, but my style otherwise matches
Wayne's.
-- 
VISTA: Viruses, Infections, Spyware, Trojans & Adware


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

end of thread, other threads:[~2006-08-13 14:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-11 10:54 What would you say is the most-used way of indenting case labels Nikolai Weibull
2006-08-11 11:10 ` Peter Stephenson
2006-08-11 12:47   ` Nikolai Weibull
2006-08-11 12:48     ` Nikolai Weibull
2006-08-11 14:22 ` Phil Pennock
2006-08-11 19:37   ` Peter Stephenson
2006-08-12 15:28     ` Bart Schaefer
2006-08-12 16:44     ` Wayne Davison
2006-08-13 14:17       ` Phil Pennock

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).