Skip to content

Commit

Permalink
Patch LibYAML to add the indent_mapping_sequence emitter option
Browse files Browse the repository at this point in the history
When indent_mapping_sequence is truthy, block sequences in mapping
context will be indented like so:

foo:
  - bar
  - baz
  • Loading branch information
viking committed Aug 15, 2014
1 parent f8dc9cd commit b4579dc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions pkg/src/api.c
Expand Up @@ -534,6 +534,18 @@ yaml_emitter_set_indent(yaml_emitter_t *emitter, int indent)
emitter->best_indent = (1 < indent && indent < 10) ? indent : 2;
}

/*
* Set whether or not to indent block sequences in mapping context.
*/

YAML_DECLARE(void)
yaml_emitter_set_indent_mapping_sequence(yaml_emitter_t *emitter, int indent_mapping_sequence)
{
assert(emitter); /* Non-NULL emitter object expected. */

emitter->indent_mapping_sequence = indent_mapping_sequence;
}

/*
* Set the preferred line width.
*/
Expand Down
4 changes: 3 additions & 1 deletion pkg/src/emitter.c
Expand Up @@ -869,7 +869,9 @@ yaml_emitter_emit_block_sequence_item(yaml_emitter_t *emitter,
if (first)
{
if (!yaml_emitter_increase_indent(emitter, 0,
(emitter->mapping_context && !emitter->indention)))
(emitter->mapping_context
&& !emitter->indent_mapping_sequence
&& !emitter->indention)))
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/src/yaml.h
Expand Up @@ -1595,6 +1595,8 @@ typedef struct yaml_emitter_s {
int canonical;
/** The number of indentation spaces. */
int best_indent;
/** Whether or not to indent block sequences in mapping context. */
int indent_mapping_sequence;
/** The preferred width of the output lines. */
int best_width;
/** Allow unescaped non-ASCII characters? */
Expand Down

1 comment on commit b4579dc

@Alessandro-Barbieri
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you send those patches upstream?

Please sign in to comment.