Index: /libyaml/branches/stable/src/emitter.c
===================================================================
--- /libyaml/branches/stable/src/emitter.c	(revision 309)
+++ /libyaml/branches/stable/src/emitter.c	(revision 315)
@@ -586,4 +586,15 @@
         if (!first || emitter->canonical) {
             implicit = 0;
+        }
+
+        if ((event->data.document_start.version_directive ||
+                    (event->data.document_start.tag_directives.start
+                     != event->data.document_start.tag_directives.end)) &&
+                emitter->open_ended)
+        {
+            if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
+                return 0;
+            if (!yaml_emitter_write_indent(emitter))
+                return 0;
         }
 
@@ -639,4 +650,12 @@
     else if (event->type == YAML_STREAM_END_EVENT)
     {
+        if (emitter->open_ended)
+        {
+            if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
+                return 0;
+            if (!yaml_emitter_write_indent(emitter))
+                return 0;
+        }
+
         if (!yaml_emitter_flush(emitter))
             return 0;
@@ -1766,4 +1785,5 @@
     emitter->whitespace = is_whitespace;
     emitter->indention = (emitter->indention && is_indention);
+    emitter->open_ended = 0;
 
     return 1;
@@ -1903,4 +1923,8 @@
     emitter->whitespace = 0;
     emitter->indention = 0;
+    if (emitter->root_context)
+    {
+        emitter->open_ended = 1;
+    }
 
     return 1;
@@ -2137,4 +2161,6 @@
     }
 
+    emitter->open_ended = 0;
+
     string.pointer = string.end;
     if (string.start == string.pointer)
@@ -2154,4 +2180,5 @@
         {
             chomp_hint = "+";
+            emitter->open_ended = 1;
         }
         else
@@ -2163,4 +2190,5 @@
             {
                 chomp_hint = "+";
+                emitter->open_ended = 1;
             }
         }
@@ -2238,5 +2266,5 @@
                     k += WIDTH_AT(string, k);
                 }
-                if (!IS_BLANK_AT(string, k)) {
+                if (!IS_BLANKZ_AT(string, k)) {
                     if (!PUT_BREAK(emitter)) return 0;
                 }
Index: /libyaml/branches/stable/include/yaml.h
===================================================================
--- /libyaml/branches/stable/include/yaml.h	(revision 243)
+++ /libyaml/branches/stable/include/yaml.h	(revision 315)
@@ -1681,4 +1681,6 @@
     /** If the last character was an indentation character (' ', '-', '?', ':')? */
     int indention;
+    /** If an explicit document end is required? */
+    int open_ended;
 
     /** Anchor analysis. */
