Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

indented heredocs



Today we have this:

0 Wed 10:53:18 ~
204 Z% cat <<xx   
foo
bar
xx
foo
bar
0 Wed 10:53:33 ~
205 Z% 

Surely people have thought of this (Alternative 1):

0 Wed 10:53:53 ~
205 Z% cat <<xx   
  foo
  bar
  xx
foo
bar
0 Wed 10:53:53 ~
206 Z% 

but shells don’t do that.

I ran this idea by Steve Bourne and asked him why indenting was not allowed.

> I never considered the indent idea.  It's a good idea although I don't like the idea of post processing the temp file to remove the 
> leading white space.  I agree the way it is now is not easy to look at, and I can't think of a way to have the ident amount specified
> in advance of reading the document.


BTW, of historical interest, he also said he stole the heredoc idea from somebody else at Cambridge <https://www.youtube.com/watch?v=FI_bZhV7wpI#t=21m8s>.

I suggested this (Alternative 2), which he liked:

0 Wed 10:53:53 ~
206 Z% cat \
  <<xx   
  foo
  bar
  xx
foo
bar
0 Wed 10:54:10 ~
207 Z% 

He also suggested

> You could find another symbol after <  Right now <xxx is file <<yyy is heredoc <<< is string.  Other meta symbols
> are available which now would cause syntax error.


I don’t think that would help anything. If the parser doesn’t know how to do the new syntax with the existing << operator, you’ll get an error, and if the parser doesn’t know the new operator, you’ll get an error. Same difference.

I propose Alternative 2.



Messages sorted by: Reverse Date, Date, Thread, Author