zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: Here document in code chunks
Date: Wed, 02 Sep 2015 14:13:54 +0100	[thread overview]
Message-ID: <20150902141354.48c4d872@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20150902100347.03027225@pwslap01u.europe.root.pri>

On Wed, 2 Sep 2015 10:03:47 +0100
Peter Stephenson <p.stephenson@samsung.com> wrote:
> On Wed, 2 Sep 2015 10:50:07 +0200
> Mikael Magnusson <mikachu@gmail.com> wrote:
>> % f() { cat << x << y; }
>> foo
>> x
>> bar
>> y
>> % which f
>> f () {
>>     cat <<x <<y
>> foo
>> xbar
>> y
>> }
>>
>> There should be a newline between x and bar in the output. The
>> function itself works fine.

It seems to be this simple.  (Here, here.)

pws

diff --git a/Src/text.c b/Src/text.c
index 3978a26..7e65f43 100644
--- a/Src/text.c
+++ b/Src/text.c
@@ -77,8 +77,8 @@ taddpending(char *str1, char *str2)
      */
     if (tpending) {
 	int oldlen = strlen(tpending);
-	tpending = zrealloc(tpending, len + oldlen);
-	sprintf(tpending + oldlen, "%s%s", str1, str2);
+	tpending = zrealloc(tpending, len + oldlen + 1);
+	sprintf(tpending + oldlen, "\n%s%s", str1, str2);
     } else {
 	tpending = (char *)zalloc(len);
 	sprintf(tpending, "%s%s", str1, str2);
diff --git a/Test/A04redirect.ztst b/Test/A04redirect.ztst
index 602341d..d7fe22f 100644
--- a/Test/A04redirect.ztst
+++ b/Test/A04redirect.ztst
@@ -555,3 +555,34 @@
 0:Assignment with exec used for redirection: POSIX_BUILTINS
 >x=And this
 ?This should appear, too
+
+  fn-two-heres() {
+# tabs below
+    cat <<-x <<-y
+	foo
+	x
+	bar
+	y
+  }
+  which -x2 fn-two-heres
+  fn-two-heres
+  eval "$(which -x2 fn-two-heres)"
+  fn-two-heres
+  print $functions[fn-two-heres]
+0:Two here-documents in a line are shown correctly.
+>fn-two-heres () {
+>  cat <<x <<y
+>foo
+>x
+>bar
+>y
+>}
+>foo
+>bar
+>foo
+>bar
+>	cat <<x <<y
+>foo
+>x
+>bar
+>y


      reply	other threads:[~2015-09-02 13:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-02  8:50 5.1.1? Mikael Magnusson
2015-09-02  9:03 ` Here document in code chunks Peter Stephenson
2015-09-02 13:13   ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150902141354.48c4d872@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).